Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.BytesRefBuilder;
import org.elasticsearch.cluster.metadata.RepositoryMetadata;
import org.elasticsearch.cluster.project.ProjectResolver;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.BackoffPolicy;
import org.elasticsearch.common.blobstore.BlobContainer;
Expand Down Expand Up @@ -235,8 +236,8 @@ public TestGoogleCloudStoragePlugin(Settings settings) {
}

@Override
protected GoogleCloudStorageService createStorageService(boolean isServerless) {
return new GoogleCloudStorageService() {
protected GoogleCloudStorageService createStorageService(ClusterService clusterService, ProjectResolver projectResolver) {
return new GoogleCloudStorageService(clusterService, projectResolver) {
@Override
StorageOptions createStorageOptions(
final GoogleCloudStorageClientSettings gcsClientSettings,
Expand Down Expand Up @@ -280,7 +281,7 @@ public Map<String, Repository.Factory> getRepositories(
projectId,
metadata,
registry,
this.storageService,
this.storageService.get(),
clusterService,
bigArrays,
recoverySettings,
Expand All @@ -289,10 +290,11 @@ public Map<String, Repository.Factory> getRepositories(
@Override
protected GoogleCloudStorageBlobStore createBlobStore() {
return new GoogleCloudStorageBlobStore(
getProjectId(),
metadata.settings().get("bucket"),
"test",
metadata.name(),
storageService,
storageService.get(),
bigArrays,
randomIntBetween(1, 8) * 1024,
BackoffPolicy.noBackoff(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.cluster.metadata.ProjectId;
import org.elasticsearch.common.BackoffPolicy;
import org.elasticsearch.common.blobstore.BlobContainer;
import org.elasticsearch.common.blobstore.BlobPath;
Expand All @@ -40,6 +41,7 @@
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.core.CheckedConsumer;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.Streams;
import org.elasticsearch.core.SuppressForbidden;
import org.elasticsearch.core.TimeValue;
Expand Down Expand Up @@ -104,6 +106,8 @@ class GoogleCloudStorageBlobStore implements BlobStore {
}
}

@Nullable // for cluster level object store in MP
private final ProjectId projectId;
private final String bucketName;
private final String clientName;
private final String repositoryName;
Expand All @@ -114,6 +118,7 @@ class GoogleCloudStorageBlobStore implements BlobStore {
private final BackoffPolicy casBackoffPolicy;

GoogleCloudStorageBlobStore(
ProjectId projectId,
String bucketName,
String clientName,
String repositoryName,
Expand All @@ -123,6 +128,7 @@ class GoogleCloudStorageBlobStore implements BlobStore {
BackoffPolicy casBackoffPolicy,
GcsRepositoryStatsCollector statsCollector
) {
this.projectId = projectId;
this.bucketName = bucketName;
this.clientName = clientName;
this.repositoryName = repositoryName;
Expand All @@ -134,7 +140,7 @@ class GoogleCloudStorageBlobStore implements BlobStore {
}

private MeteredStorage client() throws IOException {
return storageService.client(clientName, repositoryName, statsCollector);
return storageService.client(projectId, clientName, repositoryName, statsCollector);
}

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

@Override
public void close() {
storageService.closeRepositoryClients(repositoryName);
storageService.closeRepositoryClients(projectId, repositoryName);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;

import static org.elasticsearch.common.settings.Setting.timeSetting;

Expand Down Expand Up @@ -196,6 +197,25 @@ public Proxy getProxy() {
return proxy;
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
GoogleCloudStorageClientSettings that = (GoogleCloudStorageClientSettings) o;
return Objects.equals(credential, that.credential)
&& Objects.equals(endpoint, that.endpoint)
&& Objects.equals(projectId, that.projectId)
&& Objects.equals(connectTimeout, that.connectTimeout)
&& Objects.equals(readTimeout, that.readTimeout)
&& Objects.equals(applicationName, that.applicationName)
&& Objects.equals(tokenUri, that.tokenUri)
&& Objects.equals(proxy, that.proxy);
}

@Override
public int hashCode() {
return Objects.hash(credential, endpoint, projectId, connectTimeout, readTimeout, applicationName, tokenUri, proxy);
}

public static Map<String, GoogleCloudStorageClientSettings> load(final Settings settings) {
final Map<String, GoogleCloudStorageClientSettings> clients = new HashMap<>();
for (final String clientName : settings.getGroups(PREFIX).keySet()) {
Expand Down
Loading