summaryrefslogtreecommitdiffstats
path: root/configserver
diff options
context:
space:
mode:
authorjonmv <venstad@gmail.com>2023-09-08 11:25:42 +0200
committerjonmv <venstad@gmail.com>2023-09-08 11:25:42 +0200
commit69c6bb95c515143f19fe7cd47ed121e067ca61dc (patch)
tree33ed45adb642773fdb93b328fddcbf190476aa6f /configserver
parent124f4892ae45f19d49b3ca9adaa779c0f2851bfd (diff)
Translate state to "pending" for reindexing known only to config server at the time
Diffstat (limited to 'configserver')
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/ReindexingResponse.java46
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java24
2 files changed, 41 insertions, 29 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/ReindexingResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/ReindexingResponse.java
index 3ad09ea6345..47619536ae6 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/ReindexingResponse.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/response/ReindexingResponse.java
@@ -5,9 +5,12 @@ import com.yahoo.jdisc.Response;
import com.yahoo.slime.Cursor;
import com.yahoo.vespa.config.server.application.ApplicationReindexing;
import com.yahoo.vespa.config.server.application.ClusterReindexing;
+import com.yahoo.vespa.config.server.application.ClusterReindexing.State;
import com.yahoo.vespa.config.server.http.JSONResponse;
+import java.time.Instant;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
public class ReindexingResponse extends JSONResponse {
@@ -23,32 +26,35 @@ public class ReindexingResponse extends JSONResponse {
for (String type : types) {
Cursor statusObject = readyObject.setObject(type);
+ Instant readyAt = Instant.EPOCH;
+ State state = null;
if (reindexing.clusters().containsKey(cluster)) {
- if (reindexing.clusters().get(cluster).pending().containsKey(type))
+ if (reindexing.clusters().get(cluster).pending().containsKey(type)) {
pendingObject.setLong(type, reindexing.clusters().get(cluster).pending().get(type));
-
- if (reindexing.clusters().get(cluster).ready().containsKey(type))
- setStatus(statusObject, reindexing.clusters().get(cluster).ready().get(type));
+ state = State.PENDING;
+ }
+
+ if (reindexing.clusters().get(cluster).ready().containsKey(type)) {
+ ApplicationReindexing.Status readyStatus = reindexing.clusters().get(cluster).ready().get(type);
+ readyAt = readyStatus.ready();
+ statusObject.setLong("readyMillis", readyStatus.ready().toEpochMilli());
+ statusObject.setDouble("speed", readyStatus.speed());
+ statusObject.setString("cause", readyStatus.cause());
+ }
}
if (clusters.containsKey(cluster))
- if (clusters.get(cluster).documentTypeStatus().containsKey(type))
- setStatus(statusObject, clusters.get(cluster).documentTypeStatus().get(type));
+ if (clusters.get(cluster).documentTypeStatus().containsKey(type)) {
+ ClusterReindexing.Status status = clusters.get(cluster).documentTypeStatus().get(type);
+ statusObject.setLong("startedMillis", status.startedAt().toEpochMilli());
+ status.endedAt().ifPresent(endedAt -> statusObject.setLong("endedMillis", endedAt.toEpochMilli()));
+ if (status.startedAt().isAfter(readyAt) && status.state().isPresent()) state = status.state().get();
+ status.message().ifPresent(message -> statusObject.setString("message", message));
+ status.progress().ifPresent(progress -> statusObject.setDouble("progress", progress));
+ }
+ if (readyAt != Instant.EPOCH && state == null) state = State.PENDING;
+ if (state != null) statusObject.setString("state", state.asString());
}
});
}
- private static void setStatus(Cursor object, ApplicationReindexing.Status readyStatus) {
- object.setLong("readyMillis", readyStatus.ready().toEpochMilli());
- object.setDouble("speed", readyStatus.speed());
- object.setString("cause", readyStatus.cause());
- }
-
- private static void setStatus(Cursor object, ClusterReindexing.Status status) {
- object.setLong("startedMillis", status.startedAt().toEpochMilli());
- status.endedAt().ifPresent(endedAt -> object.setLong("endedMillis", endedAt.toEpochMilli()));
- status.state().map(ClusterReindexing.State::asString).ifPresent(state -> object.setString("state", state));
- status.message().ifPresent(message -> object.setString("message", message));
- status.progress().ifPresent(progress -> object.setDouble("progress", progress));
- }
-
}
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java
index 7a0ab6d2a23..951ef9df2f4 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java
@@ -318,7 +318,8 @@ public class ApplicationHandlerTest {
" \"bar\": {" +
" \"readyMillis\": " + (now - 1000) + ", " +
" \"speed\": 1.0," +
- " \"cause\": \"reindexing\"" +
+ " \"cause\": \"reindexing\"," +
+ " \"state\": \"pending\"" +
" }" +
" }" +
" }," +
@@ -328,17 +329,20 @@ public class ApplicationHandlerTest {
" \"bar\": {" +
" \"readyMillis\": " + now + ", " +
" \"speed\": 0.1," +
- " \"cause\": \"reindexing\"" +
+ " \"cause\": \"reindexing\"," +
+ " \"state\": \"pending\"" +
" }," +
" \"bax\": {" +
" \"readyMillis\": " + (now - 1000) + ", " +
" \"speed\": 1.0," +
- " \"cause\": \"reindexing\"" +
+ " \"cause\": \"reindexing\"," +
+ " \"state\": \"pending\"" +
" }," +
" \"baz\": {" +
" \"readyMillis\": " + now + ", " +
" \"speed\": 0.1," +
- " \"cause\": \"reindexing\"" +
+ " \"cause\": \"reindexing\"," +
+ " \"state\": \"pending\"" +
" }" +
" }" +
" }" +
@@ -579,9 +583,9 @@ public class ApplicationHandlerTest {
"baz": {
"startedMillis": 124456,
"endedMillis": 125456,
- "state": "failed",
"message": "message",
- "progress": 0.1
+ "progress": 0.1,
+ "state": "failed"
}
}
},
@@ -590,7 +594,9 @@ public class ApplicationHandlerTest {
"bar": 123
},
"ready": {
- "bar": {},
+ "bar": {
+ "state": "pending"
+ },
"hax": {}
}
},
@@ -606,9 +612,9 @@ public class ApplicationHandlerTest {
"cause": "reindexing",
"startedMillis": 124456,
"endedMillis": 125456,
- "state": "failed",
"message": "message",
- "progress": 0.1
+ "progress": 0.1,
+ "state": "failed"
}
}
}