Skip to content

Conversation

@liucongjy
Copy link
Contributor

@liucongjy liucongjy commented Oct 16, 2025

Purpose of this pull request

Objective: Enable pagination for querying finished and running tasks in the engine-ui interface.

Rationale: When the Seatunnel cluster handles numerous tasks,For example, when exceeding 2,000 tasks, fetching all tasks simultaneously can cause:

  • Timeout errors from /running-jobs and /finished-jobs APIs
  • Browser performance issues or crashes due to excessive data loading

The effect after implementing pagination is as follows:
image
3e77a213-4c1f-49ab-9932-d6c04f7d6ce3

Does this PR introduce any user-facing change?

No

How was this patch tested?

  • paginatiion test case: In class RestApiHttpsTest,testFinishedJobsApi() and testRunningJobsApi() test methods
  • ui test case: In file seatunnel-engine/seatunnel-engine-ui/src/tests/jobs.spec.ts

Check list

@liucongjy liucongjy changed the title [Improve][UI] seantunnel-ui support paginated queries [Improve][engine-server] engine-server and seantunnel-ui support remote paginated queries Oct 17, 2025
Comment on lines 52 to 66
int start = (page - 1) * rows;
JsonArray paginatedArray = new JsonArray();
jsonArray
.values()
.subList(start, Math.min(start + rows, total))
.forEach(
t -> {
paginatedArray.add(t);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validation is needed. If start > total or page < 0, an error may occur, causing the program to malfunction.

Copy link
Contributor Author

@liucongjy liucongjy Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validation has been added, and an exception will be thrown if the conditions are not met.

@Hisoka-X
Copy link
Member

cc @hawk9821

Comment on lines 129 to 197
restApiRequestHttp(
"http://localhost:" + HTTP_PORT + "/finished-jobs?page=1&rows=5",
response -> {
JsonObject resultJson = (JsonObject) Json.parse(response);
Assertions.assertTrue(
resultJson.get("data") != null && resultJson.get("total") != null);
});
// no pagination test
restApiRequestHttp(
"http://localhost:" + HTTP_PORT + "/finished-jobs",
response -> {
JsonArray resultJson = (JsonArray) Json.parse(response);
Assertions.assertTrue(resultJson != null);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current checking logic is a bit weak. Can we verify that the amount of data returned and the results meet expectations by modifying different parameters in the test case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented validation checks for API return row counts and added unit tests to verify behavior when page numbers exceed available data.

Comment on lines +31 to +32
private final String pageParam = "page";
private final String rowsParam = "rows";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API parameters in the docs rest-api-v2.md have been updated.

@liucongjy liucongjy force-pushed the lc-feture-branch branch 2 times, most recently from 96879ff to 97d153f Compare October 21, 2025 07:50
@liucongjy liucongjy requested a review from Hisoka-X October 24, 2025 01:47
nodeEngine.getHazelcastInstance().getMap(Constant.IMAP_RUNNING_JOB_INFO);
return values.entrySet().stream()
.map(jobInfoEntry -> convertToJson(jobInfoEntry.getValue(), jobInfoEntry.getKey()))
.sorted(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JobId is ordered, I think it can be sorted by jobId, compared to higher efficiency.

return values.entrySet().stream()
          .sorted(Map.Entry.comparingByKey(Comparator.reverseOrder()))
          .map(jobInfoEntry -> convertToJson(jobInfoEntry.getValue(), jobInfoEntry.getKey()))
          .collect(JsonArray::new, JsonArray::add, JsonArray::add);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JobId is manually passed in and may not guarantee order, so it has been changed to use the InitializationTimestamp of the JobInfo for sorting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants