|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.hadoop.util.Shell
public abstract class Shell
A base class for running a Unix command.
Shell
can be used to run unix commands like du
or
df
. It also offers facilities to gate commands by
time-intervals.
Nested Class Summary | |
---|---|
static class |
Shell.ExitCodeException
This is an IOException with exit code added. |
static class |
Shell.ShellCommandExecutor
A simple shell command executor. |
Field Summary | |
---|---|
static org.apache.commons.logging.Log |
LOG
|
static String |
SET_GROUP_COMMAND
|
static String |
SET_OWNER_COMMAND
a Unix command to set owner |
static String |
SET_PERMISSION_COMMAND
a Unix command to set permission |
protected long |
timeOutInterval
Time after which the executing script would be timedout |
static String |
ULIMIT_COMMAND
a Unix command to get ulimit of a process. |
static String |
USER_NAME_COMMAND
a Unix command to get the current user's name |
static boolean |
WINDOWS
Set to true on Windows platforms |
Constructor Summary | |
---|---|
Shell()
|
|
Shell(long interval)
|
Method Summary | |
---|---|
static String |
execCommand(Map<String,String> env,
String... cmd)
Static method to execute a shell command. |
static String |
execCommand(Map<String,String> env,
String[] cmd,
long timeout)
Static method to execute a shell command. |
static String |
execCommand(String... cmd)
Static method to execute a shell command. |
protected abstract String[] |
getExecString()
return an array containing the command name & its parameters |
int |
getExitCode()
get the exit code |
static String[] |
getGET_PERMISSION_COMMAND()
Return a Unix command to get permission information. |
static String[] |
getGroupsCommand()
a Unix command to get the current user's groups list |
static String[] |
getGroupsForUserCommand(String user)
a Unix command to get a given user's groups list |
Process |
getProcess()
get the current sub-process executing the given command |
static String[] |
getUlimitMemoryCommand(Configuration conf)
Deprecated. Use getUlimitMemoryCommand(int) |
static String[] |
getUlimitMemoryCommand(int memoryLimit)
Get the Unix command for setting the maximum virtual memory available to a given child process. |
static String[] |
getUsersForNetgroupCommand(String netgroup)
a Unix command to get a given netgroup's user list |
boolean |
isTimedOut()
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 |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final org.apache.commons.logging.Log LOG
public static final String USER_NAME_COMMAND
public static final String SET_PERMISSION_COMMAND
public static final String SET_OWNER_COMMAND
public static final String SET_GROUP_COMMAND
protected long timeOutInterval
public static final String ULIMIT_COMMAND
public static final boolean WINDOWS
Constructor Detail |
---|
public Shell()
public Shell(long interval)
interval
- the minimum duration to wait before re-executing the
command.Method Detail |
---|
public static String[] getGroupsCommand()
public static String[] getGroupsForUserCommand(String user)
public static String[] getUsersForNetgroupCommand(String netgroup)
public static String[] getGET_PERMISSION_COMMAND()
public static String[] getUlimitMemoryCommand(int memoryLimit)
null
.
memoryLimit
- virtual memory limit
String[]
with the ulimit command arguments or
null
if we are running on a non *nix platform or
if the limit is unspecified.@Deprecated public static String[] getUlimitMemoryCommand(Configuration conf)
getUlimitMemoryCommand(int)
Mapper
or the
Reducer
implementations
e.g. Hadoop Pipes
or Hadoop Streaming.
It also checks to ensure that we are running on a *nix platform else
(e.g. in Cygwin/Windows) it returns null
.
conf
- configuration
String[]
with the ulimit command arguments or
null
if we are running on a non *nix platform or
if the limit is unspecified.protected void setEnvironment(Map<String,String> env)
env
- Mapping of environment variablesprotected void setWorkingDirectory(File dir)
dir
- The directory where the command would be executedprotected void run() throws IOException
IOException
protected abstract String[] getExecString()
protected abstract void parseExecResult(BufferedReader lines) throws IOException
IOException
public Process getProcess()
public int getExitCode()
public boolean isTimedOut()
public static String execCommand(String... cmd) throws IOException
Shell
interface.
cmd
- shell command to execute.
IOException
public static String execCommand(Map<String,String> env, String[] cmd, long timeout) throws IOException
Shell
interface.
env
- the map of environment key=valuecmd
- shell command to execute.timeout
- time in milliseconds after which script should be marked timeout
IOException
public static String execCommand(Map<String,String> env, String... cmd) throws IOException
Shell
interface.
env
- the map of environment key=valuecmd
- shell command to execute.
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |