diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-09-17 12:18:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-17 12:18:35 +0200 |
commit | 55f1b1945decd65de208a8fbdbc2a917206022df (patch) | |
tree | 97d77bf72900ef5c8a7519970ac72262a3aaefb0 | |
parent | c48c65becbca835d03ebb75dcbc828d13eb0fe75 (diff) | |
parent | ef0695e16e2e6e407fa5be050dd0169a8b46f4f9 (diff) |
Merge pull request #24105 from vespa-engine/bratseth/send-model-paths
Send model paths
12 files changed, 199 insertions, 121 deletions
diff --git a/config-lib/abi-spec.json b/config-lib/abi-spec.json index 573a8a24e0c..2d3092229ae 100644 --- a/config-lib/abi-spec.json +++ b/config-lib/abi-spec.json @@ -335,20 +335,19 @@ "public" ], "methods": [ - "public void <init>(java.nio.file.Path)", - "public void <init>(java.util.Optional, java.util.Optional, java.util.Optional)", "public java.util.Optional modelId()", "public java.util.Optional url()", "public java.util.Optional path()", - "public com.yahoo.config.ModelReference withModelId(java.util.Optional)", - "public com.yahoo.config.ModelReference withUrl(java.util.Optional)", - "public com.yahoo.config.ModelReference withPath(java.util.Optional)", "public java.nio.file.Path value()", "public boolean equals(java.lang.Object)", "public int hashCode()", "public java.lang.String toString()", - "public static com.yahoo.config.ModelReference valueOf(java.nio.file.Path)", - "public static com.yahoo.config.ModelReference valueOf(java.lang.String)" + "public static com.yahoo.config.ModelReference valueOf(java.lang.String)", + "public static com.yahoo.config.ModelReference unresolved(java.lang.String)", + "public static com.yahoo.config.ModelReference unresolved(com.yahoo.config.UrlReference)", + "public static com.yahoo.config.ModelReference unresolved(com.yahoo.config.FileReference)", + "public static com.yahoo.config.ModelReference unresolved(java.util.Optional, java.util.Optional, java.util.Optional)", + "public static com.yahoo.config.ModelReference resolved(java.nio.file.Path)" ], "fields": [] }, diff --git a/config-lib/src/main/java/com/yahoo/config/ModelReference.java b/config-lib/src/main/java/com/yahoo/config/ModelReference.java index 13bb5737c6f..25caad55b84 100644 --- a/config-lib/src/main/java/com/yahoo/config/ModelReference.java +++ b/config-lib/src/main/java/com/yahoo/config/ModelReference.java @@ -22,57 +22,41 @@ public class ModelReference { // Or: If resolved, this is set private final Path resolved; - public ModelReference(Path resolved) { - this.modelId = Optional.empty(); - this.url = Optional.empty(); - this.path = Optional.empty(); - this.resolved = resolved; - } - - public ModelReference(Optional<String> modelId, - Optional<UrlReference> url, - Optional<FileReference> path) { - if (modelId.isEmpty() && url.isEmpty() && path.isEmpty()) - throw new IllegalArgumentException("A model reference must have either a model id, url or path"); + private ModelReference(Optional<String> modelId, + Optional<UrlReference> url, + Optional<FileReference> path, + Path resolved) { this.modelId = modelId; this.url = url; this.path = path; - this.resolved = null; + this.resolved = resolved; } + /** Returns the id specified for this model, oor null if it is resolved. */ public Optional<String> modelId() { return modelId; } - public Optional<UrlReference> url() { return url; } - public Optional<FileReference> path() { return path; } - public ModelReference withModelId(Optional<String> modelId) { - return new ModelReference(modelId, url, path); - } - - public ModelReference withUrl(Optional<UrlReference> url) { - return new ModelReference(modelId, url, path); - } + /** Returns the url specified for this model, or null if it is resolved. */ + public Optional<UrlReference> url() { return url; } - public ModelReference withPath(Optional<FileReference> path) { - return new ModelReference(modelId, url, path); - } + /** Returns the path specified for this model, oor null if it is resolved. */ + public Optional<FileReference> path() { return path; } - /** Returns the path to the file containing this model, or null if not available. */ - public Path value() { - return resolved; - } + /** Returns the path to the file containing this model, or null if this is unresolved. */ + public Path value() { return resolved; } @Override public boolean equals(Object o) { if ( ! (o instanceof ModelReference other)) return false; - if ( ! this.modelId.equals(other.modelId)) return false; - if ( ! this.url.equals(other.url)) return false; - if ( ! this.path.equals(other.path)) return false; + if ( ! Objects.equals(this.modelId, other.modelId)) return false; + if ( ! Objects.equals(this.url, other.url)) return false; + if ( ! Objects.equals(this.path, other.path)) return false; + if ( ! Objects.equals(this.resolved, other.resolved)) return false; return true; } @Override public int hashCode() { - return Objects.hash(modelId, url, path); + return Objects.hash(modelId, url, path, resolved); } /** Returns this on the format accepted by valueOf */ @@ -84,26 +68,50 @@ public class ModelReference { path.map(v -> v.value()).orElse("\"\""); } - /** Creates a model reference resolved to a Path to the local file. */ - public static ModelReference valueOf(Path path) { - return new ModelReference(path); - } - /** - * Creates a model reference from a three-part string on the form - * <code>modelId url path</code> - * Each of the elements is either a value not containing space, or empty represented by "". + * Creates a model reference which is either a single string with no spaces if resolved, or if unresolved + * a three-part string on the form <code>modelId url path</code>, where + * each of the elements is either a value not containing space, or empty represented by "". */ public static ModelReference valueOf(String s) { String[] parts = s.split(" "); if (parts.length == 1) - return new ModelReference(Path.of(s)); + return resolved(Path.of(s)); else if (parts.length == 3) - return new ModelReference(parts[0].equals("\"\"") ? Optional.empty() : Optional.of(parts[0]), - parts[1].equals("\"\"") ? Optional.empty() : Optional.of(new UrlReference(parts[1])), - parts[2].equals("\"\"") ? Optional.empty() : Optional.of(new FileReference(parts[2]))); + return unresolved(parts[0].equals("\"\"") ? Optional.empty() : Optional.of(parts[0]), + parts[1].equals("\"\"") ? Optional.empty() : Optional.of(new UrlReference(parts[1])), + parts[2].equals("\"\"") ? Optional.empty() : Optional.of(new FileReference(parts[2]))); else - throw new IllegalArgumentException("Unexpected model string '" + s + "'"); + throw new IllegalArgumentException("Unexpected model reference string '" + s + "'"); + } + + /** Creates an unresolved reference from a model id only. */ + public static ModelReference unresolved(String modelId) { + return new ModelReference(Optional.of(modelId), Optional.empty(), Optional.empty(), null); + } + + /** Creates an unresolved reference from an url only. */ + public static ModelReference unresolved(UrlReference url) { + return new ModelReference(Optional.empty(), Optional.of(url), Optional.empty(), null); + } + + /** Creates an unresolved reference from a path only. */ + public static ModelReference unresolved(FileReference path) { + return new ModelReference(Optional.empty(), Optional.empty(), Optional.of(path), null); + } + + /** Creates an unresolved reference. */ + public static ModelReference unresolved(Optional<String> modelId, + Optional<UrlReference> url, + Optional<FileReference> path) { + if (modelId.isEmpty() && url.isEmpty() && path.isEmpty()) + throw new IllegalArgumentException("A model reference must have either a model id, url or path"); + return new ModelReference(modelId, url, path, null); + } + + /** Creates a nresolved reference. */ + public static ModelReference resolved(Path path) { + return new ModelReference(null, null, null, Objects.requireNonNull(path)); } } diff --git a/config-lib/src/test/java/com/yahoo/config/ConfigInstanceBuilderTest.java b/config-lib/src/test/java/com/yahoo/config/ConfigInstanceBuilderTest.java index d1cd7678911..76871aaca42 100644 --- a/config-lib/src/test/java/com/yahoo/config/ConfigInstanceBuilderTest.java +++ b/config-lib/src/test/java/com/yahoo/config/ConfigInstanceBuilderTest.java @@ -169,9 +169,7 @@ public class ConfigInstanceBuilderTest { fileVal("etc"). pathVal(FileReference.mockFileReferenceForUnitTesting(new File("pom.xml"))). urlVal(new UrlReference("http://docs.vespa.ai")). - modelVal(new ModelReference(Optional.empty(), - Optional.empty(), - Optional.of(FileReference.mockFileReferenceForUnitTesting(new File("pom.xml"))))). + modelVal(ModelReference.unresolved(FileReference.mockFileReferenceForUnitTesting(new File("pom.xml")))). boolarr(false). longarr(9223372036854775807L). longarr(-9223372036854775808L). diff --git a/config-lib/src/test/java/com/yahoo/config/ConfigInstanceEqualsTest.java b/config-lib/src/test/java/com/yahoo/config/ConfigInstanceEqualsTest.java index 1a05c08d8f2..db1509fba93 100644 --- a/config-lib/src/test/java/com/yahoo/config/ConfigInstanceEqualsTest.java +++ b/config-lib/src/test/java/com/yahoo/config/ConfigInstanceEqualsTest.java @@ -132,9 +132,9 @@ public class ConfigInstanceEqualsTest { fileVal("etc"). pathVal(FileReference.mockFileReferenceForUnitTesting(new File("pom.xml"))). urlVal(new UrlReference("http://docs.vespa.ai")). - modelVal(new ModelReference(Optional.of("my-model-id"), - Optional.of(new UrlReference("http://docs.vespa.ai")), - Optional.empty())). + modelVal(ModelReference.unresolved(Optional.of("my-model-id"), + Optional.of(new UrlReference("http://docs.vespa.ai")), + Optional.empty())). boolarr(false). longarr(9223372036854775807L). longarr(-9223372036854775808L). @@ -145,9 +145,9 @@ public class ConfigInstanceEqualsTest { refarr(Arrays.asList(":parent:", ":parent", "parent:")). // test collection based setter fileArr("bin"). urlArr(new UrlReference("http://docs.vespa.ai")). - modelArr(new ModelReference(Optional.empty(), - Optional.of(new UrlReference("http://docs.vespa.ai")), - Optional.of(FileReference.mockFileReferenceForUnitTesting(new File("pom.xml"))))). + modelArr(ModelReference.unresolved(Optional.empty(), + Optional.of(new UrlReference("http://docs.vespa.ai")), + Optional.of(FileReference.mockFileReferenceForUnitTesting(new File("pom.xml"))))). basicStruct(new BasicStruct.Builder(). foo("basicFoo"). diff --git a/config-lib/src/test/java/com/yahoo/config/ModelNodeTest.java b/config-lib/src/test/java/com/yahoo/config/ModelNodeTest.java index 696e0722714..328b27bf4c8 100644 --- a/config-lib/src/test/java/com/yahoo/config/ModelNodeTest.java +++ b/config-lib/src/test/java/com/yahoo/config/ModelNodeTest.java @@ -3,6 +3,7 @@ package com.yahoo.config; import org.junit.jupiter.api.Test; +import java.nio.file.Path; import java.util.Optional; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -18,12 +19,19 @@ public class ModelNodeTest { } @Test - void testReference() { - var reference = new ModelReference(Optional.of("myModelId"), - Optional.of(new UrlReference("https://host:my/path")), - Optional.of(new FileReference("foo.txt"))); + void testUnresolvedReference() { + var reference = ModelReference.unresolved(Optional.of("myModelId"), + Optional.of(new UrlReference("https://host:my/path")), + Optional.of(new FileReference("foo.txt"))); assertEquals("myModelId https://host:my/path foo.txt", reference.toString()); assertEquals(reference, ModelReference.valueOf(reference.toString())); } + @Test + void testResolvedReference() { + var reference = ModelReference.resolved(Path.of("dir/resolvedFile.txt")); + assertEquals("dir/resolvedFile.txt", reference.toString()); + assertEquals(reference, ModelReference.valueOf(reference.toString())); + } + } diff --git a/config-model-api/src/main/java/com/yahoo/config/application/api/FileRegistry.java b/config-model-api/src/main/java/com/yahoo/config/application/api/FileRegistry.java index 53633d1b7d4..c2cde72449b 100644 --- a/config-model-api/src/main/java/com/yahoo/config/application/api/FileRegistry.java +++ b/config-model-api/src/main/java/com/yahoo/config/application/api/FileRegistry.java @@ -6,7 +6,6 @@ import com.yahoo.config.FileReference; import java.nio.ByteBuffer; import java.util.List; - /** * @author Tony Vaagenes */ diff --git a/config-model/src/main/java/com/yahoo/schema/DistributableResource.java b/config-model/src/main/java/com/yahoo/schema/DistributableResource.java index 7a8a3963ba4..e7bdb68a03d 100644 --- a/config-model/src/main/java/com/yahoo/schema/DistributableResource.java +++ b/config-model/src/main/java/com/yahoo/schema/DistributableResource.java @@ -67,14 +67,9 @@ public class DistributableResource implements Comparable <DistributableResource> public void register(FileRegistry fileRegistry) { switch (pathType) { - case FILE: - fileReference = fileRegistry.addFile(path); - break; - case URI: - fileReference = fileRegistry.addUri(path); - break; - default: - throw new IllegalArgumentException("Unknown path type " + pathType); + case FILE -> fileReference = fileRegistry.addFile(path); + case URI -> fileReference = fileRegistry.addUri(path); + default -> throw new IllegalArgumentException("Unknown path type " + pathType); } } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomConfigPayloadBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomConfigPayloadBuilder.java index 1631bd228df..ee1771cfbfc 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomConfigPayloadBuilder.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomConfigPayloadBuilder.java @@ -3,6 +3,9 @@ package com.yahoo.vespa.model.builder.xml.dom; import com.yahoo.collections.Tuple2; import com.yahoo.config.ConfigurationRuntimeException; +import com.yahoo.config.FileReference; +import com.yahoo.config.ModelReference; +import com.yahoo.config.UrlReference; import com.yahoo.text.XML; import com.yahoo.vespa.config.ConfigDefinition; import com.yahoo.vespa.config.ConfigDefinitionKey; @@ -11,6 +14,7 @@ import com.yahoo.vespa.config.util.ConfigUtils; import com.yahoo.yolean.Exceptions; import org.w3c.dom.Element; import java.util.List; +import java.util.Optional; import java.util.regex.Pattern; /** @@ -133,19 +137,19 @@ public class DomConfigPayloadBuilder { } else if (element.hasAttribute("model-id") || element.hasAttribute("url") || element.hasAttribute("path")) { // special syntax for "model" fields - String modelString = modelElement("model-id", element); - modelString += " " + modelElement("url", element); - modelString += " " + modelElement("path", element); - payloadBuilder.setField(name, modelString); + var model = ModelReference.unresolved(modelElement("model-id", element), + modelElement("url", element).map(UrlReference::new), + modelElement("path", element).map(FileReference::new)); + payloadBuilder.setField(name, model.toString()); } else { // leaf value: <myValueName>value</myValue> payloadBuilder.setField(name, value); } } - private String modelElement(String attributeName, Element element) { - String value = XML.attribute(attributeName, element).orElse("\"\"").trim(); - if (value.contains(" ")) + private Optional<String> modelElement(String attributeName, Element element) { + Optional<String> value = XML.attribute(attributeName, element); + if (value.isPresent() && value.get().contains(" ")) throw new IllegalArgumentException("The value of " + attributeName + " on " + element.getTagName() + "cannot contain space"); return 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 b9a81592ae4..39759743723 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 @@ -2,6 +2,7 @@ package com.yahoo.vespa.model.utils; import com.yahoo.config.FileReference; +import com.yahoo.config.ModelReference; import com.yahoo.config.application.api.DeployLogger; import com.yahoo.config.application.api.FileRegistry; import com.yahoo.config.model.producer.AbstractConfigProducer; @@ -17,6 +18,7 @@ import java.io.Serializable; import java.util.Collection; import java.util.HashMap; import java.util.Map; +import java.util.Optional; import java.util.logging.Level; /** @@ -40,8 +42,7 @@ public class FileSender implements Serializable { * Sends all user configured files for a producer to all given services. */ public <PRODUCER extends AbstractConfigProducer<?>> void sendUserConfiguredFiles(PRODUCER producer) { - if (services.isEmpty()) - return; + if (services.isEmpty()) return; UserConfigRepo userConfigs = producer.getUserConfigs(); Map<Path, FileReference> sentFiles = new HashMap<>(); @@ -64,22 +65,22 @@ public class FileSender implements Serializable { return; } // Inspect fields at this level - sendEntries(builder, sentFiles, configDefinition.getFileDefs()); - sendEntries(builder, sentFiles, configDefinition.getPathDefs()); + sendEntries(builder, sentFiles, configDefinition.getFileDefs(), false); + sendEntries(builder, sentFiles, configDefinition.getPathDefs(), false); + sendEntries(builder, sentFiles, configDefinition.getModelDefs(), true); // Inspect arrays for (Map.Entry<String, ConfigDefinition.ArrayDef> entry : configDefinition.getArrayDefs().entrySet()) { - if (isFileOrPathArray(entry)) { - ConfigPayloadBuilder.Array array = builder.getArray(entry.getKey()); - sendFileEntries(array.getElements(), sentFiles); - } + if ( ! isAnyFileType(entry.getValue().getTypeSpec().getType())) continue; + ConfigPayloadBuilder.Array array = builder.getArray(entry.getKey()); + sendFileEntries(array.getElements(), sentFiles, "model".equals(entry.getValue().getTypeSpec().getType())); } - // Maps + + // Inspect maps for (Map.Entry<String, ConfigDefinition.LeafMapDef> entry : configDefinition.getLeafMapDefs().entrySet()) { - if (isFileOrPathMap(entry)) { - ConfigPayloadBuilder.MapBuilder map = builder.getMap(entry.getKey()); - sendFileEntries(map.getElements(), sentFiles); - } + if ( ! isAnyFileType(entry.getValue().getTypeSpec().getType())) continue; + ConfigPayloadBuilder.MapBuilder map = builder.getMap(entry.getKey()); + sendFileEntries(map.getElements(), sentFiles, "model".equals(entry.getValue().getTypeSpec().getType())); } // Inspect inner fields @@ -98,45 +99,56 @@ public class FileSender implements Serializable { sendUserConfiguredFiles(element, sentFiles, key); } } - - } - - private static boolean isFileOrPathMap(Map.Entry<String, ConfigDefinition.LeafMapDef> entry) { - String mapType = entry.getValue().getTypeSpec().getType(); - return ("file".equals(mapType) || "path".equals(mapType)); } - private static boolean isFileOrPathArray(Map.Entry<String, ConfigDefinition.ArrayDef> entry) { - String arrayType = entry.getValue().getTypeSpec().getType(); - return ("file".equals(arrayType) || "path".equals(arrayType)); + private static boolean isAnyFileType(String type) { + return "file".equals(type) || "path".equals(type) || "model".equals(type); } private void sendEntries(ConfigPayloadBuilder builder, Map<Path, FileReference> sentFiles, - Map<String, ? extends DefaultValued<String>> entries) { + Map<String, ?> entries, + boolean isModelType) { for (String name : entries.keySet()) { ConfigPayloadBuilder fileEntry = builder.getObject(name); if (fileEntry.getValue() == null) throw new IllegalArgumentException("Unable to send file for field '" + name + "': Invalid config value " + fileEntry.getValue()); - sendFileEntry(fileEntry, sentFiles); + sendFileEntry(fileEntry, sentFiles, isModelType); } } - private void sendFileEntries(Collection<ConfigPayloadBuilder> builders, Map<Path, FileReference> sentFiles) { + private void sendFileEntries(Collection<ConfigPayloadBuilder> builders, Map<Path, FileReference> sentFiles, boolean isModelType) { for (ConfigPayloadBuilder builder : builders) { - sendFileEntry(builder, sentFiles); + sendFileEntry(builder, sentFiles, isModelType); } } - private void sendFileEntry(ConfigPayloadBuilder builder, Map<Path, FileReference> sentFiles) { - Path path = Path.fromString(builder.getValue()); + private void sendFileEntry(ConfigPayloadBuilder builder, Map<Path, FileReference> sentFiles, boolean isModelType) { + Path path; + if (isModelType) { + var modelReference = ModelReference.valueOf(builder.getValue()); + if (modelReference.path().isEmpty()) return; + path = Path.fromString(modelReference.path().get().value()); + } + else { + path = Path.fromString(builder.getValue()); + } + FileReference reference = sentFiles.get(path); if (reference == null) { reference = fileRegistry.addFile(path.getRelative()); sentFiles.put(path, reference); } - builder.setValue(reference.value()); + + if (isModelType) { + var model = ModelReference.valueOf(builder.getValue()); + var modelWithReference = ModelReference.unresolved(model.modelId(), model.url(), Optional.of(reference)); + builder.setValue(modelWithReference.toString()); + } + else { + builder.setValue(reference.value()); + } } } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/utils/FileSenderTest.java b/config-model/src/test/java/com/yahoo/vespa/model/utils/FileSenderTest.java index c7358ff1d7e..e113e53f541 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/utils/FileSenderTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/utils/FileSenderTest.java @@ -3,6 +3,8 @@ package com.yahoo.vespa.model.utils; import com.yahoo.config.FileNode; import com.yahoo.config.FileReference; +import com.yahoo.config.ModelReference; +import com.yahoo.config.UrlReference; import com.yahoo.config.application.api.FileRegistry; import com.yahoo.config.model.application.provider.BaseDeployLogger; import com.yahoo.config.model.producer.AbstractConfigProducer; @@ -22,6 +24,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -106,6 +109,42 @@ public class FileSenderTest { } @Test + void require_that_simple_model_field_with_just_path_is_modified() { + var originalValue = ModelReference.unresolved(new FileReference("myModel.onnx")); + def.addModelDef("modelVal"); + builder.setField("modelVal", originalValue.toString()); + assertFileSent("myModel.onnx", originalValue); + } + + @Test + void require_that_simple_model_field_with_path_and_url_is_modified() { + var originalValue = ModelReference.unresolved(Optional.empty(), + Optional.of(new UrlReference("myUrl")), + Optional.of(new FileReference("myModel.onnx"))); + def.addModelDef("modelVal"); + builder.setField("modelVal", originalValue.toString()); + assertFileSent("myModel.onnx", originalValue); + } + + @Test + void require_that_simple_model_field_with_just_url_is_not_modified() { + var originalValue = ModelReference.unresolved(new UrlReference("myUrl")); + def.addModelDef("modelVal"); + builder.setField("modelVal",originalValue.toString()); + fileSender().sendUserConfiguredFiles(producer); + assertEquals(originalValue, ModelReference.valueOf(builder.getObject("modelVal").getValue())); + } + + private void assertFileSent(String path, ModelReference originalValue) { + fileRegistry.pathToRef.put(path, new FileNode("myModelHash").value()); + fileSender().sendUserConfiguredFiles(producer); + var expected = ModelReference.unresolved(originalValue.modelId(), + originalValue.url(), + Optional.of(new FileReference("myModelHash"))); + assertEquals(expected, ModelReference.valueOf(builder.getObject("modelVal").getValue())); + } + + @Test void require_that_fields_in_inner_arrays_are_modified() { def.innerArrayDef("inner").addFileDef("fileVal"); def.innerArrayDef("inner").addStringDef("stringVal"); @@ -119,6 +158,25 @@ public class FileSenderTest { } @Test + void require_that_paths_and_model_fields_are_modified() { + def.arrayDef("fileArray").setTypeSpec(new ConfigDefinition.TypeSpec("fileArray", "file", null, null, null, null)); + def.arrayDef("pathArray").setTypeSpec(new ConfigDefinition.TypeSpec("pathArray", "path", null, null, null, null)); + def.arrayDef("stringArray").setTypeSpec(new ConfigDefinition.TypeSpec("stringArray", "string", null, null, null, null)); + builder.getArray("fileArray").append("foo.txt"); + builder.getArray("fileArray").append("bar.txt"); + builder.getArray("pathArray").append("path.txt"); + builder.getArray("stringArray").append("foo.txt"); + fileRegistry.pathToRef.put("foo.txt", new FileNode("foohash").value()); + fileRegistry.pathToRef.put("bar.txt", new FileNode("barhash").value()); + fileRegistry.pathToRef.put("path.txt", new FileNode("pathhash").value()); + fileSender().sendUserConfiguredFiles(producer); + assertEquals("foohash", builder.getArray("fileArray").get(0).getValue()); + assertEquals("barhash", builder.getArray("fileArray").get(1).getValue()); + assertEquals("pathhash", builder.getArray("pathArray").get(0).getValue()); + assertEquals("foo.txt", builder.getArray("stringArray").get(0).getValue()); + } + + @Test void require_that_arrays_are_modified() { def.arrayDef("fileArray").setTypeSpec(new ConfigDefinition.TypeSpec("fileArray", "file", null, null, null, null)); def.arrayDef("pathArray").setTypeSpec(new ConfigDefinition.TypeSpec("pathArray", "path", null, null, null, null)); diff --git a/config/src/main/java/com/yahoo/vespa/config/ConfigPayloadApplier.java b/config/src/main/java/com/yahoo/vespa/config/ConfigPayloadApplier.java index 4f078059f46..6beb11cf8fa 100644 --- a/config/src/main/java/com/yahoo/vespa/config/ConfigPayloadApplier.java +++ b/config/src/main/java/com/yahoo/vespa/config/ConfigPayloadApplier.java @@ -249,13 +249,10 @@ public class ConfigPayloadApplier<T extends ConfigInstance.Builder> { private ModelReference resolveModel(String modelStringValue) { var model = ModelReference.valueOf(modelStringValue); - // Resolve any of url and path present, in priority order - if (model.url().isPresent() && canResolveUrls()) { - model = new ModelReference(Path.of(resolveUrl(model.url().get().value()).value())); - } - else if (model.path().isPresent()) { - model = new ModelReference(Path.of(resolvePath(model.path().get().value()).value())); - } + if (model.url().isPresent() && canResolveUrls()) // url has priority + model = ModelReference.resolved(Path.of(resolveUrl(model.url().get().value()).value())); + else if (model.path().isPresent()) + model = ModelReference.resolved(Path.of(resolvePath(model.path().get().value()).value())); return model; } diff --git a/config/src/test/java/com/yahoo/vespa/config/ConfigPayloadApplierTest.java b/config/src/test/java/com/yahoo/vespa/config/ConfigPayloadApplierTest.java index aa517c943de..a982949e2fc 100644 --- a/config/src/test/java/com/yahoo/vespa/config/ConfigPayloadApplierTest.java +++ b/config/src/test/java/com/yahoo/vespa/config/ConfigPayloadApplierTest.java @@ -27,9 +27,9 @@ public class ConfigPayloadApplierTest { var inputConfig = new ResolvedTypesConfig.Builder(); inputConfig.myPath(new FileReference("myPath.txt")); inputConfig.myUrl(new UrlReference("myUrl.txt")); - inputConfig.myModel(new ModelReference(Optional.empty(), - Optional.of(new UrlReference("myUrl.txt")), - Optional.of(new FileReference("myPath.txt")))); + inputConfig.myModel(ModelReference.unresolved(Optional.empty(), + Optional.of(new UrlReference("myUrl.txt")), + Optional.of(new FileReference("myPath.txt")))); applier.applyPayload(ConfigPayload.fromInstance(inputConfig.build())); var config = configBuilder.build(); |