[
https://issues.apache.org/jira/browse/YARN-11823?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18064546#comment-18064546
]
ASF GitHub Bot commented on YARN-11823:
---------------------------------------
Hean-Chhinling commented on code in PR #8123:
URL: https://github.com/apache/hadoop/pull/8123#discussion_r2912902586
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/webapp/DiagnosticJStackService.java:
##########
@@ -0,0 +1,148 @@
+/** * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.yarn.server.nodemanager.webapp;
+
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.util.Shell;
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+import org.apache.hadoop.yarn.api.records.ContainerId;
+import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
+import org.apache.hadoop.yarn.server.nodemanager.Context;
+import
org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application;
+import
org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperationExecutor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+public class DiagnosticJStackService {
+
+ private static final Logger LOG =
LoggerFactory.getLogger(DiagnosticJStackService.class);
+
+ private static final String NM_USER = System.getProperty("user.name");
+ private static final String JSTACK_PATH = System.getProperty("java.home") +
"/bin/jstack";
+ private final Context context;
+ private final Configuration conf;
+
+ public DiagnosticJStackService(Context context) {
+ this.context = context;
+ this.conf = context.getConf();
+ }
+
+ public String collectNodeThreadDump(int numberOfJStack) throws IOException {
+ checkShellNotWindows();
+
+ long nodeManagerPid = ProcessHandle.current().pid();
+
+ return runJStack(nodeManagerPid, numberOfJStack);
+ }
+
+ public String collectApplicationThreadDump(String appId, int numberOfJStack)
throws IOException {
+ checkShellNotWindows();
+
+ ApplicationId applicationId = ApplicationId.fromString(appId);
+ Map<ContainerId, List<Long>> containerPids =
getApplicationContainerPids(applicationId);
+
+ return runJStack(containerPids, numberOfJStack);
+ }
+
+ private void checkShellNotWindows() {
+ if (Shell.WINDOWS) {
+ throw new UnsupportedOperationException("Not implemented for Windows.");
+ }
+ }
+
+ protected Map<ContainerId, List<Long>>
getApplicationContainerPids(ApplicationId appId){
+ Application app = context.getApplications().get(appId);
+ if (app == null){
+ throw new YarnRuntimeException("Application " + appId + " does not
exist");
+ }
+
+ Map<ContainerId, List<Long>> containerPids = new HashMap<>();
+
+ for (ContainerId containerId : app.getContainers().keySet()){
+ String pidForContainerIdStr =
context.getContainerExecutor().getProcessId(containerId);
+ long parentPid = Long.parseLong(pidForContainerIdStr);
+
+ List<Long> javaContainerPids = ProcessHandle.of(parentPid).stream()
+ .flatMap(ProcessHandle::descendants)
+ .filter(childProcess ->
childProcess.info().command().orElse("").contains("java"))
Review Comment:
Good idea, i will put those non-java container in the response.
> New JStack endpoint for running containers and nodes
> ----------------------------------------------------
>
> Key: YARN-11823
> URL: https://issues.apache.org/jira/browse/YARN-11823
> Project: Hadoop YARN
> Issue Type: New Feature
> Components: yarn
> Reporter: chhinlinghean
> Assignee: chhinlinghean
> Priority: Major
> Labels: pull-request-available
>
> Getting jstack for container is not trivial to most people. This new endpoint
> aims to streamline the process of getting jstack of running containers and
> nodes. It mainly use in the DiagnosticCollector script.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]