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 6b36f90 commit 52d80ae
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
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 @@ -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;
Expand Down Expand Up @@ -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<HttpGetCommand> {

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 52d80ae

Please sign in to comment.