use of com.netflix.exhibitor.core.entities.ServerStatus 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.entities.ServerStatus in project exhibitor by soabase.
the class ClusterState method getLiveInstances.
List<ServerStatus> getLiveInstances() {
List<ServerStatus> live = Lists.newArrayList();
List<ServerStatus> currentStatuses = statuses.get();
for (ServerStatus status : currentStatuses) {
InstanceStateTypes type = InstanceStateTypes.fromCode(status.getCode());
if (type != InstanceStateTypes.DOWN) {
live.add(status);
}
}
return live;
}
use of com.netflix.exhibitor.core.entities.ServerStatus 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.entities.ServerStatus in project exhibitor by soabase.
the class TestFixedAutoInstanceManagement method testBecomesObserver.
@Test
public void testBecomesObserver() throws Exception {
MockExhibitorInstance mockExhibitorInstance = new MockExhibitorInstance("new");
mockExhibitorInstance.getMockConfigProvider().setConfig(StringConfigs.SERVERS_SPEC, "1:a,2:b,3:c");
mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.AUTO_MANAGE_INSTANCES, 1);
mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.AUTO_MANAGE_INSTANCES_SETTLING_PERIOD_MS, 0);
mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.AUTO_MANAGE_INSTANCES_FIXED_ENSEMBLE_SIZE, 4);
mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.OBSERVER_THRESHOLD, 3);
List<ServerStatus> statuses = Lists.newArrayList();
statuses.add(new ServerStatus("a", InstanceStateTypes.SERVING.getCode(), "", true));
statuses.add(new ServerStatus("b", InstanceStateTypes.SERVING.getCode(), "", false));
statuses.add(new ServerStatus("c", InstanceStateTypes.SERVING.getCode(), "", false));
Mockito.when(mockExhibitorInstance.getMockForkJoinPool().invoke(Mockito.isA(ClusterStatusTask.class))).thenReturn(statuses);
AutomaticInstanceManagement management = new AutomaticInstanceManagement(mockExhibitorInstance.getMockExhibitor());
management.call();
Assert.assertEquals(mockExhibitorInstance.getMockExhibitor().getConfigManager().getConfig().getString(StringConfigs.SERVERS_SPEC), "1:a,2:b,3:c,O:4:new");
}
use of com.netflix.exhibitor.core.entities.ServerStatus in project exhibitor by soabase.
the class TestFlexibleAutoInstanceManagement method testBecomesObserver.
@Test
public void testBecomesObserver() throws Exception {
MockExhibitorInstance mockExhibitorInstance = new MockExhibitorInstance("new");
mockExhibitorInstance.getMockConfigProvider().setConfig(StringConfigs.SERVERS_SPEC, "1:a,2:b,3:c");
mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.AUTO_MANAGE_INSTANCES, 1);
mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.AUTO_MANAGE_INSTANCES_SETTLING_PERIOD_MS, 0);
mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.AUTO_MANAGE_INSTANCES_FIXED_ENSEMBLE_SIZE, 0);
mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.OBSERVER_THRESHOLD, 3);
List<ServerStatus> statuses = Lists.newArrayList();
statuses.add(new ServerStatus("a", InstanceStateTypes.SERVING.getCode(), "", true));
statuses.add(new ServerStatus("b", InstanceStateTypes.SERVING.getCode(), "", false));
statuses.add(new ServerStatus("c", InstanceStateTypes.SERVING.getCode(), "", false));
Mockito.when(mockExhibitorInstance.getMockForkJoinPool().invoke(Mockito.isA(ClusterStatusTask.class))).thenReturn(statuses);
AutomaticInstanceManagement management = new AutomaticInstanceManagement(mockExhibitorInstance.getMockExhibitor());
management.call();
Assert.assertEquals(mockExhibitorInstance.getMockExhibitor().getConfigManager().getConfig().getString(StringConfigs.SERVERS_SPEC), "1:a,2:b,3:c,O:4:new");
}
Aggregations