use of org.apache.helix.integration.manager.ClusterControllerManager in project helix by apache.
the class TestDriver method stopCluster.
public static void stopCluster(String uniqClusterName) throws Exception {
if (!_testInfoMap.containsKey(uniqClusterName)) {
String errMsg = "test cluster hasn't been setup:" + uniqClusterName;
throw new IllegalArgumentException(errMsg);
}
TestInfo testInfo = _testInfoMap.remove(uniqClusterName);
// stop controller first
for (String instanceName : testInfo._managers.keySet()) {
if (instanceName.startsWith(CONTROLLER_PREFIX)) {
ClusterControllerManager controller = (ClusterControllerManager) testInfo._managers.get(instanceName);
controller.syncStop();
}
}
Thread.sleep(1000);
for (String instanceName : testInfo._managers.keySet()) {
if (!instanceName.startsWith(CONTROLLER_PREFIX)) {
MockParticipantManager participant = (MockParticipantManager) testInfo._managers.get(instanceName);
participant.syncStop();
}
}
testInfo._zkClient.close();
}
use of org.apache.helix.integration.manager.ClusterControllerManager in project helix by apache.
the class TestRebalancerPersistAssignments method beforeClass.
@Override
@BeforeClass
public void beforeClass() throws Exception {
// Logger.getRootLogger().setLevel(Level.INFO);
System.out.println("START " + CLASS_NAME + " at " + new Date(System.currentTimeMillis()));
String namespace = "/" + CLUSTER_NAME;
if (_gZkClient.exists(namespace)) {
_gZkClient.deleteRecursively(namespace);
}
_setupTool = new ClusterSetup(ZK_ADDR);
// setup storage cluster
_setupTool.addCluster(CLUSTER_NAME, true);
for (int i = 0; i < NODE_NR; i++) {
String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
_setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
}
// start controller
String controllerName = CONTROLLER_PREFIX + "_0";
_controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
_controller.syncStart();
// start dummy participants
for (int i = 0; i < NODE_NR; i++) {
String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
_instanceNames.add(instanceName);
_participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
_participants[i].syncStart();
}
}
use of org.apache.helix.integration.manager.ClusterControllerManager in project helix by apache.
the class TestResetPartitionState method testResetPartitionState.
@Test()
public void testResetPartitionState() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
final int n = 5;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
// participant port
TestHelper.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
n, // replicas
3, "MasterSlave", // do rebalance
true);
// start controller
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
Map<String, Set<String>> errPartitions = new HashMap<String, Set<String>>() {
{
put("SLAVE-MASTER", TestHelper.setOf("TestDB0_4"));
put("OFFLINE-SLAVE", TestHelper.setOf("TestDB0_8"));
}
};
// start mock participants
MockParticipantManager[] participants = new MockParticipantManager[n];
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
if (i == 0) {
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].setTransition(new ErrTransition(errPartitions));
} else {
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
}
participants[i].syncStart();
}
// verify cluster
Map<String, Map<String, String>> errStateMap = new HashMap<String, Map<String, String>>();
errStateMap.put("TestDB0", new HashMap<String, String>());
errStateMap.get("TestDB0").put("TestDB0_4", "localhost_12918");
errStateMap.get("TestDB0").put("TestDB0_8", "localhost_12918");
boolean result = ClusterStateVerifier.verifyByZkCallback((new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName, errStateMap)));
Assert.assertTrue(result, "Cluster verification fails");
// reset a non-exist partition, should throw exception
try {
String command = "--zkSvr " + ZK_ADDR + " --resetPartition " + clusterName + " localhost_12918 TestDB0 TestDB0_nonExist";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
Assert.fail("Should throw exception on reset a non-exist partition");
} catch (Exception e) {
// OK
}
// reset one error partition
errPartitions.remove("SLAVE-MASTER");
participants[0].setTransition(new ErrTransitionWithResetCnt(errPartitions));
clearStatusUpdate(clusterName, "localhost_12918", "TestDB0", "TestDB0_4");
_errToOfflineInvoked = 0;
String command = "--zkSvr " + ZK_ADDR + " --resetPartition " + clusterName + " localhost_12918 TestDB0 TestDB0_4";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
// wait reset to be done
Thread.sleep(200);
try {
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
Assert.fail("Should throw exception on reset a partition not in ERROR state");
} catch (Exception e) {
// OK
}
errStateMap.get("TestDB0").remove("TestDB0_4");
result = ClusterStateVerifier.verifyByZkCallback((new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName, errStateMap)));
Assert.assertTrue(result, "Cluster verification fails");
Assert.assertEquals(_errToOfflineInvoked, 1);
// reset the other error partition
participants[0].setTransition(new ErrTransitionWithResetCnt(null));
clearStatusUpdate(clusterName, "localhost_12918", "TestDB0", "TestDB0_8");
command = "--zkSvr " + ZK_ADDR + " --resetPartition " + clusterName + " localhost_12918 TestDB0 TestDB0_8";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
result = ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result, "Cluster verification fails");
Assert.assertEquals(_errToOfflineInvoked, 2, "Should reset 2 partitions");
// clean up
controller.syncStop();
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.integration.manager.ClusterControllerManager in project helix by apache.
the class TestResourceGroupEndtoEnd method beforeClass.
@BeforeClass
public void beforeClass() throws Exception {
_admin = new ZKHelixAdmin(_gZkClient);
// setup storage cluster
_gSetupTool.addCluster(CLUSTER_NAME, true);
List<String> instanceGroupTags = new ArrayList<String>();
for (int i = 0; i < INSTANCE_GROUP_NR; i++) {
String groupTag = "cluster_" + i;
addInstanceGroup(CLUSTER_NAME, groupTag, GROUP_NODE_NR);
instanceGroupTags.add(groupTag);
}
for (String tag : instanceGroupTags) {
List<String> instances = _admin.getInstancesInClusterWithTag(CLUSTER_NAME, tag);
IdealState idealState = createIdealState(TEST_DB, tag, instances, PARTITIONS, _replica, IdealState.RebalanceMode.CUSTOMIZED.toString(), BuiltInStateModelDefinitions.OnlineOffline.name());
_gSetupTool.addResourceToCluster(CLUSTER_NAME, idealState.getResourceName(), idealState);
}
// start dummy participants
int i = 0;
for (String group : instanceGroupTags) {
List<String> instances = _admin.getInstancesInClusterWithTag(CLUSTER_NAME, group);
for (String instance : instances) {
_participants[i] = new TestParticipantManager(ZK_ADDR, CLUSTER_NAME, TEST_DB, group, instance);
_participants[i].syncStart();
i++;
}
}
// start controller
String controllerName = CONTROLLER_PREFIX + "_0";
_controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
_controller.syncStart();
boolean result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, CLUSTER_NAME));
Assert.assertTrue(result);
// start speculator
_routingTableProvider = new RoutingTableProvider();
_spectator = HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, "spectator", InstanceType.SPECTATOR, ZK_ADDR);
_spectator.connect();
_spectator.addExternalViewChangeListener(_routingTableProvider);
Thread.sleep(1000);
}
use of org.apache.helix.integration.manager.ClusterControllerManager in project helix by apache.
the class TestSchemataSM method testSchemataSM.
@Test
public void testSchemataSM() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
int n = 5;
MockParticipantManager[] participants = new MockParticipantManager[n];
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
// participant start port
TestHelper.setupCluster(// participant start port
clusterName, // participant start port
ZK_ADDR, // participant start port
12918, // participant name prefix
"localhost", // resource name prefix
"TestSchemata", // resources
1, // partitions per resource
1, // number of nodes
n, // replicas
0, "STORAGE_DEFAULT_SM_SCHEMATA", // don't rebalance
false);
// rebalance ideal-state to use ANY_LIVEINSTANCE for preference list
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
PropertyKey key = keyBuilder.idealStates("TestSchemata0");
IdealState idealState = accessor.getProperty(key);
idealState.setReplicas(IdealState.IdealStateConstants.ANY_LIVEINSTANCE.toString());
idealState.getRecord().setListField("TestSchemata0_0", Arrays.asList(IdealState.IdealStateConstants.ANY_LIVEINSTANCE.toString()));
accessor.setProperty(key, idealState);
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller");
controller.syncStart();
// start n-1 participants
for (int i = 1; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
// start the remaining 1 participant
participants[0] = new MockParticipantManager(ZK_ADDR, clusterName, "localhost_12918");
participants[0].syncStart();
// make sure we have all participants in MASTER state
result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
key = keyBuilder.externalView("TestSchemata0");
ExternalView externalView = accessor.getProperty(key);
Map<String, String> stateMap = externalView.getStateMap("TestSchemata0_0");
Assert.assertNotNull(stateMap);
Assert.assertEquals(stateMap.size(), n, "all " + n + " participants should be in Master state");
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
Assert.assertNotNull(stateMap.get(instanceName));
Assert.assertEquals(stateMap.get(instanceName), "MASTER");
}
// clean up
controller.syncStop();
for (int i = 0; i < n; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Aggregations