示例#1
0
  private void listRequests(
      @Nonnull String bucket, @Nonnull Jiterator<OfflineStoreRequest> iterator)
      throws CloudException, InternalException {
    APITrace.begin(getProvider(), "Blob.listRequests");
    try {

      boolean needQuery = true;
      String marker = null;
      Map<String, String> queryParameters = new HashMap<String, String>(1);

      // glacier can paginate results. it returns a "marker" string in the JSON response
      // which indicates you should make another query. The marker string should be passed
      // as a query parameter in the next query.

      while (needQuery) {
        if (marker != null) {
          queryParameters.put("marker", marker);
        }

        GlacierMethod method =
            GlacierMethod.build(getProvider(), GlacierAction.LIST_JOBS)
                .vaultId(bucket)
                .queryParameters(queryParameters)
                .toMethod();
        final JSONObject jsonObject = method.invokeJson();

        try {
          JSONArray vaultList = jsonObject.getJSONArray("JobList");

          for (int i = 0; i < vaultList.length(); i++) {
            iterator.push(loadRequestJson(vaultList.getJSONObject(i), bucket));
          }

          marker = getPaginationMarker(jsonObject);
          if (marker == null) {
            needQuery = false;
          }
        } catch (JSONException e) {
          throw new CloudException(e);
        }
      }
    } finally {
      APITrace.end();
    }
  }
示例#2
0
  @Nonnull
  @Override
  public OfflineStoreRequest createListRequest(@Nonnull String bucket)
      throws CloudException, InternalException {
    APITrace.begin(getProvider(), "Blob.createListRequest");
    try {
      try {

        JSONObject bodyJson = new JSONObject();
        bodyJson.put("Type", "inventory-retrieval");

        final GlacierMethod method =
            GlacierMethod.build(getProvider(), GlacierAction.CREATE_JOB)
                .vaultId(bucket)
                .bodyText(bodyJson.toString())
                .toMethod();

        Map<String, String> responseHeaders = method.invokeHeaders();
        if (!responseHeaders.containsKey(HEADER_JOB_ID)) {
          throw new CloudException("Glacier response missing " + HEADER_JOB_ID + " header");
        }
        String jobId = responseHeaders.get(HEADER_JOB_ID);

        return new OfflineStoreRequest(
            jobId,
            bucket,
            null,
            OfflineStoreRequestAction.LIST,
            ACTION_INVENTORY_RETRIEVAL,
            null,
            "",
            OfflineStoreRequestStatus.IN_PROGRESS,
            "",
            System.currentTimeMillis(),
            -1);

      } catch (JSONException e) {
        throw new CloudException(e);
      }
    } finally {
      APITrace.end();
    }
  }
示例#3
0
  private void loadVaults(@Nonnull String regionId, @Nonnull Jiterator<Blob> iterator)
      throws CloudException, InternalException {

    boolean needQuery = true;
    String marker = null;
    Map<String, String> queryParameters = new HashMap<String, String>(1);

    // glacier can paginate results. it returns a "marker" string in the JSON response
    // which indicates you should make another query. The marker string should be passed
    // as a query parameter in the next query.

    while (needQuery) {
      if (marker != null) {
        queryParameters.put("marker", marker);
      }

      GlacierMethod method =
          GlacierMethod.build(getProvider(), GlacierAction.LIST_VAULTS)
              .queryParameters(queryParameters)
              .toMethod();
      String baseUrl = method.getUrl();
      JSONObject jsonObject = method.invokeJson();

      try {
        JSONArray vaultList = jsonObject.getJSONArray("VaultList");

        for (int i = 0; i < vaultList.length(); i++) {
          iterator.push(loadVaultJson(vaultList.getJSONObject(i), regionId, baseUrl));
        }

        marker = getPaginationMarker(jsonObject);
        if (marker == null) {
          needQuery = false;
        }
      } catch (JSONException e) {
        throw new CloudException(e);
      }
    }
  }