Refine search
@Override public void close() throws IOException { LOG.info("Closing"); listeners.clear(); if (controlCache != null) { controlCache.close(); } if (nodePath != null) { try { zkClient.delete().forPath(nodePath); LOG.debug("Node with path {} successfully deleted", nodePath); } catch (Exception ex) { LOG.debug("Failed to delete node", ex); } } }
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 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); } }
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); } }
@Test public void testMaster() throws Exception { startDefaultMaster("--zk-cluster-id=" + zkClusterId); final HeliosClient client = defaultClient(); // This should succeed since the cluster ID was created by SystemTestBase client.jobs().get(); // Delete the cluster ID zk().curatorWithSuperAuth().delete().forPath(Paths.configId(zkClusterId)); // Call jobs again, and this time it should throw an exception because the cluster ID is gone try { client.jobs().get(); } catch (ExecutionException e) { assertThat(e.getMessage(), containsString("500")); } }
void mockWorkerRunningTask(final String workerId, final Task task) throws Exception { cf.delete().forPath(joiner.join(tasksPath, workerId, task.getId())); final String taskStatusPath = joiner.join(statusPath, workerId, task.getId()); TaskAnnouncement taskAnnouncement = TaskAnnouncement.create(task, TaskStatus.running(task.getId()), DUMMY_LOCATION); cf.create() .creatingParentsIfNeeded() .forPath(taskStatusPath, jsonMapper.writeValueAsBytes(taskAnnouncement)); Preconditions.checkNotNull( cf.checkExists().forPath(taskStatusPath), "Failed to write status on [%s]", taskStatusPath ); }
private void recursivelyDelete(String path) throws Exception { List<String> children = context.getExhibitor().getLocalConnection().getChildren().forPath(path); for ( String name : children ) { recursivelyDelete(ZKPaths.makePath(path, name)); } context.getExhibitor().getLocalConnection().delete().forPath(path); context.getExhibitor().getLog().add(ActivityLog.Type.INFO, String.format("deleteNode() deleted node [%s]", path)); }