Package org.apache.storm.utils
Class ShellUtils
java.lang.Object
org.apache.storm.utils.ShellUtils
- Direct Known Subclasses:
- ShellUtils.ShellCommandExecutor
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classThis is an IOException with exit code added.static enumOSType detection.static classA simple shell command executor.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final booleanstatic final booleanstatic final org.slf4j.Loggerstatic final booleanstatic final com.codahale.metrics.Meterstatic final ShellUtils.OSTypestatic final booleanstatic final booleanprotected longTime after which the executing script would be timed out.static final StringToken separator regex used to parse Shell tool outputs.static final boolean
- 
Constructor SummaryConstructorsConstructorDescriptionShellUtils(long interval) ShellUtils(long interval, boolean redirectErrorStream) Creates a new shell utils instance.
- 
Method SummaryModifier and TypeMethodDescriptionprotected abstract String[]return an array containing the command name & its parameters.intget the exit code.static String[]a Unix command to get a given user's groups list.static ShellLogHandlergetLogHandler(Map<String, Object> topoConf) get the current sub-process executing the given command.booleanTo 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 Details- 
LOGpublic static final org.slf4j.Logger LOG
- 
osType
- 
WINDOWSpublic static final boolean WINDOWS
- 
SOLARISpublic static final boolean SOLARIS
- 
MACpublic static final boolean MAC
- 
FREEBSDpublic static final boolean FREEBSD
- 
LINUXpublic static final boolean LINUX
- 
OTHERpublic static final boolean OTHER
- 
numShellExceptionspublic static final com.codahale.metrics.Meter numShellExceptions
- 
TOKEN_SEPARATOR_REGEXToken separator regex used to parse Shell tool outputs.
- 
timeOutIntervalprotected long timeOutIntervalTime after which the executing script would be timed out.
 
- 
- 
Constructor Details- 
ShellUtilspublic ShellUtils()
- 
ShellUtilspublic ShellUtils(long interval) 
- 
ShellUtilspublic 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- 
getGroupsForUserCommanda Unix command to get a given user's groups list. Windows is not supported.
- 
getLogHandler
- 
getExitCodepublic int getExitCode()get the exit code.- Returns:
- the exit code of the process
 
- 
setEnvironmentset the environment for the command.- Parameters:
- env- Mapping of environment variables
 
- 
setWorkingDirectoryset the working directory.- Parameters:
- dir- The directory where the command would be executed
 
- 
runcheck to see if a command needs to be executed and execute if needed.- Throws:
- IOException
 
- 
getExecStringreturn an array containing the command name & its parameters.
- 
parseExecResultParse the execution result.- Throws:
- IOException
 
- 
getProcessget the current sub-process executing the given command.- Returns:
- process executing the command
 
- 
isTimedOutpublic boolean isTimedOut()To check if the passed script to shell command executor timed out or not.- Returns:
- if the script timed out.
 
 
-