From 6f124e6eec416e3afb2c93c62ede72e91fe62177 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Mon, 17 Aug 2015 15:08:08 -0700 Subject: [PATCH 1/2] Internal: Simplify custom repository type setup Custom repository types are registered through the RepositoriesModule. Later, when a specific repository type is used, the RespositoryModule is installed, which in turn would spawn the module that was registered for that repository type. However, a module is not needed here. Each repository type has two associated classes, a Repository and an IndexShardRepository. This change makes the registration method for custom repository types take both of these classes, instead of a module. See #12783. --- .../common/util/ExtensionPoint.java | 7 +- .../repositories/RepositoriesModule.java | 37 ++++------ .../repositories/RepositoryModule.java | 25 +------ .../repositories/RepositoryTypesRegistry.java | 36 +++++----- .../repositories/fs/FsRepositoryModule.java | 46 ------------ .../repositories/uri/URLRepositoryModule.java | 46 ------------ .../AbstractSnapshotIntegTestCase.java | 3 +- .../DedicatedClusterSnapshotRestoreIT.java | 21 +++--- .../snapshots/RepositoriesIT.java | 3 - .../SharedClusterSnapshotRestoreIT.java | 1 - .../snapshots/mockstore/MockRepository.java | 56 +++++++++++++-- .../mockstore/MockRepositoryModule.java | 42 ----------- .../mockstore/MockRepositoryPlugin.java | 71 ------------------- .../plugin/cloud/aws/CloudAwsPlugin.java | 4 +- .../repositories/s3/S3RepositoryModule.java | 45 ------------ .../cloud/azure/AzureModule.java | 2 + .../plugin/cloud/azure/CloudAzurePlugin.java | 10 ++- .../azure/AzureRepositoryModule.java | 61 ---------------- 18 files changed, 111 insertions(+), 405 deletions(-) delete mode 100644 core/src/main/java/org/elasticsearch/repositories/fs/FsRepositoryModule.java delete mode 100644 core/src/main/java/org/elasticsearch/repositories/uri/URLRepositoryModule.java delete mode 100644 core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepositoryModule.java delete mode 100644 core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepositoryPlugin.java delete mode 100644 plugins/cloud-aws/src/main/java/org/elasticsearch/repositories/s3/S3RepositoryModule.java delete mode 100644 plugins/cloud-azure/src/main/java/org/elasticsearch/repositories/azure/AzureRepositoryModule.java diff --git a/core/src/main/java/org/elasticsearch/common/util/ExtensionPoint.java b/core/src/main/java/org/elasticsearch/common/util/ExtensionPoint.java index 5414c4eb7a6..56163378327 100644 --- a/core/src/main/java/org/elasticsearch/common/util/ExtensionPoint.java +++ b/core/src/main/java/org/elasticsearch/common/util/ExtensionPoint.java @@ -133,13 +133,16 @@ public abstract class ExtensionPoint { * the settings object. * * @param binder the binder to use - * @param settings the settings to look up the key to find the implemetation to bind + * @param settings the settings to look up the key to find the implementation to bind * @param settingsKey the key to use with the settings - * @param defaultValue the default value if they settings doesn't contain the key + * @param defaultValue the default value if the settings do not contain the key, or null if there is no default * @return the actual bound type key */ public String bindType(Binder binder, Settings settings, String settingsKey, String defaultValue) { final String type = settings.get(settingsKey, defaultValue); + if (type == null) { + throw new IllegalArgumentException("Missing setting [" + settingsKey + "]"); + } final Class instance = getExtension(type); if (instance == null) { throw new IllegalArgumentException("Unknown [" + this.name + "] type [" + type + "]"); diff --git a/core/src/main/java/org/elasticsearch/repositories/RepositoriesModule.java b/core/src/main/java/org/elasticsearch/repositories/RepositoriesModule.java index bf745905e2a..acad2753f7a 100644 --- a/core/src/main/java/org/elasticsearch/repositories/RepositoriesModule.java +++ b/core/src/main/java/org/elasticsearch/repositories/RepositoriesModule.java @@ -19,44 +19,33 @@ package org.elasticsearch.repositories; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; import org.elasticsearch.action.admin.cluster.snapshots.status.TransportNodesSnapshotsStatus; import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.inject.Module; +import org.elasticsearch.index.snapshots.IndexShardRepository; +import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardRepository; import org.elasticsearch.repositories.fs.FsRepository; -import org.elasticsearch.repositories.fs.FsRepositoryModule; import org.elasticsearch.repositories.uri.URLRepository; -import org.elasticsearch.repositories.uri.URLRepositoryModule; import org.elasticsearch.snapshots.RestoreService; -import org.elasticsearch.snapshots.SnapshotsService; import org.elasticsearch.snapshots.SnapshotShardsService; - -import java.util.Map; +import org.elasticsearch.snapshots.SnapshotsService; /** - * Module responsible for registering other repositories. - *

- * Repositories implemented as plugins should implement {@code onModule(RepositoriesModule module)} method, in which - * they should register repository using {@link #registerRepository(String, Class)} method. + * Sets up classes for Snapshot/Restore. + * + * Plugins can add custom repository types by calling {@link #registerRepository(String, Class, Class)}. */ public class RepositoriesModule extends AbstractModule { - private Map> repositoryTypes = Maps.newHashMap(); + private final RepositoryTypesRegistry repositoryTypes = new RepositoryTypesRegistry(); public RepositoriesModule() { - registerRepository(FsRepository.TYPE, FsRepositoryModule.class); - registerRepository(URLRepository.TYPE, URLRepositoryModule.class); + registerRepository(FsRepository.TYPE, FsRepository.class, BlobStoreIndexShardRepository.class); + registerRepository(URLRepository.TYPE, URLRepository.class, BlobStoreIndexShardRepository.class); } - /** - * Registers a custom repository type name against a module. - * - * @param type The type - * @param module The module - */ - public void registerRepository(String type, Class module) { - repositoryTypes.put(type, module); + /** Registers a custom repository type to the given {@link Repository} and {@link IndexShardRepository}. */ + public void registerRepository(String type, Class repositoryType, Class shardRepositoryType) { + repositoryTypes.registerRepository(type, repositoryType, shardRepositoryType); } @Override @@ -66,6 +55,6 @@ public class RepositoriesModule extends AbstractModule { bind(SnapshotShardsService.class).asEagerSingleton(); bind(TransportNodesSnapshotsStatus.class).asEagerSingleton(); bind(RestoreService.class).asEagerSingleton(); - bind(RepositoryTypesRegistry.class).toInstance(new RepositoryTypesRegistry(ImmutableMap.copyOf(repositoryTypes))); + bind(RepositoryTypesRegistry.class).toInstance(repositoryTypes); } } diff --git a/core/src/main/java/org/elasticsearch/repositories/RepositoryModule.java b/core/src/main/java/org/elasticsearch/repositories/RepositoryModule.java index 2dccc2b0186..eca82cc78e8 100644 --- a/core/src/main/java/org/elasticsearch/repositories/RepositoryModule.java +++ b/core/src/main/java/org/elasticsearch/repositories/RepositoryModule.java @@ -19,7 +19,6 @@ package org.elasticsearch.repositories; -import com.google.common.collect.ImmutableList; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.inject.Modules; @@ -29,12 +28,10 @@ import org.elasticsearch.common.settings.Settings; import java.util.Arrays; import java.util.Collections; -import static org.elasticsearch.common.Strings.toCamelCase; - /** - * This module spawns specific repository module + * Binds repository classes for the specific repository type. */ -public class RepositoryModule extends AbstractModule implements SpawnModules { +public class RepositoryModule extends AbstractModule { private RepositoryName repositoryName; @@ -59,28 +56,12 @@ public class RepositoryModule extends AbstractModule implements SpawnModules { this.typesRegistry = typesRegistry; } - /** - * Returns repository module. - *

- * First repository type is looked up in typesRegistry and if it's not found there, this module tries to - * load repository by it's class name. - * - * @return repository module - */ - @Override - public Iterable spawnModules() { - Class repoModuleClass = typesRegistry.type(repositoryName.type()); - if (repoModuleClass == null) { - throw new IllegalArgumentException("Could not find repository type [" + repositoryName.getType() + "] for repository [" + repositoryName.getName() + "]"); - } - return Collections.unmodifiableList(Arrays.asList(Modules.createModule(repoModuleClass, globalSettings))); - } - /** * {@inheritDoc} */ @Override protected void configure() { + typesRegistry.bindType(binder(), repositoryName.type()); bind(RepositorySettings.class).toInstance(new RepositorySettings(globalSettings, settings)); } } diff --git a/core/src/main/java/org/elasticsearch/repositories/RepositoryTypesRegistry.java b/core/src/main/java/org/elasticsearch/repositories/RepositoryTypesRegistry.java index 1322b65203d..b1e3041e746 100644 --- a/core/src/main/java/org/elasticsearch/repositories/RepositoryTypesRegistry.java +++ b/core/src/main/java/org/elasticsearch/repositories/RepositoryTypesRegistry.java @@ -19,31 +19,29 @@ package org.elasticsearch.repositories; -import com.google.common.collect.ImmutableMap; -import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.inject.Binder; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.util.ExtensionPoint; +import org.elasticsearch.index.snapshots.IndexShardRepository; /** - * Map of registered repository types and associated with these types modules + * A mapping from type name to implementations of {@link Repository} and {@link IndexShardRepository}. */ public class RepositoryTypesRegistry { - private final ImmutableMap> repositoryTypes; + // invariant: repositories and shardRepositories have the same keyset + private final ExtensionPoint.TypeExtensionPoint repositoryTypes = + new ExtensionPoint.TypeExtensionPoint<>("repository", Repository.class); + private final ExtensionPoint.TypeExtensionPoint shardRepositoryTypes = + new ExtensionPoint.TypeExtensionPoint<>("index_repository", IndexShardRepository.class); - /** - * Creates new repository with given map of types - * - * @param repositoryTypes - */ - public RepositoryTypesRegistry(ImmutableMap> repositoryTypes) { - this.repositoryTypes = repositoryTypes; + public void registerRepository(String name, Class repositoryType, Class shardRepositoryType) { + repositoryTypes.registerExtension(name, repositoryType); + shardRepositoryTypes.registerExtension(name, shardRepositoryType); } - /** - * Returns repository module class for the given type - * - * @param type repository type - * @return repository module class or null if type is not found - */ - public Class type(String type) { - return repositoryTypes.get(type); + public void bindType(Binder binder, String type) { + Settings settings = Settings.builder().put("type", type).build(); + repositoryTypes.bindType(binder, settings, "type", null); + shardRepositoryTypes.bindType(binder, settings, "type", null); } } diff --git a/core/src/main/java/org/elasticsearch/repositories/fs/FsRepositoryModule.java b/core/src/main/java/org/elasticsearch/repositories/fs/FsRepositoryModule.java deleted file mode 100644 index 2b8a4f4c15a..00000000000 --- a/core/src/main/java/org/elasticsearch/repositories/fs/FsRepositoryModule.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.repositories.fs; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.index.snapshots.IndexShardRepository; -import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardRepository; -import org.elasticsearch.repositories.Repository; - -/** - * File system repository module - */ -public class FsRepositoryModule extends AbstractModule { - - public FsRepositoryModule() { - super(); - } - - /** - * {@inheritDoc} - */ - @Override - protected void configure() { - bind(Repository.class).to(FsRepository.class).asEagerSingleton(); - bind(IndexShardRepository.class).to(BlobStoreIndexShardRepository.class).asEagerSingleton(); - } - -} - diff --git a/core/src/main/java/org/elasticsearch/repositories/uri/URLRepositoryModule.java b/core/src/main/java/org/elasticsearch/repositories/uri/URLRepositoryModule.java deleted file mode 100644 index 949a1b77f2c..00000000000 --- a/core/src/main/java/org/elasticsearch/repositories/uri/URLRepositoryModule.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.repositories.uri; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.index.snapshots.IndexShardRepository; -import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardRepository; -import org.elasticsearch.repositories.Repository; - -/** - * URL repository module - */ -public class URLRepositoryModule extends AbstractModule { - - public URLRepositoryModule() { - super(); - } - - /** - * {@inheritDoc} - */ - @Override - protected void configure() { - bind(Repository.class).to(URLRepository.class).asEagerSingleton(); - bind(IndexShardRepository.class).to(BlobStoreIndexShardRepository.class).asEagerSingleton(); - } - -} - diff --git a/core/src/test/java/org/elasticsearch/snapshots/AbstractSnapshotIntegTestCase.java b/core/src/test/java/org/elasticsearch/snapshots/AbstractSnapshotIntegTestCase.java index 75e910f48dd..2544f14fa3d 100644 --- a/core/src/test/java/org/elasticsearch/snapshots/AbstractSnapshotIntegTestCase.java +++ b/core/src/test/java/org/elasticsearch/snapshots/AbstractSnapshotIntegTestCase.java @@ -34,7 +34,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.repositories.RepositoriesService; import org.elasticsearch.snapshots.mockstore.MockRepository; -import org.elasticsearch.snapshots.mockstore.MockRepositoryPlugin; import org.elasticsearch.test.ESIntegTestCase; import java.io.IOException; @@ -57,7 +56,7 @@ public abstract class AbstractSnapshotIntegTestCase extends ESIntegTestCase { @Override protected Settings nodeSettings(int nodeOrdinal) { return settingsBuilder().put(super.nodeSettings(nodeOrdinal)) - .extendArray("plugin.types", MockRepositoryPlugin.class.getName()).build(); + .extendArray("plugin.types", MockRepository.Plugin.class.getName()).build(); } public static long getFailureCount(String repository) { diff --git a/core/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java b/core/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java index fa0ebdec5a0..23ea847e2b1 100644 --- a/core/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java +++ b/core/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java @@ -24,7 +24,6 @@ import com.carrotsearch.hppc.IntSet; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableList; import com.google.common.util.concurrent.ListenableFuture; - import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.action.ListenableActionFuture; import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse; @@ -41,8 +40,8 @@ import org.elasticsearch.cluster.AbstractDiffable; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ProcessedClusterStateUpdateTask; -import org.elasticsearch.cluster.metadata.MetaData.Custom; import org.elasticsearch.cluster.metadata.MetaData; +import org.elasticsearch.cluster.metadata.MetaData.Custom; import org.elasticsearch.cluster.metadata.MetaDataIndexStateService; import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider; import org.elasticsearch.common.Nullable; @@ -64,11 +63,9 @@ import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.admin.cluster.repositories.get.RestGetRepositoriesAction; import org.elasticsearch.rest.action.admin.cluster.state.RestClusterStateAction; -import org.elasticsearch.snapshots.mockstore.MockRepositoryModule; -import org.elasticsearch.snapshots.mockstore.MockRepositoryPlugin; +import org.elasticsearch.snapshots.mockstore.MockRepository; import org.elasticsearch.test.InternalTestCluster; import org.elasticsearch.test.rest.FakeRestRequest; -import org.junit.Ignore; import org.junit.Test; import java.io.IOException; @@ -88,7 +85,15 @@ import static org.elasticsearch.test.ESIntegTestCase.Scope; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertBlocked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.lessThan; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; /** */ @@ -615,7 +620,7 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest @Test public void registrationFailureTest() { logger.info("--> start first node"); - internalCluster().startNode(settingsBuilder().put("plugin.types", MockRepositoryPlugin.class.getName())); + internalCluster().startNode(settingsBuilder().put("plugin.types", MockRepository.Plugin.class.getName())); logger.info("--> start second node"); // Make sure the first node is elected as master internalCluster().startNode(settingsBuilder().put("node.master", false)); @@ -634,7 +639,7 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest @Test public void testThatSensitiveRepositorySettingsAreNotExposed() throws Exception { - Settings nodeSettings = settingsBuilder().put("plugin.types", MockRepositoryPlugin.class.getName()).build(); + Settings nodeSettings = settingsBuilder().put("plugin.types", MockRepository.Plugin.class.getName()).build(); logger.info("--> start two nodes"); internalCluster().startNodesAsync(2, nodeSettings).get(); // Register mock repositories diff --git a/core/src/test/java/org/elasticsearch/snapshots/RepositoriesIT.java b/core/src/test/java/org/elasticsearch/snapshots/RepositoriesIT.java index 27a67588df9..c5221d12f3b 100644 --- a/core/src/test/java/org/elasticsearch/snapshots/RepositoriesIT.java +++ b/core/src/test/java/org/elasticsearch/snapshots/RepositoriesIT.java @@ -32,15 +32,12 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.repositories.RepositoryException; import org.elasticsearch.repositories.RepositoryVerificationException; -import org.elasticsearch.snapshots.mockstore.MockRepositoryModule; -import org.elasticsearch.snapshots.mockstore.MockRepositoryPlugin; import org.elasticsearch.test.ESIntegTestCase; import org.junit.Test; import java.nio.file.Path; import java.util.List; -import static org.elasticsearch.common.settings.Settings.settingsBuilder; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows; import static org.hamcrest.Matchers.containsString; diff --git a/core/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java b/core/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java index df7eb4e3b9b..d89eea7206a 100644 --- a/core/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java +++ b/core/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java @@ -64,7 +64,6 @@ import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.store.IndexStore; import org.elasticsearch.indices.InvalidIndexNameException; import org.elasticsearch.repositories.RepositoriesService; -import org.elasticsearch.snapshots.mockstore.MockRepositoryModule; import org.elasticsearch.test.junit.annotations.TestLogging; import org.junit.Test; diff --git a/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepository.java b/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepository.java index 12e51475c9d..c346e5817bc 100644 --- a/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepository.java +++ b/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepository.java @@ -19,10 +19,8 @@ package org.elasticsearch.snapshots.mockstore; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.metadata.SnapshotId; @@ -30,11 +28,17 @@ import org.elasticsearch.common.blobstore.BlobContainer; import org.elasticsearch.common.blobstore.BlobMetaData; import org.elasticsearch.common.blobstore.BlobPath; import org.elasticsearch.common.blobstore.BlobStore; +import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.env.Environment; import org.elasticsearch.index.snapshots.IndexShardRepository; +import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardRepository; +import org.elasticsearch.plugins.AbstractPlugin; +import org.elasticsearch.repositories.RepositoriesModule; import org.elasticsearch.repositories.RepositoryName; import org.elasticsearch.repositories.RepositorySettings; import org.elasticsearch.repositories.fs.FsRepository; @@ -46,6 +50,10 @@ import java.io.UnsupportedEncodingException; import java.nio.file.Path; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -54,10 +62,48 @@ import java.util.concurrent.atomic.AtomicLong; import static org.elasticsearch.common.settings.Settings.settingsBuilder; -/** - */ public class MockRepository extends FsRepository { + public static class Plugin extends AbstractPlugin { + + @Override + public String name() { + return "mock-repository"; + } + + @Override + public String description() { + return "Mock Repository"; + } + + public void onModule(RepositoriesModule repositoriesModule) { + repositoriesModule.registerRepository("mock", MockRepository.class, BlobStoreIndexShardRepository.class); + } + + @Override + public Collection> modules() { + Collection> modules = new ArrayList<>(); + modules.add(SettingsFilteringModule.class); + return modules; + } + + public static class SettingsFilteringModule extends AbstractModule { + + @Override + protected void configure() { + bind(SettingsFilteringService.class).asEagerSingleton(); + } + } + + public static class SettingsFilteringService { + @Inject + public SettingsFilteringService(SettingsFilter settingsFilter) { + settingsFilter.addFilter("secret.mock.password"); + } + } + + } + private final AtomicLong failureCounter = new AtomicLong(); public long getFailureCount() { diff --git a/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepositoryModule.java b/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepositoryModule.java deleted file mode 100644 index 0da50f15d61..00000000000 --- a/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepositoryModule.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.snapshots.mockstore; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.index.snapshots.IndexShardRepository; -import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardRepository; -import org.elasticsearch.repositories.Repository; - -/** - */ -public class MockRepositoryModule extends AbstractModule { - - public MockRepositoryModule() { - super(); - } - - @Override - protected void configure() { - bind(Repository.class).to(MockRepository.class).asEagerSingleton(); - bind(IndexShardRepository.class).to(BlobStoreIndexShardRepository.class).asEagerSingleton(); - } - -} - diff --git a/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepositoryPlugin.java b/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepositoryPlugin.java deleted file mode 100644 index a09c8601f7f..00000000000 --- a/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepositoryPlugin.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.snapshots.mockstore; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.settings.SettingsFilter; -import org.elasticsearch.plugins.AbstractPlugin; -import org.elasticsearch.repositories.RepositoriesModule; - -import java.util.Collection; - -import static com.google.common.collect.Lists.newArrayList; - -public class MockRepositoryPlugin extends AbstractPlugin { - - @Override - public String name() { - return "mock-repository"; - } - - @Override - public String description() { - return "Mock Repository"; - } - - public void onModule(RepositoriesModule repositoriesModule) { - repositoriesModule.registerRepository("mock", MockRepositoryModule.class); - } - - @Override - public Collection> modules() { - Collection> modules = newArrayList(); - modules.add(SettingsFilteringModule.class); - return modules; - } - - public static class SettingsFilteringModule extends AbstractModule { - - @Override - protected void configure() { - bind(SettingsFilteringService.class).asEagerSingleton(); - } - } - - public static class SettingsFilteringService { - @Inject - public SettingsFilteringService(SettingsFilter settingsFilter) { - settingsFilter.addFilter("secret.mock.password"); - } - } - -} diff --git a/plugins/cloud-aws/src/main/java/org/elasticsearch/plugin/cloud/aws/CloudAwsPlugin.java b/plugins/cloud-aws/src/main/java/org/elasticsearch/plugin/cloud/aws/CloudAwsPlugin.java index 4b16400897f..55a0ae51fb1 100644 --- a/plugins/cloud-aws/src/main/java/org/elasticsearch/plugin/cloud/aws/CloudAwsPlugin.java +++ b/plugins/cloud-aws/src/main/java/org/elasticsearch/plugin/cloud/aws/CloudAwsPlugin.java @@ -26,10 +26,10 @@ import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.DiscoveryModule; import org.elasticsearch.discovery.ec2.Ec2Discovery; +import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardRepository; import org.elasticsearch.plugins.AbstractPlugin; import org.elasticsearch.repositories.RepositoriesModule; import org.elasticsearch.repositories.s3.S3Repository; -import org.elasticsearch.repositories.s3.S3RepositoryModule; import java.util.ArrayList; import java.util.Collection; @@ -76,7 +76,7 @@ public class CloudAwsPlugin extends AbstractPlugin { public void onModule(RepositoriesModule repositoriesModule) { if (settings.getAsBoolean("cloud.enabled", true)) { - repositoriesModule.registerRepository(S3Repository.TYPE, S3RepositoryModule.class); + repositoriesModule.registerRepository(S3Repository.TYPE, S3Repository.class, BlobStoreIndexShardRepository.class); } } diff --git a/plugins/cloud-aws/src/main/java/org/elasticsearch/repositories/s3/S3RepositoryModule.java b/plugins/cloud-aws/src/main/java/org/elasticsearch/repositories/s3/S3RepositoryModule.java deleted file mode 100644 index 6d51d61fde2..00000000000 --- a/plugins/cloud-aws/src/main/java/org/elasticsearch/repositories/s3/S3RepositoryModule.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.repositories.s3; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.index.snapshots.IndexShardRepository; -import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardRepository; -import org.elasticsearch.repositories.Repository; - -/** - * S3 repository module - */ -public class S3RepositoryModule extends AbstractModule { - - public S3RepositoryModule() { - super(); - } - - /** - * {@inheritDoc} - */ - @Override - protected void configure() { - bind(Repository.class).to(S3Repository.class).asEagerSingleton(); - bind(IndexShardRepository.class).to(BlobStoreIndexShardRepository.class).asEagerSingleton(); - } -} - diff --git a/plugins/cloud-azure/src/main/java/org/elasticsearch/cloud/azure/AzureModule.java b/plugins/cloud-azure/src/main/java/org/elasticsearch/cloud/azure/AzureModule.java index eec355af760..29d260ff97a 100644 --- a/plugins/cloud-azure/src/main/java/org/elasticsearch/cloud/azure/AzureModule.java +++ b/plugins/cloud-azure/src/main/java/org/elasticsearch/cloud/azure/AzureModule.java @@ -27,6 +27,7 @@ import org.elasticsearch.cloud.azure.management.AzureComputeSettingsFilter; import org.elasticsearch.cloud.azure.storage.AzureStorageService; import org.elasticsearch.cloud.azure.storage.AzureStorageService.Storage; import org.elasticsearch.cloud.azure.storage.AzureStorageServiceImpl; +import org.elasticsearch.cloud.azure.storage.AzureStorageSettingsFilter; import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.Inject; @@ -73,6 +74,7 @@ public class AzureModule extends AbstractModule { @Override protected void configure() { logger.debug("starting azure services"); + bind(AzureStorageSettingsFilter.class).asEagerSingleton(); bind(AzureComputeSettingsFilter.class).asEagerSingleton(); // If we have set discovery to azure, let's start the azure compute service diff --git a/plugins/cloud-azure/src/main/java/org/elasticsearch/plugin/cloud/azure/CloudAzurePlugin.java b/plugins/cloud-azure/src/main/java/org/elasticsearch/plugin/cloud/azure/CloudAzurePlugin.java index e3b5b455584..f60f05da8c3 100644 --- a/plugins/cloud-azure/src/main/java/org/elasticsearch/plugin/cloud/azure/CloudAzurePlugin.java +++ b/plugins/cloud-azure/src/main/java/org/elasticsearch/plugin/cloud/azure/CloudAzurePlugin.java @@ -26,13 +26,13 @@ import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.DiscoveryModule; import org.elasticsearch.discovery.azure.AzureDiscovery; +import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardRepository; import org.elasticsearch.index.store.IndexStoreModule; import org.elasticsearch.index.store.smbmmapfs.SmbMmapFsIndexStore; import org.elasticsearch.index.store.smbsimplefs.SmbSimpleFsIndexStore; import org.elasticsearch.plugins.AbstractPlugin; import org.elasticsearch.repositories.RepositoriesModule; import org.elasticsearch.repositories.azure.AzureRepository; -import org.elasticsearch.repositories.azure.AzureRepositoryModule; import java.util.ArrayList; import java.util.Collection; @@ -71,11 +71,9 @@ public class CloudAzurePlugin extends AbstractPlugin { return modules; } - @Override - public void processModule(Module module) { - if (isSnapshotReady(settings, logger) - && module instanceof RepositoriesModule) { - ((RepositoriesModule)module).registerRepository(AzureRepository.TYPE, AzureRepositoryModule.class); + public void onModule(RepositoriesModule module) { + if (isSnapshotReady(settings, logger)) { + module.registerRepository(AzureRepository.TYPE, AzureRepository.class, BlobStoreIndexShardRepository.class); } } diff --git a/plugins/cloud-azure/src/main/java/org/elasticsearch/repositories/azure/AzureRepositoryModule.java b/plugins/cloud-azure/src/main/java/org/elasticsearch/repositories/azure/AzureRepositoryModule.java deleted file mode 100644 index 11d420b1b07..00000000000 --- a/plugins/cloud-azure/src/main/java/org/elasticsearch/repositories/azure/AzureRepositoryModule.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.repositories.azure; - -import org.elasticsearch.cloud.azure.AzureModule; -import org.elasticsearch.cloud.azure.storage.AzureStorageSettingsFilter; -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.snapshots.IndexShardRepository; -import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardRepository; -import org.elasticsearch.repositories.Repository; - -/** - * Azure repository module - */ -public class AzureRepositoryModule extends AbstractModule { - - protected final ESLogger logger; - private Settings settings; - - public AzureRepositoryModule(Settings settings) { - super(); - this.logger = Loggers.getLogger(getClass(), settings); - this.settings = settings; - } - - /** - * {@inheritDoc} - */ - @Override - protected void configure() { - bind(AzureStorageSettingsFilter.class).asEagerSingleton(); - if (AzureModule.isSnapshotReady(settings, logger)) { - bind(Repository.class).to(AzureRepository.class).asEagerSingleton(); - bind(IndexShardRepository.class).to(BlobStoreIndexShardRepository.class).asEagerSingleton(); - } else { - logger.debug("disabling azure snapshot and restore features"); - } - } - -} - From 4c5cfd02cc25c08d9567653a06f5a97ccf08f21d Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Tue, 18 Aug 2015 10:13:01 -0700 Subject: [PATCH 2/2] Add javadocs to repository types registry methods --- .../elasticsearch/repositories/RepositoryTypesRegistry.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/src/main/java/org/elasticsearch/repositories/RepositoryTypesRegistry.java b/core/src/main/java/org/elasticsearch/repositories/RepositoryTypesRegistry.java index b1e3041e746..e66c79da06f 100644 --- a/core/src/main/java/org/elasticsearch/repositories/RepositoryTypesRegistry.java +++ b/core/src/main/java/org/elasticsearch/repositories/RepositoryTypesRegistry.java @@ -34,11 +34,16 @@ public class RepositoryTypesRegistry { private final ExtensionPoint.TypeExtensionPoint shardRepositoryTypes = new ExtensionPoint.TypeExtensionPoint<>("index_repository", IndexShardRepository.class); + /** Adds a new repository type to the registry, bound to the given implementation classes. */ public void registerRepository(String name, Class repositoryType, Class shardRepositoryType) { repositoryTypes.registerExtension(name, repositoryType); shardRepositoryTypes.registerExtension(name, shardRepositoryType); } + /** + * Looks up the given type and binds the implementation into the given binder. + * Throws an {@link IllegalArgumentException} if the given type does not exist. + */ public void bindType(Binder binder, String type) { Settings settings = Settings.builder().put("type", type).build(); repositoryTypes.bindType(binder, settings, "type", null);