Remove component settings from AbstractComponent
Related to elasticsearch/elasticsearch#9919 Closes #182.
This commit is contained in:
parent
20a99919bf
commit
7a7de12538
|
@ -63,8 +63,8 @@ public class AwsEc2Service extends AbstractLifecycleComponent<AwsEc2Service> {
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientConfiguration clientConfiguration = new ClientConfiguration();
|
ClientConfiguration clientConfiguration = new ClientConfiguration();
|
||||||
String protocol = componentSettings.get("protocol", "https").toLowerCase();
|
String protocol = settings.get("cloud.aws.protocol", "https").toLowerCase();
|
||||||
protocol = componentSettings.get("ec2.protocol", protocol).toLowerCase();
|
protocol = settings.get("cloud.aws.ec2.protocol", protocol).toLowerCase();
|
||||||
if ("http".equals(protocol)) {
|
if ("http".equals(protocol)) {
|
||||||
clientConfiguration.setProtocol(Protocol.HTTP);
|
clientConfiguration.setProtocol(Protocol.HTTP);
|
||||||
} else if ("https".equals(protocol)) {
|
} else if ("https".equals(protocol)) {
|
||||||
|
@ -72,12 +72,12 @@ public class AwsEc2Service extends AbstractLifecycleComponent<AwsEc2Service> {
|
||||||
} else {
|
} else {
|
||||||
throw new ElasticsearchIllegalArgumentException("No protocol supported [" + protocol + "], can either be [http] or [https]");
|
throw new ElasticsearchIllegalArgumentException("No protocol supported [" + protocol + "], can either be [http] or [https]");
|
||||||
}
|
}
|
||||||
String account = componentSettings.get("access_key", settings.get("cloud.account"));
|
String account = settings.get("cloud.aws.access_key", settings.get("cloud.account"));
|
||||||
String key = componentSettings.get("secret_key", settings.get("cloud.key"));
|
String key = settings.get("cloud.aws.secret_key", settings.get("cloud.key"));
|
||||||
|
|
||||||
String proxyHost = componentSettings.get("proxy_host");
|
String proxyHost = settings.get("cloud.aws.proxy_host");
|
||||||
if (proxyHost != null) {
|
if (proxyHost != null) {
|
||||||
String portString = componentSettings.get("proxy_port", "80");
|
String portString = settings.get("cloud.aws.proxy_port", "80");
|
||||||
Integer proxyPort;
|
Integer proxyPort;
|
||||||
try {
|
try {
|
||||||
proxyPort = Integer.parseInt(portString, 10);
|
proxyPort = Integer.parseInt(portString, 10);
|
||||||
|
@ -103,12 +103,12 @@ public class AwsEc2Service extends AbstractLifecycleComponent<AwsEc2Service> {
|
||||||
|
|
||||||
this.client = new AmazonEC2Client(credentials, clientConfiguration);
|
this.client = new AmazonEC2Client(credentials, clientConfiguration);
|
||||||
|
|
||||||
if (componentSettings.get("ec2.endpoint") != null) {
|
if (settings.get("cloud.aws.ec2.endpoint") != null) {
|
||||||
String endpoint = componentSettings.get("ec2.endpoint");
|
String endpoint = settings.get("cloud.aws.ec2.endpoint");
|
||||||
logger.debug("using explicit ec2 endpoint [{}]", endpoint);
|
logger.debug("using explicit ec2 endpoint [{}]", endpoint);
|
||||||
client.setEndpoint(endpoint);
|
client.setEndpoint(endpoint);
|
||||||
} else if (componentSettings.get("region") != null) {
|
} else if (settings.get("cloud.aws.region") != null) {
|
||||||
String region = componentSettings.get("region").toLowerCase();
|
String region = settings.get("cloud.aws.region").toLowerCase();
|
||||||
String endpoint;
|
String endpoint;
|
||||||
if (region.equals("us-east-1") || region.equals("us-east")) {
|
if (region.equals("us-east-1") || region.equals("us-east")) {
|
||||||
endpoint = "ec2.us-east-1.amazonaws.com";
|
endpoint = "ec2.us-east-1.amazonaws.com";
|
||||||
|
|
|
@ -32,7 +32,6 @@ import org.elasticsearch.common.collect.Tuple;
|
||||||
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.settings.SettingsFilter;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -55,8 +54,8 @@ public class InternalAwsS3Service extends AbstractLifecycleComponent<AwsS3Servic
|
||||||
@Override
|
@Override
|
||||||
public synchronized AmazonS3 client() {
|
public synchronized AmazonS3 client() {
|
||||||
String endpoint = getDefaultEndpoint();
|
String endpoint = getDefaultEndpoint();
|
||||||
String account = componentSettings.get("access_key", settings.get("cloud.account"));
|
String account = settings.get("cloud.aws.access_key", settings.get("cloud.account"));
|
||||||
String key = componentSettings.get("secret_key", settings.get("cloud.key"));
|
String key = settings.get("cloud.aws.secret_key", settings.get("cloud.key"));
|
||||||
|
|
||||||
return getClient(endpoint, null, account, key, null);
|
return getClient(endpoint, null, account, key, null);
|
||||||
}
|
}
|
||||||
|
@ -75,8 +74,8 @@ public class InternalAwsS3Service extends AbstractLifecycleComponent<AwsS3Servic
|
||||||
endpoint = getDefaultEndpoint();
|
endpoint = getDefaultEndpoint();
|
||||||
}
|
}
|
||||||
if (account == null || key == null) {
|
if (account == null || key == null) {
|
||||||
account = componentSettings.get("access_key", settings.get("cloud.account"));
|
account = settings.get("cloud.aws.access_key", settings.get("cloud.account"));
|
||||||
key = componentSettings.get("secret_key", settings.get("cloud.key"));
|
key = settings.get("cloud.aws.secret_key", settings.get("cloud.key"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return getClient(endpoint, protocol, account, key, maxRetries);
|
return getClient(endpoint, protocol, account, key, maxRetries);
|
||||||
|
@ -92,8 +91,8 @@ public class InternalAwsS3Service extends AbstractLifecycleComponent<AwsS3Servic
|
||||||
|
|
||||||
ClientConfiguration clientConfiguration = new ClientConfiguration();
|
ClientConfiguration clientConfiguration = new ClientConfiguration();
|
||||||
if (protocol == null) {
|
if (protocol == null) {
|
||||||
protocol = componentSettings.get("protocol", "https").toLowerCase();
|
protocol = settings.get("cloud.aws.protocol", "https").toLowerCase();
|
||||||
protocol = componentSettings.get("s3.protocol", protocol).toLowerCase();
|
protocol = settings.get("cloud.aws.s3.protocol", protocol).toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("http".equals(protocol)) {
|
if ("http".equals(protocol)) {
|
||||||
|
@ -104,9 +103,9 @@ public class InternalAwsS3Service extends AbstractLifecycleComponent<AwsS3Servic
|
||||||
throw new ElasticsearchIllegalArgumentException("No protocol supported [" + protocol + "], can either be [http] or [https]");
|
throw new ElasticsearchIllegalArgumentException("No protocol supported [" + protocol + "], can either be [http] or [https]");
|
||||||
}
|
}
|
||||||
|
|
||||||
String proxyHost = componentSettings.get("proxy_host");
|
String proxyHost = settings.get("cloud.aws.proxy_host");
|
||||||
if (proxyHost != null) {
|
if (proxyHost != null) {
|
||||||
String portString = componentSettings.get("proxy_port", "80");
|
String portString = settings.get("cloud.aws.proxy_port", "80");
|
||||||
Integer proxyPort;
|
Integer proxyPort;
|
||||||
try {
|
try {
|
||||||
proxyPort = Integer.parseInt(portString, 10);
|
proxyPort = Integer.parseInt(portString, 10);
|
||||||
|
@ -145,11 +144,11 @@ public class InternalAwsS3Service extends AbstractLifecycleComponent<AwsS3Servic
|
||||||
|
|
||||||
private String getDefaultEndpoint() {
|
private String getDefaultEndpoint() {
|
||||||
String endpoint = null;
|
String endpoint = null;
|
||||||
if (componentSettings.get("s3.endpoint") != null) {
|
if (settings.get("cloud.aws.s3.endpoint") != null) {
|
||||||
endpoint = componentSettings.get("s3.endpoint");
|
endpoint = settings.get("cloud.aws.s3.endpoint");
|
||||||
logger.debug("using explicit s3 endpoint [{}]", endpoint);
|
logger.debug("using explicit s3 endpoint [{}]", endpoint);
|
||||||
} else if (componentSettings.get("region") != null) {
|
} else if (settings.get("cloud.aws.region") != null) {
|
||||||
String region = componentSettings.get("region").toLowerCase();
|
String region = settings.get("cloud.aws.region").toLowerCase();
|
||||||
endpoint = getEndpoint(region);
|
endpoint = getEndpoint(region);
|
||||||
logger.debug("using s3 region [{}], with endpoint [{}]", region, endpoint);
|
logger.debug("using s3 region [{}], with endpoint [{}]", region, endpoint);
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,16 +75,16 @@ public class AwsEc2UnicastHostsProvider extends AbstractComponent implements Uni
|
||||||
this.client = awsEc2Service.client();
|
this.client = awsEc2Service.client();
|
||||||
this.version = version;
|
this.version = version;
|
||||||
|
|
||||||
this.hostType = HostType.valueOf(componentSettings.get("host_type", "private_ip").toUpperCase());
|
this.hostType = HostType.valueOf(settings.get("discovery.ec2.host_type", "private_ip").toUpperCase());
|
||||||
|
|
||||||
this.bindAnyGroup = componentSettings.getAsBoolean("any_group", true);
|
this.bindAnyGroup = settings.getAsBoolean("discovery.ec2.any_group", true);
|
||||||
this.groups = ImmutableSet.copyOf(componentSettings.getAsArray("groups"));
|
this.groups = ImmutableSet.copyOf(settings.getAsArray("discovery.ec2.groups"));
|
||||||
|
|
||||||
this.tags = componentSettings.getByPrefix("tag.").getAsMap();
|
this.tags = settings.getByPrefix("discovery.ec2.tag.").getAsMap();
|
||||||
|
|
||||||
Set<String> availabilityZones = Sets.newHashSet(componentSettings.getAsArray("availability_zones"));
|
Set<String> availabilityZones = Sets.newHashSet(settings.getAsArray("discovery.ec2.availability_zones"));
|
||||||
if (componentSettings.get("availability_zones") != null) {
|
if (settings.get("discovery.ec2.availability_zones") != null) {
|
||||||
availabilityZones.addAll(Strings.commaDelimitedListToSet(componentSettings.get("availability_zones")));
|
availabilityZones.addAll(Strings.commaDelimitedListToSet(settings.get("discovery.ec2.availability_zones")));
|
||||||
}
|
}
|
||||||
this.availabilityZones = ImmutableSet.copyOf(availabilityZones);
|
this.availabilityZones = ImmutableSet.copyOf(availabilityZones);
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ package org.elasticsearch.discovery.ec2;
|
||||||
|
|
||||||
import org.elasticsearch.cluster.ClusterName;
|
import org.elasticsearch.cluster.ClusterName;
|
||||||
import org.elasticsearch.cluster.ClusterService;
|
import org.elasticsearch.cluster.ClusterService;
|
||||||
import org.elasticsearch.cluster.node.DiscoveryNodeService;
|
|
||||||
import org.elasticsearch.cluster.settings.DynamicSettings;
|
import org.elasticsearch.cluster.settings.DynamicSettings;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
@ -41,9 +40,9 @@ public class Ec2Discovery extends ZenDiscovery {
|
||||||
@Inject
|
@Inject
|
||||||
public Ec2Discovery(Settings settings, ClusterName clusterName, ThreadPool threadPool, TransportService transportService,
|
public Ec2Discovery(Settings settings, ClusterName clusterName, ThreadPool threadPool, TransportService transportService,
|
||||||
ClusterService clusterService, NodeSettingsService nodeSettingsService, ZenPingService pingService,
|
ClusterService clusterService, NodeSettingsService nodeSettingsService, ZenPingService pingService,
|
||||||
DiscoveryNodeService discoveryNodeService, DiscoverySettings discoverySettings,
|
DiscoverySettings discoverySettings,
|
||||||
ElectMasterService electMasterService, DynamicSettings dynamicSettings) {
|
ElectMasterService electMasterService, DynamicSettings dynamicSettings) {
|
||||||
super(settings, clusterName, threadPool, transportService, clusterService, nodeSettingsService,
|
super(settings, clusterName, threadPool, transportService, clusterService, nodeSettingsService,
|
||||||
discoveryNodeService, pingService, electMasterService, discoverySettings, dynamicSettings);
|
pingService, electMasterService, discoverySettings, dynamicSettings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,15 +74,15 @@ public class S3Repository extends BlobStoreRepository {
|
||||||
public S3Repository(RepositoryName name, RepositorySettings repositorySettings, IndexShardRepository indexShardRepository, AwsS3Service s3Service) throws IOException {
|
public S3Repository(RepositoryName name, RepositorySettings repositorySettings, IndexShardRepository indexShardRepository, AwsS3Service s3Service) throws IOException {
|
||||||
super(name.getName(), repositorySettings, indexShardRepository);
|
super(name.getName(), repositorySettings, indexShardRepository);
|
||||||
|
|
||||||
String bucket = repositorySettings.settings().get("bucket", componentSettings.get("bucket"));
|
String bucket = repositorySettings.settings().get("bucket", settings.get("repositories.s3.bucket"));
|
||||||
if (bucket == null) {
|
if (bucket == null) {
|
||||||
throw new RepositoryException(name.name(), "No bucket defined for s3 gateway");
|
throw new RepositoryException(name.name(), "No bucket defined for s3 gateway");
|
||||||
}
|
}
|
||||||
|
|
||||||
String endpoint = repositorySettings.settings().get("endpoint", componentSettings.get("endpoint"));
|
String endpoint = repositorySettings.settings().get("endpoint", settings.get("repositories.s3.endpoint"));
|
||||||
String protocol = repositorySettings.settings().get("protocol", componentSettings.get("protocol"));
|
String protocol = repositorySettings.settings().get("protocol", settings.get("repositories.s3.protocol"));
|
||||||
|
|
||||||
String region = repositorySettings.settings().get("region", componentSettings.get("region"));
|
String region = repositorySettings.settings().get("region", settings.get("repositories.s3.region"));
|
||||||
if (region == null) {
|
if (region == null) {
|
||||||
// Bucket setting is not set - use global region setting
|
// Bucket setting is not set - use global region setting
|
||||||
String regionSetting = repositorySettings.settings().get("cloud.aws.region", settings.get("cloud.aws.region"));
|
String regionSetting = repositorySettings.settings().get("cloud.aws.region", settings.get("cloud.aws.region"));
|
||||||
|
@ -113,11 +113,11 @@ public class S3Repository extends BlobStoreRepository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean serverSideEncryption = repositorySettings.settings().getAsBoolean("server_side_encryption", componentSettings.getAsBoolean("server_side_encryption", false));
|
boolean serverSideEncryption = repositorySettings.settings().getAsBoolean("server_side_encryption", settings.getAsBoolean("repositories.s3.server_side_encryption", false));
|
||||||
ByteSizeValue bufferSize = repositorySettings.settings().getAsBytesSize("buffer_size", componentSettings.getAsBytesSize("buffer_size", null));
|
ByteSizeValue bufferSize = repositorySettings.settings().getAsBytesSize("buffer_size", settings.getAsBytesSize("repositories.s3.buffer_size", null));
|
||||||
Integer maxRetries = repositorySettings.settings().getAsInt("max_retries", componentSettings.getAsInt("max_retries", 3));
|
Integer maxRetries = repositorySettings.settings().getAsInt("max_retries", settings.getAsInt("repositories.s3.max_retries", 3));
|
||||||
this.chunkSize = repositorySettings.settings().getAsBytesSize("chunk_size", componentSettings.getAsBytesSize("chunk_size", new ByteSizeValue(100, ByteSizeUnit.MB)));
|
this.chunkSize = repositorySettings.settings().getAsBytesSize("chunk_size", settings.getAsBytesSize("repositories.s3.chunk_size", new ByteSizeValue(100, ByteSizeUnit.MB)));
|
||||||
this.compress = repositorySettings.settings().getAsBoolean("compress", componentSettings.getAsBoolean("compress", false));
|
this.compress = repositorySettings.settings().getAsBoolean("compress", settings.getAsBoolean("repositories.s3.compress", false));
|
||||||
|
|
||||||
logger.debug("using bucket [{}], region [{}], endpoint [{}], protocol [{}], chunk_size [{}], server_side_encryption [{}], buffer_size [{}], max_retries [{}]",
|
logger.debug("using bucket [{}], region [{}], endpoint [{}], protocol [{}], chunk_size [{}], server_side_encryption [{}], buffer_size [{}], max_retries [{}]",
|
||||||
bucket, region, endpoint, protocol, chunkSize, serverSideEncryption, bufferSize, maxRetries);
|
bucket, region, endpoint, protocol, chunkSize, serverSideEncryption, bufferSize, maxRetries);
|
||||||
|
|
|
@ -64,11 +64,11 @@ public class TestAmazonS3 extends AmazonS3Wrapper {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TestAmazonS3(AmazonS3 delegate, Settings componentSettings) {
|
public TestAmazonS3(AmazonS3 delegate, Settings settings) {
|
||||||
super(delegate);
|
super(delegate);
|
||||||
randomPrefix = componentSettings.get("test.random");
|
randomPrefix = settings.get("cloud.aws.test.random");
|
||||||
writeFailureRate = componentSettings.getAsDouble("test.write_failures", 0.0);
|
writeFailureRate = settings.getAsDouble("cloud.aws.test.write_failures", 0.0);
|
||||||
readFailureRate = componentSettings.getAsDouble("test.read_failures", 0.0);
|
readFailureRate = settings.getAsDouble("cloud.aws.test.read_failures", 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -22,7 +22,6 @@ import com.amazonaws.services.s3.AmazonS3;
|
||||||
import org.elasticsearch.ElasticsearchException;
|
import org.elasticsearch.ElasticsearchException;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.settings.SettingsFilter;
|
|
||||||
|
|
||||||
import java.util.IdentityHashMap;
|
import java.util.IdentityHashMap;
|
||||||
|
|
||||||
|
@ -57,7 +56,7 @@ public class TestAwsS3Service extends InternalAwsS3Service {
|
||||||
private AmazonS3 cachedWrapper(AmazonS3 client) {
|
private AmazonS3 cachedWrapper(AmazonS3 client) {
|
||||||
TestAmazonS3 wrapper = clients.get(client);
|
TestAmazonS3 wrapper = clients.get(client);
|
||||||
if (wrapper == null) {
|
if (wrapper == null) {
|
||||||
wrapper = new TestAmazonS3(client, componentSettings);
|
wrapper = new TestAmazonS3(client, settings);
|
||||||
clients.put(client, wrapper);
|
clients.put(client, wrapper);
|
||||||
}
|
}
|
||||||
return wrapper;
|
return wrapper;
|
||||||
|
|
Loading…
Reference in New Issue