From 30d80cc27dcc2d60171e3623c938b7693e6f4007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Reni=C3=A9?= Date: Fri, 21 Nov 2014 17:49:33 +0100 Subject: [PATCH] Allow per-repo protocols Also add an integration test for custom endpoints/protocols. --- README.md | 9 ++++++- .../elasticsearch/cloud/aws/AwsS3Service.java | 4 +-- .../cloud/aws/InternalAwsS3Service.java | 26 +++++++++---------- .../repositories/s3/S3Repository.java | 9 ++++--- .../cloud/aws/TestAwsS3Service.java | 8 +++--- .../s3/AbstractS3SnapshotRestoreTest.java | 20 +++++++++++++- 6 files changed, 52 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 90857a82a9a..bfb00afc28d 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,7 @@ The following settings are supported: * `bucket`: The name of the bucket to be used for snapshots. (Mandatory) * `region`: The region where bucket is located. Defaults to US Standard * `endpoint`: The endpoint to the S3 API. Defaults to AWS's default S3 endpoint. Note that setting a region overrides the endpoint setting. +* `protocol`: The protocol to use (`http` or `https`). Defaults to `https`. * `base_path`: Specifies the path within bucket to repository data. Defaults to root directory. * `access_key`: The access key to use for authentication. Defaults to value of `cloud.aws.access_key`. * `secret_key`: The secret key to use for authentication. Defaults to value of `cloud.aws.secret_key`. @@ -290,10 +291,16 @@ repositories: remote-bucket: bucket: region: + external-bucket: + bucket: + access_key: + secret_key: + endpoint: + protocol: ``` -Replace all occurrences of `access_key`, `secret_key`, `bucket` and `region` with your settings. Please, note that the test will delete all snapshot/restore related files in the specified buckets. +Replace all occurrences of `access_key`, `secret_key`, `endpoint`, `protocol`, `bucket` and `region` with your settings. Please, note that the test will delete all snapshot/restore related files in the specified buckets. To run test: diff --git a/src/main/java/org/elasticsearch/cloud/aws/AwsS3Service.java b/src/main/java/org/elasticsearch/cloud/aws/AwsS3Service.java index a927441056b..e5db2ed7357 100644 --- a/src/main/java/org/elasticsearch/cloud/aws/AwsS3Service.java +++ b/src/main/java/org/elasticsearch/cloud/aws/AwsS3Service.java @@ -28,7 +28,7 @@ import org.elasticsearch.common.component.LifecycleComponent; public interface AwsS3Service extends LifecycleComponent { AmazonS3 client(); - AmazonS3 client(String endpoint, String region, String account, String key); + AmazonS3 client(String endpoint, String protocol, String region, String account, String key); - AmazonS3 client(String endpoint, String region, String account, String key, Integer maxRetries); + AmazonS3 client(String endpoint, String protocol, String region, String account, String key, Integer maxRetries); } diff --git a/src/main/java/org/elasticsearch/cloud/aws/InternalAwsS3Service.java b/src/main/java/org/elasticsearch/cloud/aws/InternalAwsS3Service.java index 58baadcacf9..076c0f308e7 100644 --- a/src/main/java/org/elasticsearch/cloud/aws/InternalAwsS3Service.java +++ b/src/main/java/org/elasticsearch/cloud/aws/InternalAwsS3Service.java @@ -60,34 +60,32 @@ public class InternalAwsS3Service extends AbstractLifecycleComponent clientDescriptor = new Tuple(endpoint, account); AmazonS3Client client = clients.get(clientDescriptor); if (client != null) { @@ -95,8 +93,10 @@ public class InternalAwsS3Service extends AbstractLifecycleComponent creating s3 repostoriy with endpoint [{}], bucket[{}] and path [{}]", bucketSettings.get("endpoint"), bucketSettings.get("bucket"), basePath); + PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo") + .setType("s3").setSettings(ImmutableSettings.settingsBuilder() + .put("protocol", bucketSettings.get("protocol")) + .put("endpoint", bucketSettings.get("endpoint")) + .put("access_key", bucketSettings.get("access_key")) + .put("secret_key", bucketSettings.get("secret_key")) + ).get(); + assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); + assertRepositoryIsOperational(client, "test-repo"); + } + /** * This test verifies that the test configuration is set up in a manner that * does not make the test {@link #testRepositoryInRemoteRegion()} pointless. @@ -432,6 +449,7 @@ abstract public class AbstractS3SnapshotRestoreTest extends AbstractAwsTest { }; for (Settings bucket : buckets) { String endpoint = bucket.get("endpoint", settings.get("repositories.s3.endpoint")); + String protocol = bucket.get("protocol", settings.get("repositories.s3.protocol")); String region = bucket.get("region", settings.get("repositories.s3.region")); String accessKey = bucket.get("access_key", settings.get("cloud.aws.access_key")); String secretKey = bucket.get("secret_key", settings.get("cloud.aws.secret_key")); @@ -440,7 +458,7 @@ abstract public class AbstractS3SnapshotRestoreTest extends AbstractAwsTest { // We check that settings has been set in elasticsearch.yml integration test file // as described in README assertThat("Your settings in elasticsearch.yml are incorrects. Check README file.", bucketName, notNullValue()); - AmazonS3 client = internalCluster().getInstance(AwsS3Service.class).client(endpoint, region, accessKey, secretKey); + AmazonS3 client = internalCluster().getInstance(AwsS3Service.class).client(endpoint, protocol, region, accessKey, secretKey); try { ObjectListing prevListing = null; //From http://docs.amazonwebservices.com/AmazonS3/latest/dev/DeletingMultipleObjectsUsingJava.html