Skip to content

Commit ff000bd

Browse files
committed
more wiring changes
1 parent 9b3c605 commit ff000bd

File tree

6 files changed

+34
-24
lines changed

6 files changed

+34
-24
lines changed

modules/repository-gcs/src/internalClusterTest/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageBlobStoreRepositoryTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ public TestGoogleCloudStoragePlugin(Settings settings) {
235235
}
236236

237237
@Override
238-
protected GoogleCloudStorageService createStorageService(boolean isServerless) {
239-
return new GoogleCloudStorageService() {
238+
protected GoogleCloudStorageService createStorageService(ClusterService clusterService) {
239+
return new GoogleCloudStorageService(clusterService) {
240240
@Override
241241
StorageOptions createStorageOptions(
242242
final GoogleCloudStorageClientSettings gcsClientSettings,

modules/repository-gcs/src/main/java/org/elasticsearch/repositories/gcs/GoogleCloudStoragePlugin.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
package org.elasticsearch.repositories.gcs;
1111

1212
import org.apache.lucene.util.SetOnce;
13-
import org.elasticsearch.cluster.node.DiscoveryNode;
1413
import org.elasticsearch.cluster.service.ClusterService;
1514
import org.elasticsearch.common.settings.Setting;
1615
import org.elasticsearch.common.settings.Settings;
@@ -32,18 +31,14 @@
3231

3332
public class GoogleCloudStoragePlugin extends Plugin implements RepositoryPlugin, ReloadablePlugin {
3433

35-
private final Settings settings;
3634
// package-private for tests
3735
final SetOnce<GoogleCloudStorageService> storageService = new SetOnce<>();
3836

39-
@SuppressWarnings("this-escape")
40-
public GoogleCloudStoragePlugin(final Settings settings) {
41-
this.settings = settings;
42-
}
37+
public GoogleCloudStoragePlugin(final Settings settings) {}
4338

4439
// overridable for tests
45-
protected GoogleCloudStorageService createStorageService(boolean isServerless) {
46-
return new GoogleCloudStorageService(isServerless);
40+
protected GoogleCloudStorageService createStorageService(ClusterService clusterService) {
41+
return new GoogleCloudStorageService(clusterService);
4742
}
4843

4944
@Override
@@ -72,10 +67,10 @@ public Map<String, Repository.Factory> getRepositories(
7267

7368
@Override
7469
public Collection<?> createComponents(PluginServices services) {
75-
var isServerless = DiscoveryNode.isStateless(settings);
76-
storageService.set(createStorageService(isServerless));
70+
final ClusterService clusterService = services.clusterService();
71+
storageService.set(createStorageService(clusterService));
7772
// eagerly load client settings so that secure settings are readable (not closed)
78-
reload(settings);
73+
reload(clusterService.getSettings());
7974
return List.of(storageService.get());
8075
}
8176

modules/repository-gcs/src/main/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageService.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import org.apache.logging.log4j.LogManager;
2626
import org.apache.logging.log4j.Logger;
2727
import org.elasticsearch.ExceptionsHelper;
28+
import org.elasticsearch.cluster.node.DiscoveryNode;
29+
import org.elasticsearch.cluster.service.ClusterService;
2830
import org.elasticsearch.common.Strings;
2931
import org.elasticsearch.common.util.Maps;
3032
import org.elasticsearch.core.Nullable;
@@ -57,12 +59,8 @@ public class GoogleCloudStorageService {
5759

5860
private final boolean isServerless;
5961

60-
public GoogleCloudStorageService() {
61-
this.isServerless = false;
62-
}
63-
64-
public GoogleCloudStorageService(boolean isServerless) {
65-
this.isServerless = isServerless;
62+
public GoogleCloudStorageService(ClusterService clusterService) {
63+
this.isServerless = DiscoveryNode.isStateless(clusterService.getSettings());
6664
}
6765

6866
public boolean isServerless() {

modules/repository-gcs/src/test/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageBlobContainerRetriesTests.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import org.apache.http.HttpStatus;
2626
import org.elasticsearch.ExceptionsHelper;
27+
import org.elasticsearch.cluster.service.ClusterService;
2728
import org.elasticsearch.common.BackoffPolicy;
2829
import org.elasticsearch.common.Strings;
2930
import org.elasticsearch.common.UUIDs;
@@ -42,6 +43,7 @@
4243
import org.elasticsearch.common.unit.ByteSizeValue;
4344
import org.elasticsearch.common.util.BigArrays;
4445
import org.elasticsearch.common.util.concurrent.CountDown;
46+
import org.elasticsearch.common.util.concurrent.DeterministicTaskQueue;
4547
import org.elasticsearch.core.Nullable;
4648
import org.elasticsearch.core.SuppressForbidden;
4749
import org.elasticsearch.core.TimeValue;
@@ -51,6 +53,7 @@
5153
import org.elasticsearch.repositories.blobstore.ESMockAPIBasedRepositoryIntegTestCase;
5254
import org.elasticsearch.rest.RestStatus;
5355
import org.elasticsearch.rest.RestUtils;
56+
import org.elasticsearch.test.ClusterServiceUtils;
5457
import org.elasticsearch.test.fixture.HttpHeaderParser;
5558
import org.threeten.bp.Duration;
5659

@@ -95,6 +98,7 @@
9598
@SuppressForbidden(reason = "use a http server")
9699
public class GoogleCloudStorageBlobContainerRetriesTests extends AbstractBlobContainerRetriesTestCase {
97100

101+
private final ClusterService clusterService = ClusterServiceUtils.createClusterService(new DeterministicTaskQueue().getThreadPool());
98102
private final Map<String, AtomicInteger> requestCounters = new ConcurrentHashMap<>();
99103
private String endpointUrlOverride;
100104

@@ -145,7 +149,7 @@ protected BlobContainer createBlobContainer(
145149
secureSettings.setFile(CREDENTIALS_FILE_SETTING.getConcreteSettingForNamespace(client).getKey(), createServiceAccount(random()));
146150
clientSettings.setSecureSettings(secureSettings);
147151

148-
final GoogleCloudStorageService service = new GoogleCloudStorageService() {
152+
final GoogleCloudStorageService service = new GoogleCloudStorageService(clusterService) {
149153
@Override
150154
StorageOptions createStorageOptions(
151155
final GoogleCloudStorageClientSettings gcsClientSettings,

modules/repository-gcs/src/test/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageBlobContainerStatsTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.elasticsearch.core.TimeValue;
3232
import org.elasticsearch.core.Tuple;
3333
import org.elasticsearch.mocksocket.MockHttpServer;
34+
import org.elasticsearch.test.ClusterServiceUtils;
3435
import org.elasticsearch.test.ESTestCase;
3536
import org.elasticsearch.threadpool.TestThreadPool;
3637
import org.elasticsearch.threadpool.ThreadPool;
@@ -104,7 +105,7 @@ public void createStorageService() throws Exception {
104105
threadPool = new TestThreadPool(getTestClass().getName());
105106
httpServer = MockHttpServer.createHttp(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), 0);
106107
httpServer.start();
107-
googleCloudStorageService = new GoogleCloudStorageService();
108+
googleCloudStorageService = new GoogleCloudStorageService(ClusterServiceUtils.createClusterService(threadPool));
108109
googleCloudStorageHttpHandler = new GoogleCloudStorageHttpHandler(BUCKET);
109110
httpServer.createContext("/", googleCloudStorageHttpHandler);
110111
httpServer.createContext("/token", new FakeOAuth2HttpHandler());

modules/repository-gcs/src/test/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageServiceTests.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
import org.elasticsearch.common.settings.MockSecureSettings;
2222
import org.elasticsearch.common.settings.Setting;
2323
import org.elasticsearch.common.settings.Settings;
24+
import org.elasticsearch.common.util.concurrent.DeterministicTaskQueue;
2425
import org.elasticsearch.core.TimeValue;
2526
import org.elasticsearch.plugins.Plugin;
27+
import org.elasticsearch.test.ClusterServiceUtils;
2628
import org.elasticsearch.test.ESTestCase;
2729
import org.elasticsearch.xcontent.XContentBuilder;
2830
import org.hamcrest.Matchers;
@@ -40,6 +42,7 @@
4042
import static org.hamcrest.Matchers.containsString;
4143
import static org.hamcrest.Matchers.equalTo;
4244
import static org.mockito.Mockito.mock;
45+
import static org.mockito.Mockito.when;
4346

4447
public class GoogleCloudStorageServiceTests extends ESTestCase {
4548

@@ -73,7 +76,8 @@ public void testClientInitializer() throws Exception {
7376
.put(GoogleCloudStorageClientSettings.PROXY_PORT_SETTING.getConcreteSettingForNamespace(clientName).getKey(), 8080)
7477
.build();
7578
SetOnce<Proxy> proxy = new SetOnce<>();
76-
final GoogleCloudStorageService service = new GoogleCloudStorageService() {
79+
final var clusterService = ClusterServiceUtils.createClusterService(new DeterministicTaskQueue().getThreadPool());
80+
final GoogleCloudStorageService service = new GoogleCloudStorageService(clusterService) {
7781
@Override
7882
void notifyProxyIsSet(Proxy p) {
7983
proxy.set(p);
@@ -114,8 +118,12 @@ public void testReinitClientSettings() throws Exception {
114118
secureSettings2.setFile("gcs.client.gcs1.credentials_file", serviceAccountFileContent("project_gcs21"));
115119
secureSettings2.setFile("gcs.client.gcs3.credentials_file", serviceAccountFileContent("project_gcs23"));
116120
final Settings settings2 = Settings.builder().setSecureSettings(secureSettings2).build();
121+
final var pluginServices = mock(Plugin.PluginServices.class);
122+
when(pluginServices.clusterService()).thenReturn(
123+
ClusterServiceUtils.createClusterService(new DeterministicTaskQueue().getThreadPool())
124+
);
117125
try (GoogleCloudStoragePlugin plugin = new GoogleCloudStoragePlugin(settings1)) {
118-
plugin.createComponents(mock(Plugin.PluginServices.class));
126+
plugin.createComponents(pluginServices);
119127
final GoogleCloudStorageService storageService = plugin.storageService.get();
120128
var statsCollector = new GcsRepositoryStatsCollector();
121129
final var client11 = storageService.client("gcs1", "repo1", statsCollector);
@@ -153,8 +161,12 @@ public void testClientsAreNotSharedAcrossRepositories() throws Exception {
153161
final MockSecureSettings secureSettings1 = new MockSecureSettings();
154162
secureSettings1.setFile("gcs.client.gcs1.credentials_file", serviceAccountFileContent("test_project"));
155163
final Settings settings = Settings.builder().setSecureSettings(secureSettings1).build();
164+
final var pluginServices = mock(Plugin.PluginServices.class);
165+
when(pluginServices.clusterService()).thenReturn(
166+
ClusterServiceUtils.createClusterService(new DeterministicTaskQueue().getThreadPool())
167+
);
156168
try (GoogleCloudStoragePlugin plugin = new GoogleCloudStoragePlugin(settings)) {
157-
plugin.createComponents(mock(Plugin.PluginServices.class));
169+
plugin.createComponents(pluginServices);
158170
final GoogleCloudStorageService storageService = plugin.storageService.get();
159171

160172
final MeteredStorage repo1Client = storageService.client("gcs1", "repo1", new GcsRepositoryStatsCollector());

0 commit comments

Comments
 (0)