Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
gdliu3 committed Dec 26, 2023
1 parent 20ed5df commit 7fc7580
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 3 deletions.
28 changes: 28 additions & 0 deletions docs/en/seatunnel-engine/rest-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,31 @@ For more information about customize encryption, please refer to the documentati

</details>

### Get Log

<details>
<summary><code>GET</code> <code><b>/hazelcast/rest/maps/log</b></code> <code>(Returns detail log info.)</code></summary>

#### Parameters

#### Responses

```text
2023-12-26 09:12:38,881 WARN [c.h.i.AddressPicker ] [main] - [LOCAL] [seatunnel-620467] [5.1] You configured your member address as host name. Please be aware of that your dns can be spoofed. Make sure that your dns configurations are correct.
2023-12-26 09:12:38,896 INFO [c.h.i.AddressPicker ] [main] - [LOCAL] [seatunnel-620467] [5.1] Resolving domain name 'localhost' to address(es): [127.0.0.1, 0:0:0:0:0:0:0:1]
2023-12-26 09:12:38,897 INFO [c.h.i.AddressPicker ] [main] - [LOCAL] [seatunnel-620467] [5.1] Interfaces is disabled, trying to pick one address from TCP-IP config addresses: [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1]
2023-12-26 09:12:38,926 INFO [o.a.s.e.s.SeaTunnelServer ] [main] - SeaTunnel server start...
2023-12-26 09:12:38,928 INFO [c.h.system ] [main] - [localhost]:5801 [seatunnel-620467] [5.1] Based on Hazelcast IMDG version: 5.1.0 (20220228 - 21f20e7)
2023-12-26 09:12:38,928 INFO [c.h.system ] [main] - [localhost]:5801 [seatunnel-620467] [5.1] Cluster name: seatunnel-620467
2023-12-26 09:12:38,928 INFO [c.h.system ] [main] - [localhost]:5801 [seatunnel-620467] [5.1]
_____ _____ _
/ ___| |_ _| | |
\ `--. ___ __ _ | | _ _ _ __ _ __ ___ | |
`--. \ / _ \ / _` | | | | | | || '_ \ | '_ \ / _ \| |
/\__/ /| __/| (_| | | | | |_| || | | || | | || __/| |
\____/ \___| \__,_| \_/ \__,_||_| |_||_| |_| \___||_|
```
</details>
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,19 @@
import io.restassured.response.Response;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import static io.restassured.RestAssured.given;
import static org.apache.seatunnel.engine.server.rest.RestConstant.LOG_FILE_NAME;
import static org.apache.seatunnel.engine.server.rest.RestConstant.LOG_PATH;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.lessThan;

Expand All @@ -65,6 +73,8 @@ public class RestApiIT {
private static final String jobName = "test测试";
private static final String paramJobName = "param_test测试";

private static final String content = "Hello, World!";

@BeforeEach
void beforeClass() throws Exception {
String testClusterName = TestUtils.getClusterName("RestApiIT");
Expand Down Expand Up @@ -454,6 +464,42 @@ public void testEncryptConfig() {
});
}

@Test
public void testLog() throws IOException {

System.setProperty(LOG_PATH, "/tmp/seatunnel");
System.setProperty(LOG_FILE_NAME, "seatunnel");

String logPath = System.getProperty(LOG_PATH);
String logName = System.getProperty(LOG_FILE_NAME) + ".log";
File file = new File(Paths.get(logPath, logName).toString());
FileOutputStream fos = new FileOutputStream(file);
try (OutputStreamWriter writer = new OutputStreamWriter(fos, StandardCharsets.UTF_8)) {
writer.write(content);
}

Arrays.asList(node2, node1)
.forEach(
instance -> {
String response =
given().get(
HOST
+ instance.getCluster()
.getLocalMember()
.getAddress()
.getPort()
+ RestConstant.GET_LOG)
.then()
.contentType("text/plain")
.statusCode(200)
.extract()
.asString();
Assertions.assertEquals(content, response);
});

file.delete();
}

@AfterEach
void afterClass() {
if (node1 != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public class RestConstant {
public static final String ERROR_MSG = "errorMsg";

public static final String METRICS = "metrics";

public static final String LOG_PATH = "seatunnel.logs.path";

public static final String LOG_FILE_NAME = "seatunnel.logs.file_name";

public static final String RUNNING_JOBS_URL = "/hazelcast/rest/maps/running-jobs";
public static final String RUNNING_JOB_URL = "/hazelcast/rest/maps/running-job";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@

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.GET_LOG;
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.SYSTEM_MONITORING_INFORMATION;
import static org.apache.seatunnel.engine.server.rest.RestConstant.GET_LOG;

public class RestHttpGetCommandProcessor extends HttpCommandProcessor<HttpGetCommand> {

private final Log4j2HttpGetCommandProcessor original;
Expand Down Expand Up @@ -111,7 +112,7 @@ public void handle(HttpGetCommand httpGetCommand) {
getSystemMonitoringInformation(httpGetCommand);
} else if (uri.startsWith(GET_LOG)) {
handleLog(httpGetCommand);
}else {
} else {
original.handle(httpGetCommand);
}
} catch (IndexOutOfBoundsException e) {
Expand Down Expand Up @@ -168,7 +169,7 @@ private void getSystemMonitoringInformation(HttpGetCommand command) {
private void handleLog(HttpGetCommand command) throws IOException {

String logPath = System.getProperty("seatunnel.logs.path");
String logName = System.getProperty("seatunnel.logs.file_name")+".log";
String logName = System.getProperty("seatunnel.logs.file_name") + ".log";
Path path = Paths.get(logPath, logName);
if (!Files.exists(path)) {
this.prepareResponse(command, new JsonObject());
Expand Down

0 comments on commit 7fc7580

Please sign in to comment.