|
|
|
@ -14,8 +14,12 @@
|
|
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
|
* limitations under the License. |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
package org.apache.dolphinscheduler.common.shell; |
|
|
|
|
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader; |
|
|
|
|
import java.io.File; |
|
|
|
|
import java.io.IOException; |
|
|
|
@ -27,10 +31,6 @@ import java.util.TimerTask;
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
|
import java.util.concurrent.atomic.AtomicBoolean; |
|
|
|
|
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* A base class for running a Unix command. |
|
|
|
|
* |
|
|
|
@ -93,8 +93,6 @@ public abstract class AbstractShell {
|
|
|
|
|
this.lastTime = (interval < 0) ? 0 : -interval; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* set the environment for the command |
|
|
|
|
* @param env Mapping of environment variables |
|
|
|
@ -124,7 +122,6 @@ public abstract class AbstractShell {
|
|
|
|
|
runCommand(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Run a command actual work |
|
|
|
|
*/ |
|
|
|
@ -147,8 +144,7 @@ public abstract class AbstractShell {
|
|
|
|
|
|
|
|
|
|
if (timeOutInterval > 0) { |
|
|
|
|
timeOutTimer = new Timer(); |
|
|
|
|
timeoutTimerTask = new ShellTimeoutTimerTask( |
|
|
|
|
this); |
|
|
|
|
timeoutTimerTask = new ShellTimeoutTimerTask(this); |
|
|
|
|
//One time scheduling.
|
|
|
|
|
timeOutTimer.schedule(timeoutTimerTask, timeOutInterval); |
|
|
|
|
} |
|
|
|
@ -191,7 +187,9 @@ public abstract class AbstractShell {
|
|
|
|
|
try { |
|
|
|
|
errThread.start(); |
|
|
|
|
inThread.start(); |
|
|
|
|
} catch (IllegalStateException ise) { } |
|
|
|
|
} catch (IllegalStateException ise) { |
|
|
|
|
logger.warn("Illegal while starting the error and in thread", ise); |
|
|
|
|
} |
|
|
|
|
try { |
|
|
|
|
// parse the output
|
|
|
|
|
exitCode = process.waitFor(); |
|
|
|
@ -245,8 +243,7 @@ public abstract class AbstractShell {
|
|
|
|
|
* @param lines lines |
|
|
|
|
* @throws IOException errors |
|
|
|
|
*/ |
|
|
|
|
protected abstract void parseExecResult(BufferedReader lines) |
|
|
|
|
throws IOException; |
|
|
|
|
protected abstract void parseExecResult(BufferedReader lines) throws IOException; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* get the current sub-process executing the given command |
|
|
|
@ -271,8 +268,6 @@ public abstract class AbstractShell {
|
|
|
|
|
this.timedOut.set(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Timer which is used to timeout scripts spawned off by shell. |
|
|
|
|
*/ |
|
|
|
@ -323,9 +318,11 @@ public abstract class AbstractShell {
|
|
|
|
|
*/ |
|
|
|
|
public static class ProcessContainer extends ConcurrentHashMap<Integer, Process> { |
|
|
|
|
private static final ProcessContainer container = new ProcessContainer(); |
|
|
|
|
|
|
|
|
|
private ProcessContainer() { |
|
|
|
|
super(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static final ProcessContainer getInstance() { |
|
|
|
|
return container; |
|
|
|
|
} |
|
|
|
@ -333,6 +330,7 @@ public abstract class AbstractShell {
|
|
|
|
|
public static void putProcess(Process process) { |
|
|
|
|
getInstance().put(process.hashCode(), process); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static int processSize() { |
|
|
|
|
return getInstance().size(); |
|
|
|
|
} |
|
|
|
|