From ae343a53645194e62000f12431c785657f2fd3b5 Mon Sep 17 00:00:00 2001 From: Stefan Derkits Date: Thu, 23 May 2013 13:15:24 +0200 Subject: [PATCH] implemented end-logging --- src/at/ac/tuwien/lsdc/SchedSimulator.java | 2 +- .../tuwien/lsdc/management/MachineManager.java | 16 +++++++++++++++- .../ac/tuwien/lsdc/sched/AbstractScheduler.java | 16 ++++++++++++---- src/at/ac/tuwien/lsdc/sched/SchedulerA.java | 15 ++++----------- src/at/ac/tuwien/lsdc/sched/SchedulerB.java | 12 ++---------- src/at/ac/tuwien/lsdc/sched/SchedulerC.java | 11 ++--------- src/at/ac/tuwien/lsdc/types/PhysicalMachine.java | 6 ++++++ 7 files changed, 42 insertions(+), 36 deletions(-) diff --git a/src/at/ac/tuwien/lsdc/SchedSimulator.java b/src/at/ac/tuwien/lsdc/SchedSimulator.java index da542ab..8d9a46c 100644 --- a/src/at/ac/tuwien/lsdc/SchedSimulator.java +++ b/src/at/ac/tuwien/lsdc/SchedSimulator.java @@ -68,7 +68,7 @@ public class SchedSimulator { } ScenarioData data = scheduler.initAndStart(apps); CSVLogger logger = new CSVLogger(generalLog); -// logger.logScenarioData(data); + logger.logScenarioData(data); logger.close(); } diff --git a/src/at/ac/tuwien/lsdc/management/MachineManager.java b/src/at/ac/tuwien/lsdc/management/MachineManager.java index 2e304df..9b23ba5 100644 --- a/src/at/ac/tuwien/lsdc/management/MachineManager.java +++ b/src/at/ac/tuwien/lsdc/management/MachineManager.java @@ -17,6 +17,9 @@ public class MachineManager { private HashMap PMs = new HashMap(); private int numPMs; + + private int totalPMs = 0; + private int totalVMs = 0; public MachineManager(int numPMs) { this.numPMs = numPMs; @@ -32,6 +35,7 @@ public class MachineManager { PhysicalMachine pm = new PhysicalMachine(); PMs.put(pm.getId(), pm); pm.start(); + totalPMs++; return pm; } return null; @@ -47,7 +51,9 @@ public class MachineManager { */ public void stopPhysicalMachine(int id) throws VMsRunningException { if (PMs.containsKey(id)) { - PMs.get(id).stop(); + PhysicalMachine pm = PMs.get(id); + totalVMs += pm.getTotalVMs(); + pm.stop(); PMs.remove(id); } } @@ -155,4 +161,12 @@ public class MachineManager { } return running; } + + public int getTotalPMs() { + return totalPMs; + } + + public int getTotalVMs() { + return totalVMs; + } } diff --git a/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java b/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java index 54f8840..65ac7b7 100644 --- a/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java +++ b/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java @@ -15,9 +15,11 @@ import at.ac.tuwien.lsdc.types.ScenarioData; import at.ac.tuwien.lsdc.types.ScenarioType; import at.ac.tuwien.lsdc.types.SchedulerData; import at.ac.tuwien.lsdc.types.SchedulerEvent; +import at.ac.tuwien.lsdc.types.SchedulerType; import at.ac.tuwien.lsdc.types.SchedulerEvent.EventType; import at.ac.tuwien.lsdc.types.VirtualMachine.VMType; import at.ac.tuwien.lsdc.util.CSVLogger; +import at.ac.tuwien.lsdc.util.NumberUtils; public abstract class AbstractScheduler { @@ -93,8 +95,7 @@ public abstract class AbstractScheduler { log.error("couldn't close logger"); } // TODO make end logging work - return null; - // return doEndLogging(); + return doEndLogging(); } /** @@ -203,8 +204,15 @@ public abstract class AbstractScheduler { /** * 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 abstract ScenarioData doEndLogging(); + protected ScenarioData doEndLogging() { + return new ScenarioData(getSchedulerType(), + scenario.toString(), manager.getTotalPMs(), manager.getTotalVMs(), endTime, NumberUtils.roundDouble(totalConsumption), numTotalInSourced, + numTotalOutSourced); + } + + protected abstract String getSchedulerType(); + } diff --git a/src/at/ac/tuwien/lsdc/sched/SchedulerA.java b/src/at/ac/tuwien/lsdc/sched/SchedulerA.java index 535b3f7..a4c6eb2 100644 --- a/src/at/ac/tuwien/lsdc/sched/SchedulerA.java +++ b/src/at/ac/tuwien/lsdc/sched/SchedulerA.java @@ -168,17 +168,10 @@ public class SchedulerA extends AbstractScheduler { 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); + + @Override + protected String getSchedulerType() { + return SchedulerType.A.toString(); } } diff --git a/src/at/ac/tuwien/lsdc/sched/SchedulerB.java b/src/at/ac/tuwien/lsdc/sched/SchedulerB.java index 33ae99a..cf985f2 100644 --- a/src/at/ac/tuwien/lsdc/sched/SchedulerB.java +++ b/src/at/ac/tuwien/lsdc/sched/SchedulerB.java @@ -28,17 +28,9 @@ public class SchedulerB extends AbstractScheduler { log.info("Sched B handle events"); } - - /** - * 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 - */ @Override - protected ScenarioData doEndLogging() { - return new ScenarioData(SchedulerType.B.toString(), scenario.toString(), - 1, 1, 1, 1, numTotalInSourced, numTotalOutSourced); + protected String getSchedulerType() { + return SchedulerType.B.toString(); } } diff --git a/src/at/ac/tuwien/lsdc/sched/SchedulerC.java b/src/at/ac/tuwien/lsdc/sched/SchedulerC.java index 845b4f7..e44fedf 100644 --- a/src/at/ac/tuwien/lsdc/sched/SchedulerC.java +++ b/src/at/ac/tuwien/lsdc/sched/SchedulerC.java @@ -28,16 +28,9 @@ public class SchedulerC extends AbstractScheduler { log.info("Sched C handle Events"); } - /** - * 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 - */ @Override - protected ScenarioData doEndLogging() { - return new ScenarioData(SchedulerType.C.toString(), scenario.toString(), - 1, 1, 1, 1, numTotalInSourced, numTotalOutSourced); + protected String getSchedulerType() { + return SchedulerType.C.toString(); } } diff --git a/src/at/ac/tuwien/lsdc/types/PhysicalMachine.java b/src/at/ac/tuwien/lsdc/types/PhysicalMachine.java index caf9901..f8a268d 100644 --- a/src/at/ac/tuwien/lsdc/types/PhysicalMachine.java +++ b/src/at/ac/tuwien/lsdc/types/PhysicalMachine.java @@ -25,6 +25,8 @@ public class PhysicalMachine { private final int initialSize = 850; private final int initialRAM = 300; private final int initialCPU = 500; + + private int totalVMs = 0; private boolean running = false; @@ -67,6 +69,7 @@ public class PhysicalMachine { reservedSize = reservedSize + vm.getReservedSize(); reservedRAM = reservedRAM + vm.getReservedRAM(); reservedCPU = reservedCPU + vm.getReservedCPU(); + totalVMs++; return vm; } else return null; @@ -170,4 +173,7 @@ public class PhysicalMachine { return reservedCPU; } + public int getTotalVMs() { + return totalVMs; + } } -- 2.43.0