use of com.talend.shaded.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.talend.shaded.com.amazonaws.services.s3.AmazonS3Client in project alluxio by Alluxio.
the class S3AUnderFileSystem method createInstance.
/**
* Constructs a new instance of {@link S3AUnderFileSystem}.
*
* @param uri the {@link AlluxioURI} for this UFS
* @return the created {@link S3AUnderFileSystem} instance
*/
public static S3AUnderFileSystem createInstance(AlluxioURI uri) {
String bucketName = uri.getHost();
// Set the aws credential system properties based on Alluxio properties, if they are set
if (Configuration.containsKey(PropertyKey.S3A_ACCESS_KEY)) {
System.setProperty(SDKGlobalConfiguration.ACCESS_KEY_SYSTEM_PROPERTY, Configuration.get(PropertyKey.S3A_ACCESS_KEY));
}
if (Configuration.containsKey(PropertyKey.S3A_SECRET_KEY)) {
System.setProperty(SDKGlobalConfiguration.SECRET_KEY_SYSTEM_PROPERTY, Configuration.get(PropertyKey.S3A_SECRET_KEY));
}
// Checks, in order, env variables, system properties, profile file, and instance profile
AWSCredentialsProvider credentials = new AWSCredentialsProviderChain(new DefaultAWSCredentialsProviderChain());
// Set the client configuration based on Alluxio configuration values
ClientConfiguration clientConf = new ClientConfiguration();
// Socket timeout
clientConf.setSocketTimeout(Configuration.getInt(PropertyKey.UNDERFS_S3A_SOCKET_TIMEOUT_MS));
// HTTP protocol
if (Configuration.getBoolean(PropertyKey.UNDERFS_S3A_SECURE_HTTP_ENABLED)) {
clientConf.setProtocol(Protocol.HTTPS);
} else {
clientConf.setProtocol(Protocol.HTTP);
}
// Proxy host
if (Configuration.containsKey(PropertyKey.UNDERFS_S3_PROXY_HOST)) {
clientConf.setProxyHost(Configuration.get(PropertyKey.UNDERFS_S3_PROXY_HOST));
}
// Proxy port
if (Configuration.containsKey(PropertyKey.UNDERFS_S3_PROXY_PORT)) {
clientConf.setProxyPort(Configuration.getInt(PropertyKey.UNDERFS_S3_PROXY_PORT));
}
int numAdminThreads = Configuration.getInt(PropertyKey.UNDERFS_S3_ADMIN_THREADS_MAX);
int numTransferThreads = Configuration.getInt(PropertyKey.UNDERFS_S3_UPLOAD_THREADS_MAX);
int numThreads = Configuration.getInt(PropertyKey.UNDERFS_S3_THREADS_MAX);
if (numThreads < numAdminThreads + numTransferThreads) {
LOG.warn("Configured s3 max threads: {} is less than # admin threads: {} plus transfer " + "threads {}. Using admin threads + transfer threads as max threads instead.");
numThreads = numAdminThreads + numTransferThreads;
}
clientConf.setMaxConnections(numThreads);
// Set client request timeout for all requests since multipart copy is used, and copy parts can
// only be set with the client configuration.
clientConf.setRequestTimeout(Configuration.getInt(PropertyKey.UNDERFS_S3A_REQUEST_TIMEOUT));
AmazonS3Client amazonS3Client = new AmazonS3Client(credentials, clientConf);
// Set a custom endpoint.
if (Configuration.containsKey(PropertyKey.UNDERFS_S3_ENDPOINT)) {
amazonS3Client.setEndpoint(Configuration.get(PropertyKey.UNDERFS_S3_ENDPOINT));
}
// Disable DNS style buckets, this enables path style requests.
if (Configuration.getBoolean(PropertyKey.UNDERFS_S3_DISABLE_DNS_BUCKETS)) {
S3ClientOptions clientOptions = S3ClientOptions.builder().setPathStyleAccess(true).build();
amazonS3Client.setS3ClientOptions(clientOptions);
}
ExecutorService service = ExecutorServiceFactories.fixedThreadPoolExecutorServiceFactory("alluxio-s3-transfer-manager-worker", numTransferThreads).create();
TransferManager transferManager = new TransferManager(amazonS3Client, service);
TransferManagerConfiguration transferConf = new TransferManagerConfiguration();
transferConf.setMultipartCopyThreshold(MULTIPART_COPY_THRESHOLD);
transferManager.setConfiguration(transferConf);
// Default to readable and writable by the user.
short bucketMode = (short) 700;
// There is no known account owner by default.
String accountOwner = "";
// if ACL enabled inherit bucket acl for all the objects.
if (Configuration.getBoolean(PropertyKey.UNDERFS_S3A_INHERIT_ACL)) {
String accountOwnerId = amazonS3Client.getS3AccountOwner().getId();
// Gets the owner from user-defined static mapping from S3 canonical user
// id to Alluxio user name.
String owner = CommonUtils.getValueFromStaticMapping(Configuration.get(PropertyKey.UNDERFS_S3_OWNER_ID_TO_USERNAME_MAPPING), accountOwnerId);
// If there is no user-defined mapping, use the display name.
if (owner == null) {
owner = amazonS3Client.getS3AccountOwner().getDisplayName();
}
accountOwner = owner == null ? accountOwnerId : owner;
AccessControlList acl = amazonS3Client.getBucketAcl(bucketName);
bucketMode = S3AUtils.translateBucketAcl(acl, accountOwnerId);
}
return new S3AUnderFileSystem(uri, amazonS3Client, bucketName, bucketMode, accountOwner, transferManager);
}
use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3Client in project GNS by MobilityFirst.
the class AWSStatusCheck method init.
private static void init() throws Exception {
AWSCredentials credentials = new PropertiesCredentials(new File(CREDENTIALSFILE));
ec2 = new AmazonEC2Client(credentials);
s3 = new AmazonS3Client(credentials);
sdb = new AmazonSimpleDBClient(credentials);
}
use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3Client in project jackrabbit by apache.
the class Utils method openService.
/**
* Create AmazonS3Client from properties.
*
* @param prop properties to configure @link {@link AmazonS3Client}
* @return {@link AmazonS3Client}
*/
public static AmazonS3Client openService(final Properties prop) {
String accessKey = prop.getProperty(S3Constants.ACCESS_KEY);
String secretKey = prop.getProperty(S3Constants.SECRET_KEY);
AmazonS3Client s3service = null;
if (StringUtils.isNullOrEmpty(accessKey) || StringUtils.isNullOrEmpty(secretKey)) {
LOG.info("Configuring Amazon Client from environment");
s3service = new AmazonS3Client(getClientConfiguration(prop));
} else {
LOG.info("Configuring Amazon Client from property file.");
AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
s3service = new AmazonS3Client(credentials, getClientConfiguration(prop));
}
String region = prop.getProperty(S3Constants.S3_REGION);
String endpoint = null;
String propEndPoint = prop.getProperty(S3Constants.S3_END_POINT);
if ((propEndPoint != null) && !"".equals(propEndPoint)) {
endpoint = propEndPoint;
} else {
if (StringUtils.isNullOrEmpty(region)) {
com.amazonaws.regions.Region s3Region = Regions.getCurrentRegion();
if (s3Region != null) {
region = s3Region.getName();
} else {
throw new AmazonClientException("parameter [" + S3Constants.S3_REGION + "] not configured and cannot be derived from environment");
}
}
if (DEFAULT_AWS_BUCKET_REGION.equals(region)) {
endpoint = S3 + DOT + AWSDOTCOM;
} else if (Region.EU_Ireland.toString().equals(region)) {
endpoint = "s3-eu-west-1" + DOT + AWSDOTCOM;
} else {
endpoint = S3 + DASH + region + DOT + AWSDOTCOM;
}
}
/*
* setting endpoint to remove latency of redirection. If endpoint is
* not set, invocation first goes us standard region, which
* redirects it to correct location.
*/
s3service.setEndpoint(endpoint);
LOG.info("S3 service endpoint [{}] ", endpoint);
return s3service;
}
use of com.talend.shaded.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