diff options
author | Harald Musum <musum@oath.com> | 2017-11-23 18:04:09 +0100 |
---|---|---|
committer | Harald Musum <musum@oath.com> | 2017-11-23 18:04:09 +0100 |
commit | 351c1dc3d8b2122ccb5293bc27604878fec12a39 (patch) | |
tree | 03bdebe25e9eab6fb2410689d8ad940074f3af62 /configserver/src | |
parent | c8ac8da9a0b6ab16df85ac5d881fe35dc52e7109 (diff) |
Create connection pool for file server correctly
Use all other config servers than this one.
Diffstat (limited to 'configserver/src')
-rw-r--r-- | configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileServer.java | 31 | ||||
-rw-r--r-- | configserver/src/main/resources/configserver-app/services.xml | 1 |
2 files changed, 27 insertions, 5 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileServer.java b/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileServer.java index 9dc94c9fe93..3561a5cba9a 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileServer.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileServer.java @@ -2,24 +2,29 @@ package com.yahoo.vespa.config.server.filedistribution; import com.google.inject.Inject; +import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.config.FileReference; import com.yahoo.config.model.api.FileDistribution; import com.yahoo.config.subscription.ConfigSourceSet; import com.yahoo.io.IOUtils; +import com.yahoo.net.HostName; import com.yahoo.vespa.config.JRTConnectionPool; +import com.yahoo.vespa.config.server.ConfigServerSpec; import com.yahoo.vespa.filedistribution.FileDownloader; import java.io.File; import java.io.IOException; +import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.logging.Logger; +import java.util.stream.Collectors; public class FileServer { private static final Logger log = Logger.getLogger(FileServer.class.getName()); private final FileDirectory root; private final ExecutorService executor; - private final FileDownloader downloader = new FileDownloader(new JRTConnectionPool(ConfigSourceSet.createDefault())); + private final FileDownloader downloader; public static class ReplayStatus { private final int code; @@ -38,15 +43,21 @@ public class FileServer { } @Inject - public FileServer() { - this(FileDistribution.getDefaultFileDBPath()); + public FileServer(ConfigserverConfig configserverConfig) { + this(createConnectionPool(ConfigServerSpec.fromConfig(configserverConfig)), FileDistribution.getDefaultFileDBPath()); } + // For testing only public FileServer(File rootDir) { - this(rootDir, Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())); + this(new JRTConnectionPool(new ConfigSourceSet("tcp/localhost:19090")), rootDir); } - public FileServer(File rootDir, ExecutorService executor) { + public FileServer(JRTConnectionPool jrtConnectionPool, File rootDir) { + this(jrtConnectionPool, rootDir, Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())); + } + + public FileServer(JRTConnectionPool jrtConnectionPool, File rootDir, ExecutorService executor) { + this.downloader = new FileDownloader(jrtConnectionPool); this.root = new FileDirectory(rootDir); this.executor = executor; } @@ -94,4 +105,14 @@ public class FileServer { public void download(FileReference fileReference) { downloader.getFile(fileReference); } + + // Connection pool with all config servers except this one + private static JRTConnectionPool createConnectionPool(List<com.yahoo.config.model.api.ConfigServerSpec> configServerSpecs) { + return new JRTConnectionPool( + new ConfigSourceSet(configServerSpecs + .stream() + .filter(spec -> !spec.getHostName().equals(HostName.getLocalhost())) + .map(spec -> "tcp/" + spec.getHostName() + ":" + spec.getConfigServerPort()) + .collect(Collectors.toList()))); + } } diff --git a/configserver/src/main/resources/configserver-app/services.xml b/configserver/src/main/resources/configserver-app/services.xml index 635ce07e727..fbab854ae9e 100644 --- a/configserver/src/main/resources/configserver-app/services.xml +++ b/configserver/src/main/resources/configserver-app/services.xml @@ -34,6 +34,7 @@ <component id="com.yahoo.config.provision.Zone" bundle="config-provisioning" /> <component id="com.yahoo.vespa.config.server.application.ApplicationConvergenceChecker" bundle="configserver" /> <component id="com.yahoo.vespa.config.server.application.HttpProxy" bundle="configserver" /> + <component id="com.yahoo.vespa.config.server.filedistribution.FileServer" bundle="configserver" /> <component id="com.yahoo.vespa.serviceview.ConfigServerLocation" bundle="configserver" /> |