use of com.amazonaws.services.s3.AmazonS3Client in project opentest by mcdcorp.
the class PutS3Object method run.
@Override
public void run() {
super.run();
String awsCredentialsProfile = this.readStringArgument("awsProfile", "default");
String bucket = this.readStringArgument("bucket");
String objectKey = this.readStringArgument("objectKey");
String sourceFilePath = this.readStringArgument("sourceFile");
File sourceFile = new File(sourceFilePath);
if (sourceFile.exists()) {
try {
AmazonS3 s3Client = new AmazonS3Client(new ProfileCredentialsProvider(awsCredentialsProfile));
s3Client.putObject(new PutObjectRequest(bucket, objectKey, sourceFile));
} catch (Exception ex) {
throw new RuntimeException(String.format("Failed to upload file \"%s\" to S3 bucket \"%s\"", sourceFilePath, bucket), ex);
}
} else {
throw new RuntimeException(String.format("Source file \"%s\" doesn't exist", sourceFilePath));
}
}
use of com.amazonaws.services.s3.AmazonS3Client in project ice by Netflix.
the class BasicManagers method doWork.
private void doWork() {
logger.info("trying to find new tag group and data managers...");
Set<Product> products = Sets.newHashSet(this.products);
Map<Product, BasicTagGroupManager> tagGroupManagers = Maps.newHashMap(this.tagGroupManagers);
TreeMap<Key, BasicDataManager> costManagers = Maps.newTreeMap(this.costManagers);
TreeMap<Key, BasicDataManager> usageManagers = Maps.newTreeMap(this.usageManagers);
Set<Product> newProducts = Sets.newHashSet();
AmazonS3Client s3Client = AwsUtils.getAmazonS3Client();
for (S3ObjectSummary s3ObjectSummary : s3Client.listObjects(config.workS3BucketName, config.workS3BucketPrefix + TagGroupWriter.DB_PREFIX).getObjectSummaries()) {
String key = s3ObjectSummary.getKey();
Product product;
if (key.endsWith("_all")) {
product = null;
} else {
String name = key.substring((config.workS3BucketPrefix + TagGroupWriter.DB_PREFIX).length());
name = Tag.fromS3(name);
product = config.productService.getProductByName(name);
}
if (!products.contains(product)) {
products.add(product);
newProducts.add(product);
}
}
for (Product product : newProducts) {
tagGroupManagers.put(product, new BasicTagGroupManager(product));
for (ConsolidateType consolidateType : ConsolidateType.values()) {
Key key = new Key(product, consolidateType);
costManagers.put(key, new BasicDataManager(product, consolidateType, true));
usageManagers.put(key, new BasicDataManager(product, consolidateType, false));
}
}
if (newProducts.size() > 0) {
this.costManagers = costManagers;
this.usageManagers = usageManagers;
this.tagGroupManagers = tagGroupManagers;
this.products = products;
}
}
use of com.amazonaws.services.s3.AmazonS3Client in project ice by Netflix.
the class BillingFileProcessor method updateLastMillis.
private void updateLastMillis(long millis, String filename) {
AmazonS3Client s3Client = AwsUtils.getAmazonS3Client();
s3Client.putObject(config.workS3BucketName, config.workS3BucketPrefix + filename, IOUtils.toInputStream(millis + ""), new ObjectMetadata());
}
use of com.amazonaws.services.s3.AmazonS3Client in project ice by Netflix.
the class MapDb method upload.
void upload() {
AmazonS3Client s3Client = AwsUtils.getAmazonS3Client();
File dir = new File(config.localDir);
File[] files = dir.listFiles(new FilenameFilter() {
public boolean accept(File file, String fileName) {
return fileName.startsWith(dbName);
}
});
for (File file : files) s3Client.putObject(config.workS3BucketName, config.workS3BucketPrefix + file.getName(), file);
for (File file : files) s3Client.putObject(config.workS3BucketName, config.workS3BucketPrefix + "copy" + file.getName(), file);
}
use of com.amazonaws.services.s3.AmazonS3Client in project jackrabbit by apache.
the class TestS3Ds method deleteBucket.
public void deleteBucket(String bucket) throws Exception {
LOG.info("deleting bucket [" + bucket + "]");
Properties props = Utils.readConfig(config);
AmazonS3Client s3service = Utils.openService(props);
TransferManager tmx = new TransferManager(s3service);
if (s3service.doesBucketExist(bucket)) {
for (int i = 0; i < 4; i++) {
tmx.abortMultipartUploads(bucket, startTime);
ObjectListing prevObjectListing = s3service.listObjects(bucket);
while (prevObjectListing != null) {
List<DeleteObjectsRequest.KeyVersion> deleteList = new ArrayList<DeleteObjectsRequest.KeyVersion>();
for (S3ObjectSummary s3ObjSumm : prevObjectListing.getObjectSummaries()) {
deleteList.add(new DeleteObjectsRequest.KeyVersion(s3ObjSumm.getKey()));
}
if (deleteList.size() > 0) {
DeleteObjectsRequest delObjsReq = new DeleteObjectsRequest(bucket);
delObjsReq.setKeys(deleteList);
s3service.deleteObjects(delObjsReq);
}
if (!prevObjectListing.isTruncated())
break;
prevObjectListing = s3service.listNextBatchOfObjects(prevObjectListing);
}
}
s3service.deleteBucket(bucket);
LOG.info("bucket [ " + bucket + "] deleted");
} else {
LOG.info("bucket [" + bucket + "] doesn't exists");
}
tmx.shutdownNow();
s3service.shutdown();
}
Aggregations