diff options
author | Jon Marius Venstad <venstad@gmail.com> | 2020-10-28 14:48:29 +0100 |
---|---|---|
committer | Jon Marius Venstad <venstad@gmail.com> | 2020-10-29 12:12:13 +0100 |
commit | 41a7f812d0393194c89ade76a30f406f80a7f18f (patch) | |
tree | dc9eab9437714c6d4aa756e02b86f92008d4870e | |
parent | 55100169f422b5c051fc56b211eff940c9b7ba5b (diff) |
Split out method to get the config generation of all services of an application
3 files changed, 17 insertions, 13 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 10d566910fa..cda6be11279 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 @@ -661,12 +661,12 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye public HttpResponse checkServiceForConfigConvergence(ApplicationId applicationId, String hostAndPort, URI uri, Duration timeout, Optional<Version> vespaVersion) { - return convergeChecker.checkService(getApplication(applicationId, vespaVersion), hostAndPort, uri, timeout); + return convergeChecker.getServiceConfigGenerationJson(getApplication(applicationId, vespaVersion), hostAndPort, uri, timeout); } public HttpResponse servicesToCheckForConfigConvergence(ApplicationId applicationId, URI uri, Duration timeoutPerService, Optional<Version> vespaVersion) { - return convergeChecker.servicesToCheck(getApplication(applicationId, vespaVersion), uri, timeoutPerService); + return convergeChecker.getServiceConfigGenerationsJson(getApplication(applicationId, vespaVersion), uri, timeoutPerService); } // ---------------- Logs ---------------------------------------------------------------- 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 824cc932ecc..aceabbd12de 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 @@ -70,26 +70,30 @@ public class ConfigConvergenceChecker extends AbstractComponent { this.stateApiFactory = stateApiFactory; } - /** Check all services in given application. Returns the minimum current generation of all services */ - public ServiceListResponse servicesToCheck(Application application, URI requestUrl, Duration timeoutPerService) { - log.log(Level.FINE, () -> "Finding services to check config convergence for in '" + application); + /** Fetches the active config generation for all services in the given application. */ + public Map<ServiceInfo, Long> getServiceConfigGenerations(Application application, Duration timeoutPerService) { List<ServiceInfo> servicesToCheck = new ArrayList<>(); application.getModel().getHosts() .forEach(host -> host.getServices().stream() .filter(service -> serviceTypesToCheck.contains(service.getServiceType())) .forEach(service -> getStatePort(service).ifPresent(port -> servicesToCheck.add(service)))); - Map<ServiceInfo, Long> currentGenerations = getServiceGenerations(servicesToCheck, timeoutPerService); + return getServiceGenerations(servicesToCheck, timeoutPerService); + } + + /** Check all services in given application. Returns the minimum current generation of all services */ + public ServiceListResponse getServiceConfigGenerationsJson(Application application, URI requestUrl, Duration timeoutPerService) { + Map<ServiceInfo, Long> currentGenerations = getServiceConfigGenerations(application, timeoutPerService); long currentGeneration = currentGenerations.values().stream().mapToLong(Long::longValue).min().orElse(-1); return new ServiceListResponse(200, currentGenerations, requestUrl, application.getApplicationGeneration(), currentGeneration); } /** Check service identified by host and port in given application */ - public ServiceResponse checkService(Application application, String hostAndPortToCheck, URI requestUrl, Duration timeout) { + public ServiceResponse getServiceConfigGenerationJson(Application application, String hostAndPortToCheck, URI requestUrl, Duration timeout) { Long wantedGeneration = application.getApplicationGeneration(); try { - if (! hostInApplication(application, hostAndPortToCheck)) + if ( ! hostInApplication(application, hostAndPortToCheck)) return ServiceResponse.createHostNotFoundInAppResponse(requestUrl, hostAndPortToCheck, wantedGeneration); long currentGeneration = getServiceGeneration(URI.create("http://" + hostAndPortToCheck), timeout); 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 1f034a92cbb..2d749649ce1 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 @@ -77,7 +77,7 @@ public class ConfigConvergenceCheckerTest { String serviceName = hostAndPort(this.service); URI requestUrl = testServer().resolve("/serviceconverge/" + serviceName); wireMock.stubFor(get(urlEqualTo("/state/v1/config")).willReturn(okJson("{\"config\":{\"generation\":3}}"))); - HttpResponse serviceResponse = checker.checkService(application, hostAndPort(this.service), requestUrl, clientTimeout); + HttpResponse serviceResponse = checker.getServiceConfigGenerationJson(application, hostAndPort(this.service), requestUrl, clientTimeout); assertResponse("{\n" + " \"url\": \"" + requestUrl.toString() + "\",\n" + " \"host\": \"" + hostAndPort(this.service) + "\",\n" + @@ -92,7 +92,7 @@ public class ConfigConvergenceCheckerTest { { // Missing service String serviceName = "notPresent:1337"; URI requestUrl = testServer().resolve("/serviceconverge/" + serviceName); - HttpResponse response = checker.checkService(application, "notPresent:1337", requestUrl,clientTimeout); + HttpResponse response = checker.getServiceConfigGenerationJson(application, "notPresent:1337", requestUrl, clientTimeout); assertResponse("{\n" + " \"url\": \"" + requestUrl.toString() + "\",\n" + " \"host\": \"" + serviceName + "\",\n" + @@ -111,7 +111,7 @@ public class ConfigConvergenceCheckerTest { URI requestUrl = testServer().resolve("/serviceconverge"); URI serviceUrl = testServer().resolve("/serviceconverge/" + serviceName); wireMock.stubFor(get(urlEqualTo("/state/v1/config")).willReturn(okJson("{\"config\":{\"generation\":3}}"))); - HttpResponse response = checker.servicesToCheck(application, requestUrl, clientTimeout); + HttpResponse response = checker.getServiceConfigGenerationsJson(application, requestUrl, clientTimeout); assertResponse("{\n" + " \"services\": [\n" + " {\n" + @@ -148,7 +148,7 @@ public class ConfigConvergenceCheckerTest { URI requestUrl = testServer().resolve("/serviceconverge"); URI serviceUrl = testServer().resolve("/serviceconverge/" + hostAndPort(service)); URI serviceUrl2 = testServer().resolve("/serviceconverge/" + hostAndPort(service2)); - HttpResponse response = checker.servicesToCheck(application, requestUrl, clientTimeout); + HttpResponse response = checker.getServiceConfigGenerationsJson(application, requestUrl, clientTimeout); assertResponse("{\n" + " \"services\": [\n" + " {\n" + @@ -182,7 +182,7 @@ public class ConfigConvergenceCheckerTest { wireMock.stubFor(get(urlEqualTo("/state/v1/config")).willReturn(aResponse() .withFixedDelay((int) clientTimeout.plus(Duration.ofSeconds(1)).toMillis()) .withBody("response too slow"))); - HttpResponse response = checker.checkService(application, hostAndPort(service), requestUrl, Duration.ofMillis(1)); + HttpResponse response = checker.getServiceConfigGenerationJson(application, hostAndPort(service), requestUrl, Duration.ofMillis(1)); // Message contained in a SocketTimeoutException may differ across platforms, so we do a partial match of the response here assertResponse((responseBody) -> assertTrue("Response matches", responseBody.startsWith( "{\"url\":\"" + requestUrl.toString() + "\",\"host\":\"" + hostAndPort(requestUrl) + |