public void deletereRcursive(CuratorFramework zk, String path) throws Exception { String npath = PathUtils.normalize_path(path); if (existsNode(zk, npath, false)) { zk.delete().guaranteed().deletingChildrenIfNeeded().forPath(npath); } }
private void deleteNode() throws Exception { String localNodePath = nodePath.getAndSet(null); if (localNodePath != null) { try { client.delete().guaranteed().forPath(localNodePath); } catch (KeeperException.NoNodeException ignore) { // ignore } } }
/** * 移除房间的red5临时子节点 * * @param nodename * @return */ public boolean removeRoomChildRed5Node(String roomname) { try { logger.debug(String.format("移除房间%s的子节点red5", roomname)); client.delete().forPath(ROOMNODE + "/" + roomname + RED5); return true; } catch (Exception e) { logger.error("ZooKeeperWrapper.deleteRed5ChildNode出现异常", e); return false; } }
@Override public void removeOffset( TopicName topicName, String subscriptionName, KafkaTopicName topic, int partition) throws Exception { String offsetPath = KafkaZookeeperPaths.partitionOffsetPath( kafkaNamesMapper.toConsumerGroupId(Subscription.getId(topicName, subscriptionName)), topic, partition); curatorFramework.delete().forPath(offsetPath); }
public boolean removeRoomProcessorChildNode() { try { logger.info("移除roomprocessor节点:" + this.RPchildnode); String path = ROOMPROCESSORNODE + "/" + this.RPchildnode; Stat stat = client.checkExists().forPath(path); if (stat != null) client.delete().forPath(path); return true; } catch (Exception e) { logger.error("移除roomprocessor节点:" + this.RPchildnode + "出错", e); return false; } }
/** * 移除房间的roomprocessor临时子节点,并从backup中移除节点信息 * * @param roomname * @return */ public boolean removeRoomChildRPNode(String roomname) { try { logger.debug(String.format("移除房间%s的子节点roomprocessor", roomname)); String path = ROOMNODE + "/" + roomname + ROOMPROCESSOR; backup.remove(path); Stat tmpRPStat = client.checkExists().forPath(path); if (tmpRPStat != null) client.delete().forPath(path); return true; } catch (Exception e) { logger.error(String.format("移除房间%s的子节点roomprocessor失败", roomname), e); return false; } }
/** * 创建roomprocessornode下的roomprocessor 临时节点,并赋值 将节点信息添加到backup * * @param nodename roomprocessor的ip+prot * @param value * @return */ private boolean createRoomProcessorChildNode(String nodename, String value) { logger.debug("创建roomprocessornode下的临时节点,节点名:" + nodename); try { String path = ROOMPROCESSORNODE + "/" + nodename; backup.put(path, value); Stat tmpRPChildStat = client.checkExists().forPath(path); if (tmpRPChildStat != null) client.delete().forPath(path); client.create().withMode(CreateMode.EPHEMERAL).forPath(path, value.getBytes(charset)); return true; } catch (Exception e) { logger.error("创建roomprocessornode下的临时节点失败", e); return false; } }
private void processBackgroundCallbackClosedState(CuratorEvent event) { String path = null; if (event.getResultCode() == KeeperException.Code.NODEEXISTS.intValue()) { path = event.getPath(); } else if (event.getResultCode() == KeeperException.Code.OK.intValue()) { path = event.getName(); } if (path != null) { try { client.delete().guaranteed().inBackground().forPath(path); } catch (Exception e) { log.error("Could not delete node after close", e); } } }
private static void deletePathsNotIn( CuratorFramework curator, List<String> paths, String target, boolean dryRun) throws Exception { List<String> zkPaths = curator.getChildren().forPath(target); for (String path : zkPaths) { path = "/" + path; if (!paths.contains(path)) { if (!dryRun) { curator.delete().guaranteed().forPath(path); ; } else { System.out.printf("Deleting path %s and everything under it\n", path); } } } }
private void internalUnregisterService(final Entry<T> entry) throws Exception { if (entry != null) { synchronized (entry) { if (entry.cache != null) { CloseableUtils.closeQuietly(entry.cache); entry.cache = null; } String path = pathForInstance(entry.service.getName(), entry.service.getId()); try { client.delete().guaranteed().forPath(path); } catch (KeeperException.NoNodeException ignore) { // ignore } } } }
public void delete(String yarnAppId) { String path = this.zkRoot + "/" + yarnAppId; try { lock.acquire(); if (curator.checkExists().forPath(path) != null) { curator.delete().forPath(path); LOG.info("delete yarn app {}, path {} ", yarnAppId, path); } } catch (Exception e) { LOG.error("failed to delete yarn app {}, path {} ", yarnAppId, path); } finally { try { lock.release(); } catch (Exception e) { LOG.error("fail releasing lock", e); } } }
private static void remove(CuratorFramework client, String command, String[] args) throws Exception { if (args.length != 1) { System.err.println("syntax error (expected remove <path>): " + command); return; } String name = args[0]; if (name.contains("/")) { System.err.println("Invalid node name" + name); return; } String path = ZKPaths.makePath(PATH, name); try { client.delete().forPath(path); } catch (KeeperException.NoNodeException e) { // ignore } }
@VisibleForTesting protected void internalRegisterService(ServiceInstance<T> service) throws Exception { byte[] bytes = serializer.serialize(service); String path = pathForInstance(service.getName(), service.getId()); final int MAX_TRIES = 2; boolean isDone = false; for (int i = 0; !isDone && (i < MAX_TRIES); ++i) { try { CreateMode mode = (service.getServiceType() == ServiceType.DYNAMIC) ? CreateMode.EPHEMERAL : CreateMode.PERSISTENT; client.create().creatingParentsIfNeeded().withMode(mode).forPath(path, bytes); isDone = true; } catch (KeeperException.NodeExistsException e) { client.delete().forPath(path); // must delete then re-create so that watchers fire } } }
public void delete(String yarnAppId, String jobId) { String path = this.zkRoot + "/" + yarnAppId + "/" + jobId; try { lock.acquire(); if (curator.checkExists().forPath(path) != null) { curator.delete().deletingChildrenIfNeeded().forPath(path); LOG.info("delete job {} for yarn app {}, path {} ", jobId, yarnAppId, path); String yarnPath = this.zkRoot + "/" + yarnAppId; if (curator.getChildren().forPath(yarnPath).size() == 0) { delete(yarnAppId); } } } catch (Exception e) { LOG.error("failed to delete job {} for yarn app {}, path {}, {}", jobId, yarnAppId, path, e); } finally { try { lock.release(); } catch (Exception e) { LOG.error("fail releasing lock", e); } } }
public static void detele(CuratorFramework client, String path) throws Exception { client.delete().forPath(path); }
public void deleteNode(CuratorFramework zk, String path) throws Exception { zk.delete().forPath(PathUtils.normalize_path(path)); }
public static void guaranteedDelete(CuratorFramework client, String path) throws Exception { // delete the given node and guarantee(保证) that it completes client.delete().guaranteed().forPath(path); }