Skip to content

Commit cca38e4

Browse files
committed
even more wiring
1 parent ff000bd commit cca38e4

File tree

7 files changed

+53
-11
lines changed

7 files changed

+53
-11
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.lucene.util.BytesRef;
2424
import org.apache.lucene.util.BytesRefBuilder;
2525
import org.elasticsearch.cluster.metadata.RepositoryMetadata;
26+
import org.elasticsearch.cluster.project.ProjectResolver;
2627
import org.elasticsearch.cluster.service.ClusterService;
2728
import org.elasticsearch.common.BackoffPolicy;
2829
import org.elasticsearch.common.blobstore.BlobContainer;
@@ -235,8 +236,8 @@ public TestGoogleCloudStoragePlugin(Settings settings) {
235236
}
236237

237238
@Override
238-
protected GoogleCloudStorageService createStorageService(ClusterService clusterService) {
239-
return new GoogleCloudStorageService(clusterService) {
239+
protected GoogleCloudStorageService createStorageService(ClusterService clusterService, ProjectResolver projectResolver) {
240+
return new GoogleCloudStorageService(clusterService, projectResolver) {
240241
@Override
241242
StorageOptions createStorageOptions(
242243
final GoogleCloudStorageClientSettings gcsClientSettings,
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.repositories.gcs;
11+
12+
import org.elasticsearch.cluster.ClusterChangedEvent;
13+
import org.elasticsearch.cluster.ClusterStateApplier;
14+
import org.elasticsearch.logging.LogManager;
15+
import org.elasticsearch.logging.Logger;
16+
17+
public class GoogleCloudStorageClientsManager implements ClusterStateApplier {
18+
19+
private static final Logger logger = LogManager.getLogger(GoogleCloudStorageClientsManager.class);
20+
21+
@Override
22+
public void applyClusterState(ClusterChangedEvent event) {
23+
24+
}
25+
}

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

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

1212
import org.apache.lucene.util.SetOnce;
13+
import org.elasticsearch.cluster.project.ProjectResolver;
1314
import org.elasticsearch.cluster.service.ClusterService;
1415
import org.elasticsearch.common.settings.Setting;
1516
import org.elasticsearch.common.settings.Settings;
@@ -31,14 +32,17 @@
3132

3233
public class GoogleCloudStoragePlugin extends Plugin implements RepositoryPlugin, ReloadablePlugin {
3334

35+
private final Settings settings;
3436
// package-private for tests
3537
final SetOnce<GoogleCloudStorageService> storageService = new SetOnce<>();
3638

37-
public GoogleCloudStoragePlugin(final Settings settings) {}
39+
public GoogleCloudStoragePlugin(final Settings settings) {
40+
this.settings = settings;
41+
}
3842

3943
// overridable for tests
40-
protected GoogleCloudStorageService createStorageService(ClusterService clusterService) {
41-
return new GoogleCloudStorageService(clusterService);
44+
protected GoogleCloudStorageService createStorageService(ClusterService clusterService, ProjectResolver projectResolver) {
45+
return new GoogleCloudStorageService(clusterService, projectResolver);
4246
}
4347

4448
@Override
@@ -68,9 +72,9 @@ public Map<String, Repository.Factory> getRepositories(
6872
@Override
6973
public Collection<?> createComponents(PluginServices services) {
7074
final ClusterService clusterService = services.clusterService();
71-
storageService.set(createStorageService(clusterService));
75+
storageService.set(createStorageService(clusterService, services.projectResolver()));
7276
// eagerly load client settings so that secure settings are readable (not closed)
73-
reload(clusterService.getSettings());
77+
reload(settings);
7478
return List.of(storageService.get());
7579
}
7680

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.logging.log4j.Logger;
2727
import org.elasticsearch.ExceptionsHelper;
2828
import org.elasticsearch.cluster.node.DiscoveryNode;
29+
import org.elasticsearch.cluster.project.ProjectResolver;
2930
import org.elasticsearch.cluster.service.ClusterService;
3031
import org.elasticsearch.common.Strings;
3132
import org.elasticsearch.common.util.Maps;
@@ -54,13 +55,18 @@
5455
public class GoogleCloudStorageService {
5556

5657
private static final Logger logger = LogManager.getLogger(GoogleCloudStorageService.class);
58+
private final GoogleCloudStorageClientsManager googleCloudStorageClientsManager;
5759

5860
private volatile Map<String, GoogleCloudStorageClientSettings> clientSettings = emptyMap();
5961

6062
private final boolean isServerless;
6163

62-
public GoogleCloudStorageService(ClusterService clusterService) {
64+
public GoogleCloudStorageService(ClusterService clusterService, ProjectResolver projectResolver) {
6365
this.isServerless = DiscoveryNode.isStateless(clusterService.getSettings());
66+
this.googleCloudStorageClientsManager = new GoogleCloudStorageClientsManager();
67+
if (projectResolver.supportsMultipleProjects()) {
68+
clusterService.addHighPriorityApplier(this.googleCloudStorageClientsManager);
69+
}
6470
}
6571

6672
public boolean isServerless() {

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

Lines changed: 2 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.project.TestProjectResolvers;
2728
import org.elasticsearch.cluster.service.ClusterService;
2829
import org.elasticsearch.common.BackoffPolicy;
2930
import org.elasticsearch.common.Strings;
@@ -149,7 +150,7 @@ protected BlobContainer createBlobContainer(
149150
secureSettings.setFile(CREDENTIALS_FILE_SETTING.getConcreteSettingForNamespace(client).getKey(), createServiceAccount(random()));
150151
clientSettings.setSecureSettings(secureSettings);
151152

152-
final GoogleCloudStorageService service = new GoogleCloudStorageService(clusterService) {
153+
final GoogleCloudStorageService service = new GoogleCloudStorageService(clusterService, TestProjectResolvers.DEFAULT_PROJECT_ONLY) {
153154
@Override
154155
StorageOptions createStorageOptions(
155156
final GoogleCloudStorageClientSettings gcsClientSettings,

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.google.auth.oauth2.ServiceAccountCredentials;
1616
import com.sun.net.httpserver.HttpServer;
1717

18+
import org.elasticsearch.cluster.project.TestProjectResolvers;
1819
import org.elasticsearch.common.BackoffPolicy;
1920
import org.elasticsearch.common.blobstore.BlobPath;
2021
import org.elasticsearch.common.blobstore.BlobStoreActionStats;
@@ -105,7 +106,8 @@ public void createStorageService() throws Exception {
105106
threadPool = new TestThreadPool(getTestClass().getName());
106107
httpServer = MockHttpServer.createHttp(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), 0);
107108
httpServer.start();
108-
googleCloudStorageService = new GoogleCloudStorageService(ClusterServiceUtils.createClusterService(threadPool));
109+
googleCloudStorageService = new GoogleCloudStorageService(ClusterServiceUtils.createClusterService(threadPool),
110+
TestProjectResolvers.DEFAULT_PROJECT_ONLY);
109111
googleCloudStorageHttpHandler = new GoogleCloudStorageHttpHandler(BUCKET);
110112
httpServer.createContext("/", googleCloudStorageHttpHandler);
111113
httpServer.createContext("/token", new FakeOAuth2HttpHandler());

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.apache.http.entity.StringEntity;
1818
import org.apache.http.protocol.HttpContext;
1919
import org.apache.lucene.util.SetOnce;
20+
import org.elasticsearch.cluster.project.TestProjectResolvers;
2021
import org.elasticsearch.common.bytes.BytesReference;
2122
import org.elasticsearch.common.settings.MockSecureSettings;
2223
import org.elasticsearch.common.settings.Setting;
@@ -77,7 +78,7 @@ public void testClientInitializer() throws Exception {
7778
.build();
7879
SetOnce<Proxy> proxy = new SetOnce<>();
7980
final var clusterService = ClusterServiceUtils.createClusterService(new DeterministicTaskQueue().getThreadPool());
80-
final GoogleCloudStorageService service = new GoogleCloudStorageService(clusterService) {
81+
final GoogleCloudStorageService service = new GoogleCloudStorageService(clusterService, TestProjectResolvers.DEFAULT_PROJECT_ONLY) {
8182
@Override
8283
void notifyProxyIsSet(Proxy p) {
8384
proxy.set(p);
@@ -122,6 +123,7 @@ public void testReinitClientSettings() throws Exception {
122123
when(pluginServices.clusterService()).thenReturn(
123124
ClusterServiceUtils.createClusterService(new DeterministicTaskQueue().getThreadPool())
124125
);
126+
when(pluginServices.projectResolver()).thenReturn(TestProjectResolvers.DEFAULT_PROJECT_ONLY);
125127
try (GoogleCloudStoragePlugin plugin = new GoogleCloudStoragePlugin(settings1)) {
126128
plugin.createComponents(pluginServices);
127129
final GoogleCloudStorageService storageService = plugin.storageService.get();
@@ -165,6 +167,7 @@ public void testClientsAreNotSharedAcrossRepositories() throws Exception {
165167
when(pluginServices.clusterService()).thenReturn(
166168
ClusterServiceUtils.createClusterService(new DeterministicTaskQueue().getThreadPool())
167169
);
170+
when(pluginServices.projectResolver()).thenReturn(TestProjectResolvers.DEFAULT_PROJECT_ONLY);
168171
try (GoogleCloudStoragePlugin plugin = new GoogleCloudStoragePlugin(settings)) {
169172
plugin.createComponents(pluginServices);
170173
final GoogleCloudStorageService storageService = plugin.storageService.get();

0 commit comments

Comments
 (0)