Search in sources :

Example 66 with ClusterControllerManager

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

the class TestDelayedAutoRebalance method beforeClass.

@BeforeClass
public void beforeClass() throws Exception {
    System.out.println("START " + CLASS_NAME + " at " + new Date(System.currentTimeMillis()));
    String namespace = "/" + CLUSTER_NAME;
    if (_gZkClient.exists(namespace)) {
        _gZkClient.deleteRecursively(namespace);
    }
    _setupTool = new ClusterSetup(_gZkClient);
    _setupTool.addCluster(CLUSTER_NAME, true);
    for (int i = 0; i < NUM_NODE; i++) {
        String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
        _setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
        // start dummy participants
        MockParticipantManager participant = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, storageNodeName);
        participant.syncStart();
        _participants.add(participant);
    }
    // start controller
    String controllerName = CONTROLLER_PREFIX + "_0";
    _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
    _controller.syncStart();
    _clusterVerifier = new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(ZK_ADDR).build();
    enablePersistBestPossibleAssignment(_gZkClient, CLUSTER_NAME, true);
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) BestPossibleExternalViewVerifier(org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier) ClusterSetup(org.apache.helix.tools.ClusterSetup) Date(java.util.Date) BeforeClass(org.testng.annotations.BeforeClass)

Example 67 with ClusterControllerManager

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

the class TestDelayedAutoRebalanceWithRackaware method beforeClass.

@BeforeClass
public void beforeClass() throws Exception {
    System.out.println("START " + CLASS_NAME + " at " + new Date(System.currentTimeMillis()));
    String namespace = "/" + CLUSTER_NAME;
    if (_gZkClient.exists(namespace)) {
        _gZkClient.deleteRecursively(namespace);
    }
    _setupTool = new ClusterSetup(_gZkClient);
    _setupTool.addCluster(CLUSTER_NAME, true);
    for (int i = 0; i < NUM_NODE; i++) {
        String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
        _setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
        String zone = "zone-" + i % 3;
        _setupTool.getClusterManagementTool().setInstanceZoneId(CLUSTER_NAME, storageNodeName, zone);
        // start dummy participants
        MockParticipantManager participant = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, storageNodeName);
        participant.syncStart();
        _participants.add(participant);
    }
    enableTopologyAwareRebalance(_gZkClient, CLUSTER_NAME, true);
    enablePersistBestPossibleAssignment(_gZkClient, CLUSTER_NAME, true);
    // start controller
    String controllerName = CONTROLLER_PREFIX + "_0";
    _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
    _controller.syncStart();
    _clusterVerifier = new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(ZK_ADDR).build();
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) BestPossibleExternalViewVerifier(org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier) ClusterSetup(org.apache.helix.tools.ClusterSetup) Date(java.util.Date) BeforeClass(org.testng.annotations.BeforeClass)

Example 68 with ClusterControllerManager

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

the class TestSemiAutoRebalance method beforeClass.

@BeforeClass
public void beforeClass() throws InterruptedException {
    System.out.println("START " + getShortClassName() + " at " + new Date(System.currentTimeMillis()));
    String namespace = "/" + CLUSTER_NAME;
    if (_gZkClient.exists(namespace)) {
        _gZkClient.deleteRecursively(namespace);
    }
    // setup storage cluster
    _gSetupTool.addCluster(CLUSTER_NAME, true);
    _gSetupTool.addResourceToCluster(CLUSTER_NAME, DB_NAME, PARTITION_NUMBER, STATE_MODEL, IdealState.RebalanceMode.SEMI_AUTO.toString());
    _accessor = new ZKHelixDataAccessor(CLUSTER_NAME, _baseAccessor);
    _keyBuilder = _accessor.keyBuilder();
    List<String> instances = new ArrayList<String>();
    for (int i = 0; i < PARTICIPANT_NUMBER; i++) {
        String instance = PARTICIPANT_PREFIX + "_" + (PARTICIPANT_START_PORT + i);
        _gSetupTool.addInstanceToCluster(CLUSTER_NAME, instance);
        instances.add(instance);
    }
    _gSetupTool.rebalanceStorageCluster(CLUSTER_NAME, DB_NAME, REPLICA_NUMBER);
    // start dummy participants
    for (int i = 0; i < PARTICIPANT_NUMBER; i++) {
        MockParticipantManager participant = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instances.get(i));
        participant.syncStart();
        _participants.add(participant);
    }
    // start controller
    String controllerName = CONTROLLER_PREFIX + "_0";
    _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
    _controller.syncStart();
    Thread.sleep(1000);
    // verify ideal state and external view
    IdealState idealState = _accessor.getProperty(_keyBuilder.idealStates(DB_NAME));
    Assert.assertNotNull(idealState);
    Assert.assertEquals(idealState.getNumPartitions(), PARTITION_NUMBER);
    for (String partition : idealState.getPartitionSet()) {
        List<String> preferenceList = idealState.getPreferenceList(partition);
        Assert.assertNotNull(preferenceList);
        Assert.assertEquals(preferenceList.size(), REPLICA_NUMBER);
    }
    ExternalView externalView = _accessor.getProperty(_keyBuilder.externalView(DB_NAME));
    Assert.assertNotNull(externalView);
    Assert.assertEquals(externalView.getPartitionSet().size(), PARTITION_NUMBER);
    for (String partition : externalView.getPartitionSet()) {
        Map<String, String> stateMap = externalView.getStateMap(partition);
        Assert.assertEquals(stateMap.size(), REPLICA_NUMBER);
        int masters = 0;
        for (String state : stateMap.values()) {
            if (state.equals(MasterSlaveSMD.States.MASTER.name())) {
                ++masters;
            }
        }
        Assert.assertEquals(masters, 1);
    }
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) ExternalView(org.apache.helix.model.ExternalView) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) ArrayList(java.util.ArrayList) Date(java.util.Date) IdealState(org.apache.helix.model.IdealState) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) BeforeClass(org.testng.annotations.BeforeClass)

Example 69 with ClusterControllerManager

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

the class TaskTestBase method beforeClass.

@BeforeClass
public void beforeClass() throws Exception {
    super.beforeClass();
    // start controller
    String controllerName = CONTROLLER_PREFIX + "_0";
    _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
    _controller.syncStart();
    boolean result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, CLUSTER_NAME));
    Assert.assertTrue(result);
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) ClusterStateVerifier(org.apache.helix.tools.ClusterStateVerifier) BeforeClass(org.testng.annotations.BeforeClass)

Example 70 with ClusterControllerManager

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

the class TestAutoIsWithEmptyMap method testAutoIsWithEmptyMap.

@Test
public void testAutoIsWithEmptyMap() 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
    10, // number of nodes
    5, // replicas
    3, "LeaderStandby", // do not rebalance
    false);
    // calculate and set custom ideal state
    String idealPath = PropertyPathBuilder.idealState(clusterName, "TestDB0");
    ZNRecord curIdealState = _gZkClient.readData(idealPath);
    List<String> instanceNames = new ArrayList<String>(5);
    for (int i = 0; i < 5; i++) {
        int port = 12918 + i;
        instanceNames.add("localhost_" + port);
    }
    ZNRecord idealState = DefaultIdealStateCalculator.calculateIdealState(instanceNames, 10, 2, "TestDB0", "LEADER", "STANDBY");
    // System.out.println(idealState);
    // curIdealState.setSimpleField(IdealState.IdealStateProperty.IDEAL_STATE_MODE.toString(),
    // "CUSTOMIZED");
    curIdealState.setSimpleField(IdealState.IdealStateProperty.REPLICAS.toString(), "3");
    curIdealState.setListFields(idealState.getListFields());
    _gZkClient.writeData(idealPath, curIdealState);
    // start controller
    ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
    controller.syncStart();
    // start participants
    MockParticipantManager[] participants = new MockParticipantManager[5];
    for (int i = 0; i < 5; i++) {
        String instanceName = "localhost_" + (12918 + i);
        participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
        participants[i].syncStart();
    }
    boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    // clean up
    controller.syncStop();
    for (int i = 0; i < 5; 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) ArrayList(java.util.ArrayList) BestPossAndExtViewZkVerifier(org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier) Date(java.util.Date) ZNRecord(org.apache.helix.ZNRecord) 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