Search in sources :

Example 1 with InstanceStateTypes

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;
}
Also used : ServerStatus(com.netflix.exhibitor.core.entities.ServerStatus) InstanceStateTypes(com.netflix.exhibitor.core.state.InstanceStateTypes)

Example 2 with InstanceStateTypes

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);
}
Also used : ControlPanelTypes(com.netflix.exhibitor.core.controlpanel.ControlPanelTypes) MonitorRunningInstance(com.netflix.exhibitor.core.state.MonitorRunningInstance) ObjectNode(org.codehaus.jackson.node.ObjectNode) InstanceStateTypes(com.netflix.exhibitor.core.state.InstanceStateTypes) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with InstanceStateTypes

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();
}
Also used : ServerSpec(com.netflix.exhibitor.core.state.ServerSpec) ServerStatus(com.netflix.exhibitor.core.entities.ServerStatus) ServerList(com.netflix.exhibitor.core.state.ServerList) InstanceStateTypes(com.netflix.exhibitor.core.state.InstanceStateTypes) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 4 with InstanceStateTypes

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);
    }
}
Also used : ServerStatus(com.netflix.exhibitor.core.entities.ServerStatus) JsonNode(org.codehaus.jackson.JsonNode) InstanceStateTypes(com.netflix.exhibitor.core.state.InstanceStateTypes) IOException(java.io.IOException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 5 with InstanceStateTypes

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);
}
Also used : ServerType(com.netflix.exhibitor.core.state.ServerType) ServerSpec(com.netflix.exhibitor.core.state.ServerSpec) ServerList(com.netflix.exhibitor.core.state.ServerList) InstanceStateTypes(com.netflix.exhibitor.core.state.InstanceStateTypes)

Aggregations

InstanceStateTypes (com.netflix.exhibitor.core.state.InstanceStateTypes)5 ServerStatus (com.netflix.exhibitor.core.entities.ServerStatus)3 ServerList (com.netflix.exhibitor.core.state.ServerList)2 ServerSpec (com.netflix.exhibitor.core.state.ServerSpec)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ControlPanelTypes (com.netflix.exhibitor.core.controlpanel.ControlPanelTypes)1 MonitorRunningInstance (com.netflix.exhibitor.core.state.MonitorRunningInstance)1 ServerType (com.netflix.exhibitor.core.state.ServerType)1 IOException (java.io.IOException)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 JsonNode (org.codehaus.jackson.JsonNode)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 ObjectNode (org.codehaus.jackson.node.ObjectNode)1