Package org.apache.storm.utils
Class ShellUtils
- java.lang.Object
-
- org.apache.storm.utils.ShellUtils
-
- Direct Known Subclasses:
ShellUtils.ShellCommandExecutor
public abstract class ShellUtils extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classShellUtils.ExitCodeExceptionThis is an IOException with exit code added.static classShellUtils.OSTypeOSType detection.static classShellUtils.ShellCommandExecutorA simple shell command executor.
-
Field Summary
Fields Modifier and Type Field Description static booleanFREEBSDstatic booleanLINUXstatic org.slf4j.LoggerLOGstatic booleanMACstatic com.codahale.metrics.MeternumShellExceptionsstatic ShellUtils.OSTypeosTypestatic booleanOTHERstatic booleanSOLARISprotected longtimeOutIntervalTime after which the executing script would be timed out.static StringTOKEN_SEPARATOR_REGEXToken separator regex used to parse Shell tool outputs.static booleanWINDOWS
-
Constructor Summary
Constructors Constructor Description ShellUtils()ShellUtils(long interval)ShellUtils(long interval, boolean redirectErrorStream)Creates a new shell utils instance.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract String[]getExecString()return an array containing the command name & its parameters.intgetExitCode()get the exit code.static String[]getGroupsForUserCommand(String user)a Unix command to get a given user's groups list.static ShellLogHandlergetLogHandler(Map<String,Object> topoConf)ProcessgetProcess()get the current sub-process executing the given command.booleanisTimedOut()To check if the passed script to shell command executor timed out or not.protected abstract voidparseExecResult(BufferedReader lines)Parse the execution result.protected voidrun()check to see if a command needs to be executed and execute if needed.protected voidsetEnvironment(Map<String,String> env)set the environment for the command.protected voidsetWorkingDirectory(File dir)set the working directory.
-
-
-
Field Detail
-
LOG
public static final org.slf4j.Logger LOG
-
osType
public static final ShellUtils.OSType 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
public static final String TOKEN_SEPARATOR_REGEX
Token separator regex used to parse Shell tool outputs.
-
timeOutInterval
protected long timeOutInterval
Time after which the executing script would be timed out.
-
-
Method Detail
-
getGroupsForUserCommand
public static String[] getGroupsForUserCommand(String user)
a Unix command to get a given user's groups list. Windows is not supported.
-
getLogHandler
public static ShellLogHandler getLogHandler(Map<String,Object> topoConf)
-
getExitCode
public int getExitCode()
get the exit code.- Returns:
- the exit code of the process
-
setEnvironment
protected void setEnvironment(Map<String,String> env)
set the environment for the command.- Parameters:
env- Mapping of environment variables
-
setWorkingDirectory
protected void setWorkingDirectory(File dir)
set the working directory.- Parameters:
dir- The directory where the command would be executed
-
run
protected void run() throws IOExceptioncheck to see if a command needs to be executed and execute if needed.- Throws:
IOException
-
getExecString
protected abstract String[] getExecString()
return an array containing the command name & its parameters.
-
parseExecResult
protected abstract void parseExecResult(BufferedReader lines) throws IOException
Parse the execution result.- Throws:
IOException
-
getProcess
public Process 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.
-
-