Guide to CloudsimExample1.java simulation workflow

Any Example provided in the ‘org.cloudbus.cloudsim.example’ Package under the example folder of the CloudSim project follows some standard steps to implement the specified configuration to start a simulation. To understand the working of the CloudSim simulation framework, knowledge about these steps is a must. This article will help you to get an understanding of CloudsimExample1.java simulation workflow.

Before you start, It is essential that the cloudsim should already installed/setup on your local computer machine. In case you are yet to install it, you may follow the process of Cloudsim setup using Eclipse IDE

The main() method is the pointer from where the execution of this example starts

public static void main(String[] args)

There are eleven steps that are followed in each example with some variation in them, specified as follows:

  • Set the Number of users for the current simulation. This user count is directly proportional to a number of brokers in the current simulation.
int num_user = 1; // number of cloud users
Calendar calendar = Calendar.getInstance();
boolean trace_flag = false; 
  • Initialize the simulation, provided with the current time, number of users and trace flag.
CloudSim.init(num_user, calendar, trace_flag);
  • Create a Datacenter.
Datacenter datacenter0 = createDatacenter("Datacenter_0");

where the createDatacenter() method itself initializes the various datacenter characteristics along with the host list. This is the most important entity without this there is no way the simulation of hosting the virtual machine is applicable.

private static Datacenter createDatacenter(String name) 
{
	List<Host> hostList = new ArrayList<Host>();
	List<Pe> peList = new ArrayList<Pe>();
	int mips = 1000;
	peList.add(new Pe(0, new PeProvisionerSimple(mips))); 
	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)
              		)
		); 
	String arch = "x86"; 
	String os = "Linux"; 
	String vmm = "Xen";
	double time_zone = 10.0; 
	double cost = 3.0; 
	double costPerMem = 0.05; 
	double costPerStorage = 0.001; 	
        double costPerBw = 0.0; 
	LinkedList<Storage> storageList = new LinkedList<Storage>();
	DatacenterCharacteristics characteristics = new 
                    DatacenterCharacteristics(arch, os, vmm, hostList, 
                                              time_zone, cost, costPerMem,
                 				costPerStorage, costPerBw);
	Datacenter datacenter = null;
	try {
		datacenter = new Datacenter(name, characteristics, new 
                                VmAllocationPolicySimple(hostList), 
                                  storageList, 0);
	} catch (Exception e) {
		e.printStackTrace();
         	}
	return datacenter;
}
  • Create a Datacenter broker.
DatacenterBroker broker = createBroker();
int brokerId = broker.getId();

Where the createBroker() method initializes the entity object from DatacenterBroker class

private static DatacenterBroker createBroker() 
{
	DatacenterBroker broker = null;
	try {
		broker = new DatacenterBroker("Broker");
	} catch (Exception e) {
		e.printStackTrace();
		return null;
	}
	return broker;
}
  • Create a Virtual Machine(s).
vmlist = new ArrayList<Vm>();
int vmid = 0;
int mips = 1000;
long size = 10000;
int ram = 512;
long bw = 1000;
int pesNumber = 1;
String vmm = "Xen";

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

vmlist.add(vm);
  • Submit Virtual Machine to Datacenter broker.
broker.submitVmList(vmlist);
  • Create Cloudlet(s) by specifying their characteristics.
cloudletList = new ArrayList<Cloudlet>();

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);

cloudletList.add(cloudlet);	
  • Submit Cloudlets to Datacenter broker.
broker.submitCloudletList(cloudletList);
  • Send call to Start Simulation.
CloudSim.startSimulation();
  • Once no more event to execute, send the call to Stop Simulation.
CloudSim.stopSimulation();
  • Finally, print the final status of the Simulation.
List<Cloudlet> newList = broker.getCloudletReceivedList();
printCloudletList(newList);

Where printCloudletList() method formats the output to correctly display it on the console.

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()
				     + indent + indent + 
                                     dft.format(cloudlet.getActualCPUTime()) 
                                     + indent + indent + 
                                     dft.format(cloudlet.getExecStartTime())
				     + indent + indent + 
                                     dft.format(cloudlet.getFinishTime()));
		}
	}
}

Once you Run the example the output for cloudsimExample1.java will be displayed like:

CloudsimExample1.java console output
CloudsimExample1.java console output

Also, the following video tutorial contains a detailed about cloudsimexample1.java and helps you to understand CloudsimExample1.java simulation workflow

Learn More

You may subscribe to an online self-paced course named Learn Basics of Cloudsim, The content for this course which will be updated weekly till August 2021. 

Reference link to study material:

  1. http://www.buyya.com/papers/CloudSim2010.pdf.
  2. http://www.cloudbus.org/papers/CloudSim-HPCS2009.pdf.

CloudSim Setup using Eclipse

“How to install Cloudsim?” or “How to setup Cloudsim?” is the first question that comes to your mind when you come to know about it. And, when you look at the various links and forums, Does it looks a bit tricky?

DO NOT WORRY, the Cloudsim simulation toolkit setup or you can say the installation of cloudsim is very easy. This Cloudsim tutorial is going to take through the steps by step journey.

Now before you start to setup CloudSim, following resources must be Installed/downloaded on the local system

Cloudsim simulation toolkit setup is easy. Before you start to setup CloudSim, following resources must be Installed/downloaded on the local system

  • Java Development Kit(JDK): As the Cloudsim simulation toolkit is a class library written in the Java programming language, therefore, the latest version of Java(JDK) should be installed on your machine, which can be downloaded from Oracles Java portal. For assistance in the installation process, detailed documentation is provided by Oracle itself and you may follow the installation instructions
  • Eclipse IDE for Java developers: As per your current installed operating system(Linux/Windows). Before you download to make sure to check if 32-bit or 64-bit version is applicable to your Computer machine. Link for Eclipse Kepler version is available at the following link
  • Download CloudSim source code: To date, various versions of CloudSim are released the latest version is 5.0, which is based on a container-based engine. Whereas to keep the setup simple for beginners we will be setting up the most used version i.e. 3.0.3, which can be directly downloaded by clicking on any of the following: Click for Windows or click for Linux.
  • One external requirement of Cloudsim i.e. common jar package of math-related functions is to be downloaded from the Apache website or you may directly download by clicking here.
  • Unzip Eclipse, Cloudsim and Common Math libraries to some common folder.
Note: Installation steps are almost similar for Windows as well as Linux computer system. 

Let’s Get Started to answer “How to install Cloudsim?”

First of all, navigate to the folder where you have unzipped the eclipse folder and open Eclipse.exe

Step1

Now within Eclipse window navigate the menu: File -> New -> Project, to open the new project wizard

Step2

A ‘New Project‘ wizard should open. There are a number of options displayed and you have to find & select the ‘Java Project‘ option, once done click ‘Next

Step3

Now a detailed new project window will open, here you will provide the project name and the path of CloudSim project source code, which will be done as follows:

  • Project Name: CloudSim.
Step4
  • Unselect the ‘Use default location’ option and then click on ‘Browse’ to open the path where you have unzipped the Cloudsim project and finally click Next to set project settings.
Step5

Make sure you navigate the path till you can see the bin, docs, examples etc folder in the navigation plane.

Step 6

Once done finally, click ‘Next’ to go to the next step i.e. setting up of project settings

Step7

Now open ‘Libraries’ tab and if you do not find commons-math3-3.x.jar (here ‘x’ means the minor version release of the library which could be 2 or greater) in the list then simply click on Add External Jar’ (commons-math3-3.x.jar will be included in the project from this step)

Step 8

Once you have clicked on ‘Add External JAR’s‘ Open the path where you have unzipped the commons-math binaries and select ‘Commons-math3-3.x.jar’ and click on open.

Step9

Ensure external jar that you opened in the previous step is displayed in the list and then click on ‘Finish’ (your system may take 2-3 minutes to configure the project)

Step8

Once the project is configured you can open the ‘Project Explorerand start exploring the Cloudsim project. Also for the first time eclipse automatically start building the workspace for newly configured Cloudsim project, which may take some time depending on the configuration of the computer system.

Following is the final screen which you will see after Cloudsim is configured.

Step 11

Now just to check you within the ‘Project Explorer‘, you should navigate to the ‘examples‘ folder, then expand the package ‘org.cloudbus.cloudsim.examples‘ and double click to open the ‘CloudsimExample1.java‘.

Step 12 1
Step13

Now navigate to the Eclipse menu ‘Run -> Run‘ or directly use a keyboard shortcut ‘Ctrl + F11’ to execute the ‘CloudsimExample1.java‘.

Step14

if it is successfully executed it should be displaying the following type to output in the console window of the Eclipse IDE.

Step15

If Yes then Congratulations!! Now you have successfully setup/Installed the CloudSim Simulation Toolkit on your computer machine and you are ready to start with the experimentation for your further research work. For more insight into the class hierarchy, you may refer to “CloudSim Simulation Toolkit: An Introduction“. Also, You may subscribe to an online self-paced course named Learn Basics of Cloudsim, The content for this course which will be updated weekly till August 2021. Click here to get the applicable discount coupon codes.

Did you encounter an error during the setup of cloudsim?

If you have encountered some error then the eclipse may look like this:

Most of the times, the type of error that you may encounter during setting up of the cloudsim in eclipse should be stating either:
“Syntax error, parameterized types are only available if source level is 1.5 or greater.”

Cloudsim Setup Error Type 1

OR

“Syntax error ‘for each’ statements are only available if source level is 1.5 or greater.”

Cloudsim Setup Error Type 2

These errors occur due to two reasons:
Case 1: The version of Java installed on your computer system is older than 1.5
Case 2: Your default java environment for the eclipse project not set to the latest java version which is available on your computer system.

For Case 1, you have to download and install the latest java version from Oracle/Java website.

For Case 2, you have to do some modifications in the eclipse project, and for this, you should follow these steps:

  1. In the eclipse IDE menu, click on ‘Project’ and from the dropped menu list click on ‘Properties’ to open a project properties window.
  2. On the project properties window, from the list available on left select ‘Java Compiler’, this will display the compiler options.
  3. Now, click on the ‘Enable Project Specific Settings’ checkbox, which further enables the options provided just below the checkbox.
  4. Now, under JDK compliance heading change the ‘Compiler Compliance Level’ to the highest number available on the list.
  5. Also, make sure “Use default compliance settings” should be in the checked state.
  6. Now, click on the “Apply and Close” button. Now a popup alert will be displayed asking for the confirmation to apply the settings. Click ‘Yes’.

Now you will notice that the rebuild process for the project will get started and to confirm the error is resolved or not. You may check the error log window or run any example class available in org.cloudbus.cloudsim.examples namespace.

You may also follow the detailed step by step demo to “Configure CloudSim using Eclipse IDE

Hope this article helped you answer your big question on “How to install Cloudsim using Eclipse?

In case you find this article suitable for your work or you find any difficulty in following the method mentioned above you may feel free to share in the comments section.