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 String getSchedulerType() {
34 return SchedulerType.C.toString();
38 protected void handleEndEvents(LinkedList<SchedulerEvent> events) {
39 LOG.debug("stopApps():" + events);
40 for (SchedulerEvent evt : events) {
41 VirtualMachine vm = evt.getApp().getRunningOn();
42 vm.stopApplication(evt.getApp());
43 if (vm.getApplications().size() == 0) {
44 PhysicalMachine pm = vm.getRunningOn();
45 pm.stopVirtualMachine(vm);
46 manager.stopPhysicalMachine(pm.getId());
52 protected void handleStartEvents(LinkedList<SchedulerEvent> events) {
53 LOG.debug("startApps():" + events);
54 boolean deployed = false;
55 for (SchedulerEvent evt : events) {
57 VirtualMachine vm = null;
58 List<PhysicalMachine> sortedPMs = manager.getSortedPMs();
59 Collections.reverse(sortedPMs);
60 for (PhysicalMachine pm : sortedPMs) {
61 if (pm.isRunning() && (pm.getTotalVMs() > 0)) {
62 vm = pm.getVirtualMachines().values().iterator().next();
63 deployed = deployApp(vm, evt.getApp());
70 vm = manager.startPhysicalMachine().startVirtualMachine(vmType);
71 deployed = deployApp(vm, evt.getApp());
72 } catch (OutOfPMsException e) {
73 if (federation.askToOutsource(evt.getApp())) {
74 insertOutsourcedStartEvent(currTime + 1, evt.getApp());
76 LOG.info("delaying the start of:" + evt.getApp());
77 delayedApps.add(evt.getApp());
83 insertStopEvent(currTime + evt.getApp().getDuration(), evt.getApp());
89 protected boolean deployApp(VirtualMachine vm, Application app) {
90 return vm.startApplication(app);