aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-09-01 15:34:21 +0200
committerJon Bratseth <bratseth@gmail.com>2022-09-01 15:34:21 +0200
commit38bfeeadafabeeef540157e440224b03ba80ed4d (patch)
treebb0a1ea8fd6f9ee4c3289eaf0df821288569649f
parent86a39ab21db4a92b46944709251ccab58ef39370 (diff)
Add test
-rw-r--r--config-lib/abi-spec.json1
-rw-r--r--config-lib/src/main/java/com/yahoo/config/ModelReference.java34
-rw-r--r--config/src/main/java/com/yahoo/vespa/config/ConfigPayloadApplier.java4
-rw-r--r--config/src/test/java/com/yahoo/vespa/config/ConfigPayloadApplierTest.java49
-rw-r--r--config/src/test/resources/configs/def-files/resolved-types.def6
5 files changed, 82 insertions, 12 deletions
diff --git a/config-lib/abi-spec.json b/config-lib/abi-spec.json
index a8bdc756f08..b219e58d99f 100644
--- a/config-lib/abi-spec.json
+++ b/config-lib/abi-spec.json
@@ -335,6 +335,7 @@
"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()",
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 7f7082384af..ba35812db4d 100644
--- a/config-lib/src/main/java/com/yahoo/config/ModelReference.java
+++ b/config-lib/src/main/java/com/yahoo/config/ModelReference.java
@@ -15,11 +15,21 @@ import java.util.Optional;
*/
public class ModelReference {
- // At least one of these are set
+ // Either: If unresolved, at least one of these are set
private final Optional<String> modelId;
private final Optional<UrlReference> url;
private final Optional<FileReference> path;
+ // 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) {
@@ -28,6 +38,7 @@ public class ModelReference {
this.modelId = modelId;
this.url = url;
this.path = path;
+ this.resolved = null;
}
public Optional<String> modelId() { return modelId; }
@@ -48,6 +59,9 @@ public class ModelReference {
/** Returns the path to the file containing this model, or null if not available. */
public Path value() {
+ if (resolved != null)
+ return resolved;
+
if (url.isPresent() && new File(url.get().value()).exists())
return Path.of(url.get().value());
if (path.isPresent())
@@ -92,9 +106,9 @@ public class ModelReference {
return new ModelReference(Optional.empty(), Optional.empty(), Optional.of(new FileReference(path)));
}
- /** Creates a model reference having a path only. */
+ /** Creates a model reference resolved to a Path to the local file. */
public static ModelReference valueOf(Path path) {
- return fromPath(path.toString());
+ return new ModelReference(path);
}
/**
@@ -104,12 +118,14 @@ public class ModelReference {
*/
public static ModelReference valueOf(String s) {
String[] parts = s.split(" ");
- if (parts.length != 3)
- throw new IllegalArgumentException("Expected a config with exactly three space-separated parts, but got '" + s + "'");
- 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])));
-
+ if (parts.length == 1)
+ return new ModelReference(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])));
+ else
+ throw new IllegalArgumentException("Unexpected model string '" + s + "'");
}
}
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 e68e996fc97..259a5ef9e6b 100644
--- a/config/src/main/java/com/yahoo/vespa/config/ConfigPayloadApplier.java
+++ b/config/src/main/java/com/yahoo/vespa/config/ConfigPayloadApplier.java
@@ -10,7 +10,6 @@ import com.yahoo.slime.ArrayTraverser;
import com.yahoo.slime.Inspector;
import com.yahoo.slime.ObjectTraverser;
import com.yahoo.slime.Type;
-import com.yahoo.yolean.Exceptions;
import java.io.File;
import java.lang.reflect.Constructor;
@@ -62,8 +61,7 @@ public class ConfigPayloadApplier<T extends ConfigInstance.Builder> {
try {
handleValue(payload.getSlime().get());
} catch (Exception e) {
- throw new RuntimeException("Not able to create config builder for payload:" + payload.toString() +
- ", " + Exceptions.toMessageString(e), e);
+ throw new RuntimeException("Not able to create config builder for payload '" + payload.toString() + "'", e);
}
}
diff --git a/config/src/test/java/com/yahoo/vespa/config/ConfigPayloadApplierTest.java b/config/src/test/java/com/yahoo/vespa/config/ConfigPayloadApplierTest.java
new file mode 100644
index 00000000000..4d3b6b93b3b
--- /dev/null
+++ b/config/src/test/java/com/yahoo/vespa/config/ConfigPayloadApplierTest.java
@@ -0,0 +1,49 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.config;
+
+import com.yahoo.config.FileReference;
+import com.yahoo.config.ModelReference;
+import com.yahoo.config.ResolvedTypesConfig;
+import com.yahoo.config.UrlReference;
+import org.junit.Test;
+
+import java.io.File;
+import java.nio.file.Path;
+import java.util.Optional;
+
+/**
+ * @author bratseth
+ */
+public class ConfigPayloadApplierTest {
+
+ @Test
+ public void testConfigApplier() {
+ var applier = new ConfigPayloadApplier<>(new ResolvedTypesConfig.Builder(), new MockAcquirer(), new MockDownloader());
+ var config = new ResolvedTypesConfig.Builder();
+ config.myPath(new FileReference("mock/myPath.txt"));
+ config.myUrl(new UrlReference("mock/myUrl.txt"));
+ config.myModel(new ModelReference(Optional.empty(),
+ Optional.of(new UrlReference("mockPath/myPath.txt")),
+ Optional.of(new FileReference("mockUrl/myUrl.txt"))));
+ applier.applyPayload(ConfigPayload.fromInstance(config.build()));
+ }
+
+ private static class MockAcquirer implements ConfigTransformer.PathAcquirer {
+
+ @Override
+ public Path getPath(FileReference fileReference) {
+ return Path.of("mockPath", fileReference.value());
+ }
+
+ }
+
+ private static class MockDownloader extends UrlDownloader {
+
+ @Override
+ public File waitFor(UrlReference urlReference, long timeout) {
+ return new File("mockUrl", urlReference.value());
+ }
+
+ }
+
+}
diff --git a/config/src/test/resources/configs/def-files/resolved-types.def b/config/src/test/resources/configs/def-files/resolved-types.def
new file mode 100644
index 00000000000..184e98d51d9
--- /dev/null
+++ b/config/src/test/resources/configs/def-files/resolved-types.def
@@ -0,0 +1,6 @@
+# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+namespace=config
+
+myPath path
+myUrl url
+myModel model