aboutsummaryrefslogtreecommitdiffstats
path: root/config-lib/src/main
diff options
context:
space:
mode:
authorLester Solbakken <lesters@oath.com>2018-12-18 10:37:27 +0100
committerLester Solbakken <lesters@oath.com>2018-12-18 10:37:27 +0100
commit7caa60913e4db267f7d7bdfe0e1de90ec12db13f (patch)
treebbb2e77e81d2823fc7c1048a39a7d38c20edfc44 /config-lib/src/main
parent305d22637387d183be17a0582b1ced76f2b44982 (diff)
Add url config type
Diffstat (limited to 'config-lib/src/main')
-rw-r--r--config-lib/src/main/java/com/yahoo/config/LeafNodeMaps.java10
-rw-r--r--config-lib/src/main/java/com/yahoo/config/LeafNodeVector.java11
-rw-r--r--config-lib/src/main/java/com/yahoo/config/UrlNode.java65
-rwxr-xr-xconfig-lib/src/main/java/com/yahoo/config/UrlReference.java40
4 files changed, 123 insertions, 3 deletions
diff --git a/config-lib/src/main/java/com/yahoo/config/LeafNodeMaps.java b/config-lib/src/main/java/com/yahoo/config/LeafNodeMaps.java
index ae6040babc6..b6132a44e3c 100644
--- a/config-lib/src/main/java/com/yahoo/config/LeafNodeMaps.java
+++ b/config-lib/src/main/java/com/yahoo/config/LeafNodeMaps.java
@@ -1,11 +1,10 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config;
-import java.nio.file.Path;
import java.util.Collections;
-import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
+import java.util.stream.Collectors;
/**
* @author gjoranv
@@ -62,4 +61,11 @@ public class LeafNodeMaps {
return Collections.unmodifiableMap(pathNodeMap);
}
+ public static Map<String, UrlNode> asUrlNodeMap(Map<String, UrlReference> urlReferenceMap) {
+ return Collections.unmodifiableMap(
+ urlReferenceMap.entrySet().stream().collect(
+ Collectors.toMap(Map.Entry::getKey, e -> new UrlNode(e.getValue()))
+ ));
+ }
+
}
diff --git a/config-lib/src/main/java/com/yahoo/config/LeafNodeVector.java b/config-lib/src/main/java/com/yahoo/config/LeafNodeVector.java
index 9bbd9b594f8..259afefdd69 100644
--- a/config-lib/src/main/java/com/yahoo/config/LeafNodeVector.java
+++ b/config-lib/src/main/java/com/yahoo/config/LeafNodeVector.java
@@ -1,6 +1,7 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config;
+import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
@@ -68,7 +69,15 @@ public class LeafNodeVector<REAL, NODE extends LeafNode<REAL>> extends NodeVecto
List<Path> paths = new ArrayList<>();
for (FileReference fileReference : values)
paths.add(Paths.get(fileReference.value()));
-
return new LeafNodeVector<>(paths, new PathNode());
}
+
+ public static LeafNodeVector<File, UrlNode> createUrlNodeVector(Collection<UrlReference> values) {
+ List<File> files = new ArrayList<>();
+ for (UrlReference urlReference : values)
+ files.add(new File(urlReference.value()));
+ return new LeafNodeVector<>(files, new UrlNode());
+ }
+
+
}
diff --git a/config-lib/src/main/java/com/yahoo/config/UrlNode.java b/config-lib/src/main/java/com/yahoo/config/UrlNode.java
new file mode 100644
index 00000000000..0ed70ce0f50
--- /dev/null
+++ b/config-lib/src/main/java/com/yahoo/config/UrlNode.java
@@ -0,0 +1,65 @@
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.config;
+
+import edu.umd.cs.findbugs.annotations.NonNull;
+
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * Represents a 'url' in a {@link ConfigInstance}, which will be downloaded
+ * and made available as a {@link File}. Stored in the config builder as a
+ * {@link UrlReference} to identify fields of this type for special handling
+ * in the ConfigPayloadApplier.
+ *
+ * @author lesters
+ */
+public class UrlNode extends LeafNode<File> {
+
+ private final UrlReference url;
+
+ public UrlNode() {
+ url = null;
+ }
+
+ public UrlNode(UrlReference url) {
+ super(true);
+ this.url = url;
+ this.value = new File(url.value());
+ }
+
+ public File value() {
+ return value;
+ }
+
+ @Override
+ public String toString() {
+ return (value == null) ? "(null)" : '"' + getValue() + '"';
+ }
+
+ @Override
+ public String getValue() {
+ return value.toString();
+ }
+
+ @Override
+ protected boolean doSetValue(@NonNull String value) {
+ throw new UnsupportedOperationException("doSetValue should not be necessary since the library anymore!");
+ }
+
+ public UrlReference getUrlReference() {
+ return url;
+ }
+
+ public static List<UrlReference> toUrlReferences(List<UrlNode> urlNodes) {
+ return urlNodes.stream().map(UrlNode::getUrlReference).collect(Collectors.toList());
+ }
+
+ public static Map<String, UrlReference> toUrlReferenceMap(Map<String, UrlNode> urlNodeMap) {
+ return urlNodeMap.entrySet().stream().collect(
+ Collectors.toMap(Map.Entry::getKey, e -> e.getValue().getUrlReference()));
+ }
+
+}
diff --git a/config-lib/src/main/java/com/yahoo/config/UrlReference.java b/config-lib/src/main/java/com/yahoo/config/UrlReference.java
new file mode 100755
index 00000000000..0ec4fd8f8b8
--- /dev/null
+++ b/config-lib/src/main/java/com/yahoo/config/UrlReference.java
@@ -0,0 +1,40 @@
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.config;
+
+import java.util.Objects;
+
+/**
+ * Similar to {@link FileReference}, holds either a URL or a file path to the
+ * downloaded file depending on state.
+ *
+ * @author lesters
+ */
+public final class UrlReference {
+
+ private final String value;
+
+ public UrlReference(String value) {
+ this.value = Objects.requireNonNull(value);
+ }
+
+ public String value() {
+ return value;
+ }
+
+ @Override
+ public int hashCode() {
+ return value.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ return other instanceof UrlReference &&
+ value.equals(((UrlReference)other).value);
+ }
+
+ @Override
+ public String toString() {
+ return "url '" + value + "'";
+ }
+
+}