From c4fb45d7c7a226a26ac74c705cdd27a9545f72a6 Mon Sep 17 00:00:00 2001 From: Mahesh Kumar Gangula Date: Mon, 11 Jun 2018 13:11:44 +0530 Subject: [PATCH] Issue #000 fix: threaddump api. --- .../app/controllers/ThreadDumpController.java | 51 +++++++++++++++++++ service/conf/routes | 1 + 2 files changed, 52 insertions(+) create mode 100644 service/app/controllers/ThreadDumpController.java diff --git a/service/app/controllers/ThreadDumpController.java b/service/app/controllers/ThreadDumpController.java new file mode 100644 index 0000000000..c6f6a75c83 --- /dev/null +++ b/service/app/controllers/ThreadDumpController.java @@ -0,0 +1,51 @@ +package controllers; + +import java.lang.management.ManagementFactory; +import java.lang.management.ThreadInfo; +import java.lang.management.ThreadMXBean; + +import org.sunbird.actor.router.BackgroundRequestRouter; +import org.sunbird.actor.service.SunbirdMWService; +import org.sunbird.common.request.Request; + +import play.libs.F.Promise; +import play.mvc.Result; + +/** + * + * @author Mahesh Kumar Gangula + * + */ + +public class ThreadDumpController extends BaseController { + + public Promise threaddump() { + final StringBuilder dump = new StringBuilder(); + final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); + final ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), 100); + for (ThreadInfo threadInfo : threadInfos) { + dump.append('"'); + dump.append(threadInfo.getThreadName()); + dump.append("\" "); + final Thread.State state = threadInfo.getThreadState(); + dump.append("\n java.lang.Thread.State: "); + dump.append(state); + final StackTraceElement[] stackTraceElements = threadInfo.getStackTrace(); + for (final StackTraceElement stackTraceElement : stackTraceElements) { + dump.append("\n at "); + dump.append(stackTraceElement); + } + dump.append("\n\n"); + } + System.out.println("=== thread-dump start ==="); + System.out.println(dump.toString()); + System.out.println("=== thread-dump end ==="); + Request request = new Request(); + request.setOperation("takeThreadDump"); + request.setEnv(getEnvironment()); + if ("off".equalsIgnoreCase(BackgroundRequestRouter.getMode())) { + actorResponseHandler(SunbirdMWService.getBackgroundRequestRouter(), request, timeout, null, request()); + } + return Promise.promise(() -> ok("successful")); + } +} \ No newline at end of file diff --git a/service/conf/routes b/service/conf/routes index 7f8fb1c870..4e09a4b332 100644 --- a/service/conf/routes +++ b/service/conf/routes @@ -87,6 +87,7 @@ GET /v1/user/retire @controllers.LearnerController.getHealth() GET /v1/org/member/suspend @controllers.LearnerController.getHealth() POST /v1/org/search @controllers.organisationmanagement.OrganisationController.search() GET /health @controllers.healthmanager.HealthController.getHealth() +GET /threaddump @controllers.ThreadDumpController.threaddump() #bulk upload