NewAllocationPolicy vmAllocationPolicy = new NewAllocationPolicy();
Datacenter dc = new Datacenter (String name, DatacenterCharacteristics characteristics, vmAllocationPolicy(hostList), List<Storage> storageList, double schedulingInterval)
public boolean allocateHostForVm(Vm vm) {
try{
boolean result=false;
getHostList();
int size = getHostList().size();
double[] avgCPU = new double[size];
double[] avgBandwidth = new double[size];
double[] avgStorage = new double[size];
for(int i=0; i<size;i++){
host = getHostList().get(j); // get each Host from the list
int hid=host.getId();
double availmip=host.getAvailableMips(); //retrieves the available Cpu capacity
avgCPU[i] = ((mips-availmip)/mips) * 100
}
double minCPU=min(avgCPU[]); // apply any operation to find the minimum cpu value.
Host hs= the host which has low avgUtilized CPU value;
……
result = hs.vmCreate(vm); //the low cpu utilized Host "hs" is allocated to vm
if (result) { // if vm were succesfully created in the host
getVmTable().put(vm.getUid(), p);
getUsedPes().put(vm.getUid(), requiredPes);
getFreePes().set(idx, getFreePes().get(idx) – requiredPes);
result = true;
break;
} else {
freePesTmp.set(idx, Integer.MIN_VALUE);
}
}
Catch(Exception e){
}
return result;
}