Class AMRMClientAsync<T extends org.apache.hadoop.yarn.client.api.AMRMClient.ContainerRequest>
java.lang.Object
org.apache.hadoop.service.AbstractService
org.apache.hadoop.yarn.client.api.async.AMRMClientAsync<T>
- All Implemented Interfaces:
Closeable,AutoCloseable,Service
@Public
@Stable
public abstract class AMRMClientAsync<T extends org.apache.hadoop.yarn.client.api.AMRMClient.ContainerRequest>
extends AbstractService
AMRMClientAsync handles communication with the ResourceManager
and provides asynchronous updates on events such as container allocations and
completions. It contains a thread that sends periodic heartbeats to the
ResourceManager.
It should be used by implementing a CallbackHandler:
class MyCallbackHandler extends AMRMClientAsync.AbstractCallbackHandler {
public void onContainersAllocated(List<Container> containers) {
[run tasks on the containers]
}
public void onContainersUpdated(List<Container> containers) {
[determine if resource allocation of containers have been increased in
the ResourceManager, and if so, inform the NodeManagers to increase the
resource monitor/enforcement on the containers]
}
public void onContainersCompleted(List<ContainerStatus> statuses) {
[update progress, check whether app is done]
}
public void onNodesUpdated(List<NodeReport> updated) {}
public void onReboot() {}
}
The client's lifecycle should be managed similarly to the following:
AMRMClientAsync asyncClient =
createAMRMClientAsync(appAttId, 1000, new MyCallbackhandler());
asyncClient.init(conf);
asyncClient.start();
RegisterApplicationMasterResponse response = asyncClient
.registerApplicationMaster(appMasterHostname, appMasterRpcPort,
appMasterTrackingUrl);
asyncClient.addContainerRequest(containerRequest);
[... wait for application to complete]
asyncClient.unregisterApplicationMaster(status, appMsg, trackingUrl);
asyncClient.stop();
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classorg.apache.hadoop.yarn.client.api.async.AMRMClientAsync.AbstractCallbackHandlerThe callback abstract class.static interfaceorg.apache.hadoop.yarn.client.api.async.AMRMClientAsync.CallbackHandlerDeprecated.Nested classes/interfaces inherited from interface org.apache.hadoop.service.Service
Service.STATE -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final AMRMClient<T>protected final org.apache.hadoop.yarn.client.api.async.AMRMClientAsync.CallbackHandlerprotected final AtomicInteger -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAMRMClientAsync(int intervalMs, org.apache.hadoop.yarn.client.api.async.AMRMClientAsync.AbstractCallbackHandler callbackHandler) protectedAMRMClientAsync(int intervalMs, org.apache.hadoop.yarn.client.api.async.AMRMClientAsync.CallbackHandler callbackHandler) Deprecated.protectedAMRMClientAsync(AMRMClient<T> client, int intervalMs, org.apache.hadoop.yarn.client.api.async.AMRMClientAsync.AbstractCallbackHandler callbackHandler) protectedAMRMClientAsync(AMRMClient<T> client, int intervalMs, org.apache.hadoop.yarn.client.api.async.AMRMClientAsync.CallbackHandler callbackHandler) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionabstract voidaddContainerRequest(T req) Request containers for resources before callingallocatevoidaddSchedulingRequests(Collection<SchedulingRequest> schedulingRequests) Add a Collection of SchedulingRequests.static <T extends org.apache.hadoop.yarn.client.api.AMRMClient.ContainerRequest>
AMRMClientAsync<T>createAMRMClientAsync(int intervalMs, org.apache.hadoop.yarn.client.api.async.AMRMClientAsync.AbstractCallbackHandler callbackHandler) Create a new instance of AMRMClientAsync.static <T extends org.apache.hadoop.yarn.client.api.AMRMClient.ContainerRequest>
AMRMClientAsync<T>createAMRMClientAsync(int intervalMs, org.apache.hadoop.yarn.client.api.async.AMRMClientAsync.CallbackHandler callbackHandler) Deprecated.static <T extends org.apache.hadoop.yarn.client.api.AMRMClient.ContainerRequest>
AMRMClientAsync<T>createAMRMClientAsync(AMRMClient<T> client, int intervalMs, org.apache.hadoop.yarn.client.api.async.AMRMClientAsync.AbstractCallbackHandler callbackHandler) Create a new instance of AMRMClientAsync.static <T extends org.apache.hadoop.yarn.client.api.AMRMClient.ContainerRequest>
AMRMClientAsync<T>createAMRMClientAsync(AMRMClient<T> client, int intervalMs, org.apache.hadoop.yarn.client.api.async.AMRMClientAsync.CallbackHandler callbackHandler) Deprecated.abstract ResourceGet the currently available resources in the cluster.abstract intGet the current number of nodes in the cluster.getMatchingRequests(long allocationRequestId) Returns all matching ContainerRequests that match the given AllocationRequestId.List<? extends Collection<T>>getMatchingRequests(Priority priority, String resourceName, ExecutionType executionType, Resource capability) Returns all matching ContainerRequests that match the given Priority, ResourceName, ExecutionType and Capability.abstract List<? extends Collection<T>>getMatchingRequests(Priority priority, String resourceName, Resource capability) org.apache.hadoop.yarn.client.api.TimelineV2ClientGet registered timeline client.abstract RegisterApplicationMasterResponseregisterApplicationMaster(String appHostName, int appHostPort, String appTrackingUrl) Registers this application master with the resource manager.registerApplicationMaster(String appHostName, int appHostPort, String appTrackingUrl, Map<Set<String>, PlacementConstraint> placementConstraints) Register the application master.voidregisterTimelineV2Client(org.apache.hadoop.yarn.client.api.TimelineV2Client timelineClient) Register TimelineClient to AMRMClient.abstract voidreleaseAssignedContainer(ContainerId containerId) Release containers assigned by the Resource Manager.abstract voidremoveContainerRequest(T req) Remove previous container request.voidrequestContainerResourceChange(Container container, Resource capability) Deprecated.abstract voidrequestContainerUpdate(Container container, UpdateContainerRequest updateContainerRequest) Request a container update before callingallocate.voidsetHeartbeatInterval(int interval) abstract voidunregisterApplicationMaster(FinalApplicationStatus appStatus, String appMessage, String appTrackingUrl) Unregister the application master.abstract voidupdateBlacklist(List<String> blacklistAdditions, List<String> blacklistRemovals) Update application's blacklist with addition or removal resources.voidupdateTrackingUrl(String trackingUrl) Update application's tracking url on next heartbeat.voidWait forcheckto return true for each 1000 ms.voidWait forcheckto return true for eachcheckEveryMillisms.voidWait forcheckto return true for eachcheckEveryMillisms.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
protected final AMRMClient<T extends org.apache.hadoop.yarn.client.api.AMRMClient.ContainerRequest> client -
handler
protected final org.apache.hadoop.yarn.client.api.async.AMRMClientAsync.CallbackHandler handler -
heartbeatIntervalMs
-
-
Constructor Details
-
AMRMClientAsync
protected AMRMClientAsync(int intervalMs, org.apache.hadoop.yarn.client.api.async.AMRMClientAsync.AbstractCallbackHandler callbackHandler) -
AMRMClientAsync
@Private @VisibleForTesting protected AMRMClientAsync(AMRMClient<T> client, int intervalMs, org.apache.hadoop.yarn.client.api.async.AMRMClientAsync.AbstractCallbackHandler callbackHandler) -
AMRMClientAsync
@Deprecated protected AMRMClientAsync(int intervalMs, org.apache.hadoop.yarn.client.api.async.AMRMClientAsync.CallbackHandler callbackHandler) Deprecated. -
AMRMClientAsync
@Private @VisibleForTesting @Deprecated protected AMRMClientAsync(AMRMClient<T> client, int intervalMs, org.apache.hadoop.yarn.client.api.async.AMRMClientAsync.CallbackHandler callbackHandler) Deprecated.
-
-
Method Details
-
createAMRMClientAsync
public static <T extends org.apache.hadoop.yarn.client.api.AMRMClient.ContainerRequest> AMRMClientAsync<T> createAMRMClientAsync(int intervalMs, org.apache.hadoop.yarn.client.api.async.AMRMClientAsync.AbstractCallbackHandler callbackHandler) Create a new instance of AMRMClientAsync.
- Parameters:
intervalMs- heartbeat interval in milliseconds between AM and RMcallbackHandler- callback handler that processes responses from theResourceManager
-
createAMRMClientAsync
public static <T extends org.apache.hadoop.yarn.client.api.AMRMClient.ContainerRequest> AMRMClientAsync<T> createAMRMClientAsync(AMRMClient<T> client, int intervalMs, org.apache.hadoop.yarn.client.api.async.AMRMClientAsync.AbstractCallbackHandler callbackHandler) Create a new instance of AMRMClientAsync.
- Parameters:
client- the AMRMClient instanceintervalMs- heartbeat interval in milliseconds between AM and RMcallbackHandler- callback handler that processes responses from theResourceManager
-
createAMRMClientAsync
@Deprecated public static <T extends org.apache.hadoop.yarn.client.api.AMRMClient.ContainerRequest> AMRMClientAsync<T> createAMRMClientAsync(int intervalMs, org.apache.hadoop.yarn.client.api.async.AMRMClientAsync.CallbackHandler callbackHandler) Deprecated. -
createAMRMClientAsync
@Deprecated public static <T extends org.apache.hadoop.yarn.client.api.AMRMClient.ContainerRequest> AMRMClientAsync<T> createAMRMClientAsync(AMRMClient<T> client, int intervalMs, org.apache.hadoop.yarn.client.api.async.AMRMClientAsync.CallbackHandler callbackHandler) Deprecated. -
setHeartbeatInterval
public void setHeartbeatInterval(int interval) -
getMatchingRequests
-
addSchedulingRequests
@Public @Unstable public void addSchedulingRequests(Collection<SchedulingRequest> schedulingRequests) Add a Collection of SchedulingRequests. The AMRMClient will ensure that all requests in the same batch are sent in the same allocate call.- Parameters:
schedulingRequests- Collection of Scheduling Requests.
-
getMatchingRequests
public List<? extends Collection<T>> getMatchingRequests(Priority priority, String resourceName, ExecutionType executionType, Resource capability) Returns all matching ContainerRequests that match the given Priority, ResourceName, ExecutionType and Capability. NOTE: This matches only requests that were made by the client WITHOUT the allocationRequestId specified.- Parameters:
priority- Priority.resourceName- Location.executionType- ExecutionType.capability- Capability.- Returns:
- All matching ContainerRequests
-
getMatchingRequests
Returns all matching ContainerRequests that match the given AllocationRequestId. NOTE: This matches only requests that were made by the client WITH the allocationRequestId specified.- Parameters:
allocationRequestId- AllocationRequestId.- Returns:
- All matching ContainerRequests
-
registerApplicationMaster
public abstract RegisterApplicationMasterResponse registerApplicationMaster(String appHostName, int appHostPort, String appTrackingUrl) throws YarnException, IOException Registers this application master with the resource manager. On successful registration, starts the heartbeating thread.- Throws:
YarnExceptionIOException
-
registerApplicationMaster
@Public @Unstable public RegisterApplicationMasterResponse registerApplicationMaster(String appHostName, int appHostPort, String appTrackingUrl, Map<Set<String>, PlacementConstraint> placementConstraints) throws YarnException, IOExceptionRegister the application master. This must be called before any other interaction- Parameters:
appHostName- Name of the host on which master is runningappHostPort- Port master is listening onappTrackingUrl- URL at which the master info can be seenplacementConstraints- Placement Constraints mappings.- Returns:
RegisterApplicationMasterResponse- Throws:
YarnExceptionIOException
-
unregisterApplicationMaster
public abstract void unregisterApplicationMaster(FinalApplicationStatus appStatus, String appMessage, String appTrackingUrl) throws YarnException, IOException Unregister the application master. This must be called in the end.- Parameters:
appStatus- Success/Failure status of the masterappMessage- Diagnostics message on failureappTrackingUrl- New URL to get master info- Throws:
YarnExceptionIOException
-
addContainerRequest
Request containers for resources before callingallocate- Parameters:
req- Resource request
-
removeContainerRequest
Remove previous container request. The previous container request may have already been sent to the ResourceManager. So even after the remove request the app must be prepared to receive an allocation for the previous request even after the remove request- Parameters:
req- Resource request
-
requestContainerResourceChange
Deprecated.Request container resource change before callingallocate. Any previous pending resource change request of the same container will be removed. Application that calls this method is expected to maintain theContainers that are returned from previous successful allocations or resource changes. By passing in the existing container and a target resource capability to this method, the application requests the ResourceManager to change the existing resource allocation to the target resource allocation.- Parameters:
container- The container returned from the last successful resource allocation or resource changecapability- The target resource capability of the container
-
requestContainerUpdate
public abstract void requestContainerUpdate(Container container, UpdateContainerRequest updateContainerRequest) Request a container update before callingallocate. Any previous pending update request of the same container will be removed.- Parameters:
container- The container returned from the last successful resource allocation or updateupdateContainerRequest- TheUpdateContainerRequest.
-
releaseAssignedContainer
Release containers assigned by the Resource Manager. If the app cannot use the container or wants to give up the container then it can release them. The app needs to make new requests for the released resource capability if it still needs it. eg. it released non-local resources- Parameters:
containerId-
-
getAvailableResources
Get the currently available resources in the cluster. A valid value is available after a call to allocate has been made- Returns:
- Currently available resources
-
getClusterNodeCount
public abstract int getClusterNodeCount()Get the current number of nodes in the cluster. A valid values is available after a call to allocate has been made- Returns:
- Current number of nodes in the cluster
-
registerTimelineV2Client
public void registerTimelineV2Client(org.apache.hadoop.yarn.client.api.TimelineV2Client timelineClient) throws YarnException Register TimelineClient to AMRMClient.- Parameters:
timelineClient-- Throws:
YarnException- when this method is invoked even when ATS V2 is not configured.
-
getRegisteredTimelineV2Client
public org.apache.hadoop.yarn.client.api.TimelineV2Client getRegisteredTimelineV2Client()Get registered timeline client.- Returns:
- the registered timeline client
-
updateBlacklist
public abstract void updateBlacklist(List<String> blacklistAdditions, List<String> blacklistRemovals) Update application's blacklist with addition or removal resources.- Parameters:
blacklistAdditions- list of resources which should be added to the application blacklistblacklistRemovals- list of resources which should be removed from the application blacklist
-
updateTrackingUrl
Update application's tracking url on next heartbeat.- Parameters:
trackingUrl- new tracking url for this application
-
waitFor
Wait forcheckto return true for each 1000 ms. See alsowaitFor(java.util.function.Supplier, int)andwaitFor(java.util.function.Supplier, int, int)- Parameters:
check- the condition for which it should wait- Throws:
InterruptedException
-
waitFor
Wait forcheckto return true for eachcheckEveryMillisms. See alsowaitFor(java.util.function.Supplier, int, int)- Parameters:
check- user defined checkercheckEveryMillis- interval to callcheck- Throws:
InterruptedException
-
waitFor
public void waitFor(Supplier<Boolean> check, int checkEveryMillis, int logInterval) throws InterruptedException Wait forcheckto return true for eachcheckEveryMillisms. In the main loop, this method will log the message "waiting in main loop" for eachlogIntervaltimes iteration to confirm the thread is alive.- Parameters:
check- user defined checkercheckEveryMillis- interval to callchecklogInterval- interval to log for each- Throws:
InterruptedException
-
AMRMClientAsync.AbstractCallbackHandlerinstead.