Search in sources :

Example 16 with StateMachineEngine

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

the class HelixParticipant method participate.

/**
 * Initiate the participation by registering via the {@link HelixManager} as a participant to the associated
 * Helix cluster.
 * @param ambryStatsReports {@link List} of {@link AmbryStatsReport} to be registered to the participant.
 * @param accountStatsStore the {@link AccountStatsStore} to retrieve and store container stats.
 * @param callback a callback which will be invoked when the aggregation report has been generated successfully.
 * @throws IOException if there is an error connecting to the Helix cluster.
 */
@Override
public void participate(List<AmbryStatsReport> ambryStatsReports, AccountStatsStore accountStatsStore, Callback<StatsSnapshot> callback) throws IOException {
    logger.info("Initiating the participation. The specified state model is {}", clusterMapConfig.clustermapStateModelDefinition);
    StateMachineEngine stateMachineEngine = manager.getStateMachineEngine();
    stateMachineEngine.registerStateModelFactory(clusterMapConfig.clustermapStateModelDefinition, new AmbryStateModelFactory(clusterMapConfig, this));
    registerStatsReportAggregationTasks(stateMachineEngine, ambryStatsReports, accountStatsStore, callback);
    try {
        // register server as a participant
        manager.connect();
    } catch (Exception e) {
        throw new IOException("Exception while connecting to the Helix manager", e);
    }
    logger.info("Completed participation in cluster {} at {}", clusterName, zkConnectStr);
}
Also used : StateMachineEngine(org.apache.helix.participant.StateMachineEngine) IOException(java.io.IOException) IOException(java.io.IOException)

Example 17 with StateMachineEngine

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

the class ControllerRequestBuilderUtil method addFakeBrokerInstancesToAutoJoinHelixCluster.

public static void addFakeBrokerInstancesToAutoJoinHelixCluster(String helixClusterName, String zkServer, int numInstances, boolean isSingleTenant) throws Exception {
    for (int i = 0; i < numInstances; ++i) {
        final String brokerId = "Broker_localhost_" + i;
        final HelixManager helixZkManager = HelixManagerFactory.getZKHelixManager(helixClusterName, brokerId, InstanceType.PARTICIPANT, zkServer);
        final StateMachineEngine stateMachineEngine = helixZkManager.getStateMachineEngine();
        final StateModelFactory<?> stateModelFactory = new EmptyBrokerOnlineOfflineStateModelFactory();
        stateMachineEngine.registerStateModelFactory(EmptyBrokerOnlineOfflineStateModelFactory.getStateModelDef(), stateModelFactory);
        helixZkManager.connect();
        if (isSingleTenant) {
            helixZkManager.getClusterManagmentTool().addInstanceTag(helixClusterName, brokerId, ControllerTenantNameBuilder.getBrokerTenantNameForTenant(ControllerTenantNameBuilder.DEFAULT_TENANT_NAME));
        } else {
            helixZkManager.getClusterManagmentTool().addInstanceTag(helixClusterName, brokerId, UNTAGGED_BROKER_INSTANCE);
        }
        Thread.sleep(1000);
    }
}
Also used : HelixManager(org.apache.helix.HelixManager) StateMachineEngine(org.apache.helix.participant.StateMachineEngine)

Example 18 with StateMachineEngine

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

the class ControllerRequestBuilderUtil method addFakeDataInstancesToAutoJoinHelixCluster.

public static void addFakeDataInstancesToAutoJoinHelixCluster(String helixClusterName, String zkServer, int numInstances, boolean isSingleTenant, int adminPort) throws Exception {
    for (int i = 0; i < numInstances; ++i) {
        final String instanceId = "Server_localhost_" + i;
        final HelixManager helixZkManager = HelixManagerFactory.getZKHelixManager(helixClusterName, instanceId, InstanceType.PARTICIPANT, zkServer);
        final StateMachineEngine stateMachineEngine = helixZkManager.getStateMachineEngine();
        final StateModelFactory<?> stateModelFactory = new EmptySegmentOnlineOfflineStateModelFactory();
        stateMachineEngine.registerStateModelFactory(EmptySegmentOnlineOfflineStateModelFactory.getStateModelDef(), stateModelFactory);
        helixZkManager.connect();
        if (isSingleTenant) {
            helixZkManager.getClusterManagmentTool().addInstanceTag(helixClusterName, instanceId, TableNameBuilder.OFFLINE_TABLE_NAME_BUILDER.forTable(ControllerTenantNameBuilder.DEFAULT_TENANT_NAME));
            helixZkManager.getClusterManagmentTool().addInstanceTag(helixClusterName, instanceId, TableNameBuilder.REALTIME_TABLE_NAME_BUILDER.forTable(ControllerTenantNameBuilder.DEFAULT_TENANT_NAME));
        } else {
            helixZkManager.getClusterManagmentTool().addInstanceTag(helixClusterName, instanceId, UNTAGGED_SERVER_INSTANCE);
        }
        HelixConfigScope scope = new HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.PARTICIPANT, helixClusterName).forParticipant(instanceId).build();
        Map<String, String> props = new HashMap<>();
        props.put(CommonConstants.Helix.Instance.ADMIN_PORT_KEY, String.valueOf(adminPort + i));
        helixZkManager.getClusterManagmentTool().setConfig(scope, props);
    }
}
Also used : HelixManager(org.apache.helix.HelixManager) StateMachineEngine(org.apache.helix.participant.StateMachineEngine) HashMap(java.util.HashMap) HelixConfigScopeBuilder(org.apache.helix.model.builder.HelixConfigScopeBuilder) HelixConfigScope(org.apache.helix.model.HelixConfigScope)

Example 19 with StateMachineEngine

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

the class TestGenericTaskAssignmentCalculator 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("TaskOne", new TaskFactory() {

            @Override
            public Task createNewTask(TaskCallbackContext context) {
                return new TaskOne(context, instanceName);
            }
        });
        _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);
    Map<String, String> taskConfigMap = Maps.newHashMap();
    _taskConfig = new TaskConfig("TaskOne", taskConfigMap);
    _jobCommandMap = Maps.newHashMap();
}
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) TaskConfig(org.apache.helix.task.TaskConfig) 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 20 with StateMachineEngine

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

the class TestIndependentTaskRebalancer 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("TaskOne", new TaskFactory() {

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

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

            @Override
            public Task createNewTask(TaskCallbackContext context) {
                return new SingleFailTask();
            }
        });
        _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)

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