Search in sources :

Example 1 with StateMachineEngine

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

the class SegmentCompletionIntegrationTests method startFakeServer.

// Start a fake server that only implements helix part, does not consume any rows.
private void startFakeServer() throws Exception {
    String hostName = NetUtil.getHostAddress();
    _serverInstance = CommonConstants.Helix.PREFIX_OF_SERVER_INSTANCE + hostName + "_" + CommonConstants.Helix.DEFAULT_SERVER_NETTY_PORT;
    _helixManager = HelixManagerFactory.getZKHelixManager(_clusterName, _serverInstance, InstanceType.PARTICIPANT, ZkStarter.DEFAULT_ZK_STR);
    final StateMachineEngine stateMachineEngine = _helixManager.getStateMachineEngine();
    _helixManager.connect();
    ZkHelixPropertyStore<ZNRecord> zkPropertyStore = ZkUtils.getZkPropertyStore(_helixManager, _clusterName);
    final StateModelFactory<?> stateModelFactory = new FakeServerSegmentStateModelFactory(_clusterName, _serverInstance, zkPropertyStore);
    stateMachineEngine.registerStateModelFactory(SegmentOnlineOfflineStateModelFactory.getStateModelName(), stateModelFactory);
    _helixAdmin = _helixManager.getClusterManagmentTool();
    _helixAdmin.addInstanceTag(_clusterName, _serverInstance, TableNameBuilder.REALTIME_TABLE_NAME_BUILDER.forTable(ControllerTenantNameBuilder.DEFAULT_TENANT_NAME));
    ControllerLeaderLocator.create(_helixManager);
}
Also used : StateMachineEngine(org.apache.helix.participant.StateMachineEngine) ZNRecord(org.apache.helix.ZNRecord)

Example 2 with StateMachineEngine

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

the class HelixParticipant method initialize.

/**
 * Initialize the participant by registering via the {@link HelixManager} as a participant to the associated Helix
 * cluster.
 * @param hostName the hostname to use when registering as a participant.
 * @param port the port to use when registering as a participant.
 * @param ambryHealthReports {@link List} of {@link AmbryHealthReport} to be registered to the participant.
 * @throws IOException if there is an error connecting to the Helix cluster.
 */
@Override
public void initialize(String hostName, int port, List<AmbryHealthReport> ambryHealthReports) throws IOException {
    logger.info("Initializing participant");
    instanceName = ClusterMapUtils.getInstanceName(hostName, port);
    manager = helixFactory.getZKHelixManager(clusterName, instanceName, InstanceType.PARTICIPANT, zkConnectStr);
    StateMachineEngine stateMachineEngine = manager.getStateMachineEngine();
    stateMachineEngine.registerStateModelFactory(LeaderStandbySMD.name, new AmbryStateModelFactory());
    registerHealthReportTasks(stateMachineEngine, ambryHealthReports);
    try {
        manager.connect();
    } catch (Exception e) {
        throw new IOException("Exception while connecting to the Helix manager", e);
    }
    for (AmbryHealthReport ambryHealthReport : ambryHealthReports) {
        manager.getHealthReportCollector().addHealthReportProvider((HealthReportProvider) ambryHealthReport);
    }
}
Also used : StateMachineEngine(org.apache.helix.participant.StateMachineEngine) IOException(java.io.IOException) IOException(java.io.IOException) JSONException(org.json.JSONException) AmbryHealthReport(com.github.ambry.server.AmbryHealthReport)

Example 3 with StateMachineEngine

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

the class HelixStorageContainerManager method doStart.

@Override
protected void doStart() {
    // create the controller
    try (HelixStorageController controller = new HelixStorageController(zkServers)) {
        controller.addNode(clusterName, endpoint, endpointName);
    }
    StateMachineEngine sme = this.manager.getStateMachineEngine();
    StateModelFactory<StateModel> smFactory = new WriteReadStateModelFactory(registry);
    sme.registerStateModelFactory(WriteReadSMD.NAME, smFactory);
    try {
        manager.connect();
        manager.addExternalViewChangeListener(rtProvider);
    } catch (Exception e) {
        throw new StorageRuntimeException(e);
    }
}
Also used : StateMachineEngine(org.apache.helix.participant.StateMachineEngine) StateModel(org.apache.helix.participant.statemachine.StateModel) StorageRuntimeException(org.apache.bookkeeper.stream.storage.exceptions.StorageRuntimeException) IOException(java.io.IOException) StorageRuntimeException(org.apache.bookkeeper.stream.storage.exceptions.StorageRuntimeException)

Example 4 with StateMachineEngine

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

the class HelixControllerMain method startHelixController.

public static HelixManager startHelixController(final String zkConnectString, final String clusterName, final String controllerName, final String controllerMode) {
    HelixManager manager = null;
    try {
        if (controllerMode.equalsIgnoreCase(STANDALONE)) {
            manager = HelixManagerFactory.getZKHelixManager(clusterName, controllerName, InstanceType.CONTROLLER, zkConnectString);
            manager.connect();
        } else if (controllerMode.equalsIgnoreCase(DISTRIBUTED)) {
            manager = HelixManagerFactory.getZKHelixManager(clusterName, controllerName, InstanceType.CONTROLLER_PARTICIPANT, zkConnectString);
            DistClusterControllerStateModelFactory stateModelFactory = new DistClusterControllerStateModelFactory(zkConnectString);
            StateMachineEngine stateMach = manager.getStateMachineEngine();
            stateMach.registerStateModelFactory("LeaderStandby", stateModelFactory);
            manager.connect();
        } else {
            logger.error("cluster controller mode:" + controllerMode + " NOT supported");
        }
    } catch (Exception e) {
        logger.error("Exception while starting controller", e);
    }
    return manager;
}
Also used : HelixManager(org.apache.helix.HelixManager) DistClusterControllerStateModelFactory(org.apache.helix.participant.DistClusterControllerStateModelFactory) StateMachineEngine(org.apache.helix.participant.StateMachineEngine) ZkInterruptedException(org.I0Itec.zkclient.exception.ZkInterruptedException) ParseException(org.apache.commons.cli.ParseException)

Example 5 with StateMachineEngine

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

the class DummyParticipant method main.

public static void main(String[] args) {
    if (args.length < 3) {
        System.err.println("USAGE: DummyParticipant zkAddress clusterName instanceName");
        System.exit(1);
    }
    String zkAddr = args[0];
    String clusterName = args[1];
    String instanceName = args[2];
    HelixManager manager = null;
    try {
        manager = HelixManagerFactory.getZKHelixManager(clusterName, instanceName, InstanceType.PARTICIPANT, zkAddr);
        StateMachineEngine stateMach = manager.getStateMachineEngine();
        DummyMSModelFactory msModelFactory = new DummyMSModelFactory();
        stateMach.registerStateModelFactory("MasterSlave", msModelFactory);
        manager.connect();
        Thread.currentThread().join();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        if (manager != null) {
            manager.disconnect();
        }
    }
}
Also used : HelixManager(org.apache.helix.HelixManager) StateMachineEngine(org.apache.helix.participant.StateMachineEngine)

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