Index: src/main/java/org/apache/jackrabbit/aws/ext/Utils.java =================================================================== --- src/main/java/org/apache/jackrabbit/aws/ext/Utils.java (Revision 1707674) +++ src/main/java/org/apache/jackrabbit/aws/ext/Utils.java (Arbeitskopie) @@ -30,10 +30,11 @@ import com.amazonaws.Protocol; import com.amazonaws.auth.AWSCredentials; import com.amazonaws.auth.BasicAWSCredentials; -import com.amazonaws.services.s3.model.Region; +import com.amazonaws.regions.Regions; import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3Client; import com.amazonaws.services.s3.model.ObjectListing; +import com.amazonaws.services.s3.model.Region; import com.amazonaws.services.s3.model.S3ObjectSummary; import com.amazonaws.util.StringUtils; @@ -73,7 +74,7 @@ /** * Create AmazonS3Client from properties. - * + * * @param prop properties to configure @link {@link AmazonS3Client} * @return {@link AmazonS3Client} */ @@ -93,26 +94,32 @@ 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; + if ( region == null && Regions.getCurrentRegion() != null ) { + // this sets both, the region and the endpoint + s3service.setRegion(Regions.getCurrentRegion()); + LOG.info("S3 service region [{}] ", Regions.getCurrentRegion()); } else { - 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; + String endpoint = null; + String propEndPoint = prop.getProperty(S3Constants.S3_END_POINT); + if ((propEndPoint != null) & !"".equals(propEndPoint)) { + endpoint = propEndPoint; } else { - endpoint = S3 + DASH + region + DOT + AWSDOTCOM; + 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); } - /* - * 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; } @@ -119,7 +126,7 @@ /** * Delete S3 bucket. This method first deletes all objects from bucket and * then delete empty bucket. - * + * * @param bucketName the bucket name. */ public static void deleteBucket(final String bucketName) throws IOException { @@ -141,7 +148,7 @@ /** * Read a configuration properties file. If the file name ends with ";burn", * the file is deleted after reading. - * + * * @param fileName the properties file name * @return the properties * @throws IOException if the file doesn't exist @@ -184,30 +191,30 @@ int socketTimeOut = Integer.parseInt(prop.getProperty(S3Constants.S3_SOCK_TIMEOUT)); int maxConnections = Integer.parseInt(prop.getProperty(S3Constants.S3_MAX_CONNS)); int maxErrorRetry = Integer.parseInt(prop.getProperty(S3Constants.S3_MAX_ERR_RETRY)); - + String protocol = prop.getProperty(S3Constants.S3_CONN_PROTOCOL); String proxyHost = prop.getProperty(S3Constants.PROXY_HOST); String proxyPort = prop.getProperty(S3Constants.PROXY_PORT); - + ClientConfiguration cc = new ClientConfiguration(); - + if (protocol != null && protocol.equalsIgnoreCase("http")) { cc.setProtocol(Protocol.HTTP); } - + if (proxyHost != null && !proxyHost.isEmpty()) { cc.setProxyHost(proxyHost); } - + if (proxyPort != null && !proxyPort.isEmpty()) { cc.setProxyPort(Integer.parseInt(proxyPort)); } - + cc.setConnectionTimeout(connectionTimeOut); cc.setSocketTimeout(socketTimeOut); cc.setMaxConnections(maxConnections); cc.setMaxErrorRetry(maxErrorRetry); - + return cc; } Index: src/main/java/org/apache/jackrabbit/aws/ext/ds/S3Backend.java =================================================================== --- src/main/java/org/apache/jackrabbit/aws/ext/ds/S3Backend.java (Revision 1707674) +++ src/main/java/org/apache/jackrabbit/aws/ext/ds/S3Backend.java (Arbeitskopie) @@ -59,7 +59,6 @@ import com.amazonaws.services.s3.model.ObjectListing; import com.amazonaws.services.s3.model.ObjectMetadata; import com.amazonaws.services.s3.model.PutObjectRequest; -import com.amazonaws.services.s3.model.Region; import com.amazonaws.services.s3.model.S3Object; import com.amazonaws.services.s3.model.S3ObjectSummary; import com.amazonaws.services.s3.transfer.Copy; @@ -89,7 +88,7 @@ private Properties properties; private Date startTime; - + private ThreadPoolExecutor asyncWriteExecuter; private S3RequestDecorator s3ReqDecorator; @@ -137,23 +136,14 @@ if (bucket == null || "".equals(bucket.trim())) { bucket = prop.getProperty(S3Constants.S3_BUCKET); } - String region = prop.getProperty(S3Constants.S3_REGION); - Region s3Region = null; - if (Utils.DEFAULT_AWS_BUCKET_REGION.equals(region)) { - s3Region = Region.US_Standard; - } else if (Region.EU_Ireland.toString().equals(region)) { - s3Region = Region.EU_Ireland; - } else { - s3Region = Region.fromValue(region); - } - + if (!s3service.doesBucketExist(bucket)) { - s3service.createBucket(bucket, s3Region); - LOG.info("Created bucket [{}] in [{}] ", bucket, region); + s3service.createBucket(bucket, s3service.getRegion()); + LOG.info("Created bucket [{}] in [{}] ", bucket, s3service.getRegion()); } else { - LOG.info("Using bucket [{}] in [{}] ", bucket, region); + LOG.info("Using bucket [{}] in [{}] ", bucket, s3service.getRegion()); } - + int writeThreads = 10; String writeThreadsStr = prop.getProperty(S3Constants.S3_WRITE_THREADS); if (writeThreadsStr != null) { @@ -161,9 +151,9 @@ } LOG.info("Using thread pool of [{}] threads in S3 transfer manager.", writeThreads); tmx = new TransferManager(s3service, - (ThreadPoolExecutor) Executors.newFixedThreadPool(writeThreads, + Executors.newFixedThreadPool(writeThreads, new NamedThreadFactory("s3-transfer-manager-worker"))); - + int asyncWritePoolSize = 10; String maxConnsStr = prop.getProperty(S3Constants.S3_MAX_CONNS); if (maxConnsStr != null) { @@ -170,7 +160,7 @@ asyncWritePoolSize = Integer.parseInt(maxConnsStr) - writeThreads; } - + asyncWriteExecuter = (ThreadPoolExecutor) Executors.newFixedThreadPool( asyncWritePoolSize, new NamedThreadFactory("s3-write-worker")); String renameKeyProp = prop.getProperty(S3Constants.S3_RENAME_KEYS); @@ -299,7 +289,7 @@ retVal, (System.currentTimeMillis() - start) }); return retVal; } - + @Override public void touchAsync(final DataIdentifier identifier, final long minModifiedDate, final AsyncTouchCallback callback) @@ -528,7 +518,7 @@ // order is important here && s3service.getObjectMetadata(bucket, s3ObjSumm.getKey()).getLastModified().getTime() < min) { - + store.deleteFromCache(identifier); LOG.debug("add id [{}] to delete lists", s3ObjSumm.getKey()); @@ -659,7 +649,7 @@ identifier); } else { up.waitForUploadResult(); - LOG.debug("synchronous upload to identifier [{}] completed.", identifier); + LOG.debug("synchronous upload to identifier [{}] completed.", identifier); if (callback != null) { callback.onSuccess(new AsyncUploadResult( identifier, file)); @@ -670,7 +660,7 @@ asyncUpRes.setException(e2); if (callback != null) { callback.onAbort(asyncUpRes); - } + } throw new DataStoreException("Could not upload " + key, e2); } } @@ -795,8 +785,8 @@ } return key.substring(0, 4) + key.substring(5); } - + /** * The class renames object key in S3 in a thread. */ @@ -804,6 +794,7 @@ private String oldKey; + @Override public void run() { ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); try { @@ -843,7 +834,7 @@ private DataIdentifier identifier; private AsyncUploadCallback callback; - + private Upload upload; public S3UploadProgressListener(Upload upload, DataIdentifier identifier, File file, @@ -855,6 +846,7 @@ this.upload = upload; } + @Override public void progressChanged(ProgressEvent progressEvent) { switch (progressEvent.getEventCode()) { case ProgressEvent.COMPLETED_EVENT_CODE: @@ -878,7 +870,7 @@ } } } - + /** * This class implements {@link Runnable} interface to upload {@link File} * to S3 asynchronously. @@ -899,6 +891,7 @@ this.callback = callback; } + @Override public void run() { try { write(identifier, file, true, callback);