use of org.apache.helix.tools.ClusterSetup in project helix by apache.
the class StateModelsResource method getStateModelsRepresentation.
StringRepresentation getStateModelsRepresentation() throws JsonGenerationException, JsonMappingException, IOException {
String clusterName = (String) getRequest().getAttributes().get("clusterName");
ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
ClusterSetup setupTool = new ClusterSetup(zkClient);
List<String> models = setupTool.getClusterManagementTool().getStateModelDefs(clusterName);
ZNRecord modelDefinitions = new ZNRecord("modelDefinitions");
modelDefinitions.setListField("models", models);
StringRepresentation representation = new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(modelDefinitions), MediaType.APPLICATION_JSON);
return representation;
}
use of org.apache.helix.tools.ClusterSetup 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.tools.ClusterSetup 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");
}
use of org.apache.helix.tools.ClusterSetup in project helix by apache.
the class TestSemiAutoStateTransition method beforeClass.
@BeforeClass
public void beforeClass() throws Exception {
_participants = new MockParticipantManager[_numNodes];
_numParitions = 1;
String namespace = "/" + CLUSTER_NAME;
if (_gZkClient.exists(namespace)) {
_gZkClient.deleteRecursively(namespace);
}
_setupTool = new ClusterSetup(ZK_ADDR);
_setupTool.addCluster(CLUSTER_NAME, true);
_accessor = new ZKHelixDataAccessor(CLUSTER_NAME, _baseAccessor);
_keyBuilder = _accessor.keyBuilder();
setupParticipants();
for (int i = 0; i < _numDbs; i++) {
String db = WorkflowGenerator.DEFAULT_TGT_DB + i;
_setupTool.addResourceToCluster(CLUSTER_NAME, db, _numParitions, MASTER_SLAVE_STATE_MODEL, IdealState.RebalanceMode.SEMI_AUTO.toString());
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, db, _numReplicas);
_testDbs.add(db);
}
startParticipants();
// start controller
String controllerName = CONTROLLER_PREFIX + "_0";
_controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
_controller.syncStart();
Thread.sleep(2000L);
createManagers();
}
Aggregations