Package org.apache.storm.utils
Class ShellUtils
java.lang.Object
org.apache.storm.utils.ShellUtils
- Direct Known Subclasses:
ShellUtils.ShellCommandExecutor
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
This is an IOException with exit code added.static enum
OSType detection.static class
A simple shell command executor. -
Field Summary
Modifier and TypeFieldDescriptionstatic final boolean
static final boolean
static final org.slf4j.Logger
static final boolean
static final com.codahale.metrics.Meter
static final ShellUtils.OSType
static final boolean
static final boolean
protected long
Time after which the executing script would be timed out.static final String
Token separator regex used to parse Shell tool outputs.static final boolean
-
Constructor Summary
ConstructorDescriptionShellUtils
(long interval) ShellUtils
(long interval, boolean redirectErrorStream) Creates a new shell utils instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract String[]
return an array containing the command name & its parameters.int
get the exit code.static String[]
a Unix command to get a given user's groups list.static ShellLogHandler
getLogHandler
(Map<String, Object> topoConf) get the current sub-process executing the given command.boolean
To check if the passed script to shell command executor timed out or not.protected abstract void
parseExecResult
(BufferedReader lines) Parse the execution result.protected void
run()
check to see if a command needs to be executed and execute if needed.protected void
setEnvironment
(Map<String, String> env) set the environment for the command.protected void
setWorkingDirectory
(File dir) set the working directory.
-
Field Details
-
LOG
public static final org.slf4j.Logger LOG -
osType
-
WINDOWS
public static final boolean WINDOWS -
SOLARIS
public static final boolean SOLARIS -
MAC
public static final boolean MAC -
FREEBSD
public static final boolean FREEBSD -
LINUX
public static final boolean LINUX -
OTHER
public static final boolean OTHER -
numShellExceptions
public static final com.codahale.metrics.Meter numShellExceptions -
TOKEN_SEPARATOR_REGEX
Token separator regex used to parse Shell tool outputs. -
timeOutInterval
protected long timeOutIntervalTime after which the executing script would be timed out.
-
-
Constructor Details
-
ShellUtils
public ShellUtils() -
ShellUtils
public ShellUtils(long interval) -
ShellUtils
public ShellUtils(long interval, boolean redirectErrorStream) Creates a new shell utils instance.- Parameters:
interval
- the minimum duration to wait before re-executing the command
-
-
Method Details
-
getGroupsForUserCommand
a Unix command to get a given user's groups list. Windows is not supported. -
getLogHandler
-
getExitCode
public int getExitCode()get the exit code.- Returns:
- the exit code of the process
-
setEnvironment
set the environment for the command.- Parameters:
env
- Mapping of environment variables
-
setWorkingDirectory
set the working directory.- Parameters:
dir
- The directory where the command would be executed
-
run
check to see if a command needs to be executed and execute if needed.- Throws:
IOException
-
getExecString
return an array containing the command name & its parameters. -
parseExecResult
Parse the execution result.- Throws:
IOException
-
getProcess
get the current sub-process executing the given command.- Returns:
- process executing the command
-
isTimedOut
public boolean isTimedOut()To check if the passed script to shell command executor timed out or not.- Returns:
- if the script timed out.
-