]> git.somenet.org - pub/jan/lsdc.git/blob - src/at/ac/tuwien/lsdc/sched/AbstractSchedulerWithMigration.java
final presentation. NEED BETTER INPUT FILE!
[pub/jan/lsdc.git] / src / at / ac / tuwien / lsdc / sched / AbstractSchedulerWithMigration.java
1 package at.ac.tuwien.lsdc.sched;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.util.HashMap;
6 import java.util.LinkedList;
7 import java.util.List;
8
9 import at.ac.tuwien.lsdc.types.Application;
10 import at.ac.tuwien.lsdc.types.PhysicalMachine;
11 import at.ac.tuwien.lsdc.types.ScenarioType;
12 import at.ac.tuwien.lsdc.types.SchedulerEvent;
13 import at.ac.tuwien.lsdc.types.SchedulerEvent.EventType;
14 import at.ac.tuwien.lsdc.types.VirtualMachine;
15
16 public abstract class AbstractSchedulerWithMigration extends AbstractScheduler {
17
18         public AbstractSchedulerWithMigration(int numPMs, int numCloudPartners, File schedulerLog,
19                         ScenarioType scenario) throws IOException {
20                 super(numPMs, numCloudPartners, schedulerLog, scenario);
21         }
22
23         @Override
24         protected void handleEvents(HashMap<EventType, LinkedList<SchedulerEvent>> events) {
25                 super.handleEvents(events);
26                 runMigration();
27         }
28
29         /**
30          * Check if we can free up a VM to shut it down.
31          */
32         protected void runMigration() {
33                 List<PhysicalMachine> pms = manager.getSortedPMs();
34                 // iterate through all the PMs (except the one with the highest utilization)
35                 for (int i = 0; i < (pms.size() - 1); i++) {
36                         PhysicalMachine currentPM = pms.get(i);
37                         if (currentPM.isRunning() && (currentPM.countCurrentlyRunningVMs() > 0)) {
38                                 VirtualMachine currentVM = currentPM.getVirtualMachines().values().iterator()
39                                                 .next();
40                                 for (Application app : currentVM.getApplications()) {
41                                         
42                                         // try to fit app on most utilized machine to get maximum utilization
43                                         for (int j = pms.size()-1; j > i; j--) {
44                                                 PhysicalMachine nextPM = pms.get(j);
45                                                 if (nextPM.isRunning() && (nextPM.countCurrentlyRunningVMs() > 0)) {
46                                                         VirtualMachine nextVM = nextPM.getVirtualMachines().values().iterator()
47                                                                         .next();
48                                                         if (deployApp(nextVM, app)) {
49                                                                 currentVM.stopApplication(app);
50 //                                                              currentVM.resizeDown(app);
51                                                                 break;
52                                                         }
53                                                 }
54                                         }
55                                 }
56                                 if (currentVM.getApplications().size() == 0) {
57                                         currentPM.stopVirtualMachine(currentVM);
58                                         if (currentPM.countCurrentlyRunningVMs() == 0) {
59                                                 manager.stopPhysicalMachine(currentPM.getId());
60                                         }
61                                 }
62                         }
63                 }
64         }
65
66         protected abstract boolean deployApp(VirtualMachine vm, Application app);
67
68 }