use of org.apache.helix.manager.zk.ZKHelixDataAccessor in project helix by apache.
the class TestClusterSetup method testDisableResource.
@Test
public void testDisableResource() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
// participant port
TestHelper.setupCluster(// participant port
clusterName, // participant port
ZK_ADDR, // participant 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
true);
// disable "TestDB0" resource
ClusterSetup.processCommandLineArgs(new String[] { "--zkSvr", ZK_ADDR, "--enableResource", clusterName, "TestDB0", "false" });
BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseAccessor);
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
IdealState idealState = accessor.getProperty(keyBuilder.idealStates("TestDB0"));
Assert.assertFalse(idealState.isEnabled());
// enable "TestDB0" resource
ClusterSetup.processCommandLineArgs(new String[] { "--zkSvr", ZK_ADDR, "--enableResource", clusterName, "TestDB0", "true" });
idealState = accessor.getProperty(keyBuilder.idealStates("TestDB0"));
Assert.assertTrue(idealState.isEnabled());
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 TestHelixAdminCli method testInstanceGroupTags.
@Test
public void testInstanceGroupTags() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseAccessor);
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
String command = "-zkSvr " + ZK_ADDR + " -addCluster " + clusterName;
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
command = "-zkSvr localhost:2183 -addResource " + clusterName + " db_11 12 MasterSlave";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
for (int i = 0; i < 6; i++) {
command = "-zkSvr " + ZK_ADDR + " -addNode " + clusterName + " localhost:123" + i;
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
}
for (int i = 0; i < 2; i++) {
command = "-zkSvr " + ZK_ADDR + " -addInstanceTag " + clusterName + " localhost_123" + i + " tag1";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
}
for (int i = 2; i < 6; i++) {
command = "-zkSvr " + ZK_ADDR + " -addInstanceTag " + clusterName + " localhost_123" + i + " tag2";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
}
command = "-zkSvr " + ZK_ADDR + " -rebalance " + clusterName + " db_11 2 -instanceGroupTag tag1";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
IdealState dbIs = accessor.getProperty(accessor.keyBuilder().idealStates("db_11"));
Set<String> hosts = new HashSet<String>();
for (String p : dbIs.getPartitionSet()) {
for (String hostName : dbIs.getInstanceStateMap(p).keySet()) {
InstanceConfig config = accessor.getProperty(accessor.keyBuilder().instanceConfig(hostName));
Assert.assertTrue(config.containsTag("tag1"));
hosts.add(hostName);
}
}
Assert.assertEquals(hosts.size(), 2);
command = "-zkSvr " + ZK_ADDR + " -dropResource " + clusterName + " db_11 ";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
// re-add and rebalance
command = "-zkSvr " + ZK_ADDR + " -addResource " + clusterName + " db_11 48 MasterSlave";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
command = "-zkSvr " + ZK_ADDR + " -rebalance " + clusterName + " db_11 3 -instanceGroupTag tag2";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
dbIs = accessor.getProperty(accessor.keyBuilder().idealStates("db_11"));
hosts = new HashSet<String>();
for (String p : dbIs.getPartitionSet()) {
for (String hostName : dbIs.getInstanceStateMap(p).keySet()) {
InstanceConfig config = accessor.getProperty(accessor.keyBuilder().instanceConfig(hostName));
Assert.assertTrue(config.containsTag("tag2"));
hosts.add(hostName);
}
}
Assert.assertEquals(hosts.size(), 4);
command = "-zkSvr " + ZK_ADDR + " -dropResource " + clusterName + " db_11 ";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
for (int i = 3; i <= 3; i++) {
command = "-zkSvr " + ZK_ADDR + " -removeInstanceTag " + clusterName + " localhost_123" + i + " tag2";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
}
// re-add and rebalance
command = "-zkSvr " + ZK_ADDR + " -addResource " + clusterName + " db_11 48 MasterSlave";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
command = "-zkSvr " + ZK_ADDR + " -rebalance " + clusterName + " db_11 3 -instanceGroupTag tag2";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
dbIs = accessor.getProperty(accessor.keyBuilder().idealStates("db_11"));
hosts = new HashSet<String>();
for (String p : dbIs.getPartitionSet()) {
for (String hostName : dbIs.getInstanceStateMap(p).keySet()) {
InstanceConfig config = accessor.getProperty(accessor.keyBuilder().instanceConfig(hostName));
Assert.assertTrue(config.containsTag("tag2"));
hosts.add(hostName);
}
}
Assert.assertEquals(hosts.size(), 3);
// rebalance with key prefix
command = "-zkSvr " + ZK_ADDR + " -rebalance " + clusterName + " db_11 2 -key alias";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
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 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.manager.zk.ZKHelixDataAccessor in project helix by apache.
the class TestDisableResource method test.
@Test
public void test() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
final int n = 5;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
// participant port
TestHelper.setupCluster(// participant port
clusterName, // participant port
ZK_ADDR, // participant port
12918, // participant name prefix
"localhost", // resource name prefix
"TestDB", // resources
1, // partitions per resource
10, // number of nodes
n, // replicas
3, "MasterSlave", // do rebalance
true);
String instanceUrl = "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/resourceGroups/" + "TestDB0";
// Disable TestDB0
Map<String, String> paramMap = new HashMap<String, String>();
paramMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.enableResource);
paramMap.put(JsonParameters.ENABLED, Boolean.toString(false));
TestHelixAdminScenariosRest.assertSuccessPostOperation(instanceUrl, paramMap, false);
BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseAccessor);
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
IdealState idealState = accessor.getProperty(keyBuilder.idealStates("TestDB0"));
Assert.assertFalse(idealState.isEnabled());
// Re-enable TestDB0
paramMap.put(JsonParameters.ENABLED, Boolean.toString(true));
TestHelixAdminScenariosRest.assertSuccessPostOperation(instanceUrl, paramMap, false);
idealState = accessor.getProperty(keyBuilder.idealStates("TestDB0"));
Assert.assertTrue(idealState.isEnabled());
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 ClusterRepresentationUtil method getInstancePropertiesAsString.
public static String getInstancePropertiesAsString(ZkClient zkClient, String clusterName, PropertyKey propertyKey, MediaType mediaType) throws JsonGenerationException, JsonMappingException, IOException {
zkClient.setZkSerializer(new ZNRecordSerializer());
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(zkClient));
List<ZNRecord> records = HelixProperty.convertToList(accessor.getChildValues(propertyKey));
return ObjectToJson(records);
}
Aggregations