use of org.apache.helix.manager.zk.ZKHelixDataAccessor in project helix by apache.
the class TestDistributedCMMain method testDistributedCMMain.
@Test
public void testDistributedCMMain() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterNamePrefix = className + "_" + methodName;
final int n = 5;
final int clusterNb = 10;
System.out.println("START " + clusterNamePrefix + " at " + new Date(System.currentTimeMillis()));
// setup 10 clusters
for (int i = 0; i < clusterNb; i++) {
String clusterName = clusterNamePrefix + "0_" + i;
String participantName = "localhost" + i;
String resourceName = "TestDB" + i;
// participant port
TestHelper.setupCluster(// participant port
clusterName, // participant port
ZK_ADDR, // participant port
12918, // participant name prefix
participantName, // resource name prefix
resourceName, // resources
1, // partitions per resource
8, // number of nodes
n, // replicas
3, "MasterSlave", // do rebalance
true);
}
// setup controller cluster
final String controllerClusterName = "CONTROLLER_" + clusterNamePrefix;
// controller
TestHelper.setupCluster(// controller
"CONTROLLER_" + clusterNamePrefix, // controller
ZK_ADDR, // controller
0, // participant name prefix
"controller", // resource name prefix
clusterNamePrefix, // resources
1, // partitions per resource
clusterNb, // number of nodes
n, // replicas
3, "LeaderStandby", // do rebalance
true);
// start distributed cluster controllers
ClusterDistributedController[] controllers = new ClusterDistributedController[n + n];
for (int i = 0; i < n; i++) {
controllers[i] = new ClusterDistributedController(ZK_ADDR, controllerClusterName, "controller_" + i);
controllers[i].syncStart();
}
boolean result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, controllerClusterName), 30000);
Assert.assertTrue(result, "Controller cluster NOT in ideal state");
// start first cluster
MockParticipantManager[] participants = new MockParticipantManager[n];
final String firstClusterName = clusterNamePrefix + "0_0";
for (int i = 0; i < n; i++) {
String instanceName = "localhost0_" + (12918 + i);
participants[i] = new MockParticipantManager(ZK_ADDR, firstClusterName, instanceName);
participants[i].syncStart();
}
result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, firstClusterName));
Assert.assertTrue(result, "first cluster NOT in ideal state");
// add more controllers to controller cluster
ClusterSetup setupTool = new ClusterSetup(ZK_ADDR);
for (int i = 0; i < n; i++) {
String controller = "controller_" + (n + i);
setupTool.addInstanceToCluster(controllerClusterName, controller);
}
setupTool.rebalanceStorageCluster(controllerClusterName, clusterNamePrefix + "0", 6);
for (int i = n; i < 2 * n; i++) {
controllers[i] = new ClusterDistributedController(ZK_ADDR, controllerClusterName, "controller_" + i);
controllers[i].syncStart();
}
// verify controller cluster
result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, controllerClusterName));
Assert.assertTrue(result, "Controller cluster NOT in ideal state");
// verify first cluster
result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, firstClusterName));
Assert.assertTrue(result, "first cluster NOT in ideal state");
// stop controller_0-5
ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(controllerClusterName, baseAccessor);
Builder keyBuilder = accessor.keyBuilder();
for (int i = 0; i < n; i++) {
LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader());
String leaderName = leader.getId();
int j = Integer.parseInt(leaderName.substring(leaderName.lastIndexOf('_') + 1));
controllers[j].syncStop();
result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, controllerClusterName));
Assert.assertTrue(result, "Controller cluster NOT in ideal state");
result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, firstClusterName));
Assert.assertTrue(result, "first cluster NOT in ideal state");
}
// clean up
// wait for all zk callbacks done
System.out.println("Cleaning up...");
for (int i = 0; i < 5; i++) {
result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, controllerClusterName));
controllers[i].syncStop();
}
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterNamePrefix + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.manager.zk.ZKHelixDataAccessor in project helix by apache.
the class TestDistributedClusterController method testDistributedClusterController.
@Test
public void testDistributedClusterController() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterNamePrefix = className + "_" + methodName;
final int n = 5;
final int clusterNb = 10;
System.out.println("START " + clusterNamePrefix + " at " + new Date(System.currentTimeMillis()));
// setup 10 clusters
for (int i = 0; i < clusterNb; i++) {
String clusterName = clusterNamePrefix + "0_" + i;
String participantName = "localhost" + i;
String resourceName = "TestDB" + i;
// participant port
TestHelper.setupCluster(// participant port
clusterName, // participant port
ZK_ADDR, // participant port
12918, // participant name prefix
participantName, // resource name prefix
resourceName, // resources
1, // partitions per resource
8, // number of nodes
n, // replicas
3, "MasterSlave", // do rebalance
true);
}
// setup controller cluster
final String controllerClusterName = "CONTROLLER_" + clusterNamePrefix;
// controller
TestHelper.setupCluster(// controller
"CONTROLLER_" + clusterNamePrefix, // controller
ZK_ADDR, // controller
0, // participant name prefix
"controller", // resource name prefix
clusterNamePrefix, // resources
1, // partitions per resource
clusterNb, // number of nodes
n, // replicas
3, "LeaderStandby", // do rebalance
true);
// start distributed cluster controllers
ClusterDistributedController[] controllers = new ClusterDistributedController[n];
for (int i = 0; i < n; i++) {
controllers[i] = new ClusterDistributedController(ZK_ADDR, controllerClusterName, "controller_" + i);
controllers[i].syncStart();
}
boolean result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, controllerClusterName), 30000);
Assert.assertTrue(result, "Controller cluster NOT in ideal state");
// start first cluster
MockParticipantManager[] participants = new MockParticipantManager[n];
final String firstClusterName = clusterNamePrefix + "0_0";
for (int i = 0; i < n; i++) {
String instanceName = "localhost0_" + (12918 + i);
participants[i] = new MockParticipantManager(ZK_ADDR, firstClusterName, instanceName);
participants[i].syncStart();
}
result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, firstClusterName));
Assert.assertTrue(result, "first cluster NOT in ideal state");
// stop current leader in controller cluster
ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(controllerClusterName, baseAccessor);
Builder keyBuilder = accessor.keyBuilder();
LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader());
String leaderName = leader.getId();
int j = Integer.parseInt(leaderName.substring(leaderName.lastIndexOf('_') + 1));
controllers[j].syncStop();
// setup the second cluster
MockParticipantManager[] participants2 = new MockParticipantManager[n];
final String secondClusterName = clusterNamePrefix + "0_1";
for (int i = 0; i < n; i++) {
String instanceName = "localhost1_" + (12918 + i);
participants2[i] = new MockParticipantManager(ZK_ADDR, secondClusterName, instanceName);
participants2[i].syncStart();
}
result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, secondClusterName));
Assert.assertTrue(result, "second cluster NOT in ideal state");
// clean up
// wait for all zk callbacks done
System.out.println("Cleaning up...");
for (int i = 0; i < 5; i++) {
result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, controllerClusterName));
controllers[i].syncStop();
}
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterNamePrefix + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.manager.zk.ZKHelixDataAccessor in project helix by apache.
the class TestRenamePartition method testRenamePartitionCustomIS.
@Test()
public void testRenamePartitionCustomIS() throws Exception {
String clusterName = "CLUSTER_" + getShortClassName() + "_custom";
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
"TestDB", // resources
1, // partitions per resource
10, // number of nodes
5, // replicas
3, "MasterSlave", // do rebalance
false);
// calculate idealState
List<String> instanceNames = Arrays.asList("localhost_12918", "localhost_12919", "localhost_12920", "localhost_12921", "localhost_12922");
ZNRecord destIS = DefaultIdealStateCalculator.calculateIdealState(instanceNames, 10, 3 - 1, "TestDB0", "MASTER", "SLAVE");
IdealState idealState = new IdealState(destIS);
idealState.setRebalanceMode(RebalanceMode.CUSTOMIZED);
idealState.setReplicas("3");
idealState.setStateModelDefRef("MasterSlave");
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
Builder keyBuilder = accessor.keyBuilder();
accessor.setProperty(keyBuilder.idealStates("TestDB0"), idealState);
startAndVerify(clusterName);
Map<String, String> stateMap = idealState.getRecord().getMapFields().remove("TestDB0_0");
idealState.getRecord().getMapFields().put("TestDB0_100", stateMap);
accessor.setProperty(keyBuilder.idealStates("TestDB0"), idealState);
boolean result = ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
stop(clusterName);
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.manager.zk.ZKHelixDataAccessor in project helix by apache.
the class TestResetPartitionState method clearStatusUpdate.
private void clearStatusUpdate(String clusterName, String instance, String resource, String partition) {
// clear status update for error partition so verify() will not fail on old
// errors
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
Builder keyBuilder = accessor.keyBuilder();
LiveInstance liveInstance = accessor.getProperty(keyBuilder.liveInstance(instance));
accessor.removeProperty(keyBuilder.stateTransitionStatus(instance, liveInstance.getSessionId(), resource, partition));
}
use of org.apache.helix.manager.zk.ZKHelixDataAccessor 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