Browse Source

code smell

pull/3/MERGE
江蓠 4 years ago
parent
commit
5b14319cbc
  1. 2
      dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java
  2. 8
      dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java
  3. 6
      dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java
  4. 2
      dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java

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

@ -26,7 +26,7 @@ public class OSUtils {
throw new UnsupportedOperationException("Construct OSUtils"); throw new UnsupportedOperationException("Construct OSUtils");
} }
public static Boolean isWindows() { static Boolean isWindows() {
return System.getProperty("os.name").startsWith("Windows"); return System.getProperty("os.name").startsWith("Windows");
} }
} }

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

@ -30,21 +30,23 @@ public class ProcessUtils {
private static final Logger logger = LoggerFactory.getLogger(ProcessUtils.class); private static final Logger logger = LoggerFactory.getLogger(ProcessUtils.class);
private ProcessUtils() {
throw new IllegalStateException("Utility class");
}
/** /**
* executeScript * executeScript
* *
* @param cmd cmd params * @param cmd cmd params
* @return exit code * @return exit code
*/ */
public static Integer executeScript(String... cmd) { 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();
StreamGobbler inputStreamGobbler = new StreamGobbler(process.getInputStream()); StreamGobbler inputStreamGobbler = new StreamGobbler(process.getInputStream());
StreamGobbler errorStreamGobbler = new StreamGobbler(process.getErrorStream()); StreamGobbler errorStreamGobbler = new StreamGobbler(process.getErrorStream());

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

@ -37,13 +37,13 @@ public class ScriptSender {
private String userParams; private String userParams;
public ScriptSender(Map<String, String> config) { ScriptSender(Map<String, String> config) {
scriptPath = config.get(ScriptParamsConstants.NAME_SCRIPT_PATH); scriptPath = config.get(ScriptParamsConstants.NAME_SCRIPT_PATH);
scriptType = Integer.parseInt(config.get(ScriptParamsConstants.NAME_SCRIPT_TYPE)); scriptType = Integer.parseInt(config.get(ScriptParamsConstants.NAME_SCRIPT_TYPE));
userParams = config.get(ScriptParamsConstants.NAME_SCRIPT_USER_PARAMS); userParams = config.get(ScriptParamsConstants.NAME_SCRIPT_USER_PARAMS);
} }
public AlertResult sendScriptAlert(String msg) { AlertResult sendScriptAlert(String msg) {
AlertResult alertResult = new AlertResult(); AlertResult alertResult = new AlertResult();
if (ScriptType.of(scriptType).equals(ScriptType.SHELL)) { if (ScriptType.of(scriptType).equals(ScriptType.SHELL)) {
return executeShellScript(msg); return executeShellScript(msg);
@ -54,7 +54,7 @@ public class ScriptSender {
private AlertResult executeShellScript(String msg) { private AlertResult executeShellScript(String msg) {
AlertResult alertResult = new AlertResult(); AlertResult alertResult = new AlertResult();
alertResult.setStatus("false"); alertResult.setStatus("false");
if (OSUtils.isWindows()) { if (Boolean.TRUE.equals(OSUtils.isWindows())) {
alertResult.setMessage("shell script not support windows os"); alertResult.setMessage("shell script not support windows os");
return alertResult; return alertResult;
} }

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

@ -32,7 +32,7 @@ public class StreamGobbler extends Thread {
private static final Logger logger = LoggerFactory.getLogger(StreamGobbler.class); private static final Logger logger = LoggerFactory.getLogger(StreamGobbler.class);
InputStream inputStream; private InputStream inputStream;
StreamGobbler(InputStream inputStream) { StreamGobbler(InputStream inputStream) {
this.inputStream = inputStream; this.inputStream = inputStream;

Loading…
Cancel
Save