@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(); } }
@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(); } }
private static long parseTimestamp(String timestamp) { if (timestamp == null) { return -1; } long creationTs; SimpleDateFormat fmt; // some response dates have MS component, some do not. if (timestamp.contains(".")) { fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); } else { fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); } Calendar cal = Calendar.getInstance(new SimpleTimeZone(0, "GMT")); fmt.setCalendar(cal); try { creationTs = fmt.parse(timestamp).getTime(); } catch (ParseException e) { creationTs = System.currentTimeMillis(); } return creationTs; }