Skip to content

Commit d23285f

Browse files
committed
remove deprecated methods
1 parent 6cd68ca commit d23285f

File tree

9 files changed

+61
-52
lines changed

9 files changed

+61
-52
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ public Map<String, Repository.Factory> getRepositories(
290290
@Override
291291
protected GoogleCloudStorageBlobStore createBlobStore() {
292292
return new GoogleCloudStorageBlobStore(
293+
getProjectId(),
293294
metadata.settings().get("bucket"),
294295
"test",
295296
metadata.name(),

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.logging.log4j.LogManager;
2424
import org.apache.logging.log4j.Logger;
2525
import org.elasticsearch.ExceptionsHelper;
26+
import org.elasticsearch.cluster.metadata.ProjectId;
2627
import org.elasticsearch.common.BackoffPolicy;
2728
import org.elasticsearch.common.blobstore.BlobContainer;
2829
import org.elasticsearch.common.blobstore.BlobPath;
@@ -40,6 +41,7 @@
4041
import org.elasticsearch.common.unit.ByteSizeValue;
4142
import org.elasticsearch.common.util.BigArrays;
4243
import org.elasticsearch.core.CheckedConsumer;
44+
import org.elasticsearch.core.Nullable;
4345
import org.elasticsearch.core.Streams;
4446
import org.elasticsearch.core.SuppressForbidden;
4547
import org.elasticsearch.core.TimeValue;
@@ -104,6 +106,8 @@ class GoogleCloudStorageBlobStore implements BlobStore {
104106
}
105107
}
106108

109+
@Nullable // for cluster level object store in MP
110+
private final ProjectId projectId;
107111
private final String bucketName;
108112
private final String clientName;
109113
private final String repositoryName;
@@ -114,6 +118,7 @@ class GoogleCloudStorageBlobStore implements BlobStore {
114118
private final BackoffPolicy casBackoffPolicy;
115119

116120
GoogleCloudStorageBlobStore(
121+
ProjectId projectId,
117122
String bucketName,
118123
String clientName,
119124
String repositoryName,
@@ -123,6 +128,7 @@ class GoogleCloudStorageBlobStore implements BlobStore {
123128
BackoffPolicy casBackoffPolicy,
124129
GcsRepositoryStatsCollector statsCollector
125130
) {
131+
this.projectId = projectId;
126132
this.bucketName = bucketName;
127133
this.clientName = clientName;
128134
this.repositoryName = repositoryName;
@@ -134,7 +140,7 @@ class GoogleCloudStorageBlobStore implements BlobStore {
134140
}
135141

136142
private MeteredStorage client() throws IOException {
137-
return storageService.client(clientName, repositoryName, statsCollector);
143+
return storageService.client(projectId, clientName, repositoryName, statsCollector);
138144
}
139145

140146
@Override
@@ -144,7 +150,7 @@ public BlobContainer blobContainer(BlobPath path) {
144150

145151
@Override
146152
public void close() {
147-
storageService.closeRepositoryClients(repositoryName);
153+
storageService.closeRepositoryClients(projectId, repositoryName);
148154
}
149155

150156
/**

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,6 @@ public void applyClusterState(ClusterChangedEvent event) {
126126
}
127127
}
128128

129-
@Deprecated(forRemoval = true)
130-
MeteredStorage client(String clientName, String repositoryName, GcsRepositoryStatsCollector statsCollector) throws IOException {
131-
return client(ProjectId.DEFAULT, clientName, repositoryName, statsCollector);
132-
}
133-
134-
@Deprecated(forRemoval = true)
135-
void closeRepositoryClients(String repositoryName) {
136-
closeRepositoryClients(ProjectId.DEFAULT, repositoryName);
137-
}
138-
139129
void refreshAndClearCacheForClusterClients(Map<String, GoogleCloudStorageClientSettings> clientsSettings) {
140130
clusterClientsHolder.refreshAndClearCache(clientsSettings);
141131
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ private static Map<String, String> buildLocation(RepositoryMetadata metadata) {
139139
@Override
140140
protected GoogleCloudStorageBlobStore createBlobStore() {
141141
return new GoogleCloudStorageBlobStore(
142+
getProjectId(),
142143
bucket,
143144
clientName,
144145
metadata.name(),

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

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ public boolean isServerless() {
7878
/**
7979
* Refreshes the client settings and clears the client cache. Subsequent calls to
8080
* {@code GoogleCloudStorageService#client} will return new clients constructed
81-
* using the parameter settings.
81+
* using the parameter settings. Note this method is for clients in non-MP setup
82+
* or cluster clients in MP setup. Project clients in MP setup are refreshed differently
83+
* via cluster applier, see {@link GoogleCloudStorageClientsManager#applyClusterState}.
8284
*
8385
* @param clientsSettings the new settings used for building clients for subsequent requests
8486
*/
@@ -93,44 +95,28 @@ public void refreshAndClearCache(Map<String, GoogleCloudStorageClientSettings> c
9395
* use, the (possibly updated) instance should be requested by calling this
9496
* method.
9597
*
96-
* @param clientName name of the client settings used to create the client
97-
* @param repositoryName name of the repository that would use the client
98-
* @return a cached client storage instance that can be used to manage objects
99-
* (blobs)
100-
*/
101-
@Deprecated(forRemoval = true)
102-
public MeteredStorage client(final String clientName, final String repositoryName, final GcsRepositoryStatsCollector statsCollector)
103-
throws IOException {
104-
return clientsManager.client(clientName, repositoryName, statsCollector);
105-
}
106-
107-
/**
108-
* Attempts to retrieve a client from the cache. If the client does not exist it
109-
* will be created from the latest settings and will populate the cache. The
110-
* returned instance should not be cached by the calling code. Instead, for each
111-
* use, the (possibly updated) instance should be requested by calling this
112-
* method.
113-
*
98+
* @param projectId project for this repository. It is null if the repository is at cluster level in MP setup.
11499
* @param clientName name of the client settings used to create the client
115100
* @param repositoryName name of the repository that would use the client
116101
* @return a cached client storage instance that can be used to manage objects
117102
* (blobs)
118103
*/
119104
public MeteredStorage client(
120-
final ProjectId projectId,
105+
@Nullable final ProjectId projectId,
121106
final String clientName,
122107
final String repositoryName,
123108
final GcsRepositoryStatsCollector statsCollector
124109
) throws IOException {
125110
return clientsManager.client(projectId, clientName, repositoryName, statsCollector);
126111
}
127112

128-
@Deprecated(forRemoval = true)
129-
void closeRepositoryClients(String repositoryName) {
130-
clientsManager.closeRepositoryClients(repositoryName);
131-
}
132-
133-
void closeRepositoryClients(final ProjectId projectId, String repositoryName) {
113+
/**
114+
* Close the repository client associated with the given project and repository.
115+
*
116+
* @param projectId project for the repository. It is null if the repository is at cluster level in MP setup.
117+
* @param repositoryName name of the repository for which the client is closed
118+
*/
119+
void closeRepositoryClients(@Nullable final ProjectId projectId, String repositoryName) {
134120
clientsManager.closeRepositoryClients(projectId, repositoryName);
135121
}
136122

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

Lines changed: 2 additions & 0 deletions
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.metadata.ProjectId;
2728
import org.elasticsearch.cluster.project.TestProjectResolvers;
2829
import org.elasticsearch.cluster.service.ClusterService;
2930
import org.elasticsearch.common.BackoffPolicy;
@@ -206,6 +207,7 @@ public HttpRequestInitializer getHttpRequestInitializer(ServiceOptions<?, ?> ser
206207

207208
httpServer.createContext("/token", new FakeOAuth2HttpHandler());
208209
final GoogleCloudStorageBlobStore blobStore = new GoogleCloudStorageBlobStore(
210+
ProjectId.DEFAULT,
209211
"bucket",
210212
client,
211213
"repo",

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

Lines changed: 2 additions & 0 deletions
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.metadata.ProjectId;
1819
import org.elasticsearch.cluster.project.TestProjectResolvers;
1920
import org.elasticsearch.common.BackoffPolicy;
2021
import org.elasticsearch.common.blobstore.BlobPath;
@@ -256,6 +257,7 @@ private ContainerAndBlobStore createBlobContainer(final String repositoryName) t
256257
);
257258
googleCloudStorageService.refreshAndClearCache(Map.of(clientName, clientSettings));
258259
final GoogleCloudStorageBlobStore blobStore = new GoogleCloudStorageBlobStore(
260+
ProjectId.DEFAULT,
259261
BUCKET,
260262
clientName,
261263
repositoryName,

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.google.cloud.storage.StorageBatchResult;
1818
import com.google.cloud.storage.StorageException;
1919

20+
import org.elasticsearch.cluster.metadata.ProjectId;
2021
import org.elasticsearch.common.BackoffPolicy;
2122
import org.elasticsearch.common.blobstore.BlobContainer;
2223
import org.elasticsearch.common.blobstore.BlobPath;
@@ -81,12 +82,12 @@ public void testDeleteBlobsIgnoringIfNotExistsThrowsIOException() throws Excepti
8182
final MeteredStorage meteredStorage = new MeteredStorage(storage, storageRpc, new GcsRepositoryStatsCollector());
8283

8384
final GoogleCloudStorageService storageService = mock(GoogleCloudStorageService.class);
84-
when(storageService.client(any(String.class), any(String.class), any(GcsRepositoryStatsCollector.class))).thenReturn(
85-
meteredStorage
86-
);
85+
when(storageService.client(eq(ProjectId.DEFAULT), any(String.class), any(String.class), any(GcsRepositoryStatsCollector.class)))
86+
.thenReturn(meteredStorage);
8787

8888
try (
8989
BlobStore store = new GoogleCloudStorageBlobStore(
90+
ProjectId.DEFAULT,
9091
"bucket",
9192
"test",
9293
"repo",

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

Lines changed: 31 additions & 11 deletions
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.metadata.ProjectId;
2021
import org.elasticsearch.cluster.project.TestProjectResolvers;
2122
import org.elasticsearch.common.bytes.BytesReference;
2223
import org.elasticsearch.common.settings.MockSecureSettings;
@@ -88,13 +89,13 @@ void notifyProxyIsSet(Proxy p) {
8889
var statsCollector = new GcsRepositoryStatsCollector();
8990
final IllegalArgumentException e = expectThrows(
9091
IllegalArgumentException.class,
91-
() -> service.client("another_client", "repo", statsCollector)
92+
() -> service.client(projectIdForClusterClient(), "another_client", "repo", statsCollector)
9293
);
9394
assertThat(e.getMessage(), Matchers.startsWith("Unknown client name"));
9495
assertSettingDeprecationsAndWarnings(
9596
new Setting<?>[] { GoogleCloudStorageClientSettings.APPLICATION_NAME_SETTING.getConcreteSettingForNamespace(clientName) }
9697
);
97-
final var storage = service.client(clientName, "repo", statsCollector);
98+
final var storage = service.client(projectIdForClusterClient(), clientName, "repo", statsCollector);
9899
assertThat(storage.getOptions().getApplicationName(), Matchers.containsString(applicationName));
99100
assertThat(storage.getOptions().getHost(), Matchers.is(endpoint));
100101
assertThat(storage.getOptions().getProjectId(), Matchers.is(projectIdName));
@@ -128,33 +129,33 @@ public void testReinitClientSettings() throws Exception {
128129
plugin.createComponents(pluginServices);
129130
final GoogleCloudStorageService storageService = plugin.storageService.get();
130131
var statsCollector = new GcsRepositoryStatsCollector();
131-
final var client11 = storageService.client("gcs1", "repo1", statsCollector);
132+
final var client11 = storageService.client(projectIdForClusterClient(), "gcs1", "repo1", statsCollector);
132133
assertThat(client11.getOptions().getProjectId(), equalTo("project_gcs11"));
133-
final var client12 = storageService.client("gcs2", "repo2", statsCollector);
134+
final var client12 = storageService.client(projectIdForClusterClient(), "gcs2", "repo2", statsCollector);
134135
assertThat(client12.getOptions().getProjectId(), equalTo("project_gcs12"));
135136
// client 3 is missing
136137
final IllegalArgumentException e1 = expectThrows(
137138
IllegalArgumentException.class,
138-
() -> storageService.client("gcs3", "repo3", statsCollector)
139+
() -> storageService.client(projectIdForClusterClient(), "gcs3", "repo3", statsCollector)
139140
);
140141
assertThat(e1.getMessage(), containsString("Unknown client name [gcs3]."));
141142
// update client settings
142143
plugin.reload(settings2);
143144
// old client 1 not changed
144145
assertThat(client11.getOptions().getProjectId(), equalTo("project_gcs11"));
145146
// new client 1 is changed
146-
final var client21 = storageService.client("gcs1", "repo1", statsCollector);
147+
final var client21 = storageService.client(projectIdForClusterClient(), "gcs1", "repo1", statsCollector);
147148
assertThat(client21.getOptions().getProjectId(), equalTo("project_gcs21"));
148149
// old client 2 not changed
149150
assertThat(client12.getOptions().getProjectId(), equalTo("project_gcs12"));
150151
// new client2 is gone
151152
final IllegalArgumentException e2 = expectThrows(
152153
IllegalArgumentException.class,
153-
() -> storageService.client("gcs2", "repo2", statsCollector)
154+
() -> storageService.client(projectIdForClusterClient(), "gcs2", "repo2", statsCollector)
154155
);
155156
assertThat(e2.getMessage(), containsString("Unknown client name [gcs2]."));
156157
// client 3 emerged
157-
final var client23 = storageService.client("gcs3", "repo3", statsCollector);
158+
final var client23 = storageService.client(projectIdForClusterClient(), "gcs3", "repo3", statsCollector);
158159
assertThat(client23.getOptions().getProjectId(), equalTo("project_gcs23"));
159160
}
160161
}
@@ -172,9 +173,24 @@ public void testClientsAreNotSharedAcrossRepositories() throws Exception {
172173
plugin.createComponents(pluginServices);
173174
final GoogleCloudStorageService storageService = plugin.storageService.get();
174175

175-
final MeteredStorage repo1Client = storageService.client("gcs1", "repo1", new GcsRepositoryStatsCollector());
176-
final MeteredStorage repo2Client = storageService.client("gcs1", "repo2", new GcsRepositoryStatsCollector());
177-
final MeteredStorage repo1ClientSecondInstance = storageService.client("gcs1", "repo1", new GcsRepositoryStatsCollector());
176+
final MeteredStorage repo1Client = storageService.client(
177+
projectIdForClusterClient(),
178+
"gcs1",
179+
"repo1",
180+
new GcsRepositoryStatsCollector()
181+
);
182+
final MeteredStorage repo2Client = storageService.client(
183+
projectIdForClusterClient(),
184+
"gcs1",
185+
"repo2",
186+
new GcsRepositoryStatsCollector()
187+
);
188+
final MeteredStorage repo1ClientSecondInstance = storageService.client(
189+
projectIdForClusterClient(),
190+
"gcs1",
191+
"repo1",
192+
new GcsRepositoryStatsCollector()
193+
);
178194

179195
assertNotSame(repo1Client, repo2Client);
180196
assertSame(repo1Client, repo1ClientSecondInstance);
@@ -220,4 +236,8 @@ public void handle(HttpRequest request, HttpResponse response, HttpContext conte
220236
assertEquals(proxyProjectId, GoogleCloudStorageService.getDefaultProjectId(proxy));
221237
}
222238
}
239+
240+
private ProjectId projectIdForClusterClient() {
241+
return randomBoolean() ? ProjectId.DEFAULT : null;
242+
}
223243
}

0 commit comments

Comments
 (0)