Remove component settings from AbstractComponent

Related to elasticsearch/elasticsearch#9919

Closes #182.
This commit is contained in:
David Pilato 2015-02-27 16:32:50 +01:00
parent 20a99919bf
commit 7a7de12538
7 changed files with 45 additions and 48 deletions

View File

@ -63,8 +63,8 @@ public class AwsEc2Service extends AbstractLifecycleComponent<AwsEc2Service> {
}
ClientConfiguration clientConfiguration = new ClientConfiguration();
String protocol = componentSettings.get("protocol", "https").toLowerCase();
protocol = componentSettings.get("ec2.protocol", protocol).toLowerCase();
String protocol = settings.get("cloud.aws.protocol", "https").toLowerCase();
protocol = settings.get("cloud.aws.ec2.protocol", protocol).toLowerCase();
if ("http".equals(protocol)) {
clientConfiguration.setProtocol(Protocol.HTTP);
} else if ("https".equals(protocol)) {
@ -72,12 +72,12 @@ public class AwsEc2Service extends AbstractLifecycleComponent<AwsEc2Service> {
} else {
throw new ElasticsearchIllegalArgumentException("No protocol supported [" + protocol + "], can either be [http] or [https]");
}
String account = componentSettings.get("access_key", settings.get("cloud.account"));
String key = componentSettings.get("secret_key", settings.get("cloud.key"));
String account = settings.get("cloud.aws.access_key", settings.get("cloud.account"));
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) {
String portString = componentSettings.get("proxy_port", "80");
String portString = settings.get("cloud.aws.proxy_port", "80");
Integer proxyPort;
try {
proxyPort = Integer.parseInt(portString, 10);
@ -103,12 +103,12 @@ public class AwsEc2Service extends AbstractLifecycleComponent<AwsEc2Service> {
this.client = new AmazonEC2Client(credentials, clientConfiguration);
if (componentSettings.get("ec2.endpoint") != null) {
String endpoint = componentSettings.get("ec2.endpoint");
if (settings.get("cloud.aws.ec2.endpoint") != null) {
String endpoint = settings.get("cloud.aws.ec2.endpoint");
logger.debug("using explicit ec2 endpoint [{}]", endpoint);
client.setEndpoint(endpoint);
} else if (componentSettings.get("region") != null) {
String region = componentSettings.get("region").toLowerCase();
} else if (settings.get("cloud.aws.region") != null) {
String region = settings.get("cloud.aws.region").toLowerCase();
String endpoint;
if (region.equals("us-east-1") || region.equals("us-east")) {
endpoint = "ec2.us-east-1.amazonaws.com";

View File

@ -32,7 +32,6 @@ import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.component.AbstractLifecycleComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import java.util.HashMap;
import java.util.Map;
@ -55,8 +54,8 @@ public class InternalAwsS3Service extends AbstractLifecycleComponent<AwsS3Servic
@Override
public synchronized AmazonS3 client() {
String endpoint = getDefaultEndpoint();
String account = componentSettings.get("access_key", settings.get("cloud.account"));
String key = componentSettings.get("secret_key", settings.get("cloud.key"));
String account = settings.get("cloud.aws.access_key", settings.get("cloud.account"));
String key = settings.get("cloud.aws.secret_key", settings.get("cloud.key"));
return getClient(endpoint, null, account, key, null);
}
@ -75,8 +74,8 @@ public class InternalAwsS3Service extends AbstractLifecycleComponent<AwsS3Servic
endpoint = getDefaultEndpoint();
}
if (account == null || key == null) {
account = componentSettings.get("access_key", settings.get("cloud.account"));
key = componentSettings.get("secret_key", settings.get("cloud.key"));
account = settings.get("cloud.aws.access_key", settings.get("cloud.account"));
key = settings.get("cloud.aws.secret_key", settings.get("cloud.key"));
}
return getClient(endpoint, protocol, account, key, maxRetries);
@ -92,8 +91,8 @@ public class InternalAwsS3Service extends AbstractLifecycleComponent<AwsS3Servic
ClientConfiguration clientConfiguration = new ClientConfiguration();
if (protocol == null) {
protocol = componentSettings.get("protocol", "https").toLowerCase();
protocol = componentSettings.get("s3.protocol", protocol).toLowerCase();
protocol = settings.get("cloud.aws.protocol", "https").toLowerCase();
protocol = settings.get("cloud.aws.s3.protocol", protocol).toLowerCase();
}
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]");
}
String proxyHost = componentSettings.get("proxy_host");
String proxyHost = settings.get("cloud.aws.proxy_host");
if (proxyHost != null) {
String portString = componentSettings.get("proxy_port", "80");
String portString = settings.get("cloud.aws.proxy_port", "80");
Integer proxyPort;
try {
proxyPort = Integer.parseInt(portString, 10);
@ -145,11 +144,11 @@ public class InternalAwsS3Service extends AbstractLifecycleComponent<AwsS3Servic
private String getDefaultEndpoint() {
String endpoint = null;
if (componentSettings.get("s3.endpoint") != null) {
endpoint = componentSettings.get("s3.endpoint");
if (settings.get("cloud.aws.s3.endpoint") != null) {
endpoint = settings.get("cloud.aws.s3.endpoint");
logger.debug("using explicit s3 endpoint [{}]", endpoint);
} else if (componentSettings.get("region") != null) {
String region = componentSettings.get("region").toLowerCase();
} else if (settings.get("cloud.aws.region") != null) {
String region = settings.get("cloud.aws.region").toLowerCase();
endpoint = getEndpoint(region);
logger.debug("using s3 region [{}], with endpoint [{}]", region, endpoint);
}

View File

@ -75,16 +75,16 @@ public class AwsEc2UnicastHostsProvider extends AbstractComponent implements Uni
this.client = awsEc2Service.client();
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.groups = ImmutableSet.copyOf(componentSettings.getAsArray("groups"));
this.bindAnyGroup = settings.getAsBoolean("discovery.ec2.any_group", true);
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"));
if (componentSettings.get("availability_zones") != null) {
availabilityZones.addAll(Strings.commaDelimitedListToSet(componentSettings.get("availability_zones")));
Set<String> availabilityZones = Sets.newHashSet(settings.getAsArray("discovery.ec2.availability_zones"));
if (settings.get("discovery.ec2.availability_zones") != null) {
availabilityZones.addAll(Strings.commaDelimitedListToSet(settings.get("discovery.ec2.availability_zones")));
}
this.availabilityZones = ImmutableSet.copyOf(availabilityZones);

View File

@ -21,7 +21,6 @@ package org.elasticsearch.discovery.ec2;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.node.DiscoveryNodeService;
import org.elasticsearch.cluster.settings.DynamicSettings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
@ -41,9 +40,9 @@ public class Ec2Discovery extends ZenDiscovery {
@Inject
public Ec2Discovery(Settings settings, ClusterName clusterName, ThreadPool threadPool, TransportService transportService,
ClusterService clusterService, NodeSettingsService nodeSettingsService, ZenPingService pingService,
DiscoveryNodeService discoveryNodeService, DiscoverySettings discoverySettings,
DiscoverySettings discoverySettings,
ElectMasterService electMasterService, DynamicSettings dynamicSettings) {
super(settings, clusterName, threadPool, transportService, clusterService, nodeSettingsService,
discoveryNodeService, pingService, electMasterService, discoverySettings, dynamicSettings);
pingService, electMasterService, discoverySettings, dynamicSettings);
}
}

View File

@ -74,15 +74,15 @@ public class S3Repository extends BlobStoreRepository {
public S3Repository(RepositoryName name, RepositorySettings repositorySettings, IndexShardRepository indexShardRepository, AwsS3Service s3Service) throws IOException {
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) {
throw new RepositoryException(name.name(), "No bucket defined for s3 gateway");
}
String endpoint = repositorySettings.settings().get("endpoint", componentSettings.get("endpoint"));
String protocol = repositorySettings.settings().get("protocol", componentSettings.get("protocol"));
String endpoint = repositorySettings.settings().get("endpoint", settings.get("repositories.s3.endpoint"));
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) {
// Bucket setting is not set - use global region setting
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));
ByteSizeValue bufferSize = repositorySettings.settings().getAsBytesSize("buffer_size", componentSettings.getAsBytesSize("buffer_size", null));
Integer maxRetries = repositorySettings.settings().getAsInt("max_retries", componentSettings.getAsInt("max_retries", 3));
this.chunkSize = repositorySettings.settings().getAsBytesSize("chunk_size", componentSettings.getAsBytesSize("chunk_size", new ByteSizeValue(100, ByteSizeUnit.MB)));
this.compress = repositorySettings.settings().getAsBoolean("compress", componentSettings.getAsBoolean("compress", false));
boolean serverSideEncryption = repositorySettings.settings().getAsBoolean("server_side_encryption", settings.getAsBoolean("repositories.s3.server_side_encryption", false));
ByteSizeValue bufferSize = repositorySettings.settings().getAsBytesSize("buffer_size", settings.getAsBytesSize("repositories.s3.buffer_size", null));
Integer maxRetries = repositorySettings.settings().getAsInt("max_retries", settings.getAsInt("repositories.s3.max_retries", 3));
this.chunkSize = repositorySettings.settings().getAsBytesSize("chunk_size", settings.getAsBytesSize("repositories.s3.chunk_size", new ByteSizeValue(100, ByteSizeUnit.MB)));
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 [{}]",
bucket, region, endpoint, protocol, chunkSize, serverSideEncryption, bufferSize, maxRetries);

View File

@ -64,11 +64,11 @@ public class TestAmazonS3 extends AmazonS3Wrapper {
return 1;
}
public TestAmazonS3(AmazonS3 delegate, Settings componentSettings) {
public TestAmazonS3(AmazonS3 delegate, Settings settings) {
super(delegate);
randomPrefix = componentSettings.get("test.random");
writeFailureRate = componentSettings.getAsDouble("test.write_failures", 0.0);
readFailureRate = componentSettings.getAsDouble("test.read_failures", 0.0);
randomPrefix = settings.get("cloud.aws.test.random");
writeFailureRate = settings.getAsDouble("cloud.aws.test.write_failures", 0.0);
readFailureRate = settings.getAsDouble("cloud.aws.test.read_failures", 0.0);
}
@Override

View File

@ -22,7 +22,6 @@ import com.amazonaws.services.s3.AmazonS3;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import java.util.IdentityHashMap;
@ -57,7 +56,7 @@ public class TestAwsS3Service extends InternalAwsS3Service {
private AmazonS3 cachedWrapper(AmazonS3 client) {
TestAmazonS3 wrapper = clients.get(client);
if (wrapper == null) {
wrapper = new TestAmazonS3(client, componentSettings);
wrapper = new TestAmazonS3(client, settings);
clients.put(client, wrapper);
}
return wrapper;