org.apache.curator.utils.ZKPaths Java Examples
The following examples show how to use
org.apache.curator.utils.ZKPaths.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NodeService.java From config-toolkit with Apache License 2.0 | 6 votes |
@Override public List<PropertyItem> findProperties(String node) { LOGGER.debug("Find properties in node: [{}]", node); List<PropertyItem> properties = Lists.newArrayList(); try { Stat stat = client.checkExists().forPath(node); if (stat != null) { GetChildrenBuilder childrenBuilder = client.getChildren(); List<String> children = childrenBuilder.forPath(node); GetDataBuilder dataBuilder = client.getData(); if (children != null) { for (String child : children) { String propPath = ZKPaths.makePath(node, child); PropertyItem item = new PropertyItem(child, new String(dataBuilder.forPath(propPath), Charsets.UTF_8)); properties.add(item); } } } } catch (Exception e) { LOGGER.error(e.getMessage(), e); } return properties; }
Example #2
Source File: ZookeeperStreamMetadataStore.java From kylin-on-parquet-v2 with Apache License 2.0 | 6 votes |
@Override public ReplicaSet getReplicaSet(int rsID) { try { ReplicaSet result = new ReplicaSet(); result.setReplicaSetID(rsID); byte[] replicaSetData = client.getData().forPath(ZKPaths.makePath(replicaSetRoot, String.valueOf(rsID))); if (replicaSetData != null && replicaSetData.length > 0) { result = JsonUtil.readValue(Bytes.toString(replicaSetData), ReplicaSet.class); } readSuccess.getAndIncrement(); return result; } catch (Exception e) { readFail.getAndIncrement(); logger.error("Error when get replica set " + rsID, e); throw new StoreException(e); } }
Example #3
Source File: ZookeeperStreamMetadataStore.java From kylin-on-parquet-v2 with Apache License 2.0 | 6 votes |
@Override public void addCompleteReplicaSetForSegmentBuild(String cubeName, String segmentName, int rsID) { logger.trace("Add completed rs {} to {} {}", rsID, cubeName, segmentName); checkPath(cubeName, segmentName); try { String path = ZKPaths.makePath(cubeRoot, cubeName, CUBE_BUILD_STATE, segmentName, "replica_sets", String.valueOf(rsID)); if (client.checkExists().forPath(path) == null) { client.create().creatingParentsIfNeeded().forPath(path); } else { logger.warn("ReplicaSet id {} existed under path {}", rsID, path); } writeSuccess.getAndIncrement(); } catch (Exception e) { writeFail.getAndIncrement(); logger.error("Fail to add replicaSet Id to segment build state for " + segmentName + " " + rsID, e); throw new StoreException(e); } }
Example #4
Source File: PatchStoreZk.java From rdf-delta with Apache License 2.0 | 6 votes |
private List<DataSourceDescription> listDataSourcesZkPath_alt(String logsPath) { List<String> logNames = Zk.zkSubNodes(client, logsPath); Stream<DataSourceDescription> descriptions = logNames.stream() .map(name->{ FmtLog.info(LOGZK, "[%d] listDataSources: %s", instance, name); String logDsd = ZKPaths.makePath(ZkConst.pLogs, name, ZkConst.nDsd); JsonObject obj = zkFetchJson(client, logDsd); if ( obj == null ) { FmtLog.info(LOGZK, "[%d] listDataSourcesZkPath: %s: no DSD", instance, name); return null; } DataSourceDescription dsd = DataSourceDescription.fromJson(obj); return dsd; }) .filter(Objects::nonNull) ; return ListUtils.toList(descriptions); }
Example #5
Source File: ZookeeperClusterDataManager.java From pinpoint with Apache License 2.0 | 6 votes |
@Override public boolean registerWebCluster(String zNodeName, byte[] contents) { String zNodeFullPath = ZKPaths.makePath(ZookeeperConstants.PINPOINT_WEB_CLUSTER_PATH, zNodeName); logger.info("registerWebCluster() started. create UniqPath={}.", zNodeFullPath); CreateNodeMessage createNodeMessage = new CreateNodeMessage(zNodeFullPath, contents); PushWebClusterJob job = new PushWebClusterJob(createNodeMessage, retryInterval); if (!this.job.compareAndSet(null, job)) { logger.warn("Already Register Web Cluster Node."); return false; } // successful even for scheduler registration completion if (!isConnected()) { logger.info("Zookeeper is Disconnected."); return true; } if (!clusterDataManagerHelper.pushZnode(client, job.getCreateNodeMessage())) { timer.newTimeout(job, job.getRetryInterval(), TimeUnit.MILLISECONDS); } return true; }
Example #6
Source File: TaskManager.java From Singularity with Apache License 2.0 | 6 votes |
public void clearStartupHealthchecks(SingularityTaskId taskId) { Optional<SingularityTaskHealthcheckResult> maybeLastHealthcheck = getLastHealthcheck( taskId ); String parentPath = getHealthcheckParentPath(taskId); for (String healthcheckPath : getChildren(parentPath)) { String fullPath = ZKPaths.makePath(parentPath, healthcheckPath); if ( healthcheckPath.endsWith(STARTUP_HEALTHCHECK_PATH_SUFFIX) && ( !maybeLastHealthcheck.isPresent() || !getHealthcheckPath(maybeLastHealthcheck.get()).equals(fullPath) ) ) { delete(fullPath); } } }
Example #7
Source File: ZKSegmentContainerMonitor.java From pravega with Apache License 2.0 | 6 votes |
/** * Creates an instance of ZKSegmentContainerMonitor. * * @param containerRegistry The registry used to control the container state. * @param zkClient The curator client. * @param pravegaServiceEndpoint The pravega endpoint for which we need to fetch the container assignment. */ ZKSegmentContainerMonitor(SegmentContainerRegistry containerRegistry, CuratorFramework zkClient, Host pravegaServiceEndpoint, int parallelContainerStarts, ScheduledExecutorService executor) { Preconditions.checkNotNull(zkClient, "zkClient"); Preconditions.checkArgument(parallelContainerStarts > 0, "parallelContainerStarts"); this.registry = Preconditions.checkNotNull(containerRegistry, "containerRegistry"); this.host = Preconditions.checkNotNull(pravegaServiceEndpoint, "pravegaServiceEndpoint"); this.executor = Preconditions.checkNotNull(executor, "executor"); this.handles = new ConcurrentHashMap<>(); this.pendingTasks = new ConcurrentSkipListSet<>(); String clusterPath = ZKPaths.makePath("cluster", "segmentContainerHostMapping"); this.hostContainerMapNode = new NodeCache(zkClient, clusterPath); this.assignmentTask = new AtomicReference<>(); this.lastReportTime = new AtomicLong(CURRENT_TIME_MILLIS.get()); this.parallelContainerStartsSemaphore = new Semaphore(parallelContainerStarts); }
Example #8
Source File: SharedCacheCoordinator.java From datawave with Apache License 2.0 | 6 votes |
private void reregisterCounter(String counterName, SharedCountListener listener, int seedValue) throws Exception { ArgumentChecker.notNull(counterName, listener); SharedCount count = new SharedCount(curatorClient, ZKPaths.makePath("/counters", counterName), seedValue); count.start(); sharedCounters.put(counterName, count); sharedCountListeners.put(counterName, listener); localCounters.put(counterName, count.getCount()); count.addListener(new SharedCountListener() { @Override public void countHasChanged(SharedCountReader sharedCountReader, int i) throws Exception {} @Override public void stateChanged(CuratorFramework curatorFramework, ConnectionState connectionState) { if (connectionState == ConnectionState.RECONNECTED) { try { reregisterCounter(counterName, sharedCountListeners.get(counterName), localCounters.get(counterName)); } catch (Exception e) { System.err.println("Unable to re-register counter " + counterName + ": " + e.getMessage()); } } } }); count.addListener(listener); }
Example #9
Source File: CuratorAsyncManager.java From Singularity with Apache License 2.0 | 6 votes |
private <T> List<T> getAsyncChildrenThrows( final String parent, final Transcoder<T> transcoder ) throws Exception { try { List<String> children = getChildren(parent); final List<String> paths = Lists.newArrayListWithCapacity(children.size()); for (String child : children) { paths.add(ZKPaths.makePath(parent, child)); } List<T> result = new ArrayList<>( getAsyncThrows(parent, paths, transcoder, Optional.empty()).values() ); return result; } catch (Throwable t) { throw t; } }
Example #10
Source File: ProxyMetaManager.java From dble with GNU General Public License v2.0 | 6 votes |
private void notifyResponseZKDdl(String schema, String table, String sql, DDLInfo.DDLStatus ddlStatus, DDLInfo.DDLType ddlType, boolean needNotifyOther) throws Exception { String nodeName = StringUtil.getFullName(schema, table); String nodePath = ZKPaths.makePath(KVPathUtil.getDDLPath(), nodeName); String instancePath = ZKPaths.makePath(nodePath, KVPathUtil.DDL_INSTANCE); String thisNode = ZkConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID); ZKUtils.createTempNode(instancePath, thisNode); if (needNotifyOther) { CuratorFramework zkConn = ZKUtils.getConnection(); DDLInfo ddlInfo = new DDLInfo(schema, sql, ZkConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), ddlStatus, ddlType); ClusterDelayProvider.delayBeforeDdlNotice(); zkConn.setData().forPath(nodePath, ddlInfo.toString().getBytes(StandardCharsets.UTF_8)); ClusterDelayProvider.delayAfterDdlNotice(); while (true) { List<String> preparedList = zkConn.getChildren().forPath(instancePath); List<String> onlineList = zkConn.getChildren().forPath(KVPathUtil.getOnlinePath()); if (preparedList.size() >= onlineList.size()) { ClusterDelayProvider.delayBeforeDdlNoticeDeleted(); zkConn.delete().deletingChildrenIfNeeded().forPath(nodePath); break; } LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(100)); } } }
Example #11
Source File: ZookeeperStreamMetadataStore.java From kylin-on-parquet-v2 with Apache License 2.0 | 6 votes |
@Override public void addReceiver(Node receiver) { logger.trace("Add {}.", receiver); try { String receiverPath = ZKPaths.makePath(receiverRoot, receiver.toNormalizeString()); if (client.checkExists().forPath(receiverPath) == null) { client.create().creatingParentsIfNeeded().forPath(receiverPath); } else { logger.warn("{} exists.", receiverPath); } writeSuccess.getAndIncrement(); } catch (Exception e) { writeFail.getAndIncrement(); logger.error("Error when add new receiver " + receiver, e); throw new StoreException(e); } }
Example #12
Source File: ZookeeperConfigGroup.java From config-toolkit with Apache License 2.0 | 6 votes |
/** * 加载节点并监听节点变化 */ void loadNode() { final String nodePath = ZKPaths.makePath(configProfile.getVersionedRootNode(), node); final GetChildrenBuilder childrenBuilder = client.getChildren(); try { final List<String> children = childrenBuilder.watched().forPath(nodePath); if (children != null) { final Map<String, String> configs = new HashMap<>(); for (String child : children) { final Tuple<String, String> keyValue = loadKey(ZKPaths.makePath(nodePath, child)); if (keyValue != null) { configs.put(keyValue.getFirst(), keyValue.getSecond()); } } cleanAndPutAll(configs); } } catch (Exception e) { throw new RuntimeException(e); } if (getConfigLocalCache() != null) { getConfigLocalCache().saveLocalCache(this, getNode()); } }
Example #13
Source File: PathCacheExample.java From curator with Apache License 2.0 | 6 votes |
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 } }
Example #14
Source File: TestFrameworkEdges.java From xian with Apache License 2.0 | 6 votes |
@Test public void testMissedResponseOnESCreate() throws Exception { CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1)); client.start(); try { CreateBuilderImpl createBuilder = (CreateBuilderImpl)client.create(); createBuilder.failNextCreateForTesting = true; String ourPath = createBuilder.withProtection().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).forPath("/"); Assert.assertTrue(ourPath.startsWith(ZKPaths.makePath("/", CreateBuilderImpl.PROTECTED_PREFIX))); Assert.assertFalse(createBuilder.failNextCreateForTesting); } finally { CloseableUtils.closeQuietly(client); } }
Example #15
Source File: PathChildrenCache.java From curator with Apache License 2.0 | 6 votes |
@VisibleForTesting protected void remove(String fullPath) { ChildData data = currentData.remove(fullPath); if ( data != null ) { offerOperation(new EventOperation(this, new PathChildrenCacheEvent(PathChildrenCacheEvent.Type.CHILD_REMOVED, data))); } Map<String, ChildData> localInitialSet = initialSet.get(); if ( localInitialSet != null ) { localInitialSet.remove(ZKPaths.getNodeFromPath(fullPath)); maybeOfferInitializedEvent(localInitialSet); } }
Example #16
Source File: LockInternals.java From curator with Apache License 2.0 | 6 votes |
public static Collection<String> getParticipantNodes(CuratorFramework client, final String basePath, String lockName, LockInternalsSorter sorter) throws Exception { List<String> names = getSortedChildren(client, basePath, lockName, sorter); Iterable<String> transformed = Iterables.transform ( names, new Function<String, String>() { @Override public String apply(String name) { return ZKPaths.makePath(basePath, name); } } ); return ImmutableList.copyOf(transformed); }
Example #17
Source File: Zk.java From rdf-delta with Apache License 2.0 | 6 votes |
private static void recurse(CuratorFramework client, String path, String initial, int depth) { try { client.getChildren().forPath(path).forEach(p->{ String x = ZKPaths.makePath(path, p); String spc = StringUtils.repeat(" ", 2*(depth-1)); // Indented, with level number //System.out.printf("%-2d %s /%s\n", depth, spc, p); // Indented //System.out.printf(" %s /%s\n", spc, p); // Path below start. String print = x.startsWith(initial) ? x.substring(initial.length()) : x; System.out.printf(" %s\n", print); recurse(client, x, initial, depth+1); }); } catch (Exception ex) { return; } }
Example #18
Source File: WebhookManager.java From Singularity with Apache License 2.0 | 5 votes |
public void saveRequestUpdateForRetry(SingularityRequestHistory requestHistory) { if (!isChildNodeCountSafe(SNS_REQUEST_RETRY)) { LOG.warn("Too many queued webhooks for path {}, dropping", SNS_REQUEST_RETRY); return; } String updatePath = ZKPaths.makePath( SNS_REQUEST_RETRY, getRequestHistoryUpdateId(requestHistory) ); save(updatePath, requestHistory, requestHistoryTranscoder); }
Example #19
Source File: LeaderLatch.java From xian with Apache License 2.0 | 5 votes |
@VisibleForTesting void reset() throws Exception { setLeadership(false); setNode(null); BackgroundCallback callback = new BackgroundCallback() { @Override public void processResult(CuratorFramework client, CuratorEvent event) throws Exception { if ( debugResetWaitLatch != null ) { debugResetWaitLatch.await(); debugResetWaitLatch = null; } if ( event.getResultCode() == KeeperException.Code.OK.intValue() ) { setNode(event.getName()); if ( state.get() == State.CLOSED ) { setNode(null); } else { getChildren(); } } else { log.error("getChildren() failed. rc = " + event.getResultCode()); } } }; client.create().creatingParentContainersIfNeeded().withProtection().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).inBackground(callback).forPath(ZKPaths.makePath(latchPath, LOCK_NAME), LeaderSelector.getIdBytes(id)); }
Example #20
Source File: SingularityCmdLineArgsMigration.java From Singularity with Apache License 2.0 | 5 votes |
private Optional<String> getCmdLineArgs(SingularityPendingTaskId pendingTaskId) throws Exception { byte[] data = curator .getData() .forPath(ZKPaths.makePath(TASK_PENDING_PATH, pendingTaskId.getId())); if (data != null && data.length > 0) { return Optional.of(StringTranscoder.INSTANCE.fromBytes(data)); } return Optional.empty(); }
Example #21
Source File: PathCacheExample.java From ZKRecipesByExample with Apache License 2.0 | 5 votes |
private static void addListener(PathChildrenCache cache) { // a PathChildrenCacheListener is optional. Here, it's used just to log // changes PathChildrenCacheListener listener = new PathChildrenCacheListener() { @Override public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception { switch (event.getType()) { case CHILD_ADDED: { System.out.println("Node added: " + ZKPaths.getNodeFromPath(event.getData().getPath()) + ", value: " + new String(event.getData().getData())); break; } case CHILD_UPDATED: { System.out.println("Node changed: " + ZKPaths.getNodeFromPath(event.getData().getPath()) + ", value: " + new String(event.getData().getData())); break; } case CHILD_REMOVED: { System.out.println("Node removed: " + ZKPaths.getNodeFromPath(event.getData().getPath())); break; } default: break; } } }; cache.getListenable().addListener(listener); }
Example #22
Source File: WorkStateMachine.java From DBus with Apache License 2.0 | 5 votes |
private void registerAssignmentListener() { Watcher watcher = new Watcher() { @Override public void process(WatchedEvent event) { if (event.getType() == Event.EventType.NodeDataChanged) { // 首先停止worker中分布式的任务,然后再重新启动 } } }; zkUtils.usingWatcher(ZKPaths.makePath(zkUtils.assignmentsTopicsPath, String.valueOf(worker.getId())), watcher); }
Example #23
Source File: WebhookManager.java From Singularity with Apache License 2.0 | 5 votes |
public List<SingularityTaskHistoryUpdate> getTaskUpdatesToRetry() { List<SingularityTaskHistoryUpdate> results = new ArrayList<>(); for (String requestId : getChildren(SNS_TASK_RETRY_ROOT)) { if (results.size() > configuration.getMaxConcurrentWebhooks()) { break; } results.addAll( getAsyncChildren( ZKPaths.makePath(SNS_TASK_RETRY_ROOT, requestId), taskHistoryUpdateTranscoder ) ); } return results; }
Example #24
Source File: DefaultZooKeeperClient.java From helios with Apache License 2.0 | 5 votes |
@Override public void delete(final String path, final int version) throws KeeperException { assertClusterIdFlagTrue(); final String namespace = emptyToNull(client.getNamespace()); final String namespacedPath = ZKPaths.fixForNamespace(namespace, path); try { client.getZookeeperClient().getZooKeeper().delete(namespacedPath, version); } catch (Exception e) { throwIfInstanceOf(e, KeeperException.class); throw new RuntimeException(e); } }
Example #25
Source File: ZKNamespaces.java From emodb with Apache License 2.0 | 5 votes |
public static CuratorFramework usingChildNamespace(CuratorFramework curator, String... children) { String path = curator.getNamespace(); for (String child : children) { path = path.length() > 0 ? ZKPaths.makePath(path, child) : child; } // Curator does not allow namespaces to start with a leading '/' if (path.startsWith("/")) { path = path.substring(1); } return curator.usingNamespace(path); }
Example #26
Source File: ZooKeeperUpdatingPersistentDirectory.java From helios with Apache License 2.0 | 5 votes |
private void write(final String node, final byte[] data) throws KeeperException { final ZooKeeperClient client = client("write"); final String nodePath = ZKPaths.makePath(path, node); if (client.stat(nodePath) != null) { log.debug("setting node: {}", nodePath); client.setData(nodePath, data); } else { log.debug("creating node: {}", nodePath); client.createAndSetData(nodePath, data); } }
Example #27
Source File: UnregisterCassandraCommand.java From emodb with Apache License 2.0 | 5 votes |
@Override protected void run(Bootstrap<EmoConfiguration> bootstrap, Namespace namespace, EmoConfiguration configuration) throws Exception { String hostString = namespace.getString("host"); String serviceName = namespace.getString("service"); CuratorFramework curator = configuration.getZooKeeperConfiguration().newCurator(); curator.start(); HostAndPort host = HostAndPort.fromString(hostString).withDefaultPort(9160); ServiceEndPoint endPoint = new ServiceEndPointBuilder() .withServiceName(serviceName) .withId(host.toString()) .build(); String dir = ZKPaths.makePath("ostrich", endPoint.getServiceName()); String path = ZKPaths.makePath(dir, endPoint.getId()); curator.newNamespaceAwareEnsurePath(dir).ensure(curator.getZookeeperClient()); try { curator.delete().forPath(path); System.out.println("Deleted."); } catch (KeeperException.NoNodeException e) { System.out.println("Not found."); } curator.close(); }
Example #28
Source File: ZkTaskUsageManager.java From Singularity with Apache License 2.0 | 5 votes |
public void cleanOldUsages(List<SingularityTaskId> activeTaskIds) { for (String requestId : getChildren(TASK_PATH)) { // clean for inactive tasks for (String taskIdString : getChildren(ZKPaths.makePath(TASK_PATH, requestId))) { SingularityTaskId taskId; try { taskId = SingularityTaskId.valueOf(taskIdString); if (activeTaskIds.contains(taskId)) { // prune old usages for active tasks getChildren(getTaskUsageHistoryPath(taskId)) .stream() .map(Long::parseLong) .sorted((t1, t2) -> Long.compare(t2, t1)) .skip(configuration.getNumUsageToKeep()) .forEach( timestamp -> { delete(getSpecificTaskUsagePath(taskId, timestamp)); } ); continue; } } catch (InvalidSingularityTaskIdException e) { LOG.warn( "{} is not a valid task id, will remove task usage from zookeeper", taskIdString ); } SingularityDeleteResult result = delete( ZKPaths.makePath(TASK_PATH, requestId, taskIdString) ); // manually constructed in case SingularityTaskId.valueOf fails LOG.debug("Deleted obsolete task usage {} - {}", taskIdString, result); } } }
Example #29
Source File: DataStoreModule.java From emodb with Apache License 2.0 | 5 votes |
@Provides @Singleton @MinLagDurationValues Map<String, ValueStore<Duration>> provideMinLagDurationValues(@CassandraClusters Collection<String> cassandraClusters, @GlobalFullConsistencyZooKeeper final CuratorFramework curator, final LifeCycleRegistry lifeCycle) { final ConcurrentMap<String, ValueStore<Duration>> valuesByCluster = Maps.newConcurrentMap(); for (String cluster : cassandraClusters) { String zkPath = ZKPaths.makePath("/consistency/min-lag", cluster); ZkValueStore<Duration> holder = new ZkValueStore<>(curator, zkPath, new ZkDurationSerializer()); valuesByCluster.put(cluster, lifeCycle.manage(holder)); } return valuesByCluster; }
Example #30
Source File: PluginCacheSyncUtil.java From incubator-sentry with Apache License 2.0 | 5 votes |
public static void setUpdateFromChildEvent(PathChildrenCacheEvent cacheEvent, Update update) throws IOException { byte eventData[] = cacheEvent.getData().getData(); update.deserialize(eventData); String seqNum = ZKPaths.getNodeFromPath(cacheEvent.getData().getPath()); update.setSeqNum(Integer.valueOf(seqNum)); }