Search in sources :

Example 21 with ClusterSetup

use of org.apache.helix.tools.ClusterSetup in project helix by apache.

the class TestHelper method dropCluster.

public static void dropCluster(String clusterName, ZkClient zkClient) throws Exception {
    if (!zkClient.exists("/" + clusterName)) {
        LOG.warn("Cluster does not exist:" + clusterName + ". Deleting it");
        zkClient.deleteRecursively("/" + clusterName);
    }
    ClusterSetup setupTool = new ClusterSetup(zkClient);
    setupTool.deleteCluster(clusterName);
}
Also used : ClusterSetup(org.apache.helix.tools.ClusterSetup)

Example 22 with ClusterSetup

use of org.apache.helix.tools.ClusterSetup in project helix by apache.

the class TestHelper method setupCluster.

public static void setupCluster(String clusterName, String ZkAddr, int startPort, String participantNamePrefix, String resourceNamePrefix, int resourceNb, int partitionNb, int nodesNb, int replica, String stateModelDef, RebalanceMode mode, boolean doRebalance) throws Exception {
    ZkClient zkClient = new ZkClient(ZkAddr);
    if (zkClient.exists("/" + clusterName)) {
        LOG.warn("Cluster already exists:" + clusterName + ". Deleting it");
        zkClient.deleteRecursively("/" + clusterName);
    }
    ClusterSetup setupTool = new ClusterSetup(ZkAddr);
    setupTool.addCluster(clusterName, true);
    for (int i = 0; i < nodesNb; i++) {
        int port = startPort + i;
        setupTool.addInstanceToCluster(clusterName, participantNamePrefix + "_" + port);
    }
    for (int i = 0; i < resourceNb; i++) {
        String resourceName = resourceNamePrefix + i;
        setupTool.addResourceToCluster(clusterName, resourceName, partitionNb, stateModelDef, mode.toString());
        if (doRebalance) {
            setupTool.rebalanceStorageCluster(clusterName, resourceName, replica);
        }
    }
    zkClient.close();
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) ClusterSetup(org.apache.helix.tools.ClusterSetup)

Example 23 with ClusterSetup

use of org.apache.helix.tools.ClusterSetup in project helix by apache.

the class TestDistributedCMMain method testDistributedCMMain.

@Test
public void testDistributedCMMain() throws Exception {
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    String clusterNamePrefix = className + "_" + methodName;
    final int n = 5;
    final int clusterNb = 10;
    System.out.println("START " + clusterNamePrefix + " at " + new Date(System.currentTimeMillis()));
    // setup 10 clusters
    for (int i = 0; i < clusterNb; i++) {
        String clusterName = clusterNamePrefix + "0_" + i;
        String participantName = "localhost" + i;
        String resourceName = "TestDB" + i;
        // participant port
        TestHelper.setupCluster(// participant port
        clusterName, // participant port
        ZK_ADDR, // participant port
        12918, // participant name prefix
        participantName, // resource name prefix
        resourceName, // resources
        1, // partitions per resource
        8, // number of nodes
        n, // replicas
        3, "MasterSlave", // do rebalance
        true);
    }
    // setup controller cluster
    final String controllerClusterName = "CONTROLLER_" + clusterNamePrefix;
    // controller
    TestHelper.setupCluster(// controller
    "CONTROLLER_" + clusterNamePrefix, // controller
    ZK_ADDR, // controller
    0, // participant name prefix
    "controller", // resource name prefix
    clusterNamePrefix, // resources
    1, // partitions per resource
    clusterNb, // number of nodes
    n, // replicas
    3, "LeaderStandby", // do rebalance
    true);
    // start distributed cluster controllers
    ClusterDistributedController[] controllers = new ClusterDistributedController[n + n];
    for (int i = 0; i < n; i++) {
        controllers[i] = new ClusterDistributedController(ZK_ADDR, controllerClusterName, "controller_" + i);
        controllers[i].syncStart();
    }
    boolean result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, controllerClusterName), 30000);
    Assert.assertTrue(result, "Controller cluster NOT in ideal state");
    // start first cluster
    MockParticipantManager[] participants = new MockParticipantManager[n];
    final String firstClusterName = clusterNamePrefix + "0_0";
    for (int i = 0; i < n; i++) {
        String instanceName = "localhost0_" + (12918 + i);
        participants[i] = new MockParticipantManager(ZK_ADDR, firstClusterName, instanceName);
        participants[i].syncStart();
    }
    result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, firstClusterName));
    Assert.assertTrue(result, "first cluster NOT in ideal state");
    // add more controllers to controller cluster
    ClusterSetup setupTool = new ClusterSetup(ZK_ADDR);
    for (int i = 0; i < n; i++) {
        String controller = "controller_" + (n + i);
        setupTool.addInstanceToCluster(controllerClusterName, controller);
    }
    setupTool.rebalanceStorageCluster(controllerClusterName, clusterNamePrefix + "0", 6);
    for (int i = n; i < 2 * n; i++) {
        controllers[i] = new ClusterDistributedController(ZK_ADDR, controllerClusterName, "controller_" + i);
        controllers[i].syncStart();
    }
    // verify controller cluster
    result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, controllerClusterName));
    Assert.assertTrue(result, "Controller cluster NOT in ideal state");
    // verify first cluster
    result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, firstClusterName));
    Assert.assertTrue(result, "first cluster NOT in ideal state");
    // stop controller_0-5
    ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(controllerClusterName, baseAccessor);
    Builder keyBuilder = accessor.keyBuilder();
    for (int i = 0; i < n; i++) {
        LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader());
        String leaderName = leader.getId();
        int j = Integer.parseInt(leaderName.substring(leaderName.lastIndexOf('_') + 1));
        controllers[j].syncStop();
        result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, controllerClusterName));
        Assert.assertTrue(result, "Controller cluster NOT in ideal state");
        result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, firstClusterName));
        Assert.assertTrue(result, "first cluster NOT in ideal state");
    }
    // clean up
    // wait for all zk callbacks done
    System.out.println("Cleaning up...");
    for (int i = 0; i < 5; i++) {
        result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, controllerClusterName));
        controllers[i].syncStop();
    }
    for (int i = 0; i < 5; i++) {
        participants[i].syncStop();
    }
    System.out.println("END " + clusterNamePrefix + " at " + new Date(System.currentTimeMillis()));
}
Also used : ZkBaseDataAccessor(org.apache.helix.manager.zk.ZkBaseDataAccessor) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) Builder(org.apache.helix.PropertyKey.Builder) ClusterStateVerifier(org.apache.helix.tools.ClusterStateVerifier) ClusterSetup(org.apache.helix.tools.ClusterSetup) BestPossAndExtViewZkVerifier(org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier) Date(java.util.Date) BestPossAndExtViewZkVerifier(org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier) ClusterDistributedController(org.apache.helix.integration.manager.ClusterDistributedController) LiveInstance(org.apache.helix.model.LiveInstance) ZNRecord(org.apache.helix.ZNRecord) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) Test(org.testng.annotations.Test)

Example 24 with ClusterSetup

use of org.apache.helix.tools.ClusterSetup in project helix by apache.

the class TestPreferenceListAsQueue method beforeMethod.

@BeforeMethod
public void beforeMethod() {
    _instanceList = Lists.newLinkedList();
    _clusterSetup = new ClusterSetup(ZK_ADDR);
    _admin = _clusterSetup.getClusterManagementTool();
    _prefListHistory = Lists.newLinkedList();
    // Create cluster
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    _clusterName = className + "_" + methodName;
    _clusterSetup.addCluster(_clusterName, true);
}
Also used : ClusterSetup(org.apache.helix.tools.ClusterSetup) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 25 with ClusterSetup

use of org.apache.helix.tools.ClusterSetup in project helix by apache.

the class TestRebalancerPersistAssignments 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);
    for (int i = 0; i < NODE_NR; i++) {
        String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
        _setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
    }
    // start controller
    String controllerName = CONTROLLER_PREFIX + "_0";
    _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
    _controller.syncStart();
    // start dummy participants
    for (int i = 0; i < NODE_NR; i++) {
        String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
        _instanceNames.add(instanceName);
        _participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
        _participants[i].syncStart();
    }
}
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)

Aggregations

ClusterSetup (org.apache.helix.tools.ClusterSetup)79 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)33 BeforeClass (org.testng.annotations.BeforeClass)33 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)28 ZkClient (org.apache.helix.manager.zk.ZkClient)26 Date (java.util.Date)23 IOException (java.io.IOException)14 HelixException (org.apache.helix.HelixException)14 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)11 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)11 Test (org.testng.annotations.Test)11 ConfigAccessor (org.apache.helix.ConfigAccessor)9 ZNRecord (org.apache.helix.ZNRecord)9 HelixDataAccessor (org.apache.helix.HelixDataAccessor)8 IdealState (org.apache.helix.model.IdealState)8 BestPossAndExtViewZkVerifier (org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier)7 HelixAdmin (org.apache.helix.HelixAdmin)6 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)6 StringRepresentation (org.restlet.representation.StringRepresentation)6 ClusterDistributedController (org.apache.helix.integration.manager.ClusterDistributedController)5