From 52d80aed57e4fcbd8c08963d0437acab2bd751ee Mon Sep 17 00:00:00 2001 From: liugddx Date: Thu, 12 Sep 2024 22:55:01 +0800 Subject: [PATCH] 1 --- .../engine/server/rest/RestConstant.java | 1 + .../rest/RestHttpGetCommandProcessor.java | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) 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 3cb3938bb4f3..1089124aabd0 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 @@ -52,6 +52,7 @@ public class RestConstant { public static final String FINISHED_JOBS_INFO = "/hazelcast/rest/maps/finished-jobs"; public static final String ENCRYPT_CONFIG = "/hazelcast/rest/maps/encrypt-config"; public static final String THREAD_DUMP = "/hazelcast/rest/maps/thread-dump"; + public static final String THREAD_DUMP_URL = "/hazelcast/rest/maps/static"; // only for test use public static final String RUNNING_THREADS = "/hazelcast/rest/maps/running-threads"; 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 997ab92cb56c..bb77f3398173 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 @@ -64,7 +64,9 @@ import io.prometheus.client.exporter.common.TextFormat; import java.io.IOException; +import java.io.InputStream; import java.io.StringWriter; +import java.net.URL; import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; @@ -94,6 +96,7 @@ import static org.apache.seatunnel.engine.server.rest.RestConstant.TELEMETRY_METRICS_URL; import static org.apache.seatunnel.engine.server.rest.RestConstant.TELEMETRY_OPEN_METRICS_URL; import static org.apache.seatunnel.engine.server.rest.RestConstant.THREAD_DUMP; +import static org.apache.seatunnel.engine.server.rest.RestConstant.THREAD_DUMP_URL; public class RestHttpGetCommandProcessor extends HttpCommandProcessor { @@ -147,6 +150,8 @@ public void handle(HttpGetCommand httpGetCommand) { handleMetrics(httpGetCommand, TextFormat.CONTENT_TYPE_OPENMETRICS_100); } else if (uri.startsWith(THREAD_DUMP)) { getThreadDump(httpGetCommand); + } else if (uri.startsWith(THREAD_DUMP_URL)) { + handleStaticResource(httpGetCommand); } else { original.handle(httpGetCommand); } @@ -226,6 +231,29 @@ public void getThreadDump(HttpGetCommand command) { this.prepareResponse(command, threadInfoList); } + private void handleStaticResource(HttpGetCommand httpGetCommand) { + String uri = httpGetCommand.getURI(); + // Remove leading slash + if (uri.startsWith("/")) { + uri = uri.substring(1); + } + + // Get the resource from the classpath + URL resource = getClass().getResource(uri); + if (resource != null) { + try (InputStream inputStream = resource.openStream()) { + byte[] content = new byte[inputStream.available()]; + inputStream.read(content); + httpGetCommand.send200(); + } catch (IOException e) { + logger.warning("Error reading static resource: " + uri, e); + httpGetCommand.send404(); + } + } else { + httpGetCommand.send404(); + } + } + private void getSystemMonitoringInformation(HttpGetCommand command) { Cluster cluster = textCommandService.getNode().hazelcastInstance.getCluster(); nodeEngine = textCommandService.getNode().hazelcastInstance.node.nodeEngine;