/** * Destroys a VM running in the host. * * @param vm the VM * @pre $none * @post $none */ public void vmDestroy(Vm vm) { if (vm != null) { vmDeallocate(vm); getVmList().remove(vm); vm.setHost(null); } }
/** * Updates the list of maps between a VM and the host where it is place. * @see #savedAllocation */ protected void saveAllocation() { getSavedAllocation().clear(); for (Host host : getHostList()) { for (Vm vm : host.getVmList()) { if (host.getVmsMigratingIn().contains(vm)) { continue; } Map<String, Object> map = new HashMap<String, Object>(); map.put("host", host); map.put("vm", vm); getSavedAllocation().add(map); } } }
/** * Gets a VM by its id and user. * * @param vmId the vm id * @param userId ID of VM's owner * @return the virtual machine object, $null if not found * @pre $none * @post $none */ public Vm getVm(int vmId, int userId) { for (Vm vm : getVmList()) { if (vm.getId() == vmId && vm.getUserId() == userId) { return vm; } } return null; }
/** * Removes a migrating in vm. * * @param vm the vm */ public void removeMigratingInVm(Vm vm) { vmDeallocate(vm); getVmsMigratingIn().remove(vm); getVmList().remove(vm); getVmScheduler().getVmsMigratingIn().remove(vm.getUid()); vm.setInMigration(false); }
/** * Requests updating of cloudlets' processing in VMs running in this host. * * @param currentTime the current time * @return expected time of completion of the next cloudlet in all VMs in this host or * {@link Double#MAX_VALUE} if there is no future events expected in this host * @pre currentTime >= 0.0 * @post $none * @todo there is an inconsistency between the return value of this method * and the individual call of {@link Vm#updateVmProcessing(double, java.util.List), * and consequently the {@link CloudletScheduler#updateVmProcessing(double, java.util.List)}. * The current method returns {@link Double#MAX_VALUE} while the other ones * return 0. It has to be checked if there is a reason for this * difference.} */ public double updateVmsProcessing(double currentTime) { double smallerTime = Double.MAX_VALUE; for (Vm vm : getVmList()) { double time = vm.updateVmProcessing( currentTime, getVmScheduler().getAllocatedMipsForVm(vm)); if (time > 0.0 && time < smallerTime) { smallerTime = time; } } return smallerTime; }
@Override public double updateVmsProcessing(double currentTime) { double smallerTime = Double.MAX_VALUE; // insert in each vm packet recieved recvpackets(); for (Vm vm : super.getVmList()) { double time = ((NetworkVm) vm).updateVmProcessing(currentTime, getVmScheduler() .getAllocatedMipsForVm(vm)); if (time > 0.0 && time < smallerTime) { smallerTime = time; } } // send the packets to other hosts/VMs sendpackets(); return smallerTime; }
/** * Verifies if some cloudlet inside this Datacenter already finished. * If yes, send it to the User/Broker * * @pre $none * @post $none */ protected void checkCloudletCompletion() { List<? extends Host> list = getVmAllocationPolicy().getHostList(); for (int i = 0; i < list.size(); i++) { Host host = list.get(i); for (Vm vm : host.getVmList()) { while (vm.getCloudletScheduler().isFinishedCloudlets()) { Cloudlet cl = vm.getCloudletScheduler().getNextFinishedCloudlet(); if (cl != null) { sendNow(cl.getUserId(), CloudSimTags.CLOUDLET_RETURN, cl); } } } } }
/** * Reallocate migrating in vms. Gets the VM in the migrating in queue * and allocate them on the host. */ public void reallocateMigratingInVms() { for (Vm vm : getVmsMigratingIn()) { if (!getVmList().contains(vm)) { getVmList().add(vm); } if (!getVmScheduler().getVmsMigratingIn().contains(vm.getUid())) { getVmScheduler().getVmsMigratingIn().add(vm.getUid()); } getRamProvisioner().allocateRamForVm(vm, vm.getCurrentRequestedRam()); getBwProvisioner().allocateBwForVm(vm, vm.getCurrentRequestedBw()); getVmScheduler().allocatePesForVm(vm, vm.getCurrentRequestedMips()); setStorage(getStorage() - vm.getSize()); } }
getVmList().add(vm); updateVmsProcessing(CloudSim.clock()); vm.getHost().updateVmsProcessing(CloudSim.clock());
getVmList().add(vm); vm.setHost(this); return true;