Search in sources :

Example 11 with StateMachineEngine

use of org.apache.helix.participant.StateMachineEngine in project helix by apache.

the class TestZkHelixAdmin method initializeHelixManager.

private HelixManager initializeHelixManager(String clusterName, String instanceName, String zkAddress, String stateModelName) {
    HelixManager manager = HelixManagerFactory.getZKHelixManager(clusterName, instanceName, InstanceType.PARTICIPANT, zkAddress);
    MasterSlaveStateModelFactory stateModelFactory = new MasterSlaveStateModelFactory(instanceName);
    StateMachineEngine stateMach = manager.getStateMachineEngine();
    stateMach.registerStateModelFactory(stateModelName, stateModelFactory);
    return manager;
}
Also used : HelixManager(org.apache.helix.HelixManager) StateMachineEngine(org.apache.helix.participant.StateMachineEngine) MasterSlaveStateModelFactory(org.apache.helix.examples.MasterSlaveStateModelFactory)

Example 12 with StateMachineEngine

use of org.apache.helix.participant.StateMachineEngine in project helix by apache.

the class DummyProcessThread method run.

@Override
public void run() {
    try {
        DummyStateModelFactory stateModelFactory = new DummyStateModelFactory(0);
        StateMachineEngine stateMach = _manager.getStateMachineEngine();
        stateMach.registerStateModelFactory("MasterSlave", stateModelFactory);
        DummyLeaderStandbyStateModelFactory stateModelFactory1 = new DummyLeaderStandbyStateModelFactory(10);
        DummyOnlineOfflineStateModelFactory stateModelFactory2 = new DummyOnlineOfflineStateModelFactory(10);
        stateMach.registerStateModelFactory("LeaderStandby", stateModelFactory1);
        stateMach.registerStateModelFactory("OnlineOffline", stateModelFactory2);
        _manager.connect();
        Thread.currentThread().join();
    } catch (InterruptedException e) {
        String msg = "participant:" + _instanceName + ", " + Thread.currentThread().getName() + " interrupted";
        LOG.info(msg);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : StateMachineEngine(org.apache.helix.participant.StateMachineEngine) DummyOnlineOfflineStateModelFactory(org.apache.helix.mock.participant.DummyProcess.DummyOnlineOfflineStateModelFactory) DummyStateModelFactory(org.apache.helix.mock.participant.DummyProcess.DummyStateModelFactory) DummyLeaderStandbyStateModelFactory(org.apache.helix.mock.participant.DummyProcess.DummyLeaderStandbyStateModelFactory)

Example 13 with StateMachineEngine

use of org.apache.helix.participant.StateMachineEngine in project helix by apache.

the class TestRoutingTableProviderFromTargetEV method beforeClass.

@BeforeClass
public void beforeClass() throws Exception {
    String namespace = "/" + CLUSTER_NAME;
    _participants = new MockParticipantManager[NUM_NODES];
    if (_gZkClient.exists(namespace)) {
        _gZkClient.deleteRecursively(namespace);
    }
    _setupTool = new ClusterSetup(ZK_ADDR);
    _setupTool.addCluster(CLUSTER_NAME, true);
    _participants = new MockParticipantManager[NUM_NODES];
    for (int i = 0; i < NUM_NODES; i++) {
        String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
        _setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
    }
    _setupTool.addResourceToCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB, NUM_PARTITIONS, MASTER_SLAVE_STATE_MODEL, IdealState.RebalanceMode.FULL_AUTO.name());
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB, NUM_REPLICAS);
    for (int i = 0; i < NUM_NODES; i++) {
        String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
        _participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
        // add a delayed state model
        StateMachineEngine stateMachine = _participants[i].getStateMachineEngine();
        MockDelayMSStateModelFactory delayFactory = new MockDelayMSStateModelFactory().setDelay(-300000L);
        stateMachine.registerStateModelFactory(MASTER_SLAVE_STATE_MODEL, delayFactory);
        _participants[i].syncStart();
    }
    _manager = HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, "Admin", InstanceType.ADMINISTRATOR, ZK_ADDR);
    _manager.connect();
    String controllerName = CONTROLLER_PREFIX + "_0";
    _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
    _controller.syncStart();
    _configAccessor = new ConfigAccessor(_gZkClient);
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) StateMachineEngine(org.apache.helix.participant.StateMachineEngine) MockDelayMSStateModelFactory(org.apache.helix.mock.participant.MockDelayMSStateModelFactory) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) ConfigAccessor(org.apache.helix.ConfigAccessor) ClusterSetup(org.apache.helix.tools.ClusterSetup) BeforeClass(org.testng.annotations.BeforeClass)

Example 14 with StateMachineEngine

use of org.apache.helix.participant.StateMachineEngine in project helix by apache.

the class TestNonOfflineInitState method testNonOfflineInitState.

@Test
public void testNonOfflineInitState() throws Exception {
    System.out.println("START testNonOfflineInitState at " + new Date(System.currentTimeMillis()));
    String clusterName = getShortClassName();
    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
    1, "Bootstrap", // do rebalance
    true);
    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);
        // add a state model with non-OFFLINE initial state
        StateMachineEngine stateMach = participants[i].getStateMachineEngine();
        MockBootstrapModelFactory bootstrapFactory = new MockBootstrapModelFactory();
        stateMach.registerStateModelFactory("Bootstrap", bootstrapFactory);
        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 testNonOfflineInitState at " + new Date(System.currentTimeMillis()));
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) StateMachineEngine(org.apache.helix.participant.StateMachineEngine) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) MockBootstrapModelFactory(org.apache.helix.mock.participant.MockBootstrapModelFactory) BestPossAndExtViewZkVerifier(org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 15 with StateMachineEngine

use of org.apache.helix.participant.StateMachineEngine in project helix by apache.

the class MockParticipantManager method run.

@Override
public void run() {
    try {
        StateMachineEngine stateMach = getStateMachineEngine();
        stateMach.registerStateModelFactory(BuiltInStateModelDefinitions.MasterSlave.name(), _msModelFactory);
        stateMach.registerStateModelFactory(BuiltInStateModelDefinitions.LeaderStandby.name(), _lsModelFactory);
        stateMach.registerStateModelFactory(BuiltInStateModelDefinitions.OnlineOffline.name(), _ofModelFactory);
        MockSchemataModelFactory schemataFactory = new MockSchemataModelFactory();
        stateMach.registerStateModelFactory("STORAGE_DEFAULT_SM_SCHEMATA", schemataFactory);
        connect();
        _startCountDown.countDown();
        _stopCountDown.await();
    } catch (InterruptedException e) {
        String msg = "participant: " + getInstanceName() + ", " + Thread.currentThread().getName() + " is interrupted";
        LOG.info(msg);
    } catch (Exception e) {
        LOG.error("exception running participant-manager", e);
    } finally {
        _startCountDown.countDown();
        disconnect();
        _waitStopCompleteCountDown.countDown();
    }
}
Also used : StateMachineEngine(org.apache.helix.participant.StateMachineEngine) MockSchemataModelFactory(org.apache.helix.mock.participant.MockSchemataModelFactory)

Aggregations

StateMachineEngine (org.apache.helix.participant.StateMachineEngine)30 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)11 HashMap (java.util.HashMap)9 HelixManager (org.apache.helix.HelixManager)7 Task (org.apache.helix.task.Task)7 TaskCallbackContext (org.apache.helix.task.TaskCallbackContext)7 TaskFactory (org.apache.helix.task.TaskFactory)7 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)6 TaskStateModelFactory (org.apache.helix.task.TaskStateModelFactory)6 ClusterSetup (org.apache.helix.tools.ClusterSetup)4 BeforeClass (org.testng.annotations.BeforeClass)4 IOException (java.io.IOException)3 MockTask (org.apache.helix.integration.task.MockTask)3 TaskDriver (org.apache.helix.task.TaskDriver)3 Test (org.testng.annotations.Test)3 Date (java.util.Date)2 ParseException (org.apache.commons.cli.ParseException)2 ZNRecord (org.apache.helix.ZNRecord)2 MockDelayMSStateModelFactory (org.apache.helix.mock.participant.MockDelayMSStateModelFactory)2 MockTaskStateModelFactory (org.apache.helix.mock.statemodel.MockTaskStateModelFactory)2