Search in sources :

Example 1 with LeaderHistory

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();
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) HelixManager(org.apache.helix.HelixManager) LeaderHistory(org.apache.helix.model.LeaderHistory) PropertyKey(org.apache.helix.PropertyKey) Test(org.testng.annotations.Test)

Example 2 with LeaderHistory

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);
}
Also used : HelixDataAccessor(org.apache.helix.HelixDataAccessor) HashMap(java.util.HashMap) LeaderHistory(org.apache.helix.model.LeaderHistory) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 3 with LeaderHistory

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!");
    }
}
Also used : HelixDataAccessor(org.apache.helix.HelixDataAccessor) Builder(org.apache.helix.PropertyKey.Builder) LeaderHistory(org.apache.helix.model.LeaderHistory)

Aggregations

LeaderHistory (org.apache.helix.model.LeaderHistory)3 HelixDataAccessor (org.apache.helix.HelixDataAccessor)2 HashMap (java.util.HashMap)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 HelixManager (org.apache.helix.HelixManager)1 PropertyKey (org.apache.helix.PropertyKey)1 Builder (org.apache.helix.PropertyKey.Builder)1 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)1 Test (org.testng.annotations.Test)1