1 package at.ac.tuwien.lsdc.sched;
4 import java.io.IOException;
5 import java.util.Collections;
6 import java.util.LinkedList;
9 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory;
12 import at.ac.tuwien.lsdc.exception.OutOfPMsException;
13 import at.ac.tuwien.lsdc.types.Application;
14 import at.ac.tuwien.lsdc.types.PhysicalMachine;
15 import at.ac.tuwien.lsdc.types.ScenarioType;
16 import at.ac.tuwien.lsdc.types.SchedulerEvent;
17 import at.ac.tuwien.lsdc.types.SchedulerType;
18 import at.ac.tuwien.lsdc.types.VirtualMachine;
19 import at.ac.tuwien.lsdc.types.VirtualMachine.VMType;
21 public class SchedulerC extends AbstractSchedulerWithMigration {
23 private static final Logger LOG = LoggerFactory.getLogger(SchedulerC.class);
25 public SchedulerC(int numPMs, int numCloudPartners, File schedulerLog, ScenarioType scenario)
27 super(numPMs, numCloudPartners, schedulerLog, scenario);
29 this.vmType = VMType.NonResizable;
33 protected boolean deployApp(VirtualMachine vm, Application app) {
34 boolean deployed = false;
35 if (!vm.enoughResources(app))
38 deployed = vm.startApplication(app);
45 * Cleanup completed apps. If an VM becomes empty, shut down VM + PM.
47 * @param events list of all events that happened in this timeslot.
50 protected void handleEndEvents(LinkedList<SchedulerEvent> events) {
51 // LOG.debug("stopApps():" + events);
52 for (SchedulerEvent evt : events) {
53 VirtualMachine vm = evt.getApp().getRunningOn();
54 evt.getApp().setRunningOn(null);
55 vm.stopApplication(evt.getApp());
57 if (vm.getApplications().size() == 0) {
58 PhysicalMachine pm = vm.getRunningOn();
59 pm.stopVirtualMachine(vm);
60 manager.stopPhysicalMachine(pm.getId());
67 * Try to start all Apps. If not enough space start another PM, if not possible,
70 * @param events list of all events that happened in this timeslot.
73 protected void handleStartEvents(LinkedList<SchedulerEvent> events) {
74 // LOG.debug("startApps():" + events);
75 boolean deployed = false;
76 for (SchedulerEvent evt : events) {
78 VirtualMachine vm = null;
79 List<PhysicalMachine> sortedPMs = manager.getRevSortedPMs();
81 for (PhysicalMachine pm : sortedPMs) {
82 if (pm.isRunning() && (pm.countCurrentlyRunningVMs() > 0)) {
83 vm = pm.getVirtualMachines().values().iterator().next();
84 deployed = deployApp(vm, evt.getApp());
91 vm = manager.startPhysicalMachine().startVirtualMachine(vmType);
92 deployed = deployApp(vm, evt.getApp());
93 } catch (OutOfPMsException e) {
94 if (federation.askToOutsource(evt.getApp())) {
95 insertOutsourcedStartEvent(currTime + 1, evt.getApp());
97 LOG.info("delaying the start of:" + evt.getApp());
98 delayedApps.add(evt.getApp());
104 insertStopEvent(currTime + evt.getApp().getDuration(), evt.getApp());
106 if(manager.countCurrentlyRunningPMs() < manager.getMaxPMs()) {
107 Application app = federation.askToInsource();
109 insertInsourcedStartEvent(currTime + 1, evt.getApp());
117 protected String getSchedulerType() {
118 return SchedulerType.C.toString();