From 0dd42699cb70c1c23205f8242b906d19747bbe97 Mon Sep 17 00:00:00 2001 From: Andreas Egger Date: Thu, 13 Jun 2013 21:22:43 +0200 Subject: [PATCH] Fixed bugs in scheduler B, adjusted C --- src/at/ac/tuwien/lsdc/sched/SchedulerB.java | 8 +---- src/at/ac/tuwien/lsdc/sched/SchedulerC.java | 38 ++++++++++++++++----- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/at/ac/tuwien/lsdc/sched/SchedulerB.java b/src/at/ac/tuwien/lsdc/sched/SchedulerB.java index 4bcdf61..949aa23 100644 --- a/src/at/ac/tuwien/lsdc/sched/SchedulerB.java +++ b/src/at/ac/tuwien/lsdc/sched/SchedulerB.java @@ -49,8 +49,6 @@ public class SchedulerB extends AbstractSchedulerWithMigration { boolean deployed = false; if (!vm.enoughResources(app)) { try { -// vm.resizeVM(vm.getSize() + app.getSize(), vm.getRAM() + app.getRam(), vm.getCPU() -// + app.getCpu()); vm.resizeUp(app); } catch (VMResizeException ex) { return false; @@ -74,10 +72,6 @@ public class SchedulerB extends AbstractSchedulerWithMigration { VirtualMachine vm = evt.getApp().getRunningOn(); evt.getApp().setRunningOn(null); vm.stopApplication(evt.getApp()); - -// vm.resizeVM(vm.getSize() - evt.getApp().getSize(), vm.getRAM() -// - evt.getApp().getRam(), vm.getCPU() - evt.getApp().getCpu()); - vm.resizeDown(evt.getApp()); if (vm.getApplications().size() == 0) { @@ -104,7 +98,7 @@ public class SchedulerB extends AbstractSchedulerWithMigration { List sortedPMs = manager.getSortedPMs(); Collections.reverse(sortedPMs); for (PhysicalMachine pm : sortedPMs) { - if (pm.isRunning() && (pm.getTotalVMs() > 0)) { + if (pm.isRunning() && (pm.countCurrentlyRunningVMs() > 0)) { vm = pm.getVirtualMachines().values().iterator().next(); deployed = deployApp(vm, evt.getApp()); if (deployed) diff --git a/src/at/ac/tuwien/lsdc/sched/SchedulerC.java b/src/at/ac/tuwien/lsdc/sched/SchedulerC.java index 1c594dd..173d353 100644 --- a/src/at/ac/tuwien/lsdc/sched/SchedulerC.java +++ b/src/at/ac/tuwien/lsdc/sched/SchedulerC.java @@ -10,6 +10,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.ac.tuwien.lsdc.exception.OutOfPMsException; +import at.ac.tuwien.lsdc.exception.VMResizeException; import at.ac.tuwien.lsdc.types.Application; import at.ac.tuwien.lsdc.types.PhysicalMachine; import at.ac.tuwien.lsdc.types.ScenarioType; @@ -28,18 +29,32 @@ public class SchedulerC extends AbstractSchedulerWithMigration { this.vmType = VMType.NonResizable; } - + @Override - protected String getSchedulerType() { - return SchedulerType.C.toString(); + protected boolean deployApp(VirtualMachine vm, Application app) { + boolean deployed = false; + if (!vm.enoughResources(app)) + return false; + + deployed = vm.startApplication(app); + if (deployed) + app.setRunningOn(vm); + return deployed; } + /** + * Cleanup completed apps. If an VM becomes empty, shut down VM + PM. + * + * @param events list of all events that happened in this timeslot. + */ @Override protected void handleEndEvents(LinkedList events) { LOG.debug("stopApps():" + events); for (SchedulerEvent evt : events) { VirtualMachine vm = evt.getApp().getRunningOn(); + evt.getApp().setRunningOn(null); vm.stopApplication(evt.getApp()); + if (vm.getApplications().size() == 0) { PhysicalMachine pm = vm.getRunningOn(); pm.stopVirtualMachine(vm); @@ -48,6 +63,13 @@ public class SchedulerC extends AbstractSchedulerWithMigration { } } + + /** + * Try to start all Apps. If not enough space start another PM, if not possible, + * delay start. + * + * @param events list of all events that happened in this timeslot. + */ @Override protected void handleStartEvents(LinkedList events) { LOG.debug("startApps():" + events); @@ -58,7 +80,7 @@ public class SchedulerC extends AbstractSchedulerWithMigration { List sortedPMs = manager.getSortedPMs(); Collections.reverse(sortedPMs); for (PhysicalMachine pm : sortedPMs) { - if (pm.isRunning() && (pm.getTotalVMs() > 0)) { + if (pm.isRunning() && (pm.countCurrentlyRunningVMs() > 0)) { vm = pm.getVirtualMachines().values().iterator().next(); deployed = deployApp(vm, evt.getApp()); if (deployed) @@ -67,7 +89,8 @@ public class SchedulerC extends AbstractSchedulerWithMigration { } if (!deployed) { try { - vm = manager.startPhysicalMachine().startVirtualMachine(vmType); + vm = manager.startPhysicalMachine().startVirtualMachine(evt.getApp().getSize(), + evt.getApp().getRam(), evt.getApp().getCpu(), vmType); deployed = deployApp(vm, evt.getApp()); } catch (OutOfPMsException e) { if (federation.askToOutsource(evt.getApp())) { @@ -82,12 +105,11 @@ public class SchedulerC extends AbstractSchedulerWithMigration { if (deployed) insertStopEvent(currTime + evt.getApp().getDuration(), evt.getApp()); } - } @Override - protected boolean deployApp(VirtualMachine vm, Application app) { - return vm.startApplication(app); + protected String getSchedulerType() { + return SchedulerType.C.toString(); } } -- 2.43.0