From ab97fe867f3d0af2b5eb7132ded7ea723b799e27 Mon Sep 17 00:00:00 2001 From: Andreas Egger Date: Tue, 11 Jun 2013 20:00:34 +0200 Subject: [PATCH] Refactorings and bugfixes --- .../lsdc/management/MachineManager.java | 4 +-- src/at/ac/tuwien/lsdc/sched/SchedulerA.java | 36 +++++++++---------- src/at/ac/tuwien/lsdc/sched/SchedulerB.java | 7 ++-- .../ac/tuwien/lsdc/types/PhysicalMachine.java | 13 +++++++ 4 files changed, 35 insertions(+), 25 deletions(-) diff --git a/src/at/ac/tuwien/lsdc/management/MachineManager.java b/src/at/ac/tuwien/lsdc/management/MachineManager.java index 70f8d60..044d44b 100644 --- a/src/at/ac/tuwien/lsdc/management/MachineManager.java +++ b/src/at/ac/tuwien/lsdc/management/MachineManager.java @@ -123,9 +123,9 @@ public class MachineManager { } /** - * Gets the total power consumption summed up from each PM + * Gets the current power consumption summed up from each PM * - * @return the total power consumption + * @return the current power consumption */ public double getCurrentConsumption() { double consumption = 0; diff --git a/src/at/ac/tuwien/lsdc/sched/SchedulerA.java b/src/at/ac/tuwien/lsdc/sched/SchedulerA.java index 7cf8613..f7355c6 100644 --- a/src/at/ac/tuwien/lsdc/sched/SchedulerA.java +++ b/src/at/ac/tuwien/lsdc/sched/SchedulerA.java @@ -67,15 +67,11 @@ public class SchedulerA extends AbstractScheduler { boolean enoughResources = pm.checkVM(app.getSize(), app.getRam(), app.getCpu()); if (enoughResources) { - VirtualMachine vm = pm.startVirtualMachine(app.getSize(), app.getRam(), - app.getCpu(), vmType); - vm.startApplication(app); - insertStopEvent(currTime + app.getDuration(), app); - appDeployed = true; + appDeployed = startApp(pm, app); log.info("Application " + app.toString() + " started on new pm " + pm.getId()); } else { - log.warn("Application " + app.toString() + " cannot be run on empty pm " - + pm.getId()); + log.info("Application " + app.toString() + " cannot be run on pm " + + pm.getId() + ", too little space"); } } else { // sorting physical machines by resource utilization @@ -88,13 +84,9 @@ public class SchedulerA extends AbstractScheduler { boolean enoughResources = pm.checkVM(app.getSize(), app.getRam(), app.getCpu()); if (enoughResources) { - VirtualMachine vm = pm.startVirtualMachine(app.getSize(), app.getRam(), - app.getCpu(), vmType); - vm.startApplication(app); - insertStopEvent(currTime + app.getDuration(), app); - appDeployed = true; + appDeployed = startApp(pm, app); log.info("Application " + app.toString() + " started new vm " - + vm.getPositionOnPM() + " on pm " + pm.getId()); + + pm.getLatestVMID() + " on pm " + pm.getId()); break; } } @@ -104,16 +96,12 @@ public class SchedulerA extends AbstractScheduler { boolean enoughResources = pm.checkVM(app.getSize(), app.getRam(), app.getCpu()); if (enoughResources) { - VirtualMachine vm = pm.startVirtualMachine(app.getSize(), app.getRam(), - app.getCpu(), vmType); - vm.startApplication(app); - insertStopEvent(currTime + app.getDuration(), app); - appDeployed = true; + appDeployed = startApp(pm, app); log.info("Application " + app.toString() + " started on new pm " + pm.getId()); } else { - log.warn("Application " + app.toString() + " cannot be run on empty pm " - + pm.getId()); + log.warn("Application " + app.toString() + " cannot be run on pm " + + pm.getId() + ", too little space"); } } } @@ -129,6 +117,14 @@ public class SchedulerA extends AbstractScheduler { } } + + private boolean startApp(PhysicalMachine pm, Application app) { + VirtualMachine vm = pm.startVirtualMachine(app.getSize(), app.getRam(), + app.getCpu(), vmType); + vm.startApplication(app); + insertStopEvent(currTime + app.getDuration(), app); + return true; + } // sorting applications by amount of resources (descending) private List sortApps(LinkedList events) { diff --git a/src/at/ac/tuwien/lsdc/sched/SchedulerB.java b/src/at/ac/tuwien/lsdc/sched/SchedulerB.java index 5be16e5..cbb006c 100644 --- a/src/at/ac/tuwien/lsdc/sched/SchedulerB.java +++ b/src/at/ac/tuwien/lsdc/sched/SchedulerB.java @@ -115,10 +115,11 @@ public class SchedulerB extends AbstractSchedulerWithMigration { } catch (OutOfPMsException e) { if (federation.askToOutsource(evt.getApp())) { insertOutsourcedStartEvent(currTime + 1, evt.getApp()); - } else + } else { LOG.info("delaying the start of:" + evt.getApp()); - delayedApps.add(evt.getApp()); - return; + delayedApps.add(evt.getApp()); + return; + } } } if (deployed) diff --git a/src/at/ac/tuwien/lsdc/types/PhysicalMachine.java b/src/at/ac/tuwien/lsdc/types/PhysicalMachine.java index 9d52604..89e937b 100644 --- a/src/at/ac/tuwien/lsdc/types/PhysicalMachine.java +++ b/src/at/ac/tuwien/lsdc/types/PhysicalMachine.java @@ -1,6 +1,7 @@ package at.ac.tuwien.lsdc.types; import java.util.HashMap; +import java.util.Iterator; import at.ac.tuwien.lsdc.exception.ActiveApplicationsException; import at.ac.tuwien.lsdc.exception.VMsRunningException; @@ -157,6 +158,18 @@ public class PhysicalMachine implements Comparable { public VirtualMachine getVirtualMachine(int id) { return VMs.get(id); } + + public VirtualMachine getLatestVM() { + VirtualMachine vm = null; + for(Iterator it = VMs.values().iterator(); it.hasNext(); ) { + vm = it.next(); + } + return vm; + } + + public Integer getLatestVMID() { + return getLatestVM().getId(); + } /** * return a list of all VMs running on this PM. -- 2.43.0