diff --git a/seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/joblog/JobLogIT.java b/seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/joblog/JobLogIT.java index 8f6314cf085..611dc286239 100644 --- a/seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/joblog/JobLogIT.java +++ b/seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/joblog/JobLogIT.java @@ -18,6 +18,7 @@ package org.apache.seatunnel.engine.e2e.joblog; import org.apache.seatunnel.common.constants.JobMode; +import org.apache.seatunnel.common.utils.JsonUtils; import org.apache.seatunnel.e2e.common.util.ContainerUtil; import org.apache.seatunnel.engine.e2e.SeaTunnelEngineContainer; import org.apache.seatunnel.engine.server.rest.RestConstant; @@ -117,6 +118,8 @@ public void testJobLogFile() throws Exception { assertConsoleLog(); assertFileLog(); + assertLogFormatType(); + List> before = Lists.newArrayList( Tuple2.tuple2(false, "job-" + CUSTOM_JOB_ID + ".log"), @@ -160,6 +163,30 @@ private void assertConsoleLog() { }); } + private void assertLogFormatType() throws IOException, InterruptedException { + final String baseUrl = "curl http://localhost:8080/logs"; + final String htmlUrl = baseUrl; + final String jsonUrl = baseUrl + "?format=JSON"; + final String expectedHtmlTitle = "Seatunnel log"; + + // Execute commands and get results for both HTML and JSON logs + Container.ExecResult htmlExecResult = server.execInContainer("sh", "-c", htmlUrl); + Container.ExecResult jsonExecResult = server.execInContainer("sh", "-c", jsonUrl); + + // Get the stdout of each execution result + String htmlOutput = htmlExecResult.getStdout(); + String jsonOutput = jsonExecResult.getStdout(); + + // Verify HTML response contains expected title + Assertions.assertTrue(htmlOutput.contains(expectedHtmlTitle)); + + // Verify JSON response is valid JSON + Assertions.assertDoesNotThrow( + () -> JsonUtils.parseArray(jsonOutput), + "JSON format log list interface exception, returned type is not JSON, content:" + + jsonOutput); + } + private void assertFileLog() throws IOException, InterruptedException { String catLog = "cat /tmp/seatunnel/logs/job-862969647010611201.log"; String apiGetLog = "curl http://localhost:8080/log/job-862969647010611201.log"; diff --git a/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/servlet/AllNodeLogServlet.java b/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/servlet/AllNodeLogServlet.java index fbc1434d91c..a3f867b1025 100644 --- a/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/servlet/AllNodeLogServlet.java +++ b/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/servlet/AllNodeLogServlet.java @@ -66,7 +66,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) FormatType formatType = FormatType.fromString(req.getParameter("format")); switch (formatType) { case JSON: - writeJson(resp, logService.allNodeLogFormatHtml(jobId)); + writeJson(resp, logService.allNodeLogFormatJson(jobId)); return; case HTML: default: