]> git.somenet.org - pub/jan/lsdc.git/blob - src/at/ac/tuwien/lsdc/sched/AbstractSchedulerWithMigration.java
put code for migration into new class AbstractSchedulerWithMigration
[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.List;
6
7 import at.ac.tuwien.lsdc.types.Application;
8 import at.ac.tuwien.lsdc.types.PhysicalMachine;
9 import at.ac.tuwien.lsdc.types.ScenarioType;
10 import at.ac.tuwien.lsdc.types.VirtualMachine;
11
12 public abstract class AbstractSchedulerWithMigration extends AbstractScheduler {
13
14         public AbstractSchedulerWithMigration(int numPMs, int numCloudPartners, File schedulerLog,
15                         ScenarioType scenario) throws IOException {
16                 super(numPMs, numCloudPartners, schedulerLog, scenario);
17         }
18
19         /**
20          * Check if we can free up a VM to shut it down.
21          */
22         @Override
23         protected void runMigration() {
24                 List<PhysicalMachine> pms = manager.getSortedPMs();
25                 // iterate through all the PMs (except the one with the highest utilization)
26                 for (int i = 0; i < (pms.size() - 1); i++) {
27                         PhysicalMachine currentPM = pms.get(i);
28                         if (currentPM.isRunning() && (currentPM.getTotalVMs() > 0)) {
29                                 VirtualMachine currentVM = currentPM.getVirtualMachines().values().iterator()
30                                                 .next();
31                                 for (Application app : currentVM.getApplications()) {
32                                         for (int j = i; i < pms.size(); i++) {
33                                                 PhysicalMachine nextPM = pms.get(j);
34                                                 if (nextPM.isRunning() && (nextPM.getTotalVMs() > 0)) {
35                                                         VirtualMachine nextVM = nextPM.getVirtualMachines().values().iterator()
36                                                                         .next();
37                                                         if (deployApp(nextVM, app)) {
38                                                                 currentVM.stopApplication(app);
39                                                                 break;
40                                                         }
41                                                 }
42                                         }
43                                 }
44                                 if (currentVM.getApplications().size() == 0) {
45                                         currentPM.stopVirtualMachine(currentVM);
46                                         if (currentPM.getTotalVMs() == 0) {
47                                                 manager.stopPhysicalMachine(currentPM.getId());
48                                         }
49                                 }
50                         }
51                 }
52         }
53
54         protected abstract boolean deployApp(VirtualMachine vm, Application app);
55
56 }