Skip to content

Commit 4954732

Browse files
committed
Rename settings for repositories
Storage and Management settings are not related in Azure API. We were using the following convention for storage specific settings: ```yml cloud: azure: storage_account: your_azure_storage_account storage_key: your_azure_storage_key ``` A better naming (and Java packaging) would be by moving `storage` settings in their own package `cloud.azure.storage`: ```yml cloud: azure: storage: account: your_azure_storage_account key: your_azure_storage_key ``` 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 6b30c62) (cherry picked from commit 1237be9)
1 parent 696804e commit 4954732

File tree

12 files changed

+85
-30
lines changed

12 files changed

+85
-30
lines changed

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,17 @@ azure vm delete myesnode1
365365
Azure Repository
366366
================
367367
368-
To enable Azure repositories, you have first to set your azure storage settings:
368+
To enable Azure repositories, you have first to set your azure storage settings in `elasticsearch.yml` file:
369+
370+
```
371+
cloud:
372+
azure:
373+
storage:
374+
account: your_azure_storage_account
375+
key: your_azure_storage_key
376+
```
377+
378+
For information, in previous version of the azure plugin, settings were:
369379
370380
```
371381
cloud:
@@ -430,11 +440,12 @@ Testing
430440
=======
431441

432442
Integrations tests in this plugin require working Azure configuration and therefore disabled by default.
433-
To enable tests prepare a config file elasticsearch.yml with the following content:
443+
To enable tests prepare a config file `elasticsearch.yml` with the following content:
434444

435445
```
436446
cloud:
437447
azure:
448+
storage:
438449
account: "YOUR-AZURE-STORAGE-NAME"
439450
key: "YOUR-AZURE-STORAGE-KEY"
440451
```

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
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;
2325
import org.elasticsearch.common.Strings;
2426
import org.elasticsearch.common.inject.AbstractModule;
2527
import org.elasticsearch.common.inject.Inject;
@@ -39,7 +41,7 @@
3941
* </ul>
4042
*
4143
* @see org.elasticsearch.cloud.azure.AzureComputeServiceImpl
42-
* @see org.elasticsearch.cloud.azure.AzureStorageServiceImpl
44+
* @see org.elasticsearch.cloud.azure.storage.AzureStorageServiceImpl
4345
*/
4446
public class AzureModule extends AbstractModule {
4547
protected final ESLogger logger;
@@ -121,9 +123,11 @@ public static boolean isSnapshotReady(Settings settings, ESLogger logger) {
121123
return false;
122124
}
123125

124-
if (isPropertyMissing(settings, "cloud.azure." + AzureStorageService.Fields.ACCOUNT, null) ||
125-
isPropertyMissing(settings, "cloud.azure." + AzureStorageService.Fields.KEY, null)) {
126-
logger.trace("azure repository is not set using {} and {} properties",
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",
127131
AzureStorageService.Fields.ACCOUNT,
128132
AzureStorageService.Fields.KEY);
129133
return false;
@@ -134,6 +138,17 @@ public static boolean isSnapshotReady(Settings settings, ESLogger logger) {
134138
return true;
135139
}
136140

141+
/**
142+
* Check if we are using any deprecated settings
143+
*/
144+
public static void checkDeprecatedSettings(Settings settings, String oldParameter, String newParameter, ESLogger logger) {
145+
if (!isPropertyMissing(settings, oldParameter, null)) {
146+
logger.warn("using deprecated [{}]. Please change it to [{}] property.",
147+
oldParameter,
148+
newParameter);
149+
}
150+
}
151+
137152
public static boolean isPropertyMissing(Settings settings, String name, ESLogger logger) throws ElasticsearchException {
138153
if (!Strings.hasText(settings.get(name))) {
139154
if (logger != null) {

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919

2020
package org.elasticsearch.cloud.azure;
2121

22+
import org.elasticsearch.cloud.azure.storage.AzureStorageService;
2223
import org.elasticsearch.common.settings.ImmutableSettings;
2324
import org.elasticsearch.common.settings.SettingsFilter;
2425

2526
/**
26-
* Filtering cloud.azure.* and repositories.azure.* settings
27+
* Filtering cloud.azure.* settings
2728
*/
2829
public class AzureSettingsFilter implements SettingsFilter.Filter {
2930

@@ -35,10 +36,13 @@ public void filter(ImmutableSettings.Builder settings) {
3536
settings.remove("cloud.azure.subscription_id");
3637
settings.remove("cloud.azure.service_name");
3738

38-
// Repositories settings
39-
settings.remove("repositories.azure.account");
40-
settings.remove("repositories.azure.key");
41-
settings.remove("repositories.azure.container");
42-
settings.remove("repositories.azure.base_path");
39+
// Cloud storage API settings
40+
settings.remove("cloud.azure.storage." + AzureStorageService.Fields.ACCOUNT);
41+
settings.remove("cloud.azure.storage." + AzureStorageService.Fields.KEY);
42+
43+
// Deprecated Cloud storage API settings
44+
// TODO Remove in 3.0.0
45+
settings.remove("cloud.azure." + AzureStorageService.Fields.ACCOUNT_DEPRECATED);
46+
settings.remove("cloud.azure." + AzureStorageService.Fields.KEY_DEPRECATED);
4347
}
4448
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
package org.elasticsearch.cloud.azure.blobstore;
2121

2222
import com.microsoft.azure.storage.StorageException;
23-
import org.elasticsearch.cloud.azure.AzureStorageService;
23+
import org.elasticsearch.cloud.azure.storage.AzureStorageService;
2424
import org.elasticsearch.common.blobstore.BlobContainer;
2525
import org.elasticsearch.common.blobstore.BlobPath;
2626
import org.elasticsearch.common.blobstore.BlobStore;

src/main/java/org/elasticsearch/cloud/azure/AzureStorageService.java renamed to src/main/java/org/elasticsearch/cloud/azure/storage/AzureStorageService.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
package org.elasticsearch.cloud.azure;
20+
package org.elasticsearch.cloud.azure.storage;
2121

2222
import com.microsoft.azure.storage.StorageException;
2323
import org.elasticsearch.common.blobstore.BlobMetaData;
@@ -29,12 +29,16 @@
2929

3030
/**
3131
* Azure Storage Service interface
32-
* @see org.elasticsearch.cloud.azure.AzureStorageServiceImpl for Azure REST API implementation
32+
* @see AzureStorageServiceImpl for Azure REST API implementation
3333
*/
3434
public interface AzureStorageService {
3535
static public final class Fields {
36-
public static final String ACCOUNT = "storage_account";
37-
public static final String KEY = "storage_key";
36+
@Deprecated
37+
public static final String ACCOUNT_DEPRECATED = "storage_account";
38+
@Deprecated
39+
public static final String KEY_DEPRECATED = "storage_key";
40+
public static final String ACCOUNT = "account";
41+
public static final String KEY = "key";
3842
public static final String CONTAINER = "container";
3943
public static final String BASE_PATH = "base_path";
4044
public static final String CHUNK_SIZE = "chunk_size";

src/main/java/org/elasticsearch/cloud/azure/AzureStorageServiceImpl.java renamed to src/main/java/org/elasticsearch/cloud/azure/storage/AzureStorageServiceImpl.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
* under the License.
1818
*/
1919

20-
package org.elasticsearch.cloud.azure;
20+
package org.elasticsearch.cloud.azure.storage;
2121

2222
import com.microsoft.azure.storage.CloudStorageAccount;
2323
import com.microsoft.azure.storage.StorageException;
2424
import com.microsoft.azure.storage.blob.*;
2525
import org.elasticsearch.ElasticsearchException;
26+
import org.elasticsearch.cloud.azure.AzureSettingsFilter;
2627
import org.elasticsearch.common.blobstore.BlobMetaData;
2728
import org.elasticsearch.common.blobstore.support.PlainBlobMetaData;
2829
import org.elasticsearch.common.collect.ImmutableMap;
@@ -54,9 +55,9 @@ public AzureStorageServiceImpl(Settings settings, SettingsFilter settingsFilter)
5455
super(settings);
5556
settingsFilter.addFilter(new AzureSettingsFilter());
5657

57-
// We try to load storage API settings from `cloud.azure.`
58-
account = settings.get("cloud.azure." + Fields.ACCOUNT);
59-
key = settings.get("cloud.azure." + Fields.KEY);
58+
// We try to load storage API settings from `repositories.azure.`
59+
account = componentSettings.get(Fields.ACCOUNT, settings.get("cloud.azure." + Fields.ACCOUNT_DEPRECATED));
60+
key = componentSettings.get(Fields.KEY, settings.get("cloud.azure." + Fields.KEY_DEPRECATED));
6061
blob = "http://" + account + ".blob.core.windows.net/";
6162

6263
try {

src/main/java/org/elasticsearch/plugin/cloud/azure/CloudAzurePlugin.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.elasticsearch.plugin.cloud.azure;
2121

2222
import org.elasticsearch.cloud.azure.AzureModule;
23+
import org.elasticsearch.cloud.azure.storage.AzureStorageService;
2324
import org.elasticsearch.common.collect.Lists;
2425
import org.elasticsearch.common.inject.Module;
2526
import org.elasticsearch.common.logging.ESLogger;
@@ -32,6 +33,9 @@
3233

3334
import java.util.Collection;
3435

36+
import static org.elasticsearch.cloud.azure.AzureModule.checkDeprecatedSettings;
37+
import static org.elasticsearch.cloud.azure.AzureModule.isSnapshotReady;
38+
3539
/**
3640
*
3741
*/
@@ -65,9 +69,18 @@ public Collection<Class<? extends Module>> modules() {
6569

6670
@Override
6771
public void processModule(Module module) {
68-
if (AzureModule.isSnapshotReady(settings, logger)
72+
if (isSnapshotReady(settings, logger)
6973
&& module instanceof RepositoriesModule) {
74+
// Check if we have any deprecated setting
75+
checkDeprecated();
7076
((RepositoriesModule)module).registerRepository(AzureRepository.TYPE, AzureRepositoryModule.class);
7177
}
7278
}
79+
80+
private void checkDeprecated() {
81+
checkDeprecatedSettings(settings, "cloud.azure." + AzureStorageService.Fields.ACCOUNT_DEPRECATED,
82+
"cloud.azure.storage." + AzureStorageService.Fields.ACCOUNT, logger);
83+
checkDeprecatedSettings(settings, "cloud.azure." + AzureStorageService.Fields.KEY_DEPRECATED,
84+
"cloud.azure.storage." + AzureStorageService.Fields.KEY, logger);
85+
}
7386
}

src/main/java/org/elasticsearch/repositories/azure/AzureRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
package org.elasticsearch.repositories.azure;
2121

2222
import com.microsoft.azure.storage.StorageException;
23-
import org.elasticsearch.cloud.azure.AzureStorageService;
23+
import org.elasticsearch.cloud.azure.storage.AzureStorageService;
2424
import org.elasticsearch.cloud.azure.blobstore.AzureBlobStore;
2525
import org.elasticsearch.cluster.metadata.MetaData;
2626
import org.elasticsearch.cluster.metadata.SnapshotId;

src/test/java/org/elasticsearch/repositories/azure/AzureStorageServiceMock.java renamed to src/test/java/org/elasticsearch/cloud/azure/storage/AzureStorageServiceMock.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
* under the License.
1818
*/
1919

20-
package org.elasticsearch.repositories.azure;
20+
package org.elasticsearch.cloud.azure.storage;
2121

2222
import com.microsoft.azure.storage.StorageException;
2323
import org.elasticsearch.ElasticsearchException;
24-
import org.elasticsearch.cloud.azure.AzureStorageService;
2524
import org.elasticsearch.common.blobstore.BlobMetaData;
2625
import org.elasticsearch.common.blobstore.support.PlainBlobMetaData;
2726
import org.elasticsearch.common.collect.ImmutableMap;

src/test/java/org/elasticsearch/repositories/azure/AbstractAzureRepositoryServiceTest.java

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

2222
import com.microsoft.azure.storage.StorageException;
2323
import org.elasticsearch.cloud.azure.AbstractAzureTest;
24-
import org.elasticsearch.cloud.azure.AzureStorageService;
24+
import org.elasticsearch.cloud.azure.storage.AzureStorageService;
2525
import org.elasticsearch.cluster.metadata.IndexMetaData;
2626
import org.elasticsearch.common.settings.ImmutableSettings;
2727
import org.elasticsearch.common.settings.Settings;
@@ -66,11 +66,18 @@ public static void wipeRepositories(String... repositories) {
6666
protected Settings nodeSettings(int nodeOrdinal) {
6767
ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder()
6868
.put("plugins." + PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, true)
69-
.put("cloud.azure." + AzureStorageService.Fields.ACCOUNT, "mock_azure_account")
70-
.put("cloud.azure." + AzureStorageService.Fields.KEY, "mock_azure_key")
7169
.put("repositories.azure.api.impl", mock)
7270
.put("repositories.azure.container", "snapshots");
7371

72+
// We use sometime deprecated settings in tests
73+
if (rarely()) {
74+
builder.put("cloud.azure." + AzureStorageService.Fields.ACCOUNT_DEPRECATED, "mock_azure_account")
75+
.put("cloud.azure." + AzureStorageService.Fields.KEY_DEPRECATED, "mock_azure_key");
76+
} else {
77+
builder.put("cloud.azure.storage." + AzureStorageService.Fields.ACCOUNT, "mock_azure_account")
78+
.put("cloud.azure.storage." + AzureStorageService.Fields.KEY, "mock_azure_key");
79+
}
80+
7481
return builder.build();
7582
}
7683

src/test/java/org/elasticsearch/repositories/azure/AzureSnapshotRestoreITest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
import org.elasticsearch.client.ClusterAdminClient;
2929
import org.elasticsearch.cloud.azure.AbstractAzureTest;
3030
import org.elasticsearch.cloud.azure.AzureSettingsFilter;
31-
import org.elasticsearch.cloud.azure.AzureStorageService;
32-
import org.elasticsearch.cloud.azure.AzureStorageServiceImpl;
31+
import org.elasticsearch.cloud.azure.storage.AzureStorageService;
32+
import org.elasticsearch.cloud.azure.storage.AzureStorageServiceImpl;
3333
import org.elasticsearch.cluster.ClusterState;
3434
import org.elasticsearch.common.Strings;
3535
import org.elasticsearch.common.base.Predicate;

src/test/java/org/elasticsearch/repositories/azure/AzureSnapshotRestoreTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse;
2525
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse;
2626
import org.elasticsearch.client.Client;
27+
import org.elasticsearch.cloud.azure.storage.AzureStorageServiceMock;
2728
import org.elasticsearch.cluster.ClusterState;
2829
import org.elasticsearch.common.settings.ImmutableSettings;
2930
import org.elasticsearch.snapshots.SnapshotState;

0 commit comments

Comments
 (0)