Search in sources :

Example 96 with MockParticipantManager

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

the class TestSemiAutoRebalance method testStopAndReStartParticipant.

@Test(dependsOnMethods = "testAddParticipant")
public void testStopAndReStartParticipant() throws InterruptedException {
    MockParticipantManager participant = _participants.get(0);
    String instance = participant.getInstanceName();
    Map<String, MasterSlaveSMD.States> affectedPartitions = new HashMap<String, MasterSlaveSMD.States>();
    ExternalView externalView = _accessor.getProperty(_keyBuilder.externalView(DB_NAME));
    for (String partition : externalView.getPartitionSet()) {
        Map<String, String> stateMap = externalView.getStateMap(partition);
        if (stateMap.containsKey(instance)) {
            affectedPartitions.put(partition, MasterSlaveSMD.States.valueOf(stateMap.get(instance)));
        }
    }
    stopParticipant(participant, affectedPartitions);
    // create a new participant
    participant = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instance);
    _participants.set(0, participant);
    startParticipant(participant, affectedPartitions);
}
Also used : ExternalView(org.apache.helix.model.ExternalView) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) HashMap(java.util.HashMap) MasterSlaveSMD(org.apache.helix.model.MasterSlaveSMD) Test(org.testng.annotations.Test)

Example 97 with MockParticipantManager

use of org.apache.helix.integration.manager.MockParticipantManager 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 98 with MockParticipantManager

use of org.apache.helix.integration.manager.MockParticipantManager 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)

Example 99 with MockParticipantManager

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

the class TestAutoRebalance method beforeClass.

@Override
@BeforeClass
public void beforeClass() throws Exception {
    // Logger.getRootLogger().setLevel(Level.INFO);
    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);
    // setup storage cluster
    _setupTool.addCluster(CLUSTER_NAME, true);
    _setupTool.addResourceToCluster(CLUSTER_NAME, TEST_DB, _PARTITIONS, STATE_MODEL, RebalanceMode.FULL_AUTO + "");
    _setupTool.addResourceToCluster(CLUSTER_NAME, db2, _PARTITIONS, "OnlineOffline", RebalanceMode.FULL_AUTO + "");
    for (int i = 0; i < NODE_NR; i++) {
        String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
        _setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
    }
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, TEST_DB, _replica);
    for (int i = 0; i < 3; i++) {
        String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
        _setupTool.getClusterManagementTool().addInstanceTag(CLUSTER_NAME, storageNodeName, _tag);
    }
    _setupTool.rebalanceCluster(CLUSTER_NAME, db2, 1, "ucpx", _tag);
    // 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.verifyByZkCallback(new ExternalViewBalancedVerifier(_gZkClient, CLUSTER_NAME, TEST_DB));
    Assert.assertTrue(result);
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) ClusterSetup(org.apache.helix.tools.ClusterSetup) Date(java.util.Date) BeforeClass(org.testng.annotations.BeforeClass)

Example 100 with MockParticipantManager

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

the class TestAutoRebalancePartitionLimit method beforeClass.

@Override
@BeforeClass
public void beforeClass() throws Exception {
    // Logger.getRootLogger().setLevel(Level.INFO);
    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(ZK_ADDR);
    // setup storage cluster
    _setupTool.addCluster(CLUSTER_NAME, true);
    _setupTool.addResourceToCluster(CLUSTER_NAME, TEST_DB, 100, "OnlineOffline", RebalanceMode.FULL_AUTO + "", 0, 25);
    for (int i = 0; i < NODE_NR; i++) {
        String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
        _setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
    }
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, TEST_DB, 1);
    // start controller
    String controllerName = CONTROLLER_PREFIX + "_0";
    _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
    _controller.syncStart();
    // _startCMResultMap.get(controllerName)._manager;
    HelixManager manager = _controller;
    HelixDataAccessor accessor = manager.getHelixDataAccessor();
    // start dummy participants
    for (int i = 0; i < NODE_NR; i++) {
        String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
        _participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
        _participants[i].syncStart();
        Thread.sleep(2000);
        boolean result = ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_gZkClient, CLUSTER_NAME, TEST_DB));
        Assert.assertTrue(result);
        ExternalView ev = manager.getHelixDataAccessor().getProperty(accessor.keyBuilder().externalView(TEST_DB));
        System.out.println(ev.getPartitionSet().size());
        if (i < 3) {
            Assert.assertEquals(ev.getPartitionSet().size(), 25 * (i + 1));
        } else {
            Assert.assertEquals(ev.getPartitionSet().size(), 100);
        }
    }
    boolean result = ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_gZkClient, CLUSTER_NAME, TEST_DB));
    Assert.assertTrue(result);
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) ExternalView(org.apache.helix.model.ExternalView) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) HelixDataAccessor(org.apache.helix.HelixDataAccessor) HelixManager(org.apache.helix.HelixManager) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) ClusterSetup(org.apache.helix.tools.ClusterSetup) Date(java.util.Date) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)167 Test (org.testng.annotations.Test)113 Date (java.util.Date)101 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)101 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)43 ZNRecord (org.apache.helix.ZNRecord)40 IdealState (org.apache.helix.model.IdealState)35 BestPossAndExtViewZkVerifier (org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier)35 ClusterStateVerifier (org.apache.helix.tools.ClusterStateVerifier)34 HashMap (java.util.HashMap)33 HelixDataAccessor (org.apache.helix.HelixDataAccessor)30 ClusterSetup (org.apache.helix.tools.ClusterSetup)28 BeforeClass (org.testng.annotations.BeforeClass)27 ExternalView (org.apache.helix.model.ExternalView)24 BestPossibleExternalViewVerifier (org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier)20 HelixClusterVerifier (org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier)19 Map (java.util.Map)18 PropertyKey (org.apache.helix.PropertyKey)16 Builder (org.apache.helix.PropertyKey.Builder)15 ClusterDistributedController (org.apache.helix.integration.manager.ClusterDistributedController)15