mousio.etcd4j.responses.EtcdKeysResponse.EtcdNode Java Examples

The following examples show how to use mousio.etcd4j.responses.EtcdKeysResponse.EtcdNode. 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: EtcdUtil.java    From etcd4j with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the content of the key recursively as a JsonObject
 * @param path root path (i.e. /path1/path2)
 * @param etcdClient EtcdClient
 * @return JsonNode
 * @throws IOException
 * @throws EtcdAuthenticationException
 * @throws TimeoutException
 * @throws EtcdException
 */
public static JsonNode getAsJson(String path, EtcdClient etcdClient)
        throws IOException, EtcdAuthenticationException, TimeoutException, EtcdException {

  EtcdKeyGetRequest etcdKeyGetRequest = etcdClient.get(path).recursive();
  EtcdKeysResponse dataTree = etcdKeyGetRequest.send().get();

  ObjectNode jNode = JsonNodeFactory.instance.objectNode();

  if (dataTree.getNode().getNodes().isEmpty()) {
    iterateOverNodes(jNode, dataTree.getNode());
  } else {
    for (EtcdNode node : dataTree.getNode().getNodes()) {
      iterateOverNodes(jNode, node);
    }
  }

  return dotNotationToStandardJson(jNode.at(path));
}
 
Example #2
Source File: EtcdFlagFieldUpdater.java    From java-flagz with MIT License 5 votes vote down vote up
private List<EtcdNode> fetchAllFlagzNodes() {
  try {
    EtcdResponsePromise<EtcdKeysResponse> promise = client
        .get(this.directoryPrefix)
        .dir()
        .send();
    EtcdKeysResponse response = promise.get();
    // NOTE: We use etcdIndex here, because we know we got latest data up to this point.
    lastKnownFlagzModificationIndex = response.etcdIndex;
    return MoreObjects.firstNonNull(response.node.nodes, ImmutableList.<EtcdNode>of());
  } catch (IOException | EtcdException
      | TimeoutException | EtcdAuthenticationException exception) {
    throw new EtcdFlagFieldUpdaterException.EtcdFetchingFailed(exception);
  }
}
 
Example #3
Source File: EtcdFlagFieldUpdater.java    From java-flagz with MIT License 5 votes vote down vote up
private void setFlagFromFlagzNode(EtcdNode node) throws FlagException {
  String flagName = nodeKeyToFlagName(node.key);
  registry.setField(flagName, node.value);
  LOG.info(
      "Flag({}) updated to value='{}' from EtcdIndex({}).", flagName, node.value,
      node.modifiedIndex);
}
 
Example #4
Source File: EtcdFlagFieldUpdater.java    From java-flagz with MIT License 4 votes vote down vote up
private void initialSetAllFlagz() {
  for (EtcdNode n : fetchAllFlagzNodes()) {
    setFlagFromFlagzNode(n);
  }
}