diff options
-rw-r--r-- | pom.xml | 2 | ||||
-rw-r--r-- | tenant-base/pom.xml | 6 | ||||
-rw-r--r-- | tenant-cd-impl/pom.xml | 56 | ||||
-rw-r--r-- | tenant-cd-impl/src/main/java/ai/vespa/hosted/cd/VespaTestRuntime.java | 62 | ||||
-rw-r--r-- | tenant-cd-impl/src/main/java/ai/vespa/hosted/cd/http/HttpDeployment.java (renamed from tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpDeployment.java) | 2 | ||||
-rw-r--r-- | tenant-cd-impl/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java (renamed from tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java) | 2 | ||||
-rw-r--r-- | tenant-cd-impl/src/main/resources/META-INF/services/ai.vespa.hosted.cd.TestRuntime | 2 | ||||
-rw-r--r-- | tenant-cd/pom.xml | 30 | ||||
-rw-r--r-- | tenant-cd/src/main/java/ai/vespa/hosted/cd/Endpoint.java | 9 | ||||
-rw-r--r-- | tenant-cd/src/main/java/ai/vespa/hosted/cd/TestRuntime.java | 80 |
10 files changed, 138 insertions, 113 deletions
@@ -83,6 +83,7 @@ <module>hosted-api</module> <module>hosted-zone-api</module> <module>http-utils</module> + <module>hosted-api</module> <module>indexinglanguage</module> <module>jaxrs_client_utils</module> <module>jaxrs_utils</module> @@ -126,6 +127,7 @@ <module>tenant-auth</module> <module>tenant-base</module> <module>tenant-cd</module> + <module>tenant-cd-impl</module> <module>testutil</module> <module>vdslib</module> <module>vespaclient-core</module> diff --git a/tenant-base/pom.xml b/tenant-base/pom.xml index a3fac22a93d..651432a0b63 100644 --- a/tenant-base/pom.xml +++ b/tenant-base/pom.xml @@ -111,6 +111,12 @@ </exclusion> </exclusions> </dependency> + <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>tenant-cd-impl</artifactId> + <version>${test-framework.version}</version> + <scope>test</scope> + </dependency> </dependencies> <profiles> diff --git a/tenant-cd-impl/pom.xml b/tenant-cd-impl/pom.xml new file mode 100644 index 00000000000..1a19213a0a9 --- /dev/null +++ b/tenant-cd-impl/pom.xml @@ -0,0 +1,56 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <artifactId>tenant-cd-impl</artifactId> + <name>Hosted Vespa tenant CD implementation</name> + <description>Test library implementation for hosted Vespa applications.</description> + <url>https://github.com/vespa-engine</url> + <packaging>jar</packaging> + + <parent> + <groupId>com.yahoo.vespa</groupId> + <artifactId>parent</artifactId> + <version>7-SNAPSHOT</version> + <relativePath>../parent</relativePath> + </parent> + + <dependencies> + <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>tenant-cd</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>security-utils</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>vespajlib</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>config-provisioning</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>tenant-auth</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>hosted-api</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> +</project>
\ No newline at end of file diff --git a/tenant-cd-impl/src/main/java/ai/vespa/hosted/cd/VespaTestRuntime.java b/tenant-cd-impl/src/main/java/ai/vespa/hosted/cd/VespaTestRuntime.java new file mode 100644 index 00000000000..f77716064e5 --- /dev/null +++ b/tenant-cd-impl/src/main/java/ai/vespa/hosted/cd/VespaTestRuntime.java @@ -0,0 +1,62 @@ +// 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.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())); + } + +// In use ? +// /** Returns a copy of this runtime, with the given endpoint authenticator. */ +// public TestRuntime with(EndpointAuthenticator authenticator) { +// return new TestRuntime(config, authenticator); +// } + + /** Returns the full id of the application this is testing. */ + public ApplicationId application() { return config.application(); } + + /** Returns the zone of the deployment this is testing. */ + public ZoneId zone() { return config.zone(); } + + /** 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/tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpDeployment.java b/tenant-cd-impl/src/main/java/ai/vespa/hosted/cd/http/HttpDeployment.java index e17589c325d..80d5416ab34 100644 --- a/tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpDeployment.java +++ b/tenant-cd-impl/src/main/java/ai/vespa/hosted/cd/http/HttpDeployment.java @@ -1,4 +1,4 @@ -// Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// 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; import ai.vespa.hosted.api.EndpointAuthenticator; diff --git a/tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java b/tenant-cd-impl/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java index 74eb765dd0b..a803fc3e0e2 100644 --- a/tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java +++ b/tenant-cd-impl/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java @@ -1,4 +1,4 @@ -// Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// 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; import ai.vespa.hosted.api.EndpointAuthenticator; diff --git a/tenant-cd-impl/src/main/resources/META-INF/services/ai.vespa.hosted.cd.TestRuntime b/tenant-cd-impl/src/main/resources/META-INF/services/ai.vespa.hosted.cd.TestRuntime new file mode 100644 index 00000000000..695fe363e4e --- /dev/null +++ b/tenant-cd-impl/src/main/resources/META-INF/services/ai.vespa.hosted.cd.TestRuntime @@ -0,0 +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 diff --git a/tenant-cd/pom.xml b/tenant-cd/pom.xml index 829b1de457b..0c63a17dcc0 100644 --- a/tenant-cd/pom.xml +++ b/tenant-cd/pom.xml @@ -21,36 +21,6 @@ <dependencies> <dependency> - <groupId>com.yahoo.vespa</groupId> - <artifactId>security-utils</artifactId> - <version>${project.version}</version> - </dependency> - - <dependency> - <groupId>com.yahoo.vespa</groupId> - <artifactId>vespajlib</artifactId> - <version>${project.version}</version> - </dependency> - - <dependency> - <groupId>com.yahoo.vespa</groupId> - <artifactId>config-provisioning</artifactId> - <version>${project.version}</version> - </dependency> - - <dependency> - <groupId>com.yahoo.vespa</groupId> - <artifactId>tenant-auth</artifactId> - <version>${project.version}</version> - </dependency> - - <dependency> - <groupId>com.yahoo.vespa</groupId> - <artifactId>hosted-api</artifactId> - <version>${project.version}</version> - </dependency> - - <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> </dependency> diff --git a/tenant-cd/src/main/java/ai/vespa/hosted/cd/Endpoint.java b/tenant-cd/src/main/java/ai/vespa/hosted/cd/Endpoint.java index bd6f30767f2..afc6aa1b519 100644 --- a/tenant-cd/src/main/java/ai/vespa/hosted/cd/Endpoint.java +++ b/tenant-cd/src/main/java/ai/vespa/hosted/cd/Endpoint.java @@ -1,19 +1,12 @@ // Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package ai.vespa.hosted.cd; -import ai.vespa.hosted.api.EndpointAuthenticator; - import java.net.URI; -import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.Map; -import java.util.stream.Collectors; - -import static java.net.URLEncoder.encode; -import static java.nio.charset.StandardCharsets.UTF_8; /** * An endpoint in a Vespa application {@link Deployment}, which allows document retrieval. @@ -25,7 +18,7 @@ public interface Endpoint { /** Returns the URI of the endpoint, with scheme, host and port. */ URI uri(); - /** Sends the given request with required authentication. See {@link EndpointAuthenticator#authenticated} and {@link HttpClient#send}. */ + /** Sends the given request with required authentication. */ <T> HttpResponse<T> send(HttpRequest.Builder request, HttpResponse.BodyHandler<T> handler); /** Sends the given request with required authentication. */ diff --git a/tenant-cd/src/main/java/ai/vespa/hosted/cd/TestRuntime.java b/tenant-cd/src/main/java/ai/vespa/hosted/cd/TestRuntime.java index c479bab6e13..feea05b7064 100644 --- a/tenant-cd/src/main/java/ai/vespa/hosted/cd/TestRuntime.java +++ b/tenant-cd/src/main/java/ai/vespa/hosted/cd/TestRuntime.java @@ -1,85 +1,19 @@ // Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package ai.vespa.hosted.cd; -import ai.vespa.hosted.api.ControllerHttpClient; -import ai.vespa.hosted.api.EndpointAuthenticator; -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; +import java.util.ServiceLoader; /** * The place to obtain environment-dependent configuration for test of a Vespa deployment. * * @author jvenstad + * @author mortent */ -public class TestRuntime { - - private static TestRuntime theRuntime; - - private final TestConfig config; - private final Deployment deploymentToTest; - - private TestRuntime(TestConfig config, EndpointAuthenticator authenticator) { - this.config = config; - this.deploymentToTest = new HttpDeployment(config.deployments().get(config.zone()), authenticator); - } - - /** - * Returns the config and authenticator to use when running integration tests. - * - * If the system property {@code "vespa.test.config"} is set (to a file path), a file at that location - * is attempted read, and config parsed from it. - * Otherwise, config is fetched over HTTP from the hosted Vespa API, assuming the deployment indicated - * by the optional {@code "environment"} and {@code "region"} system properties exists. - * When environment is not specified, it defaults to {@link Environment#dev}, - * while region must be set unless the environment is {@link Environment#dev} or {@link Environment#perf}. - */ - public static synchronized TestRuntime get() { - if (theRuntime == null) { - String configPath = System.getProperty("vespa.test.config"); - TestConfig config = configPath != null ? fromFile(configPath) : fromController(); - theRuntime = new TestRuntime(config, - new ai.vespa.hosted.auth.EndpointAuthenticator(config.system())); - } - return theRuntime; - } - - /** Returns a copy of this runtime, with the given endpoint authenticator. */ - public TestRuntime with(EndpointAuthenticator authenticator) { - return new TestRuntime(config, authenticator); - } - - /** Returns the full id of the application this is testing. */ - public ApplicationId application() { return config.application(); } - - /** Returns the zone of the deployment this is testing. */ - public ZoneId zone() { return config.zone(); } - - /** Returns the deployment this is testing. */ - 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); +public interface TestRuntime { + static TestRuntime get() { + ServiceLoader<TestRuntime> serviceLoader = ServiceLoader.load(TestRuntime.class); + return serviceLoader.findFirst().orElseThrow(() -> new RuntimeException("No TestRuntime implementation found")); } + Deployment deploymentToTest(); } |