mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(batch): paginate multi-node job listings (#6512)
Honor maxResults and nextToken for MNP node summaries using the existing Batch paging conventions. Keep exhausted pages terminal and avoid overflow for large offsets.
This commit is contained in:
1 parent
b90b671c21
commit
ddb94d6c15
4 files changed
+197
-9
No files matched your search
@@ -893,7 +893,7 @@ public class BatchService {
|
||||
return listArrayChildren(arrayJobId, request);
|
||||
}
|
||||
if (multiNodeJobId != null) {
|
||||
return listMultiNodeJobNodes(multiNodeJobId);
|
||||
return listMultiNodeJobNodes(multiNodeJobId, request);
|
||||
}
|
||||
|
||||
BatchJobQueue queue = resolveJobQueue(jobQueueRef);
|
||||
@@ -959,18 +959,26 @@ public class BatchService {
|
||||
return out;
|
||||
}
|
||||
|
||||
// No pagination: realistic node counts are small, so every node is always returned.
|
||||
private ObjectNode listMultiNodeJobNodes(String jobId) {
|
||||
private ObjectNode listMultiNodeJobNodes(String jobId, JsonNode request) {
|
||||
int maxResults = request.hasNonNull("maxResults")
|
||||
? Math.max(1, Math.min(DEFAULT_MAX_RESULTS, request.path("maxResults").asInt()))
|
||||
: DEFAULT_MAX_RESULTS;
|
||||
int offset = parseNextToken(textOrNull(request, "nextToken"));
|
||||
ArrayNode summaries = objectMapper.createArrayNode();
|
||||
ObjectNode out = objectMapper.createObjectNode();
|
||||
out.set("jobSummaryList", summaries);
|
||||
getJob(jobId).ifPresent(job -> {
|
||||
if (job.getNodeProperties() != null) {
|
||||
for (BatchNodeExecution execution : job.getNodeExecutions()) {
|
||||
summaries.add(nodeJobSummary(job, execution));
|
||||
List<BatchNodeExecution> executions = job.getNodeExecutions();
|
||||
int end = (int) Math.min(executions.size(), (long) offset + maxResults);
|
||||
for (int index = offset; index < end; index++) {
|
||||
summaries.add(nodeJobSummary(job, executions.get(index)));
|
||||
}
|
||||
if (end < executions.size()) {
|
||||
out.put("nextToken", String.valueOf(end));
|
||||
}
|
||||
}
|
||||
});
|
||||
ObjectNode out = objectMapper.createObjectNode();
|
||||
out.set("jobSummaryList", summaries);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user