private void checkRedundantNode(String node) { try { // Nothing to do if it is a lock mode if (getLockMode(node) != null) { return; } List<String> children = curatorFramework.getChildren().forPath(node); for (String child : children) { checkRedundantNode(node + "/" + child); } children = curatorFramework.getChildren().forPath(node); if ((children == null) || (children.isEmpty())) { curatorFramework.delete().forPath(node); } } catch (Exception e) { LOG.warn("Error in checkRedundantNode for node " + node, e); } }
@Override public void persistEphemeral(final String key, final String value) { try { if (isExisted(key)) { client.delete().deletingChildrenIfNeeded().forPath(key); } client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).forPath(key, value.getBytes(Charsets.UTF_8)); // CHECKSTYLE:OFF } catch (final Exception ex) { // CHECKSTYLE:ON CuratorZookeeperExceptionHandler.handleException(ex); } }
@Override protected void removeStoredMasterKey(DelegationKey key) { String nodeRemovePath = getNodePath(ZK_DTSM_MASTER_KEY_ROOT, DELEGATION_KEY_PREFIX + key.getKeyId()); if (LOG.isDebugEnabled()) { LOG.debug("Removing ZKDTSMDelegationKey_" + key.getKeyId()); } try { if (zkClient.checkExists().forPath(nodeRemovePath) != null) { while(zkClient.checkExists().forPath(nodeRemovePath) != null){ try { zkClient.delete().guaranteed().forPath(nodeRemovePath); } catch (NoNodeException nne) { // It is possible that the node might be deleted between the // check and the actual delete.. which might lead to an // exception that can bring down the daemon running this // SecretManager LOG.debug("Node already deleted by peer " + nodeRemovePath); } } } else { LOG.debug("Attempted to delete a non-existing znode " + nodeRemovePath); } } catch (Exception e) { LOG.debug(nodeRemovePath + " znode could not be removed!!"); } }
@Override public void applyMigration() { final long start = System.currentTimeMillis(); try { if (curator.checkExists().forPath(PENDING_TASKS_ROOT) == null) { return; } } catch (Exception e) { throw Throwables.propagate(e); } try { for (String pendingTaskId : curator.getChildren().forPath(PENDING_TASKS_ROOT)) { SingularityPendingTaskId newPendingTaskId = createFrom(pendingTaskId, start); if (!newPendingTaskId.toString().equals(pendingTaskId)) { LOG.info("Migrating {} to {}", pendingTaskId, newPendingTaskId); Optional<String> cmdLineArgs = getCmdLineArgs(pendingTaskId); taskManager.savePendingTask( new SingularityPendingTaskBuilder() .setPendingTaskId(newPendingTaskId) .setCmdLineArgsList(cmdLineArgs.isPresent() ? Optional.of(Collections.singletonList(cmdLineArgs.get())) : Optional.<List<String>> absent()) .build()); curator.delete().forPath(ZKPaths.makePath(PENDING_TASKS_ROOT, pendingTaskId)); } } } catch (Exception e) { throw Throwables.propagate(e); } }
private void createZNodeJsonReplyForPath(StratioStreamingMessage request, Object reply, String path) throws Exception { if (client.checkExists().forPath(path) != null) { client.delete().deletingChildrenIfNeeded().forPath(path); } client.create().creatingParentsIfNeeded().forPath(path, new Gson().toJson(reply).getBytes()); }
@Override public void takeLeadership(CuratorFramework client) throws Exception { setState(State.PRIMARY); if (client.checkExists().forPath(mLeaderFolder + mName) != null) { LOG.info("Deleting zk path: {}{}", mLeaderFolder, mName); client.delete().forPath(mLeaderFolder + mName); } LOG.info("Creating zk path: {}{}", mLeaderFolder, mName); client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL) .forPath(mLeaderFolder + mName); LOG.info("{} is now the leader.", mName); try { waitForState(State.SECONDARY); } finally { LOG.warn("{} relinquishing leadership.", mName); LOG.info("The current leader is {}", mLeaderSelector.getLeader().getId()); LOG.info("All participants: {}", mLeaderSelector.getParticipants()); client.delete().forPath(mLeaderFolder + mName); } }
CuratorFrameworkFactory.builder().connectString(zooKeeperEnsemble) .retryPolicy(new ExponentialBackoffRetry(baseSleepTime, maxRetries)).build(); zooKeeperClient.start(); List<String> znodePaths = zooKeeperClient.getChildren().forPath( ZooKeeperHiveHelper.ZOOKEEPER_PATH_SEPARATOR + rootNamespace); List<String> znodePathsUpdated; LOG.warn("Will attempt to remove the znode: " + fullZnodePath + " from ZooKeeper"); System.out.println("Will attempt to remove the znode: " + fullZnodePath + " from ZooKeeper"); zooKeeperClient.delete().guaranteed().inBackground(new DeleteCallBack()) .forPath(fullZnodePath); zooKeeperClient.getChildren().forPath( ZooKeeperHiveHelper.ZOOKEEPER_PATH_SEPARATOR + rootNamespace);
); curator.start(); curator.blockUntilConnected(); curator.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).forPath("/container/billy", new byte[]{}); curator.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).forPath("/inventory/billy/1", Ints.toByteArray(100)); curator.create().withMode(CreateMode.EPHEMERAL).forPath("/inventory/billy/bob", Ints.toByteArray(2287)); curator.delete().forPath("/inventory/billy/1");
protected void assignNewProcessNode(String appId, Watcher processNodeWatcher ) { String taskHolderZnodePath = ZNODE_ROOT+ZNODE_UNSTICK_TASKS+"/"+appId; try { if(curatorFramework.checkExists().forPath(taskHolderZnodePath) != null) { curatorFramework.delete().deletingChildrenIfNeeded().forPath(taskHolderZnodePath); } curatorFramework.create().forPath(taskHolderZnodePath); //setup the watcher curatorFramework.getChildren().usingWatcher(processNodeWatcher).inBackground().forPath(taskHolderZnodePath); log.info("Done creating task holder and watcher for APP name: {}",appId); } catch (Exception e) { log.error("Could not add new processing node for name {}", appId, e); } }
public void deleteData(String path) throws Exception { if (zookeeperClient.checkExists().forPath(path) != null) { zookeeperClient.delete().deletingChildrenIfNeeded().forPath(path); } }
List<String> workers; try { workers = cf.getChildren().forPath(indexerZkConfig.getStatusPath()); taskIds = cf.getChildren().forPath(workerStatusPath); String taskStatusPath = JOINER.join(workerStatusPath, taskId); try { cf.delete().guaranteed().forPath(taskStatusPath);
@Override public void remove(final String key) { try { client.delete().deletingChildrenIfNeeded().forPath(key); //CHECKSTYLE:OFF } catch (final Exception ex) { //CHECKSTYLE:ON RegExceptionHandler.handleException(ex); } }
if (configClient.checkExists().forPath(directory) == null) { return; meta.setHost(address); configClient.delete().inBackground(new BackgroundCallback() {
private void releaseLock() { try { if (zkClient.getState().equals(CuratorFrameworkState.STARTED)) { // client.setData().forPath(ZOOKEEPER_LOCK_PATH, null); if (zkClient.checkExists().forPath(schedulerId()) != null) { zkClient.delete().guaranteed().deletingChildrenIfNeeded().forPath(schedulerId()); } } } catch (Exception e) { logger.error("error release lock:" + schedulerId()); throw new RuntimeException(e); } }
public void removeTaskRunZnode(String taskId) throws Exception { try { curatorFramework.delete().guaranteed().forPath(getTaskPathForId(taskId)); } catch (KeeperException e) { log.debug( e, "Could not delete task path for task[%s]. This is not an error if httpRemote taskRunner is being used at overlord.", taskId ); } }
@Test public void testWorkerRemoved() throws Exception { doSetup(); Future<TaskStatus> future = remoteTaskRunner.run(task); Assert.assertTrue(taskAnnounced(task.getId())); mockWorkerRunningTask(task); Assert.assertTrue(workerRunningTask(task.getId())); cf.delete().forPath(announcementsPath); TaskStatus status = future.get(); Assert.assertEquals(TaskState.FAILED, status.getStatusCode()); RemoteTaskRunnerConfig config = remoteTaskRunner.getRemoteTaskRunnerConfig(); Assert.assertTrue( TestUtils.conditionValid( new IndexingServiceCondition() { @Override public boolean isValid() { return remoteTaskRunner.getRemovedWorkerCleanups().isEmpty(); } }, // cleanup task is independently scheduled by event listener. we need to wait some more time. config.getTaskCleanupTimeout().toStandardDuration().getMillis() * 2 ) ); Assert.assertNull(cf.checkExists().forPath(statusPath)); }
private void remvBusinessStageRollbackFlag(TransactionXid transactionXid) { String global = ByteUtils.byteArrayToString(transactionXid.getGlobalTransactionId()); String parent = String.format("%s/%s/rollback", CONSTANTS_ROOT_PATH, CommonUtils.getApplication(this.endpoint)); String target = String.format("%s/%s", parent, global); try { this.curatorFramework.delete().inBackground(this).forPath(target); } catch (Exception error) { logger.warn("Error occurred while deleting zookeeper path({}).", target); } }
@Override public void purgeLocks(String lockPathRoot) { lockPathRoot = norm(lockPathRoot); try { curator.delete().guaranteed().deletingChildrenIfNeeded().forPath(lockPathRoot); logger.info("{} purged all locks under {}", client, lockPathRoot); } catch (Exception ex) { throw new IllegalStateException("Error while " + client + " trying to purge " + lockPathRoot, ex); } }