final Iterator<ClusterInstance> it = this.registeredHosts.values().iterator();
while (it.hasNext()) {
final ClusterInstance clusterInstance = it.next();
if (clusterInstance.getType().equals(currentInstanceType)) {
++numberOfMatchingInstances;
final HardwareDescription hardwareDescription = clusterInstance.getHardwareDescription();
minNumberOfCPUCores = Math.min(minNumberOfCPUCores, hardwareDescription.getNumberOfCPUCores());
minSizeOfPhysicalMemory = Math.min(minSizeOfPhysicalMemory,
hardwareDescription.getSizeOfPhysicalMemory());
minSizeOfFreeMemory = Math.min(minSizeOfFreeMemory, hardwareDescription.getSizeOfFreeMemory());
}
}
// Update number of instances
int highestAccommodationNumber = -1;
int highestAccommodationIndex = -1;
for (int j = 0; j < this.availableInstanceTypes.length; j++) {
final int accommodationNumber = canBeAccommodated(j, i);
// LOG.debug(this.availableInstanceTypes[j].getIdentifier() + " fits into "
// + this.availableInstanceTypes[i].getIdentifier() + " " + accommodationNumber + " times");
if (accommodationNumber > 0) {
numberOfInstances[j] += numberOfMatchingInstances * accommodationNumber;
if (accommodationNumber > highestAccommodationNumber) {
highestAccommodationNumber = accommodationNumber;
highestAccommodationIndex = j;
}
}
}
// Calculate hardware description
HardwareDescription pessimisticHardwareDescription = null;
if (minNumberOfCPUCores < Integer.MAX_VALUE && minSizeOfPhysicalMemory < Long.MAX_VALUE
&& minSizeOfFreeMemory < Long.MAX_VALUE) {
pessimisticHardwareDescription = HardwareDescriptionFactory.construct(minNumberOfCPUCores,
minSizeOfPhysicalMemory, minSizeOfFreeMemory);
} else {
if (highestAccommodationIndex < i) { // Since highestAccommodationIndex smaller than my index, the
// target instance must be more powerful
final InstanceTypeDescription descriptionOfLargerInstanceType = instanceTypeDescriptionList
.get(highestAccommodationIndex);
if (descriptionOfLargerInstanceType.getHardwareDescription() != null) {
final HardwareDescription hardwareDescriptionOfLargerInstanceType = descriptionOfLargerInstanceType
.getHardwareDescription();
final int numCores = hardwareDescriptionOfLargerInstanceType.getNumberOfCPUCores()
/ highestAccommodationNumber;
final long physMem = hardwareDescriptionOfLargerInstanceType.getSizeOfPhysicalMemory()
/ highestAccommodationNumber;
final long freeMem = hardwareDescriptionOfLargerInstanceType.getSizeOfFreeMemory()
/ highestAccommodationNumber;
pessimisticHardwareDescription = HardwareDescriptionFactory.construct(numCores, physMem,
freeMem);
}