@InterfaceAudience.Private @InterfaceStability.Unstable public class NMClientImpl extends NMClient
This class implements NMClient. All the APIs are blocking.
By default, this client stops all the running containers that are started by
it when it stops. It can be disabled via
cleanupRunningContainersOnStop(boolean), in which case containers will
continue to run even after this client is stopped and till the application
runs at which point ResourceManager will forcefully kill them.
Note that the blocking APIs ensure the RPC calls to NodeManager
are executed immediately, and the responses are received before these APIs
return. However, when startContainer(org.apache.hadoop.yarn.api.records.Container, org.apache.hadoop.yarn.api.records.ContainerLaunchContext) or stopContainer(org.apache.hadoop.yarn.api.records.ContainerId, org.apache.hadoop.yarn.api.records.NodeId)
returns, NodeManager may still need some time to either start
or stop the container because of its asynchronous implementation. Therefore,
getContainerStatus(org.apache.hadoop.yarn.api.records.ContainerId, org.apache.hadoop.yarn.api.records.NodeId) is likely to return a transit container status
if it is executed immediately after startContainer(org.apache.hadoop.yarn.api.records.Container, org.apache.hadoop.yarn.api.records.ContainerLaunchContext) or
stopContainer(org.apache.hadoop.yarn.api.records.ContainerId, org.apache.hadoop.yarn.api.records.NodeId).
| Modifier and Type | Class and Description |
|---|---|
protected static class |
NMClientImpl.StartedContainer |
Service.STATE| Modifier and Type | Field and Description |
|---|---|
protected ConcurrentMap<ContainerId,NMClientImpl.StartedContainer> |
startedContainers |
| Constructor and Description |
|---|
NMClientImpl() |
NMClientImpl(String name) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
cleanupRunningContainers() |
void |
cleanupRunningContainersOnStop(boolean enabled)
Set whether the containers that are started by this client, and are
still running should be stopped when the client stops.
|
protected NMClientImpl.StartedContainer |
createStartedContainer(Container container) |
AtomicBoolean |
getCleanupRunningContainers() |
ContainerStatus |
getContainerStatus(ContainerId containerId,
NodeId nodeId)
Query the status of a container.
|
protected NMClientImpl.StartedContainer |
getStartedContainer(ContainerId containerId) |
protected void |
removeStartedContainer(NMClientImpl.StartedContainer container) |
protected void |
serviceInit(Configuration conf)
All initialization code needed by a service.
|
protected void |
serviceStop()
Actions called during the transition to the STOPPED state.
|
Map<String,ByteBuffer> |
startContainer(Container container,
ContainerLaunchContext containerLaunchContext)
Start an allocated container.
|
void |
stopContainer(ContainerId containerId,
NodeId nodeId)
Stop an started container.
|
createNMClient, createNMClientclose, getBlockers, getConfig, getFailureCause, getFailureState, getLifecycleHistory, getName, getServiceState, getStartTime, init, isInState, noteFailure, putBlocker, registerGlobalListener, registerServiceListener, removeBlocker, serviceStart, setConfig, start, stop, toString, unregisterGlobalListener, unregisterServiceListener, waitForServiceToStopprotected ConcurrentMap<ContainerId,NMClientImpl.StartedContainer> startedContainers
public NMClientImpl()
public NMClientImpl(String name)
protected void serviceStop()
throws Exception
AbstractServiceAbstractService.stop() prevents re-entrancy.
Implementations MUST write this to be robust against failures, including
checks for null references -and for the first failure to not stop other
attempts to shut down parts of the service.serviceStop in class AbstractServiceException - if needed -these will be caught and logged.protected void cleanupRunningContainers()
protected void serviceInit(Configuration conf) throws Exception
AbstractServiceAbstractService.init(Configuration) prevents re-entrancy.
The base implementation checks to see if the subclass has created
a new configuration instance, and if so, updates the base class valueserviceInit in class AbstractServiceconf - configurationException - on a failure -these will be caught,
possibly wrapped, and wil; trigger a service stoppublic void cleanupRunningContainersOnStop(boolean enabled)
NMClientSet whether the containers that are started by this client, and are still running should be stopped when the client stops. By default, the feature should be enabled.
However, containers will be stopped only when service is stopped. i.e. afterAbstractService.stop().cleanupRunningContainersOnStop in class NMClientenabled - whether the feature is enabled or notpublic Map<String,ByteBuffer> startContainer(Container container, ContainerLaunchContext containerLaunchContext) throws YarnException, IOException
NMClientStart an allocated container.
The ApplicationMaster or other applications that use the
client must provide the details of the allocated container, including the
Id, the assigned node's Id and the token via Container. In
addition, the AM needs to provide the ContainerLaunchContext as
well.
startContainer in class NMClientcontainer - the allocated containercontainerLaunchContext - the context information needed by the
NodeManager to launch the
containerYarnExceptionIOExceptionpublic void stopContainer(ContainerId containerId, NodeId nodeId) throws YarnException, IOException
NMClientStop an started container.
stopContainer in class NMClientcontainerId - the Id of the started containernodeId - the Id of the NodeManagerYarnExceptionIOExceptionpublic ContainerStatus getContainerStatus(ContainerId containerId, NodeId nodeId) throws YarnException, IOException
NMClientQuery the status of a container.
getContainerStatus in class NMClientcontainerId - the Id of the started containernodeId - the Id of the NodeManagerYarnExceptionIOExceptionprotected NMClientImpl.StartedContainer createStartedContainer(Container container) throws YarnException, IOException
YarnExceptionIOExceptionprotected void removeStartedContainer(NMClientImpl.StartedContainer container)
protected NMClientImpl.StartedContainer getStartedContainer(ContainerId containerId)
public AtomicBoolean getCleanupRunningContainers()
Copyright © 2013 Apache Software Foundation. All rights reserved.