log.debug("Pending Instances State Checker has started for: " +
AutoscaleUtil.domainSubDomainString(domain, subDomain) + ". Check expiry time : " + serverStartupDelay);
// for each sub domain, get the clustering group management agent
GroupManagementAgent agent =
AutoscalerTaskDSHolder.getInstance().getAgent()
.getGroupManagementAgent(domain,
subDomain);
int startingRunningInstanceCount = agent.getMembers().size();
// we give some time for the server to get joined, we'll check time to time
// whether the instance has actually joined the ELB.
while ((agent.getMembers().size() < (originalRunningInstanceCount + expectedIncrementOfinstanceCount)) &&
totalWaitedTime < serverStartupDelay) {
int upToDateRunningInstanceCount = agent.getMembers().size();
log.debug(AutoscaleUtil.domainSubDomainString(domain, subDomain) +
" - Number of current running instances " +
upToDateRunningInstanceCount);
if (upToDateRunningInstanceCount > startingRunningInstanceCount) {
int newlyJoinedInstanceCount = upToDateRunningInstanceCount - startingRunningInstanceCount;
// set new running instance count
groupCtxt.setRunningInstanceCount(upToDateRunningInstanceCount);
// decrement the pending instance count
groupCtxt.decrementPendingInstancesIfNotZero(newlyJoinedInstanceCount);
// update the starting running instance count
startingRunningInstanceCount = upToDateRunningInstanceCount;
log.debug(AutoscaleUtil.domainSubDomainString(domain, subDomain) +
" - Instances newly joined: " +
newlyJoinedInstanceCount);
}
try {
Thread.sleep(AutoscaleConstants.INSTANCE_REMOVAL_CHECK_TIME);
} catch (InterruptedException ignore) {
}
totalWaitedTime += AutoscaleConstants.INSTANCE_REMOVAL_CHECK_TIME;
}
log.debug(AutoscaleUtil.domainSubDomainString(domain, subDomain) + "- Waited for : " +
totalWaitedTime +
" (milliseconds) till pending members get joined.");
if (agent.getMembers().size() < (originalRunningInstanceCount + expectedIncrementOfinstanceCount)) {
int instanceCountFailedToJoin =
originalRunningInstanceCount + expectedIncrementOfinstanceCount - agent.getMembers().size();
log.debug(AutoscaleUtil.domainSubDomainString(domain, subDomain) +
"Instances that are failed to join: " +
instanceCountFailedToJoin);
// to avoid an infinite loop