diff options
-rw-r--r-- | cloud-tenant-cd/pom.xml | 13 | ||||
-rw-r--r-- | cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/impl/VespaTestRuntime.java | 48 | ||||
-rw-r--r-- | cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/impl/VespaTestRuntimeProvider.java | 17 | ||||
-rw-r--r-- | cloud-tenant-cd/src/main/resources/configdefinitions/cloud-tenant-cd.def | 9 | ||||
-rw-r--r-- | tenant-cd-api/pom.xml | 7 | ||||
-rw-r--r-- | tenant-cd-api/src/main/java/ai/vespa/hosted/cd/internal/TestRuntimeProvider.java | 15 | ||||
-rw-r--r-- | tenant-cd-api/src/main/java/ai/vespa/hosted/cd/internal/package-info.java (renamed from cloud-tenant-cd/src/main/java/com/yahoo/vespa/hosted/cd/impl/package-info.java) | 2 | ||||
-rw-r--r-- | vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/JunitHandler.java | 15 |
8 files changed, 44 insertions, 82 deletions
diff --git a/cloud-tenant-cd/pom.xml b/cloud-tenant-cd/pom.xml index 03730daceb8..c771e2dd1c3 100644 --- a/cloud-tenant-cd/pom.xml +++ b/cloud-tenant-cd/pom.xml @@ -72,19 +72,6 @@ </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/impl/VespaTestRuntime.java b/cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/impl/VespaTestRuntime.java index d2367d588f6..3a70a1ed531 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/impl/VespaTestRuntime.java @@ -8,26 +8,17 @@ 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 { +public class VespaTestRuntime implements TestRuntime { private final TestConfig config; private final Deployment deploymentToTest; @@ -41,10 +32,8 @@ public class VespaTestRuntime extends AbstractComponent implements TestRuntime { /* * Used when executing tests from using Vespa test framework in container */ - @Inject - public VespaTestRuntime(CloudTenantCdConfig c) { - - this(fromVespaConfig(c)); + public VespaTestRuntime(byte[] config) { + this(fromByteArray(config)); } private VespaTestRuntime(TestConfig config) { this.config = config; @@ -75,6 +64,10 @@ public class VespaTestRuntime extends AbstractComponent implements TestRuntime { } } + private static TestConfig fromByteArray(byte[] config) { + return TestConfig.fromJson(config); + } + private static TestConfig fromController() { ControllerHttpClient controller = new ai.vespa.hosted.auth.ApiAuthenticator().controller(); ApplicationId id = Properties.application(); @@ -83,31 +76,4 @@ public class VespaTestRuntime extends AbstractComponent implements TestRuntime { .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/impl/VespaTestRuntimeProvider.java b/cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/impl/VespaTestRuntimeProvider.java new file mode 100644 index 00000000000..c27e1d4a0c9 --- /dev/null +++ b/cloud-tenant-cd/src/main/java/ai/vespa/hosted/cd/impl/VespaTestRuntimeProvider.java @@ -0,0 +1,17 @@ +// 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.hosted.cd.internal.TestRuntimeProvider; +import com.yahoo.component.AbstractComponent; + +/** + * @author mortent + */ +public class VespaTestRuntimeProvider extends AbstractComponent implements TestRuntimeProvider { + + @Override + public void initialize(byte[] config) { + VespaTestRuntime vespaTestRuntime = new VespaTestRuntime(config); + updateReference(vespaTestRuntime); + } +} 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 deleted file mode 100644 index bac21f386be..00000000000 --- a/cloud-tenant-cd/src/main/resources/configdefinitions/cloud-tenant-cd.def +++ /dev/null @@ -1,9 +0,0 @@ -# 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 diff --git a/tenant-cd-api/pom.xml b/tenant-cd-api/pom.xml index 233788a12a9..b19d42d094f 100644 --- a/tenant-cd-api/pom.xml +++ b/tenant-cd-api/pom.xml @@ -40,13 +40,6 @@ <version>${project.version}</version> <scope>provided</scope> </dependency> - <dependency> - <!-- required to inject component from test implementation --> - <groupId>com.yahoo.vespa</groupId> - <artifactId>component</artifactId> - <version>${project.version}</version> - <scope>provided</scope> - </dependency> <!-- compile --> <dependency> <!-- TODO(bjorncs): share junit version number with test-runner implementation --> diff --git a/tenant-cd-api/src/main/java/ai/vespa/hosted/cd/internal/TestRuntimeProvider.java b/tenant-cd-api/src/main/java/ai/vespa/hosted/cd/internal/TestRuntimeProvider.java index e97fa5faf85..8a12c5de862 100644 --- a/tenant-cd-api/src/main/java/ai/vespa/hosted/cd/internal/TestRuntimeProvider.java +++ b/tenant-cd-api/src/main/java/ai/vespa/hosted/cd/internal/TestRuntimeProvider.java @@ -2,28 +2,23 @@ package ai.vespa.hosted.cd.internal; import ai.vespa.hosted.cd.TestRuntime; -import com.yahoo.component.AbstractComponent; import java.util.concurrent.atomic.AtomicReference; /** * @author mortent */ -public class TestRuntimeProvider extends AbstractComponent { +public interface TestRuntimeProvider { - private static final AtomicReference<TestRuntime> testRuntime = new AtomicReference<>(); + static final AtomicReference<TestRuntime> testRuntime = new AtomicReference<>(); - public TestRuntimeProvider(TestRuntime testRuntime) { + void initialize(byte[] config); + + default void updateReference(TestRuntime testRuntime) { TestRuntimeProvider.testRuntime.set(testRuntime); } public static TestRuntime getTestRuntime() { return testRuntime.get(); } - - @Override - public void deconstruct() { - super.deconstruct(); - testRuntime.set(null); - } } diff --git a/cloud-tenant-cd/src/main/java/com/yahoo/vespa/hosted/cd/impl/package-info.java b/tenant-cd-api/src/main/java/ai/vespa/hosted/cd/internal/package-info.java index b5d6f0450ec..9f073852fc6 100644 --- a/cloud-tenant-cd/src/main/java/com/yahoo/vespa/hosted/cd/impl/package-info.java +++ b/tenant-cd-api/src/main/java/ai/vespa/hosted/cd/internal/package-info.java @@ -4,6 +4,6 @@ * @author mortent */ @ExportPackage -package com.yahoo.vespa.hosted.cd.impl; +package ai.vespa.hosted.cd.internal; import com.yahoo.osgi.annotation.ExportPackage;
\ No newline at end of file diff --git a/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/JunitHandler.java b/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/JunitHandler.java index 5534ea29d13..3db2846da4e 100644 --- a/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/JunitHandler.java +++ b/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/JunitHandler.java @@ -1,15 +1,19 @@ // Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.testrunner; +import ai.vespa.hosted.cd.internal.TestRuntimeProvider; +import com.google.inject.Inject; import com.yahoo.container.handler.metrics.JsonResponse; import com.yahoo.container.jdisc.HttpRequest; import com.yahoo.container.jdisc.HttpResponse; import com.yahoo.container.jdisc.LoggingRequestHandler; import com.yahoo.container.logging.AccessLog; +import com.yahoo.io.IOUtils; import com.yahoo.restapi.ErrorResponse; import com.yahoo.restapi.MessageResponse; import org.osgi.framework.Bundle; +import java.io.IOException; import java.util.List; import java.util.concurrent.Executor; import java.util.function.Function; @@ -20,10 +24,13 @@ import java.util.function.Function; public class JunitHandler extends LoggingRequestHandler { private final JunitRunner junitRunner; + private final TestRuntimeProvider testRuntimeProvider; - public JunitHandler(Executor executor, AccessLog accessLog, JunitRunner junitRunner) { + @Inject + public JunitHandler(Executor executor, AccessLog accessLog, JunitRunner junitRunner, TestRuntimeProvider testRuntimeProvider) { super(executor, accessLog); this.junitRunner = junitRunner; + this.testRuntimeProvider = testRuntimeProvider; } @Override @@ -31,6 +38,12 @@ public class JunitHandler extends LoggingRequestHandler { String mode = property("mode", "help", httpRequest, String::valueOf); TestDescriptor.TestCategory category = property("category", TestDescriptor.TestCategory.systemtest, httpRequest, TestDescriptor.TestCategory::valueOf); + try { + testRuntimeProvider.initialize(IOUtils.readBytes(httpRequest.getData(), 1000 * 1000)); + } catch (IOException e) { + return new ErrorResponse(500, "testruntime-initialization", "Exception reading test config"); + } + if ("help".equalsIgnoreCase(mode)) { return new MessageResponse("Accepted modes: \n help \n list \n execute"); } |