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());
}
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());
}
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");
}
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());
}
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();
}
Aggregations