@Override public OperationFuture<String> create(String path, @Nullable byte[] data, CreateMode createMode, boolean createParent, Iterable<ACL> acl) { return delegate.create(path, data, createMode, createParent, acl); }
@Override public OperationFuture<String> create(String path, @Nullable byte[] data, CreateMode createMode, boolean createParent, Iterable<ACL> acl) { return delegate.create(path, data, createMode, createParent, acl); }
public OperationFuture<String> create(String path, @Nullable byte[] data, CreateMode createMode, boolean createParent, Iterable<ACL> acl) { return client.create(path, data, createMode, createParent, acl); }
public OperationFuture<String> create(String path, @Nullable byte[] data, CreateMode createMode, boolean createParent, Iterable<ACL> acl) { return client.create(path, data, createMode, createParent, acl); }
/** * Private helper method to create a ZK node based on the parameter. The result of the creation is always * communicate via the provided {@link FutureCallback}. */ private static void createNode(ZKClient zkClient, String path, @Nullable byte[] data, CreateMode createMode, boolean createParent, Iterable<ACL> acls, FutureCallback<String> callback) { Futures.addCallback(zkClient.create(path, data, createMode, createParent, acls), callback, Threads.SAME_THREAD_EXECUTOR); }
/** * Private helper method to create a ZK node based on the parameter. The result of the creation is always * communicate via the provided {@link FutureCallback}. */ private static void createNode(ZKClient zkClient, String path, @Nullable byte[] data, CreateMode createMode, boolean createParent, Iterable<ACL> acls, FutureCallback<String> callback) { Futures.addCallback(zkClient.create(path, data, createMode, createParent, acls), callback, Threads.SAME_THREAD_EXECUTOR); }
/** * Acts as {@link ZKClient#create(String, byte[], org.apache.zookeeper.CreateMode, boolean) * create(path, null, CreateMode.PERSISTENT, true)} if node doesn't exist. Otherwise has no affect. * In latter case sets {@code null} in returned future. */ public static ListenableFuture<String> ensureExists(final ZKClient zkClient, final String path) { final SettableFuture<String> resultFuture = SettableFuture.create(); OperationFuture<String> createFuture = zkClient.create(path, null, CreateMode.PERSISTENT, true); Futures.addCallback(createFuture, new FutureCallback<String>() { @Override public void onSuccess(String result) { resultFuture.set(result); } @Override public void onFailure(Throwable t) { if (causedBy(t, KeeperException.NodeExistsException.class)) { resultFuture.set(path); } else { resultFuture.setException(t); } } }); return resultFuture; }
private void register() { state = State.IN_PROGRESS; zkNodePath = null; // Register for election final String path = String.format("%s/%s-", zkFolderPath, guid); LOG.debug("Registering for election {} with path {}", zkFolderPath, path); OperationFuture<String> createFuture = zkClient.create(path, getNodeData(), CreateMode.EPHEMERAL_SEQUENTIAL, true); Futures.addCallback(createFuture, new FutureCallback<String>() { @Override public void onSuccess(String result) { LOG.debug("Created zk node {}", result); zkNodePath = result; if (state == State.CANCELLED) { // If cancel was called after create(), but before callback trigger, delete the node created. deleteNode(); } else { runElection(); } } @Override public void onFailure(Throwable t) { LOG.error("Got exception during node creation for folder {}", path, t); // The node may created successfully on server and then server crash, // which client might receive failure instead. // Not checking for cancel here, as we don't know the zkNodePath. // Needs to rely on runElection to handle cancel. runElection(); } }, executor); }
public T put(String key, T value) { Map<String, T> current = Maps.newHashMap(currentView.get()); T result = current.put(key, value); currentView.set(ImmutableMap.<String, T>builder().putAll(current).build()); // Note: we do delete and add new node with new data VS createOrSet() to avoid attaching watchers to every node String itemNodePath = getItemNodePath(key); Futures.getUnchecked(ZKClientExt.delete(zkClient, itemNodePath, true)); Futures.getUnchecked(zkClient.create(itemNodePath, serializer.serialize(value), CreateMode.PERSISTENT)); return result; }
private OperationFuture<String> doRegister(Discoverable discoverable) { byte[] discoverableBytes = DiscoverableAdapter.encode(discoverable); return zkClient.create(getNodePath(discoverable), discoverableBytes, CreateMode.EPHEMERAL, true); }
private OperationFuture<String> doRegister(Discoverable discoverable) { byte[] discoverableBytes = DiscoverableAdapter.encode(discoverable); return zkClient.create(getNodePath(discoverable), discoverableBytes, CreateMode.EPHEMERAL, true); }
@Override public OperationFuture<String> create(String path, @Nullable byte[] data, CreateMode createMode, boolean createParent, Iterable<ACL> acl) { return relayPath(delegate.create(getNamespacedPath(path), data, createMode, createParent, acl), this.<String>createFuture(path)); }
private T putInternal(String key, T value) { Map<String, T> current = Maps.newHashMap(currentView); T result = current.put(key, value); currentView = ImmutableMap.<String, T>builder().putAll(current).build(); String itemNodePath = getItemNodePath(key); // Note: we do delete and add new node with new data VS createOrSet() so that cversion of children change (we depend // on it when checking if the current in-memory view is stale) Futures.getUnchecked(ZKClientExt.delete(zkClient, itemNodePath, true)); Futures.getUnchecked(zkClient.create(itemNodePath, serializer.serialize(value), CreateMode.PERSISTENT, true)); return result; }
@Override public OperationFuture<String> create(String path, @Nullable byte[] data, CreateMode createMode, boolean createParent, Iterable<ACL> acl) { return relayPath(delegate.create(getNamespacedPath(path), data, createMode, createParent, acl), this.<String>createFuture(path)); }
@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(); }
private void initializeCounter(Type type) { Stat stat = Futures.getUnchecked(zkClient.exists(type.path)); if (stat == null) { Futures.getUnchecked(zkClient.create(type.path, Longs.toByteArray(startId), CreateMode.PERSISTENT, true)); } } }
@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(); }
@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(); }