From aec93498670d2ca5eb935c926a65b1c5f512df91 Mon Sep 17 00:00:00 2001 From: Bjørn Christian Seime Date: Mon, 5 Jul 2021 11:15:16 +0200 Subject: Use provided apache http client bundle from container --- configserver/pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'configserver') diff --git a/configserver/pom.xml b/configserver/pom.xml index 3b7fef085b1..a237d7e00ad 100644 --- a/configserver/pom.xml +++ b/configserver/pom.xml @@ -141,6 +141,12 @@ ${project.version} provided + + com.yahoo.vespa + container-apache-http-client-bundle + ${project.version} + provided + com.yahoo.vespa -- cgit v1.2.3 From cc678563035fd0c6a3c2e1b83cd38c65e496b831 Mon Sep 17 00:00:00 2001 From: Bjørn Christian Seime Date: Mon, 5 Jul 2021 14:57:57 +0200 Subject: Allow reflective access to java.nio --- configserver/src/main/sh/start-configserver | 1 + container-disc/src/main/sh/vespa-start-container-daemon.sh | 1 + standalone-container/src/main/sh/standalone-container.sh | 1 + 3 files changed, 3 insertions(+) (limited to 'configserver') diff --git a/configserver/src/main/sh/start-configserver b/configserver/src/main/sh/start-configserver index 24acf79705d..f9eb5e3a0a5 100755 --- a/configserver/src/main/sh/start-configserver +++ b/configserver/src/main/sh/start-configserver @@ -175,6 +175,7 @@ vespa-run-as-vespa-user vespa-runserver -s configserver -r 30 -p $pidfile -- \ --add-opens=java.base/java.io=ALL-UNNAMED \ --add-opens=java.base/java.lang=ALL-UNNAMED \ --add-opens=java.base/java.net=ALL-UNNAMED \ + --add-opens=java.base/java.nio=ALL-UNNAMED \ --add-opens=java.base/jdk.internal.loader=ALL-UNNAMED \ --add-opens=java.base/sun.security.ssl=ALL-UNNAMED \ -Djava.io.tmpdir=${VESPA_HOME}/tmp \ diff --git a/container-disc/src/main/sh/vespa-start-container-daemon.sh b/container-disc/src/main/sh/vespa-start-container-daemon.sh index 4518868cb81..223124c29d6 100755 --- a/container-disc/src/main/sh/vespa-start-container-daemon.sh +++ b/container-disc/src/main/sh/vespa-start-container-daemon.sh @@ -215,6 +215,7 @@ exec $numactlcmd $envcmd java \ --add-opens=java.base/java.io=ALL-UNNAMED \ --add-opens=java.base/java.lang=ALL-UNNAMED \ --add-opens=java.base/java.net=ALL-UNNAMED \ + --add-opens=java.base/java.nio=ALL-UNNAMED \ --add-opens=java.base/jdk.internal.loader=ALL-UNNAMED \ --add-opens=java.base/sun.security.ssl=ALL-UNNAMED \ -Djava.io.tmpdir="${VESPA_HOME}/tmp" \ diff --git a/standalone-container/src/main/sh/standalone-container.sh b/standalone-container/src/main/sh/standalone-container.sh index 3f3937658d2..b30a7ad4cd0 100755 --- a/standalone-container/src/main/sh/standalone-container.sh +++ b/standalone-container/src/main/sh/standalone-container.sh @@ -167,6 +167,7 @@ StartCommand() { --add-opens=java.base/java.io=ALL-UNNAMED \ --add-opens=java.base/java.lang=ALL-UNNAMED \ --add-opens=java.base/java.net=ALL-UNNAMED \ + --add-opens=java.base/java.nio=ALL-UNNAMED \ --add-opens=java.base/jdk.internal.loader=ALL-UNNAMED \ --add-opens=java.base/sun.security.ssl=ALL-UNNAMED \ -Djava.library.path="$VESPA_HOME/lib64" \ -- cgit v1.2.3 From a930310f8558dcb6e235152616d4bdca0970d6e9 Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Mon, 5 Jul 2021 20:27:10 +0200 Subject: Revert "Use provided apache http client bundle from container [run-systemtest]" --- athenz-identity-provider-service/pom.xml | 16 ++++++++++------ config/pom.xml | 6 ------ configserver-client/pom.xml | 6 ------ configserver/pom.xml | 6 ------ container-core/pom.xml | 26 ++++++++++++++++++++------ controller-api/pom.xml | 7 ------- controller-server/pom.xml | 17 ++++++++++------- filedistribution/pom.xml | 10 ++++------ http-utils/pom.xml | 9 +++++---- jdisc-cloud-aws/pom.xml | 12 ------------ metrics-proxy/pom.xml | 6 ------ node-repository/pom.xml | 10 ++++------ service-monitor/pom.xml | 14 ++++++++------ vespa-athenz/pom.xml | 18 ++++++++---------- vespaclient-container-plugin/pom.xml | 5 +++++ 15 files changed, 74 insertions(+), 94 deletions(-) (limited to 'configserver') diff --git a/athenz-identity-provider-service/pom.xml b/athenz-identity-provider-service/pom.xml index 3c5f96a1fec..855b3afafaf 100644 --- a/athenz-identity-provider-service/pom.xml +++ b/athenz-identity-provider-service/pom.xml @@ -26,12 +26,6 @@ ${project.version} provided - - com.yahoo.vespa - container-apache-http-client-bundle - ${project.version} - provided - com.yahoo.vespa container-dev @@ -85,6 +79,16 @@ provided + + + org.apache.httpcomponents + httpclient + + + org.apache.httpcomponents + httpcore + + com.yahoo.vespa diff --git a/config/pom.xml b/config/pom.xml index 8355587c10b..6e4e26ed0f1 100755 --- a/config/pom.xml +++ b/config/pom.xml @@ -14,12 +14,6 @@ 7-SNAPSHOT - - com.yahoo.vespa - container-apache-http-client-bundle - ${project.version} - provided - com.google.guava guava diff --git a/configserver-client/pom.xml b/configserver-client/pom.xml index 39005c9ccab..0a29ba003f4 100644 --- a/configserver-client/pom.xml +++ b/configserver-client/pom.xml @@ -28,12 +28,6 @@ ${project.version} provided - - com.yahoo.vespa - container-apache-http-client-bundle - ${project.version} - provided - com.yahoo.vespa security-utils diff --git a/configserver/pom.xml b/configserver/pom.xml index a237d7e00ad..3b7fef085b1 100644 --- a/configserver/pom.xml +++ b/configserver/pom.xml @@ -141,12 +141,6 @@ ${project.version} provided - - com.yahoo.vespa - container-apache-http-client-bundle - ${project.version} - provided - com.yahoo.vespa diff --git a/container-core/pom.xml b/container-core/pom.xml index c7fe2998530..2b87d79daa4 100644 --- a/container-core/pom.xml +++ b/container-core/pom.xml @@ -139,6 +139,10 @@ vespalog ${project.version} + + org.apache.httpcomponents + httpclient + org.hdrhistogram HdrHistogram @@ -205,12 +209,6 @@ ${project.version} provided - - com.yahoo.vespa - container-apache-http-client-bundle - ${project.version} - provided - com.yahoo.vespa defaults @@ -263,6 +261,11 @@ junit test + + org.apache.httpcomponents + httpmime + test + org.assertj assertj-core @@ -299,6 +302,17 @@ mockito-core test + + org.apache.httpcomponents.client5 + httpclient5 + test + + + org.slf4j + slf4j-api + + + diff --git a/controller-api/pom.xml b/controller-api/pom.xml index 02a7028b8ca..2f01f45edaa 100644 --- a/controller-api/pom.xml +++ b/controller-api/pom.xml @@ -25,13 +25,6 @@ ${project.version} - - com.yahoo.vespa - container-apache-http-client-bundle - ${project.version} - provided - - com.yahoo.vespa serviceview diff --git a/controller-server/pom.xml b/controller-server/pom.xml index 3673e3cb9f9..0c05f7d70bb 100644 --- a/controller-server/pom.xml +++ b/controller-server/pom.xml @@ -19,13 +19,6 @@ - - com.yahoo.vespa - container-apache-http-client-bundle - ${project.version} - provided - - com.yahoo.vespa controller-api @@ -134,6 +127,16 @@ 1.3.3 + + org.apache.httpcomponents + httpcore + + + + org.apache.httpcomponents + httpclient + + com.auth0 java-jwt diff --git a/filedistribution/pom.xml b/filedistribution/pom.xml index e922d878dd7..8bfa85d8b16 100644 --- a/filedistribution/pom.xml +++ b/filedistribution/pom.xml @@ -18,12 +18,6 @@ ${project.artifactId} - - com.yahoo.vespa - container-apache-http-client-bundle - ${project.version} - provided - com.yahoo.vespa vespajlib @@ -63,6 +57,10 @@ io.airlift airline + + org.apache.httpcomponents + httpclient + com.fasterxml.jackson.core jackson-databind diff --git a/http-utils/pom.xml b/http-utils/pom.xml index 2a8ec1b9bb9..1f85658430f 100644 --- a/http-utils/pom.xml +++ b/http-utils/pom.xml @@ -31,21 +31,22 @@ slf4j-api provided - + + org.apache.httpcomponents httpclient - provided + compile org.apache.httpcomponents httpcore - provided + compile org.apache.httpcomponents.client5 httpclient5 - provided + compile org.slf4j diff --git a/jdisc-cloud-aws/pom.xml b/jdisc-cloud-aws/pom.xml index 0c89872aa46..9f4572736c8 100644 --- a/jdisc-cloud-aws/pom.xml +++ b/jdisc-cloud-aws/pom.xml @@ -23,21 +23,9 @@ ${project.version} provided - - com.yahoo.vespa - container-apache-http-client-bundle - ${project.version} - provided - com.amazonaws aws-java-sdk-core - - - org.apache.httpcomponents - httpclient - - com.amazonaws diff --git a/metrics-proxy/pom.xml b/metrics-proxy/pom.xml index 19b545df616..a7579aeb2ea 100644 --- a/metrics-proxy/pom.xml +++ b/metrics-proxy/pom.xml @@ -58,12 +58,6 @@ ${project.version} provided - - com.yahoo.vespa - container-apache-http-client-bundle - ${project.version} - provided - com.yahoo.vespa container-core diff --git a/node-repository/pom.xml b/node-repository/pom.xml index e7fdc560bc5..30aa76658fd 100644 --- a/node-repository/pom.xml +++ b/node-repository/pom.xml @@ -24,12 +24,6 @@ ${project.version} provided - - com.yahoo.vespa - container-apache-http-client-bundle - ${project.version} - provided - com.yahoo.vespa config-provisioning @@ -84,6 +78,10 @@ 6.0.3 compile + + org.apache.httpcomponents + httpclient + com.yahoo.vespa http-utils diff --git a/service-monitor/pom.xml b/service-monitor/pom.xml index df28737f352..578fcc83006 100644 --- a/service-monitor/pom.xml +++ b/service-monitor/pom.xml @@ -16,6 +16,14 @@ Service monitor component for hosted vespa. + + + org.apache.httpcomponents + httpclient + 4.5 + + compile + com.yahoo.vespa http-utils @@ -24,12 +32,6 @@ - - com.yahoo.vespa - container-apache-http-client-bundle - ${project.version} - provided - com.yahoo.vespa config diff --git a/vespa-athenz/pom.xml b/vespa-athenz/pom.xml index c4dc849a460..90ab2a81e0c 100644 --- a/vespa-athenz/pom.xml +++ b/vespa-athenz/pom.xml @@ -23,12 +23,6 @@ ${project.version} provided - - com.yahoo.vespa - container-apache-http-client-bundle - ${project.version} - provided - com.yahoo.vespa security-utils @@ -136,6 +130,14 @@ + + org.apache.httpcomponents + httpcore + + + org.apache.httpcomponents + httpclient + com.amazonaws aws-java-sdk-core @@ -152,10 +154,6 @@ com.fasterxml.jackson.core jackson-annotations - - org.apache.httpcomponents - httpclient - diff --git a/vespaclient-container-plugin/pom.xml b/vespaclient-container-plugin/pom.xml index 17443b11b6a..834c3d7c988 100644 --- a/vespaclient-container-plugin/pom.xml +++ b/vespaclient-container-plugin/pom.xml @@ -37,6 +37,11 @@ ${project.version} provided + + org.apache.httpcomponents + httpclient + test + com.yahoo.vespa vespa-http-client -- cgit v1.2.3 From 8a316f29e150ccdcb2b25c100c4ca2a2d7e818d7 Mon Sep 17 00:00:00 2001 From: Bjørn Christian Seime Date: Mon, 5 Jul 2021 11:15:16 +0200 Subject: Use provided apache http client bundle from container --- athenz-identity-provider-service/pom.xml | 16 ++++++---------- config/pom.xml | 6 ++++++ configserver-client/pom.xml | 6 ++++++ configserver/pom.xml | 6 ++++++ container-core/pom.xml | 26 ++++++-------------------- controller-api/pom.xml | 7 +++++++ controller-server/pom.xml | 17 +++++++---------- filedistribution/pom.xml | 10 ++++++---- http-utils/pom.xml | 9 ++++----- jdisc-cloud-aws/pom.xml | 12 ++++++++++++ metrics-proxy/pom.xml | 6 ++++++ node-repository/pom.xml | 10 ++++++---- service-monitor/pom.xml | 14 ++++++-------- vespa-athenz/pom.xml | 18 ++++++++++-------- vespaclient-container-plugin/pom.xml | 5 ----- 15 files changed, 94 insertions(+), 74 deletions(-) (limited to 'configserver') diff --git a/athenz-identity-provider-service/pom.xml b/athenz-identity-provider-service/pom.xml index 855b3afafaf..3c5f96a1fec 100644 --- a/athenz-identity-provider-service/pom.xml +++ b/athenz-identity-provider-service/pom.xml @@ -26,6 +26,12 @@ ${project.version} provided + + com.yahoo.vespa + container-apache-http-client-bundle + ${project.version} + provided + com.yahoo.vespa container-dev @@ -79,16 +85,6 @@ provided - - - org.apache.httpcomponents - httpclient - - - org.apache.httpcomponents - httpcore - - com.yahoo.vespa diff --git a/config/pom.xml b/config/pom.xml index 6e4e26ed0f1..8355587c10b 100755 --- a/config/pom.xml +++ b/config/pom.xml @@ -14,6 +14,12 @@ 7-SNAPSHOT + + com.yahoo.vespa + container-apache-http-client-bundle + ${project.version} + provided + com.google.guava guava diff --git a/configserver-client/pom.xml b/configserver-client/pom.xml index 0a29ba003f4..39005c9ccab 100644 --- a/configserver-client/pom.xml +++ b/configserver-client/pom.xml @@ -28,6 +28,12 @@ ${project.version} provided + + com.yahoo.vespa + container-apache-http-client-bundle + ${project.version} + provided + com.yahoo.vespa security-utils diff --git a/configserver/pom.xml b/configserver/pom.xml index 3b7fef085b1..a237d7e00ad 100644 --- a/configserver/pom.xml +++ b/configserver/pom.xml @@ -141,6 +141,12 @@ ${project.version} provided + + com.yahoo.vespa + container-apache-http-client-bundle + ${project.version} + provided + com.yahoo.vespa diff --git a/container-core/pom.xml b/container-core/pom.xml index 2b87d79daa4..c7fe2998530 100644 --- a/container-core/pom.xml +++ b/container-core/pom.xml @@ -139,10 +139,6 @@ vespalog ${project.version} - - org.apache.httpcomponents - httpclient - org.hdrhistogram HdrHistogram @@ -209,6 +205,12 @@ ${project.version} provided + + com.yahoo.vespa + container-apache-http-client-bundle + ${project.version} + provided + com.yahoo.vespa defaults @@ -261,11 +263,6 @@ junit test - - org.apache.httpcomponents - httpmime - test - org.assertj assertj-core @@ -302,17 +299,6 @@ mockito-core test - - org.apache.httpcomponents.client5 - httpclient5 - test - - - org.slf4j - slf4j-api - - - diff --git a/controller-api/pom.xml b/controller-api/pom.xml index 2f01f45edaa..02a7028b8ca 100644 --- a/controller-api/pom.xml +++ b/controller-api/pom.xml @@ -25,6 +25,13 @@ ${project.version} + + com.yahoo.vespa + container-apache-http-client-bundle + ${project.version} + provided + + com.yahoo.vespa serviceview diff --git a/controller-server/pom.xml b/controller-server/pom.xml index 0c05f7d70bb..3673e3cb9f9 100644 --- a/controller-server/pom.xml +++ b/controller-server/pom.xml @@ -19,6 +19,13 @@ + + com.yahoo.vespa + container-apache-http-client-bundle + ${project.version} + provided + + com.yahoo.vespa controller-api @@ -127,16 +134,6 @@ 1.3.3 - - org.apache.httpcomponents - httpcore - - - - org.apache.httpcomponents - httpclient - - com.auth0 java-jwt diff --git a/filedistribution/pom.xml b/filedistribution/pom.xml index 8bfa85d8b16..e922d878dd7 100644 --- a/filedistribution/pom.xml +++ b/filedistribution/pom.xml @@ -18,6 +18,12 @@ ${project.artifactId} + + com.yahoo.vespa + container-apache-http-client-bundle + ${project.version} + provided + com.yahoo.vespa vespajlib @@ -57,10 +63,6 @@ io.airlift airline - - org.apache.httpcomponents - httpclient - com.fasterxml.jackson.core jackson-databind diff --git a/http-utils/pom.xml b/http-utils/pom.xml index 1f85658430f..2a8ec1b9bb9 100644 --- a/http-utils/pom.xml +++ b/http-utils/pom.xml @@ -31,22 +31,21 @@ slf4j-api provided - - + org.apache.httpcomponents httpclient - compile + provided org.apache.httpcomponents httpcore - compile + provided org.apache.httpcomponents.client5 httpclient5 - compile + provided org.slf4j diff --git a/jdisc-cloud-aws/pom.xml b/jdisc-cloud-aws/pom.xml index 9f4572736c8..0c89872aa46 100644 --- a/jdisc-cloud-aws/pom.xml +++ b/jdisc-cloud-aws/pom.xml @@ -23,9 +23,21 @@ ${project.version} provided + + com.yahoo.vespa + container-apache-http-client-bundle + ${project.version} + provided + com.amazonaws aws-java-sdk-core + + + org.apache.httpcomponents + httpclient + + com.amazonaws diff --git a/metrics-proxy/pom.xml b/metrics-proxy/pom.xml index a7579aeb2ea..19b545df616 100644 --- a/metrics-proxy/pom.xml +++ b/metrics-proxy/pom.xml @@ -58,6 +58,12 @@ ${project.version} provided + + com.yahoo.vespa + container-apache-http-client-bundle + ${project.version} + provided + com.yahoo.vespa container-core diff --git a/node-repository/pom.xml b/node-repository/pom.xml index 30aa76658fd..e7fdc560bc5 100644 --- a/node-repository/pom.xml +++ b/node-repository/pom.xml @@ -24,6 +24,12 @@ ${project.version} provided + + com.yahoo.vespa + container-apache-http-client-bundle + ${project.version} + provided + com.yahoo.vespa config-provisioning @@ -78,10 +84,6 @@ 6.0.3 compile - - org.apache.httpcomponents - httpclient - com.yahoo.vespa http-utils diff --git a/service-monitor/pom.xml b/service-monitor/pom.xml index 578fcc83006..df28737f352 100644 --- a/service-monitor/pom.xml +++ b/service-monitor/pom.xml @@ -16,14 +16,6 @@ Service monitor component for hosted vespa. - - - org.apache.httpcomponents - httpclient - 4.5 - - compile - com.yahoo.vespa http-utils @@ -32,6 +24,12 @@ + + com.yahoo.vespa + container-apache-http-client-bundle + ${project.version} + provided + com.yahoo.vespa config diff --git a/vespa-athenz/pom.xml b/vespa-athenz/pom.xml index 90ab2a81e0c..c4dc849a460 100644 --- a/vespa-athenz/pom.xml +++ b/vespa-athenz/pom.xml @@ -23,6 +23,12 @@ ${project.version} provided + + com.yahoo.vespa + container-apache-http-client-bundle + ${project.version} + provided + com.yahoo.vespa security-utils @@ -130,14 +136,6 @@ - - org.apache.httpcomponents - httpcore - - - org.apache.httpcomponents - httpclient - com.amazonaws aws-java-sdk-core @@ -154,6 +152,10 @@ com.fasterxml.jackson.core jackson-annotations + + org.apache.httpcomponents + httpclient + diff --git a/vespaclient-container-plugin/pom.xml b/vespaclient-container-plugin/pom.xml index 834c3d7c988..17443b11b6a 100644 --- a/vespaclient-container-plugin/pom.xml +++ b/vespaclient-container-plugin/pom.xml @@ -37,11 +37,6 @@ ${project.version} provided - - org.apache.httpcomponents - httpclient - test - com.yahoo.vespa vespa-http-client -- cgit v1.2.3 From 85fecfc6ee020f05b5b77141a120dfc5179434a9 Mon Sep 17 00:00:00 2001 From: Valerij Fredriksen Date: Tue, 6 Jul 2021 09:59:18 +0200 Subject: Move response classes to upper level --- .../config/server/http/v2/ApplicationHandler.java | 74 ---------------------- .../http/v2/ApplicationSuspendedResponse.java | 11 ++++ .../server/http/v2/DeleteApplicationResponse.java | 11 ++++ .../server/http/v2/GetApplicationResponse.java | 18 ++++++ .../config/server/http/v2/QuotaUsageResponse.java | 11 ++++ .../config/server/http/v2/ReindexingResponse.java | 51 +++++++++++++++ .../server/http/v2/ApplicationHandlerTest.java | 1 - 7 files changed, 102 insertions(+), 75 deletions(-) create mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationSuspendedResponse.java create mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/DeleteApplicationResponse.java create mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/GetApplicationResponse.java create mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/QuotaUsageResponse.java create mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ReindexingResponse.java (limited to 'configserver') diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java index 3634a6825a3..ba70c34d192 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java @@ -20,8 +20,6 @@ import com.yahoo.slime.Cursor; import com.yahoo.slime.SlimeUtils; import com.yahoo.text.StringUtilities; import com.yahoo.vespa.config.server.ApplicationRepository; -import com.yahoo.vespa.config.server.application.ApplicationReindexing; -import com.yahoo.vespa.config.server.application.ClusterReindexing; import com.yahoo.vespa.config.server.http.ContentHandler; import com.yahoo.vespa.config.server.http.ContentRequest; import com.yahoo.vespa.config.server.http.HttpErrorResponse; @@ -453,78 +451,6 @@ public class ApplicationHandler extends HttpHandler { : Optional.of(Version.fromString(vespaVersion)); } - private static class DeleteApplicationResponse extends JSONResponse { - DeleteApplicationResponse(int status, ApplicationId applicationId) { - super(status); - object.setString("message", "Application '" + applicationId + "' deleted"); - } - } - - private static class GetApplicationResponse extends JSONResponse { - GetApplicationResponse(int status, long generation, List modelVersions, Optional applicationPackageReference) { - super(status); - object.setLong("generation", generation); - object.setString("applicationPackageFileReference", applicationPackageReference.orElse("")); - Cursor modelVersionArray = object.setArray("modelVersions"); - modelVersions.forEach(version -> modelVersionArray.addString(version.toFullString())); - } - } - - private static class ApplicationSuspendedResponse extends JSONResponse { - ApplicationSuspendedResponse(boolean suspended) { - super(Response.Status.OK); - object.setBool("suspended", suspended); - } - } - - private static class QuotaUsageResponse extends JSONResponse { - QuotaUsageResponse(double usageRate) { - super(Response.Status.OK); - object.setDouble("rate", usageRate); - } - } - - static class ReindexingResponse extends JSONResponse { - ReindexingResponse(Map> documentTypes, ApplicationReindexing reindexing, - Map clusters) { - super(Response.Status.OK); - object.setBool("enabled", reindexing.enabled()); - Cursor clustersObject = object.setObject("clusters"); - documentTypes.forEach((cluster, types) -> { - Cursor clusterObject = clustersObject.setObject(cluster); - Cursor pendingObject = clusterObject.setObject("pending"); - Cursor readyObject = clusterObject.setObject("ready"); - - for (String type : types) { - Cursor statusObject = readyObject.setObject(type); - if (reindexing.clusters().containsKey(cluster)) { - if (reindexing.clusters().get(cluster).pending().containsKey(type)) - pendingObject.setLong(type, reindexing.clusters().get(cluster).pending().get(type)); - - if (reindexing.clusters().get(cluster).ready().containsKey(type)) - setStatus(statusObject, reindexing.clusters().get(cluster).ready().get(type)); - } - if (clusters.containsKey(cluster)) - if (clusters.get(cluster).documentTypeStatus().containsKey(type)) - setStatus(statusObject, clusters.get(cluster).documentTypeStatus().get(type)); - } - }); - } - - private static void setStatus(Cursor object, ApplicationReindexing.Status readyStatus) { - object.setLong("readyMillis", readyStatus.ready().toEpochMilli()); - } - - private static void setStatus(Cursor object, ClusterReindexing.Status status) { - object.setLong("startedMillis", status.startedAt().toEpochMilli()); - status.endedAt().ifPresent(endedAt -> object.setLong("endedMillis", endedAt.toEpochMilli())); - status.state().map(ClusterReindexing.State::asString).ifPresent(state -> object.setString("state", state)); - status.message().ifPresent(message -> object.setString("message", message)); - status.progress().ifPresent(progress -> object.setDouble("progress", progress)); - } - - } - private static JSONResponse createMessageResponse(String message) { return new JSONResponse(Response.Status.OK) { { object.setString("message", message); } }; } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationSuspendedResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationSuspendedResponse.java new file mode 100644 index 00000000000..a339357c732 --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationSuspendedResponse.java @@ -0,0 +1,11 @@ +package com.yahoo.vespa.config.server.http.v2; + +import com.yahoo.jdisc.Response; +import com.yahoo.vespa.config.server.http.JSONResponse; + +class ApplicationSuspendedResponse extends JSONResponse { + ApplicationSuspendedResponse(boolean suspended) { + super(Response.Status.OK); + object.setBool("suspended", suspended); + } +} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/DeleteApplicationResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/DeleteApplicationResponse.java new file mode 100644 index 00000000000..2a0f785c60a --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/DeleteApplicationResponse.java @@ -0,0 +1,11 @@ +package com.yahoo.vespa.config.server.http.v2; + +import com.yahoo.config.provision.ApplicationId; +import com.yahoo.vespa.config.server.http.JSONResponse; + +class DeleteApplicationResponse extends JSONResponse { + DeleteApplicationResponse(int status, ApplicationId applicationId) { + super(status); + object.setString("message", "Application '" + applicationId + "' deleted"); + } +} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/GetApplicationResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/GetApplicationResponse.java new file mode 100644 index 00000000000..371154cf8d6 --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/GetApplicationResponse.java @@ -0,0 +1,18 @@ +package com.yahoo.vespa.config.server.http.v2; + +import com.yahoo.component.Version; +import com.yahoo.slime.Cursor; +import com.yahoo.vespa.config.server.http.JSONResponse; + +import java.util.List; +import java.util.Optional; + +class GetApplicationResponse extends JSONResponse { + GetApplicationResponse(int status, long generation, List modelVersions, Optional applicationPackageReference) { + super(status); + object.setLong("generation", generation); + object.setString("applicationPackageFileReference", applicationPackageReference.orElse("")); + Cursor modelVersionArray = object.setArray("modelVersions"); + modelVersions.forEach(version -> modelVersionArray.addString(version.toFullString())); + } +} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/QuotaUsageResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/QuotaUsageResponse.java new file mode 100644 index 00000000000..cfb14bd0887 --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/QuotaUsageResponse.java @@ -0,0 +1,11 @@ +package com.yahoo.vespa.config.server.http.v2; + +import com.yahoo.jdisc.Response; +import com.yahoo.vespa.config.server.http.JSONResponse; + +class QuotaUsageResponse extends JSONResponse { + QuotaUsageResponse(double usageRate) { + super(Response.Status.OK); + object.setDouble("rate", usageRate); + } +} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ReindexingResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ReindexingResponse.java new file mode 100644 index 00000000000..c7558d5a76a --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ReindexingResponse.java @@ -0,0 +1,51 @@ +package com.yahoo.vespa.config.server.http.v2; + +import com.yahoo.jdisc.Response; +import com.yahoo.slime.Cursor; +import com.yahoo.vespa.config.server.application.ApplicationReindexing; +import com.yahoo.vespa.config.server.application.ClusterReindexing; +import com.yahoo.vespa.config.server.http.JSONResponse; + +import java.util.Map; +import java.util.Set; + +class ReindexingResponse extends JSONResponse { + ReindexingResponse(Map> documentTypes, ApplicationReindexing reindexing, + Map clusters) { + super(Response.Status.OK); + object.setBool("enabled", reindexing.enabled()); + Cursor clustersObject = object.setObject("clusters"); + documentTypes.forEach((cluster, types) -> { + Cursor clusterObject = clustersObject.setObject(cluster); + Cursor pendingObject = clusterObject.setObject("pending"); + Cursor readyObject = clusterObject.setObject("ready"); + + for (String type : types) { + Cursor statusObject = readyObject.setObject(type); + if (reindexing.clusters().containsKey(cluster)) { + if (reindexing.clusters().get(cluster).pending().containsKey(type)) + pendingObject.setLong(type, reindexing.clusters().get(cluster).pending().get(type)); + + if (reindexing.clusters().get(cluster).ready().containsKey(type)) + setStatus(statusObject, reindexing.clusters().get(cluster).ready().get(type)); + } + if (clusters.containsKey(cluster)) + if (clusters.get(cluster).documentTypeStatus().containsKey(type)) + setStatus(statusObject, clusters.get(cluster).documentTypeStatus().get(type)); + } + }); + } + + private static void setStatus(Cursor object, ApplicationReindexing.Status readyStatus) { + object.setLong("readyMillis", readyStatus.ready().toEpochMilli()); + } + + private static void setStatus(Cursor object, ClusterReindexing.Status status) { + object.setLong("startedMillis", status.startedAt().toEpochMilli()); + status.endedAt().ifPresent(endedAt -> object.setLong("endedMillis", endedAt.toEpochMilli())); + status.state().map(ClusterReindexing.State::asString).ifPresent(state -> object.setString("state", state)); + status.message().ifPresent(message -> object.setString("message", message)); + status.progress().ifPresent(progress -> object.setDouble("progress", progress)); + } + +} diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java index 22a5b3795d9..2501bc6dc6d 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java @@ -32,7 +32,6 @@ import com.yahoo.vespa.config.server.http.HttpErrorResponse; import com.yahoo.vespa.config.server.http.SecretStoreValidator; import com.yahoo.vespa.config.server.http.SessionHandlerTest; import com.yahoo.vespa.config.server.http.StaticResponse; -import com.yahoo.vespa.config.server.http.v2.ApplicationHandler.ReindexingResponse; import com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry; import com.yahoo.vespa.config.server.provision.HostProvisionerProvider; import com.yahoo.vespa.config.server.session.PrepareParams; -- cgit v1.2.3 From eb4d2e8229936cad8d4dbf5a601001298fede5d7 Mon Sep 17 00:00:00 2001 From: Valerij Fredriksen Date: Tue, 6 Jul 2021 10:15:16 +0200 Subject: Use MessageResponse for delete application --- .../yahoo/vespa/config/server/http/v2/ApplicationHandler.java | 3 +-- .../vespa/config/server/http/v2/DeleteApplicationResponse.java | 9 ++++----- 2 files changed, 5 insertions(+), 7 deletions(-) (limited to 'configserver') diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java index ba70c34d192..7478efdd0c8 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java @@ -16,7 +16,6 @@ import com.yahoo.io.IOUtils; import com.yahoo.jdisc.Response; import com.yahoo.jdisc.application.BindingMatch; import com.yahoo.jdisc.application.UriPattern; -import com.yahoo.slime.Cursor; import com.yahoo.slime.SlimeUtils; import com.yahoo.text.StringUtilities; import com.yahoo.vespa.config.server.ApplicationRepository; @@ -97,7 +96,7 @@ public class ApplicationHandler extends HttpHandler { } if (applicationRepository.delete(applicationId)) - return new DeleteApplicationResponse(Response.Status.OK, applicationId); + return new DeleteApplicationResponse(applicationId); return HttpErrorResponse.notFoundError("Unable to delete " + applicationId.toFullString() + ": Not found"); } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/DeleteApplicationResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/DeleteApplicationResponse.java index 2a0f785c60a..add0c7a45f3 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/DeleteApplicationResponse.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/DeleteApplicationResponse.java @@ -1,11 +1,10 @@ package com.yahoo.vespa.config.server.http.v2; import com.yahoo.config.provision.ApplicationId; -import com.yahoo.vespa.config.server.http.JSONResponse; +import com.yahoo.restapi.MessageResponse; -class DeleteApplicationResponse extends JSONResponse { - DeleteApplicationResponse(int status, ApplicationId applicationId) { - super(status); - object.setString("message", "Application '" + applicationId + "' deleted"); +public class DeleteApplicationResponse extends MessageResponse { + public DeleteApplicationResponse(ApplicationId applicationId) { + super("Application '" + applicationId + "' deleted"); } } -- cgit v1.2.3 From 4ca0c6b75ba79b2ac89cc249fc01477504e170af Mon Sep 17 00:00:00 2001 From: Valerij Fredriksen Date: Tue, 6 Jul 2021 10:20:57 +0200 Subject: Move responses to own package --- .../vespa/config/server/ApplicationRepository.java | 4 +- .../server/http/v2/ApplicationApiHandler.java | 2 +- .../config/server/http/v2/ApplicationHandler.java | 5 +++ .../http/v2/ApplicationSuspendedResponse.java | 11 ----- .../server/http/v2/DeleteApplicationResponse.java | 10 ----- .../server/http/v2/DeploymentMetricsResponse.java | 50 --------------------- .../server/http/v2/GetApplicationResponse.java | 18 -------- .../server/http/v2/ListApplicationsHandler.java | 1 + .../server/http/v2/ListApplicationsResponse.java | 41 ----------------- .../config/server/http/v2/ListTenantsResponse.java | 21 --------- .../server/http/v2/ProtonMetricsResponse.java | 35 --------------- .../config/server/http/v2/QuotaUsageResponse.java | 11 ----- .../config/server/http/v2/ReindexingResponse.java | 51 --------------------- .../server/http/v2/SessionActiveHandler.java | 1 + .../server/http/v2/SessionActiveResponse.java | 29 ------------ .../server/http/v2/SessionCreateHandler.java | 4 +- .../server/http/v2/SessionCreateResponse.java | 27 ----------- .../http/v2/SessionPrepareAndActivateResponse.java | 37 --------------- .../server/http/v2/SessionPrepareHandler.java | 1 + .../server/http/v2/SessionPrepareResponse.java | 39 ---------------- .../server/http/v2/TenantCreateResponse.java | 19 -------- .../server/http/v2/TenantDeleteResponse.java | 18 -------- .../config/server/http/v2/TenantGetResponse.java | 18 -------- .../vespa/config/server/http/v2/TenantHandler.java | 4 ++ .../v2/response/ApplicationSuspendedResponse.java | 12 +++++ .../v2/response/DeleteApplicationResponse.java | 11 +++++ .../v2/response/DeploymentMetricsResponse.java | 50 +++++++++++++++++++++ .../http/v2/response/GetApplicationResponse.java | 19 ++++++++ .../http/v2/response/ListApplicationsResponse.java | 41 +++++++++++++++++ .../http/v2/response/ListTenantsResponse.java | 22 +++++++++ .../http/v2/response/ProtonMetricsResponse.java | 35 +++++++++++++++ .../http/v2/response/QuotaUsageResponse.java | 12 +++++ .../http/v2/response/ReindexingResponse.java | 52 ++++++++++++++++++++++ .../http/v2/response/SessionActiveResponse.java | 29 ++++++++++++ .../http/v2/response/SessionCreateResponse.java | 27 +++++++++++ .../SessionPrepareAndActivateResponse.java | 38 ++++++++++++++++ .../http/v2/response/SessionPrepareResponse.java | 40 +++++++++++++++++ .../http/v2/response/TenantCreateResponse.java | 19 ++++++++ .../http/v2/response/TenantDeleteResponse.java | 18 ++++++++ .../server/http/v2/response/TenantGetResponse.java | 18 ++++++++ .../server/metrics/DeploymentMetricsRetriever.java | 2 +- .../server/metrics/ProtonMetricsRetriever.java | 2 +- .../server/http/v2/ApplicationHandlerTest.java | 1 + 43 files changed, 462 insertions(+), 443 deletions(-) delete mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationSuspendedResponse.java delete mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/DeleteApplicationResponse.java delete mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/DeploymentMetricsResponse.java delete mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/GetApplicationResponse.java delete mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ListApplicationsResponse.java delete mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ListTenantsResponse.java delete mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ProtonMetricsResponse.java delete mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/QuotaUsageResponse.java delete mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ReindexingResponse.java delete mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionActiveResponse.java delete mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionCreateResponse.java delete mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareAndActivateResponse.java delete mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareResponse.java delete mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/TenantCreateResponse.java delete mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/TenantDeleteResponse.java delete mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/TenantGetResponse.java create mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/ApplicationSuspendedResponse.java create mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/DeleteApplicationResponse.java create mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/DeploymentMetricsResponse.java create mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/GetApplicationResponse.java create mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/ListApplicationsResponse.java create mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/ListTenantsResponse.java create mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/ProtonMetricsResponse.java create mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/QuotaUsageResponse.java create mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/ReindexingResponse.java create mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/SessionActiveResponse.java create mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/SessionCreateResponse.java create mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/SessionPrepareAndActivateResponse.java create mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/SessionPrepareResponse.java create mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/TenantCreateResponse.java create mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/TenantDeleteResponse.java create mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/TenantGetResponse.java (limited to 'configserver') diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java b/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java index 2d5940ebba2..6249e3bfff8 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java @@ -56,9 +56,9 @@ import com.yahoo.vespa.config.server.http.LogRetriever; import com.yahoo.vespa.config.server.http.SecretStoreValidator; import com.yahoo.vespa.config.server.http.SimpleHttpFetcher; import com.yahoo.vespa.config.server.http.TesterClient; -import com.yahoo.vespa.config.server.http.v2.DeploymentMetricsResponse; +import com.yahoo.vespa.config.server.http.v2.response.DeploymentMetricsResponse; import com.yahoo.vespa.config.server.http.v2.PrepareResult; -import com.yahoo.vespa.config.server.http.v2.ProtonMetricsResponse; +import com.yahoo.vespa.config.server.http.v2.response.ProtonMetricsResponse; import com.yahoo.vespa.config.server.metrics.DeploymentMetricsRetriever; import com.yahoo.vespa.config.server.metrics.ProtonMetricsRetriever; import com.yahoo.vespa.config.server.provision.HostProvisionerProvider; diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationApiHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationApiHandler.java index dfbce72d4ba..7e8940d28b3 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationApiHandler.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationApiHandler.java @@ -14,9 +14,9 @@ import com.yahoo.vespa.config.server.application.CompressedApplicationInputStrea import com.yahoo.vespa.config.server.http.BadRequestException; import com.yahoo.vespa.config.server.http.SessionHandler; import com.yahoo.vespa.config.server.http.Utils; +import com.yahoo.vespa.config.server.http.v2.response.SessionPrepareAndActivateResponse; import com.yahoo.vespa.config.server.session.PrepareParams; import com.yahoo.vespa.config.server.tenant.TenantRepository; -import com.yahoo.vespa.model.content.Content; import org.apache.hc.core5.http.ContentType; import org.eclipse.jetty.http.MultiPartFormInputStream; diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java index 7478efdd0c8..d79140cd552 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java @@ -25,6 +25,11 @@ import com.yahoo.vespa.config.server.http.HttpErrorResponse; import com.yahoo.vespa.config.server.http.HttpHandler; import com.yahoo.vespa.config.server.http.JSONResponse; import com.yahoo.vespa.config.server.http.NotFoundException; +import com.yahoo.vespa.config.server.http.v2.response.ApplicationSuspendedResponse; +import com.yahoo.vespa.config.server.http.v2.response.DeleteApplicationResponse; +import com.yahoo.vespa.config.server.http.v2.response.GetApplicationResponse; +import com.yahoo.vespa.config.server.http.v2.response.QuotaUsageResponse; +import com.yahoo.vespa.config.server.http.v2.response.ReindexingResponse; import com.yahoo.vespa.config.server.tenant.Tenant; import java.io.IOException; diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationSuspendedResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationSuspendedResponse.java deleted file mode 100644 index a339357c732..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationSuspendedResponse.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.yahoo.vespa.config.server.http.v2; - -import com.yahoo.jdisc.Response; -import com.yahoo.vespa.config.server.http.JSONResponse; - -class ApplicationSuspendedResponse extends JSONResponse { - ApplicationSuspendedResponse(boolean suspended) { - super(Response.Status.OK); - object.setBool("suspended", suspended); - } -} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/DeleteApplicationResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/DeleteApplicationResponse.java deleted file mode 100644 index add0c7a45f3..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/DeleteApplicationResponse.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.yahoo.vespa.config.server.http.v2; - -import com.yahoo.config.provision.ApplicationId; -import com.yahoo.restapi.MessageResponse; - -public class DeleteApplicationResponse extends MessageResponse { - public DeleteApplicationResponse(ApplicationId applicationId) { - super("Application '" + applicationId + "' deleted"); - } -} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/DeploymentMetricsResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/DeploymentMetricsResponse.java deleted file mode 100644 index cdfdce91500..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/DeploymentMetricsResponse.java +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.config.server.http.v2; - -import com.yahoo.config.provision.ApplicationId; -import com.yahoo.restapi.SlimeJsonResponse; -import com.yahoo.slime.Cursor; -import com.yahoo.vespa.config.server.metrics.ClusterInfo; -import com.yahoo.vespa.config.server.metrics.DeploymentMetricsAggregator; - -import java.util.Map; - -/** - * @author olaa - */ -public class DeploymentMetricsResponse extends SlimeJsonResponse { - - public DeploymentMetricsResponse(ApplicationId applicationId, Map aggregatedMetrics) { - Cursor application = slime.setObject(); - application.setString("applicationId", applicationId.serializedForm()); - - Cursor clusters = application.setArray("clusters"); - - for (var entry : aggregatedMetrics.entrySet()) { - Cursor cluster = clusters.addObject(); - cluster.setString("clusterId", entry.getKey().getClusterId()); - cluster.setString("clusterType", entry.getKey().getClusterType()); - - DeploymentMetricsAggregator aggregator = entry.getValue(); - Cursor metrics = cluster.setObject("metrics"); - aggregator.aggregateQueryRate().ifPresent(queryRate -> metrics.setDouble("queriesPerSecond", queryRate)); - aggregator.aggregateFeedRate().ifPresent(feedRate -> metrics.setDouble("feedPerSecond", feedRate)); - aggregator.aggregateDocumentCount().ifPresent(documentCount -> metrics.setDouble("documentCount", documentCount)); - aggregator.aggregateQueryLatency().ifPresent(queryLatency -> metrics.setDouble("queryLatency",queryLatency)); - aggregator.aggregateFeedLatency().ifPresent(feedLatency -> metrics.setDouble("feedLatency", feedLatency)); - aggregator.memoryUsage().ifPresent(memory -> { - metrics.setDouble("memoryUtil", memory.util()); - metrics.setDouble("memoryFeedBlockLimit", memory.feedBlockLimit()); - }); - aggregator.diskUsage().ifPresent(disk -> { - metrics.setDouble("diskUtil", disk.util()); - metrics.setDouble("diskFeedBlockLimit", disk.feedBlockLimit()); - }); - - aggregator.reindexingProgress().ifPresent(reindexingProgress -> { - Cursor progressObject = cluster.setObject("reindexingProgress"); - reindexingProgress.forEach(progressObject::setDouble); - }); - } - } -} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/GetApplicationResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/GetApplicationResponse.java deleted file mode 100644 index 371154cf8d6..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/GetApplicationResponse.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.yahoo.vespa.config.server.http.v2; - -import com.yahoo.component.Version; -import com.yahoo.slime.Cursor; -import com.yahoo.vespa.config.server.http.JSONResponse; - -import java.util.List; -import java.util.Optional; - -class GetApplicationResponse extends JSONResponse { - GetApplicationResponse(int status, long generation, List modelVersions, Optional applicationPackageReference) { - super(status); - object.setLong("generation", generation); - object.setString("applicationPackageFileReference", applicationPackageReference.orElse("")); - Cursor modelVersionArray = object.setArray("modelVersions"); - modelVersions.forEach(version -> modelVersionArray.addString(version.toFullString())); - } -} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ListApplicationsHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ListApplicationsHandler.java index b06d5c31ac6..20688f4f2f1 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ListApplicationsHandler.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ListApplicationsHandler.java @@ -10,6 +10,7 @@ import com.yahoo.container.jdisc.HttpRequest; import com.yahoo.container.jdisc.HttpResponse; import com.yahoo.jdisc.Response; import com.yahoo.vespa.config.server.application.TenantApplications; +import com.yahoo.vespa.config.server.http.v2.response.ListApplicationsResponse; import com.yahoo.vespa.config.server.tenant.Tenant; import com.yahoo.vespa.config.server.tenant.TenantRepository; import com.yahoo.config.provision.ApplicationId; diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ListApplicationsResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ListApplicationsResponse.java deleted file mode 100644 index a4527305abb..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ListApplicationsResponse.java +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.config.server.http.v2; - -import com.yahoo.container.jdisc.HttpResponse; -import com.yahoo.slime.Cursor; -import com.yahoo.slime.JsonFormat; -import com.yahoo.slime.Slime; -import com.yahoo.vespa.config.server.http.HttpConfigResponse; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.Collection; - -/** - * Response that lists applications. - * - * @author Ulf Lilleengen - */ -public class ListApplicationsResponse extends HttpResponse { - - private final Slime slime = new Slime(); - - public ListApplicationsResponse(int status, Collection applications) { - super(status); - Cursor array = slime.setArray(); - for (String url : applications) { - array.addString(url); - } - } - - @Override - public void render(OutputStream outputStream) throws IOException { - new JsonFormat(true).encode(outputStream, slime); - } - - @Override - public String getContentType() { - return HttpConfigResponse.JSON_CONTENT_TYPE; - } - -} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ListTenantsResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ListTenantsResponse.java deleted file mode 100644 index 3789939429c..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ListTenantsResponse.java +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.config.server.http.v2; - -import com.google.common.collect.ImmutableSet; -import com.yahoo.config.provision.TenantName; -import com.yahoo.restapi.SlimeJsonResponse; -import com.yahoo.slime.Cursor; - -/** - * Tenant list response - * - * @author vegardh - */ -public class ListTenantsResponse extends SlimeJsonResponse { - - ListTenantsResponse(ImmutableSet tenants) { - Cursor tenantArray = slime.setObject().setArray("tenants"); - tenants.forEach(tenantName -> tenantArray.addString(tenantName.value())); - } - -} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ProtonMetricsResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ProtonMetricsResponse.java deleted file mode 100644 index 99b95f9244c..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ProtonMetricsResponse.java +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.config.server.http.v2; - -import com.yahoo.config.provision.ApplicationId; -import com.yahoo.restapi.SlimeJsonResponse; -import com.yahoo.slime.Cursor; -import com.yahoo.vespa.config.server.metrics.ProtonMetricsAggregator; -import java.util.Map; - -/** - * @author akvalsvik - */ -public class ProtonMetricsResponse extends SlimeJsonResponse { - - public ProtonMetricsResponse(ApplicationId applicationId, Map aggregatedProtonMetrics) { - Cursor application = slime.setObject(); - application.setString("applicationId", applicationId.serializedForm()); - - Cursor clusters = application.setArray("clusters"); - - for (var entry : aggregatedProtonMetrics.entrySet()) { - Cursor cluster = clusters.addObject(); - cluster.setString("clusterId", entry.getKey()); - - ProtonMetricsAggregator aggregator = entry.getValue(); - Cursor metrics = cluster.setObject("metrics"); - metrics.setDouble("documentsActiveCount", aggregator.aggregateDocumentActiveCount()); - metrics.setDouble("documentsReadyCount", aggregator.aggregateDocumentReadyCount()); - metrics.setDouble("documentsTotalCount", aggregator.aggregateDocumentTotalCount()); - metrics.setDouble("documentDiskUsage", aggregator.aggregateDocumentDiskUsage()); - metrics.setDouble("resourceDiskUsageAverage", aggregator.aggregateResourceDiskUsageAverage()); - metrics.setDouble("resourceMemoryUsageAverage", aggregator.aggregateResourceMemoryUsageAverage()); - } - } -} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/QuotaUsageResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/QuotaUsageResponse.java deleted file mode 100644 index cfb14bd0887..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/QuotaUsageResponse.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.yahoo.vespa.config.server.http.v2; - -import com.yahoo.jdisc.Response; -import com.yahoo.vespa.config.server.http.JSONResponse; - -class QuotaUsageResponse extends JSONResponse { - QuotaUsageResponse(double usageRate) { - super(Response.Status.OK); - object.setDouble("rate", usageRate); - } -} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ReindexingResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ReindexingResponse.java deleted file mode 100644 index c7558d5a76a..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ReindexingResponse.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.yahoo.vespa.config.server.http.v2; - -import com.yahoo.jdisc.Response; -import com.yahoo.slime.Cursor; -import com.yahoo.vespa.config.server.application.ApplicationReindexing; -import com.yahoo.vespa.config.server.application.ClusterReindexing; -import com.yahoo.vespa.config.server.http.JSONResponse; - -import java.util.Map; -import java.util.Set; - -class ReindexingResponse extends JSONResponse { - ReindexingResponse(Map> documentTypes, ApplicationReindexing reindexing, - Map clusters) { - super(Response.Status.OK); - object.setBool("enabled", reindexing.enabled()); - Cursor clustersObject = object.setObject("clusters"); - documentTypes.forEach((cluster, types) -> { - Cursor clusterObject = clustersObject.setObject(cluster); - Cursor pendingObject = clusterObject.setObject("pending"); - Cursor readyObject = clusterObject.setObject("ready"); - - for (String type : types) { - Cursor statusObject = readyObject.setObject(type); - if (reindexing.clusters().containsKey(cluster)) { - if (reindexing.clusters().get(cluster).pending().containsKey(type)) - pendingObject.setLong(type, reindexing.clusters().get(cluster).pending().get(type)); - - if (reindexing.clusters().get(cluster).ready().containsKey(type)) - setStatus(statusObject, reindexing.clusters().get(cluster).ready().get(type)); - } - if (clusters.containsKey(cluster)) - if (clusters.get(cluster).documentTypeStatus().containsKey(type)) - setStatus(statusObject, clusters.get(cluster).documentTypeStatus().get(type)); - } - }); - } - - private static void setStatus(Cursor object, ApplicationReindexing.Status readyStatus) { - object.setLong("readyMillis", readyStatus.ready().toEpochMilli()); - } - - private static void setStatus(Cursor object, ClusterReindexing.Status status) { - object.setLong("startedMillis", status.startedAt().toEpochMilli()); - status.endedAt().ifPresent(endedAt -> object.setLong("endedMillis", endedAt.toEpochMilli())); - status.state().map(ClusterReindexing.State::asString).ifPresent(state -> object.setString("state", state)); - status.message().ifPresent(message -> object.setString("message", message)); - status.progress().ifPresent(progress -> object.setDouble("progress", progress)); - } - -} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandler.java index 4e75234620f..f97e272b132 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandler.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandler.java @@ -14,6 +14,7 @@ import com.yahoo.jdisc.Request; import com.yahoo.jdisc.handler.ResponseHandler; import java.util.logging.Level; import com.yahoo.vespa.config.server.ApplicationRepository; +import com.yahoo.vespa.config.server.http.v2.response.SessionActiveResponse; import com.yahoo.vespa.config.server.tenant.Tenant; import com.yahoo.vespa.config.server.tenant.TenantRepository; import com.yahoo.vespa.config.server.TimeoutBudget; diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionActiveResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionActiveResponse.java deleted file mode 100644 index 9c0fbdf2613..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionActiveResponse.java +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.config.server.http.v2; - -import com.yahoo.config.provision.TenantName; -import com.yahoo.config.provision.Zone; -import com.yahoo.container.jdisc.HttpRequest; -import com.yahoo.restapi.SlimeJsonResponse; -import com.yahoo.slime.Cursor; -import com.yahoo.slime.Slime; -import com.yahoo.config.provision.ApplicationId; - -public class SessionActiveResponse extends SlimeJsonResponse { - - public SessionActiveResponse(Slime metaData, HttpRequest request, ApplicationId applicationId, long sessionId, Zone zone) { - super(metaData); - TenantName tenantName = applicationId.tenant(); - String message = "Session " + sessionId + " for tenant '" + tenantName.value() + "' activated."; - Cursor root = metaData.get(); - - root.setString("tenant", tenantName.value()); - root.setString("message", message); - root.setString("url", "http://" + request.getHost() + ":" + request.getPort() + - "/application/v2/tenant/" + tenantName + - "/application/" + applicationId.application().value() + - "/environment/" + zone.environment().value() + - "/region/" + zone.region().value() + - "/instance/" + applicationId.instance().value()); - } -} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionCreateHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionCreateHandler.java index 61f099fb8ea..ea7d11d9802 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionCreateHandler.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionCreateHandler.java @@ -9,7 +9,6 @@ import com.yahoo.config.provision.InstanceName; import com.yahoo.config.provision.TenantName; import com.yahoo.container.jdisc.HttpRequest; import com.yahoo.container.jdisc.HttpResponse; -import com.yahoo.jdisc.HeaderFields; import com.yahoo.jdisc.application.UriPattern; import com.yahoo.vespa.config.server.ApplicationRepository; import com.yahoo.vespa.config.server.deploy.DeployHandlerLogger; @@ -17,13 +16,12 @@ import com.yahoo.vespa.config.server.TimeoutBudget; import com.yahoo.vespa.config.server.http.BadRequestException; import com.yahoo.vespa.config.server.http.SessionHandler; import com.yahoo.vespa.config.server.http.Utils; -import com.yahoo.vespa.model.content.Content; +import com.yahoo.vespa.config.server.http.v2.response.SessionCreateResponse; import org.apache.hc.core5.http.ContentType; import java.net.URI; import java.time.Duration; import java.util.List; -import java.util.stream.Collectors; /** * A handler that is able to create a session from an application package, diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionCreateResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionCreateResponse.java deleted file mode 100644 index faf02a1ea4f..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionCreateResponse.java +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.config.server.http.v2; - -import com.yahoo.config.provision.TenantName; -import com.yahoo.restapi.SlimeJsonResponse; -import com.yahoo.slime.Cursor; -import com.yahoo.slime.Slime; - -/** - * Creates a response for SessionCreateHandler. - * - * @author hmusum - */ -public class SessionCreateResponse extends SlimeJsonResponse { - - public SessionCreateResponse(Slime deployLog, TenantName tenantName, String hostName, int port, long sessionId) { - super(deployLog); - String path = "http://" + hostName + ":" + port + "/application/v2/tenant/" + tenantName.value() + "/session/" + sessionId; - Cursor root = deployLog.get(); - - root.setString("tenant", tenantName.value()); - root.setString("session-id", Long.toString(sessionId)); - root.setString("prepared", path + "/prepared"); - root.setString("content", path + "/content/"); - root.setString("message", "Session " + sessionId + " for tenant '" + tenantName.value() + "' created."); - } -} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareAndActivateResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareAndActivateResponse.java deleted file mode 100644 index 7bace4749a8..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareAndActivateResponse.java +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.config.server.http.v2; - -import com.yahoo.config.provision.ApplicationId; -import com.yahoo.config.provision.TenantName; -import com.yahoo.config.provision.Zone; -import com.yahoo.container.jdisc.HttpRequest; -import com.yahoo.restapi.SlimeJsonResponse; -import com.yahoo.slime.Cursor; -import com.yahoo.vespa.config.server.configchange.ConfigChangeActionsSlimeConverter; - -/** - * Creates a response for SessionPrepareHandler. - * - * @author hmusum - */ -class SessionPrepareAndActivateResponse extends SlimeJsonResponse { - - SessionPrepareAndActivateResponse(PrepareResult result, HttpRequest request, ApplicationId applicationId, Zone zone) { - super(result.deployLogger().slime()); - - TenantName tenantName = applicationId.tenant(); - String message = "Session " + result.sessionId() + " for tenant '" + tenantName.value() + "' prepared and activated."; - Cursor root = slime.get(); - - root.setString("tenant", tenantName.value()); - root.setString("url", "http://" + request.getHost() + ":" + request.getPort() + - "/application/v2/tenant/" + tenantName + - "/application/" + applicationId.application().value() + - "/environment/" + zone.environment().value() + - "/region/" + zone.region().value() + - "/instance/" + applicationId.instance().value()); - root.setString("message", message); - new ConfigChangeActionsSlimeConverter(result.configChangeActions()).toSlime(root); - } - -} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareHandler.java index 6fa2075807f..0d6d5ed943a 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareHandler.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareHandler.java @@ -7,6 +7,7 @@ import com.yahoo.config.provision.TenantName; import com.yahoo.container.jdisc.HttpRequest; import com.yahoo.container.jdisc.HttpResponse; import com.yahoo.vespa.config.server.ApplicationRepository; +import com.yahoo.vespa.config.server.http.v2.response.SessionPrepareResponse; import com.yahoo.vespa.config.server.session.PrepareParams; import com.yahoo.vespa.config.server.tenant.Tenant; import com.yahoo.vespa.config.server.tenant.TenantRepository; diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareResponse.java deleted file mode 100644 index a97cd37d3b4..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareResponse.java +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.config.server.http.v2; - -import com.yahoo.config.provision.TenantName; -import com.yahoo.container.jdisc.HttpRequest; -import com.yahoo.restapi.SlimeJsonResponse; -import com.yahoo.slime.Cursor; -import com.yahoo.slime.Slime; -import com.yahoo.slime.Type; -import com.yahoo.vespa.config.server.configchange.ConfigChangeActions; -import com.yahoo.vespa.config.server.configchange.ConfigChangeActionsSlimeConverter; - -/** - * Creates a response for SessionPrepareHandler. - * - * @author hmusum - */ -class SessionPrepareResponse extends SlimeJsonResponse { - - SessionPrepareResponse(TenantName tenantName, HttpRequest request, long sessionId) { - this(new Slime(), tenantName, request, sessionId, new ConfigChangeActions()); - } - - SessionPrepareResponse(PrepareResult result, TenantName tenantName, HttpRequest request) { - this(result.deployLogger().slime(), tenantName, request, result.sessionId(), result.configChangeActions()); - } - - private SessionPrepareResponse(Slime deployLog, TenantName tenantName, HttpRequest request, long sessionId, ConfigChangeActions actions) { - super(deployLog); - - Cursor root = deployLog.get().type() != Type.NIX ? deployLog.get() : deployLog.setObject(); - root.setString("tenant", tenantName.value()); - root.setString("activate", "http://" + request.getHost() + ":" + request.getPort() + - "/application/v2/tenant/" + tenantName.value() + "/session/" + sessionId + "/active"); - root.setString("message", "Session " + sessionId + " for tenant '" + tenantName.value() + "' prepared."); - new ConfigChangeActionsSlimeConverter(actions).toSlime(root); - } - -} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/TenantCreateResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/TenantCreateResponse.java deleted file mode 100644 index 6ff2b30075d..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/TenantCreateResponse.java +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.config.server.http.v2; - -import com.yahoo.config.provision.TenantName; -import com.yahoo.restapi.MessageResponse; - -/** - * Response for tenant create - * - * @author vegardh - * - */ -public class TenantCreateResponse extends MessageResponse { - - public TenantCreateResponse(TenantName tenant) { - super("Tenant " + tenant + " created."); - } - -} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/TenantDeleteResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/TenantDeleteResponse.java deleted file mode 100644 index d21584c8cdc..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/TenantDeleteResponse.java +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.config.server.http.v2; -import com.yahoo.config.provision.TenantName; -import com.yahoo.restapi.MessageResponse; - -/** - * Response for tenant delete - * - * @author vegardh - * - */ -public class TenantDeleteResponse extends MessageResponse { - - public TenantDeleteResponse(TenantName tenant) { - super("Tenant " + tenant + " deleted."); - } - -} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/TenantGetResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/TenantGetResponse.java deleted file mode 100644 index b918cab7828..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/TenantGetResponse.java +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.config.server.http.v2; - -import com.yahoo.config.provision.TenantName; -import com.yahoo.restapi.MessageResponse; - -/** - * Response for tenant create - * - * @author hmusum - */ -public class TenantGetResponse extends MessageResponse { - - public TenantGetResponse(TenantName tenant) { - super("Tenant '" + tenant + "' exists."); - } - -} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/TenantHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/TenantHandler.java index bb94f8d442a..a9961762f8b 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/TenantHandler.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/TenantHandler.java @@ -10,6 +10,10 @@ import com.yahoo.restapi.RestApi; import com.yahoo.restapi.RestApiException; import com.yahoo.restapi.RestApiRequestHandler; import com.yahoo.vespa.config.server.ApplicationRepository; +import com.yahoo.vespa.config.server.http.v2.response.ListTenantsResponse; +import com.yahoo.vespa.config.server.http.v2.response.TenantCreateResponse; +import com.yahoo.vespa.config.server.http.v2.response.TenantDeleteResponse; +import com.yahoo.vespa.config.server.http.v2.response.TenantGetResponse; import com.yahoo.vespa.config.server.tenant.TenantRepository; import com.yahoo.yolean.Exceptions; diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/ApplicationSuspendedResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/ApplicationSuspendedResponse.java new file mode 100644 index 00000000000..c2449d9a31d --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/ApplicationSuspendedResponse.java @@ -0,0 +1,12 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.config.server.http.v2.response; + +import com.yahoo.jdisc.Response; +import com.yahoo.vespa.config.server.http.JSONResponse; + +public class ApplicationSuspendedResponse extends JSONResponse { + public ApplicationSuspendedResponse(boolean suspended) { + super(Response.Status.OK); + object.setBool("suspended", suspended); + } +} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/DeleteApplicationResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/DeleteApplicationResponse.java new file mode 100644 index 00000000000..375a6d5e57f --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/DeleteApplicationResponse.java @@ -0,0 +1,11 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.config.server.http.v2.response; + +import com.yahoo.config.provision.ApplicationId; +import com.yahoo.restapi.MessageResponse; + +public class DeleteApplicationResponse extends MessageResponse { + public DeleteApplicationResponse(ApplicationId applicationId) { + super("Application '" + applicationId + "' deleted"); + } +} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/DeploymentMetricsResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/DeploymentMetricsResponse.java new file mode 100644 index 00000000000..253e37f2b0a --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/DeploymentMetricsResponse.java @@ -0,0 +1,50 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.config.server.http.v2.response; + +import com.yahoo.config.provision.ApplicationId; +import com.yahoo.restapi.SlimeJsonResponse; +import com.yahoo.slime.Cursor; +import com.yahoo.vespa.config.server.metrics.ClusterInfo; +import com.yahoo.vespa.config.server.metrics.DeploymentMetricsAggregator; + +import java.util.Map; + +/** + * @author olaa + */ +public class DeploymentMetricsResponse extends SlimeJsonResponse { + + public DeploymentMetricsResponse(ApplicationId applicationId, Map aggregatedMetrics) { + Cursor application = slime.setObject(); + application.setString("applicationId", applicationId.serializedForm()); + + Cursor clusters = application.setArray("clusters"); + + for (var entry : aggregatedMetrics.entrySet()) { + Cursor cluster = clusters.addObject(); + cluster.setString("clusterId", entry.getKey().getClusterId()); + cluster.setString("clusterType", entry.getKey().getClusterType()); + + DeploymentMetricsAggregator aggregator = entry.getValue(); + Cursor metrics = cluster.setObject("metrics"); + aggregator.aggregateQueryRate().ifPresent(queryRate -> metrics.setDouble("queriesPerSecond", queryRate)); + aggregator.aggregateFeedRate().ifPresent(feedRate -> metrics.setDouble("feedPerSecond", feedRate)); + aggregator.aggregateDocumentCount().ifPresent(documentCount -> metrics.setDouble("documentCount", documentCount)); + aggregator.aggregateQueryLatency().ifPresent(queryLatency -> metrics.setDouble("queryLatency",queryLatency)); + aggregator.aggregateFeedLatency().ifPresent(feedLatency -> metrics.setDouble("feedLatency", feedLatency)); + aggregator.memoryUsage().ifPresent(memory -> { + metrics.setDouble("memoryUtil", memory.util()); + metrics.setDouble("memoryFeedBlockLimit", memory.feedBlockLimit()); + }); + aggregator.diskUsage().ifPresent(disk -> { + metrics.setDouble("diskUtil", disk.util()); + metrics.setDouble("diskFeedBlockLimit", disk.feedBlockLimit()); + }); + + aggregator.reindexingProgress().ifPresent(reindexingProgress -> { + Cursor progressObject = cluster.setObject("reindexingProgress"); + reindexingProgress.forEach(progressObject::setDouble); + }); + } + } +} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/GetApplicationResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/GetApplicationResponse.java new file mode 100644 index 00000000000..dc124891540 --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/GetApplicationResponse.java @@ -0,0 +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.config.server.http.v2.response; + +import com.yahoo.component.Version; +import com.yahoo.slime.Cursor; +import com.yahoo.vespa.config.server.http.JSONResponse; + +import java.util.List; +import java.util.Optional; + +public class GetApplicationResponse extends JSONResponse { + public GetApplicationResponse(int status, long generation, List modelVersions, Optional applicationPackageReference) { + super(status); + object.setLong("generation", generation); + object.setString("applicationPackageFileReference", applicationPackageReference.orElse("")); + Cursor modelVersionArray = object.setArray("modelVersions"); + modelVersions.forEach(version -> modelVersionArray.addString(version.toFullString())); + } +} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/ListApplicationsResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/ListApplicationsResponse.java new file mode 100644 index 00000000000..6b1f7031d81 --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/ListApplicationsResponse.java @@ -0,0 +1,41 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.config.server.http.v2.response; + +import com.yahoo.container.jdisc.HttpResponse; +import com.yahoo.slime.Cursor; +import com.yahoo.slime.JsonFormat; +import com.yahoo.slime.Slime; +import com.yahoo.vespa.config.server.http.HttpConfigResponse; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.Collection; + +/** + * Response that lists applications. + * + * @author Ulf Lilleengen + */ +public class ListApplicationsResponse extends HttpResponse { + + private final Slime slime = new Slime(); + + public ListApplicationsResponse(int status, Collection applications) { + super(status); + Cursor array = slime.setArray(); + for (String url : applications) { + array.addString(url); + } + } + + @Override + public void render(OutputStream outputStream) throws IOException { + new JsonFormat(true).encode(outputStream, slime); + } + + @Override + public String getContentType() { + return HttpConfigResponse.JSON_CONTENT_TYPE; + } + +} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/ListTenantsResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/ListTenantsResponse.java new file mode 100644 index 00000000000..ec1b3c83604 --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/ListTenantsResponse.java @@ -0,0 +1,22 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.config.server.http.v2.response; + +import com.yahoo.config.provision.TenantName; +import com.yahoo.restapi.SlimeJsonResponse; +import com.yahoo.slime.Cursor; + +import java.util.Set; + +/** + * Tenant list response + * + * @author vegardh + */ +public class ListTenantsResponse extends SlimeJsonResponse { + + public ListTenantsResponse(Set tenants) { + Cursor tenantArray = slime.setObject().setArray("tenants"); + tenants.forEach(tenantName -> tenantArray.addString(tenantName.value())); + } + +} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/ProtonMetricsResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/ProtonMetricsResponse.java new file mode 100644 index 00000000000..25e770c7211 --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/ProtonMetricsResponse.java @@ -0,0 +1,35 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.config.server.http.v2.response; + +import com.yahoo.config.provision.ApplicationId; +import com.yahoo.restapi.SlimeJsonResponse; +import com.yahoo.slime.Cursor; +import com.yahoo.vespa.config.server.metrics.ProtonMetricsAggregator; +import java.util.Map; + +/** + * @author akvalsvik + */ +public class ProtonMetricsResponse extends SlimeJsonResponse { + + public ProtonMetricsResponse(ApplicationId applicationId, Map aggregatedProtonMetrics) { + Cursor application = slime.setObject(); + application.setString("applicationId", applicationId.serializedForm()); + + Cursor clusters = application.setArray("clusters"); + + for (var entry : aggregatedProtonMetrics.entrySet()) { + Cursor cluster = clusters.addObject(); + cluster.setString("clusterId", entry.getKey()); + + ProtonMetricsAggregator aggregator = entry.getValue(); + Cursor metrics = cluster.setObject("metrics"); + metrics.setDouble("documentsActiveCount", aggregator.aggregateDocumentActiveCount()); + metrics.setDouble("documentsReadyCount", aggregator.aggregateDocumentReadyCount()); + metrics.setDouble("documentsTotalCount", aggregator.aggregateDocumentTotalCount()); + metrics.setDouble("documentDiskUsage", aggregator.aggregateDocumentDiskUsage()); + metrics.setDouble("resourceDiskUsageAverage", aggregator.aggregateResourceDiskUsageAverage()); + metrics.setDouble("resourceMemoryUsageAverage", aggregator.aggregateResourceMemoryUsageAverage()); + } + } +} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/QuotaUsageResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/QuotaUsageResponse.java new file mode 100644 index 00000000000..e30f0f45098 --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/QuotaUsageResponse.java @@ -0,0 +1,12 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.config.server.http.v2.response; + +import com.yahoo.jdisc.Response; +import com.yahoo.vespa.config.server.http.JSONResponse; + +public class QuotaUsageResponse extends JSONResponse { + public QuotaUsageResponse(double usageRate) { + super(Response.Status.OK); + object.setDouble("rate", usageRate); + } +} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/ReindexingResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/ReindexingResponse.java new file mode 100644 index 00000000000..e73d4a9cb56 --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/ReindexingResponse.java @@ -0,0 +1,52 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.config.server.http.v2.response; + +import com.yahoo.jdisc.Response; +import com.yahoo.slime.Cursor; +import com.yahoo.vespa.config.server.application.ApplicationReindexing; +import com.yahoo.vespa.config.server.application.ClusterReindexing; +import com.yahoo.vespa.config.server.http.JSONResponse; + +import java.util.Map; +import java.util.Set; + +public class ReindexingResponse extends JSONResponse { + public ReindexingResponse(Map> documentTypes, ApplicationReindexing reindexing, + Map clusters) { + super(Response.Status.OK); + object.setBool("enabled", reindexing.enabled()); + Cursor clustersObject = object.setObject("clusters"); + documentTypes.forEach((cluster, types) -> { + Cursor clusterObject = clustersObject.setObject(cluster); + Cursor pendingObject = clusterObject.setObject("pending"); + Cursor readyObject = clusterObject.setObject("ready"); + + for (String type : types) { + Cursor statusObject = readyObject.setObject(type); + if (reindexing.clusters().containsKey(cluster)) { + if (reindexing.clusters().get(cluster).pending().containsKey(type)) + pendingObject.setLong(type, reindexing.clusters().get(cluster).pending().get(type)); + + if (reindexing.clusters().get(cluster).ready().containsKey(type)) + setStatus(statusObject, reindexing.clusters().get(cluster).ready().get(type)); + } + if (clusters.containsKey(cluster)) + if (clusters.get(cluster).documentTypeStatus().containsKey(type)) + setStatus(statusObject, clusters.get(cluster).documentTypeStatus().get(type)); + } + }); + } + + private static void setStatus(Cursor object, ApplicationReindexing.Status readyStatus) { + object.setLong("readyMillis", readyStatus.ready().toEpochMilli()); + } + + private static void setStatus(Cursor object, ClusterReindexing.Status status) { + object.setLong("startedMillis", status.startedAt().toEpochMilli()); + status.endedAt().ifPresent(endedAt -> object.setLong("endedMillis", endedAt.toEpochMilli())); + status.state().map(ClusterReindexing.State::asString).ifPresent(state -> object.setString("state", state)); + status.message().ifPresent(message -> object.setString("message", message)); + status.progress().ifPresent(progress -> object.setDouble("progress", progress)); + } + +} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/SessionActiveResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/SessionActiveResponse.java new file mode 100644 index 00000000000..f14f9cc6575 --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/SessionActiveResponse.java @@ -0,0 +1,29 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.config.server.http.v2.response; + +import com.yahoo.config.provision.TenantName; +import com.yahoo.config.provision.Zone; +import com.yahoo.container.jdisc.HttpRequest; +import com.yahoo.restapi.SlimeJsonResponse; +import com.yahoo.slime.Cursor; +import com.yahoo.slime.Slime; +import com.yahoo.config.provision.ApplicationId; + +public class SessionActiveResponse extends SlimeJsonResponse { + + public SessionActiveResponse(Slime metaData, HttpRequest request, ApplicationId applicationId, long sessionId, Zone zone) { + super(metaData); + TenantName tenantName = applicationId.tenant(); + String message = "Session " + sessionId + " for tenant '" + tenantName.value() + "' activated."; + Cursor root = metaData.get(); + + root.setString("tenant", tenantName.value()); + root.setString("message", message); + root.setString("url", "http://" + request.getHost() + ":" + request.getPort() + + "/application/v2/tenant/" + tenantName + + "/application/" + applicationId.application().value() + + "/environment/" + zone.environment().value() + + "/region/" + zone.region().value() + + "/instance/" + applicationId.instance().value()); + } +} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/SessionCreateResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/SessionCreateResponse.java new file mode 100644 index 00000000000..047962ea16b --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/SessionCreateResponse.java @@ -0,0 +1,27 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.config.server.http.v2.response; + +import com.yahoo.config.provision.TenantName; +import com.yahoo.restapi.SlimeJsonResponse; +import com.yahoo.slime.Cursor; +import com.yahoo.slime.Slime; + +/** + * Creates a response for SessionCreateHandler. + * + * @author hmusum + */ +public class SessionCreateResponse extends SlimeJsonResponse { + + public SessionCreateResponse(Slime deployLog, TenantName tenantName, String hostName, int port, long sessionId) { + super(deployLog); + String path = "http://" + hostName + ":" + port + "/application/v2/tenant/" + tenantName.value() + "/session/" + sessionId; + Cursor root = deployLog.get(); + + root.setString("tenant", tenantName.value()); + root.setString("session-id", Long.toString(sessionId)); + root.setString("prepared", path + "/prepared"); + root.setString("content", path + "/content/"); + root.setString("message", "Session " + sessionId + " for tenant '" + tenantName.value() + "' created."); + } +} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/SessionPrepareAndActivateResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/SessionPrepareAndActivateResponse.java new file mode 100644 index 00000000000..d219ff64b4e --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/SessionPrepareAndActivateResponse.java @@ -0,0 +1,38 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.config.server.http.v2.response; + +import com.yahoo.config.provision.ApplicationId; +import com.yahoo.config.provision.TenantName; +import com.yahoo.config.provision.Zone; +import com.yahoo.container.jdisc.HttpRequest; +import com.yahoo.restapi.SlimeJsonResponse; +import com.yahoo.slime.Cursor; +import com.yahoo.vespa.config.server.configchange.ConfigChangeActionsSlimeConverter; +import com.yahoo.vespa.config.server.http.v2.PrepareResult; + +/** + * Creates a response for SessionPrepareHandler. + * + * @author hmusum + */ +public class SessionPrepareAndActivateResponse extends SlimeJsonResponse { + + public SessionPrepareAndActivateResponse(PrepareResult result, HttpRequest request, ApplicationId applicationId, Zone zone) { + super(result.deployLogger().slime()); + + TenantName tenantName = applicationId.tenant(); + String message = "Session " + result.sessionId() + " for tenant '" + tenantName.value() + "' prepared and activated."; + Cursor root = slime.get(); + + root.setString("tenant", tenantName.value()); + root.setString("url", "http://" + request.getHost() + ":" + request.getPort() + + "/application/v2/tenant/" + tenantName + + "/application/" + applicationId.application().value() + + "/environment/" + zone.environment().value() + + "/region/" + zone.region().value() + + "/instance/" + applicationId.instance().value()); + root.setString("message", message); + new ConfigChangeActionsSlimeConverter(result.configChangeActions()).toSlime(root); + } + +} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/SessionPrepareResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/SessionPrepareResponse.java new file mode 100644 index 00000000000..5f50a5236fb --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/SessionPrepareResponse.java @@ -0,0 +1,40 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.config.server.http.v2.response; + +import com.yahoo.config.provision.TenantName; +import com.yahoo.container.jdisc.HttpRequest; +import com.yahoo.restapi.SlimeJsonResponse; +import com.yahoo.slime.Cursor; +import com.yahoo.slime.Slime; +import com.yahoo.slime.Type; +import com.yahoo.vespa.config.server.configchange.ConfigChangeActions; +import com.yahoo.vespa.config.server.configchange.ConfigChangeActionsSlimeConverter; +import com.yahoo.vespa.config.server.http.v2.PrepareResult; + +/** + * Creates a response for SessionPrepareHandler. + * + * @author hmusum + */ +public class SessionPrepareResponse extends SlimeJsonResponse { + + public SessionPrepareResponse(TenantName tenantName, HttpRequest request, long sessionId) { + this(new Slime(), tenantName, request, sessionId, new ConfigChangeActions()); + } + + public SessionPrepareResponse(PrepareResult result, TenantName tenantName, HttpRequest request) { + this(result.deployLogger().slime(), tenantName, request, result.sessionId(), result.configChangeActions()); + } + + private SessionPrepareResponse(Slime deployLog, TenantName tenantName, HttpRequest request, long sessionId, ConfigChangeActions actions) { + super(deployLog); + + Cursor root = deployLog.get().type() != Type.NIX ? deployLog.get() : deployLog.setObject(); + root.setString("tenant", tenantName.value()); + root.setString("activate", "http://" + request.getHost() + ":" + request.getPort() + + "/application/v2/tenant/" + tenantName.value() + "/session/" + sessionId + "/active"); + root.setString("message", "Session " + sessionId + " for tenant '" + tenantName.value() + "' prepared."); + new ConfigChangeActionsSlimeConverter(actions).toSlime(root); + } + +} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/TenantCreateResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/TenantCreateResponse.java new file mode 100644 index 00000000000..395a52df9f2 --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/TenantCreateResponse.java @@ -0,0 +1,19 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.config.server.http.v2.response; + +import com.yahoo.config.provision.TenantName; +import com.yahoo.restapi.MessageResponse; + +/** + * Response for tenant create + * + * @author vegardh + * + */ +public class TenantCreateResponse extends MessageResponse { + + public TenantCreateResponse(TenantName tenant) { + super("Tenant " + tenant + " created."); + } + +} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/TenantDeleteResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/TenantDeleteResponse.java new file mode 100644 index 00000000000..fbfb4d581c6 --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/TenantDeleteResponse.java @@ -0,0 +1,18 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.config.server.http.v2.response; +import com.yahoo.config.provision.TenantName; +import com.yahoo.restapi.MessageResponse; + +/** + * Response for tenant delete + * + * @author vegardh + * + */ +public class TenantDeleteResponse extends MessageResponse { + + public TenantDeleteResponse(TenantName tenant) { + super("Tenant " + tenant + " deleted."); + } + +} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/TenantGetResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/TenantGetResponse.java new file mode 100644 index 00000000000..3a50a68cb21 --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/TenantGetResponse.java @@ -0,0 +1,18 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.config.server.http.v2.response; + +import com.yahoo.config.provision.TenantName; +import com.yahoo.restapi.MessageResponse; + +/** + * Response for tenant create + * + * @author hmusum + */ +public class TenantGetResponse extends MessageResponse { + + public TenantGetResponse(TenantName tenant) { + super("Tenant '" + tenant + "' exists."); + } + +} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/metrics/DeploymentMetricsRetriever.java b/configserver/src/main/java/com/yahoo/vespa/config/server/metrics/DeploymentMetricsRetriever.java index 7fc2c47c06c..2681952cae9 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/metrics/DeploymentMetricsRetriever.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/metrics/DeploymentMetricsRetriever.java @@ -4,7 +4,7 @@ package com.yahoo.vespa.config.server.metrics; import com.yahoo.config.model.api.HostInfo; import com.yahoo.config.model.api.ServiceInfo; import com.yahoo.vespa.config.server.application.Application; -import com.yahoo.vespa.config.server.http.v2.DeploymentMetricsResponse; +import com.yahoo.vespa.config.server.http.v2.response.DeploymentMetricsResponse; import java.net.URI; import java.util.Collection; diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/metrics/ProtonMetricsRetriever.java b/configserver/src/main/java/com/yahoo/vespa/config/server/metrics/ProtonMetricsRetriever.java index 5078fba8b38..4c111687c41 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/metrics/ProtonMetricsRetriever.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/metrics/ProtonMetricsRetriever.java @@ -4,7 +4,7 @@ package com.yahoo.vespa.config.server.metrics; import com.yahoo.config.model.api.HostInfo; import com.yahoo.config.model.api.ServiceInfo; import com.yahoo.vespa.config.server.application.Application; -import com.yahoo.vespa.config.server.http.v2.ProtonMetricsResponse; +import com.yahoo.vespa.config.server.http.v2.response.ProtonMetricsResponse; import java.net.URI; import java.util.Collection; import java.util.function.Predicate; diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java index 2501bc6dc6d..dd7604264f8 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java @@ -32,6 +32,7 @@ import com.yahoo.vespa.config.server.http.HttpErrorResponse; import com.yahoo.vespa.config.server.http.SecretStoreValidator; import com.yahoo.vespa.config.server.http.SessionHandlerTest; import com.yahoo.vespa.config.server.http.StaticResponse; +import com.yahoo.vespa.config.server.http.v2.response.ReindexingResponse; import com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry; import com.yahoo.vespa.config.server.provision.HostProvisionerProvider; import com.yahoo.vespa.config.server.session.PrepareParams; -- cgit v1.2.3 From 70024bab693a533e56c947ea5d3fd5cbe436dce8 Mon Sep 17 00:00:00 2001 From: Valerij Fredriksen Date: Tue, 6 Jul 2021 10:24:18 +0200 Subject: Move requests to own package --- .../config/server/http/HttpConfigRequest.java | 4 +- .../server/http/v2/ApplicationContentRequest.java | 43 ------ .../config/server/http/v2/ApplicationHandler.java | 1 + .../vespa/config/server/http/v2/HostHandler.java | 1 + .../config/server/http/v2/HttpConfigRequests.java | 54 ------- .../server/http/v2/HttpGetConfigHandler.java | 1 + .../server/http/v2/HttpListConfigsHandler.java | 2 + .../server/http/v2/HttpListConfigsRequest.java | 156 --------------------- .../http/v2/HttpListNamedConfigsHandler.java | 2 + .../server/http/v2/SessionContentHandler.java | 1 + .../server/http/v2/SessionContentRequestV2.java | 42 ------ .../vespa/config/server/http/v2/TenantRequest.java | 15 -- .../http/v2/request/ApplicationContentRequest.java | 43 ++++++ .../server/http/v2/request/HttpConfigRequests.java | 54 +++++++ .../http/v2/request/HttpListConfigsRequest.java | 156 +++++++++++++++++++++ .../http/v2/request/SessionContentRequestV2.java | 42 ++++++ .../server/http/v2/request/TenantRequest.java | 15 ++ 17 files changed, 320 insertions(+), 312 deletions(-) delete mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationContentRequest.java delete mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpConfigRequests.java delete mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpListConfigsRequest.java delete mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionContentRequestV2.java delete mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/TenantRequest.java create mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/request/ApplicationContentRequest.java create mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/request/HttpConfigRequests.java create mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/request/HttpListConfigsRequest.java create mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/request/SessionContentRequestV2.java create mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/request/TenantRequest.java (limited to 'configserver') diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/HttpConfigRequest.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/HttpConfigRequest.java index ff70ce1e1b2..cdbd7378151 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/HttpConfigRequest.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/HttpConfigRequest.java @@ -18,8 +18,8 @@ import com.yahoo.vespa.config.protocol.DefContent; import com.yahoo.vespa.config.protocol.VespaVersion; import com.yahoo.vespa.config.server.RequestHandler; import com.yahoo.config.provision.ApplicationId; -import com.yahoo.vespa.config.server.http.v2.HttpConfigRequests; -import com.yahoo.vespa.config.server.http.v2.TenantRequest; +import com.yahoo.vespa.config.server.http.v2.request.HttpConfigRequests; +import com.yahoo.vespa.config.server.http.v2.request.TenantRequest; import com.yahoo.vespa.config.util.ConfigUtils; /** diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationContentRequest.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationContentRequest.java deleted file mode 100644 index af3ab0b1b83..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationContentRequest.java +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.config.server.http.v2; - -import com.yahoo.config.application.api.ApplicationFile; -import com.yahoo.config.provision.ApplicationId; -import com.yahoo.config.provision.Zone; -import com.yahoo.container.jdisc.HttpRequest; -import com.yahoo.vespa.config.server.http.ContentRequest; - -/** - * Represents a content request for an application. - * - * @author Ulf Lilleengen - * @since 5.3 - */ -public class ApplicationContentRequest extends ContentRequest { - - private final ApplicationId applicationId; - private final Zone zone; - - ApplicationContentRequest(HttpRequest request, - long sessionId, - ApplicationId applicationId, - Zone zone, - String contentPath, - ApplicationFile applicationFile) { - super(request, sessionId, contentPath, applicationFile); - this.applicationId = applicationId; - this.zone = zone; - } - - @Override - public String getPathPrefix() { - StringBuilder sb = new StringBuilder(); - sb.append("/application/v2/tenant/").append(applicationId.tenant().value()); - sb.append("/application/").append(applicationId.application().value()); - sb.append("/environment/").append(zone.environment().value()); - sb.append("/region/").append(zone.region().value()); - sb.append("/instance/").append(applicationId.instance().value()); - return sb.toString(); - } - -} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java index d79140cd552..f1704af99c8 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java @@ -25,6 +25,7 @@ import com.yahoo.vespa.config.server.http.HttpErrorResponse; import com.yahoo.vespa.config.server.http.HttpHandler; import com.yahoo.vespa.config.server.http.JSONResponse; import com.yahoo.vespa.config.server.http.NotFoundException; +import com.yahoo.vespa.config.server.http.v2.request.ApplicationContentRequest; import com.yahoo.vespa.config.server.http.v2.response.ApplicationSuspendedResponse; import com.yahoo.vespa.config.server.http.v2.response.DeleteApplicationResponse; import com.yahoo.vespa.config.server.http.v2.response.GetApplicationResponse; diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HostHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HostHandler.java index 1ea41b85983..0a69c7ed904 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HostHandler.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HostHandler.java @@ -12,6 +12,7 @@ import com.yahoo.vespa.config.server.ApplicationRepository; import com.yahoo.vespa.config.server.http.HttpErrorResponse; import com.yahoo.vespa.config.server.http.HttpHandler; import com.yahoo.vespa.config.server.http.JSONResponse; +import com.yahoo.vespa.config.server.http.v2.request.HttpConfigRequests; /** * Handler for getting tenant and application for a given hostname. diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpConfigRequests.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpConfigRequests.java deleted file mode 100644 index 8b482997044..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpConfigRequests.java +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.config.server.http.v2; - -import java.net.URI; - -import com.yahoo.container.jdisc.HttpRequest; -import com.yahoo.jdisc.application.BindingMatch; -import com.yahoo.jdisc.application.UriPattern; -import com.yahoo.jdisc.application.UriPattern.Match; -import com.yahoo.vespa.config.server.RequestHandler; -import com.yahoo.vespa.config.server.tenant.Tenant; -import com.yahoo.vespa.config.server.tenant.TenantRepository; -import com.yahoo.vespa.config.server.http.NotFoundException; - -/** - * Helpers for v2 config REST API - * - * @author vegardh - */ -public class HttpConfigRequests { - - static final String RECURSIVE_QUERY_PROPERTY = "recursive"; - - /** - * Produces the binding match for the request. If it's not available on the jDisc request, create one for - * testing using the long and short app id URL patterns given. - * @param req an {@link com.yahoo.container.jdisc.HttpRequest} - * @param patterns A list of patterns that should be matched if no match on binding. - * @return match - */ - public static BindingMatch getBindingMatch(HttpRequest req, String ... patterns) { - com.yahoo.jdisc.http.HttpRequest jDiscRequest = req.getJDiscRequest(); - if (jDiscRequest==null) throw new IllegalArgumentException("No JDisc request for: " + req.getUri()); - BindingMatch jdBm = jDiscRequest.getBindingMatch(); - if (jdBm!=null) return jdBm; - - // If not, use provided patterns - for (String pattern : patterns) { - UriPattern fullAppIdPattern = new UriPattern(pattern); - URI uri = req.getUri(); - Match match = fullAppIdPattern.match(uri); - if (match!=null) return new BindingMatch<>(match, new Object(), fullAppIdPattern); - } - throw new IllegalArgumentException("Illegal url for config request: " + req.getUri()); - } - - - static RequestHandler getRequestHandler(TenantRepository tenantRepository, TenantRequest request) { - Tenant tenant = tenantRepository.getTenant(request.getApplicationId().tenant()); - if (tenant==null) throw new NotFoundException("No such tenant: "+request.getApplicationId().tenant()); - return tenant.getRequestHandler(); - } - -} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpGetConfigHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpGetConfigHandler.java index 1787431e841..76a39bbcadb 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpGetConfigHandler.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpGetConfigHandler.java @@ -7,6 +7,7 @@ import com.yahoo.container.jdisc.HttpResponse; import java.util.logging.Level; import com.yahoo.vespa.config.protocol.ConfigResponse; import com.yahoo.vespa.config.server.RequestHandler; +import com.yahoo.vespa.config.server.http.v2.request.HttpConfigRequests; import com.yahoo.vespa.config.server.tenant.TenantRepository; import com.yahoo.vespa.config.server.http.HttpConfigRequest; import com.yahoo.vespa.config.server.http.HttpConfigResponse; diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpListConfigsHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpListConfigsHandler.java index 71be471193a..3210f5eb8e5 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpListConfigsHandler.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpListConfigsHandler.java @@ -15,6 +15,8 @@ import com.yahoo.slime.JsonFormat; import com.yahoo.slime.Slime; import com.yahoo.vespa.config.ConfigKey; import com.yahoo.vespa.config.server.RequestHandler; +import com.yahoo.vespa.config.server.http.v2.request.HttpConfigRequests; +import com.yahoo.vespa.config.server.http.v2.request.HttpListConfigsRequest; import com.yahoo.vespa.config.server.tenant.TenantRepository; import com.yahoo.config.provision.ApplicationId; import com.yahoo.vespa.config.server.http.HttpConfigResponse; diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpListConfigsRequest.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpListConfigsRequest.java deleted file mode 100644 index 208b682df9a..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpListConfigsRequest.java +++ /dev/null @@ -1,156 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.config.server.http.v2; - -import com.yahoo.collections.Tuple2; -import com.yahoo.config.provision.ApplicationName; -import com.yahoo.config.provision.TenantName; -import com.yahoo.container.jdisc.HttpRequest; -import com.yahoo.jdisc.application.BindingMatch; -import com.yahoo.vespa.config.ConfigKey; -import com.yahoo.config.provision.ApplicationId; -import com.yahoo.vespa.config.server.http.HttpConfigRequest; - -/** - * A request to list config, bound to tenant and app id. Optionally bound to a config key, for request for named config. - * - * @author vegardh - * - */ -public class HttpListConfigsRequest implements TenantRequest { - private final ConfigKey key; // non-null if it's a named list request - private final ApplicationId appId; - private final boolean recursive; - private final boolean fullAppId; - - private HttpListConfigsRequest(ConfigKey key, ApplicationId appId, boolean recursive, boolean fullAppId) { - this.key = key; - this.appId = appId; - this.recursive = recursive; - this.fullAppId = fullAppId; - } - - public static HttpListConfigsRequest createFromListRequest(HttpRequest req) { - BindingMatch bm = HttpConfigRequests.getBindingMatch(req, - "http://*/config/v2/tenant/*/application/*/environment/*/region/*/instance/*/", - "http://*/config/v2/tenant/*/application/*/"); - if (bm.groupCount()>4) return createFromListRequestFullAppId(req, bm); - return createFromListRequestSimpleAppId(req, bm); - } - - private static HttpListConfigsRequest createFromListRequestSimpleAppId(HttpRequest req, BindingMatch bm) { - TenantName tenant = TenantName.from(bm.group(2)); - ApplicationName application = ApplicationName.from(bm.group(3)); - return new HttpListConfigsRequest(null, new ApplicationId.Builder().tenant(tenant).applicationName(application).build(), - req.getBooleanProperty(HttpConfigRequests.RECURSIVE_QUERY_PROPERTY), false); - } - - private static HttpListConfigsRequest createFromListRequestFullAppId(HttpRequest req, BindingMatch bm) { - String tenant = bm.group(2); - String application = bm.group(3); - String environment = bm.group(4); - String region = bm.group(5); - String instance = bm.group(6); - - ApplicationId appId = new ApplicationId.Builder() - .tenant(tenant) - .applicationName(application) - .instanceName(instance) - .build(); - return new HttpListConfigsRequest(null, appId, - req.getBooleanProperty(HttpConfigRequests.RECURSIVE_QUERY_PROPERTY), true); - } - - public static HttpListConfigsRequest createFromNamedListRequest(HttpRequest req) { - // http://*/config/v2/tenant/*/application/*/*/ - // http://*/config/v2/tenant/*/application/*/*/*/ - // http://*/config/v2/tenant/*/application/*/environment/*/region/*/instance/*/*/ - // http://*/config/v2/tenant/*/application/*/environment/*/region/*/instance/*/*/*/ - BindingMatch bm = HttpConfigRequests.getBindingMatch(req, - "http://*/config/v2/tenant/*/application/*/environment/*/region/*/instance/*/*/*/", - "http://*/config/v2/tenant/*/application/*/*/*/"); - if (bm.groupCount()>6) return createFromNamedListRequestFullAppId(req, bm); - return createFromNamedListRequestSimpleAppId(req, bm); - } - - private static HttpListConfigsRequest createFromNamedListRequestSimpleAppId(HttpRequest req, BindingMatch bm) { - TenantName tenant = TenantName.from(bm.group(2)); - ApplicationName application = ApplicationName.from(bm.group(3)); - String conf = bm.group(4); - String cId; - String cName; - String cNamespace; - if (bm.groupCount() >= 6) { - cId = bm.group(5); - } else { - cId = ""; - } - Tuple2 nns = HttpConfigRequest.nameAndNamespace(conf); - cName = nns.first; - cNamespace = nns.second; - ConfigKey key = new ConfigKey<>(cName, cId, cNamespace); - return new HttpListConfigsRequest(key, new ApplicationId.Builder().tenant(tenant).applicationName(application).build(), - req.getBooleanProperty(HttpConfigRequests.RECURSIVE_QUERY_PROPERTY), false); - } - - private static HttpListConfigsRequest createFromNamedListRequestFullAppId(HttpRequest req, BindingMatch bm) { - String tenant = bm.group(2); - String application = bm.group(3); - String environment = bm.group(4); - String region = bm.group(5); - String instance = bm.group(6); - String conf = bm.group(7); - String cId; - String cName; - String cNamespace; - if (bm.groupCount() >= 9) { - cId = bm.group(8); - } else { - cId = ""; - } - Tuple2 nns = HttpConfigRequest.nameAndNamespace(conf); - cName = nns.first; - cNamespace = nns.second; - ConfigKey key = new ConfigKey<>(cName, cId, cNamespace); - ApplicationId appId = new ApplicationId.Builder() - .tenant(tenant) - .applicationName(application) - .instanceName(instance) - .build(); - return new HttpListConfigsRequest(key, appId, - req.getBooleanProperty(HttpConfigRequests.RECURSIVE_QUERY_PROPERTY), true); - } - - /** - * The application id of the request - * @return app id - */ - @Override - public ApplicationId getApplicationId() { - return appId; - } - - /** - * True if the request was of the recursive form - * @return recursive - */ - public boolean isRecursive() { - return recursive; - } - - /** - * True if this was created using a URL with tenant, application, environment, region and instance; false if only tenant and application - * @return true if full app id used - */ - public boolean isFullAppId() { - return fullAppId; - } - - /** - * Returns the config key of the request if it was for a named config, or null if it was just a listing request - * @return key or null - */ - public ConfigKey getKey() { - return key; - } - -} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpListNamedConfigsHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpListNamedConfigsHandler.java index bbc2efe9c36..425aa1c2bd2 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpListNamedConfigsHandler.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpListNamedConfigsHandler.java @@ -10,6 +10,8 @@ import com.yahoo.container.jdisc.HttpRequest; import com.yahoo.container.jdisc.HttpResponse; import com.yahoo.vespa.config.ConfigKey; import com.yahoo.vespa.config.server.RequestHandler; +import com.yahoo.vespa.config.server.http.v2.request.HttpConfigRequests; +import com.yahoo.vespa.config.server.http.v2.request.HttpListConfigsRequest; import com.yahoo.vespa.config.server.tenant.TenantRepository; import com.yahoo.config.provision.ApplicationId; import com.yahoo.vespa.config.server.http.HttpConfigRequest; diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionContentHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionContentHandler.java index 9f526bbdce8..4664fdf3557 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionContentHandler.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionContentHandler.java @@ -11,6 +11,7 @@ import com.yahoo.vespa.config.server.http.ContentRequest; import com.yahoo.vespa.config.server.http.ContentHandler; import com.yahoo.vespa.config.server.http.SessionHandler; import com.yahoo.vespa.config.server.http.Utils; +import com.yahoo.vespa.config.server.http.v2.request.SessionContentRequestV2; /** * A handler that will return content or content status for files or directories diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionContentRequestV2.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionContentRequestV2.java deleted file mode 100644 index c5a9d36f493..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionContentRequestV2.java +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.config.server.http.v2; - -import com.yahoo.config.application.api.ApplicationFile; -import com.yahoo.config.provision.TenantName; -import com.yahoo.container.jdisc.HttpRequest; -import com.yahoo.jdisc.application.BindingMatch; -import com.yahoo.vespa.config.server.http.ContentRequest; -import com.yahoo.vespa.config.server.http.Utils; - -/** - * Requests for content and content status (v2) - * are handled by this class. - * - * @author hmusum - * @since 5.3 - */ -public class SessionContentRequestV2 extends ContentRequest { - private static final String uriPattern = "http://*/application/v2/tenant/*/session/*/content/*"; - private final TenantName tenantName; - private final long sessionId; - - SessionContentRequestV2(HttpRequest request, - long sessionId, - TenantName tenantName, - String path, - ApplicationFile applicationFile) { - super(request, sessionId, path, applicationFile); - this.tenantName = tenantName; - this.sessionId = sessionId; - } - - @Override - public String getPathPrefix() { - return "/application/v2/tenant/" + tenantName.value() + "/session/" + sessionId; - } - - static String getContentPath(HttpRequest request) { - BindingMatch bm = Utils.getBindingMatch(request, uriPattern); - return bm.group(4); - } -} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/TenantRequest.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/TenantRequest.java deleted file mode 100644 index 0fae091aa78..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/TenantRequest.java +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.config.server.http.v2; - -import com.yahoo.config.provision.ApplicationId; - -/** - * Config REST requests that have been bound to an application id - * - * @author vegardh - */ -public interface TenantRequest { - - ApplicationId getApplicationId(); - -} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/request/ApplicationContentRequest.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/request/ApplicationContentRequest.java new file mode 100644 index 00000000000..b7ec6272c3a --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/request/ApplicationContentRequest.java @@ -0,0 +1,43 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.config.server.http.v2.request; + +import com.yahoo.config.application.api.ApplicationFile; +import com.yahoo.config.provision.ApplicationId; +import com.yahoo.config.provision.Zone; +import com.yahoo.container.jdisc.HttpRequest; +import com.yahoo.vespa.config.server.http.ContentRequest; + +/** + * Represents a content request for an application. + * + * @author Ulf Lilleengen + * @since 5.3 + */ +public class ApplicationContentRequest extends ContentRequest { + + private final ApplicationId applicationId; + private final Zone zone; + + public ApplicationContentRequest(HttpRequest request, + long sessionId, + ApplicationId applicationId, + Zone zone, + String contentPath, + ApplicationFile applicationFile) { + super(request, sessionId, contentPath, applicationFile); + this.applicationId = applicationId; + this.zone = zone; + } + + @Override + public String getPathPrefix() { + StringBuilder sb = new StringBuilder(); + sb.append("/application/v2/tenant/").append(applicationId.tenant().value()); + sb.append("/application/").append(applicationId.application().value()); + sb.append("/environment/").append(zone.environment().value()); + sb.append("/region/").append(zone.region().value()); + sb.append("/instance/").append(applicationId.instance().value()); + return sb.toString(); + } + +} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/request/HttpConfigRequests.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/request/HttpConfigRequests.java new file mode 100644 index 00000000000..d190ccaec12 --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/request/HttpConfigRequests.java @@ -0,0 +1,54 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.config.server.http.v2.request; + +import java.net.URI; + +import com.yahoo.container.jdisc.HttpRequest; +import com.yahoo.jdisc.application.BindingMatch; +import com.yahoo.jdisc.application.UriPattern; +import com.yahoo.jdisc.application.UriPattern.Match; +import com.yahoo.vespa.config.server.RequestHandler; +import com.yahoo.vespa.config.server.tenant.Tenant; +import com.yahoo.vespa.config.server.tenant.TenantRepository; +import com.yahoo.vespa.config.server.http.NotFoundException; + +/** + * Helpers for v2 config REST API + * + * @author vegardh + */ +public class HttpConfigRequests { + + static final String RECURSIVE_QUERY_PROPERTY = "recursive"; + + /** + * Produces the binding match for the request. If it's not available on the jDisc request, create one for + * testing using the long and short app id URL patterns given. + * @param req an {@link com.yahoo.container.jdisc.HttpRequest} + * @param patterns A list of patterns that should be matched if no match on binding. + * @return match + */ + public static BindingMatch getBindingMatch(HttpRequest req, String ... patterns) { + com.yahoo.jdisc.http.HttpRequest jDiscRequest = req.getJDiscRequest(); + if (jDiscRequest==null) throw new IllegalArgumentException("No JDisc request for: " + req.getUri()); + BindingMatch jdBm = jDiscRequest.getBindingMatch(); + if (jdBm!=null) return jdBm; + + // If not, use provided patterns + for (String pattern : patterns) { + UriPattern fullAppIdPattern = new UriPattern(pattern); + URI uri = req.getUri(); + Match match = fullAppIdPattern.match(uri); + if (match!=null) return new BindingMatch<>(match, new Object(), fullAppIdPattern); + } + throw new IllegalArgumentException("Illegal url for config request: " + req.getUri()); + } + + + public static RequestHandler getRequestHandler(TenantRepository tenantRepository, TenantRequest request) { + Tenant tenant = tenantRepository.getTenant(request.getApplicationId().tenant()); + if (tenant==null) throw new NotFoundException("No such tenant: "+request.getApplicationId().tenant()); + return tenant.getRequestHandler(); + } + +} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/request/HttpListConfigsRequest.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/request/HttpListConfigsRequest.java new file mode 100644 index 00000000000..cd9c44db85b --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/request/HttpListConfigsRequest.java @@ -0,0 +1,156 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.config.server.http.v2.request; + +import com.yahoo.collections.Tuple2; +import com.yahoo.config.provision.ApplicationName; +import com.yahoo.config.provision.TenantName; +import com.yahoo.container.jdisc.HttpRequest; +import com.yahoo.jdisc.application.BindingMatch; +import com.yahoo.vespa.config.ConfigKey; +import com.yahoo.config.provision.ApplicationId; +import com.yahoo.vespa.config.server.http.HttpConfigRequest; + +/** + * A request to list config, bound to tenant and app id. Optionally bound to a config key, for request for named config. + * + * @author vegardh + * + */ +public class HttpListConfigsRequest implements TenantRequest { + private final ConfigKey key; // non-null if it's a named list request + private final ApplicationId appId; + private final boolean recursive; + private final boolean fullAppId; + + private HttpListConfigsRequest(ConfigKey key, ApplicationId appId, boolean recursive, boolean fullAppId) { + this.key = key; + this.appId = appId; + this.recursive = recursive; + this.fullAppId = fullAppId; + } + + public static HttpListConfigsRequest createFromListRequest(HttpRequest req) { + BindingMatch bm = HttpConfigRequests.getBindingMatch(req, + "http://*/config/v2/tenant/*/application/*/environment/*/region/*/instance/*/", + "http://*/config/v2/tenant/*/application/*/"); + if (bm.groupCount()>4) return createFromListRequestFullAppId(req, bm); + return createFromListRequestSimpleAppId(req, bm); + } + + private static HttpListConfigsRequest createFromListRequestSimpleAppId(HttpRequest req, BindingMatch bm) { + TenantName tenant = TenantName.from(bm.group(2)); + ApplicationName application = ApplicationName.from(bm.group(3)); + return new HttpListConfigsRequest(null, new ApplicationId.Builder().tenant(tenant).applicationName(application).build(), + req.getBooleanProperty(HttpConfigRequests.RECURSIVE_QUERY_PROPERTY), false); + } + + private static HttpListConfigsRequest createFromListRequestFullAppId(HttpRequest req, BindingMatch bm) { + String tenant = bm.group(2); + String application = bm.group(3); + String environment = bm.group(4); + String region = bm.group(5); + String instance = bm.group(6); + + ApplicationId appId = new ApplicationId.Builder() + .tenant(tenant) + .applicationName(application) + .instanceName(instance) + .build(); + return new HttpListConfigsRequest(null, appId, + req.getBooleanProperty(HttpConfigRequests.RECURSIVE_QUERY_PROPERTY), true); + } + + public static HttpListConfigsRequest createFromNamedListRequest(HttpRequest req) { + // http://*/config/v2/tenant/*/application/*/*/ + // http://*/config/v2/tenant/*/application/*/*/*/ + // http://*/config/v2/tenant/*/application/*/environment/*/region/*/instance/*/*/ + // http://*/config/v2/tenant/*/application/*/environment/*/region/*/instance/*/*/*/ + BindingMatch bm = HttpConfigRequests.getBindingMatch(req, + "http://*/config/v2/tenant/*/application/*/environment/*/region/*/instance/*/*/*/", + "http://*/config/v2/tenant/*/application/*/*/*/"); + if (bm.groupCount()>6) return createFromNamedListRequestFullAppId(req, bm); + return createFromNamedListRequestSimpleAppId(req, bm); + } + + private static HttpListConfigsRequest createFromNamedListRequestSimpleAppId(HttpRequest req, BindingMatch bm) { + TenantName tenant = TenantName.from(bm.group(2)); + ApplicationName application = ApplicationName.from(bm.group(3)); + String conf = bm.group(4); + String cId; + String cName; + String cNamespace; + if (bm.groupCount() >= 6) { + cId = bm.group(5); + } else { + cId = ""; + } + Tuple2 nns = HttpConfigRequest.nameAndNamespace(conf); + cName = nns.first; + cNamespace = nns.second; + ConfigKey key = new ConfigKey<>(cName, cId, cNamespace); + return new HttpListConfigsRequest(key, new ApplicationId.Builder().tenant(tenant).applicationName(application).build(), + req.getBooleanProperty(HttpConfigRequests.RECURSIVE_QUERY_PROPERTY), false); + } + + private static HttpListConfigsRequest createFromNamedListRequestFullAppId(HttpRequest req, BindingMatch bm) { + String tenant = bm.group(2); + String application = bm.group(3); + String environment = bm.group(4); + String region = bm.group(5); + String instance = bm.group(6); + String conf = bm.group(7); + String cId; + String cName; + String cNamespace; + if (bm.groupCount() >= 9) { + cId = bm.group(8); + } else { + cId = ""; + } + Tuple2 nns = HttpConfigRequest.nameAndNamespace(conf); + cName = nns.first; + cNamespace = nns.second; + ConfigKey key = new ConfigKey<>(cName, cId, cNamespace); + ApplicationId appId = new ApplicationId.Builder() + .tenant(tenant) + .applicationName(application) + .instanceName(instance) + .build(); + return new HttpListConfigsRequest(key, appId, + req.getBooleanProperty(HttpConfigRequests.RECURSIVE_QUERY_PROPERTY), true); + } + + /** + * The application id of the request + * @return app id + */ + @Override + public ApplicationId getApplicationId() { + return appId; + } + + /** + * True if the request was of the recursive form + * @return recursive + */ + public boolean isRecursive() { + return recursive; + } + + /** + * True if this was created using a URL with tenant, application, environment, region and instance; false if only tenant and application + * @return true if full app id used + */ + public boolean isFullAppId() { + return fullAppId; + } + + /** + * Returns the config key of the request if it was for a named config, or null if it was just a listing request + * @return key or null + */ + public ConfigKey getKey() { + return key; + } + +} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/request/SessionContentRequestV2.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/request/SessionContentRequestV2.java new file mode 100644 index 00000000000..4f34b2fb332 --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/request/SessionContentRequestV2.java @@ -0,0 +1,42 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.config.server.http.v2.request; + +import com.yahoo.config.application.api.ApplicationFile; +import com.yahoo.config.provision.TenantName; +import com.yahoo.container.jdisc.HttpRequest; +import com.yahoo.jdisc.application.BindingMatch; +import com.yahoo.vespa.config.server.http.ContentRequest; +import com.yahoo.vespa.config.server.http.Utils; + +/** + * Requests for content and content status (v2) + * are handled by this class. + * + * @author hmusum + * @since 5.3 + */ +public class SessionContentRequestV2 extends ContentRequest { + private static final String uriPattern = "http://*/application/v2/tenant/*/session/*/content/*"; + private final TenantName tenantName; + private final long sessionId; + + public SessionContentRequestV2(HttpRequest request, + long sessionId, + TenantName tenantName, + String path, + ApplicationFile applicationFile) { + super(request, sessionId, path, applicationFile); + this.tenantName = tenantName; + this.sessionId = sessionId; + } + + @Override + public String getPathPrefix() { + return "/application/v2/tenant/" + tenantName.value() + "/session/" + sessionId; + } + + public static String getContentPath(HttpRequest request) { + BindingMatch bm = Utils.getBindingMatch(request, uriPattern); + return bm.group(4); + } +} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/request/TenantRequest.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/request/TenantRequest.java new file mode 100644 index 00000000000..84071ca2a98 --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/request/TenantRequest.java @@ -0,0 +1,15 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.config.server.http.v2.request; + +import com.yahoo.config.provision.ApplicationId; + +/** + * Config REST requests that have been bound to an application id + * + * @author vegardh + */ +public interface TenantRequest { + + ApplicationId getApplicationId(); + +} -- cgit v1.2.3 From 316ff09406bc1dcef0558f90755a12109824e81d Mon Sep 17 00:00:00 2001 From: Valerij Fredriksen Date: Tue, 6 Jul 2021 16:58:25 +0200 Subject: Cleanup ApplicationHandler --- .../config/server/http/v2/ApplicationHandler.java | 452 +++++++-------------- 1 file changed, 145 insertions(+), 307 deletions(-) (limited to 'configserver') diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java index f1704af99c8..e56fb0b1bcc 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java @@ -6,24 +6,22 @@ import com.yahoo.component.Version; import com.yahoo.config.application.api.ApplicationFile; import com.yahoo.config.model.api.Model; import com.yahoo.config.provision.ApplicationId; -import com.yahoo.config.provision.ApplicationName; import com.yahoo.config.provision.HostFilter; -import com.yahoo.config.provision.TenantName; +import com.yahoo.config.provision.InstanceName; import com.yahoo.config.provision.Zone; import com.yahoo.container.jdisc.HttpRequest; import com.yahoo.container.jdisc.HttpResponse; import com.yahoo.io.IOUtils; import com.yahoo.jdisc.Response; -import com.yahoo.jdisc.application.BindingMatch; -import com.yahoo.jdisc.application.UriPattern; +import com.yahoo.restapi.ErrorResponse; +import com.yahoo.restapi.MessageResponse; +import com.yahoo.restapi.Path; import com.yahoo.slime.SlimeUtils; import com.yahoo.text.StringUtilities; import com.yahoo.vespa.config.server.ApplicationRepository; import com.yahoo.vespa.config.server.http.ContentHandler; import com.yahoo.vespa.config.server.http.ContentRequest; -import com.yahoo.vespa.config.server.http.HttpErrorResponse; import com.yahoo.vespa.config.server.http.HttpHandler; -import com.yahoo.vespa.config.server.http.JSONResponse; import com.yahoo.vespa.config.server.http.NotFoundException; import com.yahoo.vespa.config.server.http.v2.request.ApplicationContentRequest; import com.yahoo.vespa.config.server.http.v2.response.ApplicationSuspendedResponse; @@ -34,22 +32,16 @@ import com.yahoo.vespa.config.server.http.v2.response.ReindexingResponse; import com.yahoo.vespa.config.server.tenant.Tenant; import java.io.IOException; -import java.net.URLDecoder; import java.time.Duration; import java.time.Instant; -import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.StringJoiner; import java.util.TreeMap; import java.util.TreeSet; -import java.util.stream.Stream; import static com.yahoo.yolean.Exceptions.uncheck; -import static java.nio.charset.StandardCharsets.UTF_8; -import static java.util.stream.Collectors.toList; /** * Operations on applications (delete, wait for config convergence, restart, application content etc.) @@ -58,28 +50,6 @@ import static java.util.stream.Collectors.toList; */ public class ApplicationHandler extends HttpHandler { - private static final List URI_PATTERNS = Stream.of( - "http://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/content/*", - "http://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/filedistributionstatus", - "http://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/restart", - "http://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/reindex", - "http://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/reindexing", - "http://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/suspended", - "http://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/serviceconverge", - "http://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/serviceconverge/*", - "http://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/clustercontroller/*/status/*", - "http://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/metrics/*", - "http://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/metrics/*", - "http://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/logs", - "http://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/validate-secret-store", - "http://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/tester/*/*", - "http://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/tester/*", - "http://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/quota", - "http://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*", - "http://*/application/v2/tenant/*/application/*") - .map(UriPattern::new) - .collect(toList()); - private final Zone zone; private final ApplicationRepository applicationRepository; @@ -93,152 +63,135 @@ public class ApplicationHandler extends HttpHandler { } @Override - public HttpResponse handleDELETE(HttpRequest request) { - ApplicationId applicationId = getApplicationIdFromRequest(request); - - if (isReindexingRequest(request)) { - applicationRepository.modifyReindexing(applicationId, reindexing -> reindexing.enabled(false)); - return createMessageResponse("Reindexing disabled"); - } + public HttpResponse handleGET(HttpRequest request) { + Path path = new Path(request.getUri()); + + if (path.matches("/application/v2/tenant/{tenant}/application/{application}")) return getApplicationResponse(ApplicationId.from(path.get("tenant"), path.get("application"), InstanceName.defaultName().value())); + if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}")) return getApplicationResponse(applicationId(path)); + if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/clustercontroller/{hostname}/status/{*}")) return clusterControllerStatusPage(applicationId(path), path.get("hostname"), path.getRest()); + if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/content/{*}")) return content(applicationId(path), path.getRest(), request); + if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/filedistributionstatus")) return filedistributionStatus(applicationId(path), request); + if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/logs")) return logs(applicationId(path), request); + if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/metrics/deployment")) return deploymentMetrics(applicationId(path)); + if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/metrics/proton")) return protonMetrics(applicationId(path)); + if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/reindexing")) return getReindexingStatus(applicationId(path)); + if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/serviceconverge")) return listServiceConverge(applicationId(path), request); + if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/serviceconverge/{hostAndPort}")) return checkServiceConverge(applicationId(path), path.get("hostAndPort"), request); + if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/suspended")) return isSuspended(applicationId(path)); + if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/tester/{command}")) return testerRequest(applicationId(path), path.get("command"), request); + if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/quota")) return quotaUsage(applicationId(path)); + return ErrorResponse.notFoundError("Nothing at " + path); + } - if (applicationRepository.delete(applicationId)) - return new DeleteApplicationResponse(applicationId); + @Override + public HttpResponse handlePOST(HttpRequest request) { + Path path = new Path(request.getUri()); - return HttpErrorResponse.notFoundError("Unable to delete " + applicationId.toFullString() + ": Not found"); + if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/reindex")) return triggerReindexing(applicationId(path), request); + if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/reindexing")) return enableReindexing(applicationId(path)); + if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/restart")) return restart(applicationId(path), request); + if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/tester/run/{suite}")) return testerStartTests(applicationId(path), path.get("suite"), request); + if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/validate-secret-store")) return validateSecretStore(applicationId(path), request); + return ErrorResponse.notFoundError("Nothing at " + path); } @Override - public HttpResponse handleGET(HttpRequest request) { - ApplicationId applicationId = getApplicationIdFromRequest(request); - Duration timeout = HttpHandler.getRequestTimeout(request, Duration.ofSeconds(5)); - - if (isServiceConvergeRequest(request)) { - // Expects both hostname and port in the request (hostname:port) - String hostAndPort = getHostNameFromRequest(request); - return applicationRepository.checkServiceForConfigConvergence(applicationId, hostAndPort, request.getUri(), - timeout, getVespaVersionFromRequest(request)); - } + public HttpResponse handleDELETE(HttpRequest request) { + Path path = new Path(request.getUri()); - if (isClusterControllerStatusRequest(request)) { - String hostName = getHostNameFromRequest(request); - String pathSuffix = URLDecoder.decode(getPathSuffix(request), UTF_8); - return applicationRepository.clusterControllerStatusPage(applicationId, hostName, pathSuffix); - } + if (path.matches("/application/v2/tenant/{tenant}/application/{application}")) return deleteApplication(ApplicationId.from(path.get("tenant"), path.get("application"), InstanceName.defaultName().value())); + if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}")) return deleteApplication(applicationId(path)); + if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/reindexing")) return disableReindexing(applicationId(path)); + return ErrorResponse.notFoundError("Nothing at " + path); + } - if (isReindexingRequest(request)) { - return getReindexingStatus(applicationId); - } + private HttpResponse listServiceConverge(ApplicationId applicationId, HttpRequest request) { + return applicationRepository.servicesToCheckForConfigConvergence(applicationId, request.getUri(), + getTimeoutFromRequest(request), getVespaVersionFromRequest(request)); + } - if (isContentRequest(request)) { - long sessionId = applicationRepository.getSessionIdForApplication(applicationId); - String contentPath = getBindingMatch(request).group(7); - ApplicationFile applicationFile = - applicationRepository.getApplicationFileFromSession(applicationId.tenant(), - sessionId, - contentPath, - ContentRequest.getApplicationFileMode(request.getMethod())); - ApplicationContentRequest contentRequest = new ApplicationContentRequest(request, - sessionId, - applicationId, - zone, - contentPath, - applicationFile); - return new ContentHandler().get(contentRequest); - } + private HttpResponse checkServiceConverge(ApplicationId applicationId, String hostAndPort, HttpRequest request) { + return applicationRepository.checkServiceForConfigConvergence(applicationId, hostAndPort, request.getUri(), + getTimeoutFromRequest(request), getVespaVersionFromRequest(request)); + } - if (isServiceConvergeListRequest(request)) { - return applicationRepository.servicesToCheckForConfigConvergence(applicationId, request.getUri(), timeout, - getVespaVersionFromRequest(request)); - } + private HttpResponse clusterControllerStatusPage(ApplicationId applicationId, String hostname, String pathSuffix) { + return applicationRepository.clusterControllerStatusPage(applicationId, hostname, pathSuffix); + } - if (isFiledistributionStatusRequest(request)) { - return applicationRepository.filedistributionStatus(applicationId, timeout); - } + private HttpResponse content(ApplicationId applicationId, String contentPath, HttpRequest request) { + long sessionId = applicationRepository.getSessionIdForApplication(applicationId); + ApplicationFile applicationFile = + applicationRepository.getApplicationFileFromSession(applicationId.tenant(), + sessionId, + contentPath, + ContentRequest.getApplicationFileMode(request.getMethod())); + ApplicationContentRequest contentRequest = new ApplicationContentRequest(request, + sessionId, + applicationId, + zone, + contentPath, + applicationFile); + return new ContentHandler().get(contentRequest); + } - if (isLogRequest(request)) { - Optional hostname = Optional.ofNullable(request.getProperty("hostname")); - String apiParams = Optional.ofNullable(request.getUri().getQuery()).map(q -> "?" + q).orElse(""); - return applicationRepository.getLogs(applicationId, hostname, apiParams); - } + private HttpResponse filedistributionStatus(ApplicationId applicationId, HttpRequest request) { + return applicationRepository.filedistributionStatus(applicationId, getTimeoutFromRequest(request)); + } - if (isProtonMetricsRequest(request)) { - return applicationRepository.getProtonMetrics(applicationId); - } + private HttpResponse logs(ApplicationId applicationId, HttpRequest request) { + Optional hostname = Optional.ofNullable(request.getProperty("hostname")); + String apiParams = Optional.ofNullable(request.getUri().getQuery()).map(q -> "?" + q).orElse(""); + return applicationRepository.getLogs(applicationId, hostname, apiParams); + } - if (isDeploymentMetricsRequest(request)) { - return applicationRepository.getDeploymentMetrics(applicationId); - } + private HttpResponse protonMetrics(ApplicationId applicationId) { + return applicationRepository.getProtonMetrics(applicationId); + } - if (isIsSuspendedRequest(request)) { - return new ApplicationSuspendedResponse(applicationRepository.isSuspended(applicationId)); - } + private HttpResponse deploymentMetrics(ApplicationId applicationId) { + return applicationRepository.getDeploymentMetrics(applicationId); + } - if (isTesterRequest(request)) { - String testerCommand = getTesterCommandFromRequest(request); - switch (testerCommand) { - case "status": - return applicationRepository.getTesterStatus(applicationId); - case "log": - Long after = Long.valueOf(request.getProperty("after")); - return applicationRepository.getTesterLog(applicationId, after); - case "ready": - return applicationRepository.isTesterReady(applicationId); - case "report": - return applicationRepository.getTestReport(applicationId); - default: - throw new IllegalArgumentException("Unknown tester command in request " + request.getUri().toString()); - } - } + private HttpResponse isSuspended(ApplicationId applicationId) { + return new ApplicationSuspendedResponse(applicationRepository.isSuspended(applicationId)); + } - if (isQuotaUsageRequest(request)) { - var quotaUsageRate = applicationRepository.getQuotaUsageRate(applicationId); - return new QuotaUsageResponse(quotaUsageRate); + private HttpResponse testerRequest(ApplicationId applicationId, String command, HttpRequest request) { + switch (command) { + case "status": + return applicationRepository.getTesterStatus(applicationId); + case "log": + Long after = Long.valueOf(request.getProperty("after")); + return applicationRepository.getTesterLog(applicationId, after); + case "ready": + return applicationRepository.isTesterReady(applicationId); + case "report": + return applicationRepository.getTestReport(applicationId); + default: + throw new IllegalArgumentException("Unknown tester command in request " + request.getUri().toString()); } + } - return getApplicationResponse(applicationId); + private HttpResponse quotaUsage(ApplicationId applicationId) { + double quotaUsageRate = applicationRepository.getQuotaUsageRate(applicationId); + return new QuotaUsageResponse(quotaUsageRate); } - GetApplicationResponse getApplicationResponse(ApplicationId applicationId) { + private HttpResponse getApplicationResponse(ApplicationId applicationId) { return new GetApplicationResponse(Response.Status.OK, - applicationRepository.getApplicationGeneration(applicationId), - applicationRepository.getAllVersions(applicationId), - applicationRepository.getApplicationPackageReference(applicationId)); + applicationRepository.getApplicationGeneration(applicationId), + applicationRepository.getAllVersions(applicationId), + applicationRepository.getApplicationPackageReference(applicationId)); } - @Override - public HttpResponse handlePOST(HttpRequest request) { - ApplicationId applicationId = getApplicationIdFromRequest(request); - - if (isRestartRequest(request)) - return restart(request, applicationId); - - if (isTesterStartTestsRequest(request)) { - byte[] data; - try { - data = IOUtils.readBytes(request.getData(), 1024 * 1000); - } catch (IOException e) { - throw new IllegalArgumentException("Could not read data in request " + request); - } - return applicationRepository.startTests(applicationId, getSuiteFromRequest(request), data); - } - - if (isReindexRequest(request)) { - return triggerReindexing(request, applicationId); - } - - if (isReindexingRequest(request)) { - applicationRepository.modifyReindexing(applicationId, reindexing -> reindexing.enabled(true)); - return createMessageResponse("Reindexing enabled"); - } - - if (isValidateSecretStoreRequest(request)) { - var slime = uncheck(() -> SlimeUtils.jsonToSlime(request.getData().readAllBytes())); - return applicationRepository.validateSecretStore(applicationId, zone.system(), slime); - } - - throw new NotFoundException("Illegal POST request '" + request.getUri() + "'"); + public HttpResponse deleteApplication(ApplicationId applicationId) { + if (applicationRepository.delete(applicationId)) + return new DeleteApplicationResponse(applicationId); + return ErrorResponse.notFoundError("Unable to delete " + applicationId.toFullString() + ": Not found"); } + private Model getActiveModelOrThrow(ApplicationId id) { return applicationRepository.getActiveApplicationSet(id) .orElseThrow(() -> new NotFoundException("Application '" + id + "' not found")) @@ -246,7 +199,7 @@ public class ApplicationHandler extends HttpHandler { .getModel(); } - private HttpResponse triggerReindexing(HttpRequest request, ApplicationId applicationId) { + private HttpResponse triggerReindexing(ApplicationId applicationId, HttpRequest request) { Model model = getActiveModelOrThrow(applicationId); Map> documentTypes = model.documentTypesByCluster(); Map> indexedDocumentTypes = model.indexedDocumentTypesByCluster(); @@ -277,7 +230,7 @@ public class ApplicationHandler extends HttpHandler { return reindexing; }); - return createMessageResponse(reindexed.entrySet().stream() + return new MessageResponse(reindexed.entrySet().stream() .filter(cluster -> ! cluster.getValue().isEmpty()) .map(cluster -> "[" + String.join(", ", cluster.getValue()) + "] in '" + cluster.getKey() + "'") .reduce(new StringJoiner(", ", "Reindexing document types ", " of application " + applicationId) @@ -287,6 +240,16 @@ public class ApplicationHandler extends HttpHandler { .toString()); } + public HttpResponse disableReindexing(ApplicationId applicationId) { + applicationRepository.modifyReindexing(applicationId, reindexing -> reindexing.enabled(false)); + return new MessageResponse("Reindexing disabled"); + } + + private HttpResponse enableReindexing(ApplicationId applicationId) { + applicationRepository.modifyReindexing(applicationId, reindexing -> reindexing.enabled(true)); + return new MessageResponse("Reindexing enabled"); + } + private HttpResponse getReindexingStatus(ApplicationId applicationId) { Tenant tenant = applicationRepository.getTenant(applicationId); if (tenant == null) @@ -297,167 +260,42 @@ public class ApplicationHandler extends HttpHandler { applicationRepository.getClusterReindexingStatus(applicationId)); } - private HttpResponse restart(HttpRequest request, ApplicationId applicationId) { - if (getBindingMatch(request).groupCount() != 7) - throw new NotFoundException("Illegal POST restart request '" + request.getUri() + - "': Must have 6 arguments but had " + (getBindingMatch(request).groupCount() - 1)); - applicationRepository.restart(applicationId, hostFilterFrom(request)); - return new JSONResponse(Response.Status.OK); // return empty - } - - private HostFilter hostFilterFrom(HttpRequest request) { - return HostFilter.from(request.getProperty("hostname"), - request.getProperty("flavor"), - request.getProperty("clusterType"), - request.getProperty("clusterId")); - } - - private static BindingMatch getBindingMatch(HttpRequest request) { - return URI_PATTERNS.stream() - .map(pattern -> { - UriPattern.Match match = pattern.match(request.getUri()); - if (match == null) return null; - return new BindingMatch<>(match, new Object(), pattern); - }) - .filter(Objects::nonNull) - .findFirst() - .orElseThrow(() -> new IllegalArgumentException("Illegal url for config request: " + request.getUri())); - } - - private static boolean isRestartRequest(HttpRequest request) { - return getBindingMatch(request).groupCount() == 7 && - request.getUri().getPath().endsWith("/restart"); - } - - private static boolean isReindexRequest(HttpRequest request) { - return getBindingMatch(request).groupCount() == 7 && - request.getUri().getPath().endsWith("/reindex"); - } - - private static boolean isReindexingRequest(HttpRequest request) { - return getBindingMatch(request).groupCount() == 7 && - request.getUri().getPath().endsWith("/reindexing"); - } - - private static boolean isIsSuspendedRequest(HttpRequest request) { - return getBindingMatch(request).groupCount() == 7 && - request.getUri().getPath().endsWith("/suspended"); - } - - private static boolean isProtonMetricsRequest(HttpRequest request) { - return getBindingMatch(request).groupCount() == 8 && - request.getUri().getPath().endsWith("/metrics/proton"); - } - - private static boolean isDeploymentMetricsRequest(HttpRequest request) { - return getBindingMatch(request).groupCount() == 8 && - request.getUri().getPath().endsWith("/metrics/deployment"); - } - - private static boolean isLogRequest(HttpRequest request) { - return getBindingMatch(request).groupCount() == 7 && - request.getUri().getPath().endsWith("/logs"); - } - - private static boolean isValidateSecretStoreRequest(HttpRequest request) { - return getBindingMatch(request).groupCount() == 7 && - request.getUri().getPath().endsWith("/validate-secret-store"); + private HttpResponse restart(ApplicationId applicationId, HttpRequest request) { + HostFilter filter = HostFilter.from(request.getProperty("hostname"), + request.getProperty("flavor"), + request.getProperty("clusterType"), + request.getProperty("clusterId")); + applicationRepository.restart(applicationId, filter); + return new MessageResponse("Success"); } - private static boolean isServiceConvergeListRequest(HttpRequest request) { - return getBindingMatch(request).groupCount() == 7 && - request.getUri().getPath().endsWith("/serviceconverge"); - } - - private static boolean isServiceConvergeRequest(HttpRequest request) { - return getBindingMatch(request).groupCount() == 8 && - request.getUri().getPath().contains("/serviceconverge/"); - } - - private static boolean isClusterControllerStatusRequest(HttpRequest request) { - return getBindingMatch(request).groupCount() == 9 && - request.getUri().getPath().contains("/clustercontroller/"); - } - - private static boolean isContentRequest(HttpRequest request) { - return getBindingMatch(request).groupCount() > 7 && - request.getUri().getPath().contains("/content/"); - } - - private static boolean isFiledistributionStatusRequest(HttpRequest request) { - return getBindingMatch(request).groupCount() == 7 && - request.getUri().getPath().contains("/filedistributionstatus"); - } - - private static boolean isTesterRequest(HttpRequest request) { - return getBindingMatch(request).groupCount() == 8 && - request.getUri().getPath().contains("/tester"); - } - - private static boolean isTesterStartTestsRequest(HttpRequest request) { - return getBindingMatch(request).groupCount() == 9 && - request.getUri().getPath().contains("/tester/run/"); - } - - private static boolean isQuotaUsageRequest(HttpRequest request) { - return getBindingMatch(request).groupCount() == 7 && - request.getUri().getPath().endsWith("/quota"); - } - - private static String getHostNameFromRequest(HttpRequest req) { - BindingMatch bm = getBindingMatch(req); - return bm.group(7); - } - - private static String getTesterCommandFromRequest(HttpRequest req) { - BindingMatch bm = getBindingMatch(req); - return bm.group(7); - } - - private static String getSuiteFromRequest(HttpRequest req) { - BindingMatch bm = getBindingMatch(req); - return bm.group(8); - } - - private static String getPathSuffix(HttpRequest req) { - BindingMatch bm = getBindingMatch(req); - return bm.group(8); + private HttpResponse testerStartTests(ApplicationId applicationId, String suite, HttpRequest request) { + byte[] data; + try { + data = IOUtils.readBytes(request.getData(), 1024 * 1000); + } catch (IOException e) { + throw new IllegalArgumentException("Could not read data in request " + request); + } + return applicationRepository.startTests(applicationId, suite, data); } - private static ApplicationId getApplicationIdFromRequest(HttpRequest req) { - // Two bindings for this: with full app id or only application name - BindingMatch bm = getBindingMatch(req); - if (bm.groupCount() > 4) return createFromRequestFullAppId(bm); - return createFromRequestSimpleAppId(bm); + private HttpResponse validateSecretStore(ApplicationId applicationId, HttpRequest request) { + var slime = uncheck(() -> SlimeUtils.jsonToSlime(request.getData().readAllBytes())); + return applicationRepository.validateSecretStore(applicationId, zone.system(), slime); } - // The URL pattern with only tenant and application given - private static ApplicationId createFromRequestSimpleAppId(BindingMatch bm) { - TenantName tenant = TenantName.from(bm.group(2)); - ApplicationName application = ApplicationName.from(bm.group(3)); - return new ApplicationId.Builder().tenant(tenant).applicationName(application).build(); + private static ApplicationId applicationId(Path path) { + return ApplicationId.from(path.get("tenant"), path.get("application"), path.get("instance")); } - // The URL pattern with full app id given - private static ApplicationId createFromRequestFullAppId(BindingMatch bm) { - String tenant = bm.group(2); - String application = bm.group(3); - String instance = bm.group(6); - return new ApplicationId.Builder() - .tenant(tenant) - .applicationName(application).instanceName(instance) - .build(); + private static Duration getTimeoutFromRequest(HttpRequest request) { + return HttpHandler.getRequestTimeout(request, Duration.ofSeconds(5)); } private static Optional getVespaVersionFromRequest(HttpRequest request) { - String vespaVersion = request.getProperty("vespaVersion"); - return (vespaVersion == null || vespaVersion.isEmpty()) - ? Optional.empty() - : Optional.of(Version.fromString(vespaVersion)); - } - - private static JSONResponse createMessageResponse(String message) { - return new JSONResponse(Response.Status.OK) { { object.setString("message", message); } }; + return Optional.ofNullable(request.getProperty("vespaVersion")) + .filter(s -> !s.isEmpty()) + .map(Version::fromString); } } -- cgit v1.2.3 From 8c55343f66e0aac23466a1696b6de653143870a1 Mon Sep 17 00:00:00 2001 From: Valerij Fredriksen Date: Tue, 6 Jul 2021 18:38:13 +0200 Subject: Expose status page for more distributor and storagenode under /application/v2 --- .../vespa/config/server/ApplicationRepository.java | 20 ++++++++++++--- .../config/server/http/v2/ApplicationHandler.java | 8 +++--- .../server/http/v2/ApplicationHandlerTest.java | 29 ++++++++++++++++++++++ 3 files changed, 50 insertions(+), 7 deletions(-) (limited to 'configserver') diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java b/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java index 6249e3bfff8..56fd6a64305 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java @@ -547,15 +547,27 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye } } - public HttpResponse clusterControllerStatusPage(ApplicationId applicationId, String hostName, String pathSuffix) { + public HttpResponse serviceStatusPage(ApplicationId applicationId, String hostName, String serviceName, String pathSuffix) { // WARNING: pathSuffix may be given by the external user. Make sure no security issues arise... // We should be OK here, because at most, pathSuffix may change the parent path, but cannot otherwise // change the hostname and port. Exposing other paths on the cluster controller should be fine. // TODO: It would be nice to have a simple check to verify pathSuffix doesn't contain /../ components. - String relativePath = "clustercontroller-status/" + pathSuffix; + String pathPrefix; + switch (serviceName) { + case "container-clustercontroller": { + pathPrefix = "clustercontroller-status/v1/"; + break; + } + case "distributor": + case "storagenode": { + pathPrefix = ""; + break; + } + default: + throw new NotFoundException("No status page for service: " + serviceName); + } - return httpProxy.get(getApplication(applicationId), hostName, - CLUSTERCONTROLLER_CONTAINER.serviceName, relativePath); + return httpProxy.get(getApplication(applicationId), hostName, serviceName, pathPrefix + pathSuffix); } public Map getClusterReindexingStatus(ApplicationId applicationId) { diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java index e56fb0b1bcc..7691748a4cf 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java @@ -5,6 +5,7 @@ import com.google.inject.Inject; import com.yahoo.component.Version; import com.yahoo.config.application.api.ApplicationFile; import com.yahoo.config.model.api.Model; +import com.yahoo.config.model.api.container.ContainerServiceType; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.HostFilter; import com.yahoo.config.provision.InstanceName; @@ -68,13 +69,14 @@ public class ApplicationHandler extends HttpHandler { if (path.matches("/application/v2/tenant/{tenant}/application/{application}")) return getApplicationResponse(ApplicationId.from(path.get("tenant"), path.get("application"), InstanceName.defaultName().value())); if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}")) return getApplicationResponse(applicationId(path)); - if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/clustercontroller/{hostname}/status/{*}")) return clusterControllerStatusPage(applicationId(path), path.get("hostname"), path.getRest()); + if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/clustercontroller/{hostname}/status/v1/{*}")) return serviceStatusPage(applicationId(path), ContainerServiceType.CLUSTERCONTROLLER_CONTAINER.serviceName, path.get("hostname"), path.getRest()); // TODO (freva): Remove August 2021 if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/content/{*}")) return content(applicationId(path), path.getRest(), request); if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/filedistributionstatus")) return filedistributionStatus(applicationId(path), request); if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/logs")) return logs(applicationId(path), request); if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/metrics/deployment")) return deploymentMetrics(applicationId(path)); if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/metrics/proton")) return protonMetrics(applicationId(path)); if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/reindexing")) return getReindexingStatus(applicationId(path)); + if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/service/{service}/{hostname}/status/{*}")) return serviceStatusPage(applicationId(path), path.get("service"), path.get("hostname"), path.getRest()); if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/serviceconverge")) return listServiceConverge(applicationId(path), request); if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/serviceconverge/{hostAndPort}")) return checkServiceConverge(applicationId(path), path.get("hostAndPort"), request); if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/suspended")) return isSuspended(applicationId(path)); @@ -115,8 +117,8 @@ public class ApplicationHandler extends HttpHandler { getTimeoutFromRequest(request), getVespaVersionFromRequest(request)); } - private HttpResponse clusterControllerStatusPage(ApplicationId applicationId, String hostname, String pathSuffix) { - return applicationRepository.clusterControllerStatusPage(applicationId, hostname, pathSuffix); + private HttpResponse serviceStatusPage(ApplicationId applicationId, String service, String hostname, String pathSuffix) { + return applicationRepository.serviceStatusPage(applicationId, hostname, service, pathSuffix); } private HttpResponse content(ApplicationId applicationId, String contentPath, HttpRequest request) { diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java index dd7604264f8..acc39223396 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java @@ -73,6 +73,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -363,6 +364,34 @@ public class ApplicationHandlerTest { assertHttpStatusCodeAndMessage(response, 200, "text/html", "..."); } + @Test + public void testServiceStatus() throws Exception { + applicationRepository.deploy(testApp, prepareParams(applicationId)); + String host = "foo.yahoo.com"; + HttpProxy mockHttpProxy = mock(HttpProxy.class); + ApplicationRepository applicationRepository = new ApplicationRepository.Builder() + .withTenantRepository(tenantRepository) + .withHostProvisionerProvider(HostProvisionerProvider.empty()) + .withOrchestrator(orchestrator) + .withTesterClient(testerClient) + .withHttpProxy(mockHttpProxy) + .build(); + ApplicationHandler mockHandler = createApplicationHandler(applicationRepository); + doAnswer(invoc -> new StaticResponse(200, "text/html", "" + + "host=" + invoc.getArgument(1, String.class) + "," + + "service=" + invoc.getArgument(2, String.class) + "," + + "path=" + invoc.getArgument(3, String.class) + "")).when(mockHttpProxy).get(any(), any(), any(), any()); + + HttpResponse response = mockHandler.handle(createTestRequest(toUrlPath(applicationId, Zone.defaultZone(), true) + "/service/container-clustercontroller/" + host + "/status/some/path/clusterName1", GET)); + assertHttpStatusCodeAndMessage(response, 200, "text/html", "host=foo.yahoo.com,service=container-clustercontroller,path=clustercontroller-status/v1/some/path/clusterName1"); + + response = mockHandler.handle(createTestRequest(toUrlPath(applicationId, Zone.defaultZone(), true) + "/service/distributor/" + host + "/status/something", GET)); + assertHttpStatusCodeAndMessage(response, 200, "text/html", "host=foo.yahoo.com,service=distributor,path=something"); + + response = mockHandler.handle(createTestRequest(toUrlPath(applicationId, Zone.defaultZone(), true) + "/service/fake-service/" + host + "/status/something", GET)); + assertHttpStatusCodeAndMessage(response, 404, "{\"error-code\":\"NOT_FOUND\",\"message\":\"No status page for service: fake-service\"}"); + } + @Test public void testPutIsIllegal() throws IOException { assertNotAllowed(Method.PUT); -- cgit v1.2.3 From 33894424802f5039e7c17d1c4f3c0498f3356ccf Mon Sep 17 00:00:00 2001 From: Valerij Fredriksen Date: Tue, 6 Jul 2021 21:51:05 +0200 Subject: Remove old clustercontroller status page endpoint --- .../config/server/http/v2/ApplicationHandler.java | 2 -- .../server/http/v2/ApplicationHandlerTest.java | 24 ---------------------- 2 files changed, 26 deletions(-) (limited to 'configserver') diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java index 7691748a4cf..ec7b6616bb6 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java @@ -5,7 +5,6 @@ import com.google.inject.Inject; import com.yahoo.component.Version; import com.yahoo.config.application.api.ApplicationFile; import com.yahoo.config.model.api.Model; -import com.yahoo.config.model.api.container.ContainerServiceType; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.HostFilter; import com.yahoo.config.provision.InstanceName; @@ -69,7 +68,6 @@ public class ApplicationHandler extends HttpHandler { if (path.matches("/application/v2/tenant/{tenant}/application/{application}")) return getApplicationResponse(ApplicationId.from(path.get("tenant"), path.get("application"), InstanceName.defaultName().value())); if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}")) return getApplicationResponse(applicationId(path)); - if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/clustercontroller/{hostname}/status/v1/{*}")) return serviceStatusPage(applicationId(path), ContainerServiceType.CLUSTERCONTROLLER_CONTAINER.serviceName, path.get("hostname"), path.getRest()); // TODO (freva): Remove August 2021 if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/content/{*}")) return content(applicationId(path), path.getRest(), request); if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/filedistributionstatus")) return filedistributionStatus(applicationId(path), request); if (path.matches("/application/v2/tenant/{tenant}/application/{application}/environment/{ignore}/region/{ignore}/instance/{instance}/logs")) return logs(applicationId(path), request); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java index acc39223396..46d94ec476b 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java @@ -60,7 +60,6 @@ import java.util.TreeMap; import java.util.TreeSet; import java.util.stream.Stream; -import static com.yahoo.config.model.api.container.ContainerServiceType.CLUSTERCONTROLLER_CONTAINER; import static com.yahoo.container.jdisc.HttpRequest.createTestRequest; import static com.yahoo.jdisc.http.HttpRequest.Method.DELETE; import static com.yahoo.jdisc.http.HttpRequest.Method.GET; @@ -72,10 +71,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; /** * @author hmusum @@ -343,27 +340,6 @@ public class ApplicationHandlerTest { converge(applicationId, Zone.defaultZone()); } - @Test - public void testClusterControllerStatus() throws Exception { - applicationRepository.deploy(testApp, prepareParams(applicationId)); - String host = "foo.yahoo.com"; - String url = toUrlPath(applicationId, Zone.defaultZone(), true) + "/clustercontroller/" + host + "/status/v1/clusterName1"; - HttpProxy mockHttpProxy = mock(HttpProxy.class); - ApplicationRepository applicationRepository = new ApplicationRepository.Builder() - .withTenantRepository(tenantRepository) - .withHostProvisionerProvider(HostProvisionerProvider.empty()) - .withOrchestrator(orchestrator) - .withTesterClient(testerClient) - .withHttpProxy(mockHttpProxy) - .build(); - ApplicationHandler mockHandler = createApplicationHandler(applicationRepository); - when(mockHttpProxy.get(any(), eq(host), eq(CLUSTERCONTROLLER_CONTAINER.serviceName), eq("clustercontroller-status/v1/clusterName1"))) - .thenReturn(new StaticResponse(200, "text/html", "...")); - - HttpResponse response = mockHandler.handle(createTestRequest(url, GET)); - assertHttpStatusCodeAndMessage(response, 200, "text/html", "..."); - } - @Test public void testServiceStatus() throws Exception { applicationRepository.deploy(testApp, prepareParams(applicationId)); -- cgit v1.2.3 From 92b76a15b7d00ff0c7158225398cd7dc9e40cf73 Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Thu, 8 Jul 2021 09:12:36 +0200 Subject: Add stack trace, need to figure out who calls this a long time after session is gone --- .../com/yahoo/vespa/config/server/session/SessionZooKeeperClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'configserver') diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClient.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClient.java index 26e9e45f1e7..24813891eba 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClient.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClient.java @@ -95,7 +95,7 @@ public class SessionZooKeeperClient { return Session.Status.parse(data); } catch (Exception e) { log.log(Level.INFO, "Failed to read session status at " + sessionStatusPath.getAbsolute() + - ", will assume session has been removed: " + e.getMessage()); + ", will assume session has been removed: ", e); return Session.Status.NONE; } } -- cgit v1.2.3 From c87ccbdf27353c44bf80c9a4036fef1281b129f5 Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Thu, 8 Jul 2021 14:58:31 +0200 Subject: Avoid checking and creating node If node is created between exists() and create() this will fail, just catch exception if node already exists and ignore it --- .../java/com/yahoo/vespa/config/server/zookeeper/ConfigCurator.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'configserver') diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ConfigCurator.java b/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ConfigCurator.java index 5bfa06a29dd..b13750f93d4 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ConfigCurator.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ConfigCurator.java @@ -5,6 +5,7 @@ import com.google.inject.Inject; import com.yahoo.cloud.config.ZookeeperServerConfig; import com.yahoo.text.Utf8; import com.yahoo.vespa.curator.Curator; +import org.apache.zookeeper.KeeperException; import java.util.List; import java.util.logging.Level; @@ -88,7 +89,10 @@ public class ConfigCurator { if (exists(path)) return; curator.framework().create().creatingParentsIfNeeded().forPath(path); } - catch (Exception e) { + catch (KeeperException.NodeExistsException e) { + // Ignore, path already exists + } + catch(Exception e){ throw new RuntimeException("Exception creating path " + path + " in ZooKeeper", e); } } -- cgit v1.2.3