Class DefaultContainerExecutor
java.lang.Object
org.apache.hadoop.yarn.server.nodemanager.ContainerExecutor
org.apache.hadoop.yarn.server.nodemanager.DefaultContainerExecutor
- All Implemented Interfaces:
org.apache.hadoop.conf.Configurable
- Direct Known Subclasses:
WindowsSecureContainerExecutor
The
DefaultContainerExecuter class offers generic container
execution services. Process execution is handled in a platform-independent
way via ProcessBuilder.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classThis class is a utility to create a wrapper script that is platform appropriate.Nested classes/interfaces inherited from class org.apache.hadoop.yarn.server.nodemanager.ContainerExecutor
ContainerExecutor.DelayedProcessKiller, ContainerExecutor.ExitCode, ContainerExecutor.Signal -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.apache.hadoop.fs.FileContextAFileContextfor the local file system.Fields inherited from class org.apache.hadoop.yarn.server.nodemanager.ContainerExecutor
DIRECTORY_CONTENTS, TASK_LAUNCH_SCRIPT_PERMISSION, TOKEN_FILE_NAME_FMT, WILDCARD -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected org.apache.hadoop.util.Shell.CommandExecutorbuildCommandExecutor(String wrapperScriptPath, String containerIdStr, String user, org.apache.hadoop.fs.Path pidFile, org.apache.hadoop.yarn.api.records.Resource resource, File workDir, Map<String, String> environment, String[] numaCommands) Create a newShell.ShellCommandExecutorusing the parameters.voidClear the internal variable for repeatable testing.static booleancontainerIsAlive(String pid) Returns true if the process with the specified pid is alive.protected voidCopy a file using thelfsFileContext.protected ContainerLocalizercreateContainerLocalizer(String user, String appId, String locId, String tokenFileName, List<String> localDirs, org.apache.hadoop.fs.FileContext localizerFc) Create a newContainerLocalizerinstance.protected voidcreateDir(org.apache.hadoop.fs.Path dirPath, org.apache.hadoop.fs.permission.FsPermission perms, boolean createParent, String user) Use thelfsFileContextto create the target directory.voidDelete specified directories as a given user.org.apache.hadoop.hdfs.protocol.datatransfer.IOStreamPairPerform interactive docker command into running container.getLocalWrapperScriptBuilder(String containerIdStr, org.apache.hadoop.fs.Path containerWorkDir) Create aDefaultContainerExecutor.LocalWrapperScriptBuilderfor the given container ID and path that is appropriate to the current platform.Return the default container log directory permissions.protected org.apache.hadoop.fs.PathgetWorkingDir(List<String> localDirs, String user, String appId) Return a randomly chosen application directory from a list of local storage directories.voidRun the executor initialization steps.booleanCheck if a container is alive.protected voidkillContainer(String pid, ContainerExecutor.Signal signal) Send a specified signal to the specified pidintLaunch the container on the node.voidpostComplete(org.apache.hadoop.yarn.api.records.ContainerId containerId) clean up and release of resources.intRecover an already existing container.booleanNo-op for reaping containers within the DefaultContainerExecutor.intRelaunch the container on the node.voidsetNumactl(String numactl) voidsetNumaResourceAllocator(NumaResourceAllocator numaResourceAllocator) protected voidsetScriptExecutable(org.apache.hadoop.fs.Path script, String owner) Make a file executable using thelfsFileContext.booleanSignal container with the specified signal.voidPrepare the environment for containers in this application to execute.voidCreate a symlink file which points to the target.voidupdateYarnSysFS(Context ctx, String user, String appId, String spec) Update cluster information inside container.Methods inherited from class org.apache.hadoop.yarn.server.nodemanager.ContainerExecutor
activateContainer, cleanupBeforeRelaunch, deactivateContainer, getConf, getExposedPorts, getIpAndHost, getLocalIpAndHost, getLocalResources, getNMEnvVar, getPidFilePath, getProcessId, getRunCommand, getRunCommand, getRunCommandForOther, getRunCommandForWindows, isContainerActive, localizeClasspathJar, logOutput, pauseContainer, prepareContainer, readDirAsUser, resumeContainer, setConf, start, stop, writeLaunchEnv, writeLaunchEnv
-
Field Details
-
lfs
protected final org.apache.hadoop.fs.FileContext lfsAFileContextfor the local file system.
-
-
Constructor Details
-
DefaultContainerExecutor
@VisibleForTesting public DefaultContainerExecutor()Default constructor for use in testing.
-
-
Method Details
-
copyFile
protected void copyFile(org.apache.hadoop.fs.Path src, org.apache.hadoop.fs.Path dst, String owner) throws IOException Copy a file using thelfsFileContext.- Parameters:
src- the file to copydst- where to copy the fileowner- the owner of the new copy. Used only in secure Windows clusters- Throws:
IOException- when the copy fails- See Also:
-
setScriptExecutable
protected void setScriptExecutable(org.apache.hadoop.fs.Path script, String owner) throws IOException Make a file executable using thelfsFileContext.- Parameters:
script- the path to make executableowner- the new owner for the file. Used only in secure Windows clusters- Throws:
IOException- when the change mode operation fails- See Also:
-
init
Description copied from class:ContainerExecutorRun the executor initialization steps. Verify that the necessary configs and permissions are in place.- Specified by:
initin classContainerExecutor- Parameters:
nmContext- Context of NM- Throws:
IOException- if initialization fails
-
startLocalizer
Description copied from class:ContainerExecutorPrepare the environment for containers in this application to execute.For $x in local.dirs create $x/$user/$appId Copy $nmLocal/appTokens -> $N/$user/$appId For $rsrc in private resources Copy $rsrc -> $N/$user/filecache/[idef] For $rsrc in job resources Copy $rsrc -> $N/$user/$appId/filecache/idef
- Specified by:
startLocalizerin classContainerExecutor- Parameters:
ctx- LocalizerStartContext that encapsulates necessary information for starting a localizer.- Throws:
IOException- for most application init failuresInterruptedException- if application init thread is halted by NM
-
createContainerLocalizer
@Private @VisibleForTesting protected ContainerLocalizer createContainerLocalizer(String user, String appId, String locId, String tokenFileName, List<String> localDirs, org.apache.hadoop.fs.FileContext localizerFc) throws IOException Create a newContainerLocalizerinstance.- Parameters:
user- the user who owns the job for which the localization is being runappId- the ID of the application for which the localization is being runlocId- the ID of the container for which the localization is being runlocalDirs- a list of directories to use as destinations for the localizationlocalizerFc- theFileContextto use when localizing files- Returns:
- the new
ContainerLocalizerinstance - Throws:
IOException- ifuserorlocIdisnullor if the container localizer has an initialization failure
-
launchContainer
public int launchContainer(ContainerStartContext ctx) throws IOException, org.apache.hadoop.yarn.exceptions.ConfigurationException Description copied from class:ContainerExecutorLaunch the container on the node. This is a blocking call and returns only when the container exits.- Specified by:
launchContainerin classContainerExecutor- Parameters:
ctx- Encapsulates information necessary for launching containers.- Returns:
- the return status of the launch
- Throws:
IOException- if the container launch failsorg.apache.hadoop.yarn.exceptions.ConfigurationException- if config error was found
-
relaunchContainer
public int relaunchContainer(ContainerStartContext ctx) throws IOException, org.apache.hadoop.yarn.exceptions.ConfigurationException Description copied from class:ContainerExecutorRelaunch the container on the node. This is a blocking call and returns only when the container exits.- Specified by:
relaunchContainerin classContainerExecutor- Parameters:
ctx- Encapsulates information necessary for relaunching containers.- Returns:
- the return status of the relaunch
- Throws:
IOException- if the container relaunch failsorg.apache.hadoop.yarn.exceptions.ConfigurationException- if config error was found
-
buildCommandExecutor
protected org.apache.hadoop.util.Shell.CommandExecutor buildCommandExecutor(String wrapperScriptPath, String containerIdStr, String user, org.apache.hadoop.fs.Path pidFile, org.apache.hadoop.yarn.api.records.Resource resource, File workDir, Map<String, String> environment, String[] numaCommands) Create a newShell.ShellCommandExecutorusing the parameters.- Parameters:
wrapperScriptPath- the path to the script to executecontainerIdStr- the container IDuser- the application owner's usernamepidFile- the path to the container's PID fileresource- this parameter controls memory and CPU limits.workDir- If not-null, specifies the directory which should be set as the current working directory for the command. If null, the current working directory is not modified.environment- the container environmentnumaCommands- list of prefix numa commands- Returns:
- the new
Shell.ShellCommandExecutor - See Also:
-
Shell.ShellCommandExecutor
-
getLocalWrapperScriptBuilder
protected DefaultContainerExecutor.LocalWrapperScriptBuilder getLocalWrapperScriptBuilder(String containerIdStr, org.apache.hadoop.fs.Path containerWorkDir) Create aDefaultContainerExecutor.LocalWrapperScriptBuilderfor the given container ID and path that is appropriate to the current platform.- Parameters:
containerIdStr- the container IDcontainerWorkDir- the container's working directory- Returns:
- a new
DefaultContainerExecutor.LocalWrapperScriptBuilder
-
signalContainer
Description copied from class:ContainerExecutorSignal container with the specified signal.- Specified by:
signalContainerin classContainerExecutor- Parameters:
ctx- Encapsulates information necessary for signaling containers.- Returns:
- returns true if the operation succeeded
- Throws:
IOException- if signaling the container fails
-
reapContainer
No-op for reaping containers within the DefaultContainerExecutor.- Specified by:
reapContainerin classContainerExecutor- Parameters:
ctx- Encapsulates information necessary for reaping containers.- Returns:
- true given no operations are needed.
-
isContainerAlive
Description copied from class:ContainerExecutorCheck if a container is alive.- Specified by:
isContainerAlivein classContainerExecutor- Parameters:
ctx- Encapsulates information necessary for container liveness check.- Returns:
- true if container is still alive
- Throws:
IOException- if there is a failure while checking the container status
-
containerIsAlive
Returns true if the process with the specified pid is alive.- Parameters:
pid- String pid- Returns:
- boolean true if the process is alive
- Throws:
IOException- if the command to test process liveliness fails
-
killContainer
Send a specified signal to the specified pid- Parameters:
pid- the pid of the process [group] to signal.signal- signal to send- Throws:
IOException- if the command to kill the process fails
-
deleteAsUser
Description copied from class:ContainerExecutorDelete specified directories as a given user.- Specified by:
deleteAsUserin classContainerExecutor- Parameters:
ctx- Encapsulates information necessary for deletion.- Throws:
IOException- if delete failsInterruptedException- if interrupted while waiting for the deletion operation to complete
-
symLink
Description copied from class:ContainerExecutorCreate a symlink file which points to the target.- Specified by:
symLinkin classContainerExecutor- Parameters:
target- The target for symlinksymlink- the symlink file- Throws:
IOException- Error when creating symlinks
-
getWorkingDir
protected org.apache.hadoop.fs.Path getWorkingDir(List<String> localDirs, String user, String appId) throws IOException Return a randomly chosen application directory from a list of local storage directories. The probability of selecting a directory is proportional to its size.- Parameters:
localDirs- the target directories from which to selectuser- the user who owns the applicationappId- the application ID- Returns:
- the selected directory
- Throws:
IOException- if no application directories for the user can be found
-
createDir
protected void createDir(org.apache.hadoop.fs.Path dirPath, org.apache.hadoop.fs.permission.FsPermission perms, boolean createParent, String user) throws IOException Use thelfsFileContextto create the target directory.- Parameters:
dirPath- the target directoryperms- the target permissions for the target directorycreateParent- whether the parent directories should also be createduser- the user as whom the target directory should be created. Used only on secure Windows hosts.- Throws:
IOException- if there's a failure performing a file operation- See Also:
-
getLogDirPermissions
Return the default container log directory permissions.- Returns:
- the default container log directory permissions
-
clearLogDirPermissions
@VisibleForTesting public void clearLogDirPermissions()Clear the internal variable for repeatable testing. -
execContainer
public org.apache.hadoop.hdfs.protocol.datatransfer.IOStreamPair execContainer(ContainerExecContext ctx) throws ContainerExecutionException Description copied from class:ContainerExecutorPerform interactive docker command into running container.- Specified by:
execContainerin classContainerExecutor- Parameters:
ctx- Encapsulates information necessary for exec containers.- Returns:
- the input/output stream of interactive docker shell.
- Throws:
ContainerExecutionException
-
updateYarnSysFS
Description copied from class:ContainerExecutorUpdate cluster information inside container.- Specified by:
updateYarnSysFSin classContainerExecutor- Parameters:
ctx- ContainerRuntimeContextuser- Owner of applicationappId- YARN application IDspec- Service Specification- Throws:
IOException- if there is a failure while writing spec to disk
-
reacquireContainer
public int reacquireContainer(ContainerReacquisitionContext ctx) throws IOException, InterruptedException Description copied from class:ContainerExecutorRecover an already existing container. This is a blocking call and returns only when the container exits. Note that the container must have been activated prior to this call.- Overrides:
reacquireContainerin classContainerExecutor- Parameters:
ctx- encapsulates information necessary to reacquire container- Returns:
- The exit code of the pre-existing container
- Throws:
IOException- if there is a failure while reacquiring the containerInterruptedException- if interrupted while waiting to reacquire the container
-
postComplete
public void postComplete(org.apache.hadoop.yarn.api.records.ContainerId containerId) clean up and release of resources.- Parameters:
containerId- containerId of running container
-
setNumaResourceAllocator
@VisibleForTesting public void setNumaResourceAllocator(NumaResourceAllocator numaResourceAllocator) -
setNumactl
-