/** * Prints the Cloudlet objects. * * @param list list of Cloudlets */ public static void printCloudletList(List<Cloudlet> list) { int size = list.size(); Cloudlet cloudlet; String indent = "\t"; Log.printLine(); Log.printLine("========== OUTPUT =========="); Log.printLine("Cloudlet ID" + indent + "STATUS" + indent + "Resource 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()); if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) { Log.printLine(indent + "SUCCESS" + indent + indent + cloudlet.getResourceId() + indent + cloudlet.getVmId() + indent + dft.format(cloudlet.getActualCPUTime()) + indent + dft.format(cloudlet.getExecStartTime()) + indent + indent + dft.format(cloudlet.getFinishTime())); } } }
/** * Processes the return of cloudlets. * * @param ev a simulation event. * @since 1.0 */ @Override protected void processCloudletReturn(SimEvent ev) { Cloudlet cloudlet = (Cloudlet) ev.getData(); getCloudletReceivedList().add(cloudlet); Log.printLine(CloudSim.clock()+": "+getName()+ ": Cloudlet "+cloudlet.getCloudletId()+" received"); cloudletsSubmitted -= 1; Cloudlet newCloudlet = new Cloudlet(this.cloudletId, (long) ((long)this.maxLengthOfCloudlets * RandomNumberGenerator.getRandomNumbers(1).get(0)), cloudlet.getNumberOfPes(), cloudlet.getCloudletLength(), cloudlet.getCloudletOutputSize(), cloudlet.getUtilizationModelCpu(), cloudlet.getUtilizationModelRam(), cloudlet.getUtilizationModelBw()); newCloudlet.setUserId(getId()); newCloudlet.setVmId(cloudlet.getVmId()); getCloudletList().add(newCloudlet); this.cloudletId++; submitCloudlets(); }
/** * Prints the Cloudlet objects. * * @param list list of Cloudlets */ private static void printCloudletList(List<ContainerCloudlet> 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.getCloudletStatusString() == "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())); } } }
/** * Returns the execution time of the Cloudlet. * * @return time in which the Cloudlet was running * @pre $none * @post $none */ public double getActualCPUTime() { return getFinishTime() - getExecStartTime(); }
/** * Gets the total length (across all PEs) of this Cloudlet. It considers the * {@link #cloudletLength} of the cloudlet to be executed in each Pe and the * {@link #numberOfPes}.<br/> * * For example, setting the cloudletLenght as 10000 MI and * {@link #numberOfPes} to 4, each Pe will execute 10000 MI. Thus, the * entire cloudlet has a total length of 40000 MI. * * * @return the total length of this Cloudlet * * @see #setCloudletLength(long) * @pre $none * @post $result >= 0.0 */ public long getCloudletTotalLength() { return getCloudletLength() * getNumberOfPes(); }
/** * Finalizes all relevant information before <tt>exiting</tt> the CloudResource entity. This * method sets the final data of: * <ul> * <li>wall clock time, i.e. the time of this Cloudlet resides in a CloudResource (from arrival * time until departure time). * <li>actual CPU time, i.e. the total execution time of this Cloudlet in a CloudResource. * <li>Cloudlet's finished time so far * </ul> * * @pre $none * @post $none */ public void finalizeCloudlet() { // Sets the wall clock time and actual CPU time double wallClockTime = CloudSim.clock() - arrivalTime; cloudlet.setExecParam(wallClockTime, totalCompletionTime); long finished = 0; //if (cloudlet.getCloudletTotalLength() * Consts.MILLION < cloudletFinishedSoFar) { if (cloudlet.getCloudletStatus()==Cloudlet.SUCCESS) { finished = cloudlet.getCloudletLength(); } else { finished = cloudletFinishedSoFar / Consts.MILLION; } cloudlet.setCloudletFinishedSoFar(finished); }
if (cl.isFinished()) { String name = CloudSim.getEntityName(cl.getUserId()); Log.printConcatLine(getName(), ": Warning - Cloudlet #", cl.getCloudletId(), " owned by ", name, " is already completed/finished."); Log.printLine("Therefore, it is not being executed again"); int[] data = new int[3]; data[0] = getId(); data[1] = cl.getCloudletId(); data[2] = CloudSimTags.FALSE; sendNow(cl.getUserId(), tag, data); sendNow(cl.getUserId(), CloudSimTags.CLOUDLET_RETURN, cl); cl.setResourceParameter( getId(), getCharacteristics().getCostPerSecond(), getCharacteristics().getCostPerBw()); int userId = cl.getUserId(); int vmId = cl.getVmId(); double fileTransferTime = predictFileTransferTime(cl.getRequiredFiles()); int[] data = new int[3]; data[0] = getId(); data[1] = cl.getCloudletId(); data[2] = CloudSimTags.TRUE;
UtilizationModel utilizationModel = new UtilizationModelFull(); Cloudlet cloudlet1 = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel); cloudlet1.setUserId(brokerId); Cloudlet cloudlet2 = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel); cloudlet2.setUserId(brokerId); broker.bindCloudletToVm(cloudlet1.getCloudletId(),vm1.getId()); broker.bindCloudletToVm(cloudlet2.getCloudletId(),vm2.getId());
for(Cloudlet cloudlet : cloudletsList) { List<Double> timesOfExecution = new ArrayList<Double>(); timesOfExecution.add(cloudlet.getExecStartTime()); timesOfExecution.add(cloudlet.getFinishTime()); cloudletsTimesOfExecution.put(cloudlet.getCloudletId(), timesOfExecution); cloudletsPerVm.put("VM"+cloudlet.getVmId(), cloudletsPerVm.get("VM"+cloudlet.getVmId()) + 1);
Vm vm; if (cloudlet.getVmId() == -1) { vm = getVmsCreatedList().get(vmIndex); } else { // submit to the specific vm vm = VmList.getById(getVmsCreatedList(), cloudlet.getVmId()); if (vm == null) { // vm was not created if(!Log.isDisabled()) { Log.printConcatLine(CloudSim.clock(), ": ", getName(), ": Postponing execution of cloudlet ", cloudlet.getCloudletId(), ": bount VM not available"); cloudlet.getCloudletId(), " to VM #", vm.getId()); cloudlet.setVmId(vm.getId()); sendNow(getVmsToDatacentersMap().get(vm.getId()), CloudSimTags.CLOUDLET_SUBMIT, cloudlet); cloudletsSubmitted++;
private static List<Cloudlet> createCloudlet(int userId, int cloudlets, int idShift){ // Creates a container to store Cloudlets LinkedList<Cloudlet> list = new LinkedList<Cloudlet>(); //cloudlet parameters long length = 40000; long fileSize = 300; long outputSize = 300; int pesNumber = 1; UtilizationModel utilizationModel = new UtilizationModelFull(); Cloudlet[] cloudlet = new Cloudlet[cloudlets]; for(int i=0;i<cloudlets;i++){ cloudlet[i] = new Cloudlet(idShift + i, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel); // setting the owner of these Cloudlets cloudlet[i].setUserId(userId); list.add(cloudlet[i]); } return list; }
} else { if (cl.getCloudletStatusString() == "Success") {// if yes, send it back to user int[] data = new int[3]; data[0] = getId(); data[1] = cloudletId; data[2] = 0; sendNow(cl.getUserId(), CloudSimTags.CLOUDLET_SUBMIT_ACK, data); sendNow(cl.getUserId(), CloudSimTags.CLOUDLET_RETURN, cl); cl.setVmId(vmDestId); } else { double fileTransferTime = predictFileTransferTime(cl.getRequiredFiles()); vm.getCloudletScheduler().cloudletSubmit(cl, fileTransferTime); data[2] = 1; sendNow(cl.getUserId(), CloudSimTags.CLOUDLET_SUBMIT_ACK, data);
@Override public double cloudletSubmit(Cloudlet cloudlet, double fileTransferTime) { ResCloudlet rcl = new ResCloudlet(cloudlet); rcl.setCloudletStatus(Cloudlet.INEXEC); for (int i = 0; i < cloudlet.getNumberOfPes(); i++) { rcl.setMachineAndPeId(0, i); } getCloudletExecList().add(rcl); // use the current capacity to estimate the extra amount of // time to file transferring. It must be added to the cloudlet length double extraSize = getCapacity(getCurrentMipsShare()) * fileTransferTime; long length = (long) (cloudlet.getCloudletLength() + extraSize); cloudlet.setCloudletLength(length); return cloudlet.getCloudletLength() / getCapacity(getCurrentMipsShare()); }
for(Cloudlet cloudlet: getCloudletSubmittedList()){ if(!finishedCloudlets.contains(cloudlet) && cloudlet.isFinished()){ Vm vm = getVmsCreatedList().get(cloudlet.getVmId()-1); vm.setCurrentAllocatedRam(vm.getCurrentAllocatedRam() - (int)(cloudlet.getUtilizationOfRam(CloudSim.clock())*100)); vm.updateVmProcessing(CloudSim.clock(), null); finishedCloudlets.add(cloudlet); } }
try { Cloudlet cl = (Cloudlet) ev.getData(); cloudletId = cl.getCloudletId(); userId = cl.getUserId(); vmId = cl.getVmId(); } catch (Exception e) { Log.printConcatLine(super.getName(), ": Error in processing Cloudlet");
List<Cloudlet> cloudletsList = broker.getCloudletSubmittedList(); for(Cloudlet cloudlet : cloudletsList) { if(cloudlet.getResourceId() == datacenter.getId()) { executedCloudlets.put(broker.getName(), executedCloudlets.get(broker.getName()) + 1); vmIds.add(cloudlet.getVmId());
/** * Sets the execution status code of this Cloudlet. * * @param newStatus the status code of this Cloudlet * @throws Exception Invalid range of Cloudlet status * @pre newStatus >= 0 && newStatus <= 8 * @ * post $none * * @todo It has to throw an specific (unckecked) exception */ public void setCloudletStatus(final int newStatus) throws Exception { // if the new status is same as current one, then ignore the rest if (status == newStatus) { return; } // throws an exception if the new status is outside the range if (newStatus < Cloudlet.CREATED || newStatus > Cloudlet.FAILED_RESOURCE_UNAVAILABLE) { throw new Exception( "Cloudlet.setCloudletStatus() : Error - Invalid integer range for Cloudlet status."); } if (newStatus == Cloudlet.SUCCESS) { finishTime = CloudSim.clock(); } if (record) { write("Sets Cloudlet status from " + getCloudletStatusString() + " to " + Cloudlet.getStatusString(newStatus)); } status = newStatus; }
/** * Gets this Cloudlet entity Id. * * @return the Cloudlet entity Id * @pre $none * @post $none */ public int getCloudletId() { return cloudlet.getCloudletId(); }
/** * Gets the Cloudlet's execution start time. * * @return Cloudlet's execution start time * @pre $none * @post $none */ public double getExecStartTime() { return cloudlet.getExecStartTime(); }