diff options
author | Valerij Fredriksen <valerijf@verizonmedia.com> | 2020-02-03 11:25:02 +0100 |
---|---|---|
committer | Valerij Fredriksen <valerijf@verizonmedia.com> | 2020-02-03 11:25:02 +0100 |
commit | 72b409228639471334fa8e54c7e6abc2a5ebe854 (patch) | |
tree | b9c38cca6522f3020e022bbecbba5e2a66792d7c /controller-server | |
parent | 3e21ae3340cb49c0b28e8646e3eb1ae22d6241cc (diff) |
Support getting clustercontroller status via /application/v4/
Diffstat (limited to 'controller-server')
4 files changed, 47 insertions, 13 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Controller.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Controller.java index adf957ca973..3d492bc00d4 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Controller.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Controller.java @@ -151,13 +151,6 @@ public class Controller extends AbstractComponent implements ApplicationIdSource return serviceRegistry.configServer().getApplicationView(tenantName, applicationName, instanceName, environment, region); } - // TODO: Model the response properly - public Map<?,?> getServiceApiResponse(String tenantName, String applicationName, String instanceName, - String environment, String region, String serviceName, String restPath) { - return serviceRegistry.configServer().getServiceApiResponse(tenantName, applicationName, instanceName, environment, region, - serviceName, restPath); - } - /** Replace the current version status by a new one */ public void updateVersionStatus(VersionStatus newStatus) { VersionStatus currentStatus = versionStatus(); diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java index 7e4ad0d3384..6911dd974d2 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java @@ -1331,10 +1331,17 @@ public class ApplicationApiHandler extends LoggingRequestHandler { } private HttpResponse service(String tenantName, String applicationName, String instanceName, String environment, String region, String serviceName, String restPath, HttpRequest request) { - Map<?,?> result = controller.getServiceApiResponse(tenantName, applicationName, instanceName, environment, region, serviceName, restPath); - ServiceApiResponse response = new ServiceApiResponse(ZoneId.from(environment, region), - new ApplicationId.Builder().tenant(tenantName).applicationName(applicationName).instanceName(instanceName).build(), - controller.zoneRegistry().getConfigServerApiUris(ZoneId.from(environment, region)), + DeploymentId deploymentId = new DeploymentId(ApplicationId.from(tenantName, applicationName, instanceName), ZoneId.from(environment, region)); + + if ("container-clustercontroller".equals((serviceName)) && restPath.contains("/status/")) { + String result = controller.serviceRegistry().configServer().getClusterControllerStatus(deploymentId, restPath); + return new HtmlResponse(result); + } + + Map<?,?> result = controller.serviceRegistry().configServer().getServiceApiResponse(deploymentId, serviceName, restPath); + ServiceApiResponse response = new ServiceApiResponse(deploymentId.zoneId(), + deploymentId.applicationId(), + controller.zoneRegistry().getConfigServerApiUris(deploymentId.zoneId()), request.getUri()); response.setResponse(result, serviceName, restPath); return response; diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/HtmlResponse.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/HtmlResponse.java new file mode 100644 index 00000000000..99884875a64 --- /dev/null +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/HtmlResponse.java @@ -0,0 +1,30 @@ +// Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.hosted.controller.restapi.application; + +import com.yahoo.container.jdisc.HttpResponse; + +import java.io.IOException; +import java.io.OutputStream; +import java.nio.charset.StandardCharsets; + +/** + * @author freva + */ +public class HtmlResponse extends HttpResponse { + + private final String content; + + public HtmlResponse(String content) { + super(200); + this.content = content; + } + + @Override + public void render(OutputStream stream) throws IOException { + stream.write(content.getBytes(StandardCharsets.UTF_8)); + } + + @Override + public String getContentType() { return "text/html"; } + +} diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ConfigServerMock.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ConfigServerMock.java index eb8af62a0e6..b5302c9ed43 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ConfigServerMock.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ConfigServerMock.java @@ -404,8 +404,7 @@ public class ConfigServerMock extends AbstractComponent implements ConfigServer // Returns a canned example response @Override - public Map<?,?> getServiceApiResponse(String tenantName, String applicationName, String instanceName, - String environment, String region, String serviceName, String restPath) { + public Map<?,?> getServiceApiResponse(DeploymentId deployment, String serviceName, String restPath) { Map<String,List<?>> root = new HashMap<>(); List<Map<?,?>> resources = new ArrayList<>(); Map<String,String> resource = new HashMap<>(); @@ -416,6 +415,11 @@ public class ConfigServerMock extends AbstractComponent implements ConfigServer } @Override + public String getClusterControllerStatus(DeploymentId deployment, String restPath) { + return "<h1>OK</h1>"; + } + + @Override public void setGlobalRotationStatus(DeploymentId deployment, String upstreamName, EndpointStatus status) { endpoints.put(upstreamName, status); } |