diff options
author | Harald Musum <musum@yahoo-inc.com> | 2018-01-29 07:49:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-29 07:49:55 +0100 |
commit | 36a9d6c30950aafaa235a9a9de8d53283d351914 (patch) | |
tree | 20a6e72bf6fb3513268a71dec22cdc4f552d0e45 /config-model/src/main/java/com/yahoo | |
parent | c73689030686fc239e2854bc77d07027df7c6e81 (diff) | |
parent | 116a1fa10dd3c5f98fc4d6e8cdcf762fe79df05f (diff) |
Merge pull request #4785 from vespa-engine/balder/add-uri-support-to-tensor-constants-3
Balder/add uri support to tensor constants 3
Diffstat (limited to 'config-model/src/main/java/com/yahoo')
6 files changed, 82 insertions, 16 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstant.java b/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstant.java index c65e0fad1c7..a2bdc6834c9 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstant.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstant.java @@ -12,12 +12,20 @@ import java.util.Objects; */ public class RankingConstant { + public enum PathType {FILE, URI}; + /** The search definition-unique name of this constant */ private final String name; private TensorType tensorType = null; - private String fileName = null; + private String path = null; private String fileReference = ""; + public PathType getPathType() { + return pathType; + } + + private PathType pathType = PathType.FILE; + public RankingConstant(String name) { this.name = name; } @@ -25,13 +33,20 @@ public class RankingConstant { public RankingConstant(String name, TensorType type, String fileName) { this(name); this.tensorType = type; - this.fileName = fileName; + this.path = fileName; validate(); } public void setFileName(String fileName) { Objects.requireNonNull(fileName, "Filename cannot be null"); - this.fileName = fileName; + this.path = fileName; + this.pathType = PathType.FILE; + } + + public void setUri(String uri) { + Objects.requireNonNull(uri, "uri cannot be null"); + this.path = uri; + this.pathType = PathType.URI; } /** @@ -43,14 +58,15 @@ public class RankingConstant { public void setType(TensorType tensorType) { this.tensorType = tensorType; } public String getName() { return name; } - public String getFileName() { return fileName; } + public String getFileName() { return path; } + public String getUri() { return path; } public String getFileReference() { return fileReference; } public TensorType getTensorType() { return tensorType; } public String getType() { return tensorType.toString(); } public void validate() { - if (fileName == null || fileName.isEmpty()) - throw new IllegalArgumentException("Ranking constants must have a file."); + if (path == null || path.isEmpty()) + throw new IllegalArgumentException("Ranking constants must have a file or uri."); if (tensorType == null) throw new IllegalArgumentException("Ranking constant '" + name + "' must have a type."); } @@ -58,7 +74,7 @@ public class RankingConstant { public String toString() { StringBuilder b = new StringBuilder(); b.append("constant '").append(name) - .append("' from file '").append(fileName) + .append(pathType == PathType.FILE ? "' from file '" : " from uri ").append(path) .append("' with ref '").append(fileReference) .append("' of type '").append(tensorType) .append("'"); 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/application/validation/RankingConstantsValidator.java b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/RankingConstantsValidator.java index 520ff231921..d022b2cf8ab 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/RankingConstantsValidator.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/RankingConstantsValidator.java @@ -63,15 +63,19 @@ public class RankingConstantsValidator extends Validator { } private void validateRankingConstant(RankingConstant rankingConstant, ApplicationPackage application) throws FileNotFoundException { - String constantFile = rankingConstant.getFileName(); - if (application.getFileReference(Path.fromString("")).getAbsolutePath().endsWith(FilesApplicationPackage.preprocessed) && - constantFile.startsWith(FilesApplicationPackage.preprocessed)) - constantFile = constantFile.substring(FilesApplicationPackage.preprocessed.length()); + // TODO: Handle validation of URI soon too. + if (rankingConstant.getPathType() == RankingConstant.PathType.FILE) { + String constantFile = rankingConstant.getFileName(); + if (application.getFileReference(Path.fromString("")).getAbsolutePath().endsWith(FilesApplicationPackage.preprocessed) && + constantFile.startsWith(FilesApplicationPackage.preprocessed)) { + constantFile = constantFile.substring(FilesApplicationPackage.preprocessed.length()); + } - ApplicationFile tensorApplicationFile = application.getFile(Path.fromString(constantFile)); - new ConstantTensorJsonValidator().validate(constantFile, - rankingConstant.getTensorType(), - tensorApplicationFile.createReader()); + ApplicationFile tensorApplicationFile = application.getFile(Path.fromString(constantFile)); + new ConstantTensorJsonValidator().validate(constantFile, + rankingConstant.getTensorType(), + tensorApplicationFile.createReader()); + } } } 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..e8d6a330358 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,31 @@ 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); + 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); diff --git a/config-model/src/main/java/com/yahoo/vespa/model/search/AbstractSearchCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/search/AbstractSearchCluster.java index 58fc76f1508..9550cd82b22 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/search/AbstractSearchCluster.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/search/AbstractSearchCluster.java @@ -38,7 +38,9 @@ public abstract class AbstractSearchCluster extends AbstractConfigProducer public void prepareToDistributeFiles(List<SearchNode> backends) { for (SearchDefinitionSpec sds : localSDS) { for (RankingConstant constant : sds.getSearchDefinition().getSearch().getRankingConstants().values()) { - FileReference reference = FileSender.sendFileToServices(constant.getFileName(), backends); + FileReference reference = (constant.getPathType() == RankingConstant.PathType.FILE) + ? FileSender.sendFileToServices(constant.getFileName(), backends) + : FileSender.sendUriToServices(constant.getUri(), backends); constant.setFileReference(reference.value()); } } 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. */ |