Search in sources :

Example 16 with ServerStatus

use of com.netflix.exhibitor.core.entities.ServerStatus in project exhibitor by soabase.

the class TestFlexibleAutoInstanceManagement method testAddition.

@Test
public void testAddition() 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);
    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,4:new");
}
Also used : ServerStatus(com.netflix.exhibitor.core.entities.ServerStatus) Test(org.testng.annotations.Test)

Example 17 with ServerStatus

use of com.netflix.exhibitor.core.entities.ServerStatus 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 18 with ServerStatus

use of com.netflix.exhibitor.core.entities.ServerStatus 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)

Aggregations

ServerStatus (com.netflix.exhibitor.core.entities.ServerStatus)18 Test (org.testng.annotations.Test)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 ServerList (com.netflix.exhibitor.core.state.ServerList)4 InstanceStateTypes (com.netflix.exhibitor.core.state.InstanceStateTypes)3 ServerSpec (com.netflix.exhibitor.core.state.ServerSpec)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ClusterStatusTask (com.netflix.exhibitor.core.automanage.ClusterStatusTask)1 InstanceConfig (com.netflix.exhibitor.core.config.InstanceConfig)1 LoadedInstanceConfig (com.netflix.exhibitor.core.config.LoadedInstanceConfig)1 PseudoLock (com.netflix.exhibitor.core.config.PseudoLock)1 IOException (java.io.IOException)1 List (java.util.List)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 GenericEntity (javax.ws.rs.core.GenericEntity)1 JsonNode (org.codehaus.jackson.JsonNode)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1