diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-12-15 14:22:21 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2018-01-25 13:33:55 +0000 |
commit | d2834dc7a53fe629425b53ad95f6d503ca901f31 (patch) | |
tree | 58ff101ceb86b87bc9e7dec68d7339d5a39facb2 /config-model/src/main/java/com | |
parent | f03d9cab494447f079a342124fbd0c0b3541f439 (diff) |
Add option to also send an uri.
Diffstat (limited to 'config-model/src/main/java/com')
3 files changed, 42 insertions, 0 deletions
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 3b75be5167d..65f7bbedc68 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 @@ -508,6 +508,13 @@ public abstract class AbstractService extends AbstractConfigProducer<AbstractCon throw new RuntimeException("File does not exist: '" + relativePath + "'."); } } + public FileReference sendUri(String uri) { + try { + return getRoot().getFileDistributor().sendUriToHost(uri, getHost()); + } catch (PathDoesNotExistException e) { + throw new RuntimeException("Uri does not exist: '" + uri + "'."); + } + } /** * 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 213451da55e..01944aee243 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 @@ -38,11 +38,29 @@ public class FileDistributor { return reference; } + /** + * Adds the given file to the associated application packages' registry of file and marks the file + * for distribution to the given hosts. + * <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); + 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); diff --git a/config-model/src/main/java/com/yahoo/vespa/model/utils/FileSender.java b/config-model/src/main/java/com/yahoo/vespa/model/utils/FileSender.java index 413363d7b0d..8995fcbca99 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/utils/FileSender.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/utils/FileSender.java @@ -20,6 +20,8 @@ import java.util.*; */ public class FileSender implements Serializable { + public enum FileType {FILE, URI}; + /** * Send the given file to all given services. * @@ -34,6 +36,7 @@ public class FileSender implements Serializable { throw new IllegalStateException("No service instances. Probably a standalone cluster setting up <nodes> " + "using 'count' instead of <node> tags."); } + FileReference fileref = null; for (AbstractService service : services) { // The same reference will be returned from each call. @@ -42,6 +45,20 @@ public class FileSender implements Serializable { return fileref; } + public static FileReference sendUriToServices(String uri, Collection<? extends AbstractService> services) { + if (services.isEmpty()) { + throw new IllegalStateException("No service instances. Probably a standalone cluster setting up <nodes> " + + "using 'count' instead of <node> tags."); + } + + FileReference fileref = null; + for (AbstractService service : services) { + // The same reference will be returned from each call. + fileref = service.sendUri(uri); + } + return fileref; + } + /** * Sends all user configured files for a producer to all given services. */ |