use of org.apache.helix.tools.ClusterSetup 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.tools.ClusterSetup in project helix by apache.
the class TestRoutingTableSnapshot 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);
}
for (int i = 0; i < NUM_NODES; i++) {
String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
_participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
_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();
}
use of org.apache.helix.tools.ClusterSetup in project helix by apache.
the class TestZkConnectionLost method beforeClass.
@BeforeClass
public void beforeClass() throws Exception {
_participants = new MockParticipantManager[_numNodes];
String namespace = "/" + CLUSTER_NAME;
if (_gZkClient.exists(namespace)) {
_gZkClient.deleteRecursively(namespace);
}
_setupTool = new ClusterSetup(ZK_ADDR);
_setupTool.addCluster(CLUSTER_NAME, true);
setupParticipants();
setupDBs();
createManagers();
// start controller
String controllerName = CONTROLLER_PREFIX + "_0";
_controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
_controller.syncStart();
HelixClusterVerifier clusterVerifier = new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(ZK_ADDR).build();
Assert.assertTrue(clusterVerifier.verify());
_zkServerRef.set(_zkServer);
}
use of org.apache.helix.tools.ClusterSetup in project helix by apache.
the class TestZkReconnect method testZKReconnect.
@Test(enabled = false)
public void testZKReconnect() throws Exception {
final AtomicReference<ZkServer> zkServerRef = new AtomicReference<ZkServer>();
final int zkPort = TestHelper.getRandomPort();
final String zkAddr = String.format("localhost:%d", zkPort);
ZkServer zkServer = TestHelper.startZkServer(zkAddr);
zkServerRef.set(zkServer);
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
// Setup cluster
LOG.info("Setup clusters");
ClusterSetup clusterSetup = new ClusterSetup(zkAddr);
clusterSetup.addCluster(clusterName, true);
// Registers and starts controller
LOG.info("Starts controller");
HelixManager controller = HelixManagerFactory.getZKHelixManager(clusterName, null, InstanceType.CONTROLLER, zkAddr);
controller.connect();
// Registers and starts participant
LOG.info("Starts participant");
String hostname = "localhost";
String instanceId = String.format("%s_%d", hostname, 1);
clusterSetup.addInstanceToCluster(clusterName, instanceId);
HelixManager participant = HelixManagerFactory.getZKHelixManager(clusterName, instanceId, InstanceType.PARTICIPANT, zkAddr);
participant.connect();
LOG.info("Register state machine");
final CountDownLatch latch = new CountDownLatch(1);
participant.getStateMachineEngine().registerStateModelFactory("OnlineOffline", new StateModelFactory<StateModel>() {
@Override
public StateModel createNewStateModel(String resource, String stateUnitKey) {
return new SimpleStateModel(latch);
}
}, "test");
String resourceName = "test-resource";
LOG.info("Ideal state assignment");
HelixAdmin helixAdmin = participant.getClusterManagmentTool();
helixAdmin.addResource(clusterName, resourceName, 1, "OnlineOffline", IdealState.RebalanceMode.CUSTOMIZED.toString());
IdealState idealState = helixAdmin.getResourceIdealState(clusterName, resourceName);
idealState.setReplicas("1");
idealState.setStateModelFactoryName("test");
idealState.setPartitionState(resourceName + "_0", instanceId, "ONLINE");
LOG.info("Shutdown ZK server");
TestHelper.stopZkServer(zkServerRef.get());
Executors.newSingleThreadScheduledExecutor().schedule(new Runnable() {
@Override
public void run() {
try {
LOG.info("Restart ZK server");
// zkServer.set(TestUtils.startZookeeper(zkDir, zkPort));
zkServerRef.set(TestHelper.startZkServer(zkAddr, null, false));
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
}
}, 2L, TimeUnit.SECONDS);
// future.get();
LOG.info("Before update ideal state");
helixAdmin.setResourceIdealState(clusterName, resourceName, idealState);
LOG.info("After update ideal state");
LOG.info("Wait for OFFLINE->ONLINE state transition");
try {
Assert.assertTrue(latch.await(15, TimeUnit.SECONDS));
// wait until stable state
boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(zkAddr, clusterName));
Assert.assertTrue(result);
} finally {
participant.disconnect();
zkServerRef.get().shutdown();
}
}
use of org.apache.helix.tools.ClusterSetup in project helix by apache.
the class TestZkReconnect method testZKDisconnectCallback.
@Test
public void testZKDisconnectCallback() throws Exception {
final int zkPort = TestHelper.getRandomPort();
final String zkAddr = String.format("localhost:%d", zkPort);
final ZkServer zkServer = TestHelper.startZkServer(zkAddr);
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
final String clusterName = className + "_" + methodName;
// Init flag to check if callback is triggered
final AtomicReference<Boolean> flag = new AtomicReference<Boolean>(false);
// Setup cluster
LOG.info("Setup clusters");
ClusterSetup clusterSetup = new ClusterSetup(zkAddr);
clusterSetup.addCluster(clusterName, true);
// For fast test, set short timeout
System.setProperty("zk.connection.timeout", "2000");
System.setProperty("zk.connectionReEstablishment.timeout", "1000");
// Registers and starts controller, register listener for disconnect handling
LOG.info("Starts controller");
final ZKHelixManager controller = (ZKHelixManager) HelixManagerFactory.getZKHelixManager(clusterName, null, InstanceType.CONTROLLER, zkAddr, new HelixManagerStateListener() {
@Override
public void onConnected(HelixManager helixManager) throws Exception {
return;
}
@Override
public void onDisconnected(HelixManager helixManager, Throwable error) throws Exception {
Assert.assertEquals(helixManager.getClusterName(), clusterName);
flag.getAndSet(true);
}
});
try {
controller.connect();
ZkHelixPropertyStore propertyStore = controller.getHelixPropertyStore();
// 1. shutdown zkServer and check if handler trigger callback
zkServer.shutdown();
// Retry will fail, and flag should be set within onDisconnected handler
controller.handleSessionEstablishmentError(new Exception("For testing"));
Assert.assertTrue(flag.get());
try {
propertyStore.get("/", null, 0);
Assert.fail("propertyStore should be disconnected.");
} catch (IllegalStateException e) {
// Expected exception
System.out.println(e.getMessage());
}
// 2. restart zkServer and check if handler will recover connection
flag.getAndSet(false);
zkServer.start();
// Retry will succeed, and flag should not be set
controller.handleSessionEstablishmentError(new Exception("For testing"));
Assert.assertFalse(flag.get());
// New propertyStore should be in good state
propertyStore = controller.getHelixPropertyStore();
propertyStore.get("/", null, 0);
} finally {
controller.disconnect();
zkServer.shutdown();
System.clearProperty("zk.connection.timeout");
System.clearProperty("zk.connectionReEstablishment.timeout");
}
}
Aggregations