فهرست منبع

deal with magic value

Eights-LI 4 سال پیش
والد
کامیت
c24dbc448d

+ 21 - 12
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;
 
 
+
     /**
-     * hadoop params constant
-     */
-    /**
+     * hadoop params
      * 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 int[] NOT_TERMINATED_STATES = new int[]{
-            ExecutionStatus.SUBMITTED_SUCCESS.ordinal(),
-            ExecutionStatus.RUNNING_EXECUTION.ordinal(),
-            ExecutionStatus.DELAY_EXECUTION.ordinal(),
-            ExecutionStatus.READY_PAUSE.ordinal(),
-            ExecutionStatus.READY_STOP.ordinal(),
-            ExecutionStatus.NEED_FAULT_TOLERANCE.ordinal(),
-            ExecutionStatus.WAITTING_THREAD.ordinal(),
-            ExecutionStatus.WAITTING_DEPEND.ordinal()
+    public static final int[] NOT_TERMINATED_STATES = new int[] {
+        ExecutionStatus.SUBMITTED_SUCCESS.ordinal(),
+        ExecutionStatus.RUNNING_EXECUTION.ordinal(),
+        ExecutionStatus.DELAY_EXECUTION.ordinal(),
+        ExecutionStatus.READY_PAUSE.ordinal(),
+        ExecutionStatus.READY_STOP.ordinal(),
+        ExecutionStatus.NEED_FAULT_TOLERANCE.ordinal(),
+        ExecutionStatus.WAITTING_THREAD.ordinal(),
+        ExecutionStatus.WAITTING_DEPEND.ordinal()
     };
 
     /**
@@ -1009,4 +1008,14 @@ public final class Constants {
      * Network IP gets priority, default inner outer
      */
     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";
 }

+ 3 - 3
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);
             }
 
-            String runCmd = "sh " + commandFile;
+            String runCmd = String.format("%s %s", Constants.SH, commandFile);
             if (StringUtils.isNotEmpty(tenantCode)) {
                 runCmd = "sudo -u " + tenantCode + " " + runCmd;
             }
@@ -391,12 +391,12 @@ public class ProcessUtils {
         Matcher mat = null;
         // pstree pid get sub pids
         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) {
                 mat = MACPATTERN.matcher(pids);
             }
         } else {
-            String pids = OSUtils.exeCmd("pstree -p " + processId);
+            String pids = OSUtils.exeCmd(String.format("%s -p %d", Constants.PSTREE, processId));
             mat = WINDOWSATTERN.matcher(pids);
         }
 

+ 4 - 3
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 org.apache.dolphinscheduler.common.Constants;
 import org.apache.dolphinscheduler.common.enums.ExecutionStatus;
 import org.apache.dolphinscheduler.common.utils.HadoopUtils;
 import org.apache.dolphinscheduler.common.utils.OSUtils;
@@ -57,7 +58,7 @@ public class ProcessUtilsTest {
 
         PowerMockito.mockStatic(OSUtils.class);
         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);
         Assert.assertEquals("", pidListMac);
     }
@@ -96,8 +97,8 @@ public class ProcessUtilsTest {
         taskExecutionContext.setProcessId(1);
         PowerMockito.mockStatic(OSUtils.class);
         try {
-            when(OSUtils.exeCmd("pstree -sp " + 1)).thenReturn("1111");
-            when(OSUtils.exeCmd("pstree -p " + 1)).thenReturn("1111");
+            when(OSUtils.exeCmd(String.format("%s -sp %d", Constants.PSTREE, 1))).thenReturn("1111");
+            when(OSUtils.exeCmd(String.format("%s -p %d", Constants.PSTREE, 1))).thenReturn("1111");
             when(OSUtils.exeCmd("sudo kill -9")).thenReturn("1111");
         } catch (Exception e) {
             e.printStackTrace();