List of usage examples for com.amazonaws.services.s3.model DeleteObjectsRequest DeleteObjectsRequest
public DeleteObjectsRequest(String bucketName)
From source file:org.finra.herd.dao.impl.S3DaoImpl.java
License:Apache License
/** * Deletes a list of keys/key versions from the specified S3 bucket. * * @param s3Client the S3 client//from ww w . j a va2 s. c om * @param s3BucketName the S3 bucket name * @param keyVersions the list of S3 keys/key versions */ private void deleteKeyVersions(AmazonS3Client s3Client, String s3BucketName, List<DeleteObjectsRequest.KeyVersion> keyVersions) { // Create a request to delete multiple objects in the specified bucket. DeleteObjectsRequest multiObjectDeleteRequest = new DeleteObjectsRequest(s3BucketName); // The Multi-Object Delete request can contain a list of up to 1000 keys. for (int i = 0; i < keyVersions.size() / MAX_KEYS_PER_DELETE_REQUEST + 1; i++) { List<DeleteObjectsRequest.KeyVersion> keysSubList = keyVersions.subList(i * MAX_KEYS_PER_DELETE_REQUEST, Math.min(keyVersions.size(), (i + 1) * MAX_KEYS_PER_DELETE_REQUEST)); multiObjectDeleteRequest.setKeys(keysSubList); try { s3Operations.deleteObjects(multiObjectDeleteRequest, s3Client); } catch (MultiObjectDeleteException multiObjectDeleteException) { logMultiObjectDeleteException(multiObjectDeleteException); throw multiObjectDeleteException; } LOGGER.info( "Successfully requested the deletion of the listed below keys/key versions from the S3 bucket. s3KeyCount={} s3BucketName=\"{}\"", keysSubList.size(), s3BucketName); for (DeleteObjectsRequest.KeyVersion keyVersion : keysSubList) { LOGGER.info("s3Key=\"{}\" s3VersionId=\"{}\"", keyVersion.getKey(), keyVersion.getVersion()); } } }
From source file:org.geowebcache.s3.S3BlobStore.java
License:Open Source License
@Override public boolean delete(final TileRange tileRange) throws StorageException { final String coordsPrefix = keyBuilder.coordinatesPrefix(tileRange); if (!s3Ops.prefixExists(coordsPrefix)) { return false; }/*from w w w . j a v a 2s.c om*/ final Iterator<long[]> tileLocations = new AbstractIterator<long[]>() { // TileRange iterator with 1x1 meta tiling factor private TileRangeIterator trIter = new TileRangeIterator(tileRange, new int[] { 1, 1 }); @Override protected long[] computeNext() { long[] gridLoc = trIter.nextMetaGridLocation(new long[3]); return gridLoc == null ? endOfData() : gridLoc; } }; if (listeners.isEmpty()) { // if there are no listeners, don't bother requesting every tile // metadata to notify the listeners Iterator<List<long[]>> partition = Iterators.partition(tileLocations, 1000); final TileToKey tileToKey = new TileToKey(coordsPrefix, tileRange.getMimeType()); while (partition.hasNext() && !shutDown) { List<long[]> locations = partition.next(); List<KeyVersion> keys = Lists.transform(locations, tileToKey); DeleteObjectsRequest req = new DeleteObjectsRequest(bucketName); req.setQuiet(true); req.setKeys(keys); conn.deleteObjects(req); } } else { long[] xyz; String layerName = tileRange.getLayerName(); String gridSetId = tileRange.getGridSetId(); String format = tileRange.getMimeType().getFormat(); Map<String, String> parameters = tileRange.getParameters(); while (tileLocations.hasNext()) { xyz = tileLocations.next(); TileObject tile = TileObject.createQueryTileObject(layerName, xyz, gridSetId, format, parameters); tile.setParametersId(tileRange.getParametersId()); delete(tile); } } return true; }
From source file:org.geowebcache.s3.TemporaryS3Folder.java
License:Open Source License
public void delete() { checkState(isConfigured(), "client not configured."); if (temporaryPrefix == null) { return;/*from w w w.j a v a 2s .c om*/ } Iterable<S3ObjectSummary> objects = S3Objects.withPrefix(s3, bucket, temporaryPrefix); Iterable<List<S3ObjectSummary>> partition = Iterables.partition(objects, 1000); for (List<S3ObjectSummary> os : partition) { List<KeyVersion> keys = Lists.transform(os, new Function<S3ObjectSummary, KeyVersion>() { @Override public KeyVersion apply(S3ObjectSummary input) { KeyVersion k = new KeyVersion(input.getKey()); return k; } }); DeleteObjectsRequest deleteRequest = new DeleteObjectsRequest(bucket); deleteRequest.setKeys(keys); s3.deleteObjects(deleteRequest); } }
From source file:org.huahinframework.core.util.S3Utils.java
License:Apache License
/** * {@inheritDoc}/*from ww w . j a v a 2 s . c o m*/ */ @Override public void delete(String path) throws IOException, URISyntaxException { URI uri = new URI(path); String bucketName = uri.getHost(); String key = uri.getPath().substring(1, uri.getPath().length()); List<DeleteObjectsRequest.KeyVersion> keys = new ArrayList<DeleteObjectsRequest.KeyVersion>(); String marker = null; for (;;) { ObjectListing ol = s3.listObjects( new ListObjectsRequest().withBucketName(bucketName).withPrefix(key).withMarker(marker)); for (S3ObjectSummary objectSummary : ol.getObjectSummaries()) { keys.add(new DeleteObjectsRequest.KeyVersion(objectSummary.getKey())); } marker = ol.getNextMarker(); if (marker == null) { break; } } s3.deleteObjects(new DeleteObjectsRequest(bucketName).withKeys(keys)); s3.deleteObject(bucketName, key); }
From source file:org.mule.module.s3.simpleapi.SimpleAmazonS3AmazonDevKitImpl.java
License:Open Source License
public void deleteObjects(@NotNull String bucketName, @NotNull List<KeyVersion> keys) { Validate.notNull(bucketName);//from w ww. j av a 2 s . co m Validate.notNull(keys); Validate.notEmpty(keys); DeleteObjectsRequest deleteObjectsRequest = new DeleteObjectsRequest(bucketName); List<DeleteObjectsRequest.KeyVersion> deleteKeysRequest = new ArrayList<DeleteObjectsRequest.KeyVersion>(); for (KeyVersion key : keys) { deleteKeysRequest.add(new DeleteObjectsRequest.KeyVersion(key.getValue(), key.getVersion())); } deleteObjectsRequest.setKeys(deleteKeysRequest); s3.deleteObjects(deleteObjectsRequest); }