diff options
author | Harald Musum <musum@yahooinc.com> | 2022-01-16 21:39:41 +0100 |
---|---|---|
committer | Harald Musum <musum@yahooinc.com> | 2022-01-16 21:39:41 +0100 |
commit | 86d4e876487517dce0bd58128f846c2f386f90d0 (patch) | |
tree | 590ae0febb1750af9aa5a12d8d81c50531d1a9f9 /configserver | |
parent | f3b0bc340c88b953a5f9f7985648e0a03a36ba5c (diff) |
Move request url to http response
Diffstat (limited to 'configserver')
5 files changed, 24 insertions, 30 deletions
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 c6c5b81019e..3464a31a669 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 @@ -88,7 +88,6 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.UncheckedIOException; -import java.net.URI; import java.nio.file.Files; import java.nio.file.attribute.BasicFileAttributes; import java.time.Clock; @@ -111,8 +110,8 @@ import java.util.stream.Collectors; import static com.yahoo.config.model.api.container.ContainerServiceType.CONTAINER; import static com.yahoo.config.model.api.container.ContainerServiceType.LOGSERVER_CONTAINER; -import static com.yahoo.vespa.config.server.application.ConfigConvergenceChecker.ServiceResponse; import static com.yahoo.vespa.config.server.application.ConfigConvergenceChecker.ServiceListResponse; +import static com.yahoo.vespa.config.server.application.ConfigConvergenceChecker.ServiceResponse; import static com.yahoo.vespa.config.server.filedistribution.FileDistributionUtil.fileReferenceExistsOnDisk; import static com.yahoo.vespa.config.server.filedistribution.FileDistributionUtil.getFileReferencesOnDisk; import static com.yahoo.vespa.config.server.tenant.TenantRepository.HOSTED_VESPA_TENANT; @@ -749,10 +748,9 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye } public ServiceListResponse servicesToCheckForConfigConvergence(ApplicationId applicationId, - URI uri, Duration timeoutPerService, Optional<Version> vespaVersion) { - return convergeChecker.getServiceConfigGenerations(getApplication(applicationId, vespaVersion), uri, timeoutPerService); + return convergeChecker.getConfigGenerationsForAllServices(getApplication(applicationId, vespaVersion), timeoutPerService); } public ConfigConvergenceChecker configConvergenceChecker() { return convergeChecker; } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/application/ConfigConvergenceChecker.java b/configserver/src/main/java/com/yahoo/vespa/config/server/application/ConfigConvergenceChecker.java index fc8b40777d2..594f0ef8bf8 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/application/ConfigConvergenceChecker.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/application/ConfigConvergenceChecker.java @@ -90,10 +90,10 @@ public class ConfigConvergenceChecker extends AbstractComponent { } /** Check all services in given application. Returns the minimum current generation of all services */ - public ServiceListResponse getServiceConfigGenerations(Application application, URI uri, Duration timeoutPerService) { + public ServiceListResponse getConfigGenerationsForAllServices(Application application, Duration timeoutPerService) { Map<ServiceInfo, Long> currentGenerations = getServiceConfigGenerations(application, timeoutPerService); long currentGeneration = currentGenerations.values().stream().mapToLong(Long::longValue).min().orElse(-1); - return new ServiceListResponse(currentGenerations, uri, application.getApplicationGeneration(), currentGeneration); + return new ServiceListResponse(currentGenerations, application.getApplicationGeneration(), currentGeneration); } /** Check service identified by host and port in given application */ @@ -256,23 +256,23 @@ public class ConfigConvergenceChecker extends AbstractComponent { public final boolean converged; public final Optional<String> errorMessage; - public ServiceResponse(Status status, Long wantedGeneration) { - this(status, wantedGeneration, 0L); + public ServiceResponse(Status status, long wantedGeneration) { + this(status, wantedGeneration, 0); } - public ServiceResponse(Status status, Long wantedGeneration, Long currentGeneration) { + public ServiceResponse(Status status, long wantedGeneration, long currentGeneration) { this(status, wantedGeneration, currentGeneration, false); } - public ServiceResponse(Status status, Long wantedGeneration, Long currentGeneration, boolean converged) { + public ServiceResponse(Status status, long wantedGeneration, long currentGeneration, boolean converged) { this(status, wantedGeneration, currentGeneration, converged, Optional.empty()); } - public ServiceResponse(Status status, Long wantedGeneration, String errorMessage) { - this(status, wantedGeneration, 0L, false, Optional.ofNullable(errorMessage)); + public ServiceResponse(Status status, long wantedGeneration, String errorMessage) { + this(status, wantedGeneration, 0, false, Optional.ofNullable(errorMessage)); } - private ServiceResponse(Status status, Long wantedGeneration, Long currentGeneration, boolean converged, Optional<String> errorMessage) { + private ServiceResponse(Status status, long wantedGeneration, long currentGeneration, boolean converged, Optional<String> errorMessage) { this.status = status; this.wantedGeneration = wantedGeneration; this.currentGeneration = currentGeneration; @@ -285,14 +285,12 @@ public class ConfigConvergenceChecker extends AbstractComponent { public static class ServiceListResponse { public final List<Service> services = new ArrayList<>(); - public final URI uri; public final long wantedGeneration; public final long currentGeneration; public final boolean converged; - public ServiceListResponse(Map<ServiceInfo, Long> services, URI uri, long wantedGeneration, long currentGeneration) { + public ServiceListResponse(Map<ServiceInfo, Long> services, long wantedGeneration, long currentGeneration) { services.forEach((key, value) -> this.services.add(new Service(key, value))); - this.uri = uri; this.wantedGeneration = wantedGeneration; this.currentGeneration = currentGeneration; this.converged = currentGeneration >= wantedGeneration; 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 8bd5e2bade0..df4df234ed0 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 @@ -117,10 +117,9 @@ public class ApplicationHandler extends HttpHandler { private HttpResponse listServiceConverge(ApplicationId applicationId, HttpRequest request) { ServiceListResponse response = applicationRepository.servicesToCheckForConfigConvergence(applicationId, - request.getUri(), getTimeoutFromRequest(request), getVespaVersionFromRequest(request)); - return new HttpServiceListResponse(response); + return new HttpServiceListResponse(response, request.getUri()); } private HttpResponse checkServiceConverge(ApplicationId applicationId, String hostAndPort, HttpRequest request) { @@ -370,7 +369,7 @@ public class ApplicationHandler extends HttpHandler { static class HttpServiceListResponse extends JSONResponse { // Pre-condition: servicesToCheck has a state port - public HttpServiceListResponse(ConfigConvergenceChecker.ServiceListResponse response) { + public HttpServiceListResponse(ConfigConvergenceChecker.ServiceListResponse response, URI uri) { super(200); Cursor serviceArray = object.setArray("services"); response.services().forEach((service) -> { @@ -381,10 +380,10 @@ public class ApplicationHandler extends HttpHandler { serviceObject.setString("host", hostName); serviceObject.setLong("port", statePort); serviceObject.setString("type", serviceInfo.getServiceType()); - serviceObject.setString("url", response.uri.toString() + "/" + hostName + ":" + statePort); + serviceObject.setString("url", uri.toString() + "/" + hostName + ":" + statePort); serviceObject.setLong("currentGeneration", service.currentGeneration); }); - object.setString("url", response.uri.toString()); + object.setString("url", uri.toString()); object.setLong("currentGeneration", response.currentGeneration); object.setLong("wantedGeneration", response.wantedGeneration); object.setBool("converged", response.converged); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/application/ConfigConvergenceCheckerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/application/ConfigConvergenceCheckerTest.java index 0bff1642fee..148cd8ac24f 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/application/ConfigConvergenceCheckerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/application/ConfigConvergenceCheckerTest.java @@ -89,10 +89,9 @@ public class ConfigConvergenceCheckerTest { @Test public void service_list_convergence() { { - URI requestUrl = testServer().resolve("/serviceconverge"); wireMock.stubFor(get(urlEqualTo("/state/v1/config")).willReturn(okJson("{\"config\":{\"generation\":3}}"))); - ServiceListResponse response = checker.getServiceConfigGenerations(application, requestUrl, clientTimeout); + ServiceListResponse response = checker.getConfigGenerationsForAllServices(application, clientTimeout); assertEquals(3, response.wantedGeneration); assertEquals(3, response.currentGeneration); assertTrue(response.converged); @@ -115,7 +114,7 @@ public class ConfigConvergenceCheckerTest { URI requestUrl = testServer().resolve("/serviceconverge"); - ServiceListResponse response = checker.getServiceConfigGenerations(application, requestUrl, clientTimeout); + ServiceListResponse response = checker.getConfigGenerationsForAllServices(application, clientTimeout); assertEquals(4, response.wantedGeneration); assertEquals(3, response.currentGeneration); assertFalse(response.converged); 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 04483e0191d..36930e27de4 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 @@ -556,8 +556,8 @@ public class ApplicationHandlerTest { { // Known service HttpResponse response = createResponse(new ServiceResponse(ServiceResponse.Status.ok, - 3L, - 3L, + 3, + 3, true), hostAndPort, uri); @@ -601,9 +601,9 @@ public class ApplicationHandlerTest { { HttpServiceListResponse response = new HttpServiceListResponse(new ServiceListResponse(Map.of(createServiceInfo(hostname, port), 3L), - requestUrl, 3L, - 3L)); + 3L), + requestUrl); assertResponse("{\n" + " \"services\": [\n" + " {\n" + @@ -635,9 +635,9 @@ public class ApplicationHandlerTest { HttpServiceListResponse response = new HttpServiceListResponse(new ServiceListResponse(serviceInfos, - requestUrl, 4L, - 3L)); + 3L), + requestUrl); assertResponse("{\n" + " \"services\": [\n" + " {\n" + |