Skip to content

Commit

Permalink
Return 409 if reindexing status is unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
mpolden committed Oct 5, 2022
1 parent 90d1779 commit ed0e57a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<String, Set<String>> documentTypes = getActiveModelOrThrow(applicationId).documentTypesByCluster();
ApplicationReindexing reindexing = applicationRepository.getReindexing(applicationId);
Map<String, ClusterReindexing> 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) {
Expand Down

0 comments on commit ed0e57a

Please sign in to comment.