Cloud AWS: Change endpoint parameters to distinguish between ec2 and s3, closes #574.

This commit is contained in:
kimchy 2010-12-23 09:13:44 +02:00
parent f869951364
commit 9361e3bd2b
5 changed files with 75 additions and 7 deletions

View File

@ -70,8 +70,31 @@ public class AwsEc2Service extends AbstractLifecycleComponent<AwsEc2Service> {
this.client = new AmazonEC2Client(new BasicAWSCredentials(account, key), clientConfiguration);
if (componentSettings.get("endpoint") != null) {
client.setEndpoint(componentSettings.get("endpoint"));
if (componentSettings.get("ec2.endpoint") != null) {
client.setEndpoint(componentSettings.get("ec2.endpoint"));
} else if (componentSettings.get("region") != null) {
String endpoint;
String region = componentSettings.get("region");
if ("us-east".equals(region.toLowerCase())) {
endpoint = "ec2.us-east-1.amazonaws.com";
} else if ("us-east-1".equals(region.toLowerCase())) {
endpoint = "ec2.us-east-1.amazonaws.com";
} else if ("us-west".equals(region.toLowerCase())) {
endpoint = "ec2.us-west-1.amazonaws.com";
} else if ("us-west-1".equals(region.toLowerCase())) {
endpoint = "ec2.us-west-1.amazonaws.com";
} else if ("ap-southeast".equals(region.toLowerCase())) {
endpoint = "ec2.ap-southeast-1.amazonaws.com";
} else if ("ap-southeast-1".equals(region.toLowerCase())) {
endpoint = "ec2.ap-southeast-1.amazonaws.com";
} else if ("eu-west".equals(region.toLowerCase())) {
endpoint = "ec2.eu-west-1.amazonaws.com";
} else if ("eu-west-1".equals(region.toLowerCase())) {
endpoint = "ec2.eu-west-1.amazonaws.com";
} else {
throw new ElasticSearchIllegalArgumentException("No automatic endpoint could be derived from region [" + region + "]");
}
client.setEndpoint(endpoint);
}
return this.client;

View File

@ -70,8 +70,31 @@ public class AwsS3Service extends AbstractLifecycleComponent<AwsS3Service> {
this.client = new AmazonS3Client(new BasicAWSCredentials(account, key), clientConfiguration);
if (componentSettings.get("endpoint") != null) {
client.setEndpoint(componentSettings.get("endpoint"));
if (componentSettings.get("s3.endpoint") != null) {
client.setEndpoint(componentSettings.get("s3.endpoint"));
} else if (componentSettings.get("region") != null) {
String endpoint;
String region = componentSettings.get("region");
if ("us-east".equals(region.toLowerCase())) {
endpoint = "s3.amazonaws.com";
} else if ("us-east-1".equals(region.toLowerCase())) {
endpoint = "s3.amazonaws.com";
} else if ("us-west".equals(region.toLowerCase())) {
endpoint = "s3-us-west-1.amazonaws.com";
} else if ("us-west-1".equals(region.toLowerCase())) {
endpoint = "s3-us-west-1.amazonaws.com";
} else if ("ap-southeast".equals(region.toLowerCase())) {
endpoint = "s3-ap-southeast-1.amazonaws.com";
} else if ("ap-southeast-1".equals(region.toLowerCase())) {
endpoint = "s3-ap-southeast-1.amazonaws.com";
} else if ("eu-west".equals(region.toLowerCase())) {
endpoint = null; // no specific endpoint for EU (still can be used for region)
} else if ("eu-west-1".equals(region.toLowerCase())) {
endpoint = null; // no specific endpoint for EU (still can be used for region)
} else {
throw new ElasticSearchIllegalArgumentException("No automatic endpoint could be derived from region [" + region + "]");
}
client.setEndpoint(endpoint);
}
return this.client;

View File

@ -35,13 +35,13 @@ import java.io.InputStream;
/**
* @author kimchy (shay.banon)
*/
public class AbstarctS3BlobContainer extends AbstractBlobContainer {
public class AbstractS3BlobContainer extends AbstractBlobContainer {
protected final S3BlobStore blobStore;
protected final String keyPath;
public AbstarctS3BlobContainer(BlobPath path, S3BlobStore blobStore) {
public AbstractS3BlobContainer(BlobPath path, S3BlobStore blobStore) {
super(path);
this.blobStore = blobStore;
this.keyPath = path.buildAsString("/") + "/";

View File

@ -31,7 +31,7 @@ import java.io.InputStream;
/**
* @author kimchy (shay.banon)
*/
public class S3ImmutableBlobContainer extends AbstarctS3BlobContainer implements ImmutableBlobContainer {
public class S3ImmutableBlobContainer extends AbstractS3BlobContainer implements ImmutableBlobContainer {
public S3ImmutableBlobContainer(BlobPath path, S3BlobStore blobStore) {
super(path, blobStore);

View File

@ -52,6 +52,28 @@ public class S3Gateway extends BlobStoreGateway {
}
String region = componentSettings.get("region");
if (region == null) {
if (settings.get("cloud.aws.region") != null) {
String regionSetting = settings.get("cloud.aws.region");
if ("us-east".equals(regionSetting.toLowerCase())) {
region = null;
} else if ("us-east-1".equals(regionSetting.toLowerCase())) {
region = null;
} else if ("us-west".equals(regionSetting.toLowerCase())) {
region = "us-west-1";
} else if ("us-west-1".equals(regionSetting.toLowerCase())) {
region = "us-west-1";
} else if ("ap-southeast".equals(regionSetting.toLowerCase())) {
region = "ap-southeast-1";
} else if ("ap-southeast-1".equals(regionSetting.toLowerCase())) {
region = "ap-southeast-1";
} else if ("eu-west".equals(regionSetting.toLowerCase())) {
region = "EU";
} else if ("eu-west-1".equals(regionSetting.toLowerCase())) {
region = "EU";
}
}
}
ByteSizeValue chunkSize = componentSettings.getAsBytesSize("chunk_size", new ByteSizeValue(100, ByteSizeUnit.MB));
logger.debug("using bucket [{}], region [{}], chunk_size [{}]", bucket, region, chunkSize);