Exemplo n.º 1
0
  /** Retrieves a key. Returns null if not found. */
  public EtcdResult get(String key) throws EtcdClientException {
    URI uri = buildKeyUri("v1/keys", key, "");
    HttpGet request = new HttpGet(uri);

    EtcdResult result = syncExecute(request, 100);
    if (result.isError()) {
      if (result.errorCode == 100) {
        return null;
      }
    }
    return result;
  }
Exemplo n.º 2
0
  private EtcdResult jsonToEtcdResult(JsonResponse response, int... expectedErrorCodes)
      throws EtcdClientException {
    if (response == null || response.json == null) {
      return null;
    }
    EtcdResult result = parseEtcdResult(response.json);

    if (result.isError()) {
      if (!contains(expectedErrorCodes, result.errorCode)) {
        throw new EtcdClientException(result.message, result);
      }
    }
    return result;
  }