Browse Source

deal with magic value

pull/3/MERGE
Eights-LI 4 years ago
parent
commit
c24dbc448d
  1. 33
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java
  2. 6
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/ProcessUtils.java
  3. 7
      dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/utils/ProcessUtilsTest.java

33
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java

@ -523,10 +523,9 @@ public final class Constants {
public static final int HEARTBEAT_FOR_ZOOKEEPER_INFO_LENGTH = 10; public static final int HEARTBEAT_FOR_ZOOKEEPER_INFO_LENGTH = 10;
/** /**
* hadoop params constant * hadoop params
*/
/**
* jar * jar
*/ */
public static final String JAR = "jar"; public static final String JAR = "jar";
@ -833,15 +832,15 @@ public final class Constants {
public static final String FLINK_MAIN_CLASS = "-c"; public static final String FLINK_MAIN_CLASS = "-c";
public static final int[] NOT_TERMINATED_STATES = new int[]{ public static final int[] NOT_TERMINATED_STATES = new int[] {
ExecutionStatus.SUBMITTED_SUCCESS.ordinal(), ExecutionStatus.SUBMITTED_SUCCESS.ordinal(),
ExecutionStatus.RUNNING_EXECUTION.ordinal(), ExecutionStatus.RUNNING_EXECUTION.ordinal(),
ExecutionStatus.DELAY_EXECUTION.ordinal(), ExecutionStatus.DELAY_EXECUTION.ordinal(),
ExecutionStatus.READY_PAUSE.ordinal(), ExecutionStatus.READY_PAUSE.ordinal(),
ExecutionStatus.READY_STOP.ordinal(), ExecutionStatus.READY_STOP.ordinal(),
ExecutionStatus.NEED_FAULT_TOLERANCE.ordinal(), ExecutionStatus.NEED_FAULT_TOLERANCE.ordinal(),
ExecutionStatus.WAITTING_THREAD.ordinal(), ExecutionStatus.WAITTING_THREAD.ordinal(),
ExecutionStatus.WAITTING_DEPEND.ordinal() ExecutionStatus.WAITTING_DEPEND.ordinal()
}; };
/** /**
@ -1009,4 +1008,14 @@ public final class Constants {
* Network IP gets priority, default inner outer * Network IP gets priority, default inner outer
*/ */
public static final String NETWORK_PRIORITY_STRATEGY = "dolphin.scheduler.network.priority.strategy"; public static final String NETWORK_PRIORITY_STRATEGY = "dolphin.scheduler.network.priority.strategy";
/**
* exec shell scripts
*/
public static final String SH = "sh";
/**
* pstree, get pud and sub pid
*/
public static final String PSTREE = "pstree";
} }

6
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/ProcessUtils.java

@ -339,7 +339,7 @@ public class ProcessUtils {
FileUtils.writeStringToFile(new File(commandFile), sb.toString(), StandardCharsets.UTF_8); FileUtils.writeStringToFile(new File(commandFile), sb.toString(), StandardCharsets.UTF_8);
} }
String runCmd = "sh " + commandFile; String runCmd = String.format("%s %s", Constants.SH, commandFile);
if (StringUtils.isNotEmpty(tenantCode)) { if (StringUtils.isNotEmpty(tenantCode)) {
runCmd = "sudo -u " + tenantCode + " " + runCmd; runCmd = "sudo -u " + tenantCode + " " + runCmd;
} }
@ -391,12 +391,12 @@ public class ProcessUtils {
Matcher mat = null; Matcher mat = null;
// pstree pid get sub pids // pstree pid get sub pids
if (OSUtils.isMacOS()) { if (OSUtils.isMacOS()) {
String pids = OSUtils.exeCmd("pstree -sp " + processId); String pids = OSUtils.exeCmd(String.format("%s -sp %d", Constants.PSTREE, processId));
if (null != pids) { if (null != pids) {
mat = MACPATTERN.matcher(pids); mat = MACPATTERN.matcher(pids);
} }
} else { } else {
String pids = OSUtils.exeCmd("pstree -p " + processId); String pids = OSUtils.exeCmd(String.format("%s -p %d", Constants.PSTREE, processId));
mat = WINDOWSATTERN.matcher(pids); mat = WINDOWSATTERN.matcher(pids);
} }

7
dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/utils/ProcessUtilsTest.java

@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.server.utils;
import static org.powermock.api.mockito.PowerMockito.when; import static org.powermock.api.mockito.PowerMockito.when;
import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.common.enums.ExecutionStatus; import org.apache.dolphinscheduler.common.enums.ExecutionStatus;
import org.apache.dolphinscheduler.common.utils.HadoopUtils; import org.apache.dolphinscheduler.common.utils.HadoopUtils;
import org.apache.dolphinscheduler.common.utils.OSUtils; import org.apache.dolphinscheduler.common.utils.OSUtils;
@ -57,7 +58,7 @@ public class ProcessUtilsTest {
PowerMockito.mockStatic(OSUtils.class); PowerMockito.mockStatic(OSUtils.class);
when(OSUtils.isMacOS()).thenReturn(true); when(OSUtils.isMacOS()).thenReturn(true);
when(OSUtils.exeCmd("pstree -sp " + processId)).thenReturn(null); when(OSUtils.exeCmd(String.format("%s -p %d", Constants.PSTREE, processId))).thenReturn(null);
String pidListMac = ProcessUtils.getPidsStr(processId); String pidListMac = ProcessUtils.getPidsStr(processId);
Assert.assertEquals("", pidListMac); Assert.assertEquals("", pidListMac);
} }
@ -96,8 +97,8 @@ public class ProcessUtilsTest {
taskExecutionContext.setProcessId(1); taskExecutionContext.setProcessId(1);
PowerMockito.mockStatic(OSUtils.class); PowerMockito.mockStatic(OSUtils.class);
try { try {
when(OSUtils.exeCmd("pstree -sp " + 1)).thenReturn("1111"); when(OSUtils.exeCmd(String.format("%s -sp %d", Constants.PSTREE, 1))).thenReturn("1111");
when(OSUtils.exeCmd("pstree -p " + 1)).thenReturn("1111"); when(OSUtils.exeCmd(String.format("%s -p %d", Constants.PSTREE, 1))).thenReturn("1111");
when(OSUtils.exeCmd("sudo kill -9")).thenReturn("1111"); when(OSUtils.exeCmd("sudo kill -9")).thenReturn("1111");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();

Loading…
Cancel
Save