Hisoka-X commented on code in PR #7818:
URL: https://github.com/apache/seatunnel/pull/7818#discussion_r1806380394


##########
docs/zh/seatunnel-engine/rest-api-v2.md:
##########
@@ -738,4 +738,75 @@ seatunnel:
   "message": "Invalid JSON format in request body."
 }
 ```
-</details>
\ No newline at end of file
+</details>
+
+
+------------------------------------------------------------------------------------------
+
+### 获取所有节点日志内容
+
+<details>
+ <summary><code>GET</code> <code><b>/logs/:jobId</b></code> 
<code>(返回日志列表。)</code></summary></summary>
+
+#### 请求参数
+
+#### 参数(在请求体中params字段中添加)
+
+> |         参数名称         |   是否必传   |  参数类型  |               参数描述              
  |
+> 
|----------------------|----------|--------|-----------------------------------|
+> | jobId                | optional | string | job id                          
  |
+
+当`jobId`为空时,返回所有节点的日志信息,否则返回指定`jobId`在所有节点的的日志列表。
+
+#### 响应
+
+返回请求节点的日志列表、内容
+
+#### 返回所有日志文件列表
+
+如果你想先查看日志列表,可以通过`GET`请求获取日志列表,`http://localhost:8080/seatunnel/logs?format=json`
+
+```json
+[
+  {
+    "node": "localhost:8080",
+    "logLink": 
"http://localhost:8080/seatunnel/logs/job-899485770241277953.log";,
+    "logName": "job-899485770241277953.log"
+  },
+  {
+    "node": "localhost:8080",
+    "logLink": 
"http://localhost:8080/seatunnel/logs/job-899470314109468673.log";,
+    "logName": "job-899470314109468673.log"
+  }
+]
+```
+
+当前支持的格式有`json`和`html`,默认为`html`。
+
+
+#### 例子
+
+获取所有节点jobId为`733584788375666689`的日志信息:`http://localhost:8080/logs/733584788375666689`
+获取所有节点日志列表:`http://localhost:8080/logs`
+获取所有节点日志列表以JSON格式返回:`http://localhost:8080/logs?format=json`
+获取日志文件内容:`http://localhost:8080/logs/job-898380162133917698.log`
+
+
+</details>
+
+
+### 获取单节点日志内容
+
+<details>
+ <summary><code>GET</code> <code><b>/hazelcast/rest/maps/log</b></code> 
<code>(返回日志列表。)</code></summary></summary>

Review Comment:
   why v1 path?



##########
seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/servlet/AllLogNameServlet.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.seatunnel.engine.server.rest.servlet;
+
+import org.apache.seatunnel.common.exception.SeaTunnelRuntimeException;
+import org.apache.seatunnel.common.utils.FileUtils;
+
+import com.hazelcast.spi.impl.NodeEngineImpl;
+import lombok.extern.slf4j.Slf4j;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.stream.Collectors;
+
+@Slf4j
+public class AllLogNameServlet extends LogBaseServlet {
+
+    public AllLogNameServlet(NodeEngineImpl nodeEngine) {
+        super(nodeEngine);
+    }
+
+    @Override
+    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+            throws ServletException, IOException {
+
+        String logPath = getLogPath();
+        List<File> logFileList = FileUtils.listFile(logPath);
+        List<String> fileNameList =
+                
logFileList.stream().map(File::getName).collect(Collectors.toList());
+        try {
+            writeJson(resp, fileNameList);
+        } catch (SeaTunnelRuntimeException e) {
+            resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);

Review Comment:
   ditto



##########
seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/joblog/JobLogIT.java:
##########
@@ -134,15 +134,18 @@ private void assertConsoleLog() {
     }
 
     private void assertFileLog() throws IOException, InterruptedException {
-        Container.ExecResult execResult =
-                server.execInContainer(
-                        "sh", "-c", "cat 
/tmp/seatunnel/logs/job-862969647010611201.log");
+        String catLog = "cat /tmp/seatunnel/logs/job-862969647010611201.log";
+        String apiGetLog =
+                "curl 
http://localhost:5801/hazelcast/rest/maps/log/job-862969647010611201.log";;

Review Comment:
   please test with our new rest api.



##########
docs/zh/seatunnel-engine/rest-api-v2.md:
##########
@@ -738,4 +738,75 @@ seatunnel:
   "message": "Invalid JSON format in request body."
 }
 ```
-</details>
\ No newline at end of file
+</details>
+
+
+------------------------------------------------------------------------------------------
+
+### 获取所有节点日志内容
+
+<details>
+ <summary><code>GET</code> <code><b>/logs/:jobId</b></code> 
<code>(返回日志列表。)</code></summary></summary>
+
+#### 请求参数
+
+#### 参数(在请求体中params字段中添加)
+
+> |         参数名称         |   是否必传   |  参数类型  |               参数描述              
  |
+> 
|----------------------|----------|--------|-----------------------------------|
+> | jobId                | optional | string | job id                          
  |
+
+当`jobId`为空时,返回所有节点的日志信息,否则返回指定`jobId`在所有节点的的日志列表。
+
+#### 响应
+
+返回请求节点的日志列表、内容
+
+#### 返回所有日志文件列表
+
+如果你想先查看日志列表,可以通过`GET`请求获取日志列表,`http://localhost:8080/seatunnel/logs?format=json`

Review Comment:
   ```suggestion
   如果你想先查看日志列表,可以通过`GET`请求获取日志列表,`http://localhost:8080/logs?format=json`
   ```



##########
seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/RestHttpGetCommandProcessor.java:
##########
@@ -763,4 +800,266 @@ private JsonObject getJobInfoJson(JobState jobState, 
String jobMetrics, JobDAGIn
                 .add(RestConstant.PLUGIN_JARS_URLS, new JsonArray())
                 .add(RestConstant.METRICS, 
toJsonObject(getJobMetrics(jobMetrics)));
     }
+
+    private PropertiesConfiguration getLogConfiguration() {
+        LoggerContext context = (LoggerContext) LogManager.getContext(false);
+        return (PropertiesConfiguration) context.getConfiguration();
+    }
+
+    private void getAllNodeLog(HttpGetCommand httpGetCommand, String uri)
+            throws NoSuchFieldException, IllegalAccessException {
+
+        // Analysis uri, get logName and jobId param
+        String param = getParam(uri);
+        boolean isLogFile = param.contains(".log");
+        String logName = isLogFile ? param : StringUtils.EMPTY;
+        String jobId = !isLogFile ? param : StringUtils.EMPTY;
+
+        String logPath = getLogPath();
+        if (StringUtils.isBlank(logPath)) {
+            logger.warning(
+                    "Log file path is empty, no log file path configured in 
the current configuration file");
+            httpGetCommand.send400();

Review Comment:
   ```suggestion
               httpGetCommand.send404();
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to