From ed0e57ad7344a61894bc679bdd87f03e3eb53f17 Mon Sep 17 00:00:00 2001 From: Martin Polden Date: Wed, 5 Oct 2022 15:07:52 +0200 Subject: Return 409 if reindexing status is unavailable --- .../vespa/config/server/http/HttpErrorResponse.java | 7 ++++++- .../com/yahoo/vespa/config/server/http/HttpHandler.java | 2 ++ .../config/server/http/ReindexingStatusException.java | 16 ++++++++++++++++ .../vespa/config/server/http/v2/ApplicationHandler.java | 16 +++++++++++++--- 4 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 configserver/src/main/java/com/yahoo/vespa/config/server/http/ReindexingStatusException.java diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/HttpErrorResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/HttpErrorResponse.java index 9b3b3cef5b5..40ce16145e7 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/HttpErrorResponse.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/HttpErrorResponse.java @@ -50,7 +50,8 @@ public class HttpErrorResponse extends HttpResponse { PARENT_HOST_NOT_READY, CERTIFICATE_NOT_READY, LOAD_BALANCER_NOT_READY, - CONFIG_NOT_CONVERGED + CONFIG_NOT_CONVERGED, + REINDEXING_STATUS_UNAVAILABLE } public static HttpErrorResponse notFoundError(String msg) { @@ -109,6 +110,10 @@ public class HttpErrorResponse extends HttpResponse { return new HttpErrorResponse(CONFLICT, ErrorCode.LOAD_BALANCER_NOT_READY.name(), msg); } + public static HttpResponse reindexingStatusUnavailable(String msg) { + return new HttpErrorResponse(CONFLICT, ErrorCode.REINDEXING_STATUS_UNAVAILABLE.name(), msg); + } + @Override public void render(OutputStream stream) throws IOException { new JsonFormat(true).encode(stream, slime); diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/HttpHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/HttpHandler.java index 53dbda9c4d1..25ae21f3383 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/HttpHandler.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/HttpHandler.java @@ -68,6 +68,8 @@ public class HttpHandler extends ThreadedHttpRequestHandler { return HttpErrorResponse.configNotConverged(getMessage(e, request)); } catch (LoadBalancerServiceException e) { return HttpErrorResponse.loadBalancerNotReady(getMessage(e, request)); + } catch (ReindexingStatusException e) { + return HttpErrorResponse.reindexingStatusUnavailable(getMessage(e, request)); } catch (Exception e) { log.log(Level.WARNING, "Unexpected exception handling a config server request", e); return HttpErrorResponse.internalServerError(getMessage(e, request)); diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/ReindexingStatusException.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/ReindexingStatusException.java new file mode 100644 index 00000000000..4f990fcfe6d --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/ReindexingStatusException.java @@ -0,0 +1,16 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.config.server.http; + +/** + * Exception indicating that the reindexing status for an application is currently unavailable, e.g. if the cluster is + * recently configured and its nodes are not yet up. + * + * @author mpolden + */ +public class ReindexingStatusException extends RuntimeException { + + public ReindexingStatusException(String message) { + super(message); + } + +} 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 fc33830e707..8afffd93a29 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 @@ -24,12 +24,15 @@ 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.application.ConfigConvergenceChecker; import com.yahoo.vespa.config.server.http.ContentHandler; import com.yahoo.vespa.config.server.http.ContentRequest; 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.ReindexingStatusException; 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; @@ -39,6 +42,7 @@ import com.yahoo.vespa.config.server.http.v2.response.ReindexingResponse; import com.yahoo.vespa.config.server.tenant.Tenant; import java.io.IOException; +import java.io.UncheckedIOException; import java.net.URI; import java.time.Duration; import java.time.Instant; @@ -296,9 +300,15 @@ public class ApplicationHandler extends HttpHandler { if (tenant == null) throw new NotFoundException("Tenant '" + applicationId.tenant().value() + "' not found"); - return new ReindexingResponse(getActiveModelOrThrow(applicationId).documentTypesByCluster(), - applicationRepository.getReindexing(applicationId), - applicationRepository.getClusterReindexingStatus(applicationId)); + try { + Map> documentTypes = getActiveModelOrThrow(applicationId).documentTypesByCluster(); + ApplicationReindexing reindexing = applicationRepository.getReindexing(applicationId); + Map clusters = applicationRepository.getClusterReindexingStatus(applicationId); + return new ReindexingResponse(documentTypes, reindexing, clusters); + } catch (UncheckedIOException e) { + throw new ReindexingStatusException("Reindexing status for '" + applicationId + + "' is currently unavailable"); + } } private HttpResponse restart(ApplicationId applicationId, HttpRequest request) { -- cgit v1.2.3