Skip to content

Commit

Permalink
Allow to specify region and path access style.
Browse files Browse the repository at this point in the history
The property "sys.ai.h2o.persist.s3.region" can specify S3 region.
The property "sys.ai.h2o.persist.s3.enable.path.style" can force path style acces.
  • Loading branch information
mmalohlava committed Sep 23, 2016
1 parent 6c0fdd7 commit add67c5
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion h2o-persist-s3/src/main/java/water/persist/PersistS3.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
import com.amazonaws.*;
import com.amazonaws.auth.*;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.regions.*;
import com.amazonaws.regions.Region;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.S3ClientOptions;
import com.amazonaws.services.s3.model.*;

import com.google.common.io.ByteStreams;
Expand Down Expand Up @@ -301,6 +304,12 @@ private static ObjectMetadata getObjectMetadataForKey(Key k) {
public final static String S3_FORCE_HTTP = SYSTEM_PROP_PREFIX + "persist.s3.force.http";
/** S3 end-point, for example: "https://localhost:9000 */
public final static String S3_END_POINT = SYSTEM_PROP_PREFIX + "persist.s3.endPoint";
/** S3 region, for example "us-east-1",
* see {@link com.amazonaws.regions.Region#getRegion(com.amazonaws.regions.Regions)} for region list */
public final static String S3_REGION = SYSTEM_PROP_PREFIX + "persist.s3.region";
/** Enable S3 path style access via setting the property to true.
* See: {@link com.amazonaws.services.s3.S3ClientOptions#setPathStyleAccess(boolean)} */
public final static String S3_ENABLE_PATH_STYLE = SYSTEM_PROP_PREFIX + "persist.s3.enable.path.style";


static ClientConfiguration s3ClientCfg() {
Expand All @@ -317,7 +326,20 @@ static ClientConfiguration s3ClientCfg() {

static AmazonS3Client configureClient(AmazonS3Client s3Client) {
if (System.getProperty(S3_END_POINT) != null) {
s3Client.setEndpoint(System.getProperty(S3_END_POINT));
String endPoint = System.getProperty(S3_END_POINT);
Log.debug("S3 endpoint specified: ", endPoint);
s3Client.setEndpoint(endPoint);
}
if (System.getProperty(S3_REGION) != null) {
String region = System.getProperty(S3_REGION);
Log.debug("S3 region specified: ", region);
s3Client.setRegion(RegionUtils.getRegion(region));
}
if (System.getProperty(S3_ENABLE_PATH_STYLE) != null && Boolean.valueOf(System.getProperty(S3_ENABLE_PATH_STYLE))) {
Log.debug("S3 path style access enabled");
S3ClientOptions sco = new S3ClientOptions();
sco.setPathStyleAccess(true);
s3Client.setS3ClientOptions(sco);
}
return s3Client;
}
Expand Down

0 comments on commit add67c5

Please sign in to comment.