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");
}
public static Boolean isWindows() {
static Boolean isWindows() {
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 ProcessUtils() {
throw new IllegalStateException("Utility class");
}
/**
* executeScript
*
* @param cmd cmd params
* @return exit code
*/
public static Integer executeScript(String... cmd) {
static Integer executeScript(String... cmd) {
int exitCode = -1;
ProcessBuilder processBuilder = new ProcessBuilder(cmd);
try {
Process process = processBuilder.start();
InputStream in = process.getErrorStream();
StreamGobbler inputStreamGobbler = new StreamGobbler(process.getInputStream());
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;
public ScriptSender(Map<String, String> config) {
ScriptSender(Map<String, String> config) {
scriptPath = config.get(ScriptParamsConstants.NAME_SCRIPT_PATH);
scriptType = Integer.parseInt(config.get(ScriptParamsConstants.NAME_SCRIPT_TYPE));
userParams = config.get(ScriptParamsConstants.NAME_SCRIPT_USER_PARAMS);
}
public AlertResult sendScriptAlert(String msg) {
AlertResult sendScriptAlert(String msg) {
AlertResult alertResult = new AlertResult();
if (ScriptType.of(scriptType).equals(ScriptType.SHELL)) {
return executeShellScript(msg);
@ -54,7 +54,7 @@ public class ScriptSender {
private AlertResult executeShellScript(String msg) {
AlertResult alertResult = new AlertResult();
alertResult.setStatus("false");
if (OSUtils.isWindows()) {
if (Boolean.TRUE.equals(OSUtils.isWindows())) {
alertResult.setMessage("shell script not support windows os");
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);
InputStream inputStream;
private InputStream inputStream;
StreamGobbler(InputStream inputStream) {
this.inputStream = inputStream;

Loading…
Cancel
Save