summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunner.java31
-rw-r--r--controller-server/src/test/resources/test_runner_services.xml-cd-legacy2
-rw-r--r--controller-server/src/test/resources/test_runner_services.xml-cd-osgi8
-rw-r--r--vespa-testrunner-components/src/main/java/com/yahoo/vespa/hosted/testrunner/TestRunnerHandler.java127
-rw-r--r--vespa-testrunner-components/src/test/java/com/yahoo/vespa/hosted/testrunner/TestRunnerHandlerTest.java63
5 files changed, 18 insertions, 213 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunner.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunner.java
index 577dab69279..ddf89e2f376 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunner.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunner.java
@@ -919,24 +919,16 @@ public class InternalStepRunner implements StepRunner {
String runtimeProviderClass = config.runtimeProviderClass();
String tenantCdBundle = config.tenantCdBundle();
- String handlerAndExtraComponents = useOsgiBasedTestRuntime
- ?
+ String extraJUnitComponents =
+ "\n" +
" <component id=\"" + runtimeProviderClass + "\" bundle=\"" + tenantCdBundle + "\" />\n" +
- "\n" +
- " <component id=\"com.yahoo.vespa.testrunner.JunitRunner\" bundle=\"vespa-osgi-testrunner\">\n" +
- " <config name=\"com.yahoo.vespa.testrunner.junit-test-runner\">\n" +
- " <artifactsPath>artifacts</artifactsPath>\n" +
- " <useAthenzCredentials>" + systemUsesAthenz + "</useAthenzCredentials>\n" +
- " </config>\n" +
- " </component>\n" +
- "\n" +
- " <handler id=\"com.yahoo.vespa.testrunner.TestRunnerHandler\" bundle=\"vespa-osgi-testrunner\">\n" +
- " <binding>http://*/tester/v1/*</binding>\n" +
- " </handler>\n"
- :
- " <handler id=\"com.yahoo.vespa.hosted.testrunner.TestRunnerHandler\" bundle=\"vespa-testrunner-components\">\n" +
- " <binding>http://*/tester/v1/*</binding>\n" +
- " </handler>\n";
+ "\n" +
+ " <component id=\"com.yahoo.vespa.testrunner.JunitRunner\" bundle=\"vespa-osgi-testrunner\">\n" +
+ " <config name=\"com.yahoo.vespa.testrunner.junit-test-runner\">\n" +
+ " <artifactsPath>artifacts</artifactsPath>\n" +
+ " <useAthenzCredentials>" + systemUsesAthenz + "</useAthenzCredentials>\n" +
+ " </config>\n" +
+ " </component>\n";
String servicesXml =
"<?xml version='1.0' encoding='UTF-8'?>\n" +
@@ -952,7 +944,10 @@ public class InternalStepRunner implements StepRunner {
" </config>\n" +
" </component>\n" +
"\n" +
- handlerAndExtraComponents +
+ " <handler id=\"com.yahoo.vespa.testrunner.TestRunnerHandler\" bundle=\"vespa-osgi-testrunner\">\n" +
+ " <binding>http://*/tester/v1/*</binding>\n" +
+ " </handler>\n" +
+ (useOsgiBasedTestRuntime ? extraJUnitComponents : "") +
"\n" +
" <nodes count=\"1\" allocated-memory=\"" + jdiscMemoryPct + "%\">\n" +
" " + resourceString + "\n" +
diff --git a/controller-server/src/test/resources/test_runner_services.xml-cd-legacy b/controller-server/src/test/resources/test_runner_services.xml-cd-legacy
index 125c5004d25..c6046479934 100644
--- a/controller-server/src/test/resources/test_runner_services.xml-cd-legacy
+++ b/controller-server/src/test/resources/test_runner_services.xml-cd-legacy
@@ -11,7 +11,7 @@
</config>
</component>
- <handler id="com.yahoo.vespa.hosted.testrunner.TestRunnerHandler" bundle="vespa-testrunner-components">
+ <handler id="com.yahoo.vespa.testrunner.TestRunnerHandler" bundle="vespa-osgi-testrunner">
<binding>http://*/tester/v1/*</binding>
</handler>
diff --git a/controller-server/src/test/resources/test_runner_services.xml-cd-osgi b/controller-server/src/test/resources/test_runner_services.xml-cd-osgi
index d1a83abff8d..01a7afb3bed 100644
--- a/controller-server/src/test/resources/test_runner_services.xml-cd-osgi
+++ b/controller-server/src/test/resources/test_runner_services.xml-cd-osgi
@@ -11,6 +11,10 @@
</config>
</component>
+ <handler id="com.yahoo.vespa.testrunner.TestRunnerHandler" bundle="vespa-osgi-testrunner">
+ <binding>http://*/tester/v1/*</binding>
+ </handler>
+
<component id="ai.vespa.hosted.cd.cloud.impl.VespaTestRuntimeProvider" bundle="cloud-tenant-cd" />
<component id="com.yahoo.vespa.testrunner.JunitRunner" bundle="vespa-osgi-testrunner">
@@ -20,10 +24,6 @@
</config>
</component>
- <handler id="com.yahoo.vespa.testrunner.TestRunnerHandler" bundle="vespa-osgi-testrunner">
- <binding>http://*/tester/v1/*</binding>
- </handler>
-
<nodes count="1" allocated-memory="17%">
<resources vcpu="2.00" memory="12.00Gb" disk="75.00Gb" disk-speed="fast" storage-type="local"/>
</nodes>
diff --git a/vespa-testrunner-components/src/main/java/com/yahoo/vespa/hosted/testrunner/TestRunnerHandler.java b/vespa-testrunner-components/src/main/java/com/yahoo/vespa/hosted/testrunner/TestRunnerHandler.java
deleted file mode 100644
index c10ee5416db..00000000000
--- a/vespa-testrunner-components/src/main/java/com/yahoo/vespa/hosted/testrunner/TestRunnerHandler.java
+++ /dev/null
@@ -1,127 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.vespa.hosted.testrunner;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.google.inject.Inject;
-import com.yahoo.container.jdisc.HttpRequest;
-import com.yahoo.container.jdisc.HttpResponse;
-import com.yahoo.container.jdisc.LoggingRequestHandler;
-import com.yahoo.io.IOUtils;
-import com.yahoo.restapi.MessageResponse;
-import com.yahoo.restapi.SlimeJsonResponse;
-import com.yahoo.slime.Cursor;
-import com.yahoo.slime.JsonFormat;
-import com.yahoo.slime.Slime;
-import com.yahoo.vespa.testrunner.TestRunner;
-import com.yahoo.yolean.Exceptions;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.PrintStream;
-import java.util.Collection;
-import java.util.concurrent.Executor;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
-
-import static com.yahoo.jdisc.Response.Status;
-
-/**
- * @author valerijf
- * @author jvenstad
- */
-public class TestRunnerHandler extends LoggingRequestHandler {
-
- private final com.yahoo.vespa.hosted.testrunner.TestRunner testRunner;
-
- @Inject
- public TestRunnerHandler(Executor executor, com.yahoo.vespa.hosted.testrunner.TestRunner testRunner) {
- super(executor);
- this.testRunner = testRunner;
- }
-
- @Override
- public HttpResponse handle(HttpRequest request) {
- try {
- switch (request.getMethod()) {
- case GET: return handleGET(request);
- case POST: return handlePOST(request);
-
- default: return new MessageResponse(Status.METHOD_NOT_ALLOWED, "Method '" + request.getMethod() + "' is not supported");
- }
- } catch (IllegalArgumentException e) {
- return new MessageResponse(Status.BAD_REQUEST, Exceptions.toMessageString(e));
- } catch (Exception e) {
- log.log(Level.WARNING, "Unexpected error handling '" + request.getUri() + "'", e);
- return new MessageResponse(Status.INTERNAL_SERVER_ERROR, Exceptions.toMessageString(e));
- }
- }
-
- private HttpResponse handleGET(HttpRequest request) {
- String path = request.getUri().getPath();
- if (path.equals("/tester/v1/log")) {
- return new SlimeJsonResponse(logToSlime(testRunner.getLog(request.hasProperty("after")
- ? Long.parseLong(request.getProperty("after"))
- : -1)));
- } else if (path.equals("/tester/v1/status")) {
- log.info("Responding with status " + testRunner.getStatus());
- return new MessageResponse(testRunner.getStatus().name());
- }
- return new MessageResponse(Status.NOT_FOUND, "Not found: " + request.getUri().getPath());
- }
-
- private HttpResponse handlePOST(HttpRequest request) throws IOException {
- final String path = request.getUri().getPath();
- if (path.startsWith("/tester/v1/run/")) {
- String type = lastElement(path);
- TestRunner.Suite suite = TestRunner.Suite.valueOf(type.toUpperCase() + "_TEST");
- byte[] config = IOUtils.readBytes(request.getData(), 1 << 16);
- testRunner.test(suite, config);
- log.info("Started tests of type " + type + " and status is " + testRunner.getStatus());
- return new MessageResponse("Successfully started " + type + " tests");
- }
- return new MessageResponse(Status.NOT_FOUND, "Not found: " + request.getUri().getPath());
- }
-
- private static String lastElement(String path) {
- if (path.endsWith("/"))
- path = path.substring(0, path.length() - 1);
- int lastSlash = path.lastIndexOf("/");
- if (lastSlash < 0) return path;
- return path.substring(lastSlash + 1);
- }
-
- static Slime logToSlime(Collection<LogRecord> log) {
- Slime slime = new Slime();
- Cursor root = slime.setObject();
- Cursor recordArray = root.setArray("logRecords");
- logArrayToSlime(recordArray, log);
- return slime;
- }
-
- static void logArrayToSlime(Cursor recordArray, Collection<LogRecord> log) {
- log.forEach(record -> {
- Cursor recordObject = recordArray.addObject();
- recordObject.setLong("id", record.getSequenceNumber());
- recordObject.setLong("at", record.getMillis());
- recordObject.setString("type", typeOf(record.getLevel()));
- String message = record.getMessage();
- if (record.getThrown() != null) {
- ByteArrayOutputStream buffer = new ByteArrayOutputStream();
- record.getThrown().printStackTrace(new PrintStream(buffer));
- message += "\n" + buffer;
- }
- recordObject.setString("message", message);
- });
- }
-
- public static String typeOf(Level level) {
- return level.getName().equals("html") ? "html"
- : level.intValue() < Level.INFO.intValue() ? "debug"
- : level.intValue() < Level.WARNING.intValue() ? "info"
- : level.intValue() < Level.SEVERE.intValue() ? "warning"
- : "error";
- }
-
-}
diff --git a/vespa-testrunner-components/src/test/java/com/yahoo/vespa/hosted/testrunner/TestRunnerHandlerTest.java b/vespa-testrunner-components/src/test/java/com/yahoo/vespa/hosted/testrunner/TestRunnerHandlerTest.java
deleted file mode 100644
index fdc6b633630..00000000000
--- a/vespa-testrunner-components/src/test/java/com/yahoo/vespa/hosted/testrunner/TestRunnerHandlerTest.java
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.vespa.hosted.testrunner;
-
-import com.yahoo.slime.SlimeUtils;
-import org.junit.Test;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.time.Instant;
-import java.util.Collections;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
-
-import static org.junit.Assert.assertEquals;
-
-/**
- * @author jvenstad
- */
-public class TestRunnerHandlerTest {
-
- @Test
- public void logSerialization() throws IOException {
- Log log = new Log();
- LogRecord record = log.getLogRecord();
- String trace = log.getTrace();
- assertEquals("{\"logRecords\":[{\"id\":1,\"at\":2,\"type\":\"info\",\"message\":\"Hello.\\n" + trace + "\"}]}",
- new String(SlimeUtils.toJsonBytes(TestRunnerHandler.logToSlime(Collections.singletonList(record)))));
- }
-
- private static class Log {
-
- private final LogRecord record;
- private final String trace;
-
- public Log() {
- Exception exception = new RuntimeException();
- record = createRecord(exception);
- ByteArrayOutputStream buffer = new ByteArrayOutputStream();
- exception.printStackTrace(new PrintStream(buffer));
- trace = buffer.toString()
- .replaceAll("\n", "\\\\n")
- .replaceAll("\t", "\\\\t");
- }
-
- LogRecord getLogRecord() {
- return record;
- }
-
- String getTrace() {
- return trace;
- }
-
- private static LogRecord createRecord(Exception exception) {
- LogRecord record = new LogRecord(Level.INFO, "Hello.");
- record.setSequenceNumber(1);
- record.setInstant(Instant.ofEpochMilli(2));
- record.setThrown(exception);
- return record;
- }
- }
-
-}