Esempio n. 1
0
  @Nullable
  @Override
  public OfflineStoreRequest getRequest(@Nonnull String bucket, @Nonnull String requestId)
      throws CloudException, InternalException {
    APITrace.begin(getProvider(), "Blob.getRequest");
    try {

      final GlacierMethod method =
          GlacierMethod.build(getProvider(), GlacierAction.DESCRIBE_JOB)
              .vaultId(bucket)
              .jobId(requestId)
              .toMethod();

      try {
        final JSONObject jsonObject = method.invokeJson();
        return loadRequestJson(jsonObject, bucket);

      } catch (GlacierException e) {
        if (e.getHttpCode() == 404) {
          return null;
        }
        throw e;
      } catch (JSONException e) {
        throw new CloudException(e);
      }
    } finally {
      APITrace.end();
    }
  }
Esempio n. 2
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();
    }
  }
Esempio n. 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);
      }
    }
  }
Esempio n. 4
0
  @Nonnull
  @Override
  public Iterable<Blob> getListRequestResult(@Nonnull String bucket, @Nonnull String requestId)
      throws InternalException, CloudException {
    final String regionId = getContext().getRegionId();

    if (regionId == null) {
      throw new CloudException("No region ID was specified");
    }
    APITrace.begin(getProvider(), "Blob.getListRequestResult");
    try {

      final GlacierMethod method =
          GlacierMethod.build(getProvider(), GlacierAction.GET_JOB_OUTPUT)
              .vaultId(bucket)
              .jobId(requestId)
              .toMethod();

      try {
        JSONObject jsonObject = method.invokeJson();
        JSONArray archives = jsonObject.getJSONArray("ArchiveList");

        // not using thread here because there is no potential for pagination in the API
        List<Blob> blobs = new ArrayList<Blob>(archives.length());
        for (int i = 0; i < archives.length(); i++) {
          blobs.add(loadArchiveJson(archives.getJSONObject(i), bucket, regionId));
        }
        return blobs;

      } catch (JSONException e) {
        throw new CloudException(e);
      }
    } finally {
      APITrace.end();
    }
  }
Esempio n. 5
0
  @Override
  public Blob getBucket(@Nonnull String bucketName) throws InternalException, CloudException {
    APITrace.begin(getProvider(), "Blob.getBucket");
    try {
      if (bucketName.contains("/")) {
        return null;
      }

      String regionId = getContext().getRegionId();
      if (regionId == null) {
        throw new CloudException("No region was set for this request");
      }

      try {
        GlacierMethod method =
            GlacierMethod.build(getProvider(), GlacierAction.DESCRIBE_VAULT)
                .vaultId(bucketName)
                .toMethod();
        JSONObject jsonObject = method.invokeJson();
        if (jsonObject == null) {
          return null;
        }
        return loadVaultJson(jsonObject, regionId, method.getUrl());

      } catch (GlacierException e) {
        if (e.getHttpCode() == 404) {
          return null;
        }
        throw e;
      } catch (JSONException e) {
        throw new CloudException(e);
      }
    } finally {
      APITrace.end();
    }
  }