Search in sources :

Example 6 with MasterNbInExtViewVerifier

use of org.apache.helix.tools.ClusterStateVerifier.MasterNbInExtViewVerifier in project helix by apache.

the class TestMessageThrottle method testMessageThrottle.

@Test()
public void testMessageThrottle() throws Exception {
    // Logger.getRootLogger().setLevel(Level.INFO);
    String clusterName = getShortClassName();
    MockParticipantManager[] participants = new MockParticipantManager[5];
    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
    // participant start
    TestHelper.setupCluster(// participant start
    clusterName, // participant start
    ZK_ADDR, // participant start
    12918, // participant name prefix
    "localhost", // resource name prefix
    "TestDB", // resources
    1, // partitions per resource
    10, // number of nodes
    5, // replicas
    3, "MasterSlave", // do rebalance
    true);
    // setup message constraint
    // "MESSAGE_TYPE=STATE_TRANSITION,TRANSITION=OFFLINE-SLAVE,INSTANCE=.*,CONSTRAINT_VALUE=1";
    HelixAdmin admin = new ZKHelixAdmin(_gZkClient);
    ConstraintItemBuilder builder = new ConstraintItemBuilder();
    builder.addConstraintAttribute("MESSAGE_TYPE", "STATE_TRANSITION").addConstraintAttribute("INSTANCE", ".*").addConstraintAttribute("CONSTRAINT_VALUE", "1");
    // Map<String, String> constraints = new TreeMap<String, String>();
    // constraints.put("MESSAGE_TYPE", "STATE_TRANSITION");
    // // constraints.put("TRANSITION", "OFFLINE-SLAVE");
    // constraints.put("CONSTRAINT_VALUE", "1");
    // constraints.put("INSTANCE", ".*");
    admin.setConstraint(clusterName, ConstraintType.MESSAGE_CONSTRAINT, "constraint1", builder.build());
    final ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
    // make sure we never see more than 1 state transition message for each participant
    final AtomicBoolean success = new AtomicBoolean(true);
    for (int i = 0; i < 5; i++) {
        String instanceName = "localhost_" + (12918 + i);
        String msgPath = PropertyPathBuilder.instanceMessage(clusterName, instanceName);
        _gZkClient.subscribeChildChanges(msgPath, new IZkChildListener() {

            @Override
            public void handleChildChange(String parentPath, List<String> currentChilds) throws Exception {
                if (currentChilds != null && currentChilds.size() > 1) {
                    List<ZNRecord> records = accessor.getBaseDataAccessor().getChildren(parentPath, null, 0);
                    int transitionMsgCount = 0;
                    for (ZNRecord record : records) {
                        Message msg = new Message(record);
                        if (msg.getMsgType().equals(Message.MessageType.STATE_TRANSITION.name())) {
                            transitionMsgCount++;
                        }
                    }
                    if (transitionMsgCount > 1) {
                        success.set(false);
                        Assert.fail("Should not see more than 1 message");
                    }
                }
            }
        });
    }
    ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
    controller.syncStart();
    // start participants
    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 MasterNbInExtViewVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    Assert.assertTrue(success.get());
    // 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 : MasterNbInExtViewVerifier(org.apache.helix.tools.ClusterStateVerifier.MasterNbInExtViewVerifier) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) Message(org.apache.helix.model.Message) ConstraintItemBuilder(org.apache.helix.model.builder.ConstraintItemBuilder) HelixAdmin(org.apache.helix.HelixAdmin) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) BestPossAndExtViewZkVerifier(org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier) Date(java.util.Date) ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) IZkChildListener(org.I0Itec.zkclient.IZkChildListener) List(java.util.List) ZNRecord(org.apache.helix.ZNRecord) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) Test(org.testng.annotations.Test)

Example 7 with MasterNbInExtViewVerifier

use of org.apache.helix.tools.ClusterStateVerifier.MasterNbInExtViewVerifier in project helix by apache.

the class TestStateTransitionTimeoutWithResource method testStateTransitionTimeoutByClusterLevel.

@Test
public void testStateTransitionTimeoutByClusterLevel() throws InterruptedException {
    _setupTool.addResourceToCluster(CLUSTER_NAME, TEST_DB + 1, _PARTITIONS, STATE_MODEL);
    _setupTool.getClusterManagementTool().enableResource(CLUSTER_NAME, TEST_DB + 1, false);
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, TEST_DB + 1, 3);
    StateTransitionTimeoutConfig stateTransitionTimeoutConfig = new StateTransitionTimeoutConfig(new ZNRecord(TEST_DB + 1));
    stateTransitionTimeoutConfig.setStateTransitionTimeout("SLAVE", "MASTER", 300);
    ClusterConfig clusterConfig = _configAccessor.getClusterConfig(CLUSTER_NAME);
    clusterConfig.setStateTransitionTimeoutConfig(stateTransitionTimeoutConfig);
    _configAccessor.setClusterConfig(CLUSTER_NAME, clusterConfig);
    setParticipants(TEST_DB + 1);
    _setupTool.getClusterManagementTool().enableResource(CLUSTER_NAME, TEST_DB + 1, true);
    boolean result = ClusterStateVerifier.verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR, CLUSTER_NAME));
    Assert.assertTrue(result);
    verify(TEST_DB + 1);
}
Also used : MasterNbInExtViewVerifier(org.apache.helix.tools.ClusterStateVerifier.MasterNbInExtViewVerifier) StateTransitionTimeoutConfig(org.apache.helix.api.config.StateTransitionTimeoutConfig) ZNRecord(org.apache.helix.ZNRecord) ClusterConfig(org.apache.helix.model.ClusterConfig) Test(org.testng.annotations.Test)

Example 8 with MasterNbInExtViewVerifier

use of org.apache.helix.tools.ClusterStateVerifier.MasterNbInExtViewVerifier in project helix by apache.

the class TestStateTransitionTimeout method testStateTransitionTimeOut.

@Test
public void testStateTransitionTimeOut() throws Exception {
    Map<String, SleepStateModelFactory> factories = new HashMap<String, SleepStateModelFactory>();
    IdealState idealState = _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, TEST_DB);
    for (int i = 0; i < NODE_NR; i++) {
        String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
        SleepStateModelFactory factory = new SleepStateModelFactory(1000);
        factories.put(instanceName, factory);
        for (String p : idealState.getPartitionSet()) {
            if (idealState.getPreferenceList(p).get(0).equals(instanceName)) {
                factory.addPartition(p);
            }
        }
        _participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
        _participants[i].getStateMachineEngine().registerStateModelFactory("MasterSlave", factory);
        _participants[i].syncStart();
    }
    String controllerName = CONTROLLER_PREFIX + "_0";
    _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
    _controller.syncStart();
    boolean result = ClusterStateVerifier.verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR, CLUSTER_NAME));
    Assert.assertTrue(result);
    HelixDataAccessor accessor = _participants[0].getHelixDataAccessor();
    Builder kb = accessor.keyBuilder();
    ExternalView ev = accessor.getProperty(kb.externalView(TEST_DB));
    for (String p : idealState.getPartitionSet()) {
        String idealMaster = idealState.getPreferenceList(p).get(0);
        Assert.assertTrue(ev.getStateMap(p).get(idealMaster).equals("ERROR"));
        TimeOutStateModel model = factories.get(idealMaster).getStateModel(TEST_DB, p);
        Assert.assertEquals(model._errorCallcount, 1);
        Assert.assertEquals(model._error.getCode(), ErrorCode.TIMEOUT);
    }
}
Also used : ExternalView(org.apache.helix.model.ExternalView) MasterNbInExtViewVerifier(org.apache.helix.tools.ClusterStateVerifier.MasterNbInExtViewVerifier) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) HashMap(java.util.HashMap) Builder(org.apache.helix.PropertyKey.Builder) IdealState(org.apache.helix.model.IdealState) ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) HelixDataAccessor(org.apache.helix.HelixDataAccessor) Test(org.testng.annotations.Test)

Example 9 with MasterNbInExtViewVerifier

use of org.apache.helix.tools.ClusterStateVerifier.MasterNbInExtViewVerifier in project helix by apache.

the class TestStateTransitionTimeoutWithResource method testStateTransitionTimeOut.

@Test
public void testStateTransitionTimeOut() throws Exception {
    _setupTool.addResourceToCluster(CLUSTER_NAME, TEST_DB, _PARTITIONS, STATE_MODEL);
    _setupTool.getClusterManagementTool().enableResource(CLUSTER_NAME, TEST_DB, false);
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, TEST_DB, 3);
    // Set the timeout values
    StateTransitionTimeoutConfig stateTransitionTimeoutConfig = new StateTransitionTimeoutConfig(new ZNRecord(TEST_DB));
    stateTransitionTimeoutConfig.setStateTransitionTimeout("SLAVE", "MASTER", 300);
    ResourceConfig resourceConfig = new ResourceConfig.Builder(TEST_DB).setStateTransitionTimeoutConfig(stateTransitionTimeoutConfig).setRebalanceConfig(new RebalanceConfig(new ZNRecord(TEST_DB))).setNumPartitions(_PARTITIONS).setHelixEnabled(false).build();
    _configAccessor.setResourceConfig(CLUSTER_NAME, TEST_DB, resourceConfig);
    setParticipants(TEST_DB);
    _setupTool.getClusterManagementTool().enableResource(CLUSTER_NAME, TEST_DB, true);
    boolean result = ClusterStateVerifier.verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR, CLUSTER_NAME));
    Assert.assertTrue(result);
    verify(TEST_DB);
}
Also used : MasterNbInExtViewVerifier(org.apache.helix.tools.ClusterStateVerifier.MasterNbInExtViewVerifier) StateTransitionTimeoutConfig(org.apache.helix.api.config.StateTransitionTimeoutConfig) ResourceConfig(org.apache.helix.model.ResourceConfig) ZNRecord(org.apache.helix.ZNRecord) RebalanceConfig(org.apache.helix.api.config.RebalanceConfig) Test(org.testng.annotations.Test)

Example 10 with MasterNbInExtViewVerifier

use of org.apache.helix.tools.ClusterStateVerifier.MasterNbInExtViewVerifier in project helix by apache.

the class TestStateTransitionTimeoutWithResource method beforeClass.

@Override
@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(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);
    }
    _manager = HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, "Admin", InstanceType.ADMINISTRATOR, ZK_ADDR);
    _manager.connect();
    _configAccessor = new ConfigAccessor(_gZkClient);
    String controllerName = CONTROLLER_PREFIX + "_0";
    _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
    _controller.syncStart();
    boolean result = ClusterStateVerifier.verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR, CLUSTER_NAME));
    Assert.assertTrue(result);
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) MasterNbInExtViewVerifier(org.apache.helix.tools.ClusterStateVerifier.MasterNbInExtViewVerifier) ConfigAccessor(org.apache.helix.ConfigAccessor) ClusterSetup(org.apache.helix.tools.ClusterSetup) Date(java.util.Date) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

MasterNbInExtViewVerifier (org.apache.helix.tools.ClusterStateVerifier.MasterNbInExtViewVerifier)14 Test (org.testng.annotations.Test)12 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)11 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)9 Date (java.util.Date)8 BestPossAndExtViewZkVerifier (org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier)8 ZNRecord (org.apache.helix.ZNRecord)6 HashMap (java.util.HashMap)4 HelixDataAccessor (org.apache.helix.HelixDataAccessor)4 ClusterDistributedController (org.apache.helix.integration.manager.ClusterDistributedController)3 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)3 Builder (org.apache.helix.PropertyKey.Builder)2 StateTransitionTimeoutConfig (org.apache.helix.api.config.StateTransitionTimeoutConfig)2 ZkBaseDataAccessor (org.apache.helix.manager.zk.ZkBaseDataAccessor)2 ExternalView (org.apache.helix.model.ExternalView)2 LiveInstance (org.apache.helix.model.LiveInstance)2 ClusterSetup (org.apache.helix.tools.ClusterSetup)2 BeforeClass (org.testng.annotations.BeforeClass)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1