Search in sources :

Example 11 with HelixDataAccessor

use of org.apache.helix.HelixDataAccessor in project helix by apache.

the class GenericHelixController method onControllerChange.

@Override
public void onControllerChange(NotificationContext changeContext) {
    logger.info("START: GenericClusterController.onControllerChange() for cluster " + _clusterName);
    _cache.requireFullRefresh();
    _taskCache.requireFullRefresh();
    boolean controllerIsLeader;
    if (changeContext != null && changeContext.getType() == Type.FINALIZE) {
        logger.info("GenericClusterController.onControllerChange() FINALIZE for cluster " + _clusterName);
        controllerIsLeader = false;
    } else {
        // double check if this controller is the leader
        controllerIsLeader = changeContext.getManager().isLeader();
    }
    HelixManager manager = changeContext.getManager();
    if (controllerIsLeader) {
        HelixDataAccessor accessor = manager.getHelixDataAccessor();
        Builder keyBuilder = accessor.keyBuilder();
        PauseSignal pauseSignal = accessor.getProperty(keyBuilder.pause());
        MaintenanceSignal maintenanceSignal = accessor.getProperty(keyBuilder.maintenance());
        _paused = updateControllerState(changeContext, pauseSignal, _paused);
        _inMaintenanceMode = updateControllerState(changeContext, maintenanceSignal, _inMaintenanceMode);
        enableClusterStatusMonitor(true);
        _clusterStatusMonitor.setEnabled(!_paused);
        _clusterStatusMonitor.setPaused(_paused);
        _clusterStatusMonitor.setMaintenance(_inMaintenanceMode);
    } else {
        enableClusterStatusMonitor(false);
    }
    logger.info("END: GenericClusterController.onControllerChange() for cluster " + _clusterName);
}
Also used : HelixDataAccessor(org.apache.helix.HelixDataAccessor) HelixManager(org.apache.helix.HelixManager) Builder(org.apache.helix.PropertyKey.Builder)

Example 12 with HelixDataAccessor

use of org.apache.helix.HelixDataAccessor in project helix by apache.

the class IntegrationTest method printStatus.

private static void printStatus(final HelixManager manager) {
    System.out.println("CLUSTER STATUS");
    HelixDataAccessor helixDataAccessor = manager.getHelixDataAccessor();
    Builder keyBuilder = helixDataAccessor.keyBuilder();
    System.out.println("External View \n" + helixDataAccessor.getProperty(keyBuilder.externalView("repository")));
}
Also used : HelixDataAccessor(org.apache.helix.HelixDataAccessor) HelixConfigScopeBuilder(org.apache.helix.model.builder.HelixConfigScopeBuilder) Builder(org.apache.helix.PropertyKey.Builder)

Example 13 with HelixDataAccessor

use of org.apache.helix.HelixDataAccessor in project helix by apache.

the class ServiceDiscovery method refreshCache.

private void refreshCache() {
    Builder propertyKeyBuilder = new PropertyKey.Builder(cluster);
    HelixDataAccessor helixDataAccessor = admin.getHelixDataAccessor();
    List<LiveInstance> liveInstances = helixDataAccessor.getChildValues(propertyKeyBuilder.liveInstances());
    refreshCache(liveInstances);
}
Also used : HelixDataAccessor(org.apache.helix.HelixDataAccessor) LiveInstance(org.apache.helix.model.LiveInstance) HelixConfigScopeBuilder(org.apache.helix.model.builder.HelixConfigScopeBuilder) Builder(org.apache.helix.PropertyKey.Builder)

Example 14 with HelixDataAccessor

use of org.apache.helix.HelixDataAccessor in project helix by apache.

the class TestHelixAdminScenariosRest method testInstanceOperations.

@Test
public void testInstanceOperations() throws Exception {
    final String clusterName = "clusterTestInstanceOperations";
    // setup cluster
    addCluster(clusterName);
    addInstancesToCluster(clusterName, "localhost:123", 6, null);
    addResource(clusterName, "db_11", 8);
    rebalanceResource(clusterName, "db_11");
    ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_9900");
    controller.syncStart();
    // start mock nodes
    Map<String, MockParticipantManager> participants = new HashMap<String, MockParticipantManager>();
    for (int i = 0; i < 6; i++) {
        String instanceName = "localhost_123" + i;
        MockParticipantManager participant = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
        participant.syncStart();
        participants.put(instanceName, participant);
    }
    HelixDataAccessor accessor;
    // drop node should fail as not disabled
    String instanceUrl = getInstanceUrl(clusterName, "localhost_1232");
    deleteUrl(instanceUrl, true);
    // disabled node
    String response = assertSuccessPostOperation(instanceUrl, enableInstanceCmd(false), false);
    Assert.assertTrue(response.contains("false"));
    // Cannot drop / swap
    deleteUrl(instanceUrl, true);
    String instancesUrl = getClusterUrl(clusterName) + "/instances";
    response = assertSuccessPostOperation(instancesUrl, swapInstanceCmd("localhost_1232", "localhost_12320"), true);
    // disconnect the node
    participants.get("localhost_1232").syncStop();
    // add new node then swap instance
    response = assertSuccessPostOperation(instancesUrl, addInstanceCmd("localhost_12320"), false);
    Assert.assertTrue(response.contains("localhost_12320"));
    // swap instance. The instance get swapped out should not exist anymore
    response = assertSuccessPostOperation(instancesUrl, swapInstanceCmd("localhost_1232", "localhost_12320"), false);
    Assert.assertTrue(response.contains("localhost_12320"));
    Assert.assertFalse(response.contains("localhost_1232\""));
    accessor = participants.get("localhost_1231").getHelixDataAccessor();
    String path = accessor.keyBuilder().instanceConfig("localhost_1232").getPath();
    Assert.assertFalse(_gZkClient.exists(path));
    MockParticipantManager newParticipant = new MockParticipantManager(ZK_ADDR, clusterName, "localhost_12320");
    newParticipant.syncStart();
    participants.put("localhost_12320", newParticipant);
    boolean verifyResult = ClusterStateVerifier.verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(verifyResult);
    // clean up
    controller.syncStop();
    for (MockParticipantManager participant : participants.values()) {
        participant.syncStop();
    }
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) MasterNbInExtViewVerifier(org.apache.helix.tools.ClusterStateVerifier.MasterNbInExtViewVerifier) HelixDataAccessor(org.apache.helix.HelixDataAccessor) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Example 15 with HelixDataAccessor

use of org.apache.helix.HelixDataAccessor in project helix by apache.

the class TestHelixAdminScenariosRest method testStartCluster.

@Test
public void testStartCluster() throws Exception {
    final String clusterName = "clusterTestStartCluster";
    final String controllerClusterName = "controllerClusterTestStartCluster";
    Map<String, MockParticipantManager> participants = new HashMap<String, MockParticipantManager>();
    Map<String, ClusterDistributedController> distControllers = new HashMap<String, ClusterDistributedController>();
    // setup cluster
    addCluster(clusterName);
    addInstancesToCluster(clusterName, "localhost:123", 6, null);
    addResource(clusterName, "db_11", 8);
    rebalanceResource(clusterName, "db_11");
    addCluster(controllerClusterName);
    addInstancesToCluster(controllerClusterName, "controller_900", 2, null);
    // start mock nodes
    for (int i = 0; i < 6; i++) {
        String instanceName = "localhost_123" + i;
        MockParticipantManager participant = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
        participant.syncStart();
        participants.put(instanceName, participant);
    }
    // start controller nodes
    for (int i = 0; i < 2; i++) {
        String controllerName = "controller_900" + i;
        ClusterDistributedController distController = new ClusterDistributedController(ZK_ADDR, controllerClusterName, controllerName);
        distController.syncStart();
        distControllers.put(controllerName, distController);
    }
    Thread.sleep(100);
    // activate clusters
    // wrong grand clustername
    String clusterUrl = getClusterUrl(clusterName);
    assertSuccessPostOperation(clusterUrl, activateClusterCmd("nonExistCluster", true), true);
    // wrong cluster name
    clusterUrl = getClusterUrl("nonExistCluster");
    assertSuccessPostOperation(clusterUrl, activateClusterCmd(controllerClusterName, true), true);
    clusterUrl = getClusterUrl(clusterName);
    assertSuccessPostOperation(clusterUrl, activateClusterCmd(controllerClusterName, true), false);
    Thread.sleep(500);
    deleteUrl(clusterUrl, true);
    // verify leader node
    HelixDataAccessor accessor = distControllers.get("controller_9001").getHelixDataAccessor();
    LiveInstance controllerLeader = accessor.getProperty(accessor.keyBuilder().controllerLeader());
    Assert.assertTrue(controllerLeader.getInstanceName().startsWith("controller_900"));
    accessor = participants.get("localhost_1232").getHelixDataAccessor();
    LiveInstance leader = accessor.getProperty(accessor.keyBuilder().controllerLeader());
    for (int i = 0; i < 5; i++) {
        if (leader != null) {
            break;
        }
        Thread.sleep(1000);
        leader = accessor.getProperty(accessor.keyBuilder().controllerLeader());
    }
    Assert.assertTrue(leader.getInstanceName().startsWith("controller_900"));
    boolean verifyResult = ClusterStateVerifier.verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(verifyResult);
    verifyResult = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(verifyResult);
    Thread.sleep(1000);
    // clean up
    for (ClusterDistributedController controller : distControllers.values()) {
        controller.syncStop();
    }
    for (MockParticipantManager participant : participants.values()) {
        participant.syncStop();
    }
}
Also used : MasterNbInExtViewVerifier(org.apache.helix.tools.ClusterStateVerifier.MasterNbInExtViewVerifier) ClusterDistributedController(org.apache.helix.integration.manager.ClusterDistributedController) HelixDataAccessor(org.apache.helix.HelixDataAccessor) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) LiveInstance(org.apache.helix.model.LiveInstance) HashMap(java.util.HashMap) BestPossAndExtViewZkVerifier(org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier) Test(org.testng.annotations.Test)

Aggregations

HelixDataAccessor (org.apache.helix.HelixDataAccessor)173 ZNRecord (org.apache.helix.ZNRecord)91 PropertyKey (org.apache.helix.PropertyKey)69 Test (org.testng.annotations.Test)67 Builder (org.apache.helix.PropertyKey.Builder)59 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)40 Date (java.util.Date)39 HelixManager (org.apache.helix.HelixManager)35 IdealState (org.apache.helix.model.IdealState)33 LiveInstance (org.apache.helix.model.LiveInstance)31 HashMap (java.util.HashMap)30 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)30 Message (org.apache.helix.model.Message)30 ArrayList (java.util.ArrayList)28 ExternalView (org.apache.helix.model.ExternalView)26 PropertyPathBuilder (org.apache.helix.PropertyPathBuilder)25 Map (java.util.Map)19 HelixException (org.apache.helix.HelixException)19 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)19 InstanceConfig (org.apache.helix.model.InstanceConfig)17