use of org.apache.helix.integration.manager.ClusterDistributedController in project helix by apache.
the class TestHelixAdminCli method setupCluster.
private void setupCluster(String clusterName, String grandClusterName, final int n, MockParticipantManager[] participants, ClusterDistributedController[] controllers) throws Exception, InterruptedException {
// add cluster
String command = "-zkSvr " + ZK_ADDR + " -addCluster " + clusterName;
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
// add grand cluster
command = "-zkSvr " + ZK_ADDR + " -addCluster " + grandClusterName;
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
// add nodes
for (int i = 0; i < n; i++) {
command = "-zkSvr " + ZK_ADDR + " -addNode " + clusterName + " localhost:123" + i;
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
}
// add resource
command = "-zkSvr " + ZK_ADDR + " -addResource " + clusterName + " db_11 48 MasterSlave";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
// rebalance with key prefix
command = "-zkSvr " + ZK_ADDR + " -rebalance " + clusterName + " db_11 2 -key alias";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
// add nodes to grand cluster
command = "-zkSvr " + ZK_ADDR + " -addNode " + grandClusterName + " controller:9000;controller:9001";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
// start mock nodes
for (int i = 0; i < n; i++) {
String instanceName = "localhost_123" + i;
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
// start controller nodes
for (int i = 0; i < 2; i++) {
controllers[i] = new ClusterDistributedController(ZK_ADDR, grandClusterName, "controller_900" + i);
controllers[i].syncStart();
}
Thread.sleep(100);
}
use of org.apache.helix.integration.manager.ClusterDistributedController in project helix by apache.
the class TestHelixAdminCli method testDeactivateCluster.
@Test
public void testDeactivateCluster() 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);
// deactivate cluster
command = "-zkSvr " + ZK_ADDR + " -activateCluster " + clusterName + " " + grandClusterName + " false";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseAccessor);
String path = accessor.keyBuilder().controllerLeader().getPath();
for (int i = 0; i < 10; i++) {
Thread.sleep(1000);
if (!_gZkClient.exists(path)) {
break;
}
}
Assert.assertFalse(_gZkClient.exists(path), "leader should be gone after deactivate the cluster");
command = "-zkSvr " + ZK_ADDR + " -dropCluster " + clusterName;
try {
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
Assert.fail("dropCluster should fail since there are still instances running");
} catch (Exception e) {
// OK
}
for (int i = 0; i < participants.length; i++) {
participants[i].syncStop();
}
command = "-zkSvr localhost:2183 -dropCluster " + clusterName;
ClusterSetup.processCommandLineArgs(command.split("\\s"));
for (int i = 0; i < controllers.length; i++) {
controllers[i].syncStop();
}
command = "-zkSvr localhost:2183 -dropCluster " + grandClusterName;
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.integration.manager.ClusterDistributedController 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.integration.manager.ClusterDistributedController in project helix by apache.
the class TestClusterStatusMonitorLifecycle method testClusterStatusMonitorLifecycle.
@Test
public void testClusterStatusMonitorLifecycle() throws InstanceNotFoundException, MalformedObjectNameException, NullPointerException, IOException, InterruptedException {
// Filter other unrelated clusters' metrics
QueryExp exp = Query.match(Query.attr("SensorName"), Query.value("*" + _clusterNamePrefix + "*"));
Set<ObjectInstance> mbeans = new HashSet<>(ManagementFactory.getPlatformMBeanServer().queryMBeans(new ObjectName("ClusterStatus:*"), exp));
_participants[0].disconnect();
// 1 participant goes away
// No change in instance/resource mbean
// Unregister 1 per-instance resource mbean and message queue mbean
Thread.sleep(1000);
int previousMBeanCount = mbeans.size();
mbeans = new HashSet<>(ManagementFactory.getPlatformMBeanServer().queryMBeans(new ObjectName("ClusterStatus:*"), exp));
Assert.assertEquals(mbeans.size(), previousMBeanCount - 2);
HelixDataAccessor accessor = _participants[n - 1].getHelixDataAccessor();
String firstControllerName = accessor.getProperty(accessor.keyBuilder().controllerLeader()).getId();
ClusterDistributedController firstController = null;
for (ClusterDistributedController controller : _controllers) {
if (controller.getInstanceName().equals(firstControllerName)) {
firstController = controller;
}
}
firstController.disconnect();
// 1 controller goes away
// 1 message queue mbean, 1 PerInstanceResource mbean, and one message queue mbean
Thread.sleep(2000);
previousMBeanCount = mbeans.size();
mbeans = new HashSet<>(ManagementFactory.getPlatformMBeanServer().queryMBeans(new ObjectName("ClusterStatus:*"), exp));
Assert.assertEquals(mbeans.size(), previousMBeanCount - 3);
String instanceName = "localhost0_" + (12918 + 0);
_participants[0] = new MockParticipantManager(ZK_ADDR, _firstClusterName, instanceName);
_participants[0].syncStart();
// 1 participant comes back
// No change in instance/resource mbean
// Register 1 per-instance resource mbean and 1 message queue mbean
Thread.sleep(2000);
previousMBeanCount = mbeans.size();
mbeans = new HashSet<>(ManagementFactory.getPlatformMBeanServer().queryMBeans(new ObjectName("ClusterStatus:*"), exp));
Assert.assertEquals(mbeans.size(), previousMBeanCount + 2);
// Add a resource
// Register 1 resource mbean
// Register 5 per-instance resource mbean
ClusterSetup setupTool = new ClusterSetup(ZK_ADDR);
IdealState idealState = accessor.getProperty(accessor.keyBuilder().idealStates("TestDB00"));
setupTool.addResourceToCluster(_firstClusterName, "TestDB1", idealState.getNumPartitions(), "MasterSlave");
setupTool.rebalanceResource(_firstClusterName, "TestDB1", Integer.parseInt(idealState.getReplicas()));
Thread.sleep(2000);
// Add one resource, PerInstanceResource mbeans and 1 resource monitor
previousMBeanCount = mbeans.size();
mbeans = new HashSet<>(ManagementFactory.getPlatformMBeanServer().queryMBeans(new ObjectName("ClusterStatus:*"), exp));
Assert.assertEquals(mbeans.size(), previousMBeanCount + _participants.length + 1);
// Remove a resource
// No change in instance/resource mbean
// Unregister 5 per-instance resource mbean
setupTool.dropResourceFromCluster(_firstClusterName, "TestDB1");
Thread.sleep(2000);
previousMBeanCount = mbeans.size();
mbeans = new HashSet<>(ManagementFactory.getPlatformMBeanServer().queryMBeans(new ObjectName("ClusterStatus:*"), exp));
Assert.assertEquals(mbeans.size(), previousMBeanCount - (_participants.length + 1));
// Cleanup controllers then MBeans should all be removed.
cleanupControllers();
Thread.sleep(2000);
// Check if any MBeans leftover.
// Note that MessageQueueStatus is not bound with controller only. So it will still exist.
exp = Query.and(Query.not(Query.match(Query.attr("SensorName"), Query.value("MessageQueueStatus.*"))), exp);
if (!ManagementFactory.getPlatformMBeanServer().queryMBeans(new ObjectName("ClusterStatus:*"), exp).isEmpty()) {
System.out.println(ManagementFactory.getPlatformMBeanServer().queryMBeans(new ObjectName("ClusterStatus:*"), exp));
}
Assert.assertTrue(ManagementFactory.getPlatformMBeanServer().queryMBeans(new ObjectName("ClusterStatus:*"), exp).isEmpty());
}
use of org.apache.helix.integration.manager.ClusterDistributedController 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