示例#1
0
  @Override
  public @Nonnull Blob createBucket(@Nonnull String bucketName, boolean findFreeName)
      throws InternalException, CloudException {
    APITrace.begin(getProvider(), "Blob.createBucket");
    try {
      if (bucketName.contains("/")) {
        throw new OperationNotSupportedException("Nested buckets are not supported");
      }
      String regionId = getContext().getRegionId();

      if (regionId == null) {
        throw new InternalException("No region ID was specified for this request");
      }

      GlacierMethod method =
          GlacierMethod.build(getProvider(), GlacierAction.CREATE_VAULT)
              .vaultId(bucketName)
              .toMethod();
      method.invoke();
      String url = method.getUrl();
      return Blob.getInstance(regionId, url, bucketName, System.currentTimeMillis());
    } finally {
      APITrace.end();
    }
  }
示例#2
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);
      }
    }
  }
示例#3
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();
    }
  }