diff options
author | Harald Musum <musum@verizonmedia.com> | 2020-04-14 08:33:45 +0200 |
---|---|---|
committer | Harald Musum <musum@verizonmedia.com> | 2020-04-14 08:33:45 +0200 |
commit | 92a0e866562662d5be4b3aa01da2a115bc9a2a00 (patch) | |
tree | 655712bebdcf52e51ef440e406fa1a1fbe015450 /config-model/src/main/java | |
parent | e40c993de0b870a2aec7fff91a64ac229b36fd0b (diff) |
Clean up and simplify FileDistributor
No functional changes
Diffstat (limited to 'config-model/src/main/java')
5 files changed, 29 insertions, 47 deletions
diff --git a/config-model/src/main/java/com/yahoo/config/model/test/MockRoot.java b/config-model/src/main/java/com/yahoo/config/model/test/MockRoot.java index 13f271ebe9d..f9492398f9f 100644 --- a/config-model/src/main/java/com/yahoo/config/model/test/MockRoot.java +++ b/config-model/src/main/java/com/yahoo/config/model/test/MockRoot.java @@ -26,6 +26,7 @@ import java.io.IOException; import java.io.StringReader; import java.util.ArrayList; import java.util.Collections; +import java.util.List; import java.util.Set; @@ -66,7 +67,7 @@ public class MockRoot extends AbstractConfigProducerRoot { super(rootConfigId); hostSystem = new HostSystem(this, "hostsystem", deployState.getProvisioner(), deployState.getDeployLogger()); this.deployState = deployState; - fileDistributor = new FileDistributor(deployState.getFileRegistry(), null); + fileDistributor = new FileDistributor(deployState.getFileRegistry(), List.of()); } public FileDistributionConfigProducer getFileDistributionConfigProducer() { diff --git a/config-model/src/main/java/com/yahoo/vespa/model/AbstractService.java b/config-model/src/main/java/com/yahoo/vespa/model/AbstractService.java index 72c475fb091..75b33e184d9 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/AbstractService.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/AbstractService.java @@ -461,6 +461,7 @@ public abstract class AbstractService extends AbstractConfigProducer<AbstractCon public FileReference sendFile(String relativePath) { return getRoot().getFileDistributor().sendFileToHost(relativePath, getHost()); } + public FileReference sendUri(String uri) { return getRoot().getFileDistributor().sendUriToHost(uri, getHost()); } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java b/config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java index 89cd5c2e735..2ad394d1521 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java @@ -209,7 +209,8 @@ public final class VespaModel extends AbstractConfigProducerRoot implements Seri /** Creates a mutable model with no services instantiated */ public static VespaModel createIncomplete(DeployState deployState) throws IOException, SAXException { - return new VespaModel(new NullConfigModelRegistry(), deployState, false, new FileDistributor(deployState.getFileRegistry(), null)); + return new VespaModel(new NullConfigModelRegistry(), deployState, false, + new FileDistributor(deployState.getFileRegistry(), List.of())); } private void validateWrapExceptions() { diff --git a/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributionConfigProducer.java b/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributionConfigProducer.java index 9662540e8df..a86b74e963a 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributionConfigProducer.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributionConfigProducer.java @@ -20,7 +20,8 @@ public class FileDistributionConfigProducer extends AbstractConfigProducer { private final Map<Host, FileDistributionConfigProvider> fileDistributionConfigProviders = new IdentityHashMap<>(); private final FileDistributor fileDistributor; - public FileDistributionConfigProducer(AbstractConfigProducer ancestor, FileRegistry fileRegistry, List<ConfigServerSpec> configServerSpec) { + public FileDistributionConfigProducer(AbstractConfigProducer ancestor, FileRegistry fileRegistry, + List<ConfigServerSpec> configServerSpec) { this(ancestor, new FileDistributor(fileRegistry, configServerSpec)); } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributor.java b/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributor.java index 576b009c846..591d2b2851d 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributor.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributor.java @@ -20,60 +20,39 @@ public class FileDistributor { private final FileRegistry fileRegistry; private final List<ConfigServerSpec> configServerSpecs; - /** A map from files to the hosts to which that file should be distributed */ + /** A map from file reference to the hosts to which that file reference should be distributed */ private final Map<FileReference, Set<Host>> filesToHosts = new LinkedHashMap<>(); + public FileDistributor(FileRegistry fileRegistry, List<ConfigServerSpec> configServerSpecs) { + this.fileRegistry = fileRegistry; + this.configServerSpecs = configServerSpecs; + } + /** * Adds the given file to the associated application packages' registry of file and marks the file - * for distribution to the given hosts. + * for distribution to the given host. * <b>Note: This class receives ownership of the given collection.</b> * * @return the reference to the file, created by the application package */ - public FileReference sendFileToHosts(String relativePath, Collection<Host> hosts) { - FileReference reference = fileRegistry.addFile(relativePath); - addToFilesToDistribute(reference, hosts); - - return reference; + public FileReference sendFileToHost(String relativePath, Host host) { + return addFileReference(fileRegistry.addFile(relativePath), host); } /** * Adds the given file to the associated application packages' registry of file and marks the file - * for distribution to the given hosts. + * for distribution to the given host. * <b>Note: This class receives ownership of the given collection.</b> * * @return the reference to the file, created by the application package */ - public FileReference sendUriToHosts(String uri, Collection<Host> hosts) { - FileReference reference = fileRegistry.addUri(uri); - if (reference != null) { - addToFilesToDistribute(reference, hosts); - } - - return reference; - } - - /** Same as sendFileToHost(relativePath,Collections.singletonList(host) */ - public FileReference sendFileToHost(String relativePath, Host host) { - return sendFileToHosts(relativePath, Arrays.asList(host)); - } - public FileReference sendUriToHost(String uri, Host host) { - return sendUriToHosts(uri, Arrays.asList(host)); - } - - private void addToFilesToDistribute(FileReference reference, Collection<Host> hosts) { - Set<Host> oldHosts = getHosts(reference); - oldHosts.addAll(hosts); + return addFileReference(fileRegistry.addUri(uri), host); } - private Set<Host> getHosts(FileReference reference) { - return filesToHosts.computeIfAbsent(reference, k -> new HashSet<>()); - } - - public FileDistributor(FileRegistry fileRegistry, List<ConfigServerSpec> configServerSpecs) { - this.fileRegistry = fileRegistry; - this.configServerSpecs = configServerSpecs; + private FileReference addFileReference(FileReference reference, Host host) { + filesToHosts.computeIfAbsent(reference, k -> new HashSet<>()).add(host); + return reference; } /** Returns the files which has been marked for distribution to the given host */ @@ -107,16 +86,15 @@ public class FileDistributor { // should only be called during deploy public void sendDeployedFiles(FileDistribution dbHandler) { String fileSourceHost = fileSourceHost(); - for (Host host : getTargetHosts()) { - if ( ! host.getHostname().equals(fileSourceHost)) { - dbHandler.startDownload(host.getHostname(), ConfigProxy.BASEPORT, filesToSendToHost(host)); - } - } + + getTargetHosts().stream() + .filter(host -> ! host.getHostname().equals(fileSourceHost)) + .forEach(host -> dbHandler.startDownload(host.getHostname(), ConfigProxy.BASEPORT, filesToSendToHost(host))); + // Ask other config servers to download, for redundancy - if (configServerSpecs != null) - configServerSpecs.stream() - .filter(configServerSpec -> !configServerSpec.getHostName().equals(fileSourceHost)) - .forEach(spec -> dbHandler.startDownload(spec.getHostName(), spec.getConfigServerPort(), allFilesToSend())); + configServerSpecs.stream() + .filter(spec -> !spec.getHostName().equals(fileSourceHost)) + .forEach(spec -> dbHandler.startDownload(spec.getHostName(), spec.getConfigServerPort(), allFilesToSend())); } } |