Sie sind auf Seite 1von 35

Experiment No.

Objective: Working of Goggle Drive to make spreadsheet and notes.

Requirement: Google account, Internet Connection.

THEORY:

Google Docs is a free cloud-based suite of tools for creating documents, spreadsheets,
presentations, and more. This tutorial will cover the Spreadsheets application in Google
Docs, in addition to showing you how to access and store your Docs from Google Drive.

Google Docs, Sheets, and Slides are productivity apps that let you create different kinds
of online documents, work on them in real time with other people, and store them in your
Google Drive online — all for free. You can access the documents, spreadsheets, and
presentations you create from any computer, anywhere in the world. (There's even some
work you can do without an Internet connection!) This guide will give you a quick
overview of the many things that you can do with Google Docs, Sheets, and Slides.

Google Docs

Google Docs is an online word processor that lets you create and format text documents
and collaborate with other people in real time. Here's what you can do with Google Docs:

 Upload a Word document and convert it to a Google document


 Add flair and formatting to your documents by adjusting margins, spacing, fonts,
and colors — all that fun stuff
 Invite other people to collaborate on a document with you, giving them edit,
comment or view access
 Collaborate online in real time and chat with other collaborators — right from
inside the document
 View your document's revision history and roll back to any previous version
 Download a Google document to your desktop as a Word, OpenOffice, RTF, PDF,
HTML or zip file
 Translate a document to a different language
 Email your documents to other people as attachments

Google Sheets

Google Sheets is an online spreadsheet app that lets you create and format spreadsheets
and simultaneously work with other people. Here's what you can do with Google Sheets:

 Import and convert Excel, .csv, .txt and .ods formatted data to a Google
spreadsheet
 Export Excel, .csv, .txt and .ods formatted data, as well as PDF and HTML files
 Use formula editing to perform calculations on your data, and use formatting
make it look the way you'd like
 Chat in real time with others who are editing your spreadsheet
 Create charts with your data
1
 Embed a spreadsheet — or individual sheets of your spreadsheet — on your blog
or website

Google Slides

Google Slides is an online presentations app that allows you to show off your work in a
visual way. Here's what you can do with Google Slides:

 Create and edit presentations


 Edit a presentation with friends or coworkers, and share it with others effortlessly
 Import .pptx and .pps files and convert them to Google presentations
 Download your presentations as a PDF, a PPT, or a .txt file
 Insert images and videos into your presentation
 Publish and embed your presentations in a website

Create, name or delete a Google document


Create a Google document

To create a new document, go to your Drive, click the Create button, and select
Document.

A window with a new Google document will open, and you'll be able to edit the
document, share it with other people, and collaborate on it in real-time. Google Docs
saves your document automatically, and you can always access it from your Drive.

Name a document

When you create a new document, Google Docs will name it Untitled by default.

To choose a name other than Untitled, click the File menu, and select Rename. From
here you can choose and confirm your document's title. You can also edit the name by
clicking the title displayed at the top of the page, and making your changes in the dialog
that appears. Titles can be up to 255 characters long.

Delete a document

Delete an item that you own from your Drive


1. From your Drive, select the item(s) you want to delete.
2. From the More menu, choose Move to trash.
3. If you're deleting a shared document that you own, you'll see an option to change
the ownership of the document.
4. The item will be moved to the Trash.
5. To purge individual items from Trash, select them and choose Delete forever. To
purge all your items click Empty Trash in the upper left.

2
Create and save a document

There are different ways of getting started using Google documents: you can create a new
online document, you can upload an existing one, or you can use a template from our
templates gallery.

To create a new document, go to your Drive, click the red Create button, and select
Document from the drop-down menu.

As soon as you name the document or start typing, Google Docs will automatically save
your work every few seconds. At the top of the document, you'll see text that indicates
when your document was last saved. You can access your document at any time by
opening your Drive at http://drive.google.com.

To save a copy of a document to your computer, you can download it. In your document,
go to the File menu and point your mouse to the Download as option. Select one of the
following file types: HTML (zipped), RTF, Word, Open Office, PDF, and plain text. Your
document will download to your computer.

Upload a document

You can upload existing documents to Google documents at any time. When you're
uploading, you can either keep your document in its original file type or convert it to
Google Docs format. Converting your document to Google Docs format allows you to
edit and collaborate online from any computer.

Note: When uploaded, images within a document are left as images (rather than being
converted to text by Optical Character Recognition technology).

You can upload the following file types:

 .html
 .txt
 .odt
 .rtf
 .doc and .docx
 .pdf

Follow these steps to upload a document:

1. Click the Upload icon in the top left of your Documents List.
2. Click Files..., and select the document you'd like to upload.
3. Click Open.
4. Check the box next to 'Convert documents, presentations, spreadsheets, and
drawings to the corresponding Google Docs format' if you'd like to be able to edit
and collaborate on the document online. Uploaded document files that are
converted to Google documents format can't be larger than 1 MB.
5. Click Start upload. The uploaded file will appear in your Documents List.

3
4
Experiment No. 2

Objective: Installation of Virtual Box

Requirement: Internet

THEORY:

VirtualBox is an open-source hypervisor software; it allows you to


create and run guest operating systems (“virtual machines”) such as
Linux and Windows on top of the existing operating system (host).
VirtualBox may be installed on host operating systems,
including Linux, Windows, Solaris, OS X, and OpenSolaris.

virtualbox.org install VM

After installation, you can start VirtualBox as follows:

On a Windows host, in the standard "Programs" menu, click on the item in the

5
"VirtualBox" group. On Vista or Windows 7, you can also type "VirtualBox" in the
search box of the "Start" menu.

 Creating your first virtual machine:

Click on the "New" button at the top of the VirtualBox Manager window. A wizard will
pop up to guide you through setting up a new virtual machine (VM)

Creating your first virtual machine:


Click on the "New" button at the top of the VirtualBox Manager window.
A wizard will pop up to guide you through setting up a new virtual machine (VM)

 The VM name will later be shown in the VM list of the VirtualBox Manager
window, and it will be used for the VM's files on disk. Even though any name
could be used, keep in mind that once you have created a few VMs, you will
appreciate if you have given your VMs rather informative names; "My VM"
would thus be less useful than "Windows XP SP2 with OpenOffice".

6
 On the next page, select the memory (RAM) that Virtual Box should allocate
every time the virtual machine is started. The amount of memory given here will
be taken away from your host machine and presented to the guest operating
system, which will report this size as the (virtual) computer's installed RAM.

A Windows XP guest will require at least a few hundred MB RAM to run properly, and
Windows Vista will even refuse to install with less than 512 MB. Of course, if you want
to run graphics-intensive applications in your VM, you may require even more RAM.

So, as a rule of thumb, if you have 1 GB of RAM or more in your host computer, it is
usually safe to allocate 512 MB to each VM. But, in any case, make sure you always
have at least 256 to 512 MB of RAM left on your host operating system. Otherwise you
may cause your host OS to excessively swap out memory to your hard disk, effectively
bringing your host system to a standstill. As with the other settings, you can change this
setting later, after you have created the VM.

7
 Next, you must specify a virtual hard disk for your VM. There are many and
potentially complicated ways in which VirtualBox can provide hard disk space to
a VM (see Chapter 5, Virtual storage for details), but the most common way is to
use a large image file on your "real" hard disk, whose contents VirtualBox
presents to your VM as if it were a complete hard disk. This file represents an
entire hard disk then, so you can even copy it to another host and use it with
another VirtualBox installation

8
9
Running your virtual machine: To start a virtual machine, you have several options

Double-click on its entry in the list within the Manager window or

select its entry in the list in the Manager window it and press the "Start" button at the top

for virtual machines created with VirtualBox 4.0 or later, navigate to the "VirtualBox
VMs" folder in your system user's home directory, find the subdirectory of the machine
you want to start and double-click on the machine settings file (with a .vbox file
extension). This opens up a new window, and the virtual machine which you selected will
boot up. Everything which would normally be seen on the virtual system's monitor is
shown in the window. In general, you can use the virtual machine much like you would
use a real computer. There are couple of points worth mentioning however.

Saving the state of the machine: When you click on the "Close" button of your virtual
machine window (at the top right of the window, just like you would close any other
window on your system), VirtualBox asks you whether you want to "save" or "power off"
the VM. (As a shortcut, you can also press the Host key together with "Q".)

10
11
Experiment No. 3

Objective: Installation of Virtual Box

Requirement: Internet

THEORY: We will create a developer account on amazon (aws.amazon.com). We will


work on several exercises to explore the features of amazon cloud and understand how it
can support the existing IT infrastructure you have. We will work on complete example in
collecting live twitter data and performing a simple analysis on the data.
Preliminaries:
1. Create an aws developer account at http://aws.amazon.com
2. Update your credits.
3. Navigate the aws console. Browse through the wide range of infrastructure services
offered by aws.
4. Create an amazon key pair. This is the key-pair we will use for accessing
applications/services on the cloud. Call it Richs2014 or something you will
remember. This is like a key your safety box. Don’t lose. Store Richs1.pem and
equivalent private key for putty Richs2014.ppk in a safe location.
5. Identify the credentials of your amazon; just be knowledge about where to locate
them when you need them for authenticate yourself/your application using these
credentials. https://console.aws.amazon.com/iam/home?#security_credential
6. Identity and Access Management (IAM) is an important service. Read
http://docs.aws.amazon.com/IAM/latest/UserGuide/IAM_Introduction.html

Exercise 1: Launch an instance EC2:


1. Click on the first one: Services window EC2 from the services dashboardStudy
the various items click on the lunch button

Step 1: Choose an AMI (Amazon machine image) for the instance you want: this can be
single CPU machine to a sophisticated cluster of powerful processors.
The instances can be from Amazon Market Place, Community (contributed) AMI, My
own AMIs (that I may have created: Eg.,RichsAMI) Choose a “free-tier” eligible
Windows AMI.
Step 2: Choose an instance type: small, large, micro, medium , etc.
Step 3: Review and launch. We are done, we have Windows machine.
Step 4: Create a new key-pair to access the instance that will be created. We will be
accessing the instance we create using Public-private key pair. Download the pair of the
key and store it.
Launch instance. Once it is ready you will use its public IP and the key pair we saved
and the RDP protocol to access the instance on the cloud.

12
Hosting a static web site on amazon aws.
Overview: Simply load the web site components into an appropriate S3 folder/directories
created. Configure a few parameters, policy file and the web site all set to go!
Step 1:
1. When you host a website on Amazon S3, AWS assigns your website a URL based on
the name of the storage location you create in Amazon S3 to hold the website files
(called an S3 bucket) and the geographical region where you created the bucket.
2. For example, if you create a bucket called richs on the east coast of the United States
and use it to host your website, the default URL will be http://richs.s3-website-us-
east-1.amazonaws.com/.
3. We will not use Route 53 and CloudFront for this proof-of-concept implementation.
Step 2:
1. Open the Amazon S3 console at https://console.aws.amazon.com/s3/.
2. Create 3 buckets in s3: richs.com, www.richs.com, logs.richs.com
3. Upload the files of your static web page into richs.com bucket. Upload index.html
and rangen.js from your lab documents.
4. Set the permissions of richs.com to allow others to view: In the policy edit window
enter the code given below and save.

{
"Version":"2008-10-17",
"Statement":[{
"Sid":"Allow Public Access to All Objects",
"Effect":"Allow",
"Principal": {
"AWS": "*"
},
"Action":["s3:GetObject"],
"Resource":["arn:aws:s3:::richs.com/*"
]
}
]
}

Step 3: Enable logging and redirection (note: for some reason this collides with
richs.com)
1. In the logging window enter logs.richs.com and /root in the next box; right click
on www.richs.com properties and redirect it to richs.com

13
2. In the richs.com bucket, enable web hosting and enter index,html as the index
document. If you an error document, you can ad that in the next box.
3. Click on the endpoint address that shows up in properties window of richs.com
4. You should be able to see the static application.

14
Experiment No. 4

Objective: Install cloudsim and create a data center with one host and run one
cloudlet on it.

Requirement: Jdk.17, Cloudsim, apache common math, eclipse

THEORY :

Overview of CloudSim functionalities:

 support for modeling and simulation of large scale Cloud computing data centers
 support for modeling and simulation of virtualized server hosts, with
customizable policies for provisioning host resources to virtual machines
 support for modeling and simulation of application containers
 support for modeling and simulation of energy-aware computational resources
 support for modeling and simulation of data center network topologies and
message-passing applications
 support for modeling and simulation of federated clouds
 support for dynamic insertion of simulation elements, stop and resume of
simulation
 support for user-defined policies for allocation of hosts to virtual machines and
policies for allocation of host resources to virtual machines

Installation steps

Step 1: Initialize the Cloudsim package by calling CloudSim.init(int numUser,


Calendar cal, boolean traceFlag);
Step 2: Create Datacenters and set the needed Datacenter Characteristics;
Step 3: Create Broker;
Step 4: Create virtual machine and set the configuration of each virtual machine,
such as mips, size, ram and processing
element number. Add virtual machine to the virtual machine list. Submit the
virtual machine list to the broker;
Step 5: Create Cloudlet. Similarly, set the properties of each Cloudlet and add it
into the cloudlet list. Submit the cloudlet list
to the broker;
Step 6: Implement a tasks scheduling function (say named as: public void
bindCloudletToVmsScheduling()) in the
DatacenterBroker;
Step 7: Bind the cloudlets to VMs by calling the function defined in
DatacenterBroker to apply your own task scheduling
algorithm;
Step 8: Start the simulation by calling CloudSim.startSimulation ();
Step 9: Get the results by printing them out on the console or some other possible
ways;
Step 10: Stop the simulation by calling CloudSim.stopSimulation ();

15
Program:

import java.text.DecimalFormat;

import java.util.ArrayList;

import java.util.Calendar;

import java.util.LinkedList;

import java.util.List;

import org.cloudbus.cloudsim.Cloudlet;

import org.cloudbus.cloudsim.CloudletSchedulerTimeShared ;

import org.cloudbus.cloudsim.Datacenter;

import org.cloudbus.cloudsim.DatacenterBroker;

import org.cloudbus.cloudsim.DatacenterCharacteristics ;

import org.cloudbus.cloudsim.Host;

import org.cloudbus.cloudsim.Log;

import org.cloudbus.cloudsim.Pe;

import org.cloudbus.cloudsim.Storage ;

import org.cloudbus.cloudsim.UtilizationModel;

import org.cloudbus.cloudsim.UtilizationModelFull;

import org.cloudbus.cloudsim.Vm;

import org.cloudbus.cloudsim.VmAllocationPolicySimple;

import org.cloudbus.cloudsim.VmSchedulerTimeShared ;

import org.cloudbus.cloudsim.core.CloudSim ;

import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple ;

import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple ;

import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple ;

16
/**

* A simple example showing how to create a data center with one host and run one
cloudlet on it.

*/

public class CloudSimExample1 {

/** The cloudlet list. */

private static List<Cloudlet> cloudletList;

/** The vmlist. */

private static List<Vm> vmlist;

/**

* Creates main() to run this example.

* @param args the args

*/

@SuppressWarnings("unused")

public static void main(String[] args) {

Log.printLine("Starting CloudSimExample1...");

try {

// First step: Initialize the CloudSim package. It should be


called before creating any entities.

int num_user = 1; // number of cloud users

Calendar calendar = Calendar.getInstance(); // Calendar whose fields


have been initialized with the current date and time.

boolean trace_flag = false; // trace events

17
/* Comment Start - Dinesh Bhagwat

* Initialize the CloudSim library.

* init() invokes initCommonVariable() which in turn calls


initialize() (all these 3 methods are defined in CloudSim.java).

* initialize() creates two collections - an ArrayList of


SimEntity Objects (named entities which denote the simulation entities) and

* a LinkedHashMap (named entitiesByName which denote the


LinkedHashMap of the same simulation entities), with name of every SimEntity as the
key.

* initialize() creates two queues - a Queue of SimEvents


(future) and another Queue of SimEvents (deferred).

* initialize() creates a HashMap of of Predicates (with integers


as keys) - these predicates are used to select a particular event from the deferred
queue.

* initialize() sets the simulation clock to 0 and running (a


boolean flag) to false.

* Once initialize() returns (note that we are in method


initCommonVariable() now), a CloudSimShutDown (which is derived from SimEntity)
instance is created

* (with numuser as 1, its name as CloudSimShutDown, id as -1,


and state as RUNNABLE). Then this new entity is added to the simulation

* While being added to the simulation, its id changes to 0 (from


the earlier -1). The two collections - entities and entitiesByName are updated with
this SimEntity.

* the shutdownId (whose default value was -1) is 0

* Once initCommonVariable() returns (note that we are in method


init() now), a CloudInformationService (which is also derived from SimEntity) instance
is created

* (with its name as CloudInformatinService, id as -1, and state


as RUNNABLE). Then this new entity is also added to the simulation.

* While being added to the simulation, the id of the SimEntitiy


is changed to 1 (which is the next id) from its earlier value of -1.

* The two collections - entities and entitiesByName are updated


with this SimEntity.

* the cisId(whose default value is -1) is 1

* Comment End - Dinesh Bhagwat

*/

CloudSim.init(num_user, calendar, trace_flag);

18
// Second step: Create Datacenters

// Datacenters are the resource providers in CloudSim. We need at

// list one of them to run a CloudSim simulation

Datacenter datacenter0 = createDatacenter("Datacenter_0");

// Third step: Create Broker

DatacenterBroker broker = createBroker();

int brokerId = broker.getId();

// Fourth step: Create one virtual machine

vmlist = new ArrayList<Vm>();

// VM description

int vmid = 0;

int mips = 1000;

long size = 10000; // image size (MB)

int ram = 512; // vm memory (MB)

long bw = 1000;

int pesNumber = 1; // number of cpus

String vmm = "Xen"; // VMM name

// create VM

Vm vm = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm,


new CloudletSchedulerTimeShared());

19
// add the VM to the vmList

vmlist.add(vm);

// submit vm list to the broker

broker.submitVmList(vmlist);

// Fifth step: Create one Cloudlet

cloudletList = new ArrayList<Cloudlet>();

// Cloudlet properties

int id = 0;

long length = 400000;

long fileSize = 300;

long outputSize = 300;

UtilizationModel utilizationModel = new UtilizationModelFull();

Cloudlet cloudlet =

new Cloudlet(id, length, pesNumber, fileSize,

outputSize, utilizationModel, utilizationModel,

utilizationModel);

cloudlet.setUserId(brokerId);

cloudlet.setVmId(vmid);

20
// add the cloudlet to the list

cloudletList.add(cloudlet);

// submit cloudlet list to the broker

broker.submitCloudletList(cloudletList);

// Sixth step: Starts the simulation

CloudSim.startSimulation();

CloudSim.stopSimulation();

//Final step: Print results when simulation is over

List<Cloudlet> newList = broker.getCloudletReceivedList();

printCloudletList(newList);

Log.printLine("CloudSimExample1 finished!");

} catch (Exception e) {

e.printStackTrace();

Log.printLine("Unwanted errors happen");

21
/**

* Creates the datacenter.

* @param name the name

* @return the datacenter

*/

private static Datacenter createDatacenter(String name) {

// Here are the steps needed to create a PowerDatacenter:

// 1. We need to create a list to store

// our machine

List<Host> hostList = new ArrayList<Host>();

// 2. A Machine contains one or more PEs or CPUs/Cores.

// In this example, it will have only one core.

List<Pe> peList = new ArrayList<Pe>();

int mips = 1000;

// 3. Create PEs and add these into a list.

peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id


and MIPS Rating

// 4. Create Host with its id and list of PEs and add them to the list

// of machines

22
int hostId = 0;

int ram = 2048; // host memory (MB)

long storage = 1000000; // host storage

int bw = 10000;

hostList.add(

new Host(

hostId,

new RamProvisionerSimple(ram),

new BwProvisionerSimple(bw),

storage,

peList,

new VmSchedulerTimeShared(peList)

); // This is our machine

// 5. Create a DatacenterCharacteristics object that stores the

// properties of a data center: architecture, OS, list of

// Machines, allocation policy: time- or space-shared, time zone

// and its price (G$/Pe time unit).

String arch = "x86"; // system architecture

String os = "Linux"; // operating system

String vmm = "Xen";

double time_zone = 10.0; // time zone this resource located

double cost = 3.0; // the cost of using processing in this resource

23
double costPerMem = 0.05; // the cost of using memory in this resource

double costPerStorage = 0.001; // the cost of using storage in this

// resource

double costPerBw = 0.0; // the cost of using bw in this resource

LinkedList<Storage> storageList = new LinkedList<Storage>(); // we are not


adding SAN

// devices by now

DatacenterCharacteristics characteristics = new DatacenterCharacteristics(

arch, os, vmm, hostList, time_zone, cost, costPerMem,

costPerStorage, costPerBw);

// 6. Finally, we need to create a PowerDatacenter object.

Datacenter datacenter = null;

try {

datacenter = new Datacenter(name, characteristics, new


VmAllocationPolicySimple(hostList), storageList, 0);

} catch (Exception e) {

e.printStackTrace();

return datacenter;

24
// We strongly encourage users to develop their own broker policies, to

// submit vms and cloudlets according

// to the specific rules of the simulated scenario

/**

* Creates the broker.

* @return the datacenter broker

*/

private static DatacenterBroker createBroker() {

DatacenterBroker broker = null;

try {

broker = new DatacenterBroker("Broker");

} catch (Exception e) {

e.printStackTrace();

return null;

return broker;

/**

* Prints the Cloudlet objects.

* @param list list of Cloudlets

*/

private static void printCloudletList(List<Cloudlet> list) {

int size = list.size();

25
Cloudlet cloudlet;

String indent = " ";

Log.printLine();

Log.printLine("========== OUTPUT ==========");

Log.printLine("Cloudlet ID" + indent + "STATUS" + indent

+ "Data center ID" + indent + "VM ID" + indent + "Time" + indent

+ "Start Time" + indent + "Finish Time");

DecimalFormat dft = new DecimalFormat("###.##");

for (int i = 0; i < size; i++) {

cloudlet = list.get(i);

Log.print(indent + cloudlet.getCloudletId() + indent + indent);

if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) {

Log.print("SUCCESS");

Log.printLine(indent + indent + cloudlet.getResourceId()

+ indent + indent + indent + cloudlet.getVmId()

+ indent + indent

+ dft.format(cloudlet.getActualCPUTime()) +
indent

+ indent +
dft.format(cloudlet.getExecStartTime())

+ indent + indent

26
+ dft.format(cloudlet.getFinishTime()));

27
Experiment No. 5

Objective: Create two datacenters with one host each and run two cloudlets on them
using Cloudsim

Requirement: Jdk.17, Cloudsim, apache common math, eclipse

THEORY :

Overview of CloudSim functionalities:

 support for modeling and simulation of large scale Cloud computing data centers
 support for modeling and simulation of virtualized server hosts, with
customizable policies for provisioning host resources to virtual machines
 support for modeling and simulation of application containers
 support for modeling and simulation of energy-aware computational resources
 support for modeling and simulation of data center network topologies and
message-passing applications
 support for modeling and simulation of federated clouds
 support for dynamic insertion of simulation elements, stop and resume of
simulation
 support for user-defined policies for allocation of hosts to virtual machines and
policies for allocation of host resources to virtual machines

Installation steps

Step 1: Initialize the Cloudsim package by calling CloudSim.init(int numUser,


Calendar cal, boolean traceFlag);
Step 2: Create Datacenters and set the needed Datacenter Characteristics;
Step 3: Create Broker;
Step 4: Create virtual machine and set the configuration of each virtual machine,
such as mips, size, ram and processing
element number. Add virtual machine to the virtual machine list. Submit the
virtual machine list to the broker;
Step 5: Create Cloudlet. Similarly, set the properties of each Cloudlet and add it
into the cloudlet list. Submit the cloudlet list
to the broker;
Step 6: Implement a tasks scheduling function (say named as: public void
bindCloudletToVmsScheduling()) in the
DatacenterBroker;
Step 7: Bind the cloudlets to VMs by calling the function defined in
DatacenterBroker to apply your own task scheduling
algorithm;
Step 8: Start the simulation by calling CloudSim.startSimulation ();
Step 9: Get the results by printing them out on the console or some other possible
ways;
Step 10: Stop the simulation by calling CloudSim.stopSimulation ();

28
Program:

package org.cloudbus.cloudsim.examples;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;

import org.cloudbus.cloudsim.Cloudlet;
import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
import org.cloudbus.cloudsim.Datacenter;
import org.cloudbus.cloudsim.DatacenterBroker;
import org.cloudbus.cloudsim.DatacenterCharacteristics;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Pe;
import org.cloudbus.cloudsim.Storage;
import org.cloudbus.cloudsim.UtilizationModel;
import org.cloudbus.cloudsim.UtilizationModelFull;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.VmAllocationPolicySimple;
import org.cloudbus.cloudsim.VmSchedulerSpaceShared;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;

/**
* A simple example showing how to create
* two datacenters with one host each and
* run two cloudlets on them.
*/
public class CloudSimExample4 {

/** The cloudlet list. */


private static List<Cloudlet> cloudletList;

/** The vmlist. */


private static List<Vm> vmlist;

/**
* Creates main() to run this example
*/
public static void main(String[] args) {

Log.printLine("Starting CloudSimExample4...");
29
try {
// First step: Initialize the CloudSim package. It should
be called
// before creating any entities.
int num_user = 1; // number of cloud users
Calendar calendar = Calendar.getInstance();
boolean trace_flag = false; // mean trace events

// Initialize the GridSim library


CloudSim.init(num_user, calendar, trace_flag);

// Second step: Create Datacenters


//Datacenters are the resource providers in CloudSim.
We need at list one of them to run a CloudSim simulation
@SuppressWarnings("unused")
Datacenter datacenter0 =
createDatacenter("Datacenter_0");
@SuppressWarnings("unused")
Datacenter datacenter1 =
createDatacenter("Datacenter_1");

//Third step: Create Broker


DatacenterBroker broker = createBroker();
int brokerId = broker.getId();

//Fourth step: Create one virtual machine


vmlist = new ArrayList<Vm>();

//VM description
int vmid = 0;
int mips = 250;
long size = 10000; //image size (MB)
int ram = 512; //vm memory (MB)
long bw = 1000;
int pesNumber = 1; //number of cpus
String vmm = "Xen"; //VMM name

//create two VMs


Vm vm1 = new Vm(vmid, brokerId, mips,
pesNumber, ram, bw, size, vmm, new
CloudletSchedulerTimeShared());

vmid++;
Vm vm2 = new Vm(vmid, brokerId, mips,
pesNumber, ram, bw, size, vmm, new
CloudletSchedulerTimeShared());

30
//add the VMs to the vmList
vmlist.add(vm1);
vmlist.add(vm2);

//submit vm list to the broker


broker.submitVmList(vmlist);

//Fifth step: Create two Cloudlets


cloudletList = new ArrayList<Cloudlet>();

//Cloudlet properties
int id = 0;
long length = 40000;
long fileSize = 300;
long outputSize = 300;
UtilizationModel utilizationModel = new
UtilizationModelFull();

Cloudlet cloudlet1 = new Cloudlet(id, length,


pesNumber, fileSize, outputSize, utilizationModel, utilizationModel,
utilizationModel);
cloudlet1.setUserId(brokerId);

id++;
Cloudlet cloudlet2 = new Cloudlet(id, length,
pesNumber, fileSize, outputSize, utilizationModel, utilizationModel,
utilizationModel);
cloudlet2.setUserId(brokerId);

//add the cloudlets to the list


cloudletList.add(cloudlet1);
cloudletList.add(cloudlet2);

//submit cloudlet list to the broker


broker.submitCloudletList(cloudletList);

//bind the cloudlets to the vms. This way, the broker


// will submit the bound cloudlets only to the specific
VM

broker.bindCloudletToVm(cloudlet1.getCloudletId(),vm1.getId());

broker.bindCloudletToVm(cloudlet2.getCloudletId(),vm2.getId());

// Sixth step: Starts the simulation


CloudSim.startSimulation();

31
// Final step: Print results when simulation is over
List<Cloudlet> newList =
broker.getCloudletReceivedList();

CloudSim.stopSimulation();

printCloudletList(newList);

Log.printLine("CloudSimExample4 finished!");
}
catch (Exception e) {
e.printStackTrace();
Log.printLine("The simulation has been terminated
due to an unexpected error");
}
}

private static Datacenter createDatacenter(String name){

// Here are the steps needed to create a PowerDatacenter:


// 1. We need to create a list to store
// our machine
List<Host> hostList = new ArrayList<Host>();

// 2. A Machine contains one or more PEs or CPUs/Cores.


// In this example, it will have only one core.
List<Pe> peList = new ArrayList<Pe>();

int mips = 1000;

// 3. Create PEs and add these into a list.


peList.add(new Pe(0, new PeProvisionerSimple(mips))); //
need to store Pe id and MIPS Rating

//4. Create Host with its id and list of PEs and add them to
the list of machines
int hostId=0;
int ram = 2048; //host memory (MB)
long storage = 1000000; //host storage
int bw = 10000;

//in this example, the VMAllocatonPolicy in use is


SpaceShared. It means that only one VM
//is allowed to run on each Pe. As each Host has only one
Pe, only one VM can run on each Host.

32
hostList.add(
new Host(
hostId,
new RamProvisionerSimple(ram),
new BwProvisionerSimple(bw),
storage,
peList,
new VmSchedulerSpaceShared(peList)
)
); // This is our first machine

// 5. Create a DatacenterCharacteristics object that stores


the
// properties of a data center: architecture, OS, list of
// Machines, allocation policy: time- or space-shared, time
zone
// and its price (G$/Pe time unit).
String arch = "x86"; // system architecture
String os = "Linux"; // operating system
String vmm = "Xen";
double time_zone = 10.0; // time zone this resource
located
double cost = 3.0; // the cost of using processing
in this resource
double costPerMem = 0.05; // the cost of using
memory in this resource
double costPerStorage = 0.001; // the cost of using
storage in this resource
double costPerBw = 0.0; // the cost of
using bw in this resource
LinkedList<Storage> storageList = new
LinkedList<Storage>(); //we are not adding SAN devices by now

DatacenterCharacteristics characteristics = new


DatacenterCharacteristics(
arch, os, vmm, hostList, time_zone, cost, costPerMem,
costPerStorage, costPerBw);

// 6. Finally, we need to create a PowerDatacenter object.


Datacenter datacenter = null;
try {
datacenter = new Datacenter(name, characteristics,
new VmAllocationPolicySimple(hostList), storageList, 0);
} catch (Exception e) {
e.printStackTrace();
}

33
return datacenter;
}

//We strongly encourage users to develop their own broker


policies, to submit vms and cloudlets according
//to the specific rules of the simulated scenario
private static DatacenterBroker createBroker(){

DatacenterBroker broker = null;


try {
broker = new DatacenterBroker("Broker");
} catch (Exception e) {
e.printStackTrace();
return null;
}
return broker;
}

/**
* Prints the Cloudlet objects
* @param list list of Cloudlets
*/
private static void printCloudletList(List<Cloudlet> list) {
int size = list.size();
Cloudlet cloudlet;

String indent = " ";


Log.printLine();
Log.printLine("========== OUTPUT
==========");
Log.printLine("Cloudlet ID" + indent + "STATUS" + indent
+
"Data center ID" + indent + "VM ID" + indent
+ "Time" + indent + "Start Time" + indent + "Finish Time");

DecimalFormat dft = new DecimalFormat("###.##");


for (int i = 0; i < size; i++) {
cloudlet = list.get(i);
Log.print(indent + cloudlet.getCloudletId() + indent
+ indent);

if (cloudlet.getCloudletStatus() ==
Cloudlet.SUCCESS){
Log.print("SUCCESS");

Log.printLine( indent + indent +


cloudlet.getResourceId() + indent + indent + indent +
cloudlet.getVmId() +

34
indent + indent +
dft.format(cloudlet.getActualCPUTime()) + indent + indent +
dft.format(cloudlet.getExecStartTime())+
indent + indent +
dft.format(cloudlet.getFinishTime()));
}
}

}
}

35

Das könnte Ihnen auch gefallen