fork(4) download
  1. import java.text.DecimalFormat;
  2. import java.util.ArrayList;
  3. import java.util.Calendar;
  4. import java.util.LinkedList;
  5. import java.util.List;
  6.  
  7. import org.cloudbus.cloudsim.Cloudlet;
  8. import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
  9. import org.cloudbus.cloudsim.Datacenter;
  10. import org.cloudbus.cloudsim.DatacenterBroker;
  11. import org.cloudbus.cloudsim.DatacenterCharacteristics;
  12. import org.cloudbus.cloudsim.Host;
  13. import org.cloudbus.cloudsim.Log;
  14. import org.cloudbus.cloudsim.Pe;
  15. import org.cloudbus.cloudsim.Storage;
  16. import org.cloudbus.cloudsim.UtilizationModel;
  17. import org.cloudbus.cloudsim.UtilizationModelFull;
  18. import org.cloudbus.cloudsim.Vm;
  19. import org.cloudbus.cloudsim.VmAllocationPolicySimple;
  20. import org.cloudbus.cloudsim.VmSchedulerTimeShared;
  21. import org.cloudbus.cloudsim.core.CloudSim;
  22. import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
  23. import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
  24. import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
  25.  
  26. /**
  27.  * A simple example showing how to create a data center with one host and run one cloudlet on it.
  28.  */
  29. public class CloudSimExample1 {
  30. /** The cloudlet list. */
  31. private static List<Cloudlet> cloudletList;
  32. /** The vmlist. */
  33. private static List<Vm> vmlist;
  34.  
  35. /**
  36. * Creates main() to run this example.
  37. *
  38. * @param args the args
  39. */
  40. @SuppressWarnings("unused")
  41. public static void main(String[] args) {
  42. Log.printLine("Starting CloudSimExample1...");
  43.  
  44. try {
  45. // First step: Initialize the CloudSim package. It should be called before creating any entities.
  46. int num_user = 1; // number of cloud users
  47. Calendar calendar = Calendar.getInstance(); // Calendar whose fields have been initialized with the current date and time.
  48. boolean trace_flag = false; // trace events
  49.  
  50. /* Comment Start - Dinesh Bhagwat
  51. * Initialize the CloudSim library.
  52. * init() invokes initCommonVariable() which in turn calls initialize() (all these 3 methods are defined in CloudSim.java).
  53. * initialize() creates two collections - an ArrayList of SimEntity Objects (named entities which denote the simulation entities) and
  54. * a LinkedHashMap (named entitiesByName which denote the LinkedHashMap of the same simulation entities), with name of every SimEntity as the key.
  55. * initialize() creates two queues - a Queue of SimEvents (future) and another Queue of SimEvents (deferred).
  56. * initialize() creates a HashMap of of Predicates (with integers as keys) - these predicates are used to select a particular event from the deferred queue.
  57. * initialize() sets the simulation clock to 0 and running (a boolean flag) to false.
  58. * Once initialize() returns (note that we are in method initCommonVariable() now), a CloudSimShutDown (which is derived from SimEntity) instance is created
  59. * (with numuser as 1, its name as CloudSimShutDown, id as -1, and state as RUNNABLE). Then this new entity is added to the simulation
  60. * 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.
  61. * the shutdownId (whose default value was -1) is 0
  62. * Once initCommonVariable() returns (note that we are in method init() now), a CloudInformationService (which is also derived from SimEntity) instance is created
  63. * (with its name as CloudInformatinService, id as -1, and state as RUNNABLE). Then this new entity is also added to the simulation.
  64. * 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.
  65. * The two collections - entities and entitiesByName are updated with this SimEntity.
  66. * the cisId(whose default value is -1) is 1
  67. * Comment End - Dinesh Bhagwat
  68. */
  69. CloudSim.init(num_user, calendar, trace_flag);
  70.  
  71. // Second step: Create Datacenters
  72. // Datacenters are the resource providers in CloudSim. We need at
  73. // list one of them to run a CloudSim simulation
  74. Datacenter datacenter0 = createDatacenter("Datacenter_0");
  75.  
  76. // Third step: Create Broker
  77. DatacenterBroker broker = createBroker();
  78. int brokerId = broker.getId();
  79.  
  80. // Fourth step: Create one virtual machine
  81. vmlist = new ArrayList<Vm>();
  82.  
  83. // VM description
  84. int vmid = 0;
  85. int mips = 1000;
  86. long size = 10000; // image size (MB)
  87. int ram = 512; // vm memory (MB)
  88. long bw = 1000;
  89. int pesNumber = 1; // number of cpus
  90. String vmm = "Xen"; // VMM name
  91.  
  92. // create VM
  93. Vm vm = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
  94.  
  95. // add the VM to the vmList
  96. vmlist.add(vm);
  97.  
  98. // submit vm list to the broker
  99. broker.submitVmList(vmlist);
  100.  
  101. // Fifth step: Create one Cloudlet
  102. cloudletList = new ArrayList<Cloudlet>();
  103.  
  104. // Cloudlet properties
  105. int id = 0;
  106. long length = 400000;
  107. long fileSize = 300;
  108. long outputSize = 300;
  109. UtilizationModel utilizationModel = new UtilizationModelFull();
  110.  
  111. Cloudlet cloudlet =
  112. new Cloudlet(id, length, pesNumber, fileSize,
  113. outputSize, utilizationModel, utilizationModel,
  114. utilizationModel);
  115. cloudlet.setUserId(brokerId);
  116. cloudlet.setVmId(vmid);
  117.  
  118. // add the cloudlet to the list
  119. cloudletList.add(cloudlet);
  120.  
  121. // submit cloudlet list to the broker
  122. broker.submitCloudletList(cloudletList);
  123.  
  124. // Sixth step: Starts the simulation
  125. CloudSim.startSimulation();
  126.  
  127. CloudSim.stopSimulation();
  128.  
  129. //Final step: Print results when simulation is over
  130. List<Cloudlet> newList = broker.getCloudletReceivedList();
  131. printCloudletList(newList);
  132.  
  133. Log.printLine("CloudSimExample1 finished!");
  134. } catch (Exception e) {
  135. e.printStackTrace();
  136. Log.printLine("Unwanted errors happen");
  137. }
  138. }
  139.  
  140. /**
  141. * Creates the datacenter.
  142. *
  143. * @param name the name
  144. *
  145. * @return the datacenter
  146. */
  147. private static Datacenter createDatacenter(String name) {
  148.  
  149. // Here are the steps needed to create a PowerDatacenter:
  150. // 1. We need to create a list to store
  151. // our machine
  152. List<Host> hostList = new ArrayList<Host>();
  153.  
  154. // 2. A Machine contains one or more PEs or CPUs/Cores.
  155. // In this example, it will have only one core.
  156. List<Pe> peList = new ArrayList<Pe>();
  157.  
  158. int mips = 1000;
  159.  
  160. // 3. Create PEs and add these into a list.
  161. peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating
  162.  
  163. // 4. Create Host with its id and list of PEs and add them to the list
  164. // of machines
  165. int hostId = 0;
  166. int ram = 2048; // host memory (MB)
  167. long storage = 1000000; // host storage
  168. int bw = 10000;
  169.  
  170. hostList.add(
  171. new Host(
  172. hostId,
  173. new RamProvisionerSimple(ram),
  174. new BwProvisionerSimple(bw),
  175. storage,
  176. peList,
  177. new VmSchedulerTimeShared(peList)
  178. )
  179. ); // This is our machine
  180.  
  181. // 5. Create a DatacenterCharacteristics object that stores the
  182. // properties of a data center: architecture, OS, list of
  183. // Machines, allocation policy: time- or space-shared, time zone
  184. // and its price (G$/Pe time unit).
  185. String arch = "x86"; // system architecture
  186. String os = "Linux"; // operating system
  187. String vmm = "Xen";
  188. double time_zone = 10.0; // time zone this resource located
  189. double cost = 3.0; // the cost of using processing in this resource
  190. double costPerMem = 0.05; // the cost of using memory in this resource
  191. double costPerStorage = 0.001; // the cost of using storage in this
  192. // resource
  193. double costPerBw = 0.0; // the cost of using bw in this resource
  194. LinkedList<Storage> storageList = new LinkedList<Storage>(); // we are not adding SAN
  195. // devices by now
  196.  
  197. DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
  198. arch, os, vmm, hostList, time_zone, cost, costPerMem,
  199. costPerStorage, costPerBw);
  200.  
  201. // 6. Finally, we need to create a PowerDatacenter object.
  202. Datacenter datacenter = null;
  203. try {
  204. datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0);
  205. } catch (Exception e) {
  206. e.printStackTrace();
  207. }
  208.  
  209. return datacenter;
  210. }
  211.  
  212. // We strongly encourage users to develop their own broker policies, to
  213. // submit vms and cloudlets according
  214. // to the specific rules of the simulated scenario
  215. /**
  216. * Creates the broker.
  217. *
  218. * @return the datacenter broker
  219. */
  220. private static DatacenterBroker createBroker() {
  221. DatacenterBroker broker = null;
  222. try {
  223. broker = new DatacenterBroker("Broker");
  224. } catch (Exception e) {
  225. e.printStackTrace();
  226. return null;
  227. }
  228. return broker;
  229. }
  230.  
  231. /**
  232. * Prints the Cloudlet objects.
  233. *
  234. * @param list list of Cloudlets
  235. */
  236. private static void printCloudletList(List<Cloudlet> list) {
  237. int size = list.size();
  238. Cloudlet cloudlet;
  239.  
  240. String indent = " ";
  241. Log.printLine();
  242. Log.printLine("========== OUTPUT ==========");
  243. Log.printLine("Cloudlet ID" + indent + "STATUS" + indent
  244. + "Data center ID" + indent + "VM ID" + indent + "Time" + indent
  245. + "Start Time" + indent + "Finish Time");
  246.  
  247. DecimalFormat dft = new DecimalFormat("###.##");
  248. for (int i = 0; i < size; i++) {
  249. cloudlet = list.get(i);
  250. Log.print(indent + cloudlet.getCloudletId() + indent + indent);
  251.  
  252. if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) {
  253. Log.print("SUCCESS");
  254.  
  255. Log.printLine(indent + indent + cloudlet.getResourceId()
  256. + indent + indent + indent + cloudlet.getVmId()
  257. + indent + indent
  258. + dft.format(cloudlet.getActualCPUTime()) + indent
  259. + indent + dft.format(cloudlet.getExecStartTime())
  260. + indent + indent
  261. + dft.format(cloudlet.getFinishTime()));
  262. }
  263. }
  264. }
  265. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:29: error: class CloudSimExample1 is public, should be declared in a file named CloudSimExample1.java
public class CloudSimExample1 {
       ^
Main.java:7: error: package org.cloudbus.cloudsim does not exist
import org.cloudbus.cloudsim.Cloudlet;
                            ^
Main.java:8: error: package org.cloudbus.cloudsim does not exist
import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
                            ^
Main.java:9: error: package org.cloudbus.cloudsim does not exist
import org.cloudbus.cloudsim.Datacenter;
                            ^
Main.java:10: error: package org.cloudbus.cloudsim does not exist
import org.cloudbus.cloudsim.DatacenterBroker;
                            ^
Main.java:11: error: package org.cloudbus.cloudsim does not exist
import org.cloudbus.cloudsim.DatacenterCharacteristics;
                            ^
Main.java:12: error: package org.cloudbus.cloudsim does not exist
import org.cloudbus.cloudsim.Host;
                            ^
Main.java:13: error: package org.cloudbus.cloudsim does not exist
import org.cloudbus.cloudsim.Log;
                            ^
Main.java:14: error: package org.cloudbus.cloudsim does not exist
import org.cloudbus.cloudsim.Pe;
                            ^
Main.java:15: error: package org.cloudbus.cloudsim does not exist
import org.cloudbus.cloudsim.Storage;
                            ^
Main.java:16: error: package org.cloudbus.cloudsim does not exist
import org.cloudbus.cloudsim.UtilizationModel;
                            ^
Main.java:17: error: package org.cloudbus.cloudsim does not exist
import org.cloudbus.cloudsim.UtilizationModelFull;
                            ^
Main.java:18: error: package org.cloudbus.cloudsim does not exist
import org.cloudbus.cloudsim.Vm;
                            ^
Main.java:19: error: package org.cloudbus.cloudsim does not exist
import org.cloudbus.cloudsim.VmAllocationPolicySimple;
                            ^
Main.java:20: error: package org.cloudbus.cloudsim does not exist
import org.cloudbus.cloudsim.VmSchedulerTimeShared;
                            ^
Main.java:21: error: package org.cloudbus.cloudsim.core does not exist
import org.cloudbus.cloudsim.core.CloudSim;
                                 ^
Main.java:22: error: package org.cloudbus.cloudsim.provisioners does not exist
import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
                                         ^
Main.java:23: error: package org.cloudbus.cloudsim.provisioners does not exist
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
                                         ^
Main.java:24: error: package org.cloudbus.cloudsim.provisioners does not exist
import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
                                         ^
Main.java:31: error: cannot find symbol
	private static List<Cloudlet> cloudletList;
	                    ^
  symbol:   class Cloudlet
  location: class CloudSimExample1
Main.java:33: error: cannot find symbol
	private static List<Vm> vmlist;
	                    ^
  symbol:   class Vm
  location: class CloudSimExample1
Main.java:147: error: cannot find symbol
	private static Datacenter createDatacenter(String name) {
	               ^
  symbol:   class Datacenter
  location: class CloudSimExample1
Main.java:220: error: cannot find symbol
	private static DatacenterBroker createBroker() {
	               ^
  symbol:   class DatacenterBroker
  location: class CloudSimExample1
Main.java:236: error: cannot find symbol
	private static void printCloudletList(List<Cloudlet> list) {
	                                           ^
  symbol:   class Cloudlet
  location: class CloudSimExample1
Main.java:42: error: cannot find symbol
		Log.printLine("Starting CloudSimExample1...");
		^
  symbol:   variable Log
  location: class CloudSimExample1
Main.java:69: error: cannot find symbol
			CloudSim.init(num_user, calendar, trace_flag);
			^
  symbol:   variable CloudSim
  location: class CloudSimExample1
Main.java:74: error: cannot find symbol
			Datacenter datacenter0 = createDatacenter("Datacenter_0");
			^
  symbol:   class Datacenter
  location: class CloudSimExample1
Main.java:77: error: cannot find symbol
			DatacenterBroker broker = createBroker();
			^
  symbol:   class DatacenterBroker
  location: class CloudSimExample1
Main.java:81: error: cannot find symbol
			vmlist = new ArrayList<Vm>();
			                       ^
  symbol:   class Vm
  location: class CloudSimExample1
Main.java:93: error: cannot find symbol
			Vm vm = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
			^
  symbol:   class Vm
  location: class CloudSimExample1
Main.java:93: error: cannot find symbol
			Vm vm = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
			            ^
  symbol:   class Vm
  location: class CloudSimExample1
Main.java:93: error: cannot find symbol
			Vm vm = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
			                                                                        ^
  symbol:   class CloudletSchedulerTimeShared
  location: class CloudSimExample1
Main.java:102: error: cannot find symbol
			cloudletList = new ArrayList<Cloudlet>();
			                             ^
  symbol:   class Cloudlet
  location: class CloudSimExample1
Main.java:109: error: cannot find symbol
			UtilizationModel utilizationModel = new UtilizationModelFull();
			^
  symbol:   class UtilizationModel
  location: class CloudSimExample1
Main.java:109: error: cannot find symbol
			UtilizationModel utilizationModel = new UtilizationModelFull();
			                                        ^
  symbol:   class UtilizationModelFull
  location: class CloudSimExample1
Main.java:111: error: cannot find symbol
			Cloudlet cloudlet = 
			^
  symbol:   class Cloudlet
  location: class CloudSimExample1
Main.java:112: error: cannot find symbol
                                new Cloudlet(id, length, pesNumber, fileSize, 
                                    ^
  symbol:   class Cloudlet
  location: class CloudSimExample1
Main.java:125: error: cannot find symbol
			CloudSim.startSimulation();
			^
  symbol:   variable CloudSim
  location: class CloudSimExample1
Main.java:127: error: cannot find symbol
			CloudSim.stopSimulation();
			^
  symbol:   variable CloudSim
  location: class CloudSimExample1
Main.java:130: error: cannot find symbol
			List<Cloudlet> newList = broker.getCloudletReceivedList();
			     ^
  symbol:   class Cloudlet
  location: class CloudSimExample1
Main.java:133: error: cannot find symbol
			Log.printLine("CloudSimExample1 finished!");
			^
  symbol:   variable Log
  location: class CloudSimExample1
Main.java:136: error: cannot find symbol
			Log.printLine("Unwanted errors happen");
			^
  symbol:   variable Log
  location: class CloudSimExample1
Main.java:152: error: cannot find symbol
		List<Host> hostList = new ArrayList<Host>();
		     ^
  symbol:   class Host
  location: class CloudSimExample1
Main.java:152: error: cannot find symbol
		List<Host> hostList = new ArrayList<Host>();
		                                    ^
  symbol:   class Host
  location: class CloudSimExample1
Main.java:156: error: cannot find symbol
		List<Pe> peList = new ArrayList<Pe>();
		     ^
  symbol:   class Pe
  location: class CloudSimExample1
Main.java:156: error: cannot find symbol
		List<Pe> peList = new ArrayList<Pe>();
		                                ^
  symbol:   class Pe
  location: class CloudSimExample1
Main.java:161: error: cannot find symbol
		peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating
		               ^
  symbol:   class Pe
  location: class CloudSimExample1
Main.java:161: error: cannot find symbol
		peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating
		                         ^
  symbol:   class PeProvisionerSimple
  location: class CloudSimExample1
Main.java:171: error: cannot find symbol
			new Host(
			    ^
  symbol:   class Host
  location: class CloudSimExample1
Main.java:173: error: cannot find symbol
				new RamProvisionerSimple(ram),
				    ^
  symbol:   class RamProvisionerSimple
  location: class CloudSimExample1
Main.java:174: error: cannot find symbol
				new BwProvisionerSimple(bw),
				    ^
  symbol:   class BwProvisionerSimple
  location: class CloudSimExample1
Main.java:177: error: cannot find symbol
				new VmSchedulerTimeShared(peList)
				    ^
  symbol:   class VmSchedulerTimeShared
  location: class CloudSimExample1
Main.java:194: error: cannot find symbol
		LinkedList<Storage> storageList = new LinkedList<Storage>(); // we are not adding SAN
		           ^
  symbol:   class Storage
  location: class CloudSimExample1
Main.java:194: error: cannot find symbol
		LinkedList<Storage> storageList = new LinkedList<Storage>(); // we are not adding SAN
		                                                 ^
  symbol:   class Storage
  location: class CloudSimExample1
Main.java:197: error: cannot find symbol
		DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
		^
  symbol:   class DatacenterCharacteristics
  location: class CloudSimExample1
Main.java:197: error: cannot find symbol
		DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
		                                                ^
  symbol:   class DatacenterCharacteristics
  location: class CloudSimExample1
Main.java:202: error: cannot find symbol
		Datacenter datacenter = null;
		^
  symbol:   class Datacenter
  location: class CloudSimExample1
Main.java:204: error: cannot find symbol
			datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0);
			                 ^
  symbol:   class Datacenter
  location: class CloudSimExample1
Main.java:204: error: cannot find symbol
			datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0);
			                                                       ^
  symbol:   class VmAllocationPolicySimple
  location: class CloudSimExample1
Main.java:221: error: cannot find symbol
		DatacenterBroker broker = null;
		^
  symbol:   class DatacenterBroker
  location: class CloudSimExample1
Main.java:223: error: cannot find symbol
			broker = new DatacenterBroker("Broker");
			             ^
  symbol:   class DatacenterBroker
  location: class CloudSimExample1
Main.java:238: error: cannot find symbol
		Cloudlet cloudlet;
		^
  symbol:   class Cloudlet
  location: class CloudSimExample1
Main.java:241: error: cannot find symbol
		Log.printLine();
		^
  symbol:   variable Log
  location: class CloudSimExample1
Main.java:242: error: cannot find symbol
		Log.printLine("========== OUTPUT ==========");
		^
  symbol:   variable Log
  location: class CloudSimExample1
Main.java:243: error: cannot find symbol
		Log.printLine("Cloudlet ID" + indent + "STATUS" + indent
		^
  symbol:   variable Log
  location: class CloudSimExample1
Main.java:250: error: cannot find symbol
			Log.print(indent + cloudlet.getCloudletId() + indent + indent);
			^
  symbol:   variable Log
  location: class CloudSimExample1
Main.java:252: error: cannot find symbol
			if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) {
			                                    ^
  symbol:   variable Cloudlet
  location: class CloudSimExample1
Main.java:253: error: cannot find symbol
				Log.print("SUCCESS");
				^
  symbol:   variable Log
  location: class CloudSimExample1
Main.java:255: error: cannot find symbol
				Log.printLine(indent + indent + cloudlet.getResourceId()
				^
  symbol:   variable Log
  location: class CloudSimExample1
69 errors
stdout
Standard output is empty