@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; } }
private static List<Vm> createVM(int userId, int vms, int idShift) { //Creates a container to store VMs. This list is passed to the broker later LinkedList<Vm> list = new LinkedList<Vm>(); //VM Parameters long size = 10000; //image size (MB) int ram = 512; //vm memory (MB) int mips = 250; long bw = 1000; int pesNumber = 1; //number of cpus String vmm = "Xen"; //VMM name //create VMs Vm[] vm = new Vm[vms]; for(int i=0;i<vms;i++){ vm[i] = new Vm(idShift + i, userId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared()); list.add(vm[i]); } return list; }
/** * Gets the current requested bw. * * @return the current requested bw */ public long getCurrentRequestedBw() { if (isBeingInstantiated()) { return getBw(); } return (long) (getCloudletScheduler().getCurrentRequestedUtilizationOfBw() * getBw()); }
/** * Get total CPU utilization of all cloudlets running on this VM at the given time (in MIPS). * * @param time the time * @return total cpu utilization in MIPS * @see #getTotalUtilizationOfCpu(double) */ public double getTotalUtilizationOfCpuMips(double time) { return getTotalUtilizationOfCpu(time) * getMips(); }
/** * Gets a {@link Vm} with a given id and owned by a given user. * * @param vmList list of existing VMs * @param id ID of required VM * @param userId the user ID of the VM's owner * @return Vm with the given ID, $null if not found * @pre $none * @post $none */ public static <T extends Vm> T getByIdAndUserId(List<T> vmList, int id, int userId) { for (T vm : vmList) { if (vm.getId() == id && vm.getUserId() == userId) { return vm; } } return null; }
vm.setInMigration(true); 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()); vm.getHost().updateVmsProcessing(CloudSim.clock());
int vmId = vm.getId(); double ramUtilization = (vm.getCurrentAllocatedRam()/vm.getRam())*100; dataList.add(new ReportData(RAM, null, brokerName, null, vmId, currentTime, ramUtilization, currentSimulation)); overallRam += ramUtilization; double cpuUtilization = (vm.getCurrentRequestedTotalMips()/vm.getMips())*100; dataList.add(new ReportData(CPU, null, brokerName, null, vmId, currentTime, cpuUtilization, currentSimulation)); overallCpu += cpuUtilization; double bwUtilization = (vm.getCurrentAllocatedBw()/vm.getBw())*100; dataList.add(new ReportData(BANDWIDTH, null, brokerName, null, vmId, currentTime, bwUtilization, currentSimulation)); overallBandwidth += bwUtilization;
getVmScheduler().allocatePesForVm(vm, vm.getCurrentRequestedMips()); double totalRequestedMips = vm.getCurrentRequestedTotalMips(); double totalAllocatedMips = getVmScheduler().getTotalAllocatedMipsForVm(vm); "%.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(), totalAllocatedMips, totalRequestedMips, vm.getMips(), totalRequestedMips / vm.getMips() * 100); "%.2f: [Host #" + getId() + "] MIPS for VM #" + vm.getId() + " by PEs (" + getNumberOfPes() + " * " + getVmScheduler().getPeCapacity() + ")." + pesString, Log.formatLine("%.2f: [Host #" + getId() + "] VM #" + vm.getId() + " is being migrated to Host #" + getId(), CloudSim.clock()); } else { if (totalAllocatedMips + 0.1 < totalRequestedMips) { Log.formatLine("%.2f: [Host #" + getId() + "] Under allocated MIPS for VM #" + vm.getId() + ": %.2f", CloudSim.clock(), totalRequestedMips - totalAllocatedMips); vm.addStateHistoryEntry( currentTime, totalAllocatedMips, totalRequestedMips,
if (vm.isInMigration()) { continue; for (PowerHost targetHost : targetHosts) { List<Double> hostResources = resourcesMap.get(targetHost.getId()); double vmTotalMips = vm.getNumberOfPes() * vm.getMips(); if ((hostResources.get(0) + vmTotalMips) / targetHost.getTotalMips() < upperUtilizationThreshold && (hostResources.get(1) + vm.getRam()) / targetHost.getRam() < upperUtilizationThreshold) { hostResources.set(1, hostResources.get(1) + vm.getRam()); ramUtilization -= vm.getRam(); cpuUtilization -= sourceHost.getTotalAllocatedMipsForVm(vm);
if (vm.getId() == id) { return vm;
@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; }
int requiredPes = vm.getNumberOfPes(); if (!getVmTable().containsKey(vm.getUid())) { // if this vm was not created do {// we still trying until we find a host or until we try all of them getVmTable().put(vm.getUid(), host); getUsedPes().put(vm.getUid(), requiredPes); getFreePes().set(idx, getFreePes().get(idx) - requiredPes); result = true;
/** * Gets the current requested mips. * * @return the current requested mips */ public List<Double> getCurrentRequestedMips() { List<Double> currentRequestedMips = getCloudletScheduler().getCurrentRequestedMips(); if (isBeingInstantiated()) { currentRequestedMips = new ArrayList<Double>(); for (int i = 0; i < getNumberOfPes(); i++) { currentRequestedMips.add(getMips()); } } return currentRequestedMips; }
Vm vm1 = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared()); Vm vm2 = new Vm(vmid, brokerId, mips * 2, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared()); broker.bindCloudletToVm(cloudlet1.getCloudletId(),vm1.getId()); broker.bindCloudletToVm(cloudlet2.getCloudletId(),vm2.getId());
int[] data = new int[3]; data[0] = getId(); data[1] = vm.getId(); data[2] = CloudSimTags.FALSE; send(vm.getUserId(), CloudSim.getMinTimeBetweenEvents(), CloudSimTags.VM_CREATE_ACK, data); getVmList().add(vm); if (vm.isBeingInstantiated()) { vm.setBeingInstantiated(false); vm.updateVmProcessing(CloudSim.clock(), getVmAllocationPolicy().getHost(vm).getVmScheduler() .getAllocatedMipsForVm(vm));
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); if (!getVmScheduler().allocatePesForVm(vm, vm.getCurrentRequestedMips())) { Log.printConcatLine("[VmScheduler.vmCreate] Allocation of VM #", vm.getId(), " to Host #", getId(), " failed by MIPS"); getRamProvisioner().deallocateRamForVm(vm); setStorage(getStorage() - vm.getSize()); getVmList().add(vm); vm.setHost(this); return true;
getVmAllocationPolicy().deallocateHostForVm(vm); getVmList().remove(vm); Log.printLine("VM #" + vm.getId() + " has been deallocated from host #" + host.getId()); Vm vm = (Vm) migrate.get("vm"); PowerHost targetHost = (PowerHost) migrate.get("host"); PowerHost oldHost = (PowerHost) vm.getHost(); "%.2f: Migration of VM #%d to Host #%d is started", CloudSim.clock(), vm.getId(), targetHost.getId()); } else { "%.2f: Migration of VM #%d from Host #%d to Host #%d is started", CloudSim.clock(), vm.getId(), oldHost.getId(), targetHost.getId()); vm.getRam() / ((double) vm.getBw() / 8000) + 10, CloudSimTags.VM_MIGRATE, migrate);
Log.formatLine("%.2f: Migration of VM #%d to Host #%d has started", CloudSim.clock(), vm.getId(), targetHost.getId()); } else { Log.formatLine("%.2f: Migration of VM #%d from Host #%d to Host #%d has started", CloudSim.clock(), vm.getId(), oldHost.getId(), targetHost.getId()); vm.setInMigration(true); send(getId(), vm.getRam() / ((double) vm.getBw() / 8000) + 10, CloudSimTags.VM_MIGRATE, migration.getMigrationMap());
/** * 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()); } }