public Map<JobId, Job> getJobs() { log.debug("getting jobs"); final String folder = Paths.configJobs(); final ZooKeeperClient client = provider.get("getJobs"); try {
@Test public void testZooKeeperClient() throws Exception { // Create the cluster ID node zk().curatorWithSuperAuth().newNamespaceAwareEnsurePath(Paths.configId(zkClusterId)) .ensure(zk().curatorWithSuperAuth().getZookeeperClient()); // We need to create a new curator because ZooKeeperClient will try to start it, // and zk().curator() has already been started. final ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(1000, 3); final CuratorFramework curator = CuratorFrameworkFactory.builder() .retryPolicy(retryPolicy) .connectString(zk().connectString()) .build(); final ZooKeeperClient client = new DefaultZooKeeperClient(curator, zkClusterId); client.start(); // This should work since the cluster ID exists client.create("/test"); // Now let's remove the cluster ID client.delete(Paths.configId(zkClusterId)); // Sleep so the watcher thread in ZooKeeperClient has a chance to update state Thread.sleep(500); // Try the same operation again, and it should fail this time try { client.ensurePath(Paths.configJobs()); fail("ZooKeeper operation should have failed because cluster ID was removed"); } catch (IllegalStateException ignore) { // ignored } }
set(Paths.configJobs(), UUID.randomUUID().toString().getBytes())); client.transaction(operations.build()); } catch (final NoNodeException e) {
curator.newNamespaceAwareEnsurePath(Paths.configJobs()).ensure(curator.getZookeeperClient()); curator.newNamespaceAwareEnsurePath(Paths.configJobRefs()).ensure(curator.getZookeeperClient()); curator.newNamespaceAwareEnsurePath(Paths.statusHosts()).ensure(curator.getZookeeperClient());
set(Paths.configJobs(), UUID.randomUUID().toString().getBytes())); } catch (final NodeExistsException e) { if (client.exists(creationPath) != null) {
@Override public boolean tryToRegister(final ZooKeeperClient client) throws KeeperException { client.ensurePath(Paths.configHosts()); client.ensurePath(Paths.configJobs()); client.ensurePath(Paths.configJobRefs()); client.ensurePath(Paths.statusHosts()); client.ensurePath(Paths.statusMasters()); client.ensurePath(Paths.historyJobs()); client.ensurePath(Paths.configDeploymentGroups()); client.ensurePath(Paths.statusDeploymentGroups()); if (upNode == null) { final String upPath = Paths.statusMasterUp(name); client.ensurePath(upPath, true); upNode = client.persistentEphemeralNode(upPath, Mode.EPHEMERAL, new byte[]{}); upNode.start(); } log.info("ZooKeeper registration complete"); return true; } }
public Map<JobId, Job> getJobs() { log.debug("getting jobs"); final String folder = Paths.configJobs(); final ZooKeeperClient client = provider.get("getJobs"); try {
set(Paths.configJobs(), UUID.randomUUID().toString().getBytes())); client.transaction(operations.build()); } catch (final NoNodeException e) {
set(Paths.configJobs(), UUID.randomUUID().toString().getBytes())); } catch (final NodeExistsException e) { if (client.exists(creationPath) != null) {
@Override public void tryToRegister(final ZooKeeperClient client) throws KeeperException { client.ensurePath(Paths.configHosts()); client.ensurePath(Paths.configJobs()); client.ensurePath(Paths.configJobRefs()); client.ensurePath(Paths.statusHosts()); client.ensurePath(Paths.statusMasters()); client.ensurePath(Paths.historyJobs()); client.ensurePath(Paths.configDeploymentGroups()); client.ensurePath(Paths.statusDeploymentGroups()); if (upNode == null) { final String upPath = Paths.statusMasterUp(name); upNode = client.persistentEphemeralNode(upPath, Mode.EPHEMERAL, new byte[]{}); upNode.start(); } log.info("ZooKeeper registration complete"); } }