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);
}
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;
}
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());
}
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()));
}
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);
}
}
Aggregations