@Override public void deallocateRamForVm(Vm vm) { if (getRamTable().containsKey(vm.getUid())) { int amountFreed = getRamTable().remove(vm.getUid()); setAvailableRam(getAvailableRam() + amountFreed); vm.setCurrentAllocatedRam(0); } }
@Override public boolean allocateRamForVm(Vm vm, int ram) { int maxRam = vm.getRam(); /* If the requested amount of RAM to be allocated to the VM is greater than the amount of VM is in fact requiring, allocate only the amount defined in the Vm requirements.*/ if (ram >= maxRam) { ram = maxRam; } deallocateRamForVm(vm); if (getAvailableRam() >= ram) { setAvailableRam(getAvailableRam() - ram); getRamTable().put(vm.getUid(), ram); vm.setCurrentAllocatedRam(getAllocatedRamForVm(vm)); return true; } vm.setCurrentAllocatedRam(getAllocatedRamForVm(vm)); return false; }
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); } }
setCurrentAllocatedRam(0); setCurrentAllocatedSize(0);