Search in sources :

Example 21 with StateMachineEngine

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

the class TestJobFailureTaskNotStarted method startParticipantsWithStuckTaskStateModelFactory.

protected void startParticipantsWithStuckTaskStateModelFactory() {
    Map<String, TaskFactory> taskFactoryReg = new HashMap<String, TaskFactory>();
    taskFactoryReg.put(MockTask.TASK_COMMAND, new TaskFactory() {

        @Override
        public Task createNewTask(TaskCallbackContext context) {
            return new MockTask(context);
        }
    });
    List<String> instances = _setupTool.getClusterManagementTool().getInstancesInCluster(CLUSTER_NAME);
    _participants[0] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instances.get(0));
    StateMachineEngine stateMachine = _participants[0].getStateMachineEngine();
    stateMachine.registerStateModelFactory("Task", new MockTaskStateModelFactory(_participants[0], taskFactoryReg));
    _participants[0].syncStart();
    _blockedParticipant = _participants[0];
    _participants[1] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instances.get(1));
    stateMachine = _participants[1].getStateMachineEngine();
    stateMachine.registerStateModelFactory("Task", new TaskStateModelFactory(_participants[1], taskFactoryReg));
    _participants[1].syncStart();
    _normalParticipant = _participants[1];
}
Also used : Task(org.apache.helix.task.Task) StateMachineEngine(org.apache.helix.participant.StateMachineEngine) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) HashMap(java.util.HashMap) TaskCallbackContext(org.apache.helix.task.TaskCallbackContext) TaskFactory(org.apache.helix.task.TaskFactory) MockTaskStateModelFactory(org.apache.helix.mock.statemodel.MockTaskStateModelFactory) MockTaskStateModelFactory(org.apache.helix.mock.statemodel.MockTaskStateModelFactory) TaskStateModelFactory(org.apache.helix.task.TaskStateModelFactory)

Example 22 with StateMachineEngine

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

the class TestJobTimeoutTaskNotStarted method startParticipantsWithStuckTaskStateModelFactory.

protected void startParticipantsWithStuckTaskStateModelFactory() {
    Map<String, TaskFactory> taskFactoryReg = new HashMap<String, TaskFactory>();
    taskFactoryReg.put(MockTask.TASK_COMMAND, new TaskFactory() {

        @Override
        public Task createNewTask(TaskCallbackContext context) {
            return new MockTask(context);
        }
    });
    // start dummy participants
    for (int i = 0; i < _numNodes; i++) {
        String instanceName = PARTICIPANT_PREFIX + "_" + (_startPort + i);
        _participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
        // Register a Task state model factory.
        StateMachineEngine stateMachine = _participants[i].getStateMachineEngine();
        stateMachine.registerStateModelFactory("Task", new MockTaskStateModelFactory(_participants[i], taskFactoryReg));
        _participants[i].syncStart();
    }
}
Also used : Task(org.apache.helix.task.Task) StateMachineEngine(org.apache.helix.participant.StateMachineEngine) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) HashMap(java.util.HashMap) TaskFactory(org.apache.helix.task.TaskFactory) MockTaskStateModelFactory(org.apache.helix.mock.statemodel.MockTaskStateModelFactory) TaskCallbackContext(org.apache.helix.task.TaskCallbackContext)

Example 23 with StateMachineEngine

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

the class TestUserContentStore method beforeClass.

@BeforeClass
public void beforeClass() throws Exception {
    _participants = new MockParticipantManager[_numNodes];
    String namespace = "/" + CLUSTER_NAME;
    if (_gZkClient.exists(namespace)) {
        _gZkClient.deleteRecursively(namespace);
    }
    // Setup cluster and instances
    ClusterSetup setupTool = new ClusterSetup(ZK_ADDR);
    setupTool.addCluster(CLUSTER_NAME, true);
    for (int i = 0; i < _numNodes; i++) {
        String storageNodeName = PARTICIPANT_PREFIX + "_" + (_startPort + i);
        setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
    }
    // start dummy participants
    for (int i = 0; i < _numNodes; i++) {
        final String instanceName = PARTICIPANT_PREFIX + "_" + (_startPort + i);
        // Set task callbacks
        Map<String, TaskFactory> taskFactoryReg = new HashMap<String, TaskFactory>();
        taskFactoryReg.put("ContentStoreTask", new TaskFactory() {

            @Override
            public Task createNewTask(TaskCallbackContext context) {
                return new ContentStoreTask();
            }
        });
        taskFactoryReg.put("TaskOne", new TaskFactory() {

            @Override
            public Task createNewTask(TaskCallbackContext context) {
                return new TaskOne();
            }
        });
        taskFactoryReg.put("TaskTwo", new TaskFactory() {

            @Override
            public Task createNewTask(TaskCallbackContext context) {
                return new TaskTwo();
            }
        });
        _participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
        // Register a Task state model factory.
        StateMachineEngine stateMachine = _participants[i].getStateMachineEngine();
        stateMachine.registerStateModelFactory("Task", new TaskStateModelFactory(_participants[i], taskFactoryReg));
        _participants[i].syncStart();
    }
    // Start controller
    String controllerName = CONTROLLER_PREFIX + "_0";
    _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
    _controller.syncStart();
    // Start an admin connection
    _manager = HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, "Admin", InstanceType.ADMINISTRATOR, ZK_ADDR);
    _manager.connect();
    _driver = new TaskDriver(_manager);
}
Also used : Task(org.apache.helix.task.Task) StateMachineEngine(org.apache.helix.participant.StateMachineEngine) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) HashMap(java.util.HashMap) TaskDriver(org.apache.helix.task.TaskDriver) ClusterSetup(org.apache.helix.tools.ClusterSetup) TaskCallbackContext(org.apache.helix.task.TaskCallbackContext) ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) TaskFactory(org.apache.helix.task.TaskFactory) TaskStateModelFactory(org.apache.helix.task.TaskStateModelFactory) BeforeClass(org.testng.annotations.BeforeClass)

Example 24 with StateMachineEngine

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

the class TestStateTransitionCancellation method registerParticipants.

private void registerParticipants(MockParticipantManager[] participants, int numNodes, int startPort, long sleepTime, long delay) throws InterruptedException {
    Map<String, TaskFactory> taskFactoryReg = new HashMap<String, TaskFactory>();
    taskFactoryReg.put(MockTask.TASK_COMMAND, new TaskFactory() {

        @Override
        public Task createNewTask(TaskCallbackContext context) {
            return new MockTask(context);
        }
    });
    for (int i = 0; i < numNodes; i++) {
        String instanceName = PARTICIPANT_PREFIX + "_" + (startPort + i);
        participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
        // add a state model with non-OFFLINE initial state
        StateMachineEngine stateMach = participants[i].getStateMachineEngine();
        stateMach.registerStateModelFactory("Task", new TaskStateModelFactory(participants[i], taskFactoryReg));
        InMockDelayMSStateModelFactory delayFactory = new InMockDelayMSStateModelFactory().setDelay(delay);
        stateMach.registerStateModelFactory(MASTER_SLAVE_STATE_MODEL, delayFactory);
        participants[i].syncStart();
        if (sleepTime > 0) {
            Thread.sleep(sleepTime);
        }
    }
}
Also used : Task(org.apache.helix.task.Task) MockTask(org.apache.helix.integration.task.MockTask) StateMachineEngine(org.apache.helix.participant.StateMachineEngine) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) HashMap(java.util.HashMap) MockTask(org.apache.helix.integration.task.MockTask) TaskCallbackContext(org.apache.helix.task.TaskCallbackContext) TaskFactory(org.apache.helix.task.TaskFactory) TaskStateModelFactory(org.apache.helix.task.TaskStateModelFactory)

Example 25 with StateMachineEngine

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

the class ClusterDistributedController method run.

@Override
public void run() {
    try {
        StateMachineEngine stateMach = getStateMachineEngine();
        DistClusterControllerStateModelFactory lsModelFactory = new DistClusterControllerStateModelFactory(_zkAddress);
        stateMach.registerStateModelFactory("LeaderStandby", lsModelFactory);
        connect();
        _startCountDown.countDown();
        _stopCountDown.await();
    } catch (Exception e) {
        LOG.error("exception running controller-manager", e);
    } finally {
        _startCountDown.countDown();
        disconnect();
        _waitStopFinishCountDown.countDown();
    }
}
Also used : StateMachineEngine(org.apache.helix.participant.StateMachineEngine) DistClusterControllerStateModelFactory(org.apache.helix.participant.DistClusterControllerStateModelFactory)

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