This is an automated email from the ASF dual-hosted git repository.
gaojun2048 pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/seatunnel.git
The following commit(s) were added to refs/heads/dev by this push:
new 27dcd80be5 [Feature][Engine] Change the name of the rest-api interface
for returning job info (#6813)
27dcd80be5 is described below
commit 27dcd80be5e520bd5674698d7e4294a0d28bc0f6
Author: hawk9821 <[email protected]>
AuthorDate: Thu May 9 19:21:14 2024 +0800
[Feature][Engine] Change the name of the rest-api interface for returning
job info (#6813)
---
docs/en/seatunnel-engine/rest-api.md | 59 +++++++++++++++++++++-
docs/zh/seatunnel-engine/rest-api.md | 57 +++++++++++++++++++++
.../org/apache/seatunnel/engine/e2e/RestApiIT.java | 21 ++++++++
.../seatunnel/engine/server/rest/RestConstant.java | 4 +-
.../server/rest/RestHttpGetCommandProcessor.java | 35 ++++++-------
5 files changed, 154 insertions(+), 22 deletions(-)
diff --git a/docs/en/seatunnel-engine/rest-api.md
b/docs/en/seatunnel-engine/rest-api.md
index 3f1069b566..0a0c160587 100644
--- a/docs/en/seatunnel-engine/rest-api.md
+++ b/docs/en/seatunnel-engine/rest-api.md
@@ -77,7 +77,64 @@ network:
### Return details of a job.
<details>
- <summary><code>GET</code>
<code><b>/hazelcast/rest/maps/running-job/:jobId</b></code> <code>(Return
details of a job.)</code></summary>
+ <summary><code>GET</code>
<code><b>/hazelcast/rest/maps/job-info/:jobId</b></code> <code>(Return details
of a job. )</code></summary>
+
+#### Parameters
+
+> | name | type | data type | description |
+> |-------|----------|-----------|-------------|
+> | jobId | required | long | job id |
+
+#### Responses
+
+```json
+{
+ "jobId": "",
+ "jobName": "",
+ "jobStatus": "",
+ "createTime": "",
+ "jobDag": {
+ "vertices": [
+ ],
+ "edges": [
+ ]
+ },
+ "metrics": {
+ "sourceReceivedCount": "",
+ "sinkWriteCount": ""
+ },
+ "finishedTime": "",
+ "errorMsg": null,
+ "envOptions": {
+ },
+ "pluginJarsUrls": [
+ ],
+ "isStartWithSavePoint": false
+}
+```
+
+`jobId`, `jobName`, `jobStatus`, `createTime`, `jobDag`, `metrics` always be
returned.
+`envOptions`, `pluginJarsUrls`, `isStartWithSavePoint` will return when job is
running.
+`finishedTime`, `errorMsg` will return when job is finished.
+
+When we can't get the job info, the response will be:
+
+```json
+{
+ "jobId" : ""
+}
+```
+
+</details>
+
+------------------------------------------------------------------------------------------
+
+### Return details of a job.
+
+This API has been deprecated, please use /hazelcast/rest/maps/job-info/:jobId
instead
+
+<details>
+ <summary><code>GET</code>
<code><b>/hazelcast/rest/maps/running-job/:jobId</b></code> <code>(Return
details of a job. )</code></summary>
#### Parameters
diff --git a/docs/zh/seatunnel-engine/rest-api.md
b/docs/zh/seatunnel-engine/rest-api.md
index 28a81c548d..ee9a1511a9 100644
--- a/docs/zh/seatunnel-engine/rest-api.md
+++ b/docs/zh/seatunnel-engine/rest-api.md
@@ -75,6 +75,63 @@ network:
### 返回作业的详细信息。
+<details>
+ <summary><code>GET</code>
<code><b>/hazelcast/rest/maps/job-info/:jobId</b></code>
<code>(返回作业的详细信息。)</code></summary>
+
+#### 参数
+
+> | name | type | data type | description |
+> |-------|----------|-----------|-------------|
+> | jobId | required | long | job id |
+
+#### 响应
+
+```json
+{
+ "jobId": "",
+ "jobName": "",
+ "jobStatus": "",
+ "createTime": "",
+ "jobDag": {
+ "vertices": [
+ ],
+ "edges": [
+ ]
+ },
+ "metrics": {
+ "sourceReceivedCount": "",
+ "sinkWriteCount": ""
+ },
+ "finishedTime": "",
+ "errorMsg": null,
+ "envOptions": {
+ },
+ "pluginJarsUrls": [
+ ],
+ "isStartWithSavePoint": false
+}
+```
+
+`jobId`, `jobName`, `jobStatus`, `createTime`, `jobDag`, `metrics` 字段总会返回.
+`envOptions`, `pluginJarsUrls`, `isStartWithSavePoint` 字段在Job在RUNNING状态时会返回
+`finishedTime`, `errorMsg` 字段在Job结束时会返回,结束状态为不为RUNNING,可能为FINISHED,可能为CANCEL
+
+当我们查询不到这个Job时,返回结果为:
+
+```json
+{
+ "jobId" : ""
+}
+```
+
+</details>
+
+------------------------------------------------------------------------------------------
+
+### 返回作业的详细信息
+
+此API已经弃用,请使用/hazelcast/rest/maps/job-info/:jobId替代。
+
<details>
<summary><code>GET</code>
<code><b>/hazelcast/rest/maps/running-job/:jobId</b></code>
<code>(返回作业的详细信息。)</code></summary>
diff --git
a/seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/RestApiIT.java
b/seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/RestApiIT.java
index c7be274ad2..3569fb4b11 100644
---
a/seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/RestApiIT.java
+++
b/seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/RestApiIT.java
@@ -197,6 +197,27 @@ public class RestApiIT {
});
}
+ @Test
+ public void testGetJobInfoByJobId() {
+ Arrays.asList(node2, node1)
+ .forEach(
+ instance -> {
+ given().get(
+ HOST
+ + instance.getCluster()
+ .getLocalMember()
+ .getAddress()
+ .getPort()
+ + RestConstant.JOB_INFO_URL
+ + "/"
+ + batchJobProxy.getJobId())
+ .then()
+ .statusCode(200)
+ .body("jobName",
equalTo("fake_to_console"))
+ .body("jobStatus", equalTo("FINISHED"));
+ });
+ }
+
@Test
public void testGetRunningThreads() {
Arrays.asList(node2, node1)
diff --git
a/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/RestConstant.java
b/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/RestConstant.java
index a7e93f2551..6daa817a48 100644
---
a/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/RestConstant.java
+++
b/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/RestConstant.java
@@ -45,8 +45,8 @@ public class RestConstant {
public static final String METRICS = "metrics";
public static final String RUNNING_JOBS_URL =
"/hazelcast/rest/maps/running-jobs";
- public static final String RUNNING_JOB_URL =
"/hazelcast/rest/maps/running-job";
-
+ @Deprecated public static final String RUNNING_JOB_URL =
"/hazelcast/rest/maps/running-job";
+ public static final String JOB_INFO_URL = "/hazelcast/rest/maps/job-info";
public static final String FINISHED_JOBS_INFO =
"/hazelcast/rest/maps/finished-jobs";
public static final String SUBMIT_JOB_URL =
"/hazelcast/rest/maps/submit-job";
public static final String ENCRYPT_CONFIG =
"/hazelcast/rest/maps/encrypt-config";
diff --git
a/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/RestHttpGetCommandProcessor.java
b/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/RestHttpGetCommandProcessor.java
index 25cd51474f..b4110f46ff 100644
---
a/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/RestHttpGetCommandProcessor.java
+++
b/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/RestHttpGetCommandProcessor.java
@@ -63,6 +63,7 @@ import java.util.concurrent.ExecutionException;
import static com.hazelcast.internal.ascii.rest.HttpStatusCode.SC_500;
import static
org.apache.seatunnel.engine.server.rest.RestConstant.FINISHED_JOBS_INFO;
+import static
org.apache.seatunnel.engine.server.rest.RestConstant.JOB_INFO_URL;
import static
org.apache.seatunnel.engine.server.rest.RestConstant.RUNNING_JOBS_URL;
import static
org.apache.seatunnel.engine.server.rest.RestConstant.RUNNING_JOB_URL;
import static
org.apache.seatunnel.engine.server.rest.RestConstant.RUNNING_THREADS;
@@ -99,7 +100,7 @@ public class RestHttpGetCommandProcessor extends
HttpCommandProcessor<HttpGetCom
handleRunningJobsInfo(httpGetCommand);
} else if (uri.startsWith(FINISHED_JOBS_INFO)) {
handleFinishedJobsInfo(httpGetCommand, uri);
- } else if (uri.startsWith(RUNNING_JOB_URL)) {
+ } else if (uri.startsWith(RUNNING_JOB_URL) ||
uri.startsWith(JOB_INFO_URL)) {
handleJobInfoById(httpGetCommand, uri);
} else if (uri.startsWith(SYSTEM_MONITORING_INFORMATION)) {
getSystemMonitoringInformation(httpGetCommand);
@@ -252,24 +253,20 @@ public class RestHttpGetCommandProcessor extends
HttpCommandProcessor<HttpGetCom
uri = StringUtil.stripTrailingSlash(uri);
int indexEnd = uri.indexOf('/', URI_MAPS.length());
String jobId = uri.substring(indexEnd + 1);
-
- JobInfo jobInfo =
- (JobInfo)
- this.textCommandService
- .getNode()
- .getNodeEngine()
- .getHazelcastInstance()
- .getMap(Constant.IMAP_RUNNING_JOB_INFO)
- .get(Long.valueOf(jobId));
-
- JobState finishedJobState =
- (JobState)
- this.textCommandService
- .getNode()
- .getNodeEngine()
- .getHazelcastInstance()
- .getMap(Constant.IMAP_FINISHED_JOB_STATE)
- .get(Long.valueOf(jobId));
+ IMap<Object, Object> jobInfoMap =
+ this.textCommandService
+ .getNode()
+ .getNodeEngine()
+ .getHazelcastInstance()
+ .getMap(Constant.IMAP_RUNNING_JOB_INFO);
+ JobInfo jobInfo = (JobInfo) jobInfoMap.get(Long.valueOf(jobId));
+ IMap<Object, Object> finishedJobStateMap =
+ this.textCommandService
+ .getNode()
+ .getNodeEngine()
+ .getHazelcastInstance()
+ .getMap(Constant.IMAP_FINISHED_JOB_STATE);
+ JobState finishedJobState = (JobState)
finishedJobStateMap.get(Long.valueOf(jobId));
if (!jobId.isEmpty() && jobInfo != null) {
this.prepareResponse(command, convertToJson(jobInfo,
Long.parseLong(jobId)));
} else if (!jobId.isEmpty() && finishedJobState != null) {