diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-08-17 08:36:42 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-08-17 08:36:42 +0200 |
commit | a35d40e01254be402972eecc28bfb43fc2081f20 (patch) | |
tree | 2b72cd003dd28ba68be2f10efbd595ee2895beae /config-model/src/main/java/com/yahoo/searchdefinition | |
parent | ecf3f1cfbd977e924e7152e72b46bf45054300be (diff) |
Do registration of references early and only use fileReferences when sending.
Diffstat (limited to 'config-model/src/main/java/com/yahoo/searchdefinition')
4 files changed, 23 insertions, 14 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/DistributableResource.java b/config-model/src/main/java/com/yahoo/searchdefinition/DistributableResource.java index 4793caad308..e31d90c2800 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/DistributableResource.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/DistributableResource.java @@ -1,6 +1,7 @@ package com.yahoo.searchdefinition; import com.yahoo.config.FileReference; +import com.yahoo.config.application.api.FileRegistry; import com.yahoo.path.Path; import com.yahoo.vespa.model.AbstractService; import com.yahoo.vespa.model.utils.FileSender; @@ -16,7 +17,7 @@ public class DistributableResource { private final String name; private final ByteBuffer blob; private String path; - private String fileReference = ""; + private FileReference fileReference = new FileReference(""); private PathType pathType = PathType.FILE; public PathType getPathType() { @@ -54,18 +55,7 @@ public class DistributableResource { /** Initiate sending of this constant to some services over file distribution */ public void sendTo(Collection<? extends AbstractService> services) { - fileReference = sendToServices(services).value(); - } - private FileReference sendToServices(Collection<? extends AbstractService> services) { - switch (pathType) { - case FILE: - return FileSender.sendFileToServices(path, services); - case URI: - return FileSender.sendUriToServices(path, services); - case BLOB: - return FileSender.sendBlobToServices(blob, services); - } - throw new IllegalArgumentException("Unknown path type " + pathType); + FileSender.send(fileReference, services); } public String getName() { return name; } @@ -73,7 +63,7 @@ public class DistributableResource { public String getFileName() { return path; } public Path getFilePath() { return Path.fromString(path); } public String getUri() { return path; } - public String getFileReference() { return fileReference; } + public String getFileReference() { return fileReference.value(); } public void validate() { switch (pathType) { @@ -88,6 +78,22 @@ public class DistributableResource { } } + void register(FileRegistry fileRegistry) { + switch (pathType) { + case FILE: + fileReference = fileRegistry.addFile(path); + break; + case URI: + fileReference = fileRegistry.addUri(path); + break; + case BLOB: + fileReference = fileRegistry.addBlob(blob); + break; + default: + throw new IllegalArgumentException("Unknown path type " + pathType); + } + } + public String toString() { StringBuilder b = new StringBuilder(); b.append("resource '").append(name).append(" of type '").append(pathType) diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/LargeRankExpressions.java b/config-model/src/main/java/com/yahoo/searchdefinition/LargeRankExpressions.java index 518221aac96..9d8e8b90ceb 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/LargeRankExpressions.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/LargeRankExpressions.java @@ -18,6 +18,7 @@ public class LargeRankExpressions { public void add(RankExpressionBody expression) { expression.validate(); + expression.register(fileRegistry); String name = expression.getName(); if (expressions.containsKey(name)) { throw new IllegalArgumentException("Rank expression '" + name + diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/OnnxModels.java b/config-model/src/main/java/com/yahoo/searchdefinition/OnnxModels.java index 96ee8c0c2f4..cb61b8c9cec 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/OnnxModels.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/OnnxModels.java @@ -24,6 +24,7 @@ public class OnnxModels { } public void add(OnnxModel model) { model.validate(); + model.register(fileRegistry); String name = model.getName(); models.put(name, model); } diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstants.java b/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstants.java index a61e1ae3efb..8ccc0ef429e 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstants.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstants.java @@ -26,6 +26,7 @@ public class RankingConstants { public void add(RankingConstant constant) { constant.validate(); + constant.register(fileRegistry); String name = constant.getName(); if (constants.containsKey(name)) throw new IllegalArgumentException("Ranking constant '" + name + "' defined twice"); |