Search in sources :

Example 76 with ClusterSetup

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

the class StateModelsResource method getStateModelsRepresentation.

StringRepresentation getStateModelsRepresentation() throws JsonGenerationException, JsonMappingException, IOException {
    String clusterName = (String) getRequest().getAttributes().get("clusterName");
    ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
    ClusterSetup setupTool = new ClusterSetup(zkClient);
    List<String> models = setupTool.getClusterManagementTool().getStateModelDefs(clusterName);
    ZNRecord modelDefinitions = new ZNRecord("modelDefinitions");
    modelDefinitions.setListField("models", models);
    StringRepresentation representation = new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(modelDefinitions), MediaType.APPLICATION_JSON);
    return representation;
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) StringRepresentation(org.restlet.representation.StringRepresentation) ClusterSetup(org.apache.helix.tools.ClusterSetup) ZNRecord(org.apache.helix.ZNRecord)

Example 77 with ClusterSetup

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

the class TestClusterStatusMonitorLifecycle method testClusterStatusMonitorLifecycle.

@Test
public void testClusterStatusMonitorLifecycle() throws InstanceNotFoundException, MalformedObjectNameException, NullPointerException, IOException, InterruptedException {
    // Filter other unrelated clusters' metrics
    QueryExp exp = Query.match(Query.attr("SensorName"), Query.value("*" + _clusterNamePrefix + "*"));
    Set<ObjectInstance> mbeans = new HashSet<>(ManagementFactory.getPlatformMBeanServer().queryMBeans(new ObjectName("ClusterStatus:*"), exp));
    _participants[0].disconnect();
    // 1 participant goes away
    // No change in instance/resource mbean
    // Unregister 1 per-instance resource mbean and message queue mbean
    Thread.sleep(1000);
    int previousMBeanCount = mbeans.size();
    mbeans = new HashSet<>(ManagementFactory.getPlatformMBeanServer().queryMBeans(new ObjectName("ClusterStatus:*"), exp));
    Assert.assertEquals(mbeans.size(), previousMBeanCount - 2);
    HelixDataAccessor accessor = _participants[n - 1].getHelixDataAccessor();
    String firstControllerName = accessor.getProperty(accessor.keyBuilder().controllerLeader()).getId();
    ClusterDistributedController firstController = null;
    for (ClusterDistributedController controller : _controllers) {
        if (controller.getInstanceName().equals(firstControllerName)) {
            firstController = controller;
        }
    }
    firstController.disconnect();
    // 1 controller goes away
    // 1 message queue mbean, 1 PerInstanceResource mbean, and one message queue mbean
    Thread.sleep(2000);
    previousMBeanCount = mbeans.size();
    mbeans = new HashSet<>(ManagementFactory.getPlatformMBeanServer().queryMBeans(new ObjectName("ClusterStatus:*"), exp));
    Assert.assertEquals(mbeans.size(), previousMBeanCount - 3);
    String instanceName = "localhost0_" + (12918 + 0);
    _participants[0] = new MockParticipantManager(ZK_ADDR, _firstClusterName, instanceName);
    _participants[0].syncStart();
    // 1 participant comes back
    // No change in instance/resource mbean
    // Register 1 per-instance resource mbean and 1 message queue mbean
    Thread.sleep(2000);
    previousMBeanCount = mbeans.size();
    mbeans = new HashSet<>(ManagementFactory.getPlatformMBeanServer().queryMBeans(new ObjectName("ClusterStatus:*"), exp));
    Assert.assertEquals(mbeans.size(), previousMBeanCount + 2);
    // Add a resource
    // Register 1 resource mbean
    // Register 5 per-instance resource mbean
    ClusterSetup setupTool = new ClusterSetup(ZK_ADDR);
    IdealState idealState = accessor.getProperty(accessor.keyBuilder().idealStates("TestDB00"));
    setupTool.addResourceToCluster(_firstClusterName, "TestDB1", idealState.getNumPartitions(), "MasterSlave");
    setupTool.rebalanceResource(_firstClusterName, "TestDB1", Integer.parseInt(idealState.getReplicas()));
    Thread.sleep(2000);
    // Add one resource, PerInstanceResource mbeans and 1 resource monitor
    previousMBeanCount = mbeans.size();
    mbeans = new HashSet<>(ManagementFactory.getPlatformMBeanServer().queryMBeans(new ObjectName("ClusterStatus:*"), exp));
    Assert.assertEquals(mbeans.size(), previousMBeanCount + _participants.length + 1);
    // Remove a resource
    // No change in instance/resource mbean
    // Unregister 5 per-instance resource mbean
    setupTool.dropResourceFromCluster(_firstClusterName, "TestDB1");
    Thread.sleep(2000);
    previousMBeanCount = mbeans.size();
    mbeans = new HashSet<>(ManagementFactory.getPlatformMBeanServer().queryMBeans(new ObjectName("ClusterStatus:*"), exp));
    Assert.assertEquals(mbeans.size(), previousMBeanCount - (_participants.length + 1));
    // Cleanup controllers then MBeans should all be removed.
    cleanupControllers();
    Thread.sleep(2000);
    // Check if any MBeans leftover.
    // Note that MessageQueueStatus is not bound with controller only. So it will still exist.
    exp = Query.and(Query.not(Query.match(Query.attr("SensorName"), Query.value("MessageQueueStatus.*"))), exp);
    if (!ManagementFactory.getPlatformMBeanServer().queryMBeans(new ObjectName("ClusterStatus:*"), exp).isEmpty()) {
        System.out.println(ManagementFactory.getPlatformMBeanServer().queryMBeans(new ObjectName("ClusterStatus:*"), exp));
    }
    Assert.assertTrue(ManagementFactory.getPlatformMBeanServer().queryMBeans(new ObjectName("ClusterStatus:*"), exp).isEmpty());
}
Also used : MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) ClusterSetup(org.apache.helix.tools.ClusterSetup) IdealState(org.apache.helix.model.IdealState) HelixDataAccessor(org.apache.helix.HelixDataAccessor) ClusterDistributedController(org.apache.helix.integration.manager.ClusterDistributedController) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 78 with ClusterSetup

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

the class TestClusterStatusMonitorLifecycle method beforeClass.

@BeforeClass
public void beforeClass() throws Exception {
    String className = TestHelper.getTestClassName();
    _clusterNamePrefix = className;
    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
    _controllerClusterName = "CONTROLLER_" + _clusterNamePrefix;
    // controller
    TestHelper.setupCluster(// controller
    _controllerClusterName, // controller
    ZK_ADDR, // port
    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
    _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
    _participants = new MockParticipantManager[n];
    _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");
}
Also used : ClusterDistributedController(org.apache.helix.integration.manager.ClusterDistributedController) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) 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) BeforeClass(org.testng.annotations.BeforeClass)

Example 79 with ClusterSetup

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

the class TestSemiAutoStateTransition method beforeClass.

@BeforeClass
public void beforeClass() throws Exception {
    _participants = new MockParticipantManager[_numNodes];
    _numParitions = 1;
    String namespace = "/" + CLUSTER_NAME;
    if (_gZkClient.exists(namespace)) {
        _gZkClient.deleteRecursively(namespace);
    }
    _setupTool = new ClusterSetup(ZK_ADDR);
    _setupTool.addCluster(CLUSTER_NAME, true);
    _accessor = new ZKHelixDataAccessor(CLUSTER_NAME, _baseAccessor);
    _keyBuilder = _accessor.keyBuilder();
    setupParticipants();
    for (int i = 0; i < _numDbs; i++) {
        String db = WorkflowGenerator.DEFAULT_TGT_DB + i;
        _setupTool.addResourceToCluster(CLUSTER_NAME, db, _numParitions, MASTER_SLAVE_STATE_MODEL, IdealState.RebalanceMode.SEMI_AUTO.toString());
        _setupTool.rebalanceStorageCluster(CLUSTER_NAME, db, _numReplicas);
        _testDbs.add(db);
    }
    startParticipants();
    // start controller
    String controllerName = CONTROLLER_PREFIX + "_0";
    _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
    _controller.syncStart();
    Thread.sleep(2000L);
    createManagers();
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) ClusterSetup(org.apache.helix.tools.ClusterSetup) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) 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