You are on page 1of 16

Trinity International College

(Affiliated to Tribhuvan University)

Lab Report

Cloud Computing

Submitted by Submitted to
Name:
Program: BSc.CSIT
Roll no:
Batch: 2074
Semester:
Date:

Kathmandu, Nepal
2022
Q. Create an Extended Entity Relationship framework for the following:

- a user will be able to see a list of restaurants nearby, see the menu and place an order.

- the restaurants will be able to login/signup and add/edit list of menu, give discounts up to
30%.

- the restaurants will be able to view orders and process it.

EER diagram:

Q. Convert the Extended Entity Relationship diagram from lab 1 to relational schema.

CREATE TABLE Customer (


CustomerID INT NOT NULL PRIMARY KEY,
FirstName VARCHAR(80) NOT NULL,
LastName VARCHAR(80) NOT NULL,
Email VARCHAR(255) NOT NULL,
PhoneNo BIGINT(10) NOT NULL,
Address VARCHAR(255) NOT NULL
);

CREATE TABLE Orders (


OrderID INT NOT NULL PRIMARY KEY,
OrderDate DATETIME NOT NULL,
Status VARCHAR(15) NOT NULL,
Total DECIMAL(18,2) NOT NULL,
CustomerID INT,
FOREIGN KEY (CustomerID) REFERENCES Customer(CustomerID),
FOREIGN KEY (RestaurantID) REFERENCES Customer(RestaurantID)

);

CREATE TABLE Restaurant (


RestaurantID INT NOT NULL PRIMARY KEY,
Name VARCHAR(100) NOT NULL,
PhoneNo BIGINT(10) NOT NULL,
Latitude DECIMAL(8,6) NOT NULL,
Longitude DECIMAL(9,6) NOT NULL,
Address VARCHAR(100) NOT NULL,
Discount NUMERIC(4,4)
);

CREATE TABLE Menu(


ItemName VARCHAR(100) NOT NULL UNIQUE,
Category VARCHAR(50) NOT NULL,
UnitPrice DECIMAL(18,2) NOT NULL
);

CREATE TABLE Employees(


EmployeeID INT NOT NULL PRIMARY KEY,
LastName VARCHAR(80) NOT NULL,
FirstName VARCHAR(80) NOT NULL,
BirthDate DATETIME NOT NULL,
Photo NVARCHAR(2083) NOT NULL
);

Q. Create a hierarchical structure for the following relational schema:

dbuser( id, name (firstName, middleName, lastName), phone, address (country, state, city))

Then insert self-information and 5 other entries, and select record with country as ‘Nepal’.

1. Create table:

CREATE TYPE nameFormat AS(

"firstName" text,

"middleName" text,

"lastName" text

);

CREATE TYPE addressFormat AS(

"country" text,

"state" text,

"city" text

);

CREATE TABLE dbuser (

"id" serial NOT NULL,

"name" nameFormat,

"phone" bigint NOT NULL,


"address" addressFormat,

PRIMARY KEY ("id")

);

2. Insert your information with 5 other entries:

INSERT INTO public. dbuser (id, name, phone, address)

VALUES (1, (Shyam, NULL, 'chaudhary'), 9860691080, ('Nepal', 'Kathmandu',


'Kadhghari'));

3. Select records with country as ‘Nepal’:

SELECT * FROM public dbuser WHERE (address).country = 'Nepal';


Q1. How many productline=”Motorcycles”?

SELECT productLine, COUNT(*) FROM `products` WHERE productLine="Motorcycles";

Output:

Q2. Home many orders for Motorcycles?

SELECT COUNT(*) FROM `orderdetails` WHERE orderdetails.productCode IN (SELECT


productCode FROM products WHERE products.productLine="Motorcycles");

Output:

Q3. How many products in each category?

SELECT COUNT(productLine) as number_of_products, productLine

FROM products

GROUP by productLine

ORDER BY number_of_products DESC;

Output:
Q4. How many orders on each productline?

SELECT COUNT(orderNumber) as number_of_orders, products.productLine

FROM orderdetails

INNER JOIN products

ON orderdetails.productCode=products.productCode

GROUP BY products.productLine;

Output:

Q5. Create view table for question 3?

CREATE VIEW productCount AS


SELECT COUNT(productLine) as number_of_products, productLine

FROM products

GROUP by productLine

ORDER BY number_of_products DESC;

Output:

Q6. How many orders are shipped?

SELECT products.productLine, COUNT(orders.status) AS shipped_count

FROM orderdetails

INNER JOIN products

ON orderdetails.productCode=products.productCode

INNER JOIN orders

ON orders.orderNumber=orderdetails.orderNumber

WHERE orders.status="Shipped"

GROUP BY products.productLine;

Output:
Setting up replication in MySQL

MySQL replication is a process that allows data to be copied/replicated from one server to the other at the
same time. It is mainly done to increase the availability of data. One of the main reasons that people go
for MySQL master-slave replication is for data recovery.

For setting up the master-slave in MySQL, let us assume that server (192.168.0.31) is to be our master
and (192.168.0.34) the slave.

Step 1: Edit the configuration files & start the MySQL Servers

The first step in setting up replication involves editing the “my.cnf” file on the servers that will serve as
the master and slave. We will provide local configuration files “master.cnf” and “slave.cnf” that will be
used when starting up the MySQL servers.

master.cnf:

[mysqld]

server-id=1

log-bin=black-bin.log

datadir=/home/billy/mysql/master/data

innodb_flush_log_at_trx_commit=1

sync_binlog=1

slave.cnf:

[mysqld]

server-id=2

relay-log-index=slave-relay-bin.index

relay-log=slave-relay-bin

datadir=/home/billy/mysql/slave/data

After setting up the configuration files, we will start MySQL server using the following command for
both master and slave system.
master-server> mysqld --defaults-file=<location of master.cnf> &

slave-server> mysqld --defaults-file=<location of slave.cnf> &

Step 2: Create Replication User

Creating an account on the master server that the slave server can use to connect. his account must be
given the REPLICATION SLAVE privilege.

master-server> mysql -u root --prompt='master> '

master> CREATE USER replication_user@192.168.0.46;

master> GRANT REPLICATION SLAVE ON *.* TO replication_user@192.168.0.34 IDENTIFIED BY


'password';

master> FLUSH PRIVILEGES;

master> FLUSH TABLES WITH READ LOCK;

Step 3: Initialize Replication

To initialize replication on the slave, we issue a CHANGE MASTER command.

slave> CHANGE MASTER TO MASTER_HOST='192.168.0.45 ',

-> MASTER_USER='replication_user',

-> MASTER_PASSWORD='password’,

-> MASTER_LOG_FILE='',

-> MASTER_LOG_POS=4;

where,

● MASTER_HOST: the IP or hostname of the master server i.e., 192.168.0.46.


● MASTER_USER: this is the user we granted the REPLICATION SLAVE privilege to in Step 2
i.e., “replication_user”.
● MASTER_PASSWORD: this is the password we assigned to ”replication_user” in Step 2.
● MASTER_LOG_FILE: default is ‘’ or empty, is a binary log file at which the replication I/O
(receiver) thread begins reading from the source's binary log the next time the thread starts.
● MASTER_LOG_POS: default is 4 (would likely be different if there were existing writes to be
picked up from the master), defines the location in binary log file.
Finally, start replication on the slave:

slave> start slave;

Step 4: Basic Checks

We can perform basic checks by creating a database and table in master server, then verify that table in
slave server.

Master-server:

master> create database adbms;

master> create table adbms.tb1 (id int not null primary key);

Slave-server:

slave> select * from adbms.tb1;


Basic CRUD operations in MongoDB
Let assume that a connection is already established.
Create Operations
Create or insert operations add new documents to a collection. If the collection does not
currently exist, insert operations will create the collection.

MongoDB provides following methods to insert documents into a collection:


● db.<collection>.insertOne(<document>)
● db.<collection>.insertMany(<list_of_document>)
For example,
db.users.insertOne(
{
name: “jack”,
email: “jack@gmail.com”
}
)
In MongoDB, insert operations target a single collection. All write operations in MongoDB are
atomic on the level of a single document.

Read Operations
Read operations retrieve documents from a collection; i.e. query a collection for documents.
MongoDB provides the following methods to read documents from a collection:
● db.<collection>.find(<criteria>)
We can specify query filters or criteria that identify the documents to return.
For example,
db.users.find(
{
name: “jack”
}
)

Update Operations
Update operations modify existing documents in a collection. MongoDB provides the following
methods to update documents of a collection:
● db.<collection>.updateOne(<filter>, <update>)
● db.<collection>.updateMany(<filter>, <update>)
● db.<collection>.replaceOne(<filter>, <replacement>)
In MongoDB, update operations target a single collection. All write operations in MongoDB are
atomic on the level of a single document. We can specify criteria, or filters, that identify the
documents to update. These filters use the same syntax as read operations.
For example,
db.users.updateMany(
{
name: “jack”
},
{j
$set:{ email: “jack@gmail.com” }
}
)
Delete Operations
Delete operations remove documents from a collection. MongoDB provides the following
methods to delete documents of a collection:
● db.<collection>.deleteOne(<filter>)
● db.<collection>.deleteMany(<filter>)
In MongoDB, delete operations target a single collection. All write operations in MongoDB are
atomic on the level of a single document. We can specify criteria, or filters, that identify the
documents to remove. These filters use the same syntax as read operations.
For example,
db.users.deleteMany(
{
name: “jack”
}
)
Aggregation Pipelines
Aggregation pipeline is the method of processing a group of documents in one or more stages,
where each stage performs distinct operations. Each stage passes the output to the next stage.
Aggregation pipeline is achieved by using the following methods:
● db.collection.aggregate()
● aggregate
Aggregation steps:
1. Download Mongosh from the Atlas website to connect to the database.
2. Whitelist current IP address.

3. Establish connection using the connection string like:

4. Inserting the data in the Order cluster.


5. Performing aggregation.

You might also like