diff options
author | Jon Marius Venstad <venstad@gmail.com> | 2019-10-04 15:13:25 +0200 |
---|---|---|
committer | Jon Marius Venstad <venstad@gmail.com> | 2019-10-04 15:13:25 +0200 |
commit | ca8cd24e856820538137357994671817a31e51cc (patch) | |
tree | cfc506390b312044b4303b352b21bc804ce2f14c /hosted-api | |
parent | 381e8d894d471c2b52ad8acbb8fc8fbd9f50f1bd (diff) |
Expose content clusters in TestConfig
Diffstat (limited to 'hosted-api')
4 files changed, 32 insertions, 5 deletions
diff --git a/hosted-api/src/main/java/ai/vespa/hosted/api/Properties.java b/hosted-api/src/main/java/ai/vespa/hosted/api/Properties.java index 61893a30e7e..0ca1b3e5603 100644 --- a/hosted-api/src/main/java/ai/vespa/hosted/api/Properties.java +++ b/hosted-api/src/main/java/ai/vespa/hosted/api/Properties.java @@ -38,8 +38,8 @@ public class Properties { return Paths.get(requireNonBlankProperty("privateKeyFile")); } - public static Path certificateFile() { - return Paths.get(requireNonBlankProperty("certificateFile")); + public static Optional<Path> certificateFile() { + return getNonBlankProperty("certificateFile").map(Paths::get); } /** Returns the system property with the given name if it is set, or empty. */ diff --git a/hosted-api/src/main/java/ai/vespa/hosted/api/TestConfig.java b/hosted-api/src/main/java/ai/vespa/hosted/api/TestConfig.java index c0a18121f43..c1104c649f2 100644 --- a/hosted-api/src/main/java/ai/vespa/hosted/api/TestConfig.java +++ b/hosted-api/src/main/java/ai/vespa/hosted/api/TestConfig.java @@ -3,13 +3,16 @@ package ai.vespa.hosted.api; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.SystemName; import com.yahoo.config.provision.zone.ZoneId; +import com.yahoo.slime.ArrayTraverser; import com.yahoo.slime.Inspector; import com.yahoo.slime.JsonDecoder; import com.yahoo.slime.ObjectTraverser; import com.yahoo.slime.Slime; import java.net.URI; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -26,8 +29,10 @@ public class TestConfig { private final ZoneId zone; private final SystemName system; private final Map<ZoneId, Map<String, URI>> deployments; + private final Map<ZoneId, List<String>> contentClusters; - public TestConfig(ApplicationId application, ZoneId zone, SystemName system, Map<ZoneId, Map<String, URI>> deployments) { + public TestConfig(ApplicationId application, ZoneId zone, SystemName system, Map<ZoneId, Map<String, URI>> deployments, + Map<ZoneId, List<String>> contentClusters) { if ( ! deployments.containsKey(zone)) throw new IllegalArgumentException("Config must contain a deployment for its zone, but only does for " + deployments.keySet()); this.application = requireNonNull(application); @@ -36,6 +41,9 @@ public class TestConfig { this.deployments = deployments.entrySet().stream() .collect(Collectors.toUnmodifiableMap(entry -> entry.getKey(), entry -> Map.copyOf(entry.getValue()))); + this.contentClusters = contentClusters.entrySet().stream() + .collect(Collectors.toUnmodifiableMap(entry -> entry.getKey(), + entry -> List.copyOf(entry.getValue()))); } /** @@ -56,7 +64,13 @@ public class TestConfig { config.field("zoneEndpoints").traverse((ObjectTraverser) (zoneId, clustersObject) -> { deployments.put(ZoneId.from(zoneId), toClusterMap(clustersObject)); }); - return new TestConfig(application, zone, system, deployments); + Map<ZoneId, List<String>> contentClusters = new HashMap<>(); + config.field("clusters").traverse(((ObjectTraverser) (zoneId, clustersArray) -> { + List<String> clusters = new ArrayList<>(); + clustersArray.traverse((ArrayTraverser) (__, cluster) -> clusters.add(cluster.asString())); + contentClusters.put(ZoneId.from(zoneId), clusters); + })); + return new TestConfig(application, zone, system, deployments, contentClusters); } static Map<String, URI> toClusterMap(Inspector clustersObject) { @@ -73,7 +87,8 @@ public class TestConfig { return new TestConfig(ApplicationId.defaultId(), ZoneId.defaultId(), SystemName.defaultSystem(), - Map.of(ZoneId.defaultId(), endpoints)); + Map.of(ZoneId.defaultId(), endpoints), + Map.of()); } /** Returns the full id of the application to test. */ @@ -85,6 +100,9 @@ public class TestConfig { /** Returns an immutable view of deployments, per zone, of the application to test. */ public Map<ZoneId, Map<String, URI>> deployments() { return deployments; } + /** Returns an immutable view of content clusters, per zone, of the application to test. */ + public Map<ZoneId, List<String>> contentClusters() { return contentClusters; } + /** Returns the hosted Vespa system this is run against. */ public SystemName system() { return system; } diff --git a/hosted-api/src/test/java/ai/vespa/hosted/api/TestConfigTest.java b/hosted-api/src/test/java/ai/vespa/hosted/api/TestConfigTest.java index bad838f0579..5ed008cc2ec 100644 --- a/hosted-api/src/test/java/ai/vespa/hosted/api/TestConfigTest.java +++ b/hosted-api/src/test/java/ai/vespa/hosted/api/TestConfigTest.java @@ -9,6 +9,7 @@ import java.io.IOException; import java.net.URI; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.List; import java.util.Map; import static org.junit.Assert.assertEquals; @@ -32,6 +33,9 @@ public class TestConfigTest { ZoneId.from("prod", "aws-us-east-1a"), Map.of("default", URI.create("https://prod.endpoint:443/"))), config.deployments()); + assertEquals(Map.of(ZoneId.from("prod", "aws-us-east-1c"), + List.of("documents")), + config.contentClusters()); } @Test diff --git a/hosted-api/src/test/resources/test-config.json b/hosted-api/src/test/resources/test-config.json index 9d36f9496a0..bd337e1c28a 100644 --- a/hosted-api/src/test/resources/test-config.json +++ b/hosted-api/src/test/resources/test-config.json @@ -9,5 +9,10 @@ "prod.aws-us-east-1a": { "default": "https://prod.endpoint:443/" } + }, + "clusters": { + "prod.aws-us-east-1c": [ + "documents" + ] } } |