]> git.somenet.org - pub/jan/lsdc.git/blob - src/at/ac/tuwien/lsdc/sched/SchedulerC.java
fixed scenario params in build.xml
[pub/jan/lsdc.git] / src / at / ac / tuwien / lsdc / sched / SchedulerC.java
1 package at.ac.tuwien.lsdc.sched;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.util.Collections;
6 import java.util.LinkedList;
7 import java.util.List;
8
9 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory;
11
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;
20
21 public class SchedulerC extends AbstractSchedulerWithMigration {
22
23         private static final Logger LOG = LoggerFactory.getLogger(SchedulerC.class);
24
25         public SchedulerC(int numPMs, int numCloudPartners, File schedulerLog, ScenarioType scenario)
26                         throws IOException {
27                 super(numPMs, numCloudPartners, schedulerLog, scenario);
28
29                 this.vmType = VMType.NonResizable;
30         }
31
32         @Override
33         protected String getSchedulerType() {
34                 return SchedulerType.C.toString();
35         }
36
37         @Override
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());
47                         }
48                 }
49         }
50
51         @Override
52         protected void handleStartEvents(LinkedList<SchedulerEvent> events) {
53                 LOG.debug("startApps():" + events);
54                 boolean deployed = false;
55                 for (SchedulerEvent evt : events) {
56                         deployed = false;
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());
64                                         if (deployed)
65                                                 break;
66                                 }
67                         }
68                         if (!deployed) {
69                                 try {
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());
75                                         } else {
76                                                 LOG.info("delaying the start of:" + evt.getApp());
77                                                 delayedApps.add(evt.getApp());
78                                                 return;
79                                         }
80                                 }
81                         }
82                         if (deployed)
83                                 insertStopEvent(currTime + evt.getApp().getDuration(), evt.getApp());
84                 }
85
86         }
87
88         @Override
89         protected boolean deployApp(VirtualMachine vm, Application app) {
90                 return vm.startApplication(app);
91         }
92
93 }