Commit ba4dac91 authored by Anton Beloglazov's avatar Anton Beloglazov

- Fixed PowerVmAllocationPolicySingleThreshold

- Fixed sngle threshold example
parent a0226d94
......@@ -95,16 +95,6 @@ public class FederatedDatacenter extends SimEntity {
coordinator.setDatacenter(this);
this.sensorsList = new LinkedList<Sensor<Double>>();
//HostList2<Host> test = this.<Host>getHosts();
// LinkedList<Host> test = getHosts();
// test.add(new Host(0, null, null, null, 0, null));
// getHostsWildcard();
//
//
//
// getHosts().add(new Host(0, null, null, null, 0, null));
// getHosts().add(new cloudsim.power.Host(0, null, null, null, 0, null));
setCharacteristics(characteristics);
setVmAllocationPolicy(vmAllocationPolicy);
setLastProcessTime(0.0);
......
......@@ -271,7 +271,7 @@ public class CloudSim {
private static boolean paused = false;
/** The pause at. */
private static long pauseAt = Long.MAX_VALUE;
private static long pauseAt = -1;
/** The abrupt terminate. */
private static boolean abruptTerminate = false;
......@@ -777,7 +777,7 @@ public class CloudSim {
paused = false;
if (pauseAt <= clock) {
pauseAt = Long.MAX_VALUE;
pauseAt = -1;
}
return !paused;
......@@ -798,7 +798,7 @@ public class CloudSim {
break;
}
if ((future.size() > 0 && clock <= pauseAt && pauseAt <= future.iterator().next().eventTime()) || future.size() == 0 && pauseAt <= clock) {
if (pauseAt != -1 && ((future.size() > 0 && clock <= pauseAt && pauseAt <= future.iterator().next().eventTime()) || future.size() == 0 && pauseAt <= clock)) {
pauseSimulation();
clock = pauseAt;
}
......@@ -849,7 +849,7 @@ public class CloudSim {
waitPredicates = null;
paused = false;
pauseAt = Long.MAX_VALUE;
pauseAt = -1;
abruptTerminate = false;
}
......
......@@ -453,6 +453,10 @@ public abstract class SimEntity implements Cloneable {
delay = 0;
}
if (Double.isInfinite(delay)) {
throw new IllegalArgumentException("The specified delay is infinite value");
}
if (entityId < 0) {
Log.printLine(getName() + ".send(): Error - " +
"invalid entity id " + entityId);
......
......@@ -174,7 +174,7 @@ public class PowerDatacenter extends Datacenter {
vm.setInMigration(true);
/** VM migration delay = RAM / bandwidth + C (C = 10 sec) **/
send(getId(), (double) vm.getRam() / (vm.getBw() / 8000) + 0, CloudSimTags.VM_MIGRATE, migrate);
send(getId(), vm.getRam() / ((double) vm.getBw() / 8000) + 0, CloudSimTags.VM_MIGRATE, migrate);
}
}
......
......@@ -74,8 +74,7 @@ public class PowerVmAllocationPolicySingleThreshold extends VmAllocationPolicySi
for (PowerHost host : this.<PowerHost>getHostList()) {
if (host.isSuitableForVm(vm)) {
double maxUtilization = getMaxUtilizationAfterAllocation(host, vm);
if ((!vm.isRecentlyCreated() && maxUtilization > getUtilizationThreshold()) ||
(vm.isRecentlyCreated() && maxUtilization > 1.0)) {
if ((!vm.isRecentlyCreated() && maxUtilization > getUtilizationThreshold()) || (vm.isRecentlyCreated() && maxUtilization > 1.0)) {
continue;
}
try {
......@@ -107,22 +106,15 @@ public class PowerVmAllocationPolicySingleThreshold extends VmAllocationPolicySi
*/
@Override
public boolean allocateHostForVm(Vm vm) {
boolean result = false;
PowerHost allocatedHost = findHostForVm(vm);
try {
result = allocatedHost.vmCreate(vm);
} catch (Exception e) {
result = false;
}
if (result) { //if vm has been succesfully created in the host
if (allocatedHost != null && allocatedHost.vmCreate(vm)) { //if vm has been succesfully created in the host
getVmTable().put(vm.getUid(), allocatedHost);
Log.formatLine("%.2f: VM #" + vm.getId() + " has been sent to the host #" + allocatedHost.getId(), CloudSim.clock());
if (!Log.isDisabled()) {
Log.print(String.format("%.2f: VM #" + vm.getId() + " has been allocated to the host #" + allocatedHost.getId() + "\n", CloudSim.clock()));
}
return true;
}
return result;
return false;
}
/**
......@@ -136,7 +128,7 @@ public class PowerVmAllocationPolicySingleThreshold extends VmAllocationPolicySi
@Override
public void deallocateHostForVm(Vm vm) {
if (getVmTable().containsKey(vm.getUid())) {
Host host = getVmTable().remove(vm.getUid());
PowerHost host = (PowerHost) getVmTable().remove(vm.getUid());
if (host != null) {
host.vmDestroy(vm);
}
......@@ -165,33 +157,31 @@ public class PowerVmAllocationPolicySingleThreshold extends VmAllocationPolicySi
vmTmpList.addAll(vmList);
PowerVmList.sortByCpuUtilization(vmTmpList);
for (PowerHost host : this.<PowerHost>getHostList()) {
host.reallocateMigratingVms();
}
for (Vm vm : vmTmpList) {
//Log.printLine("VM #" + vm.getId() + " utilization: " + String.format("%.2f;", vm.getTotalUtilization(CloudSim.clock()) * 100));
if (vm.isRecentlyCreated()) {
if (vm.isRecentlyCreated() || vm.isInMigration()) {
continue;
}
PowerHost oldHost = (PowerHost) getVmTable().get(vm.getUid());
//PowerHost oldHost = vm.getHost();
PowerHost allocatedHost = findHostForVm(vm);
if (allocatedHost != null) {
Log.printLine("VM #" + vm.getId() + " allocated to host #" + allocatedHost.getId());
allocatedHost.vmCreate(vm);
if (!allocatedHost.equals(oldHost)) {
if (allocatedHost.getId() != oldHost.getId()) {
Map<String, Object> migrate = new HashMap<String, Object>();
migrate.put("vm", vm);
migrate.put("host", allocatedHost);
migrationMap.add(migrate);
getVmTable().put(vm.getUid(), allocatedHost);
vmsToRestore.remove(vm);
//Log.printLine("Skip restore of VM #" + vm.getVmId());
}
}
}
restoreAllocation(vmsToRestore);
restoreAllocation(vmsToRestore, getHostList());
return migrationMap;
}
......@@ -202,16 +192,12 @@ public class PowerVmAllocationPolicySingleThreshold extends VmAllocationPolicySi
* @param vmList the vm list
*/
protected void saveAllocation(List<? extends Vm> vmList) {
getSavedAllocation().clear();
for (Vm vm : vmList) {
if (vm != null) {
Map<String, Object> map = new HashMap<String, Object>();
//Log.printLine("Trying to save VM #" + vm.getId());
map.put("vm", vm);
map.put("host", vm.getHost());
getSavedAllocation().add(map);
vm.getHost().vmDestroy(vm);
//getVmTable().remove(vm.getUid());
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("vm", vm);
map.put("host", vm.getHost());
getSavedAllocation().add(map);
}
}
......@@ -220,34 +206,23 @@ public class PowerVmAllocationPolicySingleThreshold extends VmAllocationPolicySi
*
* @param vmsToRestore the vms to restore
*/
protected void restoreAllocation(List<Vm> vmsToRestore) {
for (Map<String, Object> map : getSavedAllocation()) {
Vm vm = (Vm) map.get("vm");
PowerHost host = (PowerHost) vm.getHost();
if (host != null) {
vm.getHost().vmDestroy(vm);
}
//PowerHost host = (PowerHost) map.get("host");
//host.vmDestroy(vm);
//host.vmDestroyAll();
protected void restoreAllocation(List<Vm> vmsToRestore, List<Host> hostList) {
for (Host host : hostList) {
host.vmDestroyAll();
host.reallocateMigratingVms();
}
for (Map<String, Object> map : getSavedAllocation()) {
Vm vm = (Vm) map.get("vm");
PowerHost host = (PowerHost) map.get("host");
//Log.printLine("Trying to restore VM #" + vm.getVmId() + " on host #" + host.getMachineID());
if (!vmsToRestore.contains(vm)) {
//Log.printLine("VM #" + vm.getVmId() + " skipped because it's not in the toRestore list");
continue;
}
//host.vmDestroy(vm);
// if (!host.vmCreate(vm)) {
// host.vmCreateBestEffort(vm);
// }
//host.vmCreateBestEffort(vm);
host.vmCreate(vm);
if (!host.vmCreate(vm)) {
Log.printLine("failed");
}
getVmTable().put(vm.getUid(), host);
Log.printLine("Restored VM #" + vm.getId() + " on host #" + host.getId());
}
setSavedAllocation(new ArrayList<Map<String, Object>>());
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment