use of org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier in project helix by apache.
the class TestHelixAdminScenariosRest method testStartCluster.
@Test
public void testStartCluster() throws Exception {
final String clusterName = "clusterTestStartCluster";
final String controllerClusterName = "controllerClusterTestStartCluster";
Map<String, MockParticipantManager> participants = new HashMap<String, MockParticipantManager>();
Map<String, ClusterDistributedController> distControllers = new HashMap<String, ClusterDistributedController>();
// setup cluster
addCluster(clusterName);
addInstancesToCluster(clusterName, "localhost:123", 6, null);
addResource(clusterName, "db_11", 8);
rebalanceResource(clusterName, "db_11");
addCluster(controllerClusterName);
addInstancesToCluster(controllerClusterName, "controller_900", 2, null);
// start mock nodes
for (int i = 0; i < 6; i++) {
String instanceName = "localhost_123" + i;
MockParticipantManager participant = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participant.syncStart();
participants.put(instanceName, participant);
}
// start controller nodes
for (int i = 0; i < 2; i++) {
String controllerName = "controller_900" + i;
ClusterDistributedController distController = new ClusterDistributedController(ZK_ADDR, controllerClusterName, controllerName);
distController.syncStart();
distControllers.put(controllerName, distController);
}
Thread.sleep(100);
// activate clusters
// wrong grand clustername
String clusterUrl = getClusterUrl(clusterName);
assertSuccessPostOperation(clusterUrl, activateClusterCmd("nonExistCluster", true), true);
// wrong cluster name
clusterUrl = getClusterUrl("nonExistCluster");
assertSuccessPostOperation(clusterUrl, activateClusterCmd(controllerClusterName, true), true);
clusterUrl = getClusterUrl(clusterName);
assertSuccessPostOperation(clusterUrl, activateClusterCmd(controllerClusterName, true), false);
Thread.sleep(500);
deleteUrl(clusterUrl, true);
// verify leader node
HelixDataAccessor accessor = distControllers.get("controller_9001").getHelixDataAccessor();
LiveInstance controllerLeader = accessor.getProperty(accessor.keyBuilder().controllerLeader());
Assert.assertTrue(controllerLeader.getInstanceName().startsWith("controller_900"));
accessor = participants.get("localhost_1232").getHelixDataAccessor();
LiveInstance leader = accessor.getProperty(accessor.keyBuilder().controllerLeader());
for (int i = 0; i < 5; i++) {
if (leader != null) {
break;
}
Thread.sleep(1000);
leader = accessor.getProperty(accessor.keyBuilder().controllerLeader());
}
Assert.assertTrue(leader.getInstanceName().startsWith("controller_900"));
boolean verifyResult = ClusterStateVerifier.verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(verifyResult);
verifyResult = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(verifyResult);
Thread.sleep(1000);
// clean up
for (ClusterDistributedController controller : distControllers.values()) {
controller.syncStop();
}
for (MockParticipantManager participant : participants.values()) {
participant.syncStop();
}
}
use of org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier in project helix by apache.
the class TestHelixAdminScenariosRest method testExpandCluster.
@Test
public void testExpandCluster() throws Exception {
final String clusterName = "clusterTestExpandCluster";
// setup cluster
addCluster(clusterName);
addInstancesToCluster(clusterName, "localhost:123", 6, null);
addResource(clusterName, "db_11", 22);
rebalanceResource(clusterName, "db_11");
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_9900");
controller.syncStart();
// start mock nodes
Map<String, MockParticipantManager> participants = new HashMap<String, MockParticipantManager>();
for (int i = 0; i < 6; i++) {
String instanceName = "localhost_123" + i;
MockParticipantManager participant = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participant.syncStart();
participants.put(instanceName, participant);
}
boolean verifyResult = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(verifyResult);
String clusterUrl = getClusterUrl(clusterName);
String instancesUrl = clusterUrl + "/instances";
String instances = "localhost:12331;localhost:12341;localhost:12351;localhost:12361";
String response = assertSuccessPostOperation(instancesUrl, addInstanceCmd(instances), false);
String[] hosts = instances.split(";");
for (String host : hosts) {
Assert.assertTrue(response.contains(host.replace(':', '_')));
}
response = assertSuccessPostOperation(clusterUrl, expandClusterCmd(), false);
for (int i = 3; i <= 6; i++) {
String instanceName = "localhost_123" + i + "1";
MockParticipantManager participant = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participant.syncStart();
participants.put(instanceName, participant);
}
verifyResult = ClusterStateVerifier.verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(verifyResult);
verifyResult = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(verifyResult);
// clean up
controller.syncStop();
for (MockParticipantManager participant : participants.values()) {
participant.syncStop();
}
}
use of org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier in project helix by apache.
the class TestClusterStateVerifier method testResourceSubset.
@Test
public void testResourceSubset() throws InterruptedException {
// Ensure that this passes even when one resource is down
_admin.enableInstance(_clusterName, "localhost_12918", false);
Thread.sleep(1000);
_admin.enableCluster(_clusterName, false);
_admin.enableInstance(_clusterName, "localhost_12918", true);
boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, _clusterName, null, Sets.newHashSet(RESOURCES[1])));
Assert.assertTrue(result);
String[] args = { "--zkSvr", ZK_ADDR, "--cluster", _clusterName, "--resources", RESOURCES[1] };
result = ClusterStateVerifier.verifyState(args);
Assert.assertTrue(result);
// But the full cluster verification should fail
boolean fullResult = new BestPossAndExtViewZkVerifier(ZK_ADDR, _clusterName).verify();
Assert.assertFalse(fullResult);
_admin.enableCluster(_clusterName, true);
}
use of org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier in project helix by apache.
the class TestClusterStateVerifier method testEntireCluster.
@Test
public void testEntireCluster() {
// Just ensure that the entire cluster passes
// ensure that the external view coalesces
boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, _clusterName));
Assert.assertTrue(result);
}
use of org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier in project helix by apache.
the class TestHelixAdminCli method testDropAddResource.
@Test
public void testDropAddResource() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
String grandClusterName = clusterName + "_grand";
final int n = 6;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
MockParticipantManager[] participants = new MockParticipantManager[n];
ClusterDistributedController[] controllers = new ClusterDistributedController[2];
setupCluster(clusterName, grandClusterName, n, participants, controllers);
String command = "-zkSvr " + ZK_ADDR + " -activateCluster " + clusterName + " " + grandClusterName + " true";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
Thread.sleep(500);
// save ideal state
BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseAccessor);
IdealState idealState = accessor.getProperty(accessor.keyBuilder().idealStates("db_11"));
ZNRecordJsonSerializer serializer = new ZNRecordJsonSerializer();
String tmpDir = System.getProperty("java.io.tmpdir");
if (tmpDir == null) {
tmpDir = "/tmp";
}
final String tmpIdealStateFile = tmpDir + "/" + clusterName + "_idealState.log";
FileWriter fos = new FileWriter(tmpIdealStateFile);
PrintWriter pw = new PrintWriter(fos);
pw.write(new String(serializer.serialize(idealState.getRecord())));
pw.close();
command = "-zkSvr " + ZK_ADDR + " -dropResource " + clusterName + " db_11 ";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
boolean verifyResult = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(verifyResult);
command = "-zkSvr " + ZK_ADDR + " -addIdealState " + clusterName + " db_11 " + tmpIdealStateFile;
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
verifyResult = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(verifyResult);
IdealState idealState2 = accessor.getProperty(accessor.keyBuilder().idealStates("db_11"));
Assert.assertTrue(idealState2.getRecord().equals(idealState.getRecord()));
// clean up
for (int i = 0; i < controllers.length; i++) {
controllers[i].syncStop();
}
for (int i = 0; i < participants.length; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Aggregations