if (!getVmsMigratingIn().contains(vm)) { if (getStorage() < vm.getSize()) { Log.printConcatLine("[VmScheduler.addMigratingInVm] Allocation of VM #", vm.getId(), " to Host #", getId(), " failed by storage"); System.exit(0); if (!getRamProvisioner().allocateRamForVm(vm, vm.getCurrentRequestedRam())) { Log.printConcatLine("[VmScheduler.addMigratingInVm] Allocation of VM #", vm.getId(), " to Host #", getId(), " failed by RAM"); System.exit(0); if (!getBwProvisioner().allocateBwForVm(vm, vm.getCurrentRequestedBw())) { Log.printLine("[VmScheduler.addMigratingInVm] Allocation of VM #" + vm.getId() + " to Host #" + getId() + " failed by BW"); System.exit(0); getVmScheduler().getVmsMigratingIn().add(vm.getUid()); if (!getVmScheduler().allocatePesForVm(vm, vm.getCurrentRequestedMips())) { Log.printLine("[VmScheduler.addMigratingInVm] Allocation of VM #" + vm.getId() + " to Host #" + getId() + " failed by MIPS"); System.exit(0); setStorage(getStorage() - vm.getSize()); getVmsMigratingIn().add(vm); getVmList().add(vm); updateVmsProcessing(CloudSim.clock()); vm.getHost().updateVmsProcessing(CloudSim.clock());
/** * Sets the PEs of the host to a FAILED status. NOTE: <tt>resName</tt> is used for debugging * purposes, which is <b>ON</b> by default. Use {@link #setFailed(boolean)} if you do not want * this information. * * @param resName the name of the resource * @param failed the failed * @return <tt>true</tt> if successful, <tt>false</tt> otherwise */ public boolean setFailed(String resName, boolean failed) { // all the PEs are failed (or recovered, depending on fail) this.failed = failed; PeList.setStatusFailed(getPeList(), resName, getId(), failed); return true; }
/** * Deallocate all resources of a VM. * * @param vm the VM */ protected void vmDeallocate(Vm vm) { getRamProvisioner().deallocateRamForVm(vm); getBwProvisioner().deallocateBwForVm(vm); getVmScheduler().deallocatePesForVm(vm); setStorage(getStorage() + vm.getSize()); }
/** * Deallocate all resources of all VMs. */ protected void vmDeallocateAll() { getRamProvisioner().deallocateRamForAllVms(); getBwProvisioner().deallocateBwForAllVms(); getVmScheduler().deallocatePesForAllVms(); }
if (getStorage() < vm.getSize()) { Log.printConcatLine("[VmScheduler.vmCreate] Allocation of VM #", vm.getId(), " to Host #", getId(), " failed by storage"); return false; if (!getRamProvisioner().allocateRamForVm(vm, vm.getCurrentRequestedRam())) { Log.printConcatLine("[VmScheduler.vmCreate] Allocation of VM #", vm.getId(), " to Host #", getId(), " failed by RAM"); return false; if (!getBwProvisioner().allocateBwForVm(vm, vm.getCurrentRequestedBw())) { Log.printConcatLine("[VmScheduler.vmCreate] Allocation of VM #", vm.getId(), " to Host #", getId(), " failed by BW"); getRamProvisioner().deallocateRamForVm(vm); return false; if (!getVmScheduler().allocatePesForVm(vm, vm.getCurrentRequestedMips())) { Log.printConcatLine("[VmScheduler.vmCreate] Allocation of VM #", vm.getId(), " to Host #", getId(), " failed by MIPS"); getRamProvisioner().deallocateRamForVm(vm); getBwProvisioner().deallocateBwForVm(vm); return false; setStorage(getStorage() - vm.getSize()); getVmList().add(vm); vm.setHost(this); return true;
/** * 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()); } }
@Override public boolean allocateHostForVm(Vm vm, Host host) { if (host.vmCreate(vm)) { // if vm has been succesfully created in the host getVmTable().put(vm.getUid(), host); int requiredPes = vm.getNumberOfPes(); int idx = getHostList().indexOf(host); getUsedPes().put(vm.getUid(), requiredPes); getFreePes().set(idx, getFreePes().get(idx) - requiredPes); Log.formatLine( "%.2f: VM #" + vm.getId() + " has been allocated to the host #" + host.getId(), CloudSim.clock()); return true; } return false; } }
/** * Gets a {@link Host} with a given id. * * @param <T> the generic type * @param hostList the list of existing hosts * @param id the host ID * @return a Host with the given ID or $null if not found * * @pre id >= 0 * @post $none */ public static <T extends Host> T getById(List<T> hostList, int id) { for (T host : hostList) { if (host.getId() == id) { return host; } } return null; }
/** * Gets the max utilization among the PEs of a given VM placed at a given host. * @param host The host where the VM is placed * @param vm The VM to get the max PEs utilization * @return The max utilization among the PEs of the VM */ protected double getMaxUtilizationAfterAllocation(NetworkHost host, Vm vm) { List<Double> allocatedMipsForVm = null; NetworkHost allocatedHost = (NetworkHost) vm.getHost(); if (allocatedHost != null) { allocatedMipsForVm = vm.getHost().getAllocatedMipsForVm(vm); } if (!host.allocatePesForVm(vm, vm.getCurrentRequestedMips())) { return -1; } double maxUtilization = host.getMaxUtilizationAmongVmsPes(vm); host.deallocatePesForVm(vm); if (allocatedHost != null && allocatedMipsForVm != null) { vm.getHost().allocatePesForVm(vm, allocatedMipsForVm); } return maxUtilization; }
for (int i = 1; i < freePesTmp.size(); i++) { Host h2=hostList.get(i); freeramh1=h1.getRamProvisioner().getAvailableRam(); freeramh2=h2.getRamProvisioner().getAvailableRam(); freepesh1=freePesTmp.get(j); freepesh2=freePesTmp.get(i); result = host.vmCreate(vm);
/** * Creates the given VM within the NetworkDatacenter. * It can be directly accessed by Datacenter Broker which manages allocation of Cloudlets. * * @param vm * @return true if the VW was created successfully, false otherwise */ public boolean processVmCreateNetwork(Vm vm) { boolean result = getVmAllocationPolicy().allocateHostForVm(vm); if (result) { VmToSwitchid.put(vm.getId(), ((NetworkHost) vm.getHost()).sw.getId()); VmtoHostlist.put(vm.getId(), vm.getHost().getId()); System.out.println(vm.getId() + " VM is created on " + vm.getHost().getId()); getVmList().add(vm); vm.updateVmProcessing(CloudSim.clock(), getVmAllocationPolicy().getHost(vm).getVmScheduler() .getAllocatedMipsForVm(vm)); } return result; }
host.removeMigratingInVm(vm); boolean result = getVmAllocationPolicy().allocateHostForVm(vm, host); if (!result) { CloudSim.clock(), vm.getId(), host.getId()); vm.setInMigration(false);
@Override public double updateVmsProcessing(double currentTime) { double smallerTime = super.updateVmsProcessing(currentTime); setPreviousUtilizationMips(getUtilizationMips()); setUtilizationMips(0); Log.formatLine( "%.2f: [Host #" + getId() + "] Total allocated MIPS for VM #" + vm.getId() + " (Host #" + vm.getHost().getId() + ") is %.2f, was requested %.2f out of total %.2f (%.2f%%)", CloudSim.clock(),
new Host( hostId, new RamProvisionerSimple(ram),
/** * Gets the pes number. * * @return the pes number */ public int getNumberOfPes() { return getPeList().size(); }
/** * Gets the host memory. * * @return the host memory * @pre $none * @post $result > 0 */ public int getRam() { return getRamProvisioner().getRam(); }
result = host.vmCreate(vm);
/** * Gets the power after allocation. * * @param host the host. * @param vm the virtual machine. * @return the power usage after allocation of the virtual machine. */ protected double getPowerAfterAllocation(PowerHost host, Vm vm) { List<Double> allocatedMipsForVm = null; PowerHost allocatedHost = (PowerHost) vm.getHost(); if (allocatedHost != null) { allocatedMipsForVm = allocatedHost.getAllocatedMipsForVm(vm); } if (!host.allocatePesForVm(vm, vm.getCurrentRequestedMips())) { return -1; } double power = host.getPower(); host.deallocatePesForVm(vm); if (allocatedHost != null && allocatedMipsForVm != null) { vm.getHost().allocatePesForVm(vm, allocatedMipsForVm); } return power; }
/** * Creates a new VmAllocationPolicySimple object. * * @param list the list of hosts * @pre $none * @post $none */ public VmAllocationPolicySimple(List<? extends Host> list) { super(list); setFreePes(new ArrayList<Integer>()); for (Host host : getHostList()) { getFreePes().add(host.getNumberOfPes()); } setVmTable(new HashMap<String, Host>()); setUsedPes(new HashMap<String, Integer>()); }
/** * Gets the host bw. * * @return the host bw * @pre $none * @post $result > 0 */ public long getBw() { return getBwProvisioner().getBw(); }