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;
}
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();
}
}
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);
}
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()));
}
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();
}
}
Aggregations