use of org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier in project helix by apache.
the class TestHelixAdminScenariosRest method testDeactivateCluster.
@Test
public void testDeactivateCluster() throws Exception {
final String clusterName = "clusterTestDeactivateCluster";
final String controllerClusterName = "controllerClusterTestDeactivateCluster";
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", 16);
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);
}
String clusterUrl = getClusterUrl(clusterName);
// activate cluster
assertSuccessPostOperation(clusterUrl, activateClusterCmd(controllerClusterName, true), false);
boolean verifyResult = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, controllerClusterName));
Assert.assertTrue(verifyResult);
verifyResult = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(verifyResult);
// deactivate cluster
assertSuccessPostOperation(clusterUrl, activateClusterCmd(controllerClusterName, false), false);
Thread.sleep(6000);
Assert.assertFalse(_gZkClient.exists("/" + controllerClusterName + "/IDEALSTATES/" + clusterName));
HelixDataAccessor accessor = participants.get("localhost_1231").getHelixDataAccessor();
String path = accessor.keyBuilder().controllerLeader().getPath();
Assert.assertFalse(_gZkClient.exists(path));
deleteUrl(clusterUrl, true);
Assert.assertTrue(_gZkClient.exists("/" + clusterName));
// leader node should be gone
for (MockParticipantManager participant : participants.values()) {
participant.syncStop();
}
deleteUrl(clusterUrl, false);
Assert.assertFalse(_gZkClient.exists("/" + clusterName));
// 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 testDropAddResource.
@Test
public void testDropAddResource() throws Exception {
final String clusterName = "clusterTestDropAddResource";
// setup cluster
addCluster(clusterName);
addResource(clusterName, "db_11", 22);
addInstancesToCluster(clusterName, "localhost_123", 6, null);
rebalanceResource(clusterName, "db_11");
ZNRecord record = _gSetupTool.getClusterManagementTool().getResourceIdealState(clusterName, "db_11").getRecord();
String x = ObjectToJson(record);
FileWriter fos = new FileWriter("/tmp/temp.log");
PrintWriter pw = new PrintWriter(fos);
pw.write(x);
pw.close();
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 resourceUrl = getResourceUrl(clusterName, "db_11");
deleteUrl(resourceUrl, false);
verifyResult = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(verifyResult);
addResource(clusterName, "db_11", 22);
String idealStateUrl = getResourceUrl(clusterName, "db_11") + "/idealState";
Map<String, String> extraform = new HashMap<String, String>();
extraform.put(JsonParameters.NEW_IDEAL_STATE, x);
assertSuccessPostOperation(idealStateUrl, addIdealStateCmd(), extraform, false);
verifyResult = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(verifyResult);
ZNRecord record2 = _gSetupTool.getClusterManagementTool().getResourceIdealState(clusterName, "db_11").getRecord();
Assert.assertTrue(record2.equals(record));
// 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 TestHelixAdminScenariosRest method testEnablePartitions.
@Test
public void testEnablePartitions() throws IOException, InterruptedException {
final String clusterName = "clusterTestEnablePartitions";
// 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);
}
HelixDataAccessor accessor = participants.get("localhost_1231").getHelixDataAccessor();
// drop node should fail as not disabled
String hostName = "localhost_1231";
String instanceUrl = getInstanceUrl(clusterName, hostName);
ExternalView ev = accessor.getProperty(accessor.keyBuilder().externalView("db_11"));
String response = assertSuccessPostOperation(instanceUrl, enablePartitionCmd("db_11", "db_11_0;db_11_11", false), false);
Assert.assertTrue(response.contains("DISABLED_PARTITION"));
Assert.assertTrue(response.contains("db_11_0"));
Assert.assertTrue(response.contains("db_11_11"));
boolean verifyResult = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(verifyResult);
ev = accessor.getProperty(accessor.keyBuilder().externalView("db_11"));
Assert.assertEquals(ev.getStateMap("db_11_0").get(hostName), "OFFLINE");
Assert.assertEquals(ev.getStateMap("db_11_11").get(hostName), "OFFLINE");
response = assertSuccessPostOperation(instanceUrl, enablePartitionCmd("db_11", "db_11_0;db_11_11", true), false);
Assert.assertFalse(response.contains("db_11_0"));
Assert.assertFalse(response.contains("db_11_11"));
verifyResult = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(verifyResult);
ev = accessor.getProperty(accessor.keyBuilder().externalView("db_11"));
Assert.assertEquals(ev.getStateMap("db_11_0").get(hostName), "MASTER");
Assert.assertEquals(ev.getStateMap("db_11_11").get(hostName), "SLAVE");
// 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 TestHelixAgent method test.
@Test
public void test() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
final String clusterName = className + "_" + methodName;
final int n = 1;
final String zkAddr = ZK_ADDR;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
// participant port
TestHelper.setupCluster(// participant port
clusterName, // participant port
zkAddr, // participant port
12918, // participant name prefix
"localhost", // resource name prefix
"TestDB", // resources
1, // partitions per resource
1, // number of nodes
n, // replicas
1, "MasterSlave", // do rebalance
true);
// set cluster config
HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(clusterName).build();
ConfigAccessor configAccessor = new ConfigAccessor(_gZkClient);
// String pidFile = ScriptTestHelper.getPrefix() + ScriptTestHelper.INTEGRATION_LOG_DIR +
// "/default/foo_{PARTITION_NAME}_pid.txt";
// the pid file path for the first partition
// delete it if exists
// String pidFileFirstPartition = ScriptTestHelper.getPrefix() +
// ScriptTestHelper.INTEGRATION_LOG_DIR + "/default/foo_TestDB0_0_pid.txt";
// File file = new File(pidFileFirstPartition);
// if (file.exists()) {
// file.delete();
// }
// set commands for state-transitions
CommandConfig.Builder builder = new CommandConfig.Builder();
CommandConfig cmdConfig = builder.setTransition("SLAVE", "MASTER").setCommand("simpleHttpClient.py SLAVE-MASTER").setCommandWorkingDir(workingDir).setCommandTimeout("0").build();
configAccessor.set(scope, cmdConfig.toKeyValueMap());
builder = new CommandConfig.Builder();
cmdConfig = builder.setTransition("OFFLINE", "SLAVE").setCommand("simpleHttpClient.py OFFLINE-SLAVE").setCommandWorkingDir(workingDir).build();
configAccessor.set(scope, cmdConfig.toKeyValueMap());
builder = new CommandConfig.Builder();
cmdConfig = builder.setTransition("MASTER", "SLAVE").setCommand("simpleHttpClient.py MASTER-SLAVE").setCommandWorkingDir(workingDir).build();
configAccessor.set(scope, cmdConfig.toKeyValueMap());
builder = new CommandConfig.Builder();
cmdConfig = builder.setTransition("SLAVE", "OFFLINE").setCommand("simpleHttpClient.py SLAVE-OFFLINE").setCommandWorkingDir(workingDir).build();
configAccessor.set(scope, cmdConfig.toKeyValueMap());
builder = new CommandConfig.Builder();
cmdConfig = builder.setTransition("OFFLINE", "DROPPED").setCommand(CommandAttribute.NOP.getName()).build();
configAccessor.set(scope, cmdConfig.toKeyValueMap());
// start controller
ClusterControllerManager controller = new ClusterControllerManager(zkAddr, clusterName, "controller_0");
controller.syncStart();
// start helix-agent
Map<String, Thread> agents = new HashMap<String, Thread>();
for (int i = 0; i < n; i++) {
final String instanceName = "localhost_" + (12918 + i);
Thread agentThread = new Thread() {
@Override
public void run() {
try {
HelixAgentMain.main(new String[] { "--zkSvr", zkAddr, "--cluster", clusterName, "--instanceName", instanceName, "--stateModel", "MasterSlave" });
} catch (Exception e) {
LOG.error("Exception start helix-agent", e);
}
}
};
agents.put(instanceName, agentThread);
agentThread.start();
// wait participant thread to start
Thread.sleep(100);
}
boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
// read the pid file should get current process id
// String readPid = SystemUtil.getPidFromFile(new File(pidFileFirstPartition));
// Assert.assertNotNull(readPid, "readPid is the pid for foo_test.py. should NOT be null");
// String name = ManagementFactory.getRuntimeMXBean().getName();
// String currentPid = name.substring(0,name.indexOf("@"));
// System.out.println("read-pid: " + readPid + ", current-pid: " + currentPid);
// drop resource will trigger M->S and S->O transitions
ClusterSetup.processCommandLineArgs(new String[] { "--zkSvr", ZK_ADDR, "--dropResource", clusterName, "TestDB0" });
result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
// clean up
controller.syncStop();
for (Thread agentThread : agents.values()) {
agentThread.interrupt();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier in project helix by apache.
the class TestClusterStatusMonitorLifecycle method beforeClass.
@BeforeClass
public void beforeClass() throws Exception {
String className = TestHelper.getTestClassName();
_clusterNamePrefix = className;
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
_controllerClusterName = "CONTROLLER_" + _clusterNamePrefix;
// controller
TestHelper.setupCluster(// controller
_controllerClusterName, // controller
ZK_ADDR, // port
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
_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
_participants = new MockParticipantManager[n];
_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");
}
Aggregations