Search in sources :

Example 1 with ServerList

use of com.netflix.exhibitor.core.state.ServerList in project exhibitor by soabase.

the class FlexibleEnsembleBuilder method createPotentialServerList.

public ServerList createPotentialServerList() {
    ServerList configuredServerList = clusterState.getConfiguredServerList();
    int existingMaxId = getExistingMaxId(configuredServerList);
    List<ServerSpec> newList = Lists.newArrayList();
    Set<String> addedHostnames = Sets.newHashSet();
    for (ServerStatus status : clusterState.getLiveInstances()) {
        ServerSpec spec = configuredServerList.getSpec(status.getHostname());
        if (spec == null) {
            spec = new ServerSpec(status.getHostname(), ++existingMaxId, ServerType.STANDARD);
            addedHostnames.add(spec.getHostname());
        }
        newList.add(spec);
    }
    if (usState.getUs() == null) {
        ServerSpec spec = new ServerSpec(exhibitor.getThisJVMHostname(), ++existingMaxId, ServerType.STANDARD);
        addedHostnames.add(spec.getHostname());
        newList.add(spec);
    }
    int standardTypeCount = 0;
    for (ServerSpec spec : newList) {
        if (spec.getServerType() == ServerType.STANDARD) {
            ++standardTypeCount;
        }
    }
    int observerThreshold = exhibitor.getConfigManager().getConfig().getInt(IntConfigs.OBSERVER_THRESHOLD);
    if (observerThreshold > 0) {
        for (int i = 0; (standardTypeCount >= observerThreshold) && (i < newList.size()); ++i) {
            ServerSpec spec = newList.get(i);
            if (// i.e. don't change existing instances to observer
            addedHostnames.contains(spec.getHostname())) {
                newList.set(i, new ServerSpec(spec.getHostname(), spec.getServerId(), ServerType.OBSERVER));
                --standardTypeCount;
            }
        }
    }
    return new ServerList(newList);
}
Also used : ServerSpec(com.netflix.exhibitor.core.state.ServerSpec) ServerStatus(com.netflix.exhibitor.core.entities.ServerStatus) ServerList(com.netflix.exhibitor.core.state.ServerList)

Example 2 with ServerList

use of com.netflix.exhibitor.core.state.ServerList in project exhibitor by soabase.

the class AutomaticInstanceManagement method call.

@Override
public Boolean call() throws Exception {
    if (exhibitor.getConfigManager().getConfig().getInt(IntConfigs.AUTO_MANAGE_INSTANCES) == 0) {
        // auto manage is turned off
        return true;
    }
    if (exhibitor.getConfigManager().isRolling()) {
        return true;
    }
    if (exhibitor.getMonitorRunningInstance().getCurrentInstanceState() == InstanceStateTypes.LATENT) {
        // this instance hasn't warmed up yet
        return true;
    }
    ServerList serverList = new ServerList(exhibitor.getConfigManager().getConfig().getString(StringConfigs.SERVERS_SPEC));
    List<ServerStatus> statuses = getStatuses(serverList);
    clusterState.update(serverList, statuses);
    EnsembleBuilder ensembleBuilder = (exhibitor.getConfigManager().getConfig().getInt(IntConfigs.AUTO_MANAGE_INSTANCES_FIXED_ENSEMBLE_SIZE) > 0) ? new FixedEnsembleBuilder(exhibitor, clusterState) : new FlexibleEnsembleBuilder(exhibitor, clusterState);
    if (!ensembleBuilder.newEnsembleNeeded()) {
        return true;
    }
    if (!applyAllAtOnce() && !clusterState.isInQuorum()) {
        exhibitor.getLog().add(ActivityLog.Type.INFO, "Ensemble is not currently in quorum. Automatic Instance Management will wait for quorum. NOTE: if \"Apply All At Once\" is set to \"yes\", this quorum check is not needed.");
        return true;
    }
    int settlingPeriodMs = exhibitor.getConfigManager().getConfig().getInt(IntConfigs.AUTO_MANAGE_INSTANCES_SETTLING_PERIOD_MS);
    if (!clusterState.isStable(settlingPeriodMs)) {
        exhibitor.getLog().add(ActivityLog.Type.INFO, "Ensemble state is not yet stable. Automatic Instance Management will wait for stability.");
        return true;
    }
    PseudoLock lock = exhibitor.getConfigManager().newConfigBasedLock();
    try {
        if (lock.lock(exhibitor.getLog(), Exhibitor.AUTO_INSTANCE_MANAGEMENT_PERIOD_MS / 2, TimeUnit.MILLISECONDS)) {
            ServerList potentialServerList = ensembleBuilder.createPotentialServerList();
            if (// otherwise, no change
            !potentialServerList.equals(serverList)) {
                if (potentialServerList.getSpecs().size() == 0) {
                    exhibitor.getLog().add(ActivityLog.Type.INFO, "Automatic Instance Management skipped because new potential server list is empty");
                } else {
                    exhibitor.getLog().add(ActivityLog.Type.INFO, "Automatic Instance Management will change the server list: " + serverList + " ==> " + potentialServerList);
                    adjustConfig(potentialServerList.toSpecString(), clusterState.getLeaderHostname());
                }
            }
        }
    } finally {
        lock.unlock();
    }
    return true;
}
Also used : ServerStatus(com.netflix.exhibitor.core.entities.ServerStatus) ServerList(com.netflix.exhibitor.core.state.ServerList) PseudoLock(com.netflix.exhibitor.core.config.PseudoLock)

Example 3 with ServerList

use of com.netflix.exhibitor.core.state.ServerList in project exhibitor by soabase.

the class RollingReleaseState method serverListHasSynced.

boolean serverListHasSynced() {
    String targetServersSpec = config.getRollingConfig().getString(StringConfigs.SERVERS_SPEC);
    ServerList targetServerList = new ServerList(targetServersSpec);
    return targetServerList.equals(currentInstanceState.getServerList());
}
Also used : ServerList(com.netflix.exhibitor.core.state.ServerList)

Example 4 with ServerList

use of com.netflix.exhibitor.core.state.ServerList in project exhibitor by soabase.

the class ClusterState method clear.

void clear() {
    statuses.set(Lists.<ServerStatus>newArrayList());
    updateTimeMs.set(System.currentTimeMillis());
    configuredServerList.set(new ServerList(Lists.<ServerSpec>newArrayList()));
}
Also used : ServerSpec(com.netflix.exhibitor.core.state.ServerSpec) ServerList(com.netflix.exhibitor.core.state.ServerList)

Example 5 with ServerList

use of com.netflix.exhibitor.core.state.ServerList in project exhibitor by soabase.

the class TestRollingConfigChange method testAllDownInstances.

@Test
public void testAllDownInstances() throws Exception {
    ServerList serverList = new ServerList("1:one,2:two,3:three");
    RemoteInstanceRequestClient mockClient = new RemoteInstanceRequestClient() {

        @Override
        public void close() throws IOException {
        }

        @Override
        public <T> T getWebResource(URI remoteUri, MediaType type, Class<T> clazz) throws Exception {
            throw new Exception();
        }
    };
    ActivityLog log = new ActivityLog(100);
    ActivityQueue activityQueue = new ActivityQueue();
    Exhibitor mockExhibitor = Mockito.mock(Exhibitor.class);
    MonitorRunningInstance mockMonitorRunningInstance = makeMockMonitorRunningInstance();
    Mockito.when(mockExhibitor.getMonitorRunningInstance()).thenReturn(mockMonitorRunningInstance);
    Mockito.when(mockExhibitor.getLog()).thenReturn(log);
    Mockito.when(mockExhibitor.getActivityQueue()).thenReturn(activityQueue);
    Mockito.when(mockExhibitor.getThisJVMHostname()).thenReturn("_xxxx_");
    Mockito.when(mockExhibitor.getRemoteInstanceRequestClient()).thenReturn(mockClient);
    ConfigProvider provider = new ConfigWrapper(new AtomicLong(1));
    ConfigManager manager = new ConfigManager(mockExhibitor, provider, 10, 1);
    manager.start();
    try {
        Properties properties = new Properties();
        properties.setProperty(PropertyBasedInstanceConfig.toName(StringConfigs.SERVERS_SPEC, PropertyBasedInstanceConfig.ROOT_PROPERTY_PREFIX), serverList.toSpecString());
        PropertyBasedInstanceConfig config = new PropertyBasedInstanceConfig(properties, DefaultProperties.get(null));
        manager.startRollingConfig(config.getRootConfig(), null);
        Assert.assertFalse(manager.isRolling());
    } finally {
        CloseableUtils.closeQuietly(manager);
    }
}
Also used : ActivityLog(com.netflix.exhibitor.core.activity.ActivityLog) Properties(java.util.Properties) URI(java.net.URI) IOException(java.io.IOException) MonitorRunningInstance(com.netflix.exhibitor.core.state.MonitorRunningInstance) AtomicLong(java.util.concurrent.atomic.AtomicLong) ActivityQueue(com.netflix.exhibitor.core.activity.ActivityQueue) Exhibitor(com.netflix.exhibitor.core.Exhibitor) ServerList(com.netflix.exhibitor.core.state.ServerList) MediaType(javax.ws.rs.core.MediaType) RemoteInstanceRequestClient(com.netflix.exhibitor.core.automanage.RemoteInstanceRequestClient) Test(org.testng.annotations.Test)

Aggregations

ServerList (com.netflix.exhibitor.core.state.ServerList)16 ServerSpec (com.netflix.exhibitor.core.state.ServerSpec)7 Exhibitor (com.netflix.exhibitor.core.Exhibitor)6 ActivityLog (com.netflix.exhibitor.core.activity.ActivityLog)6 ActivityQueue (com.netflix.exhibitor.core.activity.ActivityQueue)6 RemoteInstanceRequestClient (com.netflix.exhibitor.core.automanage.RemoteInstanceRequestClient)6 MonitorRunningInstance (com.netflix.exhibitor.core.state.MonitorRunningInstance)6 URI (java.net.URI)6 Properties (java.util.Properties)6 AtomicLong (java.util.concurrent.atomic.AtomicLong)6 MediaType (javax.ws.rs.core.MediaType)6 Test (org.testng.annotations.Test)6 InstanceState (com.netflix.exhibitor.core.state.InstanceState)5 RestartSignificantConfig (com.netflix.exhibitor.core.state.RestartSignificantConfig)5 InstanceConfig (com.netflix.exhibitor.core.config.InstanceConfig)4 ServerStatus (com.netflix.exhibitor.core.entities.ServerStatus)4 IOException (java.io.IOException)4 GET (javax.ws.rs.GET)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4