/** * Fetches the {@link ResourceRequirement} for the given resource. * * @param resourceName Name of the resource. * @return A {@link ListenableFuture} that will be completed when the requirement is fetch. A {@code null} result * will be set into the future if no such requirement exists. The future will fail if failed to fetch * the requirement due to error other than requirement not exists. * Calling {@link ListenableFuture#cancel(boolean)} has no effect. */ public ListenableFuture<ResourceRequirement> fetchRequirement(String resourceName) { String zkPath = CoordinationConstants.REQUIREMENTS_PATH + "/" + resourceName; return Futures.transform( ZKOperations.ignoreError(zkClient.getData(zkPath), KeeperException.NoNodeException.class, null), NODE_DATA_TO_REQUIREMENT ); }
/** * Fetches the {@link ResourceRequirement} for the given resource. * * @param resourceName Name of the resource. * @return A {@link ListenableFuture} that will be completed when the requirement is fetch. A {@code null} result * will be set into the future if no such requirement exists. The future will fail if failed to fetch * the requirement due to error other than requirement not exists. * Calling {@link ListenableFuture#cancel(boolean)} has no effect. */ public ListenableFuture<ResourceRequirement> fetchRequirement(String resourceName) { String zkPath = CoordinationConstants.REQUIREMENTS_PATH + "/" + resourceName; return Futures.transform( ZKOperations.ignoreError(zkClient.getData(zkPath), KeeperException.NoNodeException.class, null), NODE_DATA_TO_REQUIREMENT ); }
/** * Deletes the {@link ResourceRequirement} for the given resource. * * @param resourceName Name of the resource. * @return A {@link ListenableFuture} that will be completed when the requirement is successfully removed. * If the requirement doesn't exists, the deletion would still be treated as successful. */ public ListenableFuture<String> deleteRequirement(String resourceName) { String zkPath = CoordinationConstants.REQUIREMENTS_PATH + "/" + resourceName; return Futures.transform( ZKOperations.ignoreError(zkClient.delete(zkPath), KeeperException.NoNodeException.class, resourceName), Functions.constant(resourceName) ); }
/** * Deletes the {@link ResourceRequirement} for the given resource. * * @param resourceName Name of the resource. * @return A {@link ListenableFuture} that will be completed when the requirement is successfully removed. * If the requirement doesn't exists, the deletion would still be treated as successful. */ public ListenableFuture<String> deleteRequirement(String resourceName) { String zkPath = CoordinationConstants.REQUIREMENTS_PATH + "/" + resourceName; return Futures.transform( ZKOperations.ignoreError(zkClient.delete(zkPath), KeeperException.NoNodeException.class, resourceName), Functions.constant(resourceName) ); }
private OperationFuture<String> removeLiveNode() { String liveNode = getLiveNodePath(); LOG.info("Remove live node {}{}", zkClient.getConnectString(), liveNode); return ZKOperations.ignoreError(zkClient.delete(liveNode), KeeperException.NoNodeException.class, liveNode); }
private OperationFuture<String> removeLiveNode() { String liveNode = getLiveNodePath(); LOG.info("Remove live node {}{}", zkClient.getConnectString(), liveNode); return ZKOperations.ignoreError(zkClient.delete(liveNode), KeeperException.NoNodeException.class, liveNode); }
ListenableFuture<?> asyncCancel() { if (!cancelled.compareAndSet(false, true)) { return Futures.immediateFuture(null); } // Take a snapshot of the volatile path. String path = this.path; // If it is null, meaning cancel is called before the ephemeral node is created, hence // setPath() will be called in future (through zk callback when creation is completed) // so that deletion will be done in setPath(). if (path == null) { return Futures.immediateFuture(null); } // Remove this Cancellable from the map so that upon session expiration won't try to register. lock.lock(); try { discoverables.remove(discoverable, this); } finally { lock.unlock(); } // Delete the path. It's ok if the path not exists // (e.g. what session expired and before node has been re-created) try { return ZKOperations.ignoreError(zkClient.delete(path), KeeperException.NoNodeException.class, path); } catch (Exception e) { return Futures.immediateFailedFuture(e); } } }
ListenableFuture<?> asyncCancel() { if (!cancelled.compareAndSet(false, true)) { return Futures.immediateFuture(null); } // Take a snapshot of the volatile path. String path = this.path; // If it is null, meaning cancel is called before the ephemeral node is created, hence // setPath() will be called in future (through zk callback when creation is completed) // so that deletion will be done in setPath(). if (path == null) { return Futures.immediateFuture(null); } // Remove this Cancellable from the map so that upon session expiration won't try to register. lock.lock(); try { discoverables.remove(discoverable, this); } finally { lock.unlock(); } // Delete the path. It's ok if the path not exists // (e.g. what session expired and before node has been re-created) try { return ZKOperations.ignoreError(zkClient.delete(path), KeeperException.NoNodeException.class, path); } catch (Exception e) { return Futures.immediateFailedFuture(e); } } }
@Override protected void startUp() throws Exception { LOG.info("Creating container ZK path: {}{}", zkClient.getConnectString(), path); ZKOperations.ignoreError(zkClient.create(path, null, CreateMode.PERSISTENT), KeeperException.NodeExistsException.class, null).get(TIMEOUT_SECONDS, TimeUnit.SECONDS); }
@Override protected void startUp() throws Exception { LOG.info("Creating container ZK path: {}{}", zkClient.getConnectString(), path); ZKOperations.ignoreError(zkClient.create(path, null, CreateMode.PERSISTENT), KeeperException.NodeExistsException.class, null).get(TIMEOUT_SECONDS, TimeUnit.SECONDS); }
public void init() throws InterruptedException { this.watcher = new ZKWatcher(); try { LOG.info("Initializing SharedResourceCache. Checking for parent znode {}", parentZnode); if (zookeeper.exists(parentZnode).get() == null) { // may be created in parallel by another instance // Also the child nodes are secure even without adding any ACLs to parent node. ZKOperations.ignoreError(zookeeper.create(parentZnode, null, CreateMode.PERSISTENT), KeeperException.NodeExistsException.class, null).get(); } } catch (ExecutionException ee) { // recheck if already created throw Throwables.propagate(ee.getCause()); } this.resources = reloadAll(); listeners.notifyUpdate(); }
LOG.info(String.format("Creating zookeeper namespace %s", path)); ZKOperations.ignoreError( client.create(path, null, CreateMode.PERSISTENT), KeeperException.NodeExistsException.class, path).get();
LOG.info(String.format("Creating zookeeper namespace %s", path)); ZKOperations.ignoreError( client.create(path, null, CreateMode.PERSISTENT), KeeperException.NodeExistsException.class, path).get();
@Override protected void doStart() throws Exception { LOG.info("Start application master with spec: {}", TwillRuntimeSpecificationAdapter.create().toJson(twillRuntimeSpec)); // initialize the event handler, if it fails, it will fail the application. eventHandler.initialize(new BasicEventHandlerContext(twillRuntimeSpec)); // call event handler started. eventHandler.started(); instanceChangeExecutor = Executors.newSingleThreadExecutor(Threads.createDaemonThreadFactory("instanceChanger")); // Creates ZK path for runnable. It's ok if the path already exists. // That's for the case when the AM get killed and restarted ZKOperations.ignoreError( zkClient.create("/" + runId.getId() + "/runnables", null, CreateMode.PERSISTENT), KeeperException.NodeExistsException.class, null) .get(); runningContainers.addWatcher(Constants.DISCOVERY_PATH_PREFIX); runnableContainerRequests = initContainerRequests(); }
ZKOperations.ignoreError(zkClient.create(getZKPath("messages"), null, CreateMode.PERSISTENT), KeeperException.NodeExistsException.class, null).get();
@Override protected void doStart() throws Exception { LOG.info("Start application master with spec: {}", TwillRuntimeSpecificationAdapter.create().toJson(twillRuntimeSpec)); // initialize the event handler, if it fails, it will fail the application. eventHandler.initialize(new BasicEventHandlerContext(twillRuntimeSpec)); // call event handler started. eventHandler.started(); instanceChangeExecutor = Executors.newSingleThreadExecutor(Threads.createDaemonThreadFactory("instanceChanger")); // Creates ZK path for runnable. It's ok if the path already exists. // That's for the case when the AM get killed and restarted ZKOperations.ignoreError( zkClient.create("/" + runId.getId() + "/runnables", null, CreateMode.PERSISTENT), KeeperException.NodeExistsException.class, null) .get(); runningContainers.addWatcher(Constants.DISCOVERY_PATH_PREFIX); runnableContainerRequests = initContainerRequests(); }
ZKOperations.ignoreError(zkClient.create(getZKPath("messages"), null, CreateMode.PERSISTENT), KeeperException.NodeExistsException.class, null).get();
@Override public void start() throws Exception { logAppenderInitializer.initialize(); resetShutdownTime(); createDirectory("twill"); createSystemHBaseNamespace(); updateConfigurationTable(); Services.startAndWait(zkClient, cConf.getLong(Constants.Zookeeper.CLIENT_STARTUP_TIMEOUT_MILLIS), TimeUnit.MILLISECONDS, String.format("Connection timed out while trying to start ZooKeeper client. Please " + "verify that the ZooKeeper quorum settings are correct in cdap-site.xml. " + "Currently configured as: %s", cConf.get(Constants.Zookeeper.QUORUM))); // Tries to create the ZK root node (which can be namespaced through the zk connection string) Futures.getUnchecked(ZKOperations.ignoreError(zkClient.create("/", null, CreateMode.PERSISTENT), KeeperException.NodeExistsException.class, null)); electionInfoService.startAndWait(); leaderElection.startAndWait(); }
ZKOperations.ignoreError(zkClientService.create("/", null, CreateMode.PERSISTENT), KeeperException.NodeExistsException.class, null).get();
ZKOperations.ignoreError(zkClientService.create("/", null, CreateMode.PERSISTENT), KeeperException.NodeExistsException.class, null).get();