Search in sources :

Example 41 with HelixManager

use of org.apache.helix.HelixManager in project helix by apache.

the class TestEntropyFreeNodeBounce method createParticipant.

private HelixManager createParticipant(String clusterName, String instanceName) {
    HelixManager participant = new ZKHelixManager(clusterName, instanceName, InstanceType.PARTICIPANT, ZK_ADDR);
    participant.getStateMachineEngine().registerStateModelFactory("OnlineOffline", new MockStateModelFactory());
    return participant;
}
Also used : ZKHelixManager(org.apache.helix.manager.zk.ZKHelixManager) HelixManager(org.apache.helix.HelixManager) ZKHelixManager(org.apache.helix.manager.zk.ZKHelixManager)

Example 42 with HelixManager

use of org.apache.helix.HelixManager in project helix by apache.

the class TestEntropyFreeNodeBounce method testBounceAll.

@Test
public void testBounceAll() throws Exception {
    // pick numbers that don't divide evenly
    final int NUM_PARTICIPANTS = 5;
    final int NUM_PARTITIONS = 123;
    final int NUM_REPLICAS = 1;
    final String RESOURCE_PREFIX = "TestDB";
    final String RESOURCE_NAME = RESOURCE_PREFIX + "0";
    // create a cluster name based on this test name
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    String clusterName = className + "_" + methodName;
    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
    // Set up cluster
    // 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
    NUM_PARTITIONS, // number of nodes
    NUM_PARTICIPANTS, // replicas
    NUM_REPLICAS, // use FULL_AUTO mode to test node tagging
    "OnlineOffline", // use FULL_AUTO mode to test node tagging
    RebalanceMode.FULL_AUTO, // do rebalance
    true);
    // Start the participants
    HelixManager[] participants = new HelixManager[NUM_PARTICIPANTS];
    for (int i = 0; i < NUM_PARTICIPANTS; i++) {
        final String instanceName = "localhost_" + (12918 + i);
        participants[i] = createParticipant(clusterName, instanceName);
        participants[i].connect();
    }
    // Start the controller
    ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller");
    controller.syncStart();
    // get an admin and accessor
    HelixAdmin helixAdmin = new ZKHelixAdmin(_gZkClient);
    BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
    HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseAccessor);
    PropertyKey.Builder keyBuilder = accessor.keyBuilder();
    // do the test
    try {
        Thread.sleep(1000);
        // ensure that the external view coalesces
        boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
        Assert.assertTrue(result);
        ExternalView stableExternalView = accessor.getProperty(keyBuilder.externalView(RESOURCE_NAME));
        for (HelixManager participant : participants) {
            // disable the controller, bounce the node, re-enable the controller, verify assignments
            // remained the same
            helixAdmin.enableCluster(clusterName, false);
            participant.disconnect();
            Thread.sleep(1000);
            participant = createParticipant(clusterName, participant.getInstanceName());
            participant.connect();
            Thread.sleep(1000);
            helixAdmin.enableCluster(clusterName, true);
            Thread.sleep(1000);
            result = ClusterStateVerifier.verifyByZkCallback(new MatchingExternalViewVerifier(stableExternalView, clusterName));
            Assert.assertTrue(result);
        }
    } finally {
        // clean up
        controller.syncStop();
        for (HelixManager participant : participants) {
            participant.disconnect();
        }
        System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
    }
}
Also used : ExternalView(org.apache.helix.model.ExternalView) ZkBaseDataAccessor(org.apache.helix.manager.zk.ZkBaseDataAccessor) ZKHelixManager(org.apache.helix.manager.zk.ZKHelixManager) HelixManager(org.apache.helix.HelixManager) 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) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) HelixDataAccessor(org.apache.helix.HelixDataAccessor) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) ZNRecord(org.apache.helix.ZNRecord) PropertyKey(org.apache.helix.PropertyKey) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) Test(org.testng.annotations.Test)

Example 43 with HelixManager

use of org.apache.helix.HelixManager in project helix by apache.

the class TestExternalViewStage method testCachedExternalViews.

@Test
public void testCachedExternalViews() throws Exception {
    String clusterName = "CLUSTER_" + TestHelper.getTestMethodName();
    HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
    HelixManager manager = new DummyClusterManager(clusterName, accessor);
    // ideal state: node0 is MASTER, node1 is SLAVE
    // replica=2 means 1 master and 1 slave
    setupIdealState(clusterName, new int[] { 0, 1 }, new String[] { "TestDB" }, 1, 2);
    setupLiveInstances(clusterName, new int[] { 0, 1 });
    setupStateModel(clusterName);
    ClusterEvent event = new ClusterEvent(ClusterEventType.Unknown);
    ClusterDataCache cache = new ClusterDataCache(clusterName);
    event.addAttribute(AttributeName.helixmanager.name(), manager);
    event.addAttribute(AttributeName.ClusterDataCache.name(), cache);
    ExternalViewComputeStage externalViewComputeStage = new ExternalViewComputeStage();
    Pipeline dataRefresh = new Pipeline();
    dataRefresh.addStage(new ReadClusterDataStage());
    runPipeline(event, dataRefresh);
    runStage(event, new ResourceComputationStage());
    runStage(event, new CurrentStateComputationStage());
    runStage(event, externalViewComputeStage);
    Assert.assertEquals(cache.getExternalViews().values(), accessor.getChildValues(accessor.keyBuilder().externalViews()));
    // Assure there is no external got updated
    List<ExternalView> oldExternalViews = accessor.getChildValues(accessor.keyBuilder().externalViews());
    runStage(event, externalViewComputeStage);
    List<ExternalView> newExternalViews = accessor.getChildValues(accessor.keyBuilder().externalViews());
    Assert.assertEquals(oldExternalViews, newExternalViews);
    for (int i = 0; i < oldExternalViews.size(); i++) {
        Assert.assertEquals(oldExternalViews.get(i).getStat().getVersion(), newExternalViews.get(i).getStat().getVersion());
    }
}
Also used : ExternalView(org.apache.helix.model.ExternalView) HelixManager(org.apache.helix.HelixManager) Pipeline(org.apache.helix.controller.pipeline.Pipeline) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) HelixDataAccessor(org.apache.helix.HelixDataAccessor) ZNRecord(org.apache.helix.ZNRecord) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) Test(org.testng.annotations.Test)

Example 44 with HelixManager

use of org.apache.helix.HelixManager in project helix by apache.

the class TestMessageThrottle2 method startController.

void startController() throws Exception {
    // start helixController
    System.out.println(String.format("Starting Controller{Cluster:%s, Port:%s, Zookeeper:%s}", clusterName, 12000, ZK_ADDR));
    HelixManager helixController = HelixControllerMain.startHelixController(ZK_ADDR, clusterName, "localhost_" + 12000, HelixControllerMain.STANDALONE);
    StatusPrinter statusPrinter = new StatusPrinter();
    statusPrinter.registerWith(helixController);
}
Also used : ZKHelixManager(org.apache.helix.manager.zk.ZKHelixManager) HelixManager(org.apache.helix.HelixManager)

Example 45 with HelixManager

use of org.apache.helix.HelixManager in project helix by apache.

the class TestZeroReplicaAvoidance method test.

@Test
public void test() throws Exception {
    HelixManager manager = HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, null, InstanceType.SPECTATOR, ZK_ADDR);
    manager.connect();
    manager.addExternalViewChangeListener(this);
    manager.addIdealStateChangeListener(this);
    enablePersistBestPossibleAssignment(_gZkClient, CLUSTER_NAME, true);
    // Start half number of nodes.
    int i = 0;
    for (; i < NUM_NODE / 2; i++) {
        _participants.get(i).syncStart();
    }
    int replica = 3;
    int partition = 30;
    for (String stateModel : TestStateModels) {
        String db = "Test-DB-" + stateModel;
        createResourceWithDelayedRebalance(CLUSTER_NAME, db, stateModel, partition, replica, replica, 0);
    }
    Assert.assertTrue(_clusterVerifier.verify(50000));
    _startListen = true;
    DelayedTransition.setDelay(50);
    // add the other half of nodes.
    for (; i < NUM_NODE; i++) {
        _participants.get(i).syncStart();
    }
    Assert.assertTrue(_clusterVerifier.verify(50000));
    Assert.assertTrue(_testSuccess);
}
Also used : HelixManager(org.apache.helix.HelixManager) Test(org.testng.annotations.Test)

Aggregations

HelixManager (org.apache.helix.HelixManager)115 Test (org.testng.annotations.Test)49 HelixDataAccessor (org.apache.helix.HelixDataAccessor)35 ZNRecord (org.apache.helix.ZNRecord)28 Message (org.apache.helix.model.Message)23 PropertyKey (org.apache.helix.PropertyKey)20 Date (java.util.Date)18 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)17 Builder (org.apache.helix.PropertyKey.Builder)16 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)12 HelixException (org.apache.helix.HelixException)11 ExternalView (org.apache.helix.model.ExternalView)11 NotificationContext (org.apache.helix.NotificationContext)10 LiveInstance (org.apache.helix.model.LiveInstance)10 IdealState (org.apache.helix.model.IdealState)9 Criteria (org.apache.helix.Criteria)8 HelixAdmin (org.apache.helix.HelixAdmin)8 ZKHelixManager (org.apache.helix.manager.zk.ZKHelixManager)8 StringWriter (java.io.StringWriter)7