From f48accbc0aac6fa4e032a6266949d38490cef94e Mon Sep 17 00:00:00 2001 From: Andreas Egger Date: Wed, 22 May 2013 13:25:13 +0200 Subject: [PATCH] Scheduling working, still needs to be tested --- src/at/ac/tuwien/lsdc/SchedSimulator.java | 11 ++--- .../tuwien/lsdc/sched/AbstractScheduler.java | 18 +++----- src/at/ac/tuwien/lsdc/sched/SchedulerA.java | 43 +++++++++++++------ src/at/ac/tuwien/lsdc/sched/SchedulerB.java | 28 +++++++++--- src/at/ac/tuwien/lsdc/sched/SchedulerC.java | 25 +++++++++-- .../ac/tuwien/lsdc/types/PhysicalMachine.java | 2 +- .../ac/tuwien/lsdc/types/VirtualMachine.java | 11 ++++- src/at/ac/tuwien/lsdc/util/CSVLogger.java | 10 ++++- 8 files changed, 105 insertions(+), 43 deletions(-) diff --git a/src/at/ac/tuwien/lsdc/SchedSimulator.java b/src/at/ac/tuwien/lsdc/SchedSimulator.java index cd753c5..da542ab 100644 --- a/src/at/ac/tuwien/lsdc/SchedSimulator.java +++ b/src/at/ac/tuwien/lsdc/SchedSimulator.java @@ -52,18 +52,19 @@ public class SchedSimulator { log.info(USAGE); System.exit(1); } - log.info("TEST ================================="); LinkedList apps = CSVParser.parseFile(inputFile); - log.info("apps size = "+apps.size()); Collections.sort(apps); AbstractScheduler scheduler; switch (schedulerType) { case A: - scheduler = new SchedulerA(numPMs, numCloudPartners, schedulerLog, schedulerType, scenario); + scheduler = new SchedulerA(numPMs, numCloudPartners, schedulerLog, scenario); + break; case B: - scheduler = new SchedulerB(numPMs, numCloudPartners, schedulerLog, schedulerType, scenario); + scheduler = new SchedulerB(numPMs, numCloudPartners, schedulerLog, scenario); + break; default: - scheduler = new SchedulerC(numPMs, numCloudPartners, schedulerLog, schedulerType, scenario); + scheduler = new SchedulerC(numPMs, numCloudPartners, schedulerLog, scenario); + break; } ScenarioData data = scheduler.initAndStart(apps); CSVLogger logger = new CSVLogger(generalLog); diff --git a/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java b/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java index 2409d47..4d727f5 100644 --- a/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java +++ b/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java @@ -16,7 +16,6 @@ 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.SchedulerEvent.EventType; -import at.ac.tuwien.lsdc.types.SchedulerType; import at.ac.tuwien.lsdc.types.VirtualMachine.VMType; import at.ac.tuwien.lsdc.util.CSVLogger; @@ -27,7 +26,6 @@ public abstract class AbstractScheduler { // the following types are only needed for correct // log output - protected SchedulerType schedulerType; protected ScenarioType scenario; protected int numTotalInSourced; protected int numTotalOutSourced; @@ -55,11 +53,9 @@ public abstract class AbstractScheduler { protected long endTime; public AbstractScheduler(int numPMs, int numCloudPartners, - File schedulerLog, SchedulerType schedulerType, - ScenarioType scenario) throws IOException { + File schedulerLog, ScenarioType scenario) throws IOException { this.manager = new MachineManager(numPMs); this.schedulerLog = schedulerLog; - this.schedulerType = schedulerType; this.scenario = scenario; this.eventMap = new TreeMap>(); this.logger = new CSVLogger(schedulerLog); @@ -87,8 +83,9 @@ public abstract class AbstractScheduler { for (Application app : apps) { insertStartEvent(app.getTimestamp(), app); } + + endTime = apps.getLast().getTimestamp() + 1; - log.info("event map = " + eventMap.size()); startScheduling(); try { logger.close(); @@ -155,11 +152,11 @@ public abstract class AbstractScheduler { while (true) { if (eventMap.containsKey(currTime)) { LinkedList events = eventMap.get(currTime); - log.info(events.size() + " events at timestamp " + currTime); + // log.info(events.size() + " events at timestamp " + currTime); handleEvents(events); doStateLogging(); } - // advance Time to next Event + // advance Time to next step currTime++; if (currTime == endTime) { @@ -204,8 +201,5 @@ public abstract class AbstractScheduler { * * @return a ScenarioData Object that holds the values to be logged */ - protected ScenarioData doEndLogging() { - return new ScenarioData(schedulerType.toString(), scenario.toString(), - 1, 1, 1, 1, numTotalInSourced, numTotalOutSourced); - } + protected abstract ScenarioData doEndLogging(); } diff --git a/src/at/ac/tuwien/lsdc/sched/SchedulerA.java b/src/at/ac/tuwien/lsdc/sched/SchedulerA.java index c6bc7e2..eb1311f 100644 --- a/src/at/ac/tuwien/lsdc/sched/SchedulerA.java +++ b/src/at/ac/tuwien/lsdc/sched/SchedulerA.java @@ -14,6 +14,7 @@ import org.slf4j.LoggerFactory; import at.ac.tuwien.lsdc.exception.ActiveApplicationsException; import at.ac.tuwien.lsdc.types.Application; import at.ac.tuwien.lsdc.types.PhysicalMachine; +import at.ac.tuwien.lsdc.types.ScenarioData; import at.ac.tuwien.lsdc.types.ScenarioType; import at.ac.tuwien.lsdc.types.SchedulerEvent; import at.ac.tuwien.lsdc.types.SchedulerEvent.EventType; @@ -28,16 +29,14 @@ public class SchedulerA extends AbstractScheduler { private static final Logger log = LoggerFactory.getLogger(SchedulerA.class); public SchedulerA(int numPMs, int numCloudPartners, File schedulerLog, - SchedulerType schedulerType, ScenarioType scenario) - throws IOException { - super(numPMs, numCloudPartners, schedulerLog, schedulerType, scenario); + ScenarioType scenario) throws IOException { + super(numPMs, numCloudPartners, schedulerLog, scenario); this.vmType = VMType.NonResizable; } @Override protected void handleEvents(LinkedList events) { - for (SchedulerEvent evt : events) { if (evt.getType() == EventType.endApplication) { VirtualMachine vm = evt.getApp().getRunningOn(); @@ -45,6 +44,8 @@ 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()); } catch (ActiveApplicationsException e) { log.warn("VM " + vm.getId() + "could not be stopped, " + e.getMessage()); @@ -66,11 +67,12 @@ public class SchedulerA extends AbstractScheduler { app.getRam(), app.getCpu()); if (enoughResources) { - pm.startVirtualMachine(app.getSize(), app.getRam(), + VirtualMachine vm = pm.startVirtualMachine(app.getSize(), app.getRam(), app.getCpu(), vmType); + vm.startApplication(app); insertStopEvent(currTime + app.getDuration(), app); appDeployed = true; - log.debug("Application " + app.toString() + log.info("Application " + app.toString() + " started on new pm " + pm.getId()); } else { log.warn("Application " + app.toString() @@ -80,13 +82,14 @@ public class SchedulerA extends AbstractScheduler { // sorting physical machines by resource utilization // (descending) List sortedPMs = sortPMs(); - - for (Iterator it = sortedPMs.iterator(); iter + + 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(), @@ -94,8 +97,8 @@ public class SchedulerA extends AbstractScheduler { vm.startApplication(app); insertStopEvent(currTime + app.getDuration(), app); appDeployed = true; - log.debug("Application " + app.toString() - + " started on new pm " + pm.getId()); + log.info("Application " + app.toString() + + " started new vm " +vm.getPositionOnPM()+" on pm "+ pm.getId()); break; } } @@ -113,7 +116,7 @@ public class SchedulerA extends AbstractScheduler { vm.startApplication(app); insertStopEvent(currTime + app.getDuration(), app); appDeployed = true; - log.debug("Application " + app.toString() + log.info("Application " + app.toString() + " started on new pm " + pm.getId()); } else { log.warn("Application " + app.toString() @@ -143,12 +146,26 @@ public class SchedulerA extends AbstractScheduler { // sorting physical machines by resource utilization (descending) private List sortPMs() { List sortedPMs = new LinkedList(); - for (PhysicalMachine pm : manager.getPMs()) + for (PhysicalMachine pm : manager.getPMs()) { sortedPMs.add(new SortedPhysicalMachine(pm)); + // 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); + } } diff --git a/src/at/ac/tuwien/lsdc/sched/SchedulerB.java b/src/at/ac/tuwien/lsdc/sched/SchedulerB.java index 9f3bf9c..33ae99a 100644 --- a/src/at/ac/tuwien/lsdc/sched/SchedulerB.java +++ b/src/at/ac/tuwien/lsdc/sched/SchedulerB.java @@ -4,6 +4,10 @@ import java.io.File; import java.io.IOException; import java.util.LinkedList; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.ac.tuwien.lsdc.types.ScenarioData; import at.ac.tuwien.lsdc.types.ScenarioType; import at.ac.tuwien.lsdc.types.SchedulerEvent; import at.ac.tuwien.lsdc.types.SchedulerType; @@ -11,16 +15,30 @@ import at.ac.tuwien.lsdc.types.SchedulerType; public class SchedulerB extends AbstractScheduler { - public SchedulerB(int numPMs, int numCloudPartners, File schedulerLog, - SchedulerType schedulerType, ScenarioType scenario) - throws IOException { - super(numPMs, numCloudPartners, schedulerLog, schedulerType, scenario); + private static final Logger log = LoggerFactory.getLogger(SchedulerB.class); + + public SchedulerB(int numPMs, int numCloudPartners, File schedulerLog, + ScenarioType scenario) throws IOException { + super(numPMs, numCloudPartners, schedulerLog, scenario); } @Override protected void handleEvents(LinkedList events) { // TODO Auto-generated method stub - + 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); } } diff --git a/src/at/ac/tuwien/lsdc/sched/SchedulerC.java b/src/at/ac/tuwien/lsdc/sched/SchedulerC.java index 73c8a41..845b4f7 100644 --- a/src/at/ac/tuwien/lsdc/sched/SchedulerC.java +++ b/src/at/ac/tuwien/lsdc/sched/SchedulerC.java @@ -4,6 +4,10 @@ import java.io.File; import java.io.IOException; import java.util.LinkedList; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.ac.tuwien.lsdc.types.ScenarioData; import at.ac.tuwien.lsdc.types.ScenarioType; import at.ac.tuwien.lsdc.types.SchedulerEvent; import at.ac.tuwien.lsdc.types.SchedulerType; @@ -11,16 +15,29 @@ import at.ac.tuwien.lsdc.types.SchedulerType; public class SchedulerC extends AbstractScheduler { + private static final Logger log = LoggerFactory.getLogger(SchedulerC.class); + public SchedulerC(int numPMs, int numCloudPartners, File schedulerLog, - SchedulerType schedulerType, ScenarioType scenario) - throws IOException { - super(numPMs, numCloudPartners, schedulerLog, schedulerType, scenario); + ScenarioType scenario) throws IOException { + super(numPMs, numCloudPartners, schedulerLog, scenario); } @Override protected void handleEvents(LinkedList events) { // TODO Auto-generated method stub - + 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); } } diff --git a/src/at/ac/tuwien/lsdc/types/PhysicalMachine.java b/src/at/ac/tuwien/lsdc/types/PhysicalMachine.java index be3f25f..8ebedf2 100644 --- a/src/at/ac/tuwien/lsdc/types/PhysicalMachine.java +++ b/src/at/ac/tuwien/lsdc/types/PhysicalMachine.java @@ -13,7 +13,7 @@ public class PhysicalMachine { private HashMap VMs = new HashMap(); private int id; - + private final int maxSize = 50000; private final int maxRAM = 4700; private final int maxCPU = 2400; diff --git a/src/at/ac/tuwien/lsdc/types/VirtualMachine.java b/src/at/ac/tuwien/lsdc/types/VirtualMachine.java index ae9c680..25933eb 100644 --- a/src/at/ac/tuwien/lsdc/types/VirtualMachine.java +++ b/src/at/ac/tuwien/lsdc/types/VirtualMachine.java @@ -11,7 +11,8 @@ public class VirtualMachine { private static int count = 0; - + private int posOnPM; + private PhysicalMachine runningOn; private HashMap applications = new HashMap(); @@ -35,18 +36,21 @@ public class VirtualMachine { this.RAM = RAM + initialRAM; this.CPU = CPU + initialCPU; this.runningOn = pm; + this.posOnPM = pm.countCurrentlyRunningVMs(); this.type = type; } public boolean startApplication(Application app) { if (enoughResources(app)) { applications.put(app.getID(), app); + app.setRunningOn(this); return true; } else if (type == VMType.Resizable && runningOn.checkVM(app.getSize(), app.getRam(), app.getCpu())) { applications.put(app.getID(), app); size = size + app.getSize(); RAM = RAM + app.getRam(); CPU = CPU + app.getCpu(); + app.setRunningOn(this); return true; } else return false; @@ -58,6 +62,7 @@ public class VirtualMachine { RAM = RAM - app.getRam(); CPU = CPU - app.getCpu(); applications.remove(app.getID()); + app.setRunningOn(null); return true; } else return false; @@ -88,6 +93,10 @@ public class VirtualMachine { public PhysicalMachine getRunningOn() { return runningOn; } + + public int getPositionOnPM() { + return posOnPM; + } public ArrayList getApplications() { return new ArrayList(applications.values()); diff --git a/src/at/ac/tuwien/lsdc/util/CSVLogger.java b/src/at/ac/tuwien/lsdc/util/CSVLogger.java index 291a91a..1e8e47a 100644 --- a/src/at/ac/tuwien/lsdc/util/CSVLogger.java +++ b/src/at/ac/tuwien/lsdc/util/CSVLogger.java @@ -12,25 +12,31 @@ public class CSVLogger { private CSVWriter writer; private File file; + boolean scenarioHeaderExists; + boolean schedulerHeaderExists; public CSVLogger(File file) throws IOException { this.file = file; this.writer = new CSVWriter(new FileWriter(file), ';', CSVWriter.NO_QUOTE_CHARACTER); + this.scenarioHeaderExists = false; + this.schedulerHeaderExists = false; } public void logScenarioData(ScenarioData data) throws IOException { - if (file.length() == 0) { + if (!scenarioHeaderExists) { writeScenarioDataHeader(); + scenarioHeaderExists = true; } writer.writeNext(data.toStringArray()); } public void logSchedulerData(SchedulerData data) throws IOException { - if (file.length() == 0) { + if (!schedulerHeaderExists) { writeSchedulerDataHeader(); + schedulerHeaderExists = true; } writer.writeNext(data.toStringArray()); } -- 2.43.0