List of usage examples for com.amazonaws.services.s3.model S3ObjectSummary getKey
public String getKey()
From source file:org.gridgain.grid.spi.discovery.tcp.metricsstore.s3.GridTcpDiscoveryS3MetricsStore.java
License:Open Source License
/** {@inheritDoc} */ @Override//from w w w . j a v a2 s .c o m protected Map<UUID, GridNodeMetrics> metrics0(Collection<UUID> nodeIds) throws GridSpiException { assert !F.isEmpty(nodeIds); initClient(); Map<UUID, GridNodeMetrics> res = new HashMap<>(); try { ObjectListing list = s3.listObjects(bucketName); while (true) { for (S3ObjectSummary sum : list.getObjectSummaries()) { UUID id = UUID.fromString(sum.getKey()); if (!nodeIds.contains(id)) continue; InputStream in = null; try { in = s3.getObject(bucketName, sum.getKey()).getObjectContent(); byte[] buf = new byte[GridDiscoveryMetricsHelper.METRICS_SIZE]; in.read(buf); res.put(id, GridDiscoveryMetricsHelper.deserialize(buf, 0)); } catch (IllegalArgumentException ignored) { U.warn(log, "Failed to parse UUID from entry key: " + sum.getKey()); } catch (IOException e) { U.error(log, "Failed to get entry content [bucketName=" + bucketName + ", entry=" + id.toString() + ']', e); } finally { U.closeQuiet(in); } } if (list.isTruncated()) list = s3.listNextBatchOfObjects(list); else break; } } catch (AmazonClientException e) { throw new GridSpiException("Failed to list objects in the bucket: " + bucketName, e); } return res; }
From source file:org.gridgain.grid.spi.discovery.tcp.metricsstore.s3.GridTcpDiscoveryS3MetricsStore.java
License:Open Source License
/** {@inheritDoc} */ @Override//from www . j av a 2s. c o m public Collection<UUID> allNodeIds() throws GridSpiException { initClient(); Collection<UUID> res = new LinkedList<>(); try { ObjectListing list = s3.listObjects(bucketName); while (true) { for (S3ObjectSummary sum : list.getObjectSummaries()) try { UUID id = UUID.fromString(sum.getKey()); res.add(id); } catch (IllegalArgumentException ignored) { U.warn(log, "Failed to parse UUID from entry key: " + sum.getKey()); } if (list.isTruncated()) list = s3.listNextBatchOfObjects(list); else break; } } catch (AmazonClientException e) { throw new GridSpiException("Failed to list objects in the bucket: " + bucketName, e); } return res; }
From source file:org.huahinframework.core.util.S3Utils.java
License:Apache License
/** * {@inheritDoc}//from w w w . ja v a 2 s . co 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.icgc.dcc.storage.server.repository.s3.S3ListingService.java
License:Open Source License
private static String getObjectId(S3ObjectSummary objectSummary) { val name = new File(objectSummary.getKey()).getName(); // Only UUIDs correspond to published objects return isUUID(name) ? name : null; }
From source file:org.icgc.dcc.storage.server.repository.s3.S3UploadStateStore.java
License:Open Source License
@SneakyThrows private CompletedPart readCompletedPart(String objectId, String uploadId, S3ObjectSummary objectSummary) { try {/* w w w. j a v a 2 s. c om*/ val json = extractJson(objectSummary.getKey(), objectId, uploadId); val part = MAPPER.readValue(json, CompletedPart.class); return part; } catch (JsonParseException | JsonMappingException e) { log.error("Failed to read completed parts for objectId: {}, uploadId: {}, objectSummary: {}: {}", objectId, uploadId, objectSummary.getKey(), e); throw new NotRetryableException(e); } }
From source file:org.kuali.maven.wagon.S3Wagon.java
License:Educational Community License
/** * List all of the objects in a given directory *///from w w w. j av a 2 s .co m @Override protected List<String> listDirectory(final String directory) throws Exception { ObjectListing objectListing = client.listObjects(bucket.getName(), basedir + directory); List<String> fileNames = new ArrayList<String>(); for (S3ObjectSummary summary : objectListing.getObjectSummaries()) { fileNames.add(summary.getKey()); } return fileNames; }
From source file:org.nickelproject.util.sources.S3MultiFileSource.java
License:Apache License
private static List<String> listKeysInDirectory(final String bucketName, final String prefix) { final String delimiter = "/"; final String fixedPrefix = prefix.endsWith(delimiter) ? prefix : prefix + delimiter; ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName) .withPrefix(fixedPrefix).withDelimiter(delimiter); ObjectListing objects = s3Client.listObjects(listObjectsRequest); return Lists.transform(objects.getObjectSummaries(), new Function<S3ObjectSummary, String>() { @Override/*from w ww. ja v a 2 s . co m*/ public String apply(@Nonnull final S3ObjectSummary input) { return input.getKey(); } }); }
From source file:org.nuxeo.liveconnect.importer.aws.S3Importer.java
License:Apache License
public void importBucket(DocumentModel rootFolder) { LiveconnectS3Blobprovider blobprovider = (LiveconnectS3Blobprovider) Framework.getService(BlobManager.class) .getBlobProvider(provider);/*w ww .ja v a 2 s . c om*/ AmazonS3 s3 = blobprovider.getClient(); String bucketName = blobprovider.getBucketName(); final ListObjectsRequest req = new ListObjectsRequest().withBucketName(bucketName); ObjectListing result; int docsCount = 0; do { result = s3.listObjects(req); for (S3ObjectSummary objectSummary : result.getObjectSummaries()) { String name = S3LiveConnectFile.getFilename(objectSummary.getKey()); if (name == null) continue; DocumentModel fileDoc = getOrCreateFileDocument(rootFolder, objectSummary.getKey(), name); //import object LiveConnectFileInfo info = new LiveConnectFileInfo( rootFolder.getCoreSession().getPrincipal().getName(), objectSummary.getKey(), objectSummary.getETag()); LiveConnectBlobProvider blobProvider = (LiveConnectBlobProvider) Framework .getService(BlobManager.class).getBlobProvider(provider); try { Blob blob = blobProvider.toBlob(info); fileDoc.setPropertyValue("file:content", (Serializable) blob); fileDoc.getCoreSession().saveDocument(fileDoc); } catch (IOException e) { log.warn("Couldn't get Blob with ID " + info.getFileId(), e); } docsCount++; if (docsCount % 10 == 0) { rootFolder.getCoreSession().save(); if (TransactionHelper.isTransactionActive()) { TransactionHelper.commitOrRollbackTransaction(); TransactionHelper.startTransaction(); } } } req.setMarker(result.getNextMarker()); } while (result.isTruncated()); rootFolder.getCoreSession().save(); if (TransactionHelper.isTransactionActive()) { TransactionHelper.commitOrRollbackTransaction(); TransactionHelper.startTransaction(); } }
From source file:org.onebusaway.admin.service.impl.S3FileServiceImpl.java
License:Apache License
@Override /**//from w ww . j ava 2 s . c o m * Return tabular data (filename, flag, modified date) about bundle directories. */ public List<String[]> listBundleDirectories(int maxResults) { List<String[]> rows = new ArrayList<String[]>(); HashMap<String, String> map = new HashMap<String, String>(); ListObjectsRequest request = new ListObjectsRequest(_bucketName, null, null, "/", maxResults); ObjectListing listing = null; do { if (listing == null) { listing = _s3.listObjects(request); if (listing.getCommonPrefixes() != null) { // short circuit if common prefixes works List<String> commonPrefixes = listing.getCommonPrefixes(); for (String key : commonPrefixes) { Date lastModified = getLastModifiedTimeForKey(key); String lastModifiedStr = "n/a"; if (lastModified != null) { lastModifiedStr = "" + lastModified.toString(); } String[] columns = { parseKey(key), getStatus(key), lastModifiedStr }; rows.add(columns); } return rows; } _log.error("prefixes=" + listing.getCommonPrefixes()); } else { listing = _s3.listNextBatchOfObjects(listing); } for (S3ObjectSummary summary : listing.getObjectSummaries()) { String key = parseKey(summary.getKey()); if (!map.containsKey(key)) { String[] columns = { key, " ", "" + summary.getLastModified().getTime() }; rows.add(columns); map.put(key, key); } } } while (listing.isTruncated()); return rows; }
From source file:org.onebusaway.admin.service.impl.S3FileServiceImpl.java
License:Apache License
@Override /**/*from ww w .j a va 2s. c o m*/ * list the files in the given directory. */ public List<String> list(String directory, int maxResults) { ListObjectsRequest request = new ListObjectsRequest(_bucketName, directory, null, null, maxResults); ObjectListing listing = _s3.listObjects(request); List<String> rows = new ArrayList<String>(); for (S3ObjectSummary summary : listing.getObjectSummaries()) { // if its a directory at the root level if (!summary.getKey().endsWith("/")) { rows.add(summary.getKey()); } } return rows; }