Skip to content

Commit

Permalink
Discovery EC2: Remove region setting (#23991)
Browse files Browse the repository at this point in the history
We have both endpoint and region settings. Region was removed from s3 to
simplify configuration. This is the ec2 equivalent.

closes #22758
  • Loading branch information
rjernst authored Apr 8, 2017
1 parent 05e2ea1 commit 83ba677
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 123 deletions.
3 changes: 3 additions & 0 deletions docs/reference/migration/migrate_6_0/plugins.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ See {plugins}/repository-azure-usage.html#repository-azure-repository-settings[A
==== EC2 Discovery plugin

* Specifying ec2 signer type has been removed, including `cloud.aws.signer` and `cloud.aws.ec2.signer`.

* The region setting has been removed. This includes the settings `cloud.aws.region`
and `cloud.aws.ec2.region`. Instead, specify the full endpoint.
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ interface AwsEc2Service {
*/
Setting<SecureString> PROXY_PASSWORD_SETTING = new Setting<>("cloud.aws.proxy.password", "", SecureString::new,
Property.NodeScope, Property.Filtered, Property.Shared, Property.Deprecated);
/**
* cloud.aws.region: Region. Shared with repository-s3 plugin
*/
Setting<String> REGION_SETTING =
new Setting<>("cloud.aws.region", "", s -> s.toLowerCase(Locale.ROOT), Property.NodeScope, Property.Shared, Property.Deprecated);
/**
* cloud.aws.read_timeout: Socket read timeout. Shared with repository-s3 plugin
*/
Expand Down Expand Up @@ -136,12 +131,6 @@ interface CLOUD_EC2 {
*/
Setting<SecureString> PROXY_PASSWORD_SETTING = new Setting<>("cloud.aws.ec2.proxy.password", AwsEc2Service.PROXY_PASSWORD_SETTING,
SecureString::new, Property.NodeScope, Property.Filtered, Property.Deprecated);
/**
* cloud.aws.ec2.region: Region specific for EC2 API calls. Defaults to cloud.aws.region.
* @see AwsEc2Service#REGION_SETTING
*/
Setting<String> REGION_SETTING = new Setting<>("cloud.aws.ec2.region", AwsEc2Service.REGION_SETTING,
s -> s.toLowerCase(Locale.ROOT), Property.NodeScope, Property.Deprecated);
/**
* cloud.aws.ec2.endpoint: Endpoint. If not set, endpoint will be guessed based on region setting.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,72 +131,6 @@ protected static String findEndpoint(Logger logger, Settings settings) {
if (DISCOVERY_EC2.ENDPOINT_SETTING.exists(settings) || CLOUD_EC2.ENDPOINT_SETTING.exists(settings)) {
endpoint = DISCOVERY_EC2.ENDPOINT_SETTING.get(settings);
logger.debug("using explicit ec2 endpoint [{}]", endpoint);
} else if (REGION_SETTING.exists(settings) || CLOUD_EC2.REGION_SETTING.exists(settings)) {
final String region = CLOUD_EC2.REGION_SETTING.get(settings);
switch (region) {
case "us-east-1":
case "us-east":
endpoint = "ec2.us-east-1.amazonaws.com";
break;
case "us-east-2":
endpoint = "ec2.us-east-2.amazonaws.com";
break;
case "us-west":
case "us-west-1":
endpoint = "ec2.us-west-1.amazonaws.com";
break;
case "us-west-2":
endpoint = "ec2.us-west-2.amazonaws.com";
break;
case "ap-southeast":
case "ap-southeast-1":
endpoint = "ec2.ap-southeast-1.amazonaws.com";
break;
case "ap-south":
case "ap-south-1":
endpoint = "ec2.ap-south-1.amazonaws.com";
break;
case "us-gov-west":
case "us-gov-west-1":
endpoint = "ec2.us-gov-west-1.amazonaws.com";
break;
case "ap-southeast-2":
endpoint = "ec2.ap-southeast-2.amazonaws.com";
break;
case "ap-northeast":
case "ap-northeast-1":
endpoint = "ec2.ap-northeast-1.amazonaws.com";
break;
case "ap-northeast-2":
endpoint = "ec2.ap-northeast-2.amazonaws.com";
break;
case "eu-west":
case "eu-west-1":
endpoint = "ec2.eu-west-1.amazonaws.com";
break;
case "eu-west-2":
endpoint = "ec2.eu-west-2.amazonaws.com";
break;
case "eu-central":
case "eu-central-1":
endpoint = "ec2.eu-central-1.amazonaws.com";
break;
case "sa-east":
case "sa-east-1":
endpoint = "ec2.sa-east-1.amazonaws.com";
break;
case "cn-north":
case "cn-north-1":
endpoint = "ec2.cn-north-1.amazonaws.com.cn";
break;
case "ca-central":
case "ca-central-1":
endpoint = "ec2.ca-central-1.amazonaws.com";
break;
default:
throw new IllegalArgumentException("No automatic endpoint could be derived from region [" + region + "]");
}
logger.debug("using ec2 region [{}], with endpoint [{}]", region, endpoint);
}
return endpoint;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ public List<Setting<?>> getSettings() {
AwsEc2Service.PROXY_PORT_SETTING,
AwsEc2Service.PROXY_USERNAME_SETTING,
AwsEc2Service.PROXY_PASSWORD_SETTING,
AwsEc2Service.REGION_SETTING,
AwsEc2Service.READ_TIMEOUT,
// Register EC2 specific settings: cloud.aws.ec2
AwsEc2Service.CLOUD_EC2.KEY_SETTING,
Expand All @@ -137,7 +136,6 @@ public List<Setting<?>> getSettings() {
AwsEc2Service.CLOUD_EC2.PROXY_PORT_SETTING,
AwsEc2Service.CLOUD_EC2.PROXY_USERNAME_SETTING,
AwsEc2Service.CLOUD_EC2.PROXY_PASSWORD_SETTING,
AwsEc2Service.CLOUD_EC2.REGION_SETTING,
AwsEc2Service.CLOUD_EC2.ENDPOINT_SETTING,
AwsEc2Service.CLOUD_EC2.READ_TIMEOUT,
// Register EC2 discovery settings: discovery.ec2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,41 +210,4 @@ public void testSpecificEndpointBackcompat() {
AwsEc2Service.CLOUD_EC2.ENDPOINT_SETTING
});
}

public void testRegionWithAwsSettings() {
Settings settings = Settings.builder()
.put(AwsEc2Service.REGION_SETTING.getKey(), randomFrom("eu-west", "eu-west-1"))
.build();
String endpoint = AwsEc2ServiceImpl.findEndpoint(logger, settings);
assertThat(endpoint, is("ec2.eu-west-1.amazonaws.com"));
assertSettingDeprecationsAndWarnings(new Setting<?>[] {
AwsEc2Service.REGION_SETTING
});
}

public void testRegionWithAwsAndEc2Settings() {
Settings settings = Settings.builder()
.put(AwsEc2Service.REGION_SETTING.getKey(), randomFrom("eu-west", "eu-west-1"))
.put(AwsEc2Service.CLOUD_EC2.REGION_SETTING.getKey(), randomFrom("us-west", "us-west-1"))
.build();
String endpoint = AwsEc2ServiceImpl.findEndpoint(logger, settings);
assertThat(endpoint, is("ec2.us-west-1.amazonaws.com"));
assertSettingDeprecationsAndWarnings(new Setting<?>[] {
AwsEc2Service.REGION_SETTING,
AwsEc2Service.CLOUD_EC2.REGION_SETTING
});
}

public void testInvalidRegion() {
Settings settings = Settings.builder()
.put(AwsEc2Service.REGION_SETTING.getKey(), "does-not-exist")
.build();
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> {
AwsEc2ServiceImpl.findEndpoint(logger, settings);
});
assertThat(e.getMessage(), containsString("No automatic endpoint could be derived from region"));
assertSettingDeprecationsAndWarnings(new Setting<?>[] {
AwsEc2Service.REGION_SETTING
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public class Ec2DiscoverySettingsTests extends ESTestCase {
.put(AwsEc2Service.PROXY_PORT_SETTING.getKey(), 10000)
.put(AwsEc2Service.PROXY_USERNAME_SETTING.getKey(), "global-proxy-username")
.put(AwsEc2Service.PROXY_PASSWORD_SETTING.getKey(), "global-proxy-password")
.put(AwsEc2Service.REGION_SETTING.getKey(), "global-region")
.build();

private static final Settings EC2 = Settings.builder()
Expand All @@ -48,7 +47,6 @@ public class Ec2DiscoverySettingsTests extends ESTestCase {
.put(AwsEc2Service.CLOUD_EC2.PROXY_PORT_SETTING.getKey(), 20000)
.put(AwsEc2Service.CLOUD_EC2.PROXY_USERNAME_SETTING.getKey(), "ec2-proxy-username")
.put(AwsEc2Service.CLOUD_EC2.PROXY_PASSWORD_SETTING.getKey(), "ec2-proxy-password")
.put(AwsEc2Service.CLOUD_EC2.REGION_SETTING.getKey(), "ec2-region")
.put(AwsEc2Service.CLOUD_EC2.ENDPOINT_SETTING.getKey(), "ec2-endpoint")
.build();

Expand All @@ -64,7 +62,6 @@ public void testRepositorySettingsGlobalOnly() {
assertThat(AwsEc2Service.CLOUD_EC2.PROXY_PORT_SETTING.get(nodeSettings), is(10000));
assertThat(AwsEc2Service.CLOUD_EC2.PROXY_USERNAME_SETTING.get(nodeSettings), is("global-proxy-username"));
assertThat(AwsEc2Service.CLOUD_EC2.PROXY_PASSWORD_SETTING.get(nodeSettings), is("global-proxy-password"));
assertThat(AwsEc2Service.CLOUD_EC2.REGION_SETTING.get(nodeSettings), is("global-region"));
assertThat(AwsEc2Service.CLOUD_EC2.ENDPOINT_SETTING.get(nodeSettings), isEmptyString());
assertSettingDeprecationsAndWarnings(new Setting<?>[] {
AwsEc2Service.KEY_SETTING,
Expand All @@ -74,7 +71,6 @@ public void testRepositorySettingsGlobalOnly() {
AwsEc2Service.PROXY_PORT_SETTING,
AwsEc2Service.PROXY_USERNAME_SETTING,
AwsEc2Service.PROXY_PASSWORD_SETTING,
AwsEc2Service.REGION_SETTING
});
}

Expand All @@ -90,7 +86,6 @@ public void testRepositorySettingsGlobalOverloadedByEC2() {
assertThat(AwsEc2Service.CLOUD_EC2.PROXY_PORT_SETTING.get(nodeSettings), is(20000));
assertThat(AwsEc2Service.CLOUD_EC2.PROXY_USERNAME_SETTING.get(nodeSettings), is("ec2-proxy-username"));
assertThat(AwsEc2Service.CLOUD_EC2.PROXY_PASSWORD_SETTING.get(nodeSettings), is("ec2-proxy-password"));
assertThat(AwsEc2Service.CLOUD_EC2.REGION_SETTING.get(nodeSettings), is("ec2-region"));
assertThat(AwsEc2Service.CLOUD_EC2.ENDPOINT_SETTING.get(nodeSettings), is("ec2-endpoint"));
assertSettingDeprecationsAndWarnings(new Setting<?>[] {
AwsEc2Service.KEY_SETTING,
Expand All @@ -100,15 +95,13 @@ public void testRepositorySettingsGlobalOverloadedByEC2() {
AwsEc2Service.PROXY_PORT_SETTING,
AwsEc2Service.PROXY_USERNAME_SETTING,
AwsEc2Service.PROXY_PASSWORD_SETTING,
AwsEc2Service.REGION_SETTING,
AwsEc2Service.CLOUD_EC2.KEY_SETTING,
AwsEc2Service.CLOUD_EC2.SECRET_SETTING,
AwsEc2Service.CLOUD_EC2.PROTOCOL_SETTING,
AwsEc2Service.CLOUD_EC2.PROXY_HOST_SETTING,
AwsEc2Service.CLOUD_EC2.PROXY_PORT_SETTING,
AwsEc2Service.CLOUD_EC2.PROXY_USERNAME_SETTING,
AwsEc2Service.CLOUD_EC2.PROXY_PASSWORD_SETTING,
AwsEc2Service.CLOUD_EC2.REGION_SETTING,
AwsEc2Service.CLOUD_EC2.ENDPOINT_SETTING
});
}
Expand Down

0 comments on commit 83ba677

Please sign in to comment.