Skip to content

Commit 3492bdb

Browse files
authored
Fix repository-azure for empty settings on reload (#79559)
Today when reloading settings, if the repository-azure plugin is installed and no repositories of type "azure" are defined, the repository-azure plugin will throw an exception that no client configurations are specified, and it will not process the update (thus, leaving the definition of existing repositories). This behavior has the impact that if the repository-azure plugin is installed, but no repositories of type "azure" are defined, then any attempt to reload settings will receive an exception. This behavior appears to be legacy, and is not mirrored in the other cloud service provider repository plugins. This commit removes that behavior. This enables installing the repository-azure plugin by default, without requiring that a repository of type "azure" be configured.
1 parent 965b2df commit 3492bdb

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureRepositoryPlugin.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@
99
package org.elasticsearch.repositories.azure;
1010

1111
import com.azure.core.util.serializer.JacksonAdapter;
12+
1213
import org.apache.lucene.util.SetOnce;
1314
import org.elasticsearch.client.Client;
1415
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
1516
import org.elasticsearch.cluster.service.ClusterService;
1617
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
1718
import org.elasticsearch.common.settings.Setting;
1819
import org.elasticsearch.common.settings.Settings;
19-
import org.elasticsearch.common.settings.SettingsException;
20-
import org.elasticsearch.core.TimeValue;
2120
import org.elasticsearch.common.util.BigArrays;
22-
import org.elasticsearch.xcontent.NamedXContentRegistry;
21+
import org.elasticsearch.core.TimeValue;
2322
import org.elasticsearch.env.Environment;
2423
import org.elasticsearch.env.NodeEnvironment;
2524
import org.elasticsearch.indices.recovery.RecoverySettings;
@@ -33,6 +32,7 @@
3332
import org.elasticsearch.threadpool.ScalingExecutorBuilder;
3433
import org.elasticsearch.threadpool.ThreadPool;
3534
import org.elasticsearch.watcher.ResourceWatcherService;
35+
import org.elasticsearch.xcontent.NamedXContentRegistry;
3636

3737
import java.util.Arrays;
3838
import java.util.Collection;
@@ -132,9 +132,6 @@ public static ExecutorBuilder<?> nettyEventLoopExecutorBuilder(Settings settings
132132
public void reload(Settings settings) {
133133
// secure settings should be readable
134134
final Map<String, AzureStorageSettings> clientsSettings = AzureStorageSettings.load(settings);
135-
if (clientsSettings.isEmpty()) {
136-
throw new SettingsException("If you want to use an azure repository, you need to define a client configuration.");
137-
}
138135
AzureStorageService storageService = azureStoreService.get();
139136
assert storageService != null;
140137
storageService.refreshSettings(clientsSettings);

plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureStorageServiceTests.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
package org.elasticsearch.repositories.azure;
1010

1111
import com.azure.storage.common.policy.RequestRetryOptions;
12+
1213
import org.elasticsearch.common.settings.MockSecureSettings;
1314
import org.elasticsearch.common.settings.Settings;
1415
import org.elasticsearch.common.settings.SettingsException;
@@ -163,14 +164,14 @@ public void testReinitClientEmptySettings() throws IOException {
163164
final AzureStorageService azureStorageService = plugin.azureStoreService.get();
164165
AzureBlobServiceClient client11 = azureStorageService.client("azure1", LocationMode.PRIMARY_ONLY);
165166
assertThat(client11.getSyncClient().getAccountUrl(), equalTo("https://myaccount1.blob.core.windows.net"));
166-
// reinit with empty settings
167-
final SettingsException e = expectThrows(SettingsException.class, () -> plugin.reload(Settings.EMPTY));
168-
assertThat(e.getMessage(), is("If you want to use an azure repository, you need to define a client configuration."));
167+
// reinit with empty settings is okay
168+
plugin.reload(Settings.EMPTY);
169169
// existing client untouched
170170
assertThat(client11.getSyncClient().getAccountUrl(), equalTo("https://myaccount1.blob.core.windows.net"));
171-
// new client also untouched
172-
AzureBlobServiceClient client21 = azureStorageService.client("azure1", LocationMode.PRIMARY_ONLY);
173-
assertThat(client21.getSyncClient().getAccountUrl(), equalTo("https://myaccount1.blob.core.windows.net"));
171+
// client is no longer registered
172+
final SettingsException e =
173+
expectThrows(SettingsException.class, () -> azureStorageService.client("azure1", LocationMode.PRIMARY_ONLY));
174+
assertThat(e.getMessage(), equalTo("Unable to find client with name [azure1]"));
174175
}
175176
}
176177

0 commit comments

Comments
 (0)