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 class OSUtils {
public OSUtils() {
throw new UnsupportedOperationException("Construct OSUtils");
}
public static Boolean isWindows() { public static Boolean isWindows() {
return System.getProperty("os.name").startsWith("Windows"); 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; package org.apache.dolphinscheduler.plugin.alert.script;
import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -41,25 +39,21 @@ public class ProcessUtils {
public static Integer executeScript(String... cmd) { public static Integer executeScript(String... cmd) {
int exitCode = -1; int exitCode = -1;
ProcessBuilder processBuilder = new ProcessBuilder(cmd); ProcessBuilder processBuilder = new ProcessBuilder(cmd);
try { try {
Process process = processBuilder.start(); Process process = processBuilder.start();
InputStream in = process.getErrorStream(); InputStream in = process.getErrorStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in));
StringBuilder result = new StringBuilder();
StreamGobbler inputStreamGobbler = StreamGobbler inputStreamGobbler = new StreamGobbler(process.getInputStream());
new StreamGobbler(process.getInputStream()); StreamGobbler errorStreamGobbler = new StreamGobbler(process.getErrorStream());
StreamGobbler errorStreamGobbler =
new StreamGobbler(process.getErrorStream());
inputStreamGobbler.start(); inputStreamGobbler.start();
errorStreamGobbler.start(); errorStreamGobbler.start();
return process.waitFor(); return process.waitFor();
} catch (IOException | InterruptedException e) { } 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; 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; return alertResult;
} }
alertResult.setMessage("send script alert msg error,exitCode is " + exitCode); alertResult.setMessage("send script alert msg error,exitCode is " + exitCode);
logger.info("send script alert msg error,exitCode is {}", exitCode);
return alertResult; 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; this.inputStream = inputStream;
} }
@Override
public void run() { public void run() {
InputStreamReader inputStreamReader = new InputStreamReader(inputStream); InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader inputBufferReader = new BufferedReader(inputStreamReader); BufferedReader inputBufferReader = new BufferedReader(inputStreamReader);
@ -50,10 +51,10 @@ public class StreamGobbler extends Thread {
output.append(System.getProperty("line.separator")); output.append(System.getProperty("line.separator"));
} }
if (output.length() > 0) { if (output.length() > 0) {
logger.info(output.toString()); logger.info("out put msg is{}",output.toString());
} }
} catch (IOException e) { } 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 { public class ScriptAlertChannelFactoryTest {
@Test @Test
public void testGetParams() { public void testGetParams() {
ScriptAlertChannelFactory scriptAlertChannelFactory = new ScriptAlertChannelFactory(); ScriptAlertChannelFactory scriptAlertChannelFactory = new ScriptAlertChannelFactory();

Loading…
Cancel
Save