Search in sources :

Example 6 with ServerStatus

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

the class TestFlexibleAutoInstanceManagement method testNoChange.

@Test
public void testNoChange() throws Exception {
    MockExhibitorInstance mockExhibitorInstance = new MockExhibitorInstance("a");
    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);
    final AtomicBoolean configWasChanged = new AtomicBoolean(false);
    AutomaticInstanceManagement management = new AutomaticInstanceManagement(mockExhibitorInstance.getMockExhibitor()) {

        @Override
        void adjustConfig(String newSpec, String leaderHostname) throws Exception {
            super.adjustConfig(newSpec, leaderHostname);
            configWasChanged.set(true);
        }
    };
    management.call();
    Assert.assertFalse(configWasChanged.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ServerStatus(com.netflix.exhibitor.core.entities.ServerStatus) Test(org.testng.annotations.Test)

Example 7 with ServerStatus

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

the class TestFlexibleAutoInstanceManagement method testNoServers.

@Test
public void testNoServers() throws Exception {
    MockExhibitorInstance mockExhibitorInstance = new MockExhibitorInstance("a");
    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.DOWN.getCode(), "", true));
    statuses.add(new ServerStatus("b", InstanceStateTypes.DOWN.getCode(), "", false));
    statuses.add(new ServerStatus("c", InstanceStateTypes.DOWN.getCode(), "", false));
    Mockito.when(mockExhibitorInstance.getMockForkJoinPool().invoke(Mockito.isA(ClusterStatusTask.class))).thenReturn(statuses);
    final AtomicBoolean configWasChanged = new AtomicBoolean(false);
    AutomaticInstanceManagement management = new AutomaticInstanceManagement(mockExhibitorInstance.getMockExhibitor()) {

        @Override
        void adjustConfig(String newSpec, String leaderHostname) throws Exception {
            super.adjustConfig(newSpec, leaderHostname);
            configWasChanged.set(true);
        }
    };
    management.call();
    Assert.assertFalse(configWasChanged.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ServerStatus(com.netflix.exhibitor.core.entities.ServerStatus) Test(org.testng.annotations.Test)

Example 8 with ServerStatus

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

the class TestFlexibleAutoInstanceManagement method testAdditionWithConfigContention.

@Test
public void testAdditionWithConfigContention() 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());
    LoadedInstanceConfig loadedInstanceConfig = mockExhibitorInstance.getMockExhibitor().getConfigManager().getLoadedInstanceConfig();
    LoadedInstanceConfig changedCoadedInstanceConfig = new LoadedInstanceConfig(loadedInstanceConfig.getConfig(), loadedInstanceConfig.getVersion() + 1);
    mockExhibitorInstance.getMockExhibitor().getConfigManager().testingSetLoadedInstanceConfig(changedCoadedInstanceConfig);
    management.call();
    // instance addition should have failed
    Assert.assertEquals(mockExhibitorInstance.getMockExhibitor().getConfigManager().getConfig().getString(StringConfigs.SERVERS_SPEC), "1:a,2:b,3:c");
}
Also used : ServerStatus(com.netflix.exhibitor.core.entities.ServerStatus) LoadedInstanceConfig(com.netflix.exhibitor.core.config.LoadedInstanceConfig) Test(org.testng.annotations.Test)

Example 9 with ServerStatus

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

the class TestFlexibleAutoInstanceManagement method testUnstable.

@Test
public void testUnstable() 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_FIXED_ENSEMBLE_SIZE, 0);
    mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.AUTO_MANAGE_INSTANCES_SETTLING_PERIOD_MS, 100000);
    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);
    final AtomicBoolean configWasChanged = new AtomicBoolean(false);
    AutomaticInstanceManagement management = new AutomaticInstanceManagement(mockExhibitorInstance.getMockExhibitor()) {

        @Override
        void adjustConfig(String newSpec, String leaderHostname) throws Exception {
            super.adjustConfig(newSpec, leaderHostname);
            configWasChanged.set(true);
        }
    };
    management.call();
    // hasn't settled yet
    Assert.assertFalse(configWasChanged.get());
    statuses = Lists.newArrayList();
    statuses.add(new ServerStatus("a", InstanceStateTypes.DOWN.getCode(), "", false));
    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);
    mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.AUTO_MANAGE_INSTANCES_SETTLING_PERIOD_MS, 0);
    mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.AUTO_MANAGE_INSTANCES_FIXED_ENSEMBLE_SIZE, 0);
    management.call();
    Assert.assertFalse(configWasChanged.get());
    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);
    mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.AUTO_MANAGE_INSTANCES_SETTLING_PERIOD_MS, 2000);
    mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.AUTO_MANAGE_INSTANCES_FIXED_ENSEMBLE_SIZE, 0);
    management.call();
    Assert.assertFalse(configWasChanged.get());
    Thread.sleep(3000);
    management.call();
    Assert.assertTrue(configWasChanged.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ServerStatus(com.netflix.exhibitor.core.entities.ServerStatus) Test(org.testng.annotations.Test)

Example 10 with ServerStatus

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

the class ClusterResource method getClusterStatus.

@Path("status")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getClusterStatus() throws Exception {
    InstanceConfig config = context.getExhibitor().getConfigManager().getConfig();
    ServerList serverList = new ServerList(config.getString(StringConfigs.SERVERS_SPEC));
    ClusterStatusTask task = new ClusterStatusTask(context.getExhibitor(), serverList.getSpecs());
    List<ServerStatus> statuses = context.getExhibitor().getForkJoinPool().invoke(task);
    GenericEntity<List<ServerStatus>> entity = new GenericEntity<List<ServerStatus>>(statuses) {
    };
    return Response.ok(entity).build();
}
Also used : InstanceConfig(com.netflix.exhibitor.core.config.InstanceConfig) GenericEntity(javax.ws.rs.core.GenericEntity) ServerStatus(com.netflix.exhibitor.core.entities.ServerStatus) ServerList(com.netflix.exhibitor.core.state.ServerList) ServerList(com.netflix.exhibitor.core.state.ServerList) List(java.util.List) ClusterStatusTask(com.netflix.exhibitor.core.automanage.ClusterStatusTask) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

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