Skip to content

Commit 7a7de12

Browse files
committed
Remove component settings from AbstractComponent
Related to elastic/elasticsearch#9919 Closes #182.
1 parent 20a9991 commit 7a7de12

File tree

7 files changed

+45
-48
lines changed

7 files changed

+45
-48
lines changed

src/main/java/org/elasticsearch/cloud/aws/AwsEc2Service.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,21 @@ public synchronized AmazonEC2 client() {
6363
}
6464

6565
ClientConfiguration clientConfiguration = new ClientConfiguration();
66-
String protocol = componentSettings.get("protocol", "https").toLowerCase();
67-
protocol = componentSettings.get("ec2.protocol", protocol).toLowerCase();
66+
String protocol = settings.get("cloud.aws.protocol", "https").toLowerCase();
67+
protocol = settings.get("cloud.aws.ec2.protocol", protocol).toLowerCase();
6868
if ("http".equals(protocol)) {
6969
clientConfiguration.setProtocol(Protocol.HTTP);
7070
} else if ("https".equals(protocol)) {
7171
clientConfiguration.setProtocol(Protocol.HTTPS);
7272
} else {
7373
throw new ElasticsearchIllegalArgumentException("No protocol supported [" + protocol + "], can either be [http] or [https]");
7474
}
75-
String account = componentSettings.get("access_key", settings.get("cloud.account"));
76-
String key = componentSettings.get("secret_key", settings.get("cloud.key"));
75+
String account = settings.get("cloud.aws.access_key", settings.get("cloud.account"));
76+
String key = settings.get("cloud.aws.secret_key", settings.get("cloud.key"));
7777

78-
String proxyHost = componentSettings.get("proxy_host");
78+
String proxyHost = settings.get("cloud.aws.proxy_host");
7979
if (proxyHost != null) {
80-
String portString = componentSettings.get("proxy_port", "80");
80+
String portString = settings.get("cloud.aws.proxy_port", "80");
8181
Integer proxyPort;
8282
try {
8383
proxyPort = Integer.parseInt(portString, 10);
@@ -103,12 +103,12 @@ public synchronized AmazonEC2 client() {
103103

104104
this.client = new AmazonEC2Client(credentials, clientConfiguration);
105105

106-
if (componentSettings.get("ec2.endpoint") != null) {
107-
String endpoint = componentSettings.get("ec2.endpoint");
106+
if (settings.get("cloud.aws.ec2.endpoint") != null) {
107+
String endpoint = settings.get("cloud.aws.ec2.endpoint");
108108
logger.debug("using explicit ec2 endpoint [{}]", endpoint);
109109
client.setEndpoint(endpoint);
110-
} else if (componentSettings.get("region") != null) {
111-
String region = componentSettings.get("region").toLowerCase();
110+
} else if (settings.get("cloud.aws.region") != null) {
111+
String region = settings.get("cloud.aws.region").toLowerCase();
112112
String endpoint;
113113
if (region.equals("us-east-1") || region.equals("us-east")) {
114114
endpoint = "ec2.us-east-1.amazonaws.com";

src/main/java/org/elasticsearch/cloud/aws/InternalAwsS3Service.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.elasticsearch.common.component.AbstractLifecycleComponent;
3333
import org.elasticsearch.common.inject.Inject;
3434
import org.elasticsearch.common.settings.Settings;
35-
import org.elasticsearch.common.settings.SettingsFilter;
3635

3736
import java.util.HashMap;
3837
import java.util.Map;
@@ -55,8 +54,8 @@ public InternalAwsS3Service(Settings settings) {
5554
@Override
5655
public synchronized AmazonS3 client() {
5756
String endpoint = getDefaultEndpoint();
58-
String account = componentSettings.get("access_key", settings.get("cloud.account"));
59-
String key = componentSettings.get("secret_key", settings.get("cloud.key"));
57+
String account = settings.get("cloud.aws.access_key", settings.get("cloud.account"));
58+
String key = settings.get("cloud.aws.secret_key", settings.get("cloud.key"));
6059

6160
return getClient(endpoint, null, account, key, null);
6261
}
@@ -75,8 +74,8 @@ public synchronized AmazonS3 client(String endpoint, String protocol, String reg
7574
endpoint = getDefaultEndpoint();
7675
}
7776
if (account == null || key == null) {
78-
account = componentSettings.get("access_key", settings.get("cloud.account"));
79-
key = componentSettings.get("secret_key", settings.get("cloud.key"));
77+
account = settings.get("cloud.aws.access_key", settings.get("cloud.account"));
78+
key = settings.get("cloud.aws.secret_key", settings.get("cloud.key"));
8079
}
8180

8281
return getClient(endpoint, protocol, account, key, maxRetries);
@@ -92,8 +91,8 @@ private synchronized AmazonS3 getClient(String endpoint, String protocol, String
9291

9392
ClientConfiguration clientConfiguration = new ClientConfiguration();
9493
if (protocol == null) {
95-
protocol = componentSettings.get("protocol", "https").toLowerCase();
96-
protocol = componentSettings.get("s3.protocol", protocol).toLowerCase();
94+
protocol = settings.get("cloud.aws.protocol", "https").toLowerCase();
95+
protocol = settings.get("cloud.aws.s3.protocol", protocol).toLowerCase();
9796
}
9897

9998
if ("http".equals(protocol)) {
@@ -104,9 +103,9 @@ private synchronized AmazonS3 getClient(String endpoint, String protocol, String
104103
throw new ElasticsearchIllegalArgumentException("No protocol supported [" + protocol + "], can either be [http] or [https]");
105104
}
106105

107-
String proxyHost = componentSettings.get("proxy_host");
106+
String proxyHost = settings.get("cloud.aws.proxy_host");
108107
if (proxyHost != null) {
109-
String portString = componentSettings.get("proxy_port", "80");
108+
String portString = settings.get("cloud.aws.proxy_port", "80");
110109
Integer proxyPort;
111110
try {
112111
proxyPort = Integer.parseInt(portString, 10);
@@ -145,11 +144,11 @@ private synchronized AmazonS3 getClient(String endpoint, String protocol, String
145144

146145
private String getDefaultEndpoint() {
147146
String endpoint = null;
148-
if (componentSettings.get("s3.endpoint") != null) {
149-
endpoint = componentSettings.get("s3.endpoint");
147+
if (settings.get("cloud.aws.s3.endpoint") != null) {
148+
endpoint = settings.get("cloud.aws.s3.endpoint");
150149
logger.debug("using explicit s3 endpoint [{}]", endpoint);
151-
} else if (componentSettings.get("region") != null) {
152-
String region = componentSettings.get("region").toLowerCase();
150+
} else if (settings.get("cloud.aws.region") != null) {
151+
String region = settings.get("cloud.aws.region").toLowerCase();
153152
endpoint = getEndpoint(region);
154153
logger.debug("using s3 region [{}], with endpoint [{}]", region, endpoint);
155154
}

src/main/java/org/elasticsearch/discovery/ec2/AwsEc2UnicastHostsProvider.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,16 @@ public AwsEc2UnicastHostsProvider(Settings settings, TransportService transportS
7575
this.client = awsEc2Service.client();
7676
this.version = version;
7777

78-
this.hostType = HostType.valueOf(componentSettings.get("host_type", "private_ip").toUpperCase());
78+
this.hostType = HostType.valueOf(settings.get("discovery.ec2.host_type", "private_ip").toUpperCase());
7979

80-
this.bindAnyGroup = componentSettings.getAsBoolean("any_group", true);
81-
this.groups = ImmutableSet.copyOf(componentSettings.getAsArray("groups"));
80+
this.bindAnyGroup = settings.getAsBoolean("discovery.ec2.any_group", true);
81+
this.groups = ImmutableSet.copyOf(settings.getAsArray("discovery.ec2.groups"));
8282

83-
this.tags = componentSettings.getByPrefix("tag.").getAsMap();
83+
this.tags = settings.getByPrefix("discovery.ec2.tag.").getAsMap();
8484

85-
Set<String> availabilityZones = Sets.newHashSet(componentSettings.getAsArray("availability_zones"));
86-
if (componentSettings.get("availability_zones") != null) {
87-
availabilityZones.addAll(Strings.commaDelimitedListToSet(componentSettings.get("availability_zones")));
85+
Set<String> availabilityZones = Sets.newHashSet(settings.getAsArray("discovery.ec2.availability_zones"));
86+
if (settings.get("discovery.ec2.availability_zones") != null) {
87+
availabilityZones.addAll(Strings.commaDelimitedListToSet(settings.get("discovery.ec2.availability_zones")));
8888
}
8989
this.availabilityZones = ImmutableSet.copyOf(availabilityZones);
9090

src/main/java/org/elasticsearch/discovery/ec2/Ec2Discovery.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import org.elasticsearch.cluster.ClusterName;
2323
import org.elasticsearch.cluster.ClusterService;
24-
import org.elasticsearch.cluster.node.DiscoveryNodeService;
2524
import org.elasticsearch.cluster.settings.DynamicSettings;
2625
import org.elasticsearch.common.inject.Inject;
2726
import org.elasticsearch.common.settings.Settings;
@@ -41,9 +40,9 @@ public class Ec2Discovery extends ZenDiscovery {
4140
@Inject
4241
public Ec2Discovery(Settings settings, ClusterName clusterName, ThreadPool threadPool, TransportService transportService,
4342
ClusterService clusterService, NodeSettingsService nodeSettingsService, ZenPingService pingService,
44-
DiscoveryNodeService discoveryNodeService, DiscoverySettings discoverySettings,
43+
DiscoverySettings discoverySettings,
4544
ElectMasterService electMasterService, DynamicSettings dynamicSettings) {
4645
super(settings, clusterName, threadPool, transportService, clusterService, nodeSettingsService,
47-
discoveryNodeService, pingService, electMasterService, discoverySettings, dynamicSettings);
46+
pingService, electMasterService, discoverySettings, dynamicSettings);
4847
}
4948
}

src/main/java/org/elasticsearch/repositories/s3/S3Repository.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ public class S3Repository extends BlobStoreRepository {
7474
public S3Repository(RepositoryName name, RepositorySettings repositorySettings, IndexShardRepository indexShardRepository, AwsS3Service s3Service) throws IOException {
7575
super(name.getName(), repositorySettings, indexShardRepository);
7676

77-
String bucket = repositorySettings.settings().get("bucket", componentSettings.get("bucket"));
77+
String bucket = repositorySettings.settings().get("bucket", settings.get("repositories.s3.bucket"));
7878
if (bucket == null) {
7979
throw new RepositoryException(name.name(), "No bucket defined for s3 gateway");
8080
}
8181

82-
String endpoint = repositorySettings.settings().get("endpoint", componentSettings.get("endpoint"));
83-
String protocol = repositorySettings.settings().get("protocol", componentSettings.get("protocol"));
82+
String endpoint = repositorySettings.settings().get("endpoint", settings.get("repositories.s3.endpoint"));
83+
String protocol = repositorySettings.settings().get("protocol", settings.get("repositories.s3.protocol"));
8484

85-
String region = repositorySettings.settings().get("region", componentSettings.get("region"));
85+
String region = repositorySettings.settings().get("region", settings.get("repositories.s3.region"));
8686
if (region == null) {
8787
// Bucket setting is not set - use global region setting
8888
String regionSetting = repositorySettings.settings().get("cloud.aws.region", settings.get("cloud.aws.region"));
@@ -113,11 +113,11 @@ public S3Repository(RepositoryName name, RepositorySettings repositorySettings,
113113
}
114114
}
115115

116-
boolean serverSideEncryption = repositorySettings.settings().getAsBoolean("server_side_encryption", componentSettings.getAsBoolean("server_side_encryption", false));
117-
ByteSizeValue bufferSize = repositorySettings.settings().getAsBytesSize("buffer_size", componentSettings.getAsBytesSize("buffer_size", null));
118-
Integer maxRetries = repositorySettings.settings().getAsInt("max_retries", componentSettings.getAsInt("max_retries", 3));
119-
this.chunkSize = repositorySettings.settings().getAsBytesSize("chunk_size", componentSettings.getAsBytesSize("chunk_size", new ByteSizeValue(100, ByteSizeUnit.MB)));
120-
this.compress = repositorySettings.settings().getAsBoolean("compress", componentSettings.getAsBoolean("compress", false));
116+
boolean serverSideEncryption = repositorySettings.settings().getAsBoolean("server_side_encryption", settings.getAsBoolean("repositories.s3.server_side_encryption", false));
117+
ByteSizeValue bufferSize = repositorySettings.settings().getAsBytesSize("buffer_size", settings.getAsBytesSize("repositories.s3.buffer_size", null));
118+
Integer maxRetries = repositorySettings.settings().getAsInt("max_retries", settings.getAsInt("repositories.s3.max_retries", 3));
119+
this.chunkSize = repositorySettings.settings().getAsBytesSize("chunk_size", settings.getAsBytesSize("repositories.s3.chunk_size", new ByteSizeValue(100, ByteSizeUnit.MB)));
120+
this.compress = repositorySettings.settings().getAsBoolean("compress", settings.getAsBoolean("repositories.s3.compress", false));
121121

122122
logger.debug("using bucket [{}], region [{}], endpoint [{}], protocol [{}], chunk_size [{}], server_side_encryption [{}], buffer_size [{}], max_retries [{}]",
123123
bucket, region, endpoint, protocol, chunkSize, serverSideEncryption, bufferSize, maxRetries);

src/test/java/org/elasticsearch/cloud/aws/TestAmazonS3.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ private long incrementAndGet(String path) {
6464
return 1;
6565
}
6666

67-
public TestAmazonS3(AmazonS3 delegate, Settings componentSettings) {
67+
public TestAmazonS3(AmazonS3 delegate, Settings settings) {
6868
super(delegate);
69-
randomPrefix = componentSettings.get("test.random");
70-
writeFailureRate = componentSettings.getAsDouble("test.write_failures", 0.0);
71-
readFailureRate = componentSettings.getAsDouble("test.read_failures", 0.0);
69+
randomPrefix = settings.get("cloud.aws.test.random");
70+
writeFailureRate = settings.getAsDouble("cloud.aws.test.write_failures", 0.0);
71+
readFailureRate = settings.getAsDouble("cloud.aws.test.read_failures", 0.0);
7272
}
7373

7474
@Override

src/test/java/org/elasticsearch/cloud/aws/TestAwsS3Service.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.elasticsearch.ElasticsearchException;
2323
import org.elasticsearch.common.inject.Inject;
2424
import org.elasticsearch.common.settings.Settings;
25-
import org.elasticsearch.common.settings.SettingsFilter;
2625

2726
import java.util.IdentityHashMap;
2827

@@ -57,7 +56,7 @@ public synchronized AmazonS3 client(String endpoint, String protocol, String reg
5756
private AmazonS3 cachedWrapper(AmazonS3 client) {
5857
TestAmazonS3 wrapper = clients.get(client);
5958
if (wrapper == null) {
60-
wrapper = new TestAmazonS3(client, componentSettings);
59+
wrapper = new TestAmazonS3(client, settings);
6160
clients.put(client, wrapper);
6261
}
6362
return wrapper;

0 commit comments

Comments
 (0)