Class NMClientAsync
java.lang.Object
org.apache.hadoop.service.AbstractService
org.apache.hadoop.yarn.client.api.async.NMClientAsync
- All Implemented Interfaces:
Closeable,AutoCloseable,Service
NMClientAsync handles communication with all the NodeManagers
and provides asynchronous updates on getting responses from them. It
maintains a thread pool to communicate with individual NMs where a number of
worker threads process requests to NMs by using NMClientImpl. The max
size of the thread pool is configurable through
YarnConfiguration.NM_CLIENT_ASYNC_THREAD_POOL_MAX_SIZE.
It should be used in conjunction with a CallbackHandler. For example
class MyCallbackHandler extends NMClientAsync.AbstractCallbackHandler {
public void onContainerStarted(ContainerId containerId,
Map<String, ByteBuffer> allServiceResponse) {
[post process after the container is started, process the response]
}
public void onContainerResourceIncreased(ContainerId containerId,
Resource resource) {
[post process after the container resource is increased]
}
public void onContainerStatusReceived(ContainerId containerId,
ContainerStatus containerStatus) {
[make use of the status of the container]
}
public void onContainerStopped(ContainerId containerId) {
[post process after the container is stopped]
}
public void onStartContainerError(
ContainerId containerId, Throwable t) {
[handle the raised exception]
}
public void onGetContainerStatusError(
ContainerId containerId, Throwable t) {
[handle the raised exception]
}
public void onStopContainerError(
ContainerId containerId, Throwable t) {
[handle the raised exception]
}
}
The client's life-cycle should be managed like the following:
NMClientAsync asyncClient =
NMClientAsync.createNMClientAsync(new MyCallbackhandler());
asyncClient.init(conf);
asyncClient.start();
asyncClient.startContainer(container, containerLaunchContext);
[... wait for container being started]
asyncClient.getContainerStatus(container.getId(), container.getNodeId(),
container.getContainerToken());
[... handle the status in the callback instance]
asyncClient.stopContainer(container.getId(), container.getNodeId(),
container.getContainerToken());
[... wait for container being stopped]
asyncClient.stop();
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classorg.apache.hadoop.yarn.client.api.async.NMClientAsync.AbstractCallbackHandlerThe callback abstract class.static interfaceorg.apache.hadoop.yarn.client.api.async.NMClientAsync.CallbackHandlerDeprecated.Nested classes/interfaces inherited from interface org.apache.hadoop.service.Service
Service.STATE -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.apache.hadoop.yarn.client.api.async.NMClientAsync.CallbackHandlerprotected NMClient -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedNMClientAsync(String name, org.apache.hadoop.yarn.client.api.async.NMClientAsync.AbstractCallbackHandler callbackHandler) protectedNMClientAsync(String name, org.apache.hadoop.yarn.client.api.async.NMClientAsync.CallbackHandler callbackHandler) Deprecated.UseNMClientAsync(String, AbstractCallbackHandler)instead.protectedNMClientAsync(String name, NMClient client, org.apache.hadoop.yarn.client.api.async.NMClientAsync.AbstractCallbackHandler callbackHandler) protectedNMClientAsync(String name, NMClient client, org.apache.hadoop.yarn.client.api.async.NMClientAsync.CallbackHandler callbackHandler) Deprecated.protectedNMClientAsync(org.apache.hadoop.yarn.client.api.async.NMClientAsync.AbstractCallbackHandler callbackHandler) protectedNMClientAsync(org.apache.hadoop.yarn.client.api.async.NMClientAsync.CallbackHandler callbackHandler) Deprecated.UseNMClientAsync(AbstractCallbackHandler)instead. -
Method Summary
Modifier and TypeMethodDescriptionabstract voidcommitLastReInitializationAsync(ContainerId containerId) Commit last reInitialization of the specified container.static NMClientAsynccreateNMClientAsync(org.apache.hadoop.yarn.client.api.async.NMClientAsync.AbstractCallbackHandler callbackHandler) static NMClientAsynccreateNMClientAsync(org.apache.hadoop.yarn.client.api.async.NMClientAsync.CallbackHandler callbackHandler) Deprecated.UsecreateNMClientAsync(AbstractCallbackHandler)instead.org.apache.hadoop.yarn.client.api.async.NMClientAsync.CallbackHandlerabstract voidgetContainerStatusAsync(ContainerId containerId, NodeId nodeId) abstract voidincreaseContainerResourceAsync(Container container) Deprecated.abstract voidreInitializeContainerAsync(ContainerId containerId, ContainerLaunchContext containerLaunchContex, boolean autoCommit) Re-Initialize the Container.abstract voidrestartContainerAsync(ContainerId containerId) Restart the specified container.abstract voidrollbackLastReInitializationAsync(ContainerId containerId) Rollback last reInitialization of the specified container.voidsetCallbackHandler(org.apache.hadoop.yarn.client.api.async.NMClientAsync.CallbackHandler callbackHandler) voidabstract voidstartContainerAsync(Container container, ContainerLaunchContext containerLaunchContext) abstract voidstopContainerAsync(ContainerId containerId, NodeId nodeId) abstract voidupdateContainerResourceAsync(Container container) Update the resources of a container.Methods inherited from class org.apache.hadoop.service.AbstractService
close, getBlockers, getConfig, getFailureCause, getFailureState, getLifecycleHistory, getName, getServiceState, getStartTime, init, isInState, noteFailure, putBlocker, registerGlobalListener, registerServiceListener, removeBlocker, serviceInit, serviceStart, serviceStop, setConfig, start, stop, toString, unregisterGlobalListener, unregisterServiceListener, waitForServiceToStop
-
Field Details
-
client
-
callbackHandler
protected org.apache.hadoop.yarn.client.api.async.NMClientAsync.CallbackHandler callbackHandler
-
-
Constructor Details
-
NMClientAsync
protected NMClientAsync(org.apache.hadoop.yarn.client.api.async.NMClientAsync.AbstractCallbackHandler callbackHandler) -
NMClientAsync
protected NMClientAsync(String name, org.apache.hadoop.yarn.client.api.async.NMClientAsync.AbstractCallbackHandler callbackHandler) -
NMClientAsync
-
NMClientAsync
@Deprecated protected NMClientAsync(org.apache.hadoop.yarn.client.api.async.NMClientAsync.CallbackHandler callbackHandler) Deprecated.UseNMClientAsync(AbstractCallbackHandler)instead. -
NMClientAsync
@Deprecated protected NMClientAsync(String name, org.apache.hadoop.yarn.client.api.async.NMClientAsync.CallbackHandler callbackHandler) Deprecated.UseNMClientAsync(String, AbstractCallbackHandler)instead. -
NMClientAsync
@Private @VisibleForTesting @Deprecated protected NMClientAsync(String name, NMClient client, org.apache.hadoop.yarn.client.api.async.NMClientAsync.CallbackHandler callbackHandler) Deprecated.
-
-
Method Details
-
createNMClientAsync
public static NMClientAsync createNMClientAsync(org.apache.hadoop.yarn.client.api.async.NMClientAsync.AbstractCallbackHandler callbackHandler) -
createNMClientAsync
@Deprecated public static NMClientAsync createNMClientAsync(org.apache.hadoop.yarn.client.api.async.NMClientAsync.CallbackHandler callbackHandler) Deprecated.UsecreateNMClientAsync(AbstractCallbackHandler)instead. -
startContainerAsync
public abstract void startContainerAsync(Container container, ContainerLaunchContext containerLaunchContext) -
increaseContainerResourceAsync
Deprecated. -
updateContainerResourceAsync
Update 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.- Parameters:
container- the container with updated token.
-
reInitializeContainerAsync
public abstract void reInitializeContainerAsync(ContainerId containerId, ContainerLaunchContext containerLaunchContex, boolean autoCommit) Re-Initialize the Container.
- Parameters:
containerId- the Id of the container to Re-Initialize.containerLaunchContex- the updated ContainerLaunchContext.autoCommit- commit re-initialization automatically ?
-
restartContainerAsync
Restart the specified container.
- Parameters:
containerId- the Id of the container to restart.
-
rollbackLastReInitializationAsync
Rollback last reInitialization of the specified container.
- Parameters:
containerId- the Id of the container to restart.
-
commitLastReInitializationAsync
Commit last reInitialization of the specified container.
- Parameters:
containerId- the Id of the container to commit reInitialize.
-
stopContainerAsync
-
getContainerStatusAsync
-
getClient
-
setClient
-
getCallbackHandler
public org.apache.hadoop.yarn.client.api.async.NMClientAsync.CallbackHandler getCallbackHandler() -
setCallbackHandler
public void setCallbackHandler(org.apache.hadoop.yarn.client.api.async.NMClientAsync.CallbackHandler callbackHandler)
-
NMClientAsync.AbstractCallbackHandlerinstead.