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 for (SchedulerEvent evt : events) {
68 if (evt.getType() == EventType.startApplication) {
69 VirtualMachine vm = null;
70 for (PhysicalMachine pm : manager.getPMs()) {
71 log.debug("PMs: " + pm);
72 vm = pm.getVirtualMachines().get((pm.getVirtualMachines().keySet().toArray(new Integer[0]))[0]);
74 vm.resizeVM(vm.getSize() + evt.getApp().getSize(), vm.getRAM() + evt.getApp().getRam(), vm.getCPU()
75 + evt.getApp().getCpu());
77 } catch (VMResizeException ex) {
83 vm = manager.startPhysicalMachine().startVirtualMachine(evt.getApp().getSize(), evt.getApp().getRam(),
84 evt.getApp().getCpu(), vmType);
85 } catch (OutOfPMsException e) {
87 // TODO: delay APP start.
91 vm.startApplication(evt.getApp());
92 evt.getApp().setRunningOn(vm);
93 insertStopEvent(currTime + evt.getApp().getDuration(), evt.getApp());
99 protected String getSchedulerType() {
100 return SchedulerType.B.toString();