From ced330ec114071ff48e1474a84bf8b985bd3fe05 Mon Sep 17 00:00:00 2001 From: Bhumika Saini Date: Tue, 19 Sep 2023 13:14:50 +0530 Subject: [PATCH] Pass S3RepositoryTests Signed-off-by: Bhumika Saini --- .../opensearch/repositories/s3/S3Repository.java | 4 +--- .../repositories/s3/S3RepositoryTests.java | 8 +++++++- .../repositories/blobstore/BlobStoreRepository.java | 13 ++++++++++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/plugins/repository-s3/src/main/java/org/opensearch/repositories/s3/S3Repository.java b/plugins/repository-s3/src/main/java/org/opensearch/repositories/s3/S3Repository.java index 88859f378ef4c..5fc2114f0af66 100644 --- a/plugins/repository-s3/src/main/java/org/opensearch/repositories/s3/S3Repository.java +++ b/plugins/repository-s3/src/main/java/org/opensearch/repositories/s3/S3Repository.java @@ -44,7 +44,6 @@ import org.opensearch.common.logging.DeprecationLogger; import org.opensearch.common.settings.SecureSetting; import org.opensearch.common.settings.Setting; -import org.opensearch.common.settings.Settings; import org.opensearch.core.action.ActionListener; import org.opensearch.core.common.Strings; import org.opensearch.core.common.settings.SecureString; @@ -427,8 +426,7 @@ public void reload(RepositoryMetadata newRepositoryMetadata, boolean compress) { repositoryMetadata = newRepositoryMetadata; // Reload configs for S3RepositoryPlugin - Settings settings = clusterService.getSettings(); - final Map clientsSettings = S3ClientSettings.load(settings, pluginConfigPath); + final Map clientsSettings = S3ClientSettings.load(repositoryMetadata.settings(), pluginConfigPath); service.refreshAndClearCache(clientsSettings); s3AsyncService.refreshAndClearCache(clientsSettings); diff --git a/plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/S3RepositoryTests.java b/plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/S3RepositoryTests.java index 533c3aa17009d..3fb39f7833899 100644 --- a/plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/S3RepositoryTests.java +++ b/plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/S3RepositoryTests.java @@ -73,6 +73,12 @@ public void refreshAndClearCache(Map clientsSettings) public void close() {} } + private static class DummyS3AsyncService extends S3AsyncService { + DummyS3AsyncService(Path configPath) { + super(configPath); + } + } + public void testInvalidChunkBufferSizeSettings() { // chunk < buffer should fail final Settings s1 = bufferAndChunkSettings(10, 5); @@ -143,7 +149,7 @@ private S3Repository createS3Repo(RepositoryMetadata metadata) { null, null, null, - null, + new DummyS3AsyncService(configPath()), false ) { @Override diff --git a/server/src/main/java/org/opensearch/repositories/blobstore/BlobStoreRepository.java b/server/src/main/java/org/opensearch/repositories/blobstore/BlobStoreRepository.java index 5799d913d2342..b2ed0289864ec 100644 --- a/server/src/main/java/org/opensearch/repositories/blobstore/BlobStoreRepository.java +++ b/server/src/main/java/org/opensearch/repositories/blobstore/BlobStoreRepository.java @@ -412,7 +412,8 @@ protected BlobStoreRepository( final ClusterService clusterService, final RecoverySettings recoverySettings ) { - reload(repositoryMetadata, compress); + // Read RepositoryMetadata as the first step + readRepositoryMetadata(repositoryMetadata, compress); isSystemRepository = SYSTEM_REPOSITORY_SETTING.get(metadata.settings()); this.namedXContentRegistry = namedXContentRegistry; @@ -423,6 +424,16 @@ protected BlobStoreRepository( @Override public void reload(RepositoryMetadata repositoryMetadata, boolean compress) { + readRepositoryMetadata(repositoryMetadata, compress); + } + + /** + * Reloads the values derived from the Repository Metadata + * + * @param repositoryMetadata RepositoryMetadata instance to derive the values from + * @param compress boolean representing whether compression is to be used + */ + private void readRepositoryMetadata(RepositoryMetadata repositoryMetadata, boolean compress) { this.metadata = repositoryMetadata; supportURLRepo = SUPPORT_URL_REPO.get(metadata.settings());