Class LinuxContainerExecutor
- All Implemented Interfaces:
org.apache.hadoop.conf.Configurable
This class provides Container execution using a native
container-executor binary. By using a helper written it native code,
this class is able to do several things that the
DefaultContainerExecutor cannot, such as execution of applications
as the applications' owners, provide localization that takes advantage of
mapping the application owner to a UID on the execution host, resource
management through Linux CGROUPS, and Docker support.
If hadoop.security.authentication is set to simple,
then the
yarn.nodemanager.linux-container-executor.nonsecure-mode.limit-users
property will determine whether the LinuxContainerExecutor runs
processes as the application owner or as the default user, as set in the
yarn.nodemanager.linux-container-executor.nonsecure-mode.local-user
property.
The LinuxContainerExecutor will manage applications through an
appropriate LinuxContainerRuntime instance. This class uses a
DelegatingLinuxContainerRuntime instance, which will delegate calls
to either a DefaultLinuxContainerRuntime instance or a
OCIContainerRuntime instance, depending on the job's
configuration.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe container exit code.Nested classes/interfaces inherited from class org.apache.hadoop.yarn.server.nodemanager.ContainerExecutor
ContainerExecutor.DelayedProcessKiller, ContainerExecutor.Signal -
Field Summary
Fields inherited from class org.apache.hadoop.yarn.server.nodemanager.ContainerExecutor
DIRECTORY_CONTENTS, TASK_LAUNCH_SCRIPT_PERMISSION, TOKEN_FILE_NAME_FMT, WILDCARD -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor to allow for creation through reflection.LinuxContainerExecutor(LinuxContainerRuntime linuxContainerRuntime) Create a LinuxContainerExecutor with a providedLinuxContainerRuntime. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddSchedPriorityCommand(List<String> command) Add a niceness level to the process that will be executed.voidbuildMainArgs(List<String> command, String user, String appId, String locId, InetSocketAddress nmAddr, String tokenFileName, List<String> localDirs) Set up theContainerLocalizer.voidDelete specified directories as a given user.org.apache.hadoop.hdfs.protocol.datatransfer.IOStreamPairPerforms container exec.protected StringgetContainerExecutorExecutablePath(org.apache.hadoop.conf.Configuration conf) Get the path to thecontainer-executorbinary.getExposedPorts(Container container) String[]getIpAndHost(Container container) getLocalResources(Container container) protected PrivilegedOperationExecutorvoidRun the executor initialization steps.booleanCheck if a container is alive.intLaunch the container on the node.voidmountCgroups(List<String> cgroupKVs, String hierarchy) Mount a CGROUPS controller at the requested mount point and create a hierarchy for the NodeManager to manage.voidPrepare the container prior to the launch environment being written.intRecover an already existing container.protected File[]readDirAsUser(String user, org.apache.hadoop.fs.Path dir) Return the files in the target directory.booleanPerforms the tasks necessary to reap the container.intRelaunch the container on the node.voidremoveDockerContainer(String containerId) Remove the docker container referenced in the context.voidsetConf(org.apache.hadoop.conf.Configuration conf) booleanSignal container with the specified signal.voidstart()voidPrepare the environment for containers in this application to execute.voidstop()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, getLocalIpAndHost, getNMEnvVar, getPidFilePath, getProcessId, getRunCommand, getRunCommand, getRunCommandForOther, getRunCommandForWindows, isContainerActive, localizeClasspathJar, logOutput, pauseContainer, resumeContainer, writeLaunchEnv, writeLaunchEnv
-
Constructor Details
-
LinuxContainerExecutor
public LinuxContainerExecutor()Default constructor to allow for creation through reflection. -
LinuxContainerExecutor
Create a LinuxContainerExecutor with a providedLinuxContainerRuntime. Used primarily for testing.- Parameters:
linuxContainerRuntime- the runtime to use
-
-
Method Details
-
setConf
public void setConf(org.apache.hadoop.conf.Configuration conf) - Specified by:
setConfin interfaceorg.apache.hadoop.conf.Configurable- Overrides:
setConfin classContainerExecutor
-
getContainerExecutorExecutablePath
Get the path to thecontainer-executorbinary. The path will be absolute.- Parameters:
conf- theConfiguration- Returns:
- the path to the
container-executorbinary
-
addSchedPriorityCommand
Add a niceness level to the process that will be executed. Adds-n <nice>to the given command. The niceness level will be taken from theYarnConfiguration.NM_CONTAINER_EXECUTOR_SCHED_PRIORITYproperty.- Parameters:
command- the command to which to add the niceness setting.
-
getPrivilegedOperationExecutor
-
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:
context- Context of NM- Throws:
IOException- if initialization fails
-
start
public void start()- Overrides:
startin classContainerExecutor
-
stop
public void stop()- Overrides:
stopin classContainerExecutor
-
startLocalizer
public void startLocalizer(LocalizerStartContext ctx) throws IOException, InterruptedException, org.apache.hadoop.yarn.exceptions.ConfigurationException 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 NMorg.apache.hadoop.yarn.exceptions.ConfigurationException- if config error was found
-
buildMainArgs
@VisibleForTesting public void buildMainArgs(List<String> command, String user, String appId, String locId, InetSocketAddress nmAddr, String tokenFileName, List<String> localDirs) Set up theContainerLocalizer.- Parameters:
command- the current ShellCommandExecutor command lineuser- localization userappId- localized app idlocId- localizer idnmAddr- nodemanager addresslocalDirs- list of local dirs- See Also:
-
prepareContainer
Description copied from class:ContainerExecutorPrepare the container prior to the launch environment being written.- Overrides:
prepareContainerin classContainerExecutor- Parameters:
ctx- Encapsulates information necessary for launching containers.- Throws:
IOException- if errors occur during container preparation
-
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
-
getIpAndHost
- Overrides:
getIpAndHostin classContainerExecutor- Throws:
ContainerExecutionException
-
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
-
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
Performs the tasks necessary to reap the container.- Specified by:
reapContainerin classContainerExecutor- Parameters:
ctx- Encapsulates information necessary for reaping containers.- Returns:
- true if the reaping was successful.
- Throws:
IOException- if an error occurs while reaping the container.
-
execContainer
public org.apache.hadoop.hdfs.protocol.datatransfer.IOStreamPair execContainer(ContainerExecContext ctx) throws ContainerExecutionException Performs container exec.- Specified by:
execContainerin classContainerExecutor- Parameters:
ctx- Encapsulates information necessary for exec container.- Returns:
- stdin and stdout of container exec.
- Throws:
ContainerExecutionException- if container exec fails.
-
deleteAsUser
Description copied from class:ContainerExecutorDelete specified directories as a given user.- Specified by:
deleteAsUserin classContainerExecutor- Parameters:
ctx- Encapsulates information necessary for deletion.
-
readDirAsUser
Description copied from class:ContainerExecutorReturn the files in the target directory. If retrieving the list of files requires specific access rights, that access will happen as the specified user. The list will not include entries for "." or "..".- Overrides:
readDirAsUserin classContainerExecutor- Parameters:
user- the user as whom to access the target directorydir- the target directory- Returns:
- a list of files in the target directory
-
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
-
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
-
mountCgroups
Mount a CGROUPS controller at the requested mount point and create a hierarchy for the NodeManager to manage.- Parameters:
cgroupKVs- a key-value pair of the formcontroller=mount-pathhierarchy- the top directory of the hierarchy for the NodeManager- Throws:
IOException- if there is a problem mounting the CGROUPS
-
getResourceHandler
-
removeDockerContainer
Remove the docker container referenced in the context.- Parameters:
containerId- the containerId for the container.
-
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
-
getExposedPorts
- Overrides:
getExposedPortsin classContainerExecutor- Throws:
ContainerExecutionException
-
getLocalResources
public Map<String,org.apache.hadoop.yarn.api.records.LocalResource> getLocalResources(Container container) throws IOException - Overrides:
getLocalResourcesin classContainerExecutor- Throws:
IOException
-