Skip to content

Commit db888a5

Browse files
committed
Remove component settings from AbstractComponent
Related to elastic/elasticsearch#9919 Closes elastic#72.
1 parent d6b1710 commit db888a5

17 files changed

+219
-232
lines changed

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ How to start (short story)
6363
Azure credential API settings
6464
-----------------------------
6565

66-
The following are a list of settings (prefixed with `cloud.azure.management`) that can further control the discovery:
66+
The following are a list of settings that can further control the credential API:
6767

68-
* `keystore.path`: /path/to/keystore
69-
* `keystore.type`: `pkcs12`, `jceks` or `jks`. Defaults to `pkcs12`.
70-
* `keystore.password`: your_password for the keystore
71-
* `subscription.id`: your_azure_subscription_id
72-
* `cloud.service.name`: your_azure_cloud_service_name
68+
* `cloud.azure.management.keystore.path`: /path/to/keystore
69+
* `cloud.azure.management.keystore.type`: `pkcs12`, `jceks` or `jks`. Defaults to `pkcs12`.
70+
* `cloud.azure.management.keystore.password`: your_password for the keystore
71+
* `cloud.azure.management.subscription.id`: your_azure_subscription_id
72+
* `cloud.azure.management.cloud.service.name`: your_azure_cloud_service_name
7373

7474
Note that in previous versions, it was:
7575

@@ -85,16 +85,16 @@ cloud:
8585
Advanced settings
8686
-----------------
8787

88-
The following are a list of settings (prefixed with `discovery.azure`) that can further control the discovery:
88+
The following are a list of settings that can further control the discovery:
8989

90-
* `host.type`: either `public_ip` or `private_ip` (default). Azure discovery will use the one you set to ping
90+
* `discovery.azure.host.type`: either `public_ip` or `private_ip` (default). Azure discovery will use the one you set to ping
9191
other nodes. This feature was not documented before but was existing under `cloud.azure.host_type`.
92-
* `endpoint.name`: when using `public_ip` this setting is used to identify the endpoint name used to forward requests
92+
* `discovery.azure.endpoint.name`: when using `public_ip` this setting is used to identify the endpoint name used to forward requests
9393
to elasticsearch (aka transport port name). Defaults to `elasticsearch`. In Azure management console, you could define
9494
an endpoint `elasticsearch` forwarding for example requests on public IP on port 8100 to the virtual machine on port 9300.
9595
This feature was not documented before but was existing under `cloud.azure.port_name`.
96-
* `deployment.name`: deployment name if any. Defaults to the value set with `cloud.azure.management.cloud.service.name`.
97-
* `deployment.slot`: either `staging` or `production` (default).
96+
* `discovery.azure.deployment.name`: deployment name if any. Defaults to the value set with `cloud.azure.management.cloud.service.name`.
97+
* `discovery.azure.deployment.slot`: either `staging` or `production` (default).
9898

9999
For example:
100100

@@ -475,10 +475,10 @@ Example using Java:
475475

476476
```java
477477
client.admin().cluster().preparePutRepository("my_backup3")
478-
.setType("azure").setSettings(ImmutableSettings.settingsBuilder()
479-
.put(AzureStorageService.Fields.CONTAINER, "backup_container")
480-
.put(AzureStorageService.Fields.CHUNK_SIZE, new ByteSizeValue(32, ByteSizeUnit.MB))
481-
).get();
478+
.setType("azure").setSettings(ImmutableSettings.settingsBuilder()
479+
.put(Storage.CONTAINER, "backup_container")
480+
.put(Storage.CHUNK_SIZE, new ByteSizeValue(32, ByteSizeUnit.MB))
481+
).get();
482482
```
483483

484484
Repository validation rules

src/main/java/org/elasticsearch/cloud/azure/AzureModule.java

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@
2020
package org.elasticsearch.cloud.azure;
2121

2222
import org.elasticsearch.ElasticsearchException;
23-
import org.elasticsearch.cloud.azure.storage.AzureStorageService;
24-
import org.elasticsearch.cloud.azure.storage.AzureStorageServiceImpl;
2523
import org.elasticsearch.cloud.azure.management.AzureComputeService;
24+
import org.elasticsearch.cloud.azure.management.AzureComputeService.Discovery;
25+
import org.elasticsearch.cloud.azure.management.AzureComputeService.Management;
2626
import org.elasticsearch.cloud.azure.management.AzureComputeServiceImpl;
27+
import org.elasticsearch.cloud.azure.storage.AzureStorageService;
28+
import org.elasticsearch.cloud.azure.storage.AzureStorageService.Storage;
29+
import org.elasticsearch.cloud.azure.storage.AzureStorageServiceImpl;
2730
import org.elasticsearch.common.Strings;
2831
import org.elasticsearch.common.inject.AbstractModule;
2932
import org.elasticsearch.common.inject.Inject;
@@ -63,15 +66,15 @@ protected void configure() {
6366
if (isDiscoveryReady(settings, logger)) {
6467
logger.debug("starting azure discovery service");
6568
bind(AzureComputeService.class)
66-
.to(settings.getAsClass("cloud.azure.api.impl", AzureComputeServiceImpl.class))
69+
.to(settings.getAsClass(Management.API_IMPLEMENTATION, AzureComputeServiceImpl.class))
6770
.asEagerSingleton();
6871
}
6972

7073
// If we have settings for azure repository, let's start the azure storage service
7174
if (isSnapshotReady(settings, logger)) {
7275
logger.debug("starting azure repository service");
7376
bind(AzureStorageService.class)
74-
.to(settings.getAsClass("repositories.azure.api.impl", AzureStorageServiceImpl.class))
77+
.to(settings.getAsClass(Storage.API_IMPLEMENTATION, AzureStorageServiceImpl.class))
7578
.asEagerSingleton();
7679
}
7780
}
@@ -102,22 +105,22 @@ public static boolean isDiscoveryReady(Settings settings, ESLogger logger) {
102105
}
103106

104107
if ( // We check new parameters
105-
(isPropertyMissing(settings, "cloud.azure.management." + AzureComputeService.Fields.SUBSCRIPTION_ID) ||
106-
isPropertyMissing(settings, "cloud.azure.management." + AzureComputeService.Fields.SERVICE_NAME) ||
107-
isPropertyMissing(settings, "cloud.azure.management." + AzureComputeService.Fields.KEYSTORE_PATH) ||
108-
isPropertyMissing(settings, "cloud.azure.management." + AzureComputeService.Fields.KEYSTORE_PASSWORD))
108+
(isPropertyMissing(settings, Management.SUBSCRIPTION_ID) ||
109+
isPropertyMissing(settings, Management.SERVICE_NAME) ||
110+
isPropertyMissing(settings, Management.KEYSTORE_PATH) ||
111+
isPropertyMissing(settings, Management.KEYSTORE_PASSWORD))
109112
// We check deprecated
110-
&& (isPropertyMissing(settings, "cloud.azure." + AzureComputeService.Fields.SUBSCRIPTION_ID_DEPRECATED) ||
111-
isPropertyMissing(settings, "cloud.azure." + AzureComputeService.Fields.SERVICE_NAME_DEPRECATED) ||
112-
isPropertyMissing(settings, "cloud.azure." + AzureComputeService.Fields.KEYSTORE_DEPRECATED) ||
113-
isPropertyMissing(settings, "cloud.azure." + AzureComputeService.Fields.PASSWORD_DEPRECATED))
113+
&& (isPropertyMissing(settings, Management.SUBSCRIPTION_ID_DEPRECATED) ||
114+
isPropertyMissing(settings, Management.SERVICE_NAME_DEPRECATED) ||
115+
isPropertyMissing(settings, Management.KEYSTORE_DEPRECATED) ||
116+
isPropertyMissing(settings, Management.PASSWORD_DEPRECATED))
114117
) {
115118
logger.debug("one or more azure discovery settings are missing. " +
116-
"Check elasticsearch.yml file and `cloud.azure.management`. Should have [{}], [{}], [{}] and [{}].",
117-
AzureComputeService.Fields.SUBSCRIPTION_ID,
118-
AzureComputeService.Fields.SERVICE_NAME,
119-
AzureComputeService.Fields.KEYSTORE_PATH,
120-
AzureComputeService.Fields.KEYSTORE_PASSWORD);
119+
"Check elasticsearch.yml file. Should have [{}], [{}], [{}] and [{}].",
120+
Management.SUBSCRIPTION_ID,
121+
Management.SERVICE_NAME,
122+
Management.KEYSTORE_PATH,
123+
Management.KEYSTORE_PASSWORD);
121124
return false;
122125
}
123126

@@ -137,13 +140,13 @@ public static boolean isSnapshotReady(Settings settings, ESLogger logger) {
137140
return false;
138141
}
139142

140-
if ((isPropertyMissing(settings, "cloud.azure.storage." + AzureStorageService.Fields.ACCOUNT) ||
141-
isPropertyMissing(settings, "cloud.azure.storage." + AzureStorageService.Fields.KEY)) &&
142-
(isPropertyMissing(settings, "cloud.azure." + AzureStorageService.Fields.ACCOUNT_DEPRECATED) ||
143-
isPropertyMissing(settings, "cloud.azure." + AzureStorageService.Fields.KEY_DEPRECATED))) {
144-
logger.debug("azure repository is not set [using cloud.azure.storage.{}] and [cloud.azure.storage.{}] properties",
145-
AzureStorageService.Fields.ACCOUNT,
146-
AzureStorageService.Fields.KEY);
143+
if ((isPropertyMissing(settings, Storage.ACCOUNT) ||
144+
isPropertyMissing(settings, Storage.KEY)) &&
145+
(isPropertyMissing(settings, Storage.ACCOUNT_DEPRECATED) ||
146+
isPropertyMissing(settings, Storage.KEY_DEPRECATED))) {
147+
logger.debug("azure repository is not set using [{}] and [{}] properties",
148+
Storage.ACCOUNT,
149+
Storage.KEY);
147150
return false;
148151
}
149152

@@ -171,24 +174,16 @@ public static void checkDeprecatedSettings(Settings settings, String oldParamete
171174
public static void checkDeprecated(Settings settings, ESLogger logger) {
172175
// Cloud services are disabled
173176
if (isCloudReady(settings)) {
174-
checkDeprecatedSettings(settings, "cloud.azure." + AzureStorageService.Fields.ACCOUNT_DEPRECATED,
175-
"cloud.azure.storage." + AzureStorageService.Fields.ACCOUNT, logger);
176-
checkDeprecatedSettings(settings, "cloud.azure." + AzureStorageService.Fields.KEY_DEPRECATED,
177-
"cloud.azure.storage." + AzureStorageService.Fields.KEY, logger);
177+
checkDeprecatedSettings(settings, Storage.ACCOUNT_DEPRECATED, Storage.ACCOUNT, logger);
178+
checkDeprecatedSettings(settings, Storage.KEY_DEPRECATED, Storage.KEY, logger);
178179

179180
// TODO Remove in 3.0.0
180-
checkDeprecatedSettings(settings, "cloud.azure." + AzureComputeService.Fields.KEYSTORE_DEPRECATED,
181-
"cloud.azure.management." + AzureComputeService.Fields.KEYSTORE_PATH, logger);
182-
checkDeprecatedSettings(settings, "cloud.azure." + AzureComputeService.Fields.PASSWORD_DEPRECATED,
183-
"cloud.azure.management." + AzureComputeService.Fields.KEYSTORE_PASSWORD, logger);
184-
checkDeprecatedSettings(settings, "cloud.azure." + AzureComputeService.Fields.SERVICE_NAME_DEPRECATED,
185-
"cloud.azure.management." + AzureComputeService.Fields.SERVICE_NAME, logger);
186-
checkDeprecatedSettings(settings, "cloud.azure." + AzureComputeService.Fields.SUBSCRIPTION_ID_DEPRECATED,
187-
"cloud.azure.management." + AzureComputeService.Fields.SUBSCRIPTION_ID, logger);
188-
checkDeprecatedSettings(settings, "cloud.azure." + AzureComputeService.Fields.HOST_TYPE_DEPRECATED,
189-
"discovery.azure." + AzureComputeService.Fields.HOST_TYPE, logger);
190-
checkDeprecatedSettings(settings, "cloud.azure." + AzureComputeService.Fields.PORT_NAME_DEPRECATED,
191-
"discovery.azure." + AzureComputeService.Fields.ENDPOINT_NAME, logger);
181+
checkDeprecatedSettings(settings, Management.KEYSTORE_DEPRECATED, Management.KEYSTORE_PATH, logger);
182+
checkDeprecatedSettings(settings, Management.PASSWORD_DEPRECATED, Management.KEYSTORE_PASSWORD, logger);
183+
checkDeprecatedSettings(settings, Management.SERVICE_NAME_DEPRECATED, Management.SERVICE_NAME, logger);
184+
checkDeprecatedSettings(settings, Management.SUBSCRIPTION_ID_DEPRECATED, Management.SUBSCRIPTION_ID, logger);
185+
checkDeprecatedSettings(settings, Discovery.HOST_TYPE_DEPRECATED, Discovery.HOST_TYPE, logger);
186+
checkDeprecatedSettings(settings, Discovery.PORT_NAME_DEPRECATED, Discovery.ENDPOINT_NAME, logger);
192187
}
193188
}
194189

src/main/java/org/elasticsearch/cloud/azure/blobstore/AzureBlobStore.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@
2929
import org.elasticsearch.common.settings.Settings;
3030
import org.elasticsearch.repositories.RepositoryName;
3131
import org.elasticsearch.repositories.RepositorySettings;
32-
import org.elasticsearch.repositories.azure.AzureRepository;
3332

3433
import java.net.URISyntaxException;
3534

35+
import static org.elasticsearch.cloud.azure.storage.AzureStorageService.Storage.CONTAINER;
36+
import static org.elasticsearch.repositories.azure.AzureRepository.CONTAINER_DEFAULT;
37+
3638
/**
3739
*
3840
*/
@@ -48,8 +50,7 @@ public AzureBlobStore(RepositoryName name, Settings settings, RepositorySettings
4850
AzureStorageService client) throws URISyntaxException, StorageException {
4951
super(settings);
5052
this.client = client;
51-
this.container = repositorySettings.settings().get(AzureStorageService.Fields.CONTAINER,
52-
componentSettings.get(AzureStorageService.Fields.CONTAINER, AzureRepository.CONTAINER_DEFAULT));
53+
this.container = repositorySettings.settings().get("container", settings.get(CONTAINER, CONTAINER_DEFAULT));
5354
this.repositoryName = name.getName();
5455
}
5556

src/main/java/org/elasticsearch/cloud/azure/management/AzureComputeService.java

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,43 @@
2626
*/
2727
public interface AzureComputeService {
2828

29-
static public final class Fields {
29+
static public final class Management {
3030
// Deprecated azure management cloud settings
3131
@Deprecated
32-
public static final String SUBSCRIPTION_ID_DEPRECATED = "subscription_id";
32+
public static final String SUBSCRIPTION_ID_DEPRECATED = "cloud.azure.subscription_id";
3333
@Deprecated
34-
public static final String SERVICE_NAME_DEPRECATED = "service_name";
34+
public static final String SERVICE_NAME_DEPRECATED = "cloud.azure.service_name";
3535
@Deprecated
36-
public static final String KEYSTORE_DEPRECATED = "keystore";
36+
public static final String KEYSTORE_DEPRECATED = "cloud.azure.keystore";
3737
@Deprecated
38-
public static final String PASSWORD_DEPRECATED = "password";
39-
@Deprecated
40-
public static final String PORT_NAME_DEPRECATED = "port_name";
41-
@Deprecated
42-
public static final String HOST_TYPE_DEPRECATED = "host_type";
38+
public static final String PASSWORD_DEPRECATED = "cloud.azure.password";
39+
40+
public static final String API_IMPLEMENTATION = "cloud.azure.management.api.impl";
4341

44-
public static final String SUBSCRIPTION_ID = "subscription.id";
45-
public static final String SERVICE_NAME = "cloud.service.name";
42+
public static final String SUBSCRIPTION_ID = "cloud.azure.management.subscription.id";
43+
public static final String SERVICE_NAME = "cloud.azure.management.cloud.service.name";
4644

4745
// Keystore settings
48-
public static final String KEYSTORE_PATH = "keystore.path";
49-
public static final String KEYSTORE_PASSWORD = "keystore.password";
50-
public static final String KEYSTORE_TYPE = "keystore.type";
46+
public static final String KEYSTORE_PATH = "cloud.azure.management.keystore.path";
47+
public static final String KEYSTORE_PASSWORD = "cloud.azure.management.keystore.password";
48+
public static final String KEYSTORE_TYPE = "cloud.azure.management.keystore.type";
49+
}
5150

52-
public static final String REFRESH = "refresh_interval";
51+
static public final class Discovery {
52+
// Deprecated azure discovery cloud settings
53+
@Deprecated
54+
public static final String PORT_NAME_DEPRECATED = "cloud.azure.port_name";
55+
@Deprecated
56+
public static final String HOST_TYPE_DEPRECATED = "cloud.azure.host_type";
57+
@Deprecated
58+
public static final String REFRESH_DEPRECATED = "cloud.azure.refresh_interval";
5359

54-
public static final String HOST_TYPE = "host.type";
55-
public static final String ENDPOINT_NAME = "endpoint.name";
56-
public static final String DEPLOYMENT_NAME = "deployment.name";
57-
public static final String DEPLOYMENT_SLOT = "deployment.slot";
58-
}
60+
public static final String REFRESH = "discovery.azure.refresh_interval";
5961

62+
public static final String HOST_TYPE = "discovery.azure.host.type";
63+
public static final String ENDPOINT_NAME = "discovery.azure.endpoint.name";
64+
public static final String DEPLOYMENT_NAME = "discovery.azure.deployment.name";
65+
public static final String DEPLOYMENT_SLOT = "discovery.azure.deployment.slot";
66+
}
6067
public HostedServiceGetDetailedResponse getServiceDetails();
6168
}

src/main/java/org/elasticsearch/cloud/azure/management/AzureComputeServiceImpl.java

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import java.net.URI;
3838
import java.net.URISyntaxException;
3939

40+
import static org.elasticsearch.cloud.azure.management.AzureComputeService.Management.*;
41+
4042
/**
4143
*
4244
*/
@@ -53,34 +55,29 @@ static final class Azure {
5355
@Inject
5456
public AzureComputeServiceImpl(Settings settings, SettingsFilter settingsFilter) {
5557
super(settings);
56-
// Cloud global settings
57-
settingsFilter.addFilter("cloud.azure." + AzureComputeService.Fields.REFRESH);
58-
59-
// Cloud management API settings
60-
settingsFilter.addFilter("cloud.azure.management." + AzureComputeService.Fields.KEYSTORE_PATH);
61-
settingsFilter.addFilter("cloud.azure.management." + AzureComputeService.Fields.KEYSTORE_PASSWORD);
62-
settingsFilter.addFilter("cloud.azure.management." + AzureComputeService.Fields.KEYSTORE_TYPE);
63-
settingsFilter.addFilter("cloud.azure.management." + AzureComputeService.Fields.SUBSCRIPTION_ID);
64-
settingsFilter.addFilter("cloud.azure.management." + AzureComputeService.Fields.SERVICE_NAME);
58+
// Cloud management API settings we need to hide
59+
settingsFilter.addFilter(KEYSTORE_PATH);
60+
settingsFilter.addFilter(KEYSTORE_PASSWORD);
61+
settingsFilter.addFilter(KEYSTORE_TYPE);
62+
settingsFilter.addFilter(SUBSCRIPTION_ID);
6563

66-
// Deprecated Cloud management API settings
64+
// Deprecated Cloud management API settings we need to hide
6765
// TODO Remove in 3.0.0
68-
settingsFilter.addFilter("cloud.azure." + AzureComputeService.Fields.KEYSTORE_DEPRECATED);
69-
settingsFilter.addFilter("cloud.azure." + AzureComputeService.Fields.PASSWORD_DEPRECATED);
70-
settingsFilter.addFilter("cloud.azure." + AzureComputeService.Fields.SUBSCRIPTION_ID_DEPRECATED);
71-
settingsFilter.addFilter("cloud.azure." + AzureComputeService.Fields.SERVICE_NAME_DEPRECATED);
66+
settingsFilter.addFilter(KEYSTORE_DEPRECATED);
67+
settingsFilter.addFilter(PASSWORD_DEPRECATED);
68+
settingsFilter.addFilter(SUBSCRIPTION_ID_DEPRECATED);
7269

73-
String subscriptionId = componentSettings.get(Fields.SUBSCRIPTION_ID, settings.get("cloud.azure." + Fields.SUBSCRIPTION_ID_DEPRECATED));
70+
String subscriptionId = settings.get(SUBSCRIPTION_ID, settings.get(SUBSCRIPTION_ID_DEPRECATED));
7471

75-
serviceName = componentSettings.get(Fields.SERVICE_NAME, settings.get("cloud.azure." + Fields.SERVICE_NAME_DEPRECATED));
76-
String keystorePath = componentSettings.get(Fields.KEYSTORE_PATH, settings.get("cloud.azure." + Fields.KEYSTORE_DEPRECATED));
77-
String keystorePassword = componentSettings.get(Fields.KEYSTORE_PASSWORD, settings.get("cloud.azure." + Fields.PASSWORD_DEPRECATED));
78-
String strKeyStoreType = componentSettings.get(Fields.KEYSTORE_TYPE, KeyStoreType.pkcs12.name());
72+
serviceName = settings.get(Management.SERVICE_NAME, settings.get(Management.SERVICE_NAME_DEPRECATED));
73+
String keystorePath = settings.get(KEYSTORE_PATH, settings.get(KEYSTORE_DEPRECATED));
74+
String keystorePassword = settings.get(KEYSTORE_PASSWORD, settings.get(PASSWORD_DEPRECATED));
75+
String strKeyStoreType = settings.get(KEYSTORE_TYPE, KeyStoreType.pkcs12.name());
7976
KeyStoreType tmpKeyStoreType = KeyStoreType.pkcs12;
8077
try {
8178
tmpKeyStoreType = KeyStoreType.fromString(strKeyStoreType);
8279
} catch (Exception e) {
83-
logger.warn("wrong value for [{}]: [{}]. falling back to [{}]...", Fields.KEYSTORE_TYPE,
80+
logger.warn("wrong value for [{}]: [{}]. falling back to [{}]...", KEYSTORE_TYPE,
8481
strKeyStoreType, KeyStoreType.pkcs12.name());
8582
}
8683
KeyStoreType keystoreType = tmpKeyStoreType;

0 commit comments

Comments
 (0)