-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPowerTestVmAllocationPolicy.java
63 lines (55 loc) · 2.1 KB
/
PowerTestVmAllocationPolicy.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.cloudsub.cloudsim.power_examples;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.VmAllocationPolicy;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.power.PowerHostUtilizationHistory;
import org.cloudbus.cloudsim.power.PowerVmAllocationPolicyAbstract;
import org.cloudbus.cloudsim.power.PowerVmAllocationPolicyMigrationAbstract;
/**
*
* @author Zahra Bagheri
*/
public class PowerTestVmAllocationPolicy extends PowerVmAllocationPolicyAbstract{
public PowerTestVmAllocationPolicy (List<? extends Host> hostList) {
super(hostList);
}
/*
* (non-Javadoc)
* @see org.cloudbus.cloudsim.VmAllocationPolicy#optimizeAllocation(java.util.List)
*/
@Override
public List<Map<String, Object>> optimizeAllocation(List<? extends Vm> vmList) {
List<Map<String, Object>> migrationMap = new LinkedList<Map<String, Object>>();
Map<String, Object> migrate = new HashMap<String, Object>();
//Find VMs to migrate
Vm vm = null;
for (PowerHostUtilizationHistory host : this.<PowerHostUtilizationHistory> getHostList()) {
if (host.getUtilizationOfCpu() * 100 > 95){
vm = host.getVmList().get(0);
}
}
//Find target hosts
Host allocatedHost = null;
for (PowerHostUtilizationHistory host1 : this.<PowerHostUtilizationHistory> getHostList()){
if (host1.getUtilizationOfCpu() * 100 < 65){
allocatedHost = host1;
}
}
if (vm != null && allocatedHost != null){
migrate.put("vm", vm);
migrate.put("host", allocatedHost);
migrationMap.add(migrate);
}
return migrationMap;
}
}