Class NMClientImpl
- All Implemented Interfaces:
Closeable,AutoCloseable,org.apache.hadoop.service.Service
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).
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.apache.hadoop.yarn.client.api.NMClient
NMClient.UpgradeOpNested classes/interfaces inherited from interface org.apache.hadoop.service.Service
org.apache.hadoop.service.Service.STATE -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ConcurrentMap<org.apache.hadoop.yarn.api.records.ContainerId,NMClientImpl.StartedContainer> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidvoidcleanupRunningContainersOnStop(boolean enabled) Set whether the containers that are started by this client, and are still running should be stopped when the client stops.voidcommitLastReInitialization(org.apache.hadoop.yarn.api.records.ContainerId containerId) Commit last reInitialization of the specified container.org.apache.hadoop.yarn.api.records.ContainerStatusgetContainerStatus(org.apache.hadoop.yarn.api.records.ContainerId containerId, org.apache.hadoop.yarn.api.records.NodeId nodeId) Query the status of a container.List<org.apache.hadoop.yarn.api.records.LocalizationStatus>getLocalizationStatuses(org.apache.hadoop.yarn.api.records.ContainerId containerId, org.apache.hadoop.yarn.api.records.NodeId nodeId) Get the localization statuses of a container.org.apache.hadoop.yarn.api.records.NodeIdgetNodeIdOfStartedContainer(org.apache.hadoop.yarn.api.records.ContainerId containerId) Get the NodeId of the node on which container is running.voidincreaseContainerResource(org.apache.hadoop.yarn.api.records.Container container) Deprecated.voidlocalize(org.apache.hadoop.yarn.api.records.ContainerId containerId, org.apache.hadoop.yarn.api.records.NodeId nodeId, Map<String, org.apache.hadoop.yarn.api.records.LocalResource> localResources) Localize resources for a container.voidreInitializeContainer(org.apache.hadoop.yarn.api.records.ContainerId containerId, org.apache.hadoop.yarn.api.records.ContainerLaunchContext containerLaunchContex, boolean autoCommit) Re-Initialize the Container.voidrestartContainer(org.apache.hadoop.yarn.api.records.ContainerId containerId) Restart the specified container.voidrollbackLastReInitialization(org.apache.hadoop.yarn.api.records.ContainerId containerId) Rollback last reInitialization of the specified container.protected voidserviceInit(org.apache.hadoop.conf.Configuration conf) protected voidstartContainer(org.apache.hadoop.yarn.api.records.Container container, org.apache.hadoop.yarn.api.records.ContainerLaunchContext containerLaunchContext) Start an allocated container.voidstopContainer(org.apache.hadoop.yarn.api.records.ContainerId containerId, org.apache.hadoop.yarn.api.records.NodeId nodeId) Stop an started container.voidupdateContainerResource(org.apache.hadoop.yarn.api.records.Container container) Update the resources of a container.Methods inherited from class org.apache.hadoop.yarn.client.api.NMClient
createNMClient, createNMClient, getNMTokenCache, setNMTokenCacheMethods inherited from class org.apache.hadoop.service.AbstractService
close, getBlockers, getConfig, getFailureCause, getFailureState, getLifecycleHistory, getName, getServiceState, getStartTime, init, isInState, noteFailure, putBlocker, registerGlobalListener, registerServiceListener, removeBlocker, serviceStart, setConfig, start, stop, toString, unregisterGlobalListener, unregisterServiceListener, waitForServiceToStop
-
Field Details
-
startedContainers
protected ConcurrentMap<org.apache.hadoop.yarn.api.records.ContainerId,NMClientImpl.StartedContainer> startedContainers
-
-
Constructor Details
-
NMClientImpl
public NMClientImpl() -
NMClientImpl
-
-
Method Details
-
serviceStop
- Overrides:
serviceStopin classorg.apache.hadoop.service.AbstractService- Throws:
Exception
-
cleanupRunningContainers
protected void cleanupRunningContainers() -
serviceInit
- Overrides:
serviceInitin classorg.apache.hadoop.service.AbstractService- Throws:
Exception
-
cleanupRunningContainersOnStop
public void cleanupRunningContainersOnStop(boolean enabled) Description copied from class: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().- Specified by:
cleanupRunningContainersOnStopin classNMClient- Parameters:
enabled- whether the feature is enabled or not
-
startContainer
public Map<String,ByteBuffer> startContainer(org.apache.hadoop.yarn.api.records.Container container, org.apache.hadoop.yarn.api.records.ContainerLaunchContext containerLaunchContext) throws org.apache.hadoop.yarn.exceptions.YarnException, IOException Description copied from class:NMClientStart an allocated container.
The
ApplicationMasteror 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 viaContainer. In addition, the AM needs to provide theContainerLaunchContextas well.- Specified by:
startContainerin classNMClient- Parameters:
container- the allocated containercontainerLaunchContext- the context information needed by theNodeManagerto launch the container- Returns:
- a map between the auxiliary service names and their outputs
- Throws:
org.apache.hadoop.yarn.exceptions.YarnException- YarnException.IOException- IOException.
-
increaseContainerResource
@Deprecated public void increaseContainerResource(org.apache.hadoop.yarn.api.records.Container container) throws org.apache.hadoop.yarn.exceptions.YarnException, IOException Deprecated.Description copied from class:NMClientIncrease the resource of a container.
The
ApplicationMasteror other applications that use the client must provide the details of the container, including the Id and the target resource encapsulated in the updated container token viaContainer.- Specified by:
increaseContainerResourcein classNMClient- Parameters:
container- the container with updated token.- Throws:
org.apache.hadoop.yarn.exceptions.YarnException- YarnException.IOException- IOException.
-
updateContainerResource
public void updateContainerResource(org.apache.hadoop.yarn.api.records.Container container) throws org.apache.hadoop.yarn.exceptions.YarnException, IOException Description copied from class:NMClientUpdate the resources of a container.
The
ApplicationMasteror other applications that use the client must provide the details of the container, including the Id and the target resource encapsulated in the updated container token viaContainer.- Specified by:
updateContainerResourcein classNMClient- Parameters:
container- the container with updated token.- Throws:
org.apache.hadoop.yarn.exceptions.YarnException- YarnException.IOException- IOException.
-
stopContainer
public void stopContainer(org.apache.hadoop.yarn.api.records.ContainerId containerId, org.apache.hadoop.yarn.api.records.NodeId nodeId) throws org.apache.hadoop.yarn.exceptions.YarnException, IOException Description copied from class:NMClientStop an started container.
- Specified by:
stopContainerin classNMClient- Parameters:
containerId- the Id of the started containernodeId- the Id of theNodeManager- Throws:
org.apache.hadoop.yarn.exceptions.YarnException- YarnException.IOException- IOException.
-
getContainerStatus
public org.apache.hadoop.yarn.api.records.ContainerStatus getContainerStatus(org.apache.hadoop.yarn.api.records.ContainerId containerId, org.apache.hadoop.yarn.api.records.NodeId nodeId) throws org.apache.hadoop.yarn.exceptions.YarnException, IOException Description copied from class:NMClientQuery the status of a container.
- Specified by:
getContainerStatusin classNMClient- Parameters:
containerId- the Id of the started containernodeId- the Id of theNodeManager- Returns:
- the status of a container.
- Throws:
org.apache.hadoop.yarn.exceptions.YarnException- YarnException.IOException- IOException.
-
reInitializeContainer
public void reInitializeContainer(org.apache.hadoop.yarn.api.records.ContainerId containerId, org.apache.hadoop.yarn.api.records.ContainerLaunchContext containerLaunchContex, boolean autoCommit) throws org.apache.hadoop.yarn.exceptions.YarnException, IOException Description copied from class:NMClientRe-Initialize the Container.
- Specified by:
reInitializeContainerin classNMClient- Parameters:
containerId- the Id of the container to Re-Initialize.containerLaunchContex- the updated ContainerLaunchContext.autoCommit- commit re-initialization automatically ?- Throws:
org.apache.hadoop.yarn.exceptions.YarnException- YarnException.IOException- IOException.
-
restartContainer
public void restartContainer(org.apache.hadoop.yarn.api.records.ContainerId containerId) throws org.apache.hadoop.yarn.exceptions.YarnException, IOException Description copied from class:NMClientRestart the specified container.
- Specified by:
restartContainerin classNMClient- Parameters:
containerId- the Id of the container to restart.- Throws:
org.apache.hadoop.yarn.exceptions.YarnException- YarnException.IOException- IOException.
-
rollbackLastReInitialization
public void rollbackLastReInitialization(org.apache.hadoop.yarn.api.records.ContainerId containerId) throws org.apache.hadoop.yarn.exceptions.YarnException, IOException Description copied from class:NMClientRollback last reInitialization of the specified container.
- Specified by:
rollbackLastReInitializationin classNMClient- Parameters:
containerId- the Id of the container to restart.- Throws:
org.apache.hadoop.yarn.exceptions.YarnException- YarnException.IOException- IOException.
-
commitLastReInitialization
public void commitLastReInitialization(org.apache.hadoop.yarn.api.records.ContainerId containerId) throws org.apache.hadoop.yarn.exceptions.YarnException, IOException Description copied from class:NMClientCommit last reInitialization of the specified container.
- Specified by:
commitLastReInitializationin classNMClient- Parameters:
containerId- the Id of the container to commit reInitialize.- Throws:
org.apache.hadoop.yarn.exceptions.YarnException- YarnException.IOException- IOException.
-
getCleanupRunningContainers
-
getNodeIdOfStartedContainer
public org.apache.hadoop.yarn.api.records.NodeId getNodeIdOfStartedContainer(org.apache.hadoop.yarn.api.records.ContainerId containerId) Description copied from class:NMClientGet the NodeId of the node on which container is running. It returns null if the container if container is not found or if it is not running.- Overrides:
getNodeIdOfStartedContainerin classNMClient- Parameters:
containerId- Container Id of the container.- Returns:
- NodeId of the container on which it is running.
-
localize
public void localize(org.apache.hadoop.yarn.api.records.ContainerId containerId, org.apache.hadoop.yarn.api.records.NodeId nodeId, Map<String, org.apache.hadoop.yarn.api.records.LocalResource> localResources) throws org.apache.hadoop.yarn.exceptions.YarnException, IOExceptionDescription copied from class:NMClientLocalize resources for a container.- Overrides:
localizein classNMClient- Parameters:
containerId- the ID of the containernodeId- node Id of the containerlocalResources- resources to localize- Throws:
org.apache.hadoop.yarn.exceptions.YarnExceptionIOException
-
getLocalizationStatuses
public List<org.apache.hadoop.yarn.api.records.LocalizationStatus> getLocalizationStatuses(org.apache.hadoop.yarn.api.records.ContainerId containerId, org.apache.hadoop.yarn.api.records.NodeId nodeId) throws org.apache.hadoop.yarn.exceptions.YarnException, IOException Description copied from class:NMClientGet the localization statuses of a container.- Overrides:
getLocalizationStatusesin classNMClient- Parameters:
containerId- the Id of the containernodeId- node Id of the container- Returns:
- the status of a container.
- Throws:
org.apache.hadoop.yarn.exceptions.YarnException- YarnException.IOException- IOException.
-