use of com.netflix.exhibitor.core.state.InstanceStateTypes 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.state.InstanceStateTypes in project exhibitor by soabase.
the class ClusterResource method getStatus.
@Path("state")
@GET
@Produces(MediaType.APPLICATION_JSON)
public String getStatus() throws Exception {
ObjectNode mainNode = JsonNodeFactory.instance.objectNode();
ObjectNode switchesNode = JsonNodeFactory.instance.objectNode();
for (ControlPanelTypes type : ControlPanelTypes.values()) {
switchesNode.put(UIResource.fixName(type), context.getExhibitor().getControlPanelValues().isSet(type));
}
mainNode.put("switches", switchesNode);
MonitorRunningInstance monitorRunningInstance = context.getExhibitor().getMonitorRunningInstance();
InstanceStateTypes state = monitorRunningInstance.getCurrentInstanceState();
mainNode.put("state", state.getCode());
mainNode.put("description", state.getDescription());
mainNode.put("isLeader", monitorRunningInstance.isCurrentlyLeader());
return JsonUtil.writeValueAsString(mainNode);
}
use of com.netflix.exhibitor.core.state.InstanceStateTypes in project exhibitor by soabase.
the class ClusterState method buildStatusMap.
Map<ServerSpec, InstanceStateTypes> buildStatusMap() {
ServerList serverList = configuredServerList.get();
ImmutableMap.Builder<ServerSpec, InstanceStateTypes> builder = ImmutableMap.builder();
List<ServerStatus> currentStatuses = statuses.get();
for (ServerStatus status : currentStatuses) {
ServerSpec spec = serverList.getSpec(status.getHostname());
if (spec != null) {
builder.put(spec, status.getInstanceStateType());
} else {
log.error("No configured spec found for hostname: " + status.getHostname());
}
}
return builder.build();
}
use of com.netflix.exhibitor.core.state.InstanceStateTypes in project exhibitor by soabase.
the class ClusterStatusTask method getStatus.
private ServerStatus getStatus(ServerSpec spec) {
if (spec.equals(us)) {
InstanceStateTypes state = exhibitor.getMonitorRunningInstance().getCurrentInstanceState();
return new ServerStatus(spec.getHostname(), state.getCode(), state.getDescription(), exhibitor.getMonitorRunningInstance().isCurrentlyLeader());
}
try {
RemoteInstanceRequest request = new RemoteInstanceRequest(exhibitor, spec.getHostname());
RemoteInstanceRequest.Result result = request.makeRequest(exhibitor.getRemoteInstanceRequestClient(), "getStatus");
ObjectMapper mapper = new ObjectMapper();
JsonNode value = mapper.readTree(mapper.getJsonFactory().createJsonParser(result.remoteResponse));
if (value.size() == 0) {
return new ServerStatus(spec.getHostname(), InstanceStateTypes.DOWN.getCode(), InstanceStateTypes.DOWN.getDescription(), false);
}
int code = value.get("state").asInt();
String description = value.get("description").getTextValue();
return new ServerStatus(spec.getHostname(), code, description, value.get("isLeader").getBooleanValue());
} catch (IOException e) {
log.error("Getting remote server status", e);
throw new RuntimeException(e);
}
}
use of com.netflix.exhibitor.core.state.InstanceStateTypes in project exhibitor by soabase.
the class FixedEnsembleBuilder method createPotentialServerList.
@Override
public ServerList createPotentialServerList() {
ServerList configuredServerList = clusterState.getConfiguredServerList();
Map<ServerSpec, InstanceStateTypes> statusMap = clusterState.buildStatusMap();
List<ServerSpec> newList = Lists.newArrayList();
for (ServerSpec spec : configuredServerList.getSpecs()) {
if (statusMap.get(spec) != InstanceStateTypes.DOWN) {
newList.add(spec);
}
}
if (newList.size() >= fixedEnsembleSize) {
// no room for us
return configuredServerList;
}
int standardTypeCount = 0;
for (ServerSpec spec : newList) {
if (spec.getServerType() == ServerType.STANDARD) {
++standardTypeCount;
}
}
int observerThreshold = exhibitor.getConfigManager().getConfig().getInt(IntConfigs.OBSERVER_THRESHOLD);
ServerType serverType = ((observerThreshold > 0) && (standardTypeCount >= observerThreshold)) ? ServerType.OBSERVER : ServerType.STANDARD;
int existingMaxId = FlexibleEnsembleBuilder.getExistingMaxId(configuredServerList);
ServerSpec us = new ServerSpec(exhibitor.getThisJVMHostname(), existingMaxId + 1, serverType);
newList.add(us);
return new ServerList(newList);
}
Aggregations