Browse Source

fix: 修复odpscmd问题

许家凯 4 years ago
parent
commit
eecb54cb2a
1 changed files with 29 additions and 6 deletions
  1. 29 6
      src/main/java/com/winhc/dataworks/flow/touch/cmd/OdpsCmd.java

+ 29 - 6
src/main/java/com/winhc/dataworks/flow/touch/cmd/OdpsCmd.java

@@ -7,12 +7,14 @@ import lombok.AllArgsConstructor;
 import lombok.Getter;
 import lombok.Getter;
 import lombok.Setter;
 import lombok.Setter;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang3.SystemUtils;
 import org.apache.commons.lang3.SystemUtils;
 
 
 import java.io.File;
 import java.io.File;
 import java.time.LocalDateTime;
 import java.time.LocalDateTime;
 import java.time.ZoneId;
 import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.List;
 import java.util.Locale;
 import java.util.Locale;
 import java.util.Objects;
 import java.util.Objects;
@@ -72,27 +74,48 @@ public class OdpsCmd {
     }
     }
 
 
 
 
-    private List<String> execute(String cmd) {
-        return RuntimeUtil.execForLines(baseCmd + " --project "+project_name+" -e \"" + cmd + "\";");
+    private synchronized List<String> execute(String cmd) {
+        String c = baseCmd + " --project winhc_eci_dev " + " -e \"" + cmd + "\";";
+        log.info(c);
+        List<String> execute = new ArrayList<>();
+        if (SystemUtils.IS_OS_WINDOWS) {
+            execute = RuntimeUtil.execForLines(c);
+        } else {
+            String fs = basePath + "/xjk_start.sh";
+            try {
+                File file = new File(fs);
+                if (!file.exists()) {
+                    file.createNewFile();
+                }
+                file.setExecutable(true);
+                List<String> list = new ArrayList<String>();
+                list.add("#!/bin/bash");
+                list.add(c);
+                FileUtils.writeLines(file, list, false);
+                execute = RuntimeUtil.execForLines(fs);
+            } catch (Exception e) {
+                log.error(e.getMessage(), e);
+            }
+        }
+        log.info("out:\n{}", String.join("\n", execute));
+        return execute;
     }
     }
 
 
     private static final Pattern pattern = Pattern.compile("(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) +(\\w+?) +(\\w+?) +(\\w+?) +([0-9a-zA-Z\\._]+?) *");
     private static final Pattern pattern = Pattern.compile("(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) +(\\w+?) +(\\w+?) +(\\w+?) +([0-9a-zA-Z\\._]+?) *");
 
 
     public Boolean kill(String instanceId) {
     public Boolean kill(String instanceId) {
-        List<String> execute = execute("spark kill -i " + instanceId);
-        execute.forEach(System.out::println);
+        execute("spark kill -i " + instanceId);
         return true;
         return true;
     }
     }
 
 
     public List<SparkJobInfo> query(String state) {
     public List<SparkJobInfo> query(String state) {
         List<String> execute = execute("spark list -s " + state.toUpperCase());
         List<String> execute = execute("spark list -s " + state.toUpperCase());
-        execute.forEach(System.out::println);
         return execute.stream().filter(str -> !str.startsWith("StartTime")).map(str -> {
         return execute.stream().filter(str -> !str.startsWith("StartTime")).map(str -> {
             Matcher m = pattern.matcher(str);
             Matcher m = pattern.matcher(str);
             if (m.find()) {
             if (m.find()) {
                 return new SparkJobInfo(parse(m.group(1)), m.group(2), m.group(3), m.group(4), m.group(5));
                 return new SparkJobInfo(parse(m.group(1)), m.group(2), m.group(3), m.group(4), m.group(5));
             } else {
             } else {
-                log.error("execute result is error!");
+                log.error("error str : {}", str);
                 return null;
                 return null;
             }
             }
         }).filter(Objects::nonNull).collect(Collectors.toList());
         }).filter(Objects::nonNull).collect(Collectors.toList());