Search in sources :

Example 6 with InstanceState

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;
}
Also used : InstanceState(com.netflix.exhibitor.core.state.InstanceState) RemoteInstanceRequest(com.netflix.exhibitor.core.automanage.RemoteInstanceRequest)

Aggregations

InstanceState (com.netflix.exhibitor.core.state.InstanceState)6 Exhibitor (com.netflix.exhibitor.core.Exhibitor)5 ActivityLog (com.netflix.exhibitor.core.activity.ActivityLog)5 ActivityQueue (com.netflix.exhibitor.core.activity.ActivityQueue)5 RemoteInstanceRequestClient (com.netflix.exhibitor.core.automanage.RemoteInstanceRequestClient)5 MonitorRunningInstance (com.netflix.exhibitor.core.state.MonitorRunningInstance)5 RestartSignificantConfig (com.netflix.exhibitor.core.state.RestartSignificantConfig)5 ServerList (com.netflix.exhibitor.core.state.ServerList)5 URI (java.net.URI)5 Properties (java.util.Properties)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 MediaType (javax.ws.rs.core.MediaType)5 Test (org.testng.annotations.Test)5 IOException (java.io.IOException)3 RemoteInstanceRequest (com.netflix.exhibitor.core.automanage.RemoteInstanceRequest)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1