From 77697dd8a7a76121fd9bbf52b5a42c2fafe525e3 Mon Sep 17 00:00:00 2001 From: Stefan Derkits Date: Tue, 11 Jun 2013 12:37:14 +0200 Subject: [PATCH] Big changes: change EventMap, move the stop/stopOutsourced/delayed/start/startOutsourced cylce into AbstractScheduler, remove SortedApp & SortedPhysicalMachine --- .../tuwien/lsdc/sched/AbstractScheduler.java | 96 +++++------ src/at/ac/tuwien/lsdc/sched/SchedulerA.java | 151 +++++++++--------- src/at/ac/tuwien/lsdc/sched/SchedulerB.java | 113 ++++++------- src/at/ac/tuwien/lsdc/sched/SchedulerC.java | 34 ++-- src/at/ac/tuwien/lsdc/types/Application.java | 9 +- .../types/ApplicationResourceComparator.java | 27 ++++ .../ac/tuwien/lsdc/types/PhysicalMachine.java | 52 +++--- .../tuwien/lsdc/types/SortedApplication.java | 38 ----- .../lsdc/types/SortedPhysicalMachine.java | 32 ---- 9 files changed, 263 insertions(+), 289 deletions(-) create mode 100644 src/at/ac/tuwien/lsdc/types/ApplicationResourceComparator.java delete mode 100644 src/at/ac/tuwien/lsdc/types/SortedApplication.java delete mode 100644 src/at/ac/tuwien/lsdc/types/SortedPhysicalMachine.java diff --git a/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java b/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java index e2eb2be..fc0109c 100644 --- a/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java +++ b/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java @@ -3,6 +3,7 @@ package at.ac.tuwien.lsdc.sched; import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.LinkedList; import java.util.SortedMap; import java.util.TreeMap; @@ -50,7 +51,7 @@ public abstract class AbstractScheduler { * this map saves the following Type of Events: start of an Application, end of an * Application(start outSourced, end outSourced, start inSourced, end inSourced) */ - protected SortedMap> eventMap; + protected SortedMap>> eventMap; /** * Scheduler has an internal Time "Abstraction" at every point in time it checks for Events in @@ -73,7 +74,7 @@ public abstract class AbstractScheduler { manager = new MachineManager(numPMs); this.schedulerLog = schedulerLog; this.scenario = scenario; - eventMap = new TreeMap>(); + eventMap = new TreeMap>>(); logger = new CSVLogger(schedulerLog); federation = new Federation(numCloudPartners); delayedApps = new ArrayList(); @@ -96,57 +97,36 @@ public abstract class AbstractScheduler { /** * Insert a start event into the map, at timestamp when the application should start - * + * * @param timestamp the timestamp when the application should start * @param app the application to start */ protected void insertStartEvent(long timestamp, Application app) { SchedulerEvent evt = new SchedulerEvent(timestamp, EventType.startApplication, app); - if (!eventMap.containsKey(timestamp)) { - LinkedList list = new LinkedList(); - list.add(evt); - eventMap.put(timestamp, list); - } else { - LinkedList list = eventMap.get(timestamp); - list.add(evt); - } + insertEvent(evt); } /** * Insert a start outsourced event into the map, at timestamp when the application should start - * + * * @param timestamp the timestamp when the application should start * @param app the application to start */ protected void insertOutsourcedStartEvent(long timestamp, Application app) { SchedulerEvent evt = new SchedulerEvent(timestamp, EventType.startOutsourcedApplication, app); - if (!eventMap.containsKey(timestamp)) { - LinkedList list = new LinkedList(); - list.add(evt); - eventMap.put(timestamp, list); - } else { - LinkedList list = eventMap.get(timestamp); - list.add(evt); - } + insertEvent(evt); } /** * Insert a stop event into the map, at timestamp when the application should stop. - * + * * @param timestamp the timestamp when the application should stop * @param app the application to stop */ protected void insertStopEvent(long timestamp, Application app) { SchedulerEvent evt = new SchedulerEvent(timestamp, EventType.endApplication, app); - if (!eventMap.containsKey(timestamp)) { - LinkedList list = new LinkedList(); - list.add(evt); - eventMap.put(timestamp, list); - } else { - LinkedList list = eventMap.get(timestamp); - list.add(evt); - } + insertEvent(evt); if (endTime < timestamp) { endTime = timestamp; } @@ -154,25 +134,33 @@ public abstract class AbstractScheduler { /** * Insert a stop event into the map, at timestamp when the application should stop. - * + * * @param timestamp the timestamp when the application should stop * @param app the application to stop */ protected void insertOutsourcedStopEvent(long timestamp, Application app) { SchedulerEvent evt = new SchedulerEvent(timestamp, EventType.endOutsourcedApplication, app); - if (!eventMap.containsKey(timestamp)) { - LinkedList list = new LinkedList(); - list.add(evt); - eventMap.put(timestamp, list); - } else { - LinkedList list = eventMap.get(timestamp); - list.add(evt); - } + insertEvent(evt); if (endTime < timestamp) { endTime = timestamp; } } + private void insertEvent(SchedulerEvent evt) { + LinkedList list; + if (!eventMap.containsKey(evt.getTimestamp())) { + HashMap> map = new HashMap>(); + eventMap.put(evt.getTimestamp(), map); + } + if (!eventMap.get(evt.getTimestamp()).containsKey(evt.getType())) { + list = new LinkedList(); + eventMap.get(evt.getTimestamp()).put(evt.getType(), list); + } else { + list = eventMap.get(evt.getTimestamp()).get(evt.getType()); + } + list.add(evt); + } + /** * Start the actual scheduling algorithm. Each scheduler will implement the method handleEvents * differently @@ -180,9 +168,8 @@ public abstract class AbstractScheduler { protected void startScheduling() { while (true) { if (eventMap.containsKey(currTime)) { - LinkedList events = eventMap.get(currTime); // log.info(events.size() + " events at timestamp " + currTime); - handleEvents(events); + handleEvents(eventMap.get(currTime)); } doStateLogging(); // advance Time to next step @@ -199,14 +186,33 @@ public abstract class AbstractScheduler { /** * this method is where the Scheduling Algorithm resides it reads the Events (start & stop of * applications) - * + * * @param events the events to be read and used by the scheduler */ - protected abstract void handleEvents(LinkedList events); + private void handleEvents(HashMap> events) { + if (events.containsKey(EventType.endApplication)) + handleEndEvents(events.get(EventType.endApplication)); + if (events.containsKey(EventType.endOutsourcedApplication)) + handleOutsourcedEndEvents(events.get(EventType.endOutsourcedApplication)); + handleDelayedApps(); + if (events.containsKey(EventType.startOutsourcedApplication)) + handleOutsourcedStartEvents(events.get(EventType.startOutsourcedApplication)); + if (events.containsKey(EventType.startApplication)) + handleStartEvents(events.get(EventType.startApplication)); + runMigration(); + } + + protected abstract void handleEndEvents(LinkedList events); + + protected abstract void handleDelayedApps(); + + protected abstract void handleStartEvents(LinkedList events); + + protected abstract void runMigration(); /** * handle running of outsourced apps. - * + * * @param events list of all events that happened in this timeslot. */ protected void handleOutsourcedStartEvents(LinkedList events) { @@ -221,7 +227,7 @@ public abstract class AbstractScheduler { /** * handle stopping of outsourced apps. - * + * * @param events list of all events that happened in this timeslot. */ protected void handleOutsourcedEndEvents(LinkedList events) { @@ -251,7 +257,7 @@ 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 ScenarioData doEndLogging() { diff --git a/src/at/ac/tuwien/lsdc/sched/SchedulerA.java b/src/at/ac/tuwien/lsdc/sched/SchedulerA.java index a4c6eb2..3a0c479 100644 --- a/src/at/ac/tuwien/lsdc/sched/SchedulerA.java +++ b/src/at/ac/tuwien/lsdc/sched/SchedulerA.java @@ -2,11 +2,9 @@ package at.ac.tuwien.lsdc.sched; import java.io.File; import java.io.IOException; - -import java.util.Iterator; +import java.util.Collections; import java.util.LinkedList; import java.util.List; -import java.util.Collections; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -14,14 +12,11 @@ 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.ApplicationResourceComparator; 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; import at.ac.tuwien.lsdc.types.SchedulerType; -import at.ac.tuwien.lsdc.types.SortedApplication; -import at.ac.tuwien.lsdc.types.SortedPhysicalMachine; import at.ac.tuwien.lsdc.types.VirtualMachine; import at.ac.tuwien.lsdc.types.VirtualMachine.VMType; @@ -29,138 +24,138 @@ 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 { + public SchedulerA(int numPMs, int numCloudPartners, File schedulerLog, ScenarioType scenario) + throws IOException { super(numPMs, numCloudPartners, schedulerLog, scenario); this.vmType = VMType.NonResizable; } @Override - protected void handleEvents(LinkedList events) { + protected void handleEndEvents(LinkedList events) { for (SchedulerEvent evt : events) { - if (evt.getType() == EventType.endApplication) { - VirtualMachine vm = evt.getApp().getRunningOn(); - vm.stopApplication(evt.getApp()); - PhysicalMachine pm = vm.getRunningOn(); - try { - pm.stopVirtualMachine(vm); - if (pm.countCurrentlyRunningVMs() == 0) { - try { - manager.stopPhysicalMachine(pm.getId()); - } catch (VMsRunningException e) { - log.warn("PM " + pm.getId() - + " could not be stopped, " - + e.getMessage()); - } + VirtualMachine vm = evt.getApp().getRunningOn(); + vm.stopApplication(evt.getApp()); + PhysicalMachine pm = vm.getRunningOn(); + try { + pm.stopVirtualMachine(vm); + 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()); } + 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()); } } + } + + @Override + protected void handleDelayedApps() { + // TODO Auto-generated method stub + + } + @Override + protected void handleStartEvents(LinkedList events) { // sorting applications by amount of resources (descending) - List sortedApps = sortApps(events); + List sortedApps = sortApps(events); - for (Iterator iter = sortedApps.iterator(); iter - .hasNext();) { + for (Application app : sortedApps) { boolean appDeployed = false; - Application app = iter.next().getApp(); if (manager.getPMs().size() == 0) { PhysicalMachine pm = manager.startPhysicalMachine(); - boolean enoughResources = pm.checkVM(app.getSize(), - app.getRam(), app.getCpu()); + boolean enoughResources = pm.checkVM(app.getSize(), 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; - log.info("Application " + app.toString() - + " started on new pm " + pm.getId()); + 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 empty pm " + + pm.getId()); } } else { // sorting physical machines by resource utilization // (descending) - List sortedPMs = sortPMs(); + List sortedPMs = sortPMs(); - for (Iterator it = sortedPMs.iterator(); it - .hasNext();) { + for (PhysicalMachine pm : sortedPMs) { - PhysicalMachine pm = it.next().getPm(); - boolean enoughResources = pm.checkVM(app.getSize(), - app.getRam(), app.getCpu()); + boolean enoughResources = pm.checkVM(app.getSize(), 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; - log.info("Application " + app.toString() - + " started new vm " + vm.getPositionOnPM() - + " on pm " + pm.getId()); + log.info("Application " + app.toString() + " started new vm " + + vm.getPositionOnPM() + " on pm " + pm.getId()); break; } } - if (!appDeployed - && (manager.getPMs().size() < manager.getMaxPMs())) { + if (!appDeployed && (manager.getPMs().size() < manager.getMaxPMs())) { PhysicalMachine pm = manager.startPhysicalMachine(); - boolean enoughResources = pm.checkVM(app.getSize(), - app.getRam(), app.getCpu()); + boolean enoughResources = pm.checkVM(app.getSize(), 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; - log.info("Application " + app.toString() - + " started on new pm " + pm.getId()); + 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 empty pm " + + pm.getId()); } } } + if (!appDeployed) { + if (federation.askToOutsource(app)) { + insertOutsourcedStartEvent(currTime + 1, app); + appDeployed = true; + } else + delayedApps.add(app); + } 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 + log.warn("Application " + app.toString() + " could not be deployed on any pm"); } + + } + + @Override + protected void runMigration() { + // Scheduler A doesn't support Migration, nothing to do here } // sorting applications by amount of resources (descending) - private List sortApps(LinkedList events) { - List sortedApps = new LinkedList(); + private List sortApps(LinkedList events) { + List sortedApps = new LinkedList(); for (SchedulerEvent evt : events) { - if (evt.getType() == EventType.startApplication) - sortedApps.add(new SortedApplication(evt.getApp())); + sortedApps.add(evt.getApp()); } - Collections.sort(sortedApps); + Collections.sort(sortedApps, new ApplicationResourceComparator()); Collections.reverse(sortedApps); return sortedApps; } // sorting physical machines by resource utilization (descending) - private List sortPMs() { - List sortedPMs = new LinkedList(); + private List sortPMs() { + List sortedPMs = new LinkedList(); for (PhysicalMachine pm : manager.getPMs()) { - sortedPMs.add(new SortedPhysicalMachine(pm)); + sortedPMs.add(pm); // log.info("pm util = "+pm.getAverageUtilization()); } @@ -168,7 +163,7 @@ public class SchedulerA extends AbstractScheduler { Collections.reverse(sortedPMs); return sortedPMs; } - + @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 d1f7d0a..e71a990 100644 --- a/src/at/ac/tuwien/lsdc/sched/SchedulerB.java +++ b/src/at/ac/tuwien/lsdc/sched/SchedulerB.java @@ -13,23 +13,22 @@ import at.ac.tuwien.lsdc.types.Application; import at.ac.tuwien.lsdc.types.PhysicalMachine; import at.ac.tuwien.lsdc.types.ScenarioType; 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; import at.ac.tuwien.lsdc.types.VirtualMachine.VMType; /** * Scheduler B. - * + * * Initial State: All PMs switched off. If an application arrives, try to modify size, CPU and RAM * of an existing VM to run the application. If no VM is running, create a new one (start a new PM * if necessary). If the application has finished decrease the size, CPU and RAM of the VM. If no * applications are running on a VM, shut down the VM. If no VM is running on a PM, shut down the * PM. Try to get a maximum of utilization on every PM. Migration: Try to move applications from VMs * to other VMs to get a better utilization and to use less PMs. - * + * * @author jan - * + * */ public class SchedulerB extends AbstractScheduler { /** @@ -43,21 +42,11 @@ public class SchedulerB extends AbstractScheduler { vmType = VMType.Resizable; } - @Override - protected void handleEvents(LinkedList events) { - LOG.debug("handleEvents():" + events); - handleEndEvents(events); - handleOutsourcedEndEvents(events); - runMigration(); - runDelayedApps(); - handleOutsourcedStartEvents(events); - handleStartEvents(events); - } - /** * Check if we have any delayed apps. Try to launch them. */ - private void runDelayedApps() { + @Override + protected void handleDelayedApps() { // TODO: probably mostly the same code as handleStartEvents // TOOD: (namely: use case: "start an application",do merge it for (Application app : delayedApps) { @@ -97,33 +86,33 @@ public class SchedulerB extends AbstractScheduler { /** * Check if we can free up a VM to shut it down. */ - private void runMigration() { + @Override + protected void runMigration() { // TODO Auto-generated method stub } /** * Cleanup completed apps. Downsize VMs and 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) { - if (evt.getType() == EventType.endApplication) { - VirtualMachine vm = evt.getApp().getRunningOn(); - evt.getApp().setRunningOn(null); - vm.stopApplication(evt.getApp()); - try { - vm.resizeVM(vm.getSize() - evt.getApp().getSize(), vm.getRAM() - - evt.getApp().getRam(), vm.getCPU() - evt.getApp().getCpu()); - } catch (VMResizeException e) { - // LOG.error("failed to resize VM: " + e.getVm(), e); - } - if (vm.getApplications().size() == 0) { - PhysicalMachine pm = vm.getRunningOn(); - pm.stopVirtualMachine(vm); - manager.stopPhysicalMachine(pm.getId()); - } + VirtualMachine vm = evt.getApp().getRunningOn(); + evt.getApp().setRunningOn(null); + vm.stopApplication(evt.getApp()); + try { + vm.resizeVM(vm.getSize() - evt.getApp().getSize(), vm.getRAM() + - evt.getApp().getRam(), vm.getCPU() - evt.getApp().getCpu()); + } catch (VMResizeException e) { + // LOG.error("failed to resize VM: " + e.getVm(), e); + } + if (vm.getApplications().size() == 0) { + PhysicalMachine pm = vm.getRunningOn(); + pm.stopVirtualMachine(vm); + manager.stopPhysicalMachine(pm.getId()); } } } @@ -131,44 +120,42 @@ public class SchedulerB extends AbstractScheduler { /** * Try to start all Apps. Upsize the VM, if not possible 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); for (SchedulerEvent evt : events) { - if (evt.getType() == EventType.startApplication) { - VirtualMachine vm = null; - for (PhysicalMachine pm : manager.getPMs()) { - // TODO: choose VM with good Utilization to get even better utilization - vm = pm.getVirtualMachines().get( - (pm.getVirtualMachines().keySet().toArray(new Integer[0]))[0]); - try { - vm.resizeVM(vm.getSize() + evt.getApp().getSize(), vm.getRAM() - + evt.getApp().getRam(), vm.getCPU() + evt.getApp().getCpu()); - break; - } catch (VMResizeException ex) { - vm = null; - } + VirtualMachine vm = null; + for (PhysicalMachine pm : manager.getPMs()) { + // TODO: choose VM with good Utilization to get even better utilization + vm = pm.getVirtualMachines().get( + (pm.getVirtualMachines().keySet().toArray(new Integer[0]))[0]); + try { + vm.resizeVM(vm.getSize() + evt.getApp().getSize(), vm.getRAM() + + evt.getApp().getRam(), vm.getCPU() + evt.getApp().getCpu()); + break; + } catch (VMResizeException ex) { + vm = null; } - if (vm == null) { - try { - vm = manager.startPhysicalMachine().startVirtualMachine( - evt.getApp().getSize(), evt.getApp().getRam(), - evt.getApp().getCpu(), vmType); - } catch (OutOfPMsException e) { - if (federation.askToOutsource(evt.getApp())) { - insertOutsourcedStartEvent(currTime + 1, evt.getApp()); - } else - LOG.info("delaying the start of:" + evt.getApp()); - delayedApps.add(evt.getApp()); - return; - } + } + if (vm == null) { + try { + vm = manager.startPhysicalMachine().startVirtualMachine(evt.getApp().getSize(), + evt.getApp().getRam(), evt.getApp().getCpu(), vmType); + } catch (OutOfPMsException e) { + if (federation.askToOutsource(evt.getApp())) { + insertOutsourcedStartEvent(currTime + 1, evt.getApp()); + } else + LOG.info("delaying the start of:" + evt.getApp()); + delayedApps.add(evt.getApp()); + return; } - vm.startApplication(evt.getApp()); - evt.getApp().setRunningOn(vm); - insertStopEvent(currTime + evt.getApp().getDuration(), evt.getApp()); } + vm.startApplication(evt.getApp()); + evt.getApp().setRunningOn(vm); + insertStopEvent(currTime + evt.getApp().getDuration(), evt.getApp()); } } diff --git a/src/at/ac/tuwien/lsdc/sched/SchedulerC.java b/src/at/ac/tuwien/lsdc/sched/SchedulerC.java index e44fedf..199a0da 100644 --- a/src/at/ac/tuwien/lsdc/sched/SchedulerC.java +++ b/src/at/ac/tuwien/lsdc/sched/SchedulerC.java @@ -7,30 +7,46 @@ 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; - public class SchedulerC extends AbstractScheduler { private static final Logger log = LoggerFactory.getLogger(SchedulerC.class); - - public SchedulerC(int numPMs, int numCloudPartners, File schedulerLog, - ScenarioType scenario) throws IOException { + + public SchedulerC(int numPMs, int numCloudPartners, File schedulerLog, ScenarioType scenario) + throws IOException { super(numPMs, numCloudPartners, schedulerLog, scenario); } @Override - protected void handleEvents(LinkedList events) { + protected String getSchedulerType() { + return SchedulerType.C.toString(); + } + + @Override + protected void handleEndEvents(LinkedList events) { // TODO Auto-generated method stub - log.info("Sched C handle Events"); + } @Override - protected String getSchedulerType() { - return SchedulerType.C.toString(); + protected void handleDelayedApps() { + // TODO Auto-generated method stub + + } + + @Override + protected void handleStartEvents(LinkedList events) { + // TODO Auto-generated method stub + + } + + @Override + protected void runMigration() { + // TODO Auto-generated method stub + } } diff --git a/src/at/ac/tuwien/lsdc/types/Application.java b/src/at/ac/tuwien/lsdc/types/Application.java index 618261e..08d3334 100644 --- a/src/at/ac/tuwien/lsdc/types/Application.java +++ b/src/at/ac/tuwien/lsdc/types/Application.java @@ -11,8 +11,7 @@ public class Application implements Comparable { private VirtualMachine runningOn; - public Application(int id, long timestamp, int size, int ram, int cpu, - int duration) { + public Application(int id, long timestamp, int size, int ram, int cpu, int duration) { this.id = id; this.timestamp = timestamp; this.size = size; @@ -45,10 +44,10 @@ public class Application implements Comparable { return duration; } + @Override public String toString() { - return new String("App ID: " + id + " Timestamp: " + timestamp - + " size: " + size + " ram: " + ram + " cpu: " + cpu - + " duration: " + duration); + return new String("App ID: " + id + " Timestamp: " + timestamp + " size: " + size + + " ram: " + ram + " cpu: " + cpu + " duration: " + duration); } public VirtualMachine getRunningOn() { diff --git a/src/at/ac/tuwien/lsdc/types/ApplicationResourceComparator.java b/src/at/ac/tuwien/lsdc/types/ApplicationResourceComparator.java new file mode 100644 index 0000000..12bff01 --- /dev/null +++ b/src/at/ac/tuwien/lsdc/types/ApplicationResourceComparator.java @@ -0,0 +1,27 @@ +package at.ac.tuwien.lsdc.types; + +import java.util.Comparator; + +public class ApplicationResourceComparator implements Comparator { + + final int BEFORE = -1; + final int EQUAL = 0; + final int AFTER = 1; + + @Override + public int compare(Application a1, Application a2) { + if (a1 == a2) + return EQUAL; + if (getResourceDifference(a1, a2) < 0) + return BEFORE; + else if (getResourceDifference(a1, a2) > 0) + return AFTER; + else + return EQUAL; + } + + public int getResourceDifference(Application a1, Application a2) { + return a1.getSize() - a2.getSize() + a1.getRam() - a2.getRam() + a1.getCpu() - a2.getCpu(); + } + +} diff --git a/src/at/ac/tuwien/lsdc/types/PhysicalMachine.java b/src/at/ac/tuwien/lsdc/types/PhysicalMachine.java index f775784..9d52604 100644 --- a/src/at/ac/tuwien/lsdc/types/PhysicalMachine.java +++ b/src/at/ac/tuwien/lsdc/types/PhysicalMachine.java @@ -6,7 +6,11 @@ import at.ac.tuwien.lsdc.exception.ActiveApplicationsException; import at.ac.tuwien.lsdc.exception.VMsRunningException; import at.ac.tuwien.lsdc.types.VirtualMachine.VMType; -public class PhysicalMachine { +public class PhysicalMachine implements Comparable { + + final int BEFORE = -1; + final int EQUAL = 0; + final int AFTER = 1; private static int count = 0; @@ -25,7 +29,7 @@ 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; @@ -44,8 +48,7 @@ public class PhysicalMachine { public void stop() throws VMsRunningException { if (VMs.size() > 0) - throw new VMsRunningException( - "PM cannot be stopped. Some VMs still running"); + throw new VMsRunningException("PM cannot be stopped. Some VMs still running"); VMs = new HashMap(); reservedSize = 0; @@ -61,8 +64,7 @@ public class PhysicalMachine { return 0.0; } - public VirtualMachine startVirtualMachine(int sz, int ram, int cpu, - VMType type) { + public VirtualMachine startVirtualMachine(int sz, int ram, int cpu, VMType type) { if (checkVM(sz, ram, cpu)) { VirtualMachine vm = new VirtualMachine(sz, ram, cpu, this, type); VMs.put(vm.getId(), vm); @@ -75,13 +77,11 @@ public class PhysicalMachine { return null; } - public void stopVirtualMachine(VirtualMachine vm) - throws ActiveApplicationsException { + public void stopVirtualMachine(VirtualMachine vm) throws ActiveApplicationsException { if (VMs.containsKey(vm.getId())) { if (vm.getApplications().size() != 0) { throw new ActiveApplicationsException( - "Applications must be migrated before stopping a VM, VM id " - + vm.getId()); + "Applications must be migrated before stopping a VM, VM id " + vm.getId()); } else { VMs.remove(vm.getId()); reservedSize = reservedSize - vm.getReservedSize(); @@ -92,7 +92,8 @@ public class PhysicalMachine { } public boolean checkVM(int size, int RAM, int CPU) { - return ((VirtualMachine.initialSize + size) <= availableSize()) && ((VirtualMachine.initialRAM + RAM) <= availableRAM()) + return ((VirtualMachine.initialSize + size) <= availableSize()) + && ((VirtualMachine.initialRAM + RAM) <= availableRAM()) && ((VirtualMachine.initialCPU + CPU) <= availableCPU()); } @@ -157,14 +158,14 @@ public class PhysicalMachine { return VMs.get(id); } - /** - * return a list of all VMs running on this PM. - * - * @return a HashMap with all VMs running on this PM. - */ - public HashMap getVirtualMachines() { - return VMs; - } + /** + * return a list of all VMs running on this PM. + * + * @return a HashMap with all VMs running on this PM. + */ + public HashMap getVirtualMachines() { + return VMs; + } public int countCurrentlyRunningVMs() { return VMs.values().size(); @@ -185,4 +186,17 @@ public class PhysicalMachine { public int getTotalVMs() { return totalVMs; } + + @Override + public int compareTo(PhysicalMachine other) { + if (this == other) + return EQUAL; + + if (getAverageUtilization() < other.getAverageUtilization()) + return BEFORE; + else if (getAverageUtilization() > other.getAverageUtilization()) + return AFTER; + else + return EQUAL; + } } diff --git a/src/at/ac/tuwien/lsdc/types/SortedApplication.java b/src/at/ac/tuwien/lsdc/types/SortedApplication.java deleted file mode 100644 index ff052a3..0000000 --- a/src/at/ac/tuwien/lsdc/types/SortedApplication.java +++ /dev/null @@ -1,38 +0,0 @@ -package at.ac.tuwien.lsdc.types; - -public class SortedApplication implements Comparable { - - - private Application app; - final int BEFORE = -1; - final int EQUAL = 0; - final int AFTER = 1; - - public SortedApplication(Application app) { - this.app = app; - } - - @Override - public int compareTo(SortedApplication other) { - if (this == other) - return EQUAL; - - if(getResourceDifference(other) < 0) - return BEFORE; - else if(getResourceDifference(other) > 0) - return AFTER; - else - return EQUAL; - } - - public Application getApp() { - return app; - } - - public int getResourceDifference(SortedApplication other) { - return app.getSize() - other.getApp().getSize() + - app.getRam() - other.getApp().getRam() + - app.getCpu() - other.getApp().getCpu(); - } - -} diff --git a/src/at/ac/tuwien/lsdc/types/SortedPhysicalMachine.java b/src/at/ac/tuwien/lsdc/types/SortedPhysicalMachine.java deleted file mode 100644 index 6d61fbf..0000000 --- a/src/at/ac/tuwien/lsdc/types/SortedPhysicalMachine.java +++ /dev/null @@ -1,32 +0,0 @@ -package at.ac.tuwien.lsdc.types; - -public class SortedPhysicalMachine implements Comparable { - - private PhysicalMachine pm; - final int BEFORE = -1; - final int EQUAL = 0; - final int AFTER = 1; - - public SortedPhysicalMachine(PhysicalMachine pm) { - this.pm = pm; - } - - @Override - public int compareTo(SortedPhysicalMachine other) { - if(this == other) - return EQUAL; - - if(pm.getAverageUtilization() < other.getPm().getAverageUtilization()) - return BEFORE; - else if(pm.getAverageUtilization() > other.getPm().getAverageUtilization()) - return AFTER; - else - return EQUAL; - } - - - public PhysicalMachine getPm() { - return pm; - } - -} -- 2.43.0