1 package at.ac.tuwien.lsdc.sched;
4 import java.io.IOException;
5 import java.util.HashMap;
6 import java.util.LinkedList;
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;
16 public abstract class AbstractSchedulerWithMigration extends AbstractScheduler {
18 public AbstractSchedulerWithMigration(int numPMs, int numCloudPartners, File schedulerLog,
19 ScenarioType scenario) throws IOException {
20 super(numPMs, numCloudPartners, schedulerLog, scenario);
24 protected void handleEvents(HashMap<EventType, LinkedList<SchedulerEvent>> events) {
25 super.handleEvents(events);
30 * Check if we can free up a VM to shut it down.
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()
40 for (Application app : currentVM.getApplications()) {
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()
48 if (deployApp(nextVM, app)) {
49 currentVM.stopApplication(app);
50 // currentVM.resizeDown(app);
56 if (currentVM.getApplications().size() == 0) {
57 currentPM.stopVirtualMachine(currentVM);
58 if (currentPM.countCurrentlyRunningVMs() == 0) {
59 manager.stopPhysicalMachine(currentPM.getId());
66 protected abstract boolean deployApp(VirtualMachine vm, Application app);