1 package at.ac.tuwien.lsdc.sched;
4 import java.io.IOException;
5 import java.util.LinkedList;
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
10 import at.ac.tuwien.lsdc.exception.OutOfPMsException;
11 import at.ac.tuwien.lsdc.exception.VMResizeException;
12 import at.ac.tuwien.lsdc.types.PhysicalMachine;
13 import at.ac.tuwien.lsdc.types.ScenarioType;
14 import at.ac.tuwien.lsdc.types.SchedulerEvent;
15 import at.ac.tuwien.lsdc.types.SchedulerEvent.EventType;
16 import at.ac.tuwien.lsdc.types.SchedulerType;
17 import at.ac.tuwien.lsdc.types.VirtualMachine;
18 import at.ac.tuwien.lsdc.types.VirtualMachine.VMType;
23 * Initial State: All PMs switched off. If an application arrives, try to modify
24 * size, CPU and RAM of an existing VM to run the application. If no VM is
25 * running, create a new one (start a new PM if necessary). If the application
26 * has finished decrease the size, CPU and RAM of the VM. If no applications are
27 * running on a VM, shut down the VM. If no VM is running on a PM, shut down the
28 * PM. Try to get a maximum of utilization on every PM. Migration: Try to move
29 * applications from VMs to other VMs to get a better utilization and to use
35 public class SchedulerB extends AbstractScheduler {
37 private static final Logger log = LoggerFactory.getLogger(SchedulerB.class);
39 public SchedulerB(int numPMs, int numCloudPartners, File schedulerLog, ScenarioType scenario) throws IOException {
40 super(numPMs, numCloudPartners, schedulerLog, scenario);
42 vmType = VMType.Resizable;
46 protected void handleEvents(LinkedList<SchedulerEvent> events) {
47 log.debug("handleEvents():" + events);
48 for (SchedulerEvent evt : events) {
49 if (evt.getType() == EventType.endApplication) {
50 VirtualMachine vm = evt.getApp().getRunningOn();
51 evt.getApp().setRunningOn(null);
52 vm.stopApplication(evt.getApp());
54 vm.resizeVM(vm.getSize() - evt.getApp().getSize(), vm.getRAM() - evt.getApp().getRam(), vm.getCPU()
55 - evt.getApp().getCpu());
56 } catch (VMResizeException e) {
57 log.error("lol: " + e.getVm(), e);
59 if (vm.getApplications().size() == 0) {
60 PhysicalMachine pm = vm.getRunningOn();
61 pm.stopVirtualMachine(vm);
62 manager.stopPhysicalMachine(pm.getId());
67 // TODO: migrate apps to get an empty VM and shut it down.
68 // TODO: run all delayed.
70 for (SchedulerEvent evt : events) {
71 if (evt.getType() == EventType.startApplication) {
72 VirtualMachine vm = null;
73 for (PhysicalMachine pm : manager.getPMs()) {
74 log.debug("PMs: " + pm);
75 vm = pm.getVirtualMachines().get((pm.getVirtualMachines().keySet().toArray(new Integer[0]))[0]);
77 vm.resizeVM(vm.getSize() + evt.getApp().getSize(), vm.getRAM() + evt.getApp().getRam(), vm.getCPU()
78 + evt.getApp().getCpu());
80 } catch (VMResizeException ex) {
86 vm = manager.startPhysicalMachine().startVirtualMachine(evt.getApp().getSize(), evt.getApp().getRam(),
87 evt.getApp().getCpu(), vmType);
88 } catch (OutOfPMsException e) {
90 // TODO: delay APP start.
94 vm.startApplication(evt.getApp());
95 evt.getApp().setRunningOn(vm);
96 insertStopEvent(currTime + evt.getApp().getDuration(), evt.getApp());
102 protected String getSchedulerType() {
103 return SchedulerType.B.toString();