use of com.netflix.exhibitor.core.state.InstanceState in project exhibitor by soabase.
the class ConfigManager method checkNextInstanceState.
private ConfigCollection checkNextInstanceState(ConfigCollection config, List<String> rollingHostNames, int rollingHostNamesIndex) {
if ((rollingHostNamesIndex + 1) >= rollingHostNames.size()) {
// we're done - switch back to single config
return new ConfigCollectionImpl(config.getRollingConfig(), null);
}
ConfigCollection newCollection = new ConfigCollectionImpl(config.getRootConfig(), config.getRollingConfig(), rollingHostNames, rollingHostNamesIndex + 1);
RollingReleaseState state = new RollingReleaseState(new InstanceState(), newCollection);
if (state.getCurrentRollingHostname().equals(exhibitor.getThisJVMHostname())) {
return newCollection;
}
RollingConfigAdvanceAttempt activeAttempt = rollingConfigAdvanceAttempt.get();
RemoteInstanceRequest.Result result;
if ((activeAttempt == null) || !activeAttempt.getHostname().equals(state.getCurrentRollingHostname()) || (activeAttempt.getAttemptCount() < maxAttempts)) {
RemoteInstanceRequest remoteInstanceRequest = new RemoteInstanceRequest(exhibitor, state.getCurrentRollingHostname());
result = callRemoteInstanceRequest(remoteInstanceRequest);
if (activeAttempt == null) {
activeAttempt = new RollingConfigAdvanceAttempt(state.getCurrentRollingHostname());
rollingConfigAdvanceAttempt.set(activeAttempt);
}
activeAttempt.incrementAttemptCount();
if (result.errorMessage.length() != 0) {
if (activeAttempt.getAttemptCount() >= maxAttempts) {
exhibitor.getLog().add(ActivityLog.Type.INFO, "Exhausted attempts to connect to " + remoteInstanceRequest.getHostname() + " - skipping and moving on to next instance");
// it must be down. Skip it.
newCollection = checkNextInstanceState(config, rollingHostNames, rollingHostNamesIndex + 1);
} else {
exhibitor.getLog().add(ActivityLog.Type.INFO, "Could not connect to " + remoteInstanceRequest.getHostname() + " - attempt #" + activeAttempt.getAttemptCount());
newCollection = null;
}
}
} else {
newCollection = null;
}
return newCollection;
}
Aggregations