Browse Source

code smell

pull/3/MERGE
江蓠 4 years ago
parent
commit
05eabda391
  1. 4
      dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java
  2. 16
      dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java
  3. 1
      dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java
  4. 5
      dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java
  5. 1
      dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactoryTest.java

4
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java

@ -22,6 +22,10 @@ package org.apache.dolphinscheduler.plugin.alert.script;
*/
public class OSUtils {
public OSUtils() {
throw new UnsupportedOperationException("Construct OSUtils");
}
public static Boolean isWindows() {
return System.getProperty("os.name").startsWith("Windows");
}

16
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java

@ -17,10 +17,8 @@
package org.apache.dolphinscheduler.plugin.alert.script;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -41,25 +39,21 @@ public class ProcessUtils {
public static Integer executeScript(String... cmd) {
int exitCode = -1;
ProcessBuilder processBuilder = new ProcessBuilder(cmd);
try {
Process process = processBuilder.start();
InputStream in = process.getErrorStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in));
StringBuilder result = new StringBuilder();
StreamGobbler inputStreamGobbler =
new StreamGobbler(process.getInputStream());
StreamGobbler errorStreamGobbler =
new StreamGobbler(process.getErrorStream());
StreamGobbler inputStreamGobbler = new StreamGobbler(process.getInputStream());
StreamGobbler errorStreamGobbler = new StreamGobbler(process.getErrorStream());
inputStreamGobbler.start();
errorStreamGobbler.start();
return process.waitFor();
} catch (IOException | InterruptedException e) {
logger.error("execute alert script error", e.getMessage());
logger.error("execute alert script error {}", e.getMessage());
Thread.currentThread().interrupt();
}
return exitCode;

1
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java

@ -67,6 +67,7 @@ public class ScriptSender {
return alertResult;
}
alertResult.setMessage("send script alert msg error,exitCode is " + exitCode);
logger.info("send script alert msg error,exitCode is {}", exitCode);
return alertResult;
}

5
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java

@ -38,6 +38,7 @@ public class StreamGobbler extends Thread {
this.inputStream = inputStream;
}
@Override
public void run() {
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader inputBufferReader = new BufferedReader(inputStreamReader);
@ -50,10 +51,10 @@ public class StreamGobbler extends Thread {
output.append(System.getProperty("line.separator"));
}
if (output.length() > 0) {
logger.info(output.toString());
logger.info("out put msg is{}",output.toString());
}
} catch (IOException e) {
logger.error("I/O error occurs %S", e.getMessage());
logger.error("I/O error occurs {}", e.getMessage());
}
}

1
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactoryTest.java

@ -31,7 +31,6 @@ import org.junit.Test;
*/
public class ScriptAlertChannelFactoryTest {
@Test
public void testGetParams() {
ScriptAlertChannelFactory scriptAlertChannelFactory = new ScriptAlertChannelFactory();

Loading…
Cancel
Save