diff options
author | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2020-06-26 16:27:31 +0200 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2020-06-26 16:27:31 +0200 |
commit | d9da501de962175b6798cef10c1bdbf7d74e827e (patch) | |
tree | d3b847edd091c6adaad5e5f6f56f772325d38f83 /cloud-tenant-cd/src | |
parent | 5060839763d1f7d1210eafc44b33968b99626a42 (diff) |
Move shared tenant-cd-api implementations to new module
Introduce new module tenant-cd-commons. Remove tenant-auth.
Change package name for cloud-tenant-cd to avoid potential package conflict.
Move ApiAuthenticator to hosted-api.
Diffstat (limited to 'cloud-tenant-cd/src')
-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 |
5 files changed, 8 insertions, 111 deletions
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 |