diff options
author | Morten Tokle <mortent@verizonmedia.com> | 2020-06-22 08:55:36 +0200 |
---|---|---|
committer | Morten Tokle <mortent@verizonmedia.com> | 2020-06-22 08:55:36 +0200 |
commit | e2dace4bc4f72e86a671664cb1b32eea48361cfb (patch) | |
tree | 2aadf30b9343cdba51646248ad5588f4f22d8bbc /cloud-tenant-cd | |
parent | 3a66636ae7790b334467898ab31badf522f70a1e (diff) |
Execute Junit tests in container
Diffstat (limited to 'cloud-tenant-cd')
-rw-r--r-- | cloud-tenant-cd/pom.xml | 19 | ||||
-rw-r--r-- | cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/VespaTestRuntime.java | 57 | ||||
-rw-r--r-- | cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/impl/VespaTestRuntime.java | 113 | ||||
-rw-r--r-- | cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/impl/http/HttpDeployment.java (renamed from cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpDeployment.java) | 4 | ||||
-rw-r--r-- | cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/impl/http/HttpEndpoint.java (renamed from cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java) | 2 | ||||
-rw-r--r-- | cloud-tenant-cd/src/main/java/com/yahoo/vespa/hosted/cd/impl/package-info.java | 9 | ||||
-rw-r--r-- | cloud-tenant-cd/src/main/resources/META-INF/services/ai.vespa.hosted.cd.TestRuntime | 2 | ||||
-rw-r--r-- | cloud-tenant-cd/src/main/resources/configdefinitions/cloud-tenant-cd.def | 9 |
8 files changed, 154 insertions, 61 deletions
diff --git a/cloud-tenant-cd/pom.xml b/cloud-tenant-cd/pom.xml index ba4b7d02020..03730daceb8 100644 --- a/cloud-tenant-cd/pom.xml +++ b/cloud-tenant-cd/pom.xml @@ -43,6 +43,12 @@ <version>${project.version}</version> <scope>provided</scope> </dependency> + <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>container-dev</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> <!-- compile scope --> <dependency> @@ -66,6 +72,19 @@ </dependencies> <build> + <pluginManagement> + <plugins> + <plugin> + <!-- TODO: Make config class plugin work with other packageprefix. Below does not work--> + <groupId>com.yahoo.vespa</groupId> + <artifactId>config-class-plugin</artifactId> + <version>${project.version}</version> + <configuration> + <packagePrefix>ai.vespa</packagePrefix> + </configuration> + </plugin> + </plugins> + </pluginManagement> <plugins> <plugin> <groupId>com.yahoo.vespa</groupId> diff --git a/cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/VespaTestRuntime.java b/cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/VespaTestRuntime.java deleted file mode 100644 index 75aaaec78ba..00000000000 --- a/cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/VespaTestRuntime.java +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package ai.vespa.hosted.cd; - -import ai.vespa.cloud.Zone; -import ai.vespa.hosted.api.ControllerHttpClient; -import ai.vespa.hosted.api.Properties; -import ai.vespa.hosted.api.TestConfig; -import ai.vespa.hosted.cd.http.HttpDeployment; -import com.yahoo.config.provision.ApplicationId; -import com.yahoo.config.provision.Environment; -import com.yahoo.config.provision.zone.ZoneId; - -import java.nio.file.Files; -import java.nio.file.Paths; - -/** - * @author mortent - */ -public class VespaTestRuntime implements TestRuntime { - private final TestConfig config; - private final Deployment deploymentToTest; - - public VespaTestRuntime() { - String configPath = System.getProperty("vespa.test.config"); - TestConfig config = configPath != null ? fromFile(configPath) : fromController(); - this.config = config; - this.deploymentToTest = new HttpDeployment(config.deployments().get(config.zone()), new ai.vespa.hosted.auth.EndpointAuthenticator(config.system())); - } - - @Override - public Zone zone() { - return new Zone( - ai.vespa.cloud.Environment.valueOf(config.zone().environment().name()), - config.zone().region().value()); } - - /** Returns the deployment this is testing. */ - @Override - public Deployment deploymentToTest() { return deploymentToTest; } - - private static TestConfig fromFile(String path) { - try { - return TestConfig.fromJson(Files.readAllBytes(Paths.get(path))); - } - catch (Exception e) { - throw new IllegalArgumentException("Failed reading config from '" + path + "'!", e); - } - } - - private static TestConfig fromController() { - ControllerHttpClient controller = new ai.vespa.hosted.auth.ApiAuthenticator().controller(); - ApplicationId id = Properties.application(); - Environment environment = Properties.environment().orElse(Environment.dev); - ZoneId zone = Properties.region().map(region -> ZoneId.from(environment, region)) - .orElseGet(() -> controller.defaultZone(environment)); - return controller.testConfig(id, zone); - } -} diff --git a/cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/impl/VespaTestRuntime.java b/cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/impl/VespaTestRuntime.java new file mode 100644 index 00000000000..d2367d588f6 --- /dev/null +++ b/cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/impl/VespaTestRuntime.java @@ -0,0 +1,113 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package ai.vespa.hosted.cd.impl; + +import ai.vespa.cloud.Zone; +import ai.vespa.hosted.api.ControllerHttpClient; +import ai.vespa.hosted.api.Properties; +import ai.vespa.hosted.api.TestConfig; +import ai.vespa.hosted.cd.Deployment; +import ai.vespa.hosted.cd.TestRuntime; +import ai.vespa.hosted.cd.impl.http.HttpDeployment; +import com.google.inject.Inject; +import com.yahoo.component.AbstractComponent; +import com.yahoo.config.provision.ApplicationId; +import com.yahoo.config.provision.Environment; +import com.yahoo.config.provision.SystemName; +import com.yahoo.config.provision.zone.ZoneId; +import com.yahoo.vespa.hosted.cd.impl.CloudTenantCdConfig; + +import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * @author mortent + */ +public class VespaTestRuntime extends AbstractComponent implements TestRuntime { + private final TestConfig config; + private final Deployment deploymentToTest; + + /* + * Used when executing tests locally + */ + public VespaTestRuntime() { + this(configFromPropertyOrController()); + } + + /* + * Used when executing tests from using Vespa test framework in container + */ + @Inject + public VespaTestRuntime(CloudTenantCdConfig c) { + + this(fromVespaConfig(c)); + } + private VespaTestRuntime(TestConfig config) { + this.config = config; + this.deploymentToTest = new HttpDeployment(config.deployments().get(config.zone()), new ai.vespa.hosted.auth.EndpointAuthenticator(config.system())); + } + + @Override + public Zone zone() { + return new Zone( + ai.vespa.cloud.Environment.valueOf(config.zone().environment().name()), + config.zone().region().value()); } + + /** Returns the deployment this is testing. */ + @Override + public Deployment deploymentToTest() { return deploymentToTest; } + + private static TestConfig configFromPropertyOrController() { + String configPath = System.getProperty("vespa.test.config"); + return configPath != null ? fromFile(configPath) : fromController(); + } + + private static TestConfig fromFile(String path) { + try { + return TestConfig.fromJson(Files.readAllBytes(Paths.get(path))); + } + catch (Exception e) { + throw new IllegalArgumentException("Failed reading config from '" + path + "'!", e); + } + } + + private static TestConfig fromController() { + ControllerHttpClient controller = new ai.vespa.hosted.auth.ApiAuthenticator().controller(); + ApplicationId id = Properties.application(); + Environment environment = Properties.environment().orElse(Environment.dev); + ZoneId zone = Properties.region().map(region -> ZoneId.from(environment, region)) + .orElseGet(() -> controller.defaultZone(environment)); + return controller.testConfig(id, zone); + } + + private static TestConfig fromVespaConfig(CloudTenantCdConfig config) { + Map<ZoneId, Map<String, URI>> deployments = new HashMap<>(); + Map<ZoneId, List<String>> contentClusters = new HashMap<>(); + for (Map.Entry<String, CloudTenantCdConfig.Zones> entry : config.zones().entrySet()) { + ZoneId zoneId = ZoneId.from(entry.getKey()); + + Map<String, URI> zoneDeployments = entry.getValue().deployments().entrySet().stream() + .collect(Collectors.toMap(Map.Entry::getKey, e -> URI.create(e.getValue()))); + + deployments.put(zoneId, zoneDeployments); + + contentClusters.put(zoneId, entry.getValue().contentClusters()); + } + return new TestConfig( + ApplicationId.fromFullString(config.application()), + ZoneId.from(config.zone()), + SystemName.from(config.systemName()), + config.isCi(), + deployments, + contentClusters); + } + + @Override + public void deconstruct() { + super.deconstruct(); + } +} diff --git a/cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpDeployment.java b/cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/impl/http/HttpDeployment.java index 80d5416ab34..65210455b85 100644 --- a/cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpDeployment.java +++ b/cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/impl/http/HttpDeployment.java @@ -1,5 +1,5 @@ // Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package ai.vespa.hosted.cd.http; +package ai.vespa.hosted.cd.impl.http; import ai.vespa.hosted.api.EndpointAuthenticator; import ai.vespa.hosted.cd.Deployment; @@ -17,7 +17,7 @@ import java.util.stream.Collectors; */ public class HttpDeployment implements Deployment { - private final Map<String, HttpEndpoint> endpoints; + private final Map<String, Endpoint> endpoints; /** Creates a representation of the given deployment endpoints, using the authenticator for data plane access. */ public HttpDeployment(Map<String, URI> endpoints, EndpointAuthenticator authenticator) { diff --git a/cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java b/cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/impl/http/HttpEndpoint.java index a803fc3e0e2..f48973b7382 100644 --- a/cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java +++ b/cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/impl/http/HttpEndpoint.java @@ -1,5 +1,5 @@ // Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package ai.vespa.hosted.cd.http; +package ai.vespa.hosted.cd.impl.http; import ai.vespa.hosted.api.EndpointAuthenticator; import ai.vespa.hosted.cd.Endpoint; diff --git a/cloud-tenant-cd/src/main/java/com/yahoo/vespa/hosted/cd/impl/package-info.java b/cloud-tenant-cd/src/main/java/com/yahoo/vespa/hosted/cd/impl/package-info.java new file mode 100644 index 00000000000..b5d6f0450ec --- /dev/null +++ b/cloud-tenant-cd/src/main/java/com/yahoo/vespa/hosted/cd/impl/package-info.java @@ -0,0 +1,9 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +/** + * @author mortent + */ +@ExportPackage +package com.yahoo.vespa.hosted.cd.impl; + +import com.yahoo.osgi.annotation.ExportPackage;
\ No newline at end of file diff --git a/cloud-tenant-cd/src/main/resources/META-INF/services/ai.vespa.hosted.cd.TestRuntime b/cloud-tenant-cd/src/main/resources/META-INF/services/ai.vespa.hosted.cd.TestRuntime index 695fe363e4e..35cb2ed7c25 100644 --- a/cloud-tenant-cd/src/main/resources/META-INF/services/ai.vespa.hosted.cd.TestRuntime +++ b/cloud-tenant-cd/src/main/resources/META-INF/services/ai.vespa.hosted.cd.TestRuntime @@ -1,2 +1,2 @@ # Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -ai.vespa.hosted.cd.VespaTestRuntime
\ No newline at end of file +ai.vespa.hosted.cd.impl.VespaTestRuntime
\ No newline at end of file diff --git a/cloud-tenant-cd/src/main/resources/configdefinitions/cloud-tenant-cd.def b/cloud-tenant-cd/src/main/resources/configdefinitions/cloud-tenant-cd.def new file mode 100644 index 00000000000..bac21f386be --- /dev/null +++ b/cloud-tenant-cd/src/main/resources/configdefinitions/cloud-tenant-cd.def @@ -0,0 +1,9 @@ +# Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +namespace=vespa.hosted.cd.impl + +application string +zone string +systemName string +isCi bool +zones{}.deployments{} string +zones{}.contentClusters[] string |