/** * Process a cloudlet (job) return event. * * @param ev a SimEvent object * @pre ev != $null * @post $none */ @Override protected void processCloudletReturn(SimEvent ev) { Cloudlet cloudlet = (Cloudlet) ev.getData(); Job job = (Job) cloudlet; /** Generate a failure if failure rate is not zeros. */ FailureGenerator.generate(job); getCloudletReceivedList().add(cloudlet); getCloudletSubmittedList().remove(cloudlet); CondorVM vm = (CondorVM) getVmsCreatedList().get(cloudlet.getVmId()); // so that this resource is released vm.setState(WorkflowSimTags.VM_STATUS_IDLE); double delay = 0.0; if (Parameters.getOverheadParams().getPostDelay() != null) { delay = Parameters.getOverheadParams().getPostDelay(job); } schedule(this.workflowEngineId, delay, CloudSimTags.CLOUDLET_RETURN, cloudlet); cloudletsSubmitted--; // not really update right now, should wait 1 s until many jobs have returned schedule(this.getId(), 0.0, WorkflowSimTags.CLOUDLET_UPDATE); }
/** * Creates instances of CloudSim's Cloudlet class from a customer's utilization profile. * * @param ugr the utilization profile. * @param brokerId the id of the broker that owns the cloudlets. * @param numOfVms the number of virtual machines. * @return a list of Cloudlet instances. * @since 1.0 */ static List<Cloudlet> createCloudlets(UtilizationProfile ugr, int brokerId, long numOfVms) throws IOException, ServiceDeniedException { List<Cloudlet> list = new ArrayList<Cloudlet>(); for (int i = 0; i < numOfVms; i++) { Optional<UtilizationModel> cpu = UTILIZATION_MODEL.getExtensionInstanceByName(ugr.getUtilizationModelCpuAlias()); if (!cpu.isPresent()) { Dialog.showErrorMessage( null, format( "Error on loading the CPU utilization model [%s]", ugr.getUtilizationModelCpuAlias())); return null; } Optional<UtilizationModel> ram = UTILIZATION_MODEL.getExtensionInstanceByName(ugr.getUtilizationModelRamAlias()); if (!ram.isPresent()) { Dialog.showErrorMessage( null, format( "Error on loading the RAM utilization model [%s]", ugr.getUtilizationModelRamAlias())); return null; } Optional<UtilizationModel> bw = UTILIZATION_MODEL.getExtensionInstanceByName(ugr.getUtilizationModelBwAlias()); if (!bw.isPresent()) { Dialog.showErrorMessage( null, format( "Error on loading the bandwidth utilization model [%s]", ugr.getUtilizationModelBwAlias())); return null; } Cloudlet cloudlet = new Cloudlet( i, (long) ((long) ugr.getLength() * RandomNumberGenerator.getRandomNumbers(1).get(0)), ugr.getCloudletsPesNumber(), ugr.getFileSize(), ugr.getOutputSize(), cpu.get(), ram.get(), bw.get()); cloudlet.setUserId(brokerId); cloudlet.setVmId(i); list.add(cloudlet); } return list; }
/** * Update a cloudlet (job) * * @param ev a simEvent object */ protected void processCloudletUpdate(SimEvent ev) { BaseSchedulingAlgorithm scheduler = getScheduler(Parameters.getSchedulingAlgorithm()); scheduler.setCloudletList(getCloudletList()); scheduler.setVmList(getVmsCreatedList()); try { scheduler.run(); } catch (Exception e) { Log.printLine("Error in configuring scheduler_method"); e.printStackTrace(); } List<Cloudlet> scheduledList = scheduler.getScheduledList(); for (Cloudlet cloudlet : scheduledList) { int vmId = cloudlet.getVmId(); double delay = 0.0; if (Parameters.getOverheadParams().getQueueDelay() != null) { delay = Parameters.getOverheadParams().getQueueDelay(cloudlet); } schedule(getVmsToDatacentersMap().get(vmId), delay, CloudSimTags.CLOUDLET_SUBMIT, cloudlet); } getCloudletList().removeAll(scheduledList); getCloudletSubmittedList().addAll(scheduledList); cloudletsSubmitted += scheduledList.size(); }
@Override public void run() { int size = getCloudletList().size(); for (int i = 0; i < size; i++) { Cloudlet cloudlet = (Cloudlet) getCloudletList().get(i); int vmSize = getVmList().size(); CondorVM closestVm = null; // (CondorVM)getVmList().get(0); double minTime = Double.MAX_VALUE; for (int j = 0; j < vmSize; j++) { CondorVM vm = (CondorVM) getVmList().get(j); if (vm.getState() == WorkflowSimTags.VM_STATUS_IDLE) { Job job = (Job) cloudlet; double time = dataTransferTime(job.getFileList(), cloudlet, vm.getId()); if (time < minTime) { minTime = time; closestVm = vm; } } } if (closestVm != null) { closestVm.setState(WorkflowSimTags.VM_STATUS_BUSY); cloudlet.setVmId(closestVm.getId()); getScheduledList().add(cloudlet); } } }
/** * 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() + indent + indent + dft.format(cloudlet.getActualCPUTime()) + indent + indent + dft.format(cloudlet.getExecStartTime()) + indent + indent + dft.format(cloudlet.getFinishTime())); } } }
/** * Creates the cloudlet list. * * @param brokerId the broker id * @param cloudletsNumber the cloudlets number * @return the list< cloudlet> */ public static List<Cloudlet> createCloudletList(int brokerId, int cloudletsNumber) { List<Cloudlet> list = new ArrayList<Cloudlet>(); long fileSize = 300; long outputSize = 300; long seed = RandomConstants.CLOUDLET_UTILIZATION_SEED; UtilizationModel utilizationModelNull = new UtilizationModelNull(); for (int i = 0; i < cloudletsNumber; i++) { Cloudlet cloudlet = null; if (seed == -1) { cloudlet = new Cloudlet( i, Constants.CLOUDLET_LENGTH, Constants.CLOUDLET_PES, fileSize, outputSize, new UtilizationModelStochastic(), utilizationModelNull, utilizationModelNull); } else { cloudlet = new Cloudlet( i, Constants.CLOUDLET_LENGTH, Constants.CLOUDLET_PES, fileSize, outputSize, new UtilizationModelStochastic(seed * i), utilizationModelNull, utilizationModelNull); } cloudlet.setUserId(brokerId); cloudlet.setVmId(i); list.add(cloudlet); } return list; }
@Override public void run() { // Round Robin for (Iterator it = getCloudletList().iterator(); it.hasNext(); ) { Cloudlet cloudlet = (Cloudlet) it.next(); boolean stillHasVm = false; for (Iterator itc = getVmList().iterator(); itc.hasNext(); ) { CondorVM vm = (CondorVM) itc.next(); if (vm.getState() == WorkflowSimTags.VM_STATUS_IDLE) { stillHasVm = true; vm.setState(WorkflowSimTags.VM_STATUS_BUSY); cloudlet.setVmId(vm.getId()); this.scheduledList.add(cloudlet); break; } } // no vm available if (!stillHasVm) { break; } } }
/** Creates main() to run this example */ public static void main(String[] args) { Log.printLine("Starting CloudSimExample2..."); try { // First step: Initialize the CloudSim package. It should be called // before creating any entities. int num_user = 8; // number of cloud users Calendar calendar = Calendar.getInstance(); boolean trace_flag = false; // mean trace events // Initialize the CloudSim 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 Datacenter datacenter0 = createDatacenter("Datacenter_0"); Datacenter datacenter1 = createDatacenter("Datacenter_1"); Datacenter datacenter2 = createDatacenter("Datacenter_2"); Datacenter datacenter3 = createDatacenter("Datacenter_3"); // 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; double costpersec = 20.0; 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, costpersec, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared()); costpersec = 28.0; mips = 450; ram = 768; bw = 512; vmid++; Vm vm2 = new Vm( vmid, brokerId, mips, costpersec, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared()); costpersec = 25.0; mips = 580; ram = 256; bw = 768; vmid++; Vm vm3 = new Vm( vmid, brokerId, mips, costpersec, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared()); costpersec = 30.0; mips = 300; ram = 768; bw = 512; vmid++; Vm vm4 = new Vm( vmid, brokerId, mips, costpersec, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared()); costpersec = 22.0; mips = 280; ram = 1000; bw = 128; vmid++; Vm vm5 = new Vm( vmid, brokerId, mips, costpersec, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared()); vmid++; costpersec = 50.0; mips = 220; ram = 128; bw = 128; // Vm vm6 = new Vm(vmid, brokerId, mips,costpersec, pesNumber, ram, bw, // size, vmm, new CloudletSchedulerTimeShared()); // vmid++; // costpersec=22.0; // mips =280; // ram = 2048; // bw = 64; // Vm vm7 = new Vm(vmid, brokerId, mips,costpersec, pesNumber, ram, bw, // size, vmm, new CloudletSchedulerTimeShared()); // vmid++; // Vm vm8 = new Vm(vmid, brokerId, mips,costpersec, pesNumber, ram, bw, size, // vmm, new CloudletSchedulerTimeShared()); // vmid++; // Vm vm9 = new Vm(vmid, brokerId, mips,costpersec, pesNumber, ram, bw, size, // vmm, new CloudletSchedulerTimeShared()); // vmid++; // Vm vm10 = new Vm(vmid, brokerId, mips,costpersec, pesNumber, ram, bw, size, // vmm, new CloudletSchedulerTimeShared()); // vmid++; // Vm vm11 = new Vm(vmid, brokerId, mips,costpersec, pesNumber, ram, bw, size, // vmm, new CloudletSchedulerTimeShared()); // vmid++; // Vm vm12 = new Vm(vmid, brokerId, mips,costpersec, pesNumber, ram, bw, size, // vmm, new CloudletSchedulerTimeShared()); // vmid++; // Vm vm13 = new Vm(vmid, brokerId, mips,costpersec, pesNumber, ram, bw, size, // vmm, new CloudletSchedulerTimeShared()); // vmid++; // Vm vm14 = new Vm(vmid, brokerId, mips,costpersec, pesNumber, ram, bw, size, // vmm, new CloudletSchedulerTimeShared()); // vmid++; // Vm vm15 = new Vm(vmid, brokerId, mips,costpersec, pesNumber, ram, bw, size, // vmm, new CloudletSchedulerTimeShared()); // vmid++; // Vm vm16 = new Vm(vmid, brokerId, mips,costpersec, pesNumber, ram, bw, size, // vmm, new CloudletSchedulerTimeShared()); // add the VMs to the vmList vmlist.add(vm1); vmlist.add(vm2); vmlist.add(vm3); vmlist.add(vm4); vmlist.add(vm5); // vmlist.add(vm6); // vmlist.add(vm7); // vmlist.add(vm9); // vmlist.add(vm10); // vmlist.add(vm11); // vmlist.add(vm12); // vmlist.add(vm13); // vmlist.add(vm14); // vmlist.add(vm15); // vmlist.add(vm16); // submit vm list to the broker broker.submitVmList(vmlist); // Fifth step: Create two Cloudlets cloudletList = new ArrayList<Cloudlet>(); // Cloudlet properties int id = 0; pesNumber = 1; long length = 2500; long fileSize = 300; long outputSize = 450; UtilizationModel utilizationModel = new UtilizationModelFull(); double wt = 1.0; double wm = 0; Cloudlet cloudlet1 = new Cloudlet( wt, wm, id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel); cloudlet1.setUserId(brokerId); id++; pesNumber = 1; length = 2800; fileSize = 600; outputSize = 600; Cloudlet cloudlet2 = new Cloudlet( wt, wm, id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel); cloudlet2.setUserId(brokerId); id++; pesNumber = 1; length = 1250; fileSize = 800; outputSize = 800; Cloudlet cloudlet3 = new Cloudlet( wt, wm, id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel); cloudlet3.setUserId(brokerId); id++; pesNumber = 1; length = 2480; fileSize = 300; outputSize = 300; Cloudlet cloudlet4 = new Cloudlet( wt, wm, id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel); cloudlet4.setUserId(brokerId); id++; pesNumber = 1; length = 7000; fileSize = 500; outputSize = 500; Cloudlet cloudlet5 = new Cloudlet( wt, wm, id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel); cloudlet5.setUserId(brokerId); id++; pesNumber = 1; length = 1500; fileSize = 500; outputSize = 500; Cloudlet cloudlet6 = new Cloudlet( wt, wm, id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel); cloudlet6.setUserId(brokerId); id++; pesNumber = 1; length = 800; fileSize = 500; outputSize = 500; Cloudlet cloudlet7 = new Cloudlet( wt, wm, id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel); cloudlet7.setUserId(brokerId); id++; pesNumber = 1; length = 7500; fileSize = 500; outputSize = 500; Cloudlet cloudlet8 = new Cloudlet( wt, wm, id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel); cloudlet8.setUserId(brokerId); // add the cloudlets to the list cloudletList.add(cloudlet1); cloudletList.add(cloudlet2); cloudletList.add(cloudlet3); cloudletList.add(cloudlet4); cloudletList.add(cloudlet5); cloudletList.add(cloudlet6); cloudletList.add(cloudlet7); cloudletList.add(cloudlet8); // 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(); // Final step: Print results when simulation is over List<Cloudlet> newList = broker.getCloudletReceivedList(); CloudSim.stopSimulation(); printCloudletList(newList); // Print the debt of each user to each datacenter // datacenter0.printDebts(); Log.printLine("CloudSimExample2 finished!"); } catch (Exception e) { e.printStackTrace(); Log.printLine("The simulation has been terminated due to an unexpected error"); } }
/** Creates main() to run this example */ public static void main(String[] args) { Log.printLine("Starting NetworkExample3..."); try { // First step: Initialize the CloudSim package. It should be called // before creating any entities. int num_user = 2; // number of cloud users Calendar calendar = Calendar.getInstance(); boolean trace_flag = false; // mean trace events // Initialize the CloudSim 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 Datacenter datacenter0 = createDatacenter("Datacenter_0"); Datacenter datacenter1 = createDatacenter("Datacenter_1"); // Third step: Create Brokers DatacenterBroker broker1 = createBroker(1); int brokerId1 = broker1.getId(); DatacenterBroker broker2 = createBroker(2); int brokerId2 = broker2.getId(); // Fourth step: Create one virtual machine for each broker/user vmlist1 = new ArrayList<Vm>(); vmlist2 = new ArrayList<Vm>(); // VM description int vmid = 0; long size = 10000; // image size (MB) int mips = 250; int ram = 512; // vm memory (MB) long bw = 1000; int pesNumber = 1; // number of cpus String vmm = "Xen"; // VMM name // create two VMs: the first one belongs to user1 Vm vm1 = new Vm( vmid, brokerId1, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared()); // the second VM: this one belongs to user2 Vm vm2 = new Vm( vmid, brokerId2, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared()); // add the VMs to the vmlists vmlist1.add(vm1); vmlist2.add(vm2); // submit vm list to the broker broker1.submitVmList(vmlist1); broker2.submitVmList(vmlist2); // Fifth step: Create two Cloudlets cloudletList1 = new ArrayList<Cloudlet>(); cloudletList2 = 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(brokerId1); Cloudlet cloudlet2 = new Cloudlet( id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel); cloudlet2.setUserId(brokerId2); // add the cloudlets to the lists: each cloudlet belongs to one user cloudletList1.add(cloudlet1); cloudletList2.add(cloudlet2); // submit cloudlet list to the brokers broker1.submitCloudletList(cloudletList1); broker2.submitCloudletList(cloudletList2); // Sixth step: configure network // load the network topology file NetworkTopology.buildNetworkTopology("topology.brite"); // maps CloudSim entities to BRITE entities // Datacenter0 will correspond to BRITE node 0 int briteNode = 0; NetworkTopology.mapNode(datacenter0.getId(), briteNode); // Datacenter1 will correspond to BRITE node 2 briteNode = 2; NetworkTopology.mapNode(datacenter1.getId(), briteNode); // Broker1 will correspond to BRITE node 3 briteNode = 3; NetworkTopology.mapNode(broker1.getId(), briteNode); // Broker2 will correspond to BRITE node 4 briteNode = 4; NetworkTopology.mapNode(broker2.getId(), briteNode); // Sixth step: Starts the simulation CloudSim.startSimulation(); // Final step: Print results when simulation is over List<Cloudlet> newList1 = broker1.getCloudletReceivedList(); List<Cloudlet> newList2 = broker2.getCloudletReceivedList(); CloudSim.stopSimulation(); Log.print("=============> User " + brokerId1 + " "); printCloudletList(newList1); Log.print("=============> User " + brokerId2 + " "); printCloudletList(newList2); // Print the debt of each user to each datacenter datacenter0.printDebts(); datacenter1.printDebts(); Log.printLine("NetworkExample3 finished!"); } catch (Exception e) { e.printStackTrace(); Log.printLine("Unwanted errors happen"); } }