summaryrefslogtreecommitdiffstats
path: root/controller-server
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@verizonmedia.com>2021-09-16 16:17:38 +0200
committerBjørn Christian Seime <bjorncs@verizonmedia.com>2021-09-16 16:17:38 +0200
commite57804532c9678e04a9d03c9409f5091ab401f4d (patch)
treeff6799adb388fd286a9ac9f43a4897e4f2074971 /controller-server
parentf868227bde97f245746e6472f37d3b31ec81e56e (diff)
Wait for service dump to complete if request attribute is present
Diffstat (limited to 'controller-server')
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java24
1 files changed, 22 insertions, 2 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java
index 77e49933d2c..3896ad87397 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java
@@ -77,7 +77,6 @@ import com.yahoo.vespa.hosted.controller.api.role.Role;
import com.yahoo.vespa.hosted.controller.api.role.RoleDefinition;
import com.yahoo.vespa.hosted.controller.api.role.SecurityContext;
import com.yahoo.vespa.hosted.controller.application.ActivateResult;
-import com.yahoo.vespa.hosted.controller.application.pkg.ApplicationPackage;
import com.yahoo.vespa.hosted.controller.application.AssignedRotation;
import com.yahoo.vespa.hosted.controller.application.Change;
import com.yahoo.vespa.hosted.controller.application.Deployment;
@@ -87,6 +86,7 @@ import com.yahoo.vespa.hosted.controller.application.EndpointList;
import com.yahoo.vespa.hosted.controller.application.QuotaUsage;
import com.yahoo.vespa.hosted.controller.application.SystemApplication;
import com.yahoo.vespa.hosted.controller.application.TenantAndApplicationId;
+import com.yahoo.vespa.hosted.controller.application.pkg.ApplicationPackage;
import com.yahoo.vespa.hosted.controller.auditlog.AuditLoggingRequestHandler;
import com.yahoo.vespa.hosted.controller.deployment.DeploymentStatus;
import com.yahoo.vespa.hosted.controller.deployment.DeploymentSteps;
@@ -2122,7 +2122,9 @@ public class ApplicationApiHandler extends AuditLoggingRequestHandler {
}
var reportsUpdate = Map.of("serviceDump", new String(uncheck(() -> SlimeUtils.toJsonBytes(dumpRequest))));
nodeRepository.updateReports(zone, hostname, reportsUpdate);
- return new MessageResponse("Request created");
+ boolean wait = request.getBooleanProperty("wait");
+ if (!wait) return new MessageResponse("Request created");
+ return waitForServiceDumpResult(nodeRepository, zone, tenant, application, instance, hostname);
}
private HttpResponse getServiceDump(String tenant, String application, String instance, String environment,
@@ -2134,6 +2136,24 @@ public class ApplicationApiHandler extends AuditLoggingRequestHandler {
return new SlimeJsonResponse(report);
}
+ private HttpResponse waitForServiceDumpResult(NodeRepository nodeRepository, ZoneId zone, String tenant,
+ String application, String instance, String hostname) {
+ int pollInterval = 2;
+ Slime report;
+ while (true) {
+ report = getReport(nodeRepository, zone, tenant, application, instance, hostname).get();
+ Cursor cursor = report.get();
+ if (cursor.field("completedAt").asLong() > 0 || cursor.field("failedAt").asLong() > 0) {
+ break;
+ }
+ final Slime copyForLambda = report;
+ log.fine(() -> uncheck(() -> new String(SlimeUtils.toJsonBytes(copyForLambda))));
+ log.fine("Sleeping " + pollInterval + " seconds before checking report status again");
+ controller.sleeper().sleep(Duration.ofSeconds(pollInterval));
+ }
+ return new SlimeJsonResponse(report);
+ }
+
private Optional<Slime> getReport(NodeRepository nodeRepository, ZoneId zone, String tenant,
String application, String instance, String hostname) {
Node node;