private ChildData getConfigNode() { return Iterables.find ( cache.getCurrentData(), new Predicate<ChildData>() { @Override public boolean apply(ChildData data) { return ZKPaths.getNodeFromPath(data.getPath()).equals(CONFIG_NODE_NAME); } }, null ); } }
public Map<String, TaskAnnouncement> getRunningTasks() { Map<String, TaskAnnouncement> retVal = new HashMap<>(); for (TaskAnnouncement taskAnnouncement : Lists.transform( statusCache.getCurrentData(), cacheConverter )) { retVal.put(taskAnnouncement.getTaskStatus().getId(), taskAnnouncement); } return retVal; }
/** * Gets the current bootstrap nodes. * * @return the current bootstrap nodes */ public List<BootstrapNodeInfo> getCurrentBootstrapNodes() { List<ChildData> nodesData = bootstrapCache != null ? bootstrapCache .getCurrentData() : new ArrayList<ChildData>(); List<BootstrapNodeInfo> result = new ArrayList<>(nodesData.size()); for (ChildData data : nodesData) { result.add(extractBootstrapServerInfo(data)); } return result; }
final List<ChildData> children; if (isTokenCache) { children = tokenCache.getCurrentData(); } else { children = keyCache.getCurrentData();
/** * Gets the current endpoint nodes. * * @return the current endpoint nodes */ public List<OperationsNodeInfo> getCurrentOperationServerNodes() { List<ChildData> nodesData = endpointCache != null ? endpointCache .getCurrentData() : new ArrayList<ChildData>(); Map<ConnectionInfoKey, OperationsNodeInfo> uniqueMap = new HashMap<>(); for (ChildData data : nodesData) { OperationsNodeInfo newNodeInfo = extractOperationServerInfo(data); ConnectionInfoKey key = new ConnectionInfoKey(newNodeInfo.getConnectionInfo()); OperationsNodeInfo oldNodeInfo = uniqueMap.get(key); if (oldNodeInfo != null) { if (newNodeInfo.getTimeStarted() >= oldNodeInfo.getTimeStarted()) { uniqueMap.put(key, newNodeInfo); } } else { uniqueMap.put(key, newNodeInfo); } } return new ArrayList<>(uniqueMap.values()); }
Map<String, Long> slotByWorker = new HashMap<String, Long>(); Set<LlapServiceInstance> unsorted = Sets.newHashSet(); for (ChildData childData : instancesCache.getCurrentData()) { if (childData == null) continue; byte[] data = childData.getData();
@Override public ApplicationId getApplicationId() { for (ChildData childData : instancesCache.getCurrentData()) { byte[] data = getWorkerData(childData, WORKER_PREFIX); if (data == null) continue; ServiceRecord sr = null; try { sr = encoder.fromBytes(childData.getPath(), data); } catch (IOException e) { LOG.error("Unable to decode data for zkpath: {}." + " Ignoring from current instances list..", childData.getPath()); continue; } String containerStr = sr.get(HiveConf.ConfVars.LLAP_DAEMON_CONTAINER_ID.varname); if (containerStr == null || containerStr.isEmpty()) continue; return ContainerId.fromString(containerStr).getApplicationAttemptId().getApplicationId(); } return null; } }
@Override public void childEvent(CuratorFramework client1, PathChildrenCacheEvent event) throws Exception { if (LOGGER.isDebugEnabled(config.getAppName())) { LOGGER.debugWithApp(config.getAppName(), "Receive zookeeper event: " + "type=[" + event.getType() + "]"); } switch (event.getType()) { case CHILD_ADDED: //加了一个provider providerObserver.addProvider(config, providerPath, event.getData(), finalPathChildrenCache.getCurrentData()); break; case CHILD_REMOVED: //删了一个provider providerObserver.removeProvider(config, providerPath, event.getData(), finalPathChildrenCache.getCurrentData()); break; case CHILD_UPDATED: // 更新一个Provider providerObserver.updateProvider(config, providerPath, event.getData(), finalPathChildrenCache.getCurrentData()); break; default: break; } } });
@Override public void childEvent(CuratorFramework client1, PathChildrenCacheEvent event) throws Exception { if (LOGGER.isDebugEnabled(config.getAppName())) { LOGGER.debugWithApp(config.getAppName(), "Receive zookeeper event: " + "type=[" + event.getType() + "]"); } switch (event.getType()) { case CHILD_ADDED: //加了一个provider providerObserver.addProvider(config, providerPath, event.getData(), finalPathChildrenCache.getCurrentData()); break; case CHILD_REMOVED: //删了一个provider providerObserver.removeProvider(config, providerPath, event.getData(), finalPathChildrenCache.getCurrentData()); break; case CHILD_UPDATED: // 更新一个Provider providerObserver.updateProvider(config, providerPath, event.getData(), finalPathChildrenCache.getCurrentData()); break; default: break; } } });
protected final void populateCache(PathChildrenCache instancesCache, boolean doInvokeListeners) { for (ChildData childData : instancesCache.getCurrentData()) { byte[] data = getWorkerData(childData, workerNodePrefix); if (data == null) continue; String nodeName = extractNodeName(childData); if (!nodeName.startsWith(workerNodePrefix)) continue; int ephSeqVersion = extractSeqNum(nodeName); try { ServiceRecord srv = encoder.fromBytes(childData.getPath(), data); InstanceType instance = createServiceInstance(srv); addToCache(childData.getPath(), instance.getHost(), instance); if (doInvokeListeners) { for (ServiceInstanceStateChangeListener<InstanceType> listener : stateChangeListeners) { listener.onCreate(instance, ephSeqVersion); } } } catch (IOException e) { LOG.error("Unable to decode data for zkpath: {}." + " Ignoring from current instances list..", childData.getPath()); } } }
pathChildrenCache.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE); INTERFACE_CONFIG_CACHE.put(configPath, pathChildrenCache); configObserver.updateConfigAll(config, configPath, pathChildrenCache.getCurrentData()); } catch (Exception e) { throw new SofaRpcRuntimeException("Failed to subscribe provider config from zookeeperRegistry!", e);
pathChildrenCache.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE); INTERFACE_CONFIG_CACHE.put(configPath, pathChildrenCache); configObserver.updateConfigAll(config, configPath, pathChildrenCache.getCurrentData()); } catch (Exception e) { throw new SofaRpcRuntimeException("Failed to subscribe provider config from zookeeperRegistry!", e);
pathChildrenCache.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE); INTERFACE_OVERRIDE_CACHE.put(overridePath, pathChildrenCache); overrideObserver.updateConfigAll(config, overridePath, pathChildrenCache.getCurrentData()); } catch (Exception e) { throw new SofaRpcRuntimeException("Failed to subscribe provider config from zookeeperRegistry!", e);
pathChildrenCache.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE); INTERFACE_OVERRIDE_CACHE.put(overridePath, pathChildrenCache); overrideObserver.updateConfigAll(config, overridePath, pathChildrenCache.getCurrentData()); } catch (Exception e) { throw new SofaRpcRuntimeException("Failed to subscribe provider config from zookeeperRegistry!", e);
providerPath, pathChildrenCache.getCurrentData()); matchProviders = ZookeeperRegistryHelper.matchProviderInfos(config, providerInfos); } catch (Exception e) {
providerPath, pathChildrenCache.getCurrentData()); matchProviders = ZookeeperRegistryHelper.matchProviderInfos(config, providerInfos); } catch (Exception e) {
@Override public String get(String key) { Assert.notNull(key, "'key' must not be null."); Assert.state(isRunning(), "ZookeeperMetadataStore has to be started before using."); synchronized (this.updateMap) { ChildData currentData = this.cache.getCurrentData(getPath(key)); if (currentData == null) { if (this.updateMap.containsKey(key)) { // we have saved the value, but the cache hasn't updated yet // if the value had changed via replication, we would have been notified by the listener return this.updateMap.get(key).getValue(); } else { // the value just doesn't exist return null; } } else { if (this.updateMap.containsKey(key)) { // our version is more recent than the cache if (this.updateMap.get(key).getVersion() >= currentData.getStat().getVersion()) { return this.updateMap.get(key).getValue(); } } return IntegrationUtils.bytesToString(currentData.getData(), this.encoding); } } }
public List<String> getDatas(){ List<ChildData> datas = cacher.getCurrentData(); if (CollectionUtil.isNullOrEmpty(datas)){ return Collections.emptyList(); } List<String> stringDatas = Lists.newArrayListWithExpectedSize(datas.size()); for (ChildData data : datas){ stringDatas.add(new String(data.getData())); } return stringDatas; }
public Map<String, TaskAnnouncement> getRunningTasks() { Map<String, TaskAnnouncement> retVal = Maps.newHashMap(); for (TaskAnnouncement taskAnnouncement : Lists.transform( statusCache.getCurrentData(), cacheConverter )) { retVal.put(taskAnnouncement.getTaskStatus().getId(), taskAnnouncement); } return retVal; }
@Override public void start() throws Exception { Preconditions.checkState(state.compareAndSet(State.LATENT, State.STARTED), "Cannot be started more than once"); cache.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE); for (ChildData childData : cache.getCurrentData()) { addInstance(childData, true); } discovery.cacheOpened(this); }