use of org.apache.helix.model.LeaderHistory in project helix by apache.
the class TestControllerHistory method testControllerLeaderHistory.
@Test()
public void testControllerLeaderHistory() throws Exception {
HelixManager manager = HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, "admin", InstanceType.ADMINISTRATOR, ZK_ADDR);
manager.connect();
PropertyKey.Builder keyBuilder = new PropertyKey.Builder(CLUSTER_NAME);
PropertyKey propertyKey = keyBuilder.controllerLeaderHistory();
LeaderHistory leaderHistory = manager.getHelixDataAccessor().getProperty(propertyKey);
Assert.assertNotNull(leaderHistory);
List<String> list = leaderHistory.getRecord().getListField("HISTORY");
Assert.assertEquals(list.size(), 1);
for (int i = 0; i <= 12; i++) {
_controller.syncStop();
_controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, "Controller-" + i);
_controller.syncStart();
}
leaderHistory = manager.getHelixDataAccessor().getProperty(propertyKey);
Assert.assertNotNull(leaderHistory);
list = leaderHistory.getRecord().getListField("HISTORY");
Assert.assertEquals(list.size(), 10);
manager.disconnect();
}
use of org.apache.helix.model.LeaderHistory in project helix by apache.
the class ClusterAccessor method getClusterControllerHistory.
@GET
@Path("{clusterId}/controller/history")
public Response getClusterControllerHistory(@PathParam("clusterId") String clusterId) {
HelixDataAccessor dataAccessor = getDataAccssor(clusterId);
Map<String, Object> controllerHistory = new HashMap<>();
controllerHistory.put(Properties.id.name(), clusterId);
LeaderHistory history = dataAccessor.getProperty(dataAccessor.keyBuilder().controllerLeaderHistory());
if (history != null) {
controllerHistory.put(Properties.history.name(), history.getHistoryList());
} else {
controllerHistory.put(Properties.history.name(), Collections.emptyList());
}
return JSONRepresentation(controllerHistory);
}
use of org.apache.helix.model.LeaderHistory in project helix by apache.
the class DistributedLeaderElection method updateHistory.
private void updateHistory(HelixManager manager) {
HelixDataAccessor accessor = manager.getHelixDataAccessor();
Builder keyBuilder = accessor.keyBuilder();
LeaderHistory history = accessor.getProperty(keyBuilder.controllerLeaderHistory());
if (history == null) {
history = new LeaderHistory(PropertyType.HISTORY.toString());
}
history.updateHistory(manager.getClusterName(), manager.getInstanceName(), manager.getVersion());
if (!accessor.setProperty(keyBuilder.controllerLeaderHistory(), history)) {
LOG.error("Failed to persist leader history to ZK!");
}
}
Aggregations