Search in sources :

Example 91 with ClusterControllerManager

use of org.apache.helix.integration.manager.ClusterControllerManager in project helix by apache.

the class TestDisableExternalView method beforeClass.

@BeforeClass
public void beforeClass() throws Exception {
    System.out.println("START " + CLASS_NAME + " at " + new Date(System.currentTimeMillis()));
    _admin = new ZKHelixAdmin(_gZkClient);
    String namespace = "/" + CLUSTER_NAME;
    if (_gZkClient.exists(namespace)) {
        _gZkClient.deleteRecursively(namespace);
    }
    // setup storage cluster
    _gSetupTool.addCluster(CLUSTER_NAME, true);
    _gSetupTool.addResourceToCluster(CLUSTER_NAME, TEST_DB1, _PARTITIONS, STATE_MODEL, IdealState.RebalanceMode.FULL_AUTO + "");
    IdealState idealState = _admin.getResourceIdealState(CLUSTER_NAME, TEST_DB1);
    idealState.setDisableExternalView(true);
    _admin.setResourceIdealState(CLUSTER_NAME, TEST_DB1, idealState);
    _gSetupTool.addResourceToCluster(CLUSTER_NAME, TEST_DB2, _PARTITIONS, STATE_MODEL, IdealState.RebalanceMode.FULL_AUTO + "");
    for (int i = 0; i < NODE_NR; i++) {
        instances[i] = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
        _gSetupTool.addInstanceToCluster(CLUSTER_NAME, instances[i]);
    }
    _gSetupTool.rebalanceStorageCluster(CLUSTER_NAME, TEST_DB1, _replica);
    _gSetupTool.rebalanceStorageCluster(CLUSTER_NAME, TEST_DB2, _replica);
    // start dummy participants
    for (int i = 0; i < NODE_NR; i++) {
        String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
        MockParticipantManager participant = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
        participant.syncStart();
        _participants[i] = participant;
    }
    // start controller
    String controllerName = CONTROLLER_PREFIX + "_0";
    _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
    _controller.syncStart();
    boolean result = ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, CLUSTER_NAME));
    Assert.assertTrue(result);
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) ClusterStateVerifier(org.apache.helix.tools.ClusterStateVerifier) Date(java.util.Date) IdealState(org.apache.helix.model.IdealState) BeforeClass(org.testng.annotations.BeforeClass)

Example 92 with ClusterControllerManager

use of org.apache.helix.integration.manager.ClusterControllerManager in project helix by apache.

the class TestDisablePartition method testDisableFullAuto.

@Test(dataProvider = "rebalancer", enabled = true)
public void testDisableFullAuto(String rebalancerName) throws Exception {
    final int NUM_PARTITIONS = 8;
    final int NUM_PARTICIPANTS = 2;
    final int NUM_REPLICAS = 1;
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    String clusterName = className + "_" + methodName;
    ClusterSetup clusterSetup = new ClusterSetup(ZK_ADDR);
    clusterSetup.addCluster(clusterName, true);
    for (int i = 0; i < NUM_PARTICIPANTS; i++) {
        String instanceName = "localhost_" + (11420 + i);
        clusterSetup.addInstanceToCluster(clusterName, instanceName);
    }
    // Create a known problematic scenario
    HelixAdmin admin = clusterSetup.getClusterManagementTool();
    String resourceName = "MailboxDB";
    IdealState idealState = new IdealState(resourceName + "DR");
    idealState.setRebalanceMode(RebalanceMode.SEMI_AUTO);
    idealState.setStateModelDefRef("LeaderStandby");
    idealState.setReplicas(String.valueOf(NUM_REPLICAS));
    idealState.setNumPartitions(NUM_PARTITIONS);
    for (int i = 0; i < NUM_PARTITIONS; i++) {
        String partitionName = resourceName + '_' + i;
        List<String> assignmentList = Lists.newArrayList();
        if (i < NUM_PARTITIONS / 2) {
            assignmentList.add("localhost_11420");
        } else {
            assignmentList.add("localhost_11421");
        }
        Map<String, String> emptyMap = Maps.newHashMap();
        idealState.getRecord().setListField(partitionName, assignmentList);
        idealState.getRecord().setMapField(partitionName, emptyMap);
    }
    admin.addResource(clusterName, idealState.getResourceName(), idealState);
    // Start everything
    MockParticipantManager[] participants = new MockParticipantManager[NUM_PARTICIPANTS];
    for (int i = 0; i < NUM_PARTICIPANTS; i++) {
        String instanceName = "localhost_" + (11420 + i);
        participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
        participants[i].syncStart();
    }
    ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_1");
    controller.syncStart();
    Thread.sleep(1000);
    // Switch to full auto
    idealState.setRebalanceMode(RebalanceMode.FULL_AUTO);
    idealState.setRebalancerClassName(rebalancerName);
    for (int i = 0; i < NUM_PARTITIONS; i++) {
        List<String> emptyList = Collections.emptyList();
        idealState.getRecord().setListField(resourceName + '_' + i, emptyList);
    }
    admin.setResourceIdealState(clusterName, idealState.getResourceName(), idealState);
    Thread.sleep(1000);
    // Get the external view
    HelixDataAccessor accessor = controller.getHelixDataAccessor();
    PropertyKey.Builder keyBuilder = accessor.keyBuilder();
    ExternalView externalView = accessor.getProperty(keyBuilder.externalView(idealState.getResourceName()));
    // Disable the partitions in an order known to cause problems
    int[] pid = { 0, 7 };
    for (int i = 0; i < pid.length; i++) {
        String partitionName = resourceName + '_' + pid[i];
        Map<String, String> stateMap = externalView.getStateMap(partitionName);
        String leader = null;
        for (String participantName : stateMap.keySet()) {
            String state = stateMap.get(participantName);
            if (state.equals("LEADER")) {
                leader = participantName;
            }
        }
        List<String> partitionNames = Lists.newArrayList(partitionName);
        admin.enablePartition(false, clusterName, leader, idealState.getResourceName(), partitionNames);
        Thread.sleep(1000);
    }
    // Ensure that nothing was reassigned and the disabled are offline
    externalView = accessor.getProperty(keyBuilder.externalView(idealState.getResourceName()));
    Map<String, String> p0StateMap = externalView.getStateMap(resourceName + "_0");
    Assert.assertEquals(p0StateMap.size(), 1);
    String p0Participant = p0StateMap.keySet().iterator().next();
    Assert.assertEquals(p0StateMap.get(p0Participant), "OFFLINE");
    Map<String, String> p7StateMap = externalView.getStateMap(resourceName + "_7");
    Assert.assertEquals(p7StateMap.size(), 1);
    String p7Participant = p7StateMap.keySet().iterator().next();
    Assert.assertEquals(p7StateMap.get(p7Participant), "OFFLINE");
    // Cleanup
    controller.syncStop();
    for (MockParticipantManager participant : participants) {
        participant.syncStop();
    }
}
Also used : ExternalView(org.apache.helix.model.ExternalView) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) ClusterSetup(org.apache.helix.tools.ClusterSetup) HelixAdmin(org.apache.helix.HelixAdmin) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) IdealState(org.apache.helix.model.IdealState) ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) HelixDataAccessor(org.apache.helix.HelixDataAccessor) PropertyKey(org.apache.helix.PropertyKey) Test(org.testng.annotations.Test)

Example 93 with ClusterControllerManager

use of org.apache.helix.integration.manager.ClusterControllerManager in project helix by apache.

the class TestDisableResource method testDisableResourceInFullAutoMode.

@Test
public void testDisableResourceInFullAutoMode() throws Exception {
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    String clusterName = className + "_" + methodName;
    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
    // participant port
    TestHelper.setupCluster(// participant port
    clusterName, // participant port
    ZK_ADDR, // participant port
    12918, // participant name prefix
    "localhost", // resource name prefix
    "TestDB", // resources
    1, // partitions per resource
    PARTITION_NUM, // number of nodes
    N, // replicas
    2, "MasterSlave", RebalanceMode.FULL_AUTO, // do rebalance
    true);
    ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller");
    controller.syncStart();
    // start participants
    MockParticipantManager[] participants = new MockParticipantManager[N];
    for (int i = 0; i < N; i++) {
        String instanceName = "localhost_" + (12918 + i);
        participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
        participants[i].syncStart();
    }
    boolean result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    // disable TestDB0
    enableResource(clusterName, false);
    checkExternalView(clusterName);
    // Re-enable TestDB0
    enableResource(clusterName, true);
    result = ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    // Clean up
    controller.syncStop();
    for (int i = 0; i < N; i++) {
        participants[i].syncStop();
    }
    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) ClusterStateVerifier(org.apache.helix.tools.ClusterStateVerifier) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 94 with ClusterControllerManager

use of org.apache.helix.integration.manager.ClusterControllerManager in project helix by apache.

the class TestDisableResource method testDisableResourceInSemiAutoMode.

@Test
public void testDisableResourceInSemiAutoMode() throws Exception {
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    String clusterName = className + "_" + methodName;
    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
    // participant port
    TestHelper.setupCluster(// participant port
    clusterName, // participant port
    ZK_ADDR, // participant port
    12918, // participant name prefix
    "localhost", // resource name prefix
    "TestDB", // resources
    1, // partitions per resource
    PARTITION_NUM, // number of nodes
    N, // replicas
    2, "MasterSlave", // do rebalance
    true);
    ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller");
    controller.syncStart();
    // start participants
    MockParticipantManager[] participants = new MockParticipantManager[N];
    for (int i = 0; i < N; i++) {
        String instanceName = "localhost_" + (12918 + i);
        participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
        participants[i].syncStart();
    }
    boolean result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    // Disable TestDB0
    enableResource(clusterName, false);
    checkExternalView(clusterName);
    // Re-enable TestDB0
    enableResource(clusterName, true);
    result = ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    // Clean up
    controller.syncStop();
    for (int i = 0; i < N; i++) {
        participants[i].syncStop();
    }
    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) ClusterStateVerifier(org.apache.helix.tools.ClusterStateVerifier) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 95 with ClusterControllerManager

use of org.apache.helix.integration.manager.ClusterControllerManager in project helix by apache.

the class TestZkSessionExpiry method testMsgHdlrFtyReRegistration.

@Test
public void testMsgHdlrFtyReRegistration() throws Exception {
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    String clusterName = className + "_" + methodName;
    int n = 2;
    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
    // participant port
    TestHelper.setupCluster(// participant port
    clusterName, // participant port
    ZK_ADDR, // participant port
    12918, // participant name prefix
    "localhost", // resource name prefix
    "TestDB", // resources
    1, // partitions per resource
    8, // number of nodes
    n, // replicas
    2, "MasterSlave", // do rebalance
    true);
    ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
    controller.syncStart();
    // start participants
    Set<String> handledMsgSet = new HashSet<String>();
    MockParticipantManager[] participants = new MockParticipantManager[n];
    for (int i = 0; i < n; i++) {
        String instanceName = "localhost_" + (12918 + i);
        participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
        participants[i].getMessagingService().registerMessageHandlerFactory(DUMMY_MSG_TYPE, new DummyMessageHandlerFactory(handledMsgSet));
        participants[i].syncStart();
    }
    boolean result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    // trigger dummy message handler
    checkDummyMsgHandler(participants[0], handledMsgSet);
    // expire localhost_12918
    ZkTestHelper.expireSession(participants[0].getZkClient());
    result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    // trigger dummy message handler again
    checkDummyMsgHandler(participants[0], handledMsgSet);
    // clean up
    controller.syncStop();
    for (int i = 0; i < n; i++) {
        participants[i].syncStop();
    }
    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Also used : MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) ClusterStateVerifier(org.apache.helix.tools.ClusterStateVerifier) Date(java.util.Date) ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)125 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)101 Date (java.util.Date)88 Test (org.testng.annotations.Test)78 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)38 BeforeClass (org.testng.annotations.BeforeClass)37 ZNRecord (org.apache.helix.ZNRecord)33 ClusterSetup (org.apache.helix.tools.ClusterSetup)33 ClusterStateVerifier (org.apache.helix.tools.ClusterStateVerifier)30 BestPossAndExtViewZkVerifier (org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier)28 HashMap (java.util.HashMap)26 IdealState (org.apache.helix.model.IdealState)24 HelixDataAccessor (org.apache.helix.HelixDataAccessor)19 PropertyKey (org.apache.helix.PropertyKey)19 Map (java.util.Map)18 HelixClusterVerifier (org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier)17 ZKHelixAdmin (org.apache.helix.manager.zk.ZKHelixAdmin)15 BestPossibleExternalViewVerifier (org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier)15 Set (java.util.Set)14 ConfigAccessor (org.apache.helix.ConfigAccessor)14