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 9b3b3cef5b58..40ce16145e78 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 enum ErrorCode { 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 static HttpErrorResponse loadBalancerNotReady(String msg) { 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 53dbda9c4d13..25ae21f33833 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 HttpResponse handle(HttpRequest request) { 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 000000000000..4f990fcfe6d7 --- /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 fc33830e7071..8afffd93a293 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.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.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 @@ private HttpResponse getReindexingStatus(ApplicationId applicationId) { 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) {