|
|
@ -18,6 +18,7 @@ package cn.escheduler.server.utils; |
|
|
|
|
|
|
|
|
|
|
|
import cn.escheduler.common.Constants; |
|
|
|
import cn.escheduler.common.Constants; |
|
|
|
import cn.escheduler.common.utils.CommonUtils; |
|
|
|
import cn.escheduler.common.utils.CommonUtils; |
|
|
|
|
|
|
|
import cn.escheduler.common.utils.OSUtils; |
|
|
|
import cn.escheduler.dao.model.TaskInstance; |
|
|
|
import cn.escheduler.dao.model.TaskInstance; |
|
|
|
import cn.escheduler.server.rpc.LogClient; |
|
|
|
import cn.escheduler.server.rpc.LogClient; |
|
|
|
import org.apache.commons.io.FileUtils; |
|
|
|
import org.apache.commons.io.FileUtils; |
|
|
@ -33,6 +34,7 @@ import java.util.List; |
|
|
|
import java.util.regex.Matcher; |
|
|
|
import java.util.regex.Matcher; |
|
|
|
import java.util.regex.Pattern; |
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* mainly used to get the start command line of a process |
|
|
|
* mainly used to get the start command line of a process |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -139,6 +141,8 @@ public class ProcessUtils { |
|
|
|
|
|
|
|
|
|
|
|
{' ', '\t', '<', '>'}, {' ', '\t'}}; |
|
|
|
{' ', '\t', '<', '>'}, {' ', '\t'}}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static Matcher matcher; |
|
|
|
|
|
|
|
|
|
|
|
private static String createCommandLine(int verificationType, final String executablePath, final String[] cmd) { |
|
|
|
private static String createCommandLine(int verificationType, final String executablePath, final String[] cmd) { |
|
|
|
StringBuilder cmdbuf = new StringBuilder(80); |
|
|
|
StringBuilder cmdbuf = new StringBuilder(80); |
|
|
|
|
|
|
|
|
|
|
@ -256,11 +260,11 @@ public class ProcessUtils { |
|
|
|
return ; |
|
|
|
return ; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String cmd = String.format("sudo kill -9 %d", processId); |
|
|
|
String cmd = String.format("sudo kill -9 %s", getPidsStr(processId)); |
|
|
|
|
|
|
|
|
|
|
|
logger.info("process id:{}, cmd:{}", processId, cmd); |
|
|
|
logger.info("process id:{}, cmd:{}", processId, cmd); |
|
|
|
|
|
|
|
|
|
|
|
Runtime.getRuntime().exec(cmd); |
|
|
|
OSUtils.exeCmd(cmd); |
|
|
|
|
|
|
|
|
|
|
|
// find log and kill yarn job
|
|
|
|
// find log and kill yarn job
|
|
|
|
killYarnJob(taskInstance); |
|
|
|
killYarnJob(taskInstance); |
|
|
@ -270,6 +274,23 @@ public class ProcessUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* get pids str |
|
|
|
|
|
|
|
* @param processId |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
* @throws Exception |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private static String getPidsStr(int processId)throws Exception{ |
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
|
|
|
|
// pstree -p pid get sub pids
|
|
|
|
|
|
|
|
String pids = OSUtils.exeCmd("pstree -p " +processId+ ""); |
|
|
|
|
|
|
|
Matcher mat = Pattern.compile("(\\d+)").matcher(pids); |
|
|
|
|
|
|
|
while (mat.find()){ |
|
|
|
|
|
|
|
sb.append(mat.group()+" "); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return sb.toString().trim(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* find logs and kill yarn tasks |
|
|
|
* find logs and kill yarn tasks |
|
|
|
* @param taskInstance |
|
|
|
* @param taskInstance |
|
|
|