use of com.amazonaws.services.s3.model.Bucket in project cloudstack by apache.
the class NfsSecondaryStorageResource method s3ListVolume.
Map<Long, TemplateProp> s3ListVolume(S3TO s3) {
String bucket = s3.getBucketName();
// List the objects in the source directory on S3
final List<S3ObjectSummary> objectSummaries = S3Utils.listDirectory(s3, bucket, VOLUME_ROOT_DIR);
if (objectSummaries == null) {
return null;
}
Map<Long, TemplateProp> tmpltInfos = new HashMap<Long, TemplateProp>();
for (S3ObjectSummary objectSummary : objectSummaries) {
String key = objectSummary.getKey();
// String installPath = StringUtils.substringBeforeLast(key,
// S3Utils.SEPARATOR);
Long id = determineS3VolumeIdFromKey(key);
// TODO: how to get volume template name
TemplateProp tInfo = new TemplateProp(id.toString(), key, objectSummary.getSize(), objectSummary.getSize(), true, false);
tmpltInfos.put(id, tInfo);
}
return tmpltInfos;
}
use of com.amazonaws.services.s3.model.Bucket in project cloudstack by apache.
the class S3Utils method deleteDirectory.
public static void deleteDirectory(final ClientOptions clientOptions, final String bucketName, final String directoryName) {
LOGGER.debug(format("Deleting S3 Directory %1$s in bucket %2$s", directoryName, bucketName));
final List<S3ObjectSummary> objects = listDirectory(clientOptions, bucketName, directoryName);
for (final S3ObjectSummary object : objects) {
deleteObject(clientOptions, bucketName, object.getKey());
}
deleteObject(clientOptions, bucketName, directoryName);
}
use of com.amazonaws.services.s3.model.Bucket in project cloudstack by apache.
the class S3Utils method listDirectory.
public static List<S3ObjectSummary> listDirectory(final ClientOptions clientOptions, final String bucketName, final String directory) {
LOGGER.debug(format("Listing S3 directory %1$s in bucket %2$s", directory, bucketName));
List<S3ObjectSummary> objects = new ArrayList<>();
ListObjectsRequest listObjectsRequest = new ListObjectsRequest();
listObjectsRequest.withBucketName(bucketName);
listObjectsRequest.withPrefix(directory);
ObjectListing ol = getAmazonS3Client(clientOptions).listObjects(listObjectsRequest);
if (ol.isTruncated()) {
do {
objects.addAll(ol.getObjectSummaries());
listObjectsRequest.setMarker(ol.getNextMarker());
ol = getAmazonS3Client(clientOptions).listObjects(listObjectsRequest);
} while (ol.isTruncated());
} else {
objects.addAll(ol.getObjectSummaries());
}
if (objects.isEmpty()) {
return emptyList();
}
return unmodifiableList(objects);
}
use of com.amazonaws.services.s3.model.Bucket in project exhibitor by soabase.
the class TestS3BackupProviderBase method testDownload.
@Test
public void testDownload() throws Exception {
InputStream in = null;
OutputStream out = null;
File tempFile = File.createTempFile("test", ".test");
try {
in = new FileInputStream(sourceFile);
PutObjectRequest dummyRequest = new PutObjectRequest("bucket", "exhibitor-backup" + S3BackupProvider.SEPARATOR + "test" + S3BackupProvider.SEPARATOR + 1, in, null);
MockS3Client s3Client = new MockS3Client(null, null);
s3Client.putObject(dummyRequest);
S3BackupProvider provider = new S3BackupProvider(new MockS3ClientFactory(s3Client), new PropertyBasedS3Credential(new Properties()), new PropertyBasedS3ClientConfig(new Properties()), null);
out = new FileOutputStream(tempFile);
provider.downloadBackup(null, new BackupMetaData("test", 1), out, Maps.<String, String>newHashMap());
Assert.assertEquals(Files.toByteArray(sourceFile), Files.toByteArray(tempFile));
} finally {
CloseableUtils.closeQuietly(in);
CloseableUtils.closeQuietly(out);
//noinspection ResultOfMethodCallIgnored
tempFile.delete();
}
}
use of com.amazonaws.services.s3.model.Bucket in project exhibitor by soabase.
the class S3PseudoLock method createFile.
@Override
protected void createFile(String key, byte[] contents) throws Exception {
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(contents.length);
PutObjectRequest request = new PutObjectRequest(bucket, key, new ByteArrayInputStream(contents), metadata);
client.putObject(request);
}
Aggregations