From 8ac7848de672539a7ae2d81994762bd8196db9c2 Mon Sep 17 00:00:00 2001 From: liugddx Date: Thu, 12 Sep 2024 22:52:07 +0800 Subject: [PATCH] 1 --- .../engine/server/rest/RestConstant.java | 1 + .../rest/RestHttpGetCommandProcessor.java | 31 ++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) 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 3cb3938bb4f..1089124aabd 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 997ab92cb56..6c7b2eaf7b9 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 @@ -17,6 +17,7 @@ package org.apache.seatunnel.engine.server.rest; +import static org.apache.seatunnel.engine.server.rest.RestConstant.THREAD_DUMP_URL; import org.apache.seatunnel.shade.com.fasterxml.jackson.core.JsonProcessingException; import org.apache.seatunnel.shade.com.fasterxml.jackson.databind.JsonNode; import org.apache.seatunnel.shade.com.fasterxml.jackson.databind.ObjectMapper; @@ -64,7 +65,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; @@ -147,7 +150,10 @@ public void handle(HttpGetCommand httpGetCommand) { handleMetrics(httpGetCommand, TextFormat.CONTENT_TYPE_OPENMETRICS_100); } else if (uri.startsWith(THREAD_DUMP)) { getThreadDump(httpGetCommand); - } else { + } else if (uri.startsWith(THREAD_DUMP_URL)) { + handleStaticResource(httpGetCommand); + } + else { original.handle(httpGetCommand); } } catch (IndexOutOfBoundsException e) { @@ -226,6 +232,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;