Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
liugddx committed Sep 12, 2024
1 parent 5b65ac9 commit 8ac7848
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8ac7848

Please sign in to comment.