summaryrefslogtreecommitdiffstats
path: root/tenant-cd
diff options
context:
space:
mode:
authorJon Marius Venstad <jvenstad@yahoo-inc.com>2019-04-23 13:18:07 +0200
committerJon Marius Venstad <jvenstad@yahoo-inc.com>2019-06-06 13:03:28 +0200
commit031f63ae546a60048d4e7967811ee4fdf4f49ef6 (patch)
tree6ccf9d699b14b7f82439c4ac3351ca7f67ecab66 /tenant-cd
parent960e67b125c2a8baa36653fec5f500aaaae98e29 (diff)
Trimmed down TestConfig, which depends on config-provisioning
Diffstat (limited to 'tenant-cd')
-rw-r--r--tenant-cd/pom.xml6
-rw-r--r--tenant-cd/src/main/java/com/yahoo/vespa/tenant/cd/TestConfig.java75
2 files changed, 81 insertions, 0 deletions
diff --git a/tenant-cd/pom.xml b/tenant-cd/pom.xml
index 072fdbff869..2fdf5adfb57 100644
--- a/tenant-cd/pom.xml
+++ b/tenant-cd/pom.xml
@@ -32,6 +32,12 @@
</dependency>
<dependency>
+ <groupId>com.yahoo.vespa</groupId>
+ <artifactId>config-provisioning</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
diff --git a/tenant-cd/src/main/java/com/yahoo/vespa/tenant/cd/TestConfig.java b/tenant-cd/src/main/java/com/yahoo/vespa/tenant/cd/TestConfig.java
new file mode 100644
index 00000000000..9edb76cfe35
--- /dev/null
+++ b/tenant-cd/src/main/java/com/yahoo/vespa/tenant/cd/TestConfig.java
@@ -0,0 +1,75 @@
+package com.yahoo.vespa.tenant.cd;
+
+import com.yahoo.config.provision.ApplicationId;
+import com.yahoo.slime.ArrayTraverser;
+import com.yahoo.slime.Inspector;
+import com.yahoo.slime.JsonDecoder;
+import com.yahoo.slime.ObjectTraverser;
+import com.yahoo.config.provision.zone.ZoneId;
+import com.yahoo.slime.Slime;
+
+import java.net.URI;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * The place to obtain environment-dependent configuration for the current test run.
+ *
+ * If the system property 'vespa.test.config' is set, this class attempts to parse config
+ * from a JSON file at that location -- otherwise, attempts to access the config will return null.
+ *
+ * @author jvenstad
+ */
+public class TestConfig {
+
+ private static final TestConfig theConfig = fromFile(Paths.get(System.getProperty("vespa.test.config")));
+
+ private final ApplicationId application;
+ private final ZoneId zone;
+ private final Map<ZoneId, Deployment> deployments;
+
+ private TestConfig(ApplicationId application, ZoneId zone, Map<ZoneId, Deployment> deployments) {
+ this.application = application;
+ this.zone = zone;
+ this.deployments = Map.copyOf(deployments);
+ }
+
+ /** Returns the config for this test, or null if it has not been provided. */
+ public static TestConfig get() { return theConfig; }
+
+ /** Returns the full id of the application to be tested. */
+ public ApplicationId application() { return application; }
+
+ /** Returns the zone of the deployment to test. */
+ public ZoneId zone() { return zone; }
+
+ /** Returns an immutable view of all configured endpoints for each zone of the application to test. */
+ public Map<ZoneId, Deployment> deployments() { return deployments; }
+
+ static TestConfig fromFile(Path path) {
+ if (path == null)
+ return null;
+
+ try {
+ Inspector config = new JsonDecoder().decode(new Slime(), Files.readAllBytes(path)).get();
+ ApplicationId application = ApplicationId.fromSerializedForm(config.field("application").asString());
+ ZoneId zone = ZoneId.from(config.field("zone").asString());
+ Map<ZoneId, Deployment> endpoints = new HashMap<>();
+ config.field("endpoints").traverse((ObjectTraverser) (zoneId, endpointArray) -> {
+ List<URI> uris = new ArrayList<>();
+ endpointArray.traverse((ArrayTraverser) (__, uri) -> uris.add(URI.create(uri.asString())));
+ endpoints.put(ZoneId.from(zoneId), null); // TODO jvenstad
+ });
+ return new TestConfig(application, zone, endpoints);
+ }
+ catch (Exception e) {
+ throw new IllegalArgumentException("Failed reading config from '" + path + "'!", e);
+ }
+ }
+
+}