use of org.apache.helix.manager.zk.ZkClient in project helix by apache.
the class ZkUnitTestBase method beforeSuite.
@BeforeSuite(alwaysRun = true)
public void beforeSuite() throws Exception {
// Due to ZOOKEEPER-2693 fix, we need to specify whitelist for execute zk commends
System.setProperty("zookeeper.4lw.commands.whitelist", "*");
_zkServer = TestHelper.startZkServer(ZK_ADDR);
AssertJUnit.assertTrue(_zkServer != null);
ZKClientPool.reset();
// System.out.println("Number of open zkClient before ZkUnitTests: "
// + ZkClient.getNumberOfConnections());
_gZkClient = new ZkClient(ZK_ADDR);
_gZkClient.setZkSerializer(new ZNRecordSerializer());
}
use of org.apache.helix.manager.zk.ZkClient in project helix by apache.
the class TestExecutor method executeTestHelper.
private static Map<TestCommand, Boolean> executeTestHelper(List<TestCommand> commandList, String zkAddr, CountDownLatch countDown) {
final Map<TestCommand, Boolean> testResults = new ConcurrentHashMap<TestCommand, Boolean>();
ZkClient zkClient = null;
zkClient = new ZkClient(zkAddr, ZkClient.DEFAULT_CONNECTION_TIMEOUT);
zkClient.setZkSerializer(new ZNRecordSerializer());
// sort on trigger's start time, stable sort
Collections.sort(commandList, new Comparator<TestCommand>() {
@Override
public int compare(TestCommand o1, TestCommand o2) {
return (int) (o1._trigger._startTime - o2._trigger._startTime);
}
});
for (TestCommand command : commandList) {
testResults.put(command, new Boolean(false));
TestTrigger trigger = command._trigger;
command._startTimestamp = System.currentTimeMillis() + trigger._startTime;
new Thread(new ExecuteCommand(command._startTimestamp, command, countDown, zkClient, testResults)).start();
}
return testResults;
}
use of org.apache.helix.manager.zk.ZkClient in project helix by apache.
the class ZkCopy method main.
public static void main(String[] args) throws Exception {
CommandLineParser cliParser = new GnuParser();
Options cliOptions = constructCmdLineOpt();
CommandLine cmd = null;
try {
cmd = cliParser.parse(cliOptions, args);
} catch (ParseException pe) {
System.err.println("CommandLineClient: failed to parse command-line options: " + pe.toString());
printUsage(cliOptions);
System.exit(1);
}
URI srcUri = new URI(cmd.getOptionValue(src));
URI dstUri = new URI(cmd.getOptionValue(dst));
ZkCopyScheme srcScheme = ZkCopyScheme.valueOf(srcUri.getScheme());
ZkCopyScheme dstScheme = ZkCopyScheme.valueOf(dstUri.getScheme());
if (srcScheme == ZkCopyScheme.zk && dstScheme == ZkCopyScheme.zk) {
String srcZkAddr = srcUri.getAuthority();
String dstZkAddr = dstUri.getAuthority();
ZkClient srcClient = null;
ZkClient dstClient = null;
try {
if (srcZkAddr.equals(dstZkAddr)) {
srcClient = dstClient = new ZkClient(srcZkAddr, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ByteArraySerializer());
} else {
srcClient = new ZkClient(srcZkAddr, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ByteArraySerializer());
dstClient = new ZkClient(dstZkAddr, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ByteArraySerializer());
}
String srcPath = srcUri.getPath();
String dstPath = dstUri.getPath();
zkCopy(srcClient, srcPath, dstClient, dstPath);
} finally {
if (srcClient != null) {
srcClient.close();
}
if (dstClient != null) {
dstClient.close();
}
}
} else {
System.err.println("Unsupported scheme. srcScheme: " + srcScheme + ", dstScheme: " + dstScheme);
System.exit(1);
}
}
use of org.apache.helix.manager.zk.ZkClient in project helix by apache.
the class TestHelper method verifyState.
/**
* @param stateMap
* : "ResourceName/partitionKey" -> setOf(instances)
* @param state
* : MASTER|SLAVE|ERROR...
*/
public static void verifyState(String clusterName, String zkAddr, Map<String, Set<String>> stateMap, String state) {
ZkClient zkClient = new ZkClient(zkAddr);
zkClient.setZkSerializer(new ZNRecordSerializer());
try {
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(zkClient));
Builder keyBuilder = accessor.keyBuilder();
for (String resGroupPartitionKey : stateMap.keySet()) {
Map<String, String> retMap = getResourceAndPartitionKey(resGroupPartitionKey);
String resGroup = retMap.get("RESOURCE");
String partitionKey = retMap.get("PARTITION");
ExternalView extView = accessor.getProperty(keyBuilder.externalView(resGroup));
for (String instance : stateMap.get(resGroupPartitionKey)) {
String actualState = extView.getStateMap(partitionKey).get(instance);
Assert.assertNotNull(actualState, "externalView doesn't contain state for " + resGroup + "/" + partitionKey + " on " + instance + " (expect " + state + ")");
Assert.assertEquals(actualState, state, "externalView for " + resGroup + "/" + partitionKey + " on " + instance + " is " + actualState + " (expect " + state + ")");
}
}
} finally {
zkClient.close();
}
}
use of org.apache.helix.manager.zk.ZkClient in project helix by apache.
the class TestHelper method verifyEmptyCurStateAndExtView.
public static boolean verifyEmptyCurStateAndExtView(String clusterName, String resourceName, Set<String> instanceNames, String zkAddr) {
ZkClient zkClient = new ZkClient(zkAddr);
zkClient.setZkSerializer(new ZNRecordSerializer());
try {
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(zkClient));
Builder keyBuilder = accessor.keyBuilder();
for (String instanceName : instanceNames) {
List<String> sessionIds = accessor.getChildNames(keyBuilder.sessions(instanceName));
for (String sessionId : sessionIds) {
CurrentState curState = accessor.getProperty(keyBuilder.currentState(instanceName, sessionId, resourceName));
if (curState != null && curState.getRecord().getMapFields().size() != 0) {
return false;
}
}
ExternalView extView = accessor.getProperty(keyBuilder.externalView(resourceName));
if (extView != null && extView.getRecord().getMapFields().size() != 0) {
return false;
}
}
return true;
} finally {
zkClient.close();
}
}
Aggregations