/** * 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; }
NetworkHost hs1 = (NetworkHost) hs; hs1.bandwidth = NetworkConstants.BandWidthEdgeHost; int switchnum = (int) (hs.getId() / NetworkConstants.EdgeSwitchPort); edgeswitch[switchnum].hostlist.put(hs.getId(), hs1); dc.HostToSwitchid.put(hs.getId(), edgeswitch[switchnum].getId()); hs1.sw = edgeswitch[switchnum]; List<NetworkHost> hslist = hs1.sw.fintimelistHost.get(0D);
Host host = hosts.get(j); if (!vmAllocationPolicy.getTimeHistory().containsKey(host.getId())) { continue; File file = new File(outputPath + "_" + host.getId() + ".csv"); try { file.createNewFile(); List<Double> timeData = vmAllocationPolicy.getTimeHistory().get(host.getId()); List<Double> utilizationData = vmAllocationPolicy.getUtilizationHistory().get(host.getId()); List<Double> metricData = vmAllocationPolicy.getMetricHistory().get(host.getId());
/** * 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; }
/** * Prints the metric history. * * @param hosts the hosts * @param vmAllocationPolicy the vm allocation policy */ public static void printMetricHistory( List<? extends Host> hosts, PowerVmAllocationPolicyMigrationAbstract vmAllocationPolicy) { for (int i = 0; i < 10; i++) { Host host = hosts.get(i); Log.printLine("Host #" + host.getId()); Log.printLine("Time:"); if (!vmAllocationPolicy.getTimeHistory().containsKey(host.getId())) { continue; } for (Double time : vmAllocationPolicy.getTimeHistory().get(host.getId())) { Log.format("%.2f, ", time); } Log.printLine(); for (Double utilization : vmAllocationPolicy.getUtilizationHistory().get(host.getId())) { Log.format("%.2f, ", utilization); } Log.printLine(); for (Double metric : vmAllocationPolicy.getMetricHistory().get(host.getId())) { Log.format("%.2f, ", metric); } Log.printLine(); } }
@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; } }
@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; } }
/** * 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; }
@Override public boolean allocateHostForVm(Vm vm, Host host) { if (host == null) { Log.formatLine("%.2f: No suitable host found for VM #" + vm.getId() + "\n", CloudSim.clock()); return false; } if (host.vmCreate(vm)) { // if vm has been succesfully created in the host getVmTable().put(vm.getUid(), host); Log.formatLine( "%.2f: VM #" + vm.getId() + " has been allocated to the host #" + host.getId(), CloudSim.clock()); return true; } Log.formatLine( "%.2f: Creation of VM #" + vm.getId() + " on the host #" + host.getId() + " failed\n", CloudSim.clock()); return false; }
if (getStorage() < vm.getSize()) { Log.printConcatLine("[VmScheduler.addMigratingInVm] Allocation of VM #", vm.getId(), " to Host #", getId(), " failed by storage"); System.exit(0); getId(), " failed by RAM"); System.exit(0); + getId() + " failed by BW"); System.exit(0); if (!getVmScheduler().allocatePesForVm(vm, vm.getCurrentRequestedMips())) { Log.printLine("[VmScheduler.addMigratingInVm] Allocation of VM #" + vm.getId() + " to Host #" + getId() + " failed by MIPS"); System.exit(0);
CloudSim.clock(), vm.getId(), host.getId()); vm.setInMigration(false);
Log.printConcatLine("[VmScheduler.vmCreate] Allocation of VM #", vm.getId(), " to Host #", getId(), " failed by storage"); return false; Log.printConcatLine("[VmScheduler.vmCreate] Allocation of VM #", vm.getId(), " to Host #", getId(), " failed by RAM"); return false; Log.printConcatLine("[VmScheduler.vmCreate] Allocation of VM #", vm.getId(), " to Host #", getId(), " failed by BW"); getRamProvisioner().deallocateRamForVm(vm); Log.printConcatLine("[VmScheduler.vmCreate] Allocation of VM #", vm.getId(), " to Host #", getId(), " failed by MIPS"); getRamProvisioner().deallocateRamForVm(vm);
getVmsToDatacentersMap().put(vmId, datacenterId); getVmsCreatedList().add(VmList.getById(getVmList(), vmId)); Log.printLine(CloudSim.clock()+": "+getName()+ ": VM #"+vmId+" has been created in " + getDatacenterCharacteristicsList().get(datacenterId).getResourceName() + ", Host #" + VmList.getById(getVmsCreatedList(), vmId).getHost().getId()); } else { Log.printLine(CloudSim.clock()+": "+getName()+ ": Creation of VM #"+vmId+" failed in "+ getDatacenterCharacteristicsList().get(datacenterId).getResourceName());
Log.printConcatLine(CloudSim.clock(), ": ", getName(), ": VM #", vmId, " has been created in Datacenter #", datacenterId, ", Host #", VmList.getById(getVmsCreatedList(), vmId).getHost().getId()); } else { Log.printConcatLine(CloudSim.clock(), ": ", getName(), ": Creation of VM #", vmId,
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(),