diff options
author | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2020-06-30 12:57:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-30 12:57:04 +0200 |
commit | 590d56ee6c92dce0637c252622d224ea61844c9b (patch) | |
tree | 3d424c3e84c0271365327ba4f58b03d7cca4a0ff /cloud-tenant-cd | |
parent | 087c670cadd94e24106276609d525a69db3972db (diff) | |
parent | d9da501de962175b6798cef10c1bdbf7d74e827e (diff) |
Merge pull request #13722 from vespa-engine/bjorncs/tenant-cd-commons
Move shared tenant-cd-api implementations to new module
Diffstat (limited to 'cloud-tenant-cd')
-rw-r--r-- | cloud-tenant-cd/OWNERS | 2 | ||||
-rw-r--r-- | cloud-tenant-cd/pom.xml | 6 | ||||
-rw-r--r-- | cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/cloud/impl/VespaTestRuntime.java (renamed from cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/impl/VespaTestRuntime.java) | 10 | ||||
-rw-r--r-- | cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/cloud/impl/VespaTestRuntimeProvider.java (renamed from cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/impl/VespaTestRuntimeProvider.java) | 2 | ||||
-rw-r--r-- | cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/impl/http/HttpDeployment.java | 37 | ||||
-rw-r--r-- | cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/impl/http/HttpEndpoint.java | 68 | ||||
-rw-r--r-- | cloud-tenant-cd/src/main/resources/META-INF/services/ai.vespa.hosted.cd.TestRuntime | 2 |
7 files changed, 13 insertions, 114 deletions
diff --git a/cloud-tenant-cd/OWNERS b/cloud-tenant-cd/OWNERS new file mode 100644 index 00000000000..ff9741f2060 --- /dev/null +++ b/cloud-tenant-cd/OWNERS @@ -0,0 +1,2 @@ +mortent +bjorncs
\ No newline at end of file diff --git a/cloud-tenant-cd/pom.xml b/cloud-tenant-cd/pom.xml index b4670e6e83f..d7e5a4a9642 100644 --- a/cloud-tenant-cd/pom.xml +++ b/cloud-tenant-cd/pom.xml @@ -53,19 +53,19 @@ <!-- compile scope --> <dependency> <groupId>com.yahoo.vespa</groupId> - <artifactId>tenant-auth</artifactId> + <artifactId>hosted-api</artifactId> <version>${project.version}</version> <scope>compile</scope> </dependency> <dependency> <groupId>com.yahoo.vespa</groupId> - <artifactId>hosted-api</artifactId> + <artifactId>config-provisioning</artifactId> <version>${project.version}</version> <scope>compile</scope> </dependency> <dependency> <groupId>com.yahoo.vespa</groupId> - <artifactId>config-provisioning</artifactId> + <artifactId>tenant-cd-commons</artifactId> <version>${project.version}</version> <scope>compile</scope> </dependency> 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/cloud/impl/VespaTestRuntime.java index 3a70a1ed531..5f6cc252d85 100644 --- 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/cloud/impl/VespaTestRuntime.java @@ -1,13 +1,15 @@ // 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; +package ai.vespa.hosted.cd.cloud.impl; import ai.vespa.cloud.Zone; import ai.vespa.hosted.api.ControllerHttpClient; +import ai.vespa.hosted.api.DefaultApiAuthenticator; +import ai.vespa.hosted.cd.commons.DefaultEndpointAuthenticator; 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 ai.vespa.hosted.cd.commons.HttpDeployment; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.Environment; import com.yahoo.config.provision.zone.ZoneId; @@ -37,7 +39,7 @@ public class VespaTestRuntime implements TestRuntime { } private VespaTestRuntime(TestConfig config) { this.config = config; - this.deploymentToTest = new HttpDeployment(config.deployments().get(config.zone()), new ai.vespa.hosted.auth.EndpointAuthenticator(config.system())); + this.deploymentToTest = new HttpDeployment(config.deployments().get(config.zone()), new DefaultEndpointAuthenticator(config.system())); } @Override @@ -69,7 +71,7 @@ public class VespaTestRuntime implements TestRuntime { } private static TestConfig fromController() { - ControllerHttpClient controller = new ai.vespa.hosted.auth.ApiAuthenticator().controller(); + ControllerHttpClient controller = new DefaultApiAuthenticator().controller(); ApplicationId id = Properties.application(); Environment environment = Properties.environment().orElse(Environment.dev); ZoneId zone = Properties.region().map(region -> ZoneId.from(environment, region)) diff --git a/cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/impl/VespaTestRuntimeProvider.java b/cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/cloud/impl/VespaTestRuntimeProvider.java index c27e1d4a0c9..d90a2d595c7 100644 --- a/cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/impl/VespaTestRuntimeProvider.java +++ b/cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/cloud/impl/VespaTestRuntimeProvider.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.impl; +package ai.vespa.hosted.cd.cloud.impl; import ai.vespa.hosted.cd.internal.TestRuntimeProvider; import com.yahoo.component.AbstractComponent; diff --git a/cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/impl/http/HttpDeployment.java b/cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/impl/http/HttpDeployment.java deleted file mode 100644 index 65210455b85..00000000000 --- a/cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/impl/http/HttpDeployment.java +++ /dev/null @@ -1,37 +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.impl.http; - -import ai.vespa.hosted.api.EndpointAuthenticator; -import ai.vespa.hosted.cd.Deployment; -import ai.vespa.hosted.cd.Endpoint; - -import java.net.URI; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.stream.Collectors; - -/** - * A remote deployment of a Vespa application, reachable over HTTP. Contains {@link HttpEndpoint}s. - * - * @author jonmv - */ -public class HttpDeployment implements Deployment { - - 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) { - this.endpoints = endpoints.entrySet().stream() - .collect(Collectors.toUnmodifiableMap(entry -> entry.getKey(), - entry -> new HttpEndpoint(entry.getValue(), authenticator))); - } - - @Override - public Endpoint endpoint(String id) { - if ( ! endpoints.containsKey(id)) - throw new NoSuchElementException("No cluster with id '" + id + "'"); - - return endpoints.get(id); - } - -} diff --git a/cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/impl/http/HttpEndpoint.java b/cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/impl/http/HttpEndpoint.java deleted file mode 100644 index f48973b7382..00000000000 --- a/cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/impl/http/HttpEndpoint.java +++ /dev/null @@ -1,68 +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.impl.http; - -import ai.vespa.hosted.api.EndpointAuthenticator; -import ai.vespa.hosted.cd.Endpoint; - -import javax.net.ssl.SSLParameters; -import java.io.IOException; -import java.net.URI; -import java.net.http.HttpClient; -import java.net.http.HttpRequest; -import java.net.http.HttpResponse; -import java.time.Duration; -import java.util.Map; -import java.util.stream.Collectors; - -import static java.net.URLEncoder.encode; -import static java.nio.charset.StandardCharsets.UTF_8; -import static java.util.Objects.requireNonNull; - -/** - * A remote endpoint in a {@link HttpDeployment} of a Vespa application, reachable over HTTP. - * - * @author jonmv - */ -public class HttpEndpoint implements Endpoint { - - private final URI endpoint; - private final HttpClient client; - private final EndpointAuthenticator authenticator; - - public HttpEndpoint(URI endpoint, EndpointAuthenticator authenticator) { - this.endpoint = requireNonNull(endpoint); - this.authenticator = requireNonNull(authenticator); - SSLParameters sslParameters = new SSLParameters(); - sslParameters.setProtocols(new String[] {"TLSv1.2" }); - this.client = HttpClient.newBuilder() - .sslContext(authenticator.sslContext()) - .connectTimeout(Duration.ofSeconds(5)) - .version(HttpClient.Version.HTTP_1_1) - .sslParameters(sslParameters) - .build(); - } - - @Override - public URI uri() { - return endpoint; - } - - @Override - public <T> HttpResponse<T> send(HttpRequest.Builder request, HttpResponse.BodyHandler<T> handler) { - try { - return client.send(authenticator.authenticated(request).build(), handler); - } - catch (IOException | InterruptedException e) { - throw new RuntimeException(request.build() + " failed: " + e.getMessage(), e); - } - } - - @Override - public HttpRequest.Builder request(String path, Map<String, String> properties) { - return HttpRequest.newBuilder(endpoint.resolve(path + - properties.entrySet().stream() - .map(entry -> encode(entry.getKey(), UTF_8) + "=" + encode(entry.getValue(), UTF_8)) - .collect(Collectors.joining("&", path.contains("?") ? "&" : "?", "")))); - } - -} 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 35cb2ed7c25..884d7d4b171 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.impl.VespaTestRuntime
\ No newline at end of file +ai.vespa.hosted.cd.cloud.impl.VespaTestRuntime
\ No newline at end of file |