List<?> partitions = Arrays.asList(networkPartitionContext.getPartitions());
for (int i = currentPartitionIndex; i >= 0; i--) {
if (partitions.get(currentPartitionIndex) instanceof Partition) {
currentPartitionIndex = networkPartitionContext.getCurrentPartitionIndex();
Partition currentPartition = (Partition) partitions.get(currentPartitionIndex);
String currentPartitionId = currentPartition.getId();
// has more than minimum instances.
int currentlyActiveMemberCount = networkPartitionContext.getActiveMemberCount(currentPartitionId);
if ( currentlyActiveMemberCount > currentPartition.getPartitionMin()) {
// current partition is free
if (log.isDebugEnabled())
log.debug(String.format("A free space found for scale down in partition %s [current] %s [min] %s",
currentPartitionId, currentlyActiveMemberCount, currentPartition.getPartitionMin())) ;
return currentPartition;
} else {
if (currentPartitionIndex == 0) {
if (log.isDebugEnabled())
log.debug(String.format("Partition %s reached with no space to scale down," +
"[active] %s [min] %s", currentPartitionId, currentlyActiveMemberCount,
currentPartition.getPartitionMin()));
return null;
}
// Set next partition as current partition in Autoscaler Context
currentPartitionIndex = currentPartitionIndex - 1;
networkPartitionContext.setCurrentPartitionIndex(currentPartitionIndex);