From 5ffdf15f02cb063a562c3a29a4b2b101fc6470a0 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 26 Oct 2015 11:34:17 +0100 Subject: [PATCH] Remove guice injection from IndexStore and friends This commit replaces dependency injection from IndexStore and subclasses and replaces it with dedicated set of dependencies. --- .../org/elasticsearch/index/IndexModule.java | 75 ++++++++++++++-- .../index/store/FsDirectoryService.java | 11 +-- .../elasticsearch/index/store/IndexStore.java | 2 - .../index/store/IndexStoreModule.java | 87 ------------------- .../elasticsearch/indices/IndicesService.java | 9 +- .../TransportNodesListShardStoreMetaData.java | 5 +- .../elasticsearch/index/IndexModuleTests.java | 38 ++++++-- .../index/store/IndexStoreTests.java | 7 +- .../plugins/PluginsServiceTests.java | 8 +- .../test/store/MockFSDirectoryService.java | 9 +- .../test/store/MockFSIndexStore.java | 20 ++--- .../test/store/MockFSIndexStoreModule.java | 32 ------- .../smbmmapfs/SmbMmapFsDirectoryService.java | 1 - .../store/smbmmapfs/SmbMmapFsIndexStore.java | 2 - .../SmbSimpleFsDirectoryService.java | 2 - .../smbsimplefs/SmbSimpleFsIndexStore.java | 2 - .../plugin/store/smb/SMBStorePlugin.java | 7 +- 17 files changed, 136 insertions(+), 181 deletions(-) delete mode 100644 core/src/main/java/org/elasticsearch/index/store/IndexStoreModule.java delete mode 100644 core/src/test/java/org/elasticsearch/test/store/MockFSIndexStoreModule.java diff --git a/core/src/main/java/org/elasticsearch/index/IndexModule.java b/core/src/main/java/org/elasticsearch/index/IndexModule.java index 58b673a209f1..26fc45fae5fe 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexModule.java +++ b/core/src/main/java/org/elasticsearch/index/IndexModule.java @@ -19,7 +19,6 @@ package org.elasticsearch.index; -import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.util.Providers; import org.elasticsearch.common.settings.Settings; @@ -29,9 +28,11 @@ import org.elasticsearch.index.fielddata.IndexFieldDataService; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.shard.IndexEventListener; import org.elasticsearch.index.shard.IndexSearcherWrapper; +import org.elasticsearch.index.store.IndexStore; +import org.elasticsearch.indices.store.IndicesStore; -import java.util.HashSet; -import java.util.Set; +import java.util.*; +import java.util.function.BiFunction; import java.util.function.Consumer; /** @@ -39,16 +40,20 @@ import java.util.function.Consumer; */ public class IndexModule extends AbstractModule { + public static final String STORE_TYPE = "index.store.type"; private final IndexSettings indexSettings; + private final IndicesStore indicesStore; // pkg private so tests can mock Class engineFactoryImpl = InternalEngineFactory.class; Class indexSearcherWrapper = null; private final Set> settingsConsumers = new HashSet<>(); private final Set indexEventListeners = new HashSet<>(); private IndexEventListener listener; + private final Map> storeTypes = new HashMap<>(); - public IndexModule(IndexSettings indexSettings) { + public IndexModule(IndexSettings indexSettings, IndicesStore indicesStore) { + this.indicesStore = indicesStore; this.indexSettings = indexSettings; } @@ -105,6 +110,23 @@ public class IndexModule extends AbstractModule { this.indexEventListeners.add(listener); } + /** + * Adds an {@link IndexStore} type to this index module. Typically stores are registered with a refrence to + * it's constructor: + *
+     *     indexModule.addIndexStore("my_store_type", MyStore::new);
+     * 
+ * + * @param type the type to register + * @param provider the instance provider / factory method + */ + public void addIndexStore(String type, BiFunction provider) { + if (storeTypes.containsKey(type)) { + throw new IllegalArgumentException("key [" + type +"] already registerd"); + } + storeTypes.put(type, provider); + } + public IndexEventListener freeze() { // TODO somehow we need to make this pkg private... if (listener == null) { @@ -113,6 +135,15 @@ public class IndexModule extends AbstractModule { return listener; } + private static boolean isBuiltinType(String storeType) { + for (Type type : Type.values()) { + if (type.match(storeType)) { + return true; + } + } + return false; + } + @Override protected void configure() { bind(EngineFactory.class).to(engineFactoryImpl).asEagerSingleton(); @@ -126,7 +157,41 @@ public class IndexModule extends AbstractModule { bind(IndexServicesProvider.class).asEagerSingleton(); bind(MapperService.class).asEagerSingleton(); bind(IndexFieldDataService.class).asEagerSingleton(); - bind(IndexSettings.class).toInstance(new IndexSettings(indexSettings.getIndexMetaData(), indexSettings.getNodeSettings(), settingsConsumers)); + final IndexSettings settings = new IndexSettings(indexSettings.getIndexMetaData(), indexSettings.getNodeSettings(), settingsConsumers); + bind(IndexSettings.class).toInstance(settings); + + final String storeType = settings.getSettings().get(STORE_TYPE); + final IndexStore store; + if (storeType == null || isBuiltinType(storeType)) { + store = new IndexStore(settings, indicesStore); + } else { + BiFunction factory = storeTypes.get(storeType); + if (factory == null) { + throw new IllegalArgumentException("Unknown store type [" + storeType + "]"); + } + store = factory.apply(settings, indicesStore); + if (store == null) { + throw new IllegalStateException("store must not be null"); + } + } + bind(IndexStore.class).toInstance(store); } + public enum Type { + NIOFS, + MMAPFS, + SIMPLEFS, + FS, + DEFAULT; + + public String getSettingsKey() { + return this.name().toLowerCase(Locale.ROOT); + } + /** + * Returns true iff this settings matches the type. + */ + public boolean match(String setting) { + return getSettingsKey().equals(setting); + } + } } diff --git a/core/src/main/java/org/elasticsearch/index/store/FsDirectoryService.java b/core/src/main/java/org/elasticsearch/index/store/FsDirectoryService.java index 837b113d1c58..5c673b2aebcc 100644 --- a/core/src/main/java/org/elasticsearch/index/store/FsDirectoryService.java +++ b/core/src/main/java/org/elasticsearch/index/store/FsDirectoryService.java @@ -25,6 +25,7 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.metrics.CounterMetric; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.set.Sets; +import org.elasticsearch.index.IndexModule; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.shard.ShardPath; @@ -100,18 +101,18 @@ public class FsDirectoryService extends DirectoryService implements StoreRateLim protected Directory newFSDirectory(Path location, LockFactory lockFactory) throws IOException { - final String storeType = indexSettings.get(IndexStoreModule.STORE_TYPE, IndexStoreModule.Type.DEFAULT.getSettingsKey()); - if (IndexStoreModule.Type.FS.match(storeType) || IndexStoreModule.Type.DEFAULT.match(storeType)) { + final String storeType = indexSettings.get(IndexModule.STORE_TYPE, IndexModule.Type.DEFAULT.getSettingsKey()); + if (IndexModule.Type.FS.match(storeType) || IndexModule.Type.DEFAULT.match(storeType)) { final FSDirectory open = FSDirectory.open(location, lockFactory); // use lucene defaults if (open instanceof MMapDirectory && Constants.WINDOWS == false) { return newDefaultDir(location, (MMapDirectory) open, lockFactory); } return open; - } else if (IndexStoreModule.Type.SIMPLEFS.match(storeType)) { + } else if (IndexModule.Type.SIMPLEFS.match(storeType)) { return new SimpleFSDirectory(location, lockFactory); - } else if (IndexStoreModule.Type.NIOFS.match(storeType)) { + } else if (IndexModule.Type.NIOFS.match(storeType)) { return new NIOFSDirectory(location, lockFactory); - } else if (IndexStoreModule.Type.MMAPFS.match(storeType)) { + } else if (IndexModule.Type.MMAPFS.match(storeType)) { return new MMapDirectory(location, lockFactory); } throw new IllegalArgumentException("No directory found for type [" + storeType + "]"); diff --git a/core/src/main/java/org/elasticsearch/index/store/IndexStore.java b/core/src/main/java/org/elasticsearch/index/store/IndexStore.java index 07ae843421af..0715b971ae73 100644 --- a/core/src/main/java/org/elasticsearch/index/store/IndexStore.java +++ b/core/src/main/java/org/elasticsearch/index/store/IndexStore.java @@ -20,7 +20,6 @@ package org.elasticsearch.index.store; import org.apache.lucene.store.StoreRateLimiting; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.index.AbstractIndexComponent; @@ -43,7 +42,6 @@ public class IndexStore extends AbstractIndexComponent { private final StoreRateLimiting rateLimiting = new StoreRateLimiting(); - @Inject public IndexStore(IndexSettings indexSettings, IndicesStore indicesStore) { super(indexSettings); this.indicesStore = indicesStore; diff --git a/core/src/main/java/org/elasticsearch/index/store/IndexStoreModule.java b/core/src/main/java/org/elasticsearch/index/store/IndexStoreModule.java deleted file mode 100644 index 84c856d1701c..000000000000 --- a/core/src/main/java/org/elasticsearch/index/store/IndexStoreModule.java +++ /dev/null @@ -1,87 +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.index.store; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.settings.Settings; - -import java.util.HashMap; -import java.util.Map; -import java.util.Locale; - -/** - * - */ -public class IndexStoreModule extends AbstractModule { - - public static final String STORE_TYPE = "index.store.type"; - - private final Settings settings; - private final Map> storeTypes = new HashMap<>(); - - public enum Type { - NIOFS, - MMAPFS, - SIMPLEFS, - FS, - DEFAULT; - - public String getSettingsKey() { - return this.name().toLowerCase(Locale.ROOT); - } - /** - * Returns true iff this settings matches the type. - */ - public boolean match(String setting) { - return getSettingsKey().equals(setting); - } - } - - public IndexStoreModule(Settings settings) { - this.settings = settings; - } - - public void addIndexStore(String type, Class clazz) { - storeTypes.put(type, clazz); - } - - private static boolean isBuiltinType(String storeType) { - for (Type type : Type.values()) { - if (type.match(storeType)) { - return true; - } - } - return false; - } - - @Override - protected void configure() { - final String storeType = settings.get(STORE_TYPE); - if (storeType == null || isBuiltinType(storeType)) { - bind(IndexStore.class).asEagerSingleton(); - } else { - Class clazz = storeTypes.get(storeType); - if (clazz == null) { - throw new IllegalArgumentException("Unknown store type [" + storeType + "]"); - } - bind(IndexStore.class).to(clazz).asEagerSingleton(); - } - } -} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/indices/IndicesService.java b/core/src/main/java/org/elasticsearch/indices/IndicesService.java index b5022401366d..3bcb1db39a0b 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndicesService.java +++ b/core/src/main/java/org/elasticsearch/indices/IndicesService.java @@ -60,9 +60,9 @@ import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.index.shard.IndexEventListener; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.similarity.SimilarityModule; -import org.elasticsearch.index.store.IndexStoreModule; import org.elasticsearch.indices.analysis.IndicesAnalysisService; import org.elasticsearch.indices.recovery.RecoverySettings; +import org.elasticsearch.indices.store.IndicesStore; import org.elasticsearch.plugins.PluginsService; import java.io.Closeable; @@ -77,8 +77,6 @@ import java.util.stream.Stream; import static java.util.Collections.emptyMap; import static java.util.Collections.unmodifiableMap; -import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS; -import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS; import static org.elasticsearch.common.collect.MapBuilder.newMapBuilder; import static org.elasticsearch.common.settings.Settings.settingsBuilder; import static org.elasticsearch.common.util.CollectionUtils.arrayAsArrayList; @@ -290,6 +288,8 @@ public class IndicesService extends AbstractLifecycleComponent i if (!lifecycle.started()) { throw new IllegalStateException("Can't create an index [" + indexMetaData.getIndex() + "], node is closed"); } + + final IndicesStore indicesStore = injector.getInstance(IndicesStore.class); // TODO remove this circular dep!! final IndexSettings idxSettings = new IndexSettings(indexMetaData, this.settings, Collections.EMPTY_LIST); Index index = new Index(indexMetaData.getIndex()); if (indices.containsKey(index.name())) { @@ -307,12 +307,11 @@ public class IndicesService extends AbstractLifecycleComponent i for (Module pluginModule : pluginsService.indexModules(idxSettings.getSettings())) { modules.add(pluginModule); } - final IndexModule indexModule = new IndexModule(idxSettings); + final IndexModule indexModule = new IndexModule(idxSettings, indicesStore); for (IndexEventListener listener : builtInListeners) { indexModule.addIndexEventListener(listener); } indexModule.addIndexEventListener(oldShardsStats); - modules.add(new IndexStoreModule(idxSettings.getSettings())); modules.add(new AnalysisModule(idxSettings.getSettings(), indicesAnalysisService)); modules.add(new SimilarityModule(idxSettings)); modules.add(new IndexCacheModule(idxSettings.getSettings())); diff --git a/core/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetaData.java b/core/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetaData.java index 2972fcfa6cf8..44c9fbec0e07 100644 --- a/core/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetaData.java +++ b/core/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetaData.java @@ -42,13 +42,12 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.gateway.AsyncShardFetch; -import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexModule; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardPath; -import org.elasticsearch.index.store.IndexStoreModule; import org.elasticsearch.index.store.Store; import org.elasticsearch.index.store.StoreFileMetaData; import org.elasticsearch.indices.IndicesService; @@ -168,7 +167,7 @@ public class TransportNodesListShardStoreMetaData extends TransportNodesAction x == null); module.indexSearcherWrapper = Wrapper.class; assertBinding(module, IndexSearcherWrapper.class, Wrapper.class); @@ -53,12 +55,27 @@ public class IndexModuleTests extends ModuleTestCase { final Index index = new Index("foo"); final Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings, Collections.EMPTY_LIST); - IndexModule module = new IndexModule(indexSettings); + IndexModule module = new IndexModule(indexSettings, null); assertBinding(module, EngineFactory.class, InternalEngineFactory.class); module.engineFactoryImpl = MockEngineFactory.class; assertBinding(module, EngineFactory.class, MockEngineFactory.class); } + public void testRegisterIndexStore() { + final Index index = new Index("foo"); + final Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexModule.STORE_TYPE, "foo_store").build(); + IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings, Collections.EMPTY_LIST); + IndexModule module = new IndexModule(indexSettings, null); + module.addIndexStore("foo_store", FooStore::new); + assertInstanceBinding(module, IndexStore.class, (x) -> x.getClass() == FooStore.class); + try { + module.addIndexStore("foo_store", FooStore::new); + fail("already registered"); + } catch (IllegalArgumentException ex) { + // fine + } + } + public void testOtherServiceBound() { final AtomicBoolean atomicBoolean = new AtomicBoolean(false); final IndexEventListener eventListener = new IndexEventListener() { @@ -70,16 +87,20 @@ public class IndexModuleTests extends ModuleTestCase { final Index index = new Index("foo"); final Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings, Collections.EMPTY_LIST); - IndexModule module = new IndexModule(indexSettings); + IndexModule module = new IndexModule(indexSettings, null); Consumer listener = (s) -> {}; module.addIndexSettingsListener(listener); module.addIndexEventListener(eventListener); assertBinding(module, IndexService.class, IndexService.class); assertBinding(module, IndexServicesProvider.class, IndexServicesProvider.class); - assertInstanceBinding(module, IndexEventListener.class, (x) -> {x.beforeIndexDeleted(null); return atomicBoolean.get();}); + assertInstanceBinding(module, IndexEventListener.class, (x) -> { + x.beforeIndexDeleted(null); + return atomicBoolean.get(); + }); assertInstanceBinding(module, IndexSettings.class, (x) -> x.getSettings().getAsMap().equals(indexSettings.getSettings().getAsMap())); assertInstanceBinding(module, IndexSettings.class, (x) -> x.getIndex().equals(indexSettings.getIndex())); assertInstanceBinding(module, IndexSettings.class, (x) -> x.getUpdateListeners().get(0) == listener); + assertInstanceBinding(module, IndexStore.class, (x) -> x.getClass() == IndexStore.class); } @@ -87,7 +108,7 @@ public class IndexModuleTests extends ModuleTestCase { final Index index = new Index("foo"); final Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings, Collections.EMPTY_LIST); - IndexModule module = new IndexModule(indexSettings); + IndexModule module = new IndexModule(indexSettings, null); Consumer listener = (s) -> { }; module.addIndexSettingsListener(listener); @@ -124,4 +145,11 @@ public class IndexModuleTests extends ModuleTestCase { } } + public static final class FooStore extends IndexStore { + + public FooStore(IndexSettings indexSettings, IndicesStore indicesStore) { + super(indexSettings, indicesStore); + } + } + } diff --git a/core/src/test/java/org/elasticsearch/index/store/IndexStoreTests.java b/core/src/test/java/org/elasticsearch/index/store/IndexStoreTests.java index 9228f075d616..97faf1ed3745 100644 --- a/core/src/test/java/org/elasticsearch/index/store/IndexStoreTests.java +++ b/core/src/test/java/org/elasticsearch/index/store/IndexStoreTests.java @@ -25,6 +25,7 @@ import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexModule; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardPath; @@ -42,9 +43,9 @@ public class IndexStoreTests extends ESTestCase { public void testStoreDirectory() throws IOException { final Path tempDir = createTempDir().resolve("foo").resolve("0"); - final IndexStoreModule.Type[] values = IndexStoreModule.Type.values(); - final IndexStoreModule.Type type = RandomPicks.randomFrom(random(), values); - Settings settings = Settings.settingsBuilder().put(IndexStoreModule.STORE_TYPE, type.name().toLowerCase(Locale.ROOT)) + final IndexModule.Type[] values = IndexModule.Type.values(); + final IndexModule.Type type = RandomPicks.randomFrom(random(), values); + Settings settings = Settings.settingsBuilder().put(IndexModule.STORE_TYPE, type.name().toLowerCase(Locale.ROOT)) .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(new Index("foo"), settings, Collections.EMPTY_LIST); FsDirectoryService service = new FsDirectoryService(indexSettings, null, new ShardPath(false, tempDir, tempDir, "foo", new ShardId("foo", 0))); diff --git a/core/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java b/core/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java index d4553bd0c46f..e5150ada63e4 100644 --- a/core/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java +++ b/core/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java @@ -21,7 +21,7 @@ package org.elasticsearch.plugins; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; -import org.elasticsearch.index.store.IndexStoreModule; +import org.elasticsearch.index.IndexModule; import org.elasticsearch.test.ESTestCase; import java.util.Arrays; @@ -38,7 +38,7 @@ public class PluginsServiceTests extends ESTestCase { } @Override public Settings additionalSettings() { - return Settings.builder().put("foo.bar", "1").put(IndexStoreModule.STORE_TYPE, IndexStoreModule.Type.MMAPFS.getSettingsKey()).build(); + return Settings.builder().put("foo.bar", "1").put(IndexModule.STORE_TYPE, IndexModule.Type.MMAPFS.getSettingsKey()).build(); } } public static class AdditionalSettingsPlugin2 extends Plugin { @@ -64,12 +64,12 @@ public class PluginsServiceTests extends ESTestCase { Settings settings = Settings.builder() .put("path.home", createTempDir()) .put("my.setting", "test") - .put(IndexStoreModule.STORE_TYPE, IndexStoreModule.Type.SIMPLEFS.getSettingsKey()).build(); + .put(IndexModule.STORE_TYPE, IndexModule.Type.SIMPLEFS.getSettingsKey()).build(); PluginsService service = newPluginsService(settings, AdditionalSettingsPlugin1.class); Settings newSettings = service.updatedSettings(); assertEquals("test", newSettings.get("my.setting")); // previous settings still exist assertEquals("1", newSettings.get("foo.bar")); // added setting exists - assertEquals(IndexStoreModule.Type.SIMPLEFS.getSettingsKey(), newSettings.get(IndexStoreModule.STORE_TYPE)); // does not override pre existing settings + assertEquals(IndexModule.Type.SIMPLEFS.getSettingsKey(), newSettings.get(IndexModule.STORE_TYPE)); // does not override pre existing settings } public void testAdditionalSettingsClash() { diff --git a/core/src/test/java/org/elasticsearch/test/store/MockFSDirectoryService.java b/core/src/test/java/org/elasticsearch/test/store/MockFSDirectoryService.java index dc20feed0995..9c2b8612d511 100644 --- a/core/src/test/java/org/elasticsearch/test/store/MockFSDirectoryService.java +++ b/core/src/test/java/org/elasticsearch/test/store/MockFSDirectoryService.java @@ -33,16 +33,15 @@ import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.IndexModule; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.shard.*; import org.elasticsearch.index.store.FsDirectoryService; import org.elasticsearch.index.store.IndexStore; -import org.elasticsearch.index.store.IndexStoreModule; import org.elasticsearch.index.store.Store; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.IndexSettingsModule; import org.junit.Assert; import java.io.Closeable; @@ -63,13 +62,12 @@ public class MockFSDirectoryService extends FsDirectoryService { private final double randomIOExceptionRate; private final double randomIOExceptionRateOnOpen; private final MockDirectoryWrapper.Throttling throttle; - private final Settings indexSettings; private final boolean preventDoubleWrite; private final boolean noDeleteOpenFile; private final boolean crashIndex; @Inject - public MockFSDirectoryService(IndexSettings idxSettings, IndexStore indexStore, final IndicesService service, final ShardPath path) { + public MockFSDirectoryService(IndexSettings idxSettings, IndexStore indexStore, final ShardPath path) { super(idxSettings, indexStore, path); Settings indexSettings = idxSettings.getSettings(); final long seed = indexSettings.getAsLong(ESIntegTestCase.SETTING_INDEX_SEED, 0l); @@ -87,7 +85,6 @@ public class MockFSDirectoryService extends FsDirectoryService { logger.debug("Using MockDirWrapper with seed [{}] throttle: [{}] crashIndex: [{}]", SeedUtils.formatSeed(seed), throttle, crashIndex); } - this.indexSettings = indexSettings; delegateService = randomDirectorService(indexStore, path); } @@ -175,7 +172,7 @@ public class MockFSDirectoryService extends FsDirectoryService { private FsDirectoryService randomDirectorService(IndexStore indexStore, ShardPath path) { final IndexSettings indexSettings = indexStore.getIndexSettings(); - final IndexMetaData build = IndexMetaData.builder(indexSettings.getIndexMetaData()).settings(Settings.builder().put(indexSettings.getSettings()).put(IndexStoreModule.STORE_TYPE, RandomPicks.randomFrom(random, IndexStoreModule.Type.values()).getSettingsKey())).build(); + final IndexMetaData build = IndexMetaData.builder(indexSettings.getIndexMetaData()).settings(Settings.builder().put(indexSettings.getSettings()).put(IndexModule.STORE_TYPE, RandomPicks.randomFrom(random, IndexModule.Type.values()).getSettingsKey())).build(); final IndexSettings newIndexSettings = new IndexSettings(build, indexSettings.getNodeSettings(), Collections.EMPTY_LIST); return new FsDirectoryService(newIndexSettings, indexStore, path); } diff --git a/core/src/test/java/org/elasticsearch/test/store/MockFSIndexStore.java b/core/src/test/java/org/elasticsearch/test/store/MockFSIndexStore.java index 4898ac164d19..07f0e62b1a15 100644 --- a/core/src/test/java/org/elasticsearch/test/store/MockFSIndexStore.java +++ b/core/src/test/java/org/elasticsearch/test/store/MockFSIndexStore.java @@ -21,7 +21,6 @@ package org.elasticsearch.test.store; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; @@ -30,8 +29,6 @@ import org.elasticsearch.index.IndexModule; import org.elasticsearch.index.shard.*; import org.elasticsearch.index.store.DirectoryService; import org.elasticsearch.index.store.IndexStore; -import org.elasticsearch.index.store.IndexStoreModule; -import org.elasticsearch.indices.IndicesService; import org.elasticsearch.indices.store.IndicesStore; import org.elasticsearch.plugins.Plugin; @@ -40,7 +37,6 @@ import java.util.*; public class MockFSIndexStore extends IndexStore { public static final String CHECK_INDEX_ON_CLOSE = "index.store.mock.check_index_on_close"; - private final IndicesService indicesService; public static class TestPlugin extends Plugin { @Override @@ -51,33 +47,29 @@ public class MockFSIndexStore extends IndexStore { public String description() { return "a mock index store for testing"; } - public void onModule(IndexStoreModule indexStoreModule) { - indexStoreModule.addIndexStore("mock", MockFSIndexStore.class); - } @Override public Settings additionalSettings() { - return Settings.builder().put(IndexStoreModule.STORE_TYPE, "mock").build(); + return Settings.builder().put(IndexModule.STORE_TYPE, "mock").build(); } public void onModule(IndexModule module) { Settings indexSettings = module.getSettings(); - if ("mock".equals(indexSettings.get(IndexStoreModule.STORE_TYPE))) { + if ("mock".equals(indexSettings.get(IndexModule.STORE_TYPE))) { if (indexSettings.getAsBoolean(CHECK_INDEX_ON_CLOSE, true)) { module.addIndexEventListener(new Listener()); } + module.addIndexStore("mock", MockFSIndexStore::new); } } } - @Inject - public MockFSIndexStore(IndexSettings indexSettings, - IndicesStore indicesStore, IndicesService indicesService) { + MockFSIndexStore(IndexSettings indexSettings, + IndicesStore indicesStore) { super(indexSettings, indicesStore); - this.indicesService = indicesService; } public DirectoryService newDirectoryService(ShardPath path) { - return new MockFSDirectoryService(indexSettings, this, indicesService, path); + return new MockFSDirectoryService(indexSettings, this, path); } private static final EnumSet validCheckIndexStates = EnumSet.of( diff --git a/core/src/test/java/org/elasticsearch/test/store/MockFSIndexStoreModule.java b/core/src/test/java/org/elasticsearch/test/store/MockFSIndexStoreModule.java deleted file mode 100644 index c4f9d2046adc..000000000000 --- a/core/src/test/java/org/elasticsearch/test/store/MockFSIndexStoreModule.java +++ /dev/null @@ -1,32 +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.test.store; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.index.store.IndexStore; - -public class MockFSIndexStoreModule extends AbstractModule { - - @Override - protected void configure() { - bind(IndexStore.class).to(MockFSIndexStore.class).asEagerSingleton(); - } - -} diff --git a/plugins/store-smb/src/main/java/org/elasticsearch/index/store/smbmmapfs/SmbMmapFsDirectoryService.java b/plugins/store-smb/src/main/java/org/elasticsearch/index/store/smbmmapfs/SmbMmapFsDirectoryService.java index 1d8e46f09e0c..744be5e49de2 100644 --- a/plugins/store-smb/src/main/java/org/elasticsearch/index/store/smbmmapfs/SmbMmapFsDirectoryService.java +++ b/plugins/store-smb/src/main/java/org/elasticsearch/index/store/smbmmapfs/SmbMmapFsDirectoryService.java @@ -34,7 +34,6 @@ import java.nio.file.Path; public class SmbMmapFsDirectoryService extends FsDirectoryService { - @Inject public SmbMmapFsDirectoryService(IndexSettings indexSettings, IndexStore indexStore, ShardPath path) { super(indexSettings, indexStore, path); } diff --git a/plugins/store-smb/src/main/java/org/elasticsearch/index/store/smbmmapfs/SmbMmapFsIndexStore.java b/plugins/store-smb/src/main/java/org/elasticsearch/index/store/smbmmapfs/SmbMmapFsIndexStore.java index 940cb2407ca7..20529d7767b8 100644 --- a/plugins/store-smb/src/main/java/org/elasticsearch/index/store/smbmmapfs/SmbMmapFsIndexStore.java +++ b/plugins/store-smb/src/main/java/org/elasticsearch/index/store/smbmmapfs/SmbMmapFsIndexStore.java @@ -19,7 +19,6 @@ package org.elasticsearch.index.store.smbmmapfs; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.shard.ShardPath; import org.elasticsearch.index.store.DirectoryService; @@ -28,7 +27,6 @@ import org.elasticsearch.indices.store.IndicesStore; public class SmbMmapFsIndexStore extends IndexStore { - @Inject public SmbMmapFsIndexStore(IndexSettings indexSettings, IndicesStore indicesStore) { super(indexSettings, indicesStore); } diff --git a/plugins/store-smb/src/main/java/org/elasticsearch/index/store/smbsimplefs/SmbSimpleFsDirectoryService.java b/plugins/store-smb/src/main/java/org/elasticsearch/index/store/smbsimplefs/SmbSimpleFsDirectoryService.java index 939058a78b37..dc43c627bfd1 100644 --- a/plugins/store-smb/src/main/java/org/elasticsearch/index/store/smbsimplefs/SmbSimpleFsDirectoryService.java +++ b/plugins/store-smb/src/main/java/org/elasticsearch/index/store/smbsimplefs/SmbSimpleFsDirectoryService.java @@ -23,7 +23,6 @@ import org.apache.lucene.store.Directory; import org.apache.lucene.store.LockFactory; import org.apache.lucene.store.SimpleFSDirectory; import org.apache.lucene.store.SmbDirectoryWrapper; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.shard.ShardPath; import org.elasticsearch.index.store.FsDirectoryService; @@ -34,7 +33,6 @@ import java.nio.file.Path; public class SmbSimpleFsDirectoryService extends FsDirectoryService { - @Inject public SmbSimpleFsDirectoryService(IndexSettings indexSettings, IndexStore indexStore, ShardPath path) { super(indexSettings, indexStore, path); } diff --git a/plugins/store-smb/src/main/java/org/elasticsearch/index/store/smbsimplefs/SmbSimpleFsIndexStore.java b/plugins/store-smb/src/main/java/org/elasticsearch/index/store/smbsimplefs/SmbSimpleFsIndexStore.java index b4b9d7ed6842..6ad1152bc307 100644 --- a/plugins/store-smb/src/main/java/org/elasticsearch/index/store/smbsimplefs/SmbSimpleFsIndexStore.java +++ b/plugins/store-smb/src/main/java/org/elasticsearch/index/store/smbsimplefs/SmbSimpleFsIndexStore.java @@ -19,7 +19,6 @@ package org.elasticsearch.index.store.smbsimplefs; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.shard.ShardPath; import org.elasticsearch.index.store.DirectoryService; @@ -28,7 +27,6 @@ import org.elasticsearch.indices.store.IndicesStore; public class SmbSimpleFsIndexStore extends IndexStore { - @Inject public SmbSimpleFsIndexStore(IndexSettings indexSettings, IndicesStore indicesStore) { super(indexSettings, indicesStore); } diff --git a/plugins/store-smb/src/main/java/org/elasticsearch/plugin/store/smb/SMBStorePlugin.java b/plugins/store-smb/src/main/java/org/elasticsearch/plugin/store/smb/SMBStorePlugin.java index 5a5ace336c49..1da91f527910 100644 --- a/plugins/store-smb/src/main/java/org/elasticsearch/plugin/store/smb/SMBStorePlugin.java +++ b/plugins/store-smb/src/main/java/org/elasticsearch/plugin/store/smb/SMBStorePlugin.java @@ -19,6 +19,7 @@ package org.elasticsearch.plugin.store.smb; +import org.elasticsearch.index.IndexModule; import org.elasticsearch.index.store.IndexStoreModule; import org.elasticsearch.index.store.smbmmapfs.SmbMmapFsIndexStore; import org.elasticsearch.index.store.smbsimplefs.SmbSimpleFsIndexStore; @@ -36,8 +37,8 @@ public class SMBStorePlugin extends Plugin { return "SMB Store Plugin"; } - public void onModule(IndexStoreModule storeModule) { - storeModule.addIndexStore("smb_mmap_fs", SmbMmapFsIndexStore.class); - storeModule.addIndexStore("smb_simple_fs", SmbSimpleFsIndexStore.class); + public void onModule(IndexModule storeModule) { + storeModule.addIndexStore("smb_mmap_fs", SmbMmapFsIndexStore::new); + storeModule.addIndexStore("smb_simple_fs", SmbSimpleFsIndexStore::new); } }