Skip to content

Commit 42509d0

Browse files
committed
Rename settings for discovery
Azure Java SDK follows some conventions about property names and we can use the same convention. The benefit is that it makes the code cleaner and easier to understand as components settings relies on package name without the `org.elasticsearch` prefix. In previous versions, we defined: ``` cloud: azure: keystore: /path/to/keystore password: your_password_for_keystore subscription_id: your_azure_subscription_id service_name: your_azure_cloud_service_name port_name: elasticsearch host_type: private_ip ``` We now define: ``` cloud: azure: management: keystore: path: /path/to/keystore password: your_password_for_keystore subscription: id: your_azure_subscription_id cloud: service: name: your_azure_cloud_service_name discovery: azure: host: type: private_ip endpoint: name: elasticsearch ``` The following are a list of settings (prefixed with `cloud.azure.management`) that can further control the discovery: * `keystore.path`: /path/to/keystore * `keystore.password`: your_password for the keystore * `subscription.id`: your_azure_subscription_id * `cloud.service.name`: your_azure_cloud_service_name So basically we deprecate the following properties: * `cloud.azure.keystore` to `cloud.azure.management.keystore.path` * `cloud.azure.password` to `cloud.azure.management.keystore.password` * `cloud.azure.subscription_id` to `cloud.azure.management.subscription.id` * `cloud.azure.service_name` to `cloud.azure.management.cloud.service.name` * `cloud.azure.port_name` to `discovery.azure.port.name` * `cloud.azure.host_type` to `discovery.azure.host.type` Note that we can still read deprecated settings but it will print a `WARN` with an advice to make sure users don't forget to move. (cherry picked from commit 04920a8) (cherry picked from commit 9745826)
1 parent 4954732 commit 42509d0

16 files changed

+221
-106
lines changed

README.md

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,16 @@ multicast environments). Here is a simple sample configuration:
3939
```
4040
cloud:
4141
azure:
42-
keystore: /path/to/keystore
43-
password: your_password_for_keystore
44-
subscription_id: your_azure_subscription_id
45-
service_name: your_azure_cloud_service_name
42+
management:
43+
subscription.id: XXX-XXX-XXX-XXX
44+
cloud.service.name: es-demo-app
45+
keystore:
46+
path: /path/to/azurekeystore.pkcs12
47+
password: WHATEVER
48+
type: pkcs12
49+
4650
discovery:
47-
type: azure
51+
type: azure
4852
```
4953

5054
How to start (short story)
@@ -56,6 +60,41 @@ How to start (short story)
5660
* Modify `elasticsearch.yml` file
5761
* Start Elasticsearch
5862

63+
Azure credential API settings
64+
-----------------------------
65+
66+
The following are a list of settings (prefixed with `cloud.azure.management`) that can further control the discovery:
67+
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
73+
74+
Note that in previous versions, it was:
75+
76+
```
77+
cloud:
78+
azure:
79+
keystore: /path/to/keystore
80+
password: your_password_for_keystore
81+
subscription_id: your_azure_subscription_id
82+
service_name: your_azure_cloud_service_name
83+
```
84+
85+
Advanced settings
86+
-----------------
87+
88+
The following are a list of settings (prefixed with `discovery.azure`) that can further control the discovery:
89+
90+
* `host.type`: either `public_ip` or `private_ip` (default). Azure discovery will use the one you set to ping
91+
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
93+
to elasticsearch (aka transport port name). Defaults to `elasticsearch`. In Azure management console, you could define
94+
an endpoint `elasticsearch` forwarding for example requests on public IP on port 8100 to the virtual machine on port 9300.
95+
This feature was not documented before but was existing under `cloud.azure.port_name`.
96+
97+
5998
How to start (long story)
6099
--------------------------
61100

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

Lines changed: 0 additions & 40 deletions
This file was deleted.

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

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import org.elasticsearch.ElasticsearchException;
2323
import org.elasticsearch.cloud.azure.storage.AzureStorageService;
2424
import org.elasticsearch.cloud.azure.storage.AzureStorageServiceImpl;
25+
import org.elasticsearch.cloud.azure.management.AzureComputeService;
26+
import org.elasticsearch.cloud.azure.management.AzureComputeServiceImpl;
2527
import org.elasticsearch.common.Strings;
2628
import org.elasticsearch.common.inject.AbstractModule;
2729
import org.elasticsearch.common.inject.Inject;
@@ -40,7 +42,7 @@
4042
* to AzureStorageServiceImpl.</li>
4143
* </ul>
4244
*
43-
* @see org.elasticsearch.cloud.azure.AzureComputeServiceImpl
45+
* @see org.elasticsearch.cloud.azure.management.AzureComputeServiceImpl
4446
* @see org.elasticsearch.cloud.azure.storage.AzureStorageServiceImpl
4547
*/
4648
public class AzureModule extends AbstractModule {
@@ -99,11 +101,23 @@ public static boolean isDiscoveryReady(Settings settings, ESLogger logger) {
99101
return false;
100102
}
101103

102-
if (isPropertyMissing(settings, "cloud.azure." + AzureComputeService.Fields.SUBSCRIPTION_ID, logger) ||
103-
isPropertyMissing(settings, "cloud.azure." + AzureComputeService.Fields.SERVICE_NAME, logger) ||
104-
isPropertyMissing(settings, "cloud.azure." + AzureComputeService.Fields.KEYSTORE, logger) ||
105-
isPropertyMissing(settings, "cloud.azure." + AzureComputeService.Fields.PASSWORD, logger)
104+
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))
109+
// 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))
106114
) {
115+
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);
107121
return false;
108122
}
109123

@@ -123,11 +137,11 @@ public static boolean isSnapshotReady(Settings settings, ESLogger logger) {
123137
return false;
124138
}
125139

126-
if ((isPropertyMissing(settings, "cloud.azure.storage." + AzureStorageService.Fields.ACCOUNT, null) ||
127-
isPropertyMissing(settings, "cloud.azure.storage." + AzureStorageService.Fields.KEY, null)) &&
128-
(isPropertyMissing(settings, "cloud.azure." + AzureStorageService.Fields.ACCOUNT_DEPRECATED, null) ||
129-
isPropertyMissing(settings, "cloud.azure." + AzureStorageService.Fields.KEY_DEPRECATED, null))) {
130-
logger.trace("azure repository is not set [using cloud.azure.storage.{}] and [cloud.azure.storage.{}] properties",
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",
131145
AzureStorageService.Fields.ACCOUNT,
132146
AzureStorageService.Fields.KEY);
133147
return false;
@@ -142,18 +156,44 @@ public static boolean isSnapshotReady(Settings settings, ESLogger logger) {
142156
* Check if we are using any deprecated settings
143157
*/
144158
public static void checkDeprecatedSettings(Settings settings, String oldParameter, String newParameter, ESLogger logger) {
145-
if (!isPropertyMissing(settings, oldParameter, null)) {
159+
if (!isPropertyMissing(settings, oldParameter)) {
146160
logger.warn("using deprecated [{}]. Please change it to [{}] property.",
147161
oldParameter,
148162
newParameter);
149163
}
150164
}
151165

152-
public static boolean isPropertyMissing(Settings settings, String name, ESLogger logger) throws ElasticsearchException {
166+
/**
167+
* Check all deprecated settings
168+
* @param settings
169+
* @param logger
170+
*/
171+
public static void checkDeprecated(Settings settings, ESLogger logger) {
172+
// Cloud services are disabled
173+
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);
178+
179+
// 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);
192+
}
193+
}
194+
195+
public static boolean isPropertyMissing(Settings settings, String name) throws ElasticsearchException {
153196
if (!Strings.hasText(settings.get(name))) {
154-
if (logger != null) {
155-
logger.warn("{} is not set or is incorrect.", name);
156-
}
157197
return true;
158198
}
159199
return false;

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.cloud.azure;
2121

22+
import org.elasticsearch.cloud.azure.management.AzureComputeService;
2223
import org.elasticsearch.cloud.azure.storage.AzureStorageService;
2324
import org.elasticsearch.common.settings.ImmutableSettings;
2425
import org.elasticsearch.common.settings.SettingsFilter;
@@ -30,11 +31,18 @@ public class AzureSettingsFilter implements SettingsFilter.Filter {
3031

3132
@Override
3233
public void filter(ImmutableSettings.Builder settings) {
33-
// Cloud settings
34-
settings.remove("cloud.azure.keystore");
35-
settings.remove("cloud.azure.password");
36-
settings.remove("cloud.azure.subscription_id");
37-
settings.remove("cloud.azure.service_name");
34+
// Cloud management API settings
35+
settings.remove("cloud.azure.management." + AzureComputeService.Fields.KEYSTORE_PATH);
36+
settings.remove("cloud.azure.management." + AzureComputeService.Fields.KEYSTORE_PASSWORD);
37+
settings.remove("cloud.azure.management." + AzureComputeService.Fields.SUBSCRIPTION_ID);
38+
settings.remove("cloud.azure.management." + AzureComputeService.Fields.SERVICE_NAME);
39+
40+
// Deprecated Cloud management API settings
41+
// TODO Remove in 3.0.0
42+
settings.remove("cloud.azure." + AzureComputeService.Fields.KEYSTORE_DEPRECATED);
43+
settings.remove("cloud.azure." + AzureComputeService.Fields.PASSWORD_DEPRECATED);
44+
settings.remove("cloud.azure." + AzureComputeService.Fields.SUBSCRIPTION_ID_DEPRECATED);
45+
settings.remove("cloud.azure." + AzureComputeService.Fields.SERVICE_NAME_DEPRECATED);
3846

3947
// Cloud storage API settings
4048
settings.remove("cloud.azure.storage." + AzureStorageService.Fields.ACCOUNT);
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.cloud.azure.management;
21+
22+
import org.elasticsearch.cloud.azure.Instance;
23+
24+
import java.util.Set;
25+
26+
/**
27+
*
28+
*/
29+
public interface AzureComputeService {
30+
31+
static public final class Fields {
32+
// Deprecated azure management cloud settings
33+
@Deprecated
34+
public static final String SUBSCRIPTION_ID_DEPRECATED = "subscription_id";
35+
@Deprecated
36+
public static final String SERVICE_NAME_DEPRECATED = "service_name";
37+
@Deprecated
38+
public static final String KEYSTORE_DEPRECATED = "keystore";
39+
@Deprecated
40+
public static final String PASSWORD_DEPRECATED = "password";
41+
@Deprecated
42+
public static final String PORT_NAME_DEPRECATED = "port_name";
43+
@Deprecated
44+
public static final String HOST_TYPE_DEPRECATED = "host_type";
45+
46+
public static final String SUBSCRIPTION_ID = "subscription.id";
47+
public static final String SERVICE_NAME = "cloud.service.name";
48+
49+
// Keystore settings
50+
public static final String KEYSTORE_PATH = "keystore.path";
51+
public static final String KEYSTORE_PASSWORD = "keystore.password";
52+
53+
public static final String REFRESH = "refresh_interval";
54+
55+
public static final String HOST_TYPE = "host.type";
56+
public static final String ENDPOINT_NAME = "endpoint.name";
57+
}
58+
59+
public Set<Instance> instances();
60+
}

0 commit comments

Comments
 (0)