From 459cd945849fd8e9480ef8e253ee85b1d529df21 Mon Sep 17 00:00:00 2001 From: Stefan Derkits Date: Wed, 22 May 2013 22:00:11 +0200 Subject: [PATCH] shutdown PMs, fixed a small (but important) bug in AbstractScheduler --- .../tuwien/lsdc/sched/AbstractScheduler.java | 2 +- src/at/ac/tuwien/lsdc/sched/SchedulerA.java | 45 ++++++++++++------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java b/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java index 83de1ad..aae7694 100644 --- a/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java +++ b/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java @@ -159,7 +159,7 @@ public abstract class AbstractScheduler { // advance Time to next step currTime++; - if (currTime == endTime) { + if (currTime > endTime) { // reached last Event, Scheduler will shut down log.info("Last event reached at time " + currTime); break; diff --git a/src/at/ac/tuwien/lsdc/sched/SchedulerA.java b/src/at/ac/tuwien/lsdc/sched/SchedulerA.java index eb1311f..535b3f7 100644 --- a/src/at/ac/tuwien/lsdc/sched/SchedulerA.java +++ b/src/at/ac/tuwien/lsdc/sched/SchedulerA.java @@ -12,6 +12,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.ac.tuwien.lsdc.exception.ActiveApplicationsException; +import at.ac.tuwien.lsdc.exception.VMsRunningException; import at.ac.tuwien.lsdc.types.Application; import at.ac.tuwien.lsdc.types.PhysicalMachine; import at.ac.tuwien.lsdc.types.ScenarioData; @@ -29,7 +30,7 @@ public class SchedulerA extends AbstractScheduler { private static final Logger log = LoggerFactory.getLogger(SchedulerA.class); public SchedulerA(int numPMs, int numCloudPartners, File schedulerLog, - ScenarioType scenario) throws IOException { + ScenarioType scenario) throws IOException { super(numPMs, numCloudPartners, schedulerLog, scenario); this.vmType = VMType.NonResizable; @@ -44,8 +45,18 @@ public class SchedulerA extends AbstractScheduler { PhysicalMachine pm = vm.getRunningOn(); try { pm.stopVirtualMachine(vm); - log.info("application stopped at timestamp "+currTime+", " + - "vm "+vm.getPositionOnPM()+", pm "+pm.getId()); + if (pm.countCurrentlyRunningVMs() == 0) { + try { + manager.stopPhysicalMachine(pm.getId()); + } catch (VMsRunningException e) { + log.warn("PM " + pm.getId() + + " could not be stopped, " + + e.getMessage()); + } + } + log.info("application stopped at timestamp " + currTime + + ", " + "vm " + vm.getPositionOnPM() + ", pm " + + pm.getId()); } catch (ActiveApplicationsException e) { log.warn("VM " + vm.getId() + "could not be stopped, " + e.getMessage()); @@ -67,8 +78,8 @@ public class SchedulerA extends AbstractScheduler { app.getRam(), app.getCpu()); if (enoughResources) { - VirtualMachine vm = pm.startVirtualMachine(app.getSize(), app.getRam(), - app.getCpu(), vmType); + VirtualMachine vm = pm.startVirtualMachine(app.getSize(), + app.getRam(), app.getCpu(), vmType); vm.startApplication(app); insertStopEvent(currTime + app.getDuration(), app); appDeployed = true; @@ -82,14 +93,14 @@ public class SchedulerA extends AbstractScheduler { // sorting physical machines by resource utilization // (descending) List sortedPMs = sortPMs(); - + for (Iterator it = sortedPMs.iterator(); it .hasNext();) { - + PhysicalMachine pm = it.next().getPm(); boolean enoughResources = pm.checkVM(app.getSize(), app.getRam(), app.getCpu()); - + if (enoughResources) { VirtualMachine vm = pm.startVirtualMachine( app.getSize(), app.getRam(), app.getCpu(), @@ -98,7 +109,8 @@ public class SchedulerA extends AbstractScheduler { insertStopEvent(currTime + app.getDuration(), app); appDeployed = true; log.info("Application " + app.toString() - + " started new vm " +vm.getPositionOnPM()+" on pm "+ pm.getId()); + + " started new vm " + vm.getPositionOnPM() + + " on pm " + pm.getId()); break; } } @@ -127,7 +139,8 @@ public class SchedulerA extends AbstractScheduler { if (!appDeployed) log.warn("Application " + app.toString() + " could not be deployed on any pm"); - //TODO: save app in a List and try to deploy with next handled events + // TODO: save app in a List and try to deploy with next handled + // events } } @@ -148,24 +161,24 @@ public class SchedulerA extends AbstractScheduler { List sortedPMs = new LinkedList(); for (PhysicalMachine pm : manager.getPMs()) { sortedPMs.add(new SortedPhysicalMachine(pm)); - // log.info("pm util = "+pm.getAverageUtilization()); + // log.info("pm util = "+pm.getAverageUtilization()); } Collections.sort(sortedPMs); Collections.reverse(sortedPMs); return sortedPMs; } - - + /** * this creates the total summary which should be written to a CSV at the * end - * + * * @return a ScenarioData Object that holds the values to be logged */ protected ScenarioData doEndLogging() { - return new ScenarioData(SchedulerType.A.toString(), scenario.toString(), - 1, 1, 1, 1, numTotalInSourced, numTotalOutSourced); + return new ScenarioData(SchedulerType.A.toString(), + scenario.toString(), 1, 1, 1, 1, numTotalInSourced, + numTotalOutSourced); } } -- 2.43.0