diff --git a/server/src/main/java/org/elasticsearch/node/Node.java b/server/src/main/java/org/elasticsearch/node/Node.java index f3433dfa1ba..757d81de4a3 100644 --- a/server/src/main/java/org/elasticsearch/node/Node.java +++ b/server/src/main/java/org/elasticsearch/node/Node.java @@ -151,7 +151,6 @@ import org.elasticsearch.usage.UsageService; import org.elasticsearch.watcher.ResourceWatcherService; import javax.net.ssl.SNIHostName; - import java.io.BufferedWriter; import java.io.Closeable; import java.io.IOException; @@ -396,7 +395,6 @@ public class Node implements Closeable { .flatMap(p -> p.getNamedXContent().stream()), ClusterModule.getNamedXWriteables().stream()) .flatMap(Function.identity()).collect(toList())); - modules.add(new RepositoriesModule(this.environment, pluginsService.filterPlugins(RepositoryPlugin.class), xContentRegistry)); final MetaStateService metaStateService = new MetaStateService(nodeEnvironment, xContentRegistry); // collect engine factory providers from server and from plugins @@ -478,6 +476,10 @@ public class Node implements Closeable { SearchExecutionStatsCollector.makeWrapper(responseCollectorService)); final HttpServerTransport httpServerTransport = newHttpTransport(networkModule); + + modules.add(new RepositoriesModule(this.environment, pluginsService.filterPlugins(RepositoryPlugin.class), transportService, + clusterService, threadPool, xContentRegistry)); + final DiscoveryModule discoveryModule = new DiscoveryModule(this.settings, threadPool, transportService, namedWriteableRegistry, networkService, clusterService.getMasterService(), clusterService.getClusterApplierService(), clusterService.getClusterSettings(), pluginsService.filterPlugins(DiscoveryPlugin.class), diff --git a/server/src/main/java/org/elasticsearch/repositories/RepositoriesModule.java b/server/src/main/java/org/elasticsearch/repositories/RepositoriesModule.java index 3073e1f0b0e..637ec2d8dfb 100644 --- a/server/src/main/java/org/elasticsearch/repositories/RepositoriesModule.java +++ b/server/src/main/java/org/elasticsearch/repositories/RepositoriesModule.java @@ -20,8 +20,8 @@ package org.elasticsearch.repositories; import org.elasticsearch.action.admin.cluster.snapshots.status.TransportNodesSnapshotsStatus; +import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.inject.multibindings.MapBinder; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.env.Environment; import org.elasticsearch.plugins.RepositoryPlugin; @@ -29,6 +29,8 @@ import org.elasticsearch.repositories.fs.FsRepository; import org.elasticsearch.snapshots.RestoreService; import org.elasticsearch.snapshots.SnapshotShardsService; import org.elasticsearch.snapshots.SnapshotsService; +import org.elasticsearch.threadpool.ThreadPool; +import org.elasticsearch.transport.TransportService; import java.util.Collections; import java.util.HashMap; @@ -40,9 +42,10 @@ import java.util.Map; */ public class RepositoriesModule extends AbstractModule { - private final Map repositoryTypes; + private final RepositoriesService repositoriesService; - public RepositoriesModule(Environment env, List repoPlugins, NamedXContentRegistry namedXContentRegistry) { + public RepositoriesModule(Environment env, List repoPlugins, TransportService transportService, + ClusterService clusterService, ThreadPool threadPool, NamedXContentRegistry namedXContentRegistry) { Map factories = new HashMap<>(); factories.put(FsRepository.TYPE, (metadata) -> new FsRepository(metadata, env, namedXContentRegistry)); @@ -54,17 +57,17 @@ public class RepositoriesModule extends AbstractModule { } } } - repositoryTypes = Collections.unmodifiableMap(factories); + + Map repositoryTypes = Collections.unmodifiableMap(factories); + repositoriesService = new RepositoriesService(env.settings(), clusterService, transportService, repositoryTypes, threadPool); } @Override protected void configure() { - bind(RepositoriesService.class).asEagerSingleton(); + bind(RepositoriesService.class).toInstance(repositoriesService); bind(SnapshotsService.class).asEagerSingleton(); bind(SnapshotShardsService.class).asEagerSingleton(); bind(TransportNodesSnapshotsStatus.class).asEagerSingleton(); bind(RestoreService.class).asEagerSingleton(); - MapBinder typesBinder = MapBinder.newMapBinder(binder(), String.class, Repository.Factory.class); - repositoryTypes.forEach((k, v) -> typesBinder.addBinding(k).toInstance(v)); } } diff --git a/server/src/main/java/org/elasticsearch/repositories/RepositoriesService.java b/server/src/main/java/org/elasticsearch/repositories/RepositoriesService.java index 295b64c554f..e156fcebbec 100644 --- a/server/src/main/java/org/elasticsearch/repositories/RepositoriesService.java +++ b/server/src/main/java/org/elasticsearch/repositories/RepositoriesService.java @@ -34,7 +34,6 @@ import org.elasticsearch.cluster.metadata.RepositoriesMetaData; import org.elasticsearch.cluster.metadata.RepositoryMetaData; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.snapshots.RestoreService; @@ -68,7 +67,6 @@ public class RepositoriesService implements ClusterStateApplier { private volatile Map repositories = Collections.emptyMap(); - @Inject public RepositoriesService(Settings settings, ClusterService clusterService, TransportService transportService, Map typesRegistry, ThreadPool threadPool) {