@InterfaceAudience.Public
@InterfaceStability.Stable
public abstract class AMRMClientAsync<T extends AMRMClient.ContainerRequest>
extends org.apache.hadoop.service.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();
Modifier and Type | Class and Description |
---|---|
static class |
AMRMClientAsync.AbstractCallbackHandler
The callback abstract class.
|
static interface |
AMRMClientAsync.CallbackHandler
Deprecated.
Use
AMRMClientAsync.AbstractCallbackHandler instead. |
Modifier and Type | Field and Description |
---|---|
protected AMRMClient<T> |
client |
protected AMRMClientAsync.CallbackHandler |
handler |
protected AtomicInteger |
heartbeatIntervalMs |
Modifier | Constructor and Description |
---|---|
protected |
AMRMClientAsync(AMRMClient<T> client,
int intervalMs,
AMRMClientAsync.AbstractCallbackHandler callbackHandler) |
protected |
AMRMClientAsync(AMRMClient<T> client,
int intervalMs,
AMRMClientAsync.CallbackHandler callbackHandler)
Deprecated.
|
protected |
AMRMClientAsync(int intervalMs,
AMRMClientAsync.AbstractCallbackHandler callbackHandler) |
protected |
AMRMClientAsync(int intervalMs,
AMRMClientAsync.CallbackHandler callbackHandler)
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
abstract void |
addContainerRequest(T req)
Request containers for resources before calling
allocate |
void |
addSchedulingRequests(Collection<org.apache.hadoop.yarn.api.records.SchedulingRequest> schedulingRequests)
Add a Collection of SchedulingRequests.
|
static <T extends AMRMClient.ContainerRequest> |
createAMRMClientAsync(AMRMClient<T> client,
int intervalMs,
AMRMClientAsync.AbstractCallbackHandler callbackHandler)
Create a new instance of AMRMClientAsync.
|
static <T extends AMRMClient.ContainerRequest> |
createAMRMClientAsync(AMRMClient<T> client,
int intervalMs,
AMRMClientAsync.CallbackHandler callbackHandler)
Deprecated.
|
static <T extends AMRMClient.ContainerRequest> |
createAMRMClientAsync(int intervalMs,
AMRMClientAsync.AbstractCallbackHandler callbackHandler)
Create a new instance of AMRMClientAsync.
|
static <T extends AMRMClient.ContainerRequest> |
createAMRMClientAsync(int intervalMs,
AMRMClientAsync.CallbackHandler callbackHandler)
Deprecated.
|
abstract org.apache.hadoop.yarn.api.records.Resource |
getAvailableResources()
Get the currently available resources in the cluster.
|
abstract int |
getClusterNodeCount()
Get the current number of nodes in the cluster.
|
Collection<T> |
getMatchingRequests(long allocationRequestId)
Returns all matching ContainerRequests that match the given
AllocationRequestId.
|
List<? extends Collection<T>> |
getMatchingRequests(org.apache.hadoop.yarn.api.records.Priority priority,
String resourceName,
org.apache.hadoop.yarn.api.records.ExecutionType executionType,
org.apache.hadoop.yarn.api.records.Resource capability)
Returns all matching ContainerRequests that match the given Priority,
ResourceName, ExecutionType and Capability.
|
abstract List<? extends Collection<T>> |
getMatchingRequests(org.apache.hadoop.yarn.api.records.Priority priority,
String resourceName,
org.apache.hadoop.yarn.api.records.Resource capability) |
org.apache.hadoop.yarn.client.api.TimelineV2Client |
getRegisteredTimelineV2Client()
Get registered timeline client.
|
abstract org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse |
registerApplicationMaster(String appHostName,
int appHostPort,
String appTrackingUrl)
Registers this application master with the resource manager.
|
org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse |
registerApplicationMaster(String appHostName,
int appHostPort,
String appTrackingUrl,
Map<Set<String>,org.apache.hadoop.yarn.api.resource.PlacementConstraint> placementConstraints)
Register the application master.
|
void |
registerTimelineV2Client(org.apache.hadoop.yarn.client.api.TimelineV2Client timelineClient)
Register TimelineClient to AMRMClient.
|
abstract void |
releaseAssignedContainer(org.apache.hadoop.yarn.api.records.ContainerId containerId)
Release containers assigned by the Resource Manager.
|
abstract void |
removeContainerRequest(T req)
Remove previous container request.
|
void |
requestContainerResourceChange(org.apache.hadoop.yarn.api.records.Container container,
org.apache.hadoop.yarn.api.records.Resource capability)
Deprecated.
|
abstract void |
requestContainerUpdate(org.apache.hadoop.yarn.api.records.Container container,
org.apache.hadoop.yarn.api.records.UpdateContainerRequest updateContainerRequest)
Request a container update before calling
allocate . |
void |
setHeartbeatInterval(int interval) |
abstract void |
unregisterApplicationMaster(org.apache.hadoop.yarn.api.records.FinalApplicationStatus appStatus,
String appMessage,
String appTrackingUrl)
Unregister the application master.
|
abstract void |
updateBlacklist(List<String> blacklistAdditions,
List<String> blacklistRemovals)
Update application's blacklist with addition or removal resources.
|
void |
waitFor(Supplier<Boolean> check)
Wait for
check to return true for each 1000 ms. |
void |
waitFor(Supplier<Boolean> check,
int checkEveryMillis)
Wait for
check to return true for each
checkEveryMillis ms. |
void |
waitFor(Supplier<Boolean> check,
int checkEveryMillis,
int logInterval)
Wait for
check to return true for each
checkEveryMillis ms. |
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
protected final AMRMClient<T extends AMRMClient.ContainerRequest> client
protected final AMRMClientAsync.CallbackHandler handler
protected final AtomicInteger heartbeatIntervalMs
protected AMRMClientAsync(int intervalMs, AMRMClientAsync.AbstractCallbackHandler callbackHandler)
@InterfaceAudience.Private protected AMRMClientAsync(AMRMClient<T> client, int intervalMs, AMRMClientAsync.AbstractCallbackHandler callbackHandler)
@Deprecated protected AMRMClientAsync(int intervalMs, AMRMClientAsync.CallbackHandler callbackHandler)
@InterfaceAudience.Private @Deprecated protected AMRMClientAsync(AMRMClient<T> client, int intervalMs, AMRMClientAsync.CallbackHandler callbackHandler)
public static <T extends AMRMClient.ContainerRequest> AMRMClientAsync<T> createAMRMClientAsync(int intervalMs, AMRMClientAsync.AbstractCallbackHandler callbackHandler)
Create a new instance of AMRMClientAsync.
intervalMs
- heartbeat interval in milliseconds between AM and RMcallbackHandler
- callback handler that processes responses from
the ResourceManager
public static <T extends AMRMClient.ContainerRequest> AMRMClientAsync<T> createAMRMClientAsync(AMRMClient<T> client, int intervalMs, AMRMClientAsync.AbstractCallbackHandler callbackHandler)
Create a new instance of AMRMClientAsync.
client
- the AMRMClient instanceintervalMs
- heartbeat interval in milliseconds between AM and RMcallbackHandler
- callback handler that processes responses from
the ResourceManager
@Deprecated public static <T extends AMRMClient.ContainerRequest> AMRMClientAsync<T> createAMRMClientAsync(int intervalMs, AMRMClientAsync.CallbackHandler callbackHandler)
createAMRMClientAsync(int,
AMRMClientAsync.AbstractCallbackHandler)
instead.@Deprecated public static <T extends AMRMClient.ContainerRequest> AMRMClientAsync<T> createAMRMClientAsync(AMRMClient<T> client, int intervalMs, AMRMClientAsync.CallbackHandler callbackHandler)
createAMRMClientAsync(AMRMClient,
int, AMRMClientAsync.AbstractCallbackHandler)
instead.public void setHeartbeatInterval(int interval)
public abstract List<? extends Collection<T>> getMatchingRequests(org.apache.hadoop.yarn.api.records.Priority priority, String resourceName, org.apache.hadoop.yarn.api.records.Resource capability)
@InterfaceAudience.Public @InterfaceStability.Unstable public void addSchedulingRequests(Collection<org.apache.hadoop.yarn.api.records.SchedulingRequest> schedulingRequests)
schedulingRequests
- Collection of Scheduling Requests.public List<? extends Collection<T>> getMatchingRequests(org.apache.hadoop.yarn.api.records.Priority priority, String resourceName, org.apache.hadoop.yarn.api.records.ExecutionType executionType, org.apache.hadoop.yarn.api.records.Resource capability)
priority
- Priority.resourceName
- Location.executionType
- ExecutionType.capability
- Capability.public Collection<T> getMatchingRequests(long allocationRequestId)
allocationRequestId
- AllocationRequestId.public abstract org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse registerApplicationMaster(String appHostName, int appHostPort, String appTrackingUrl) throws org.apache.hadoop.yarn.exceptions.YarnException, IOException
org.apache.hadoop.yarn.exceptions.YarnException
IOException
@InterfaceAudience.Public @InterfaceStability.Unstable public org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse registerApplicationMaster(String appHostName, int appHostPort, String appTrackingUrl, Map<Set<String>,org.apache.hadoop.yarn.api.resource.PlacementConstraint> placementConstraints) throws org.apache.hadoop.yarn.exceptions.YarnException, IOException
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.RegisterApplicationMasterResponse
org.apache.hadoop.yarn.exceptions.YarnException
IOException
public abstract void unregisterApplicationMaster(org.apache.hadoop.yarn.api.records.FinalApplicationStatus appStatus, String appMessage, String appTrackingUrl) throws org.apache.hadoop.yarn.exceptions.YarnException, IOException
appStatus
- Success/Failure status of the masterappMessage
- Diagnostics message on failureappTrackingUrl
- New URL to get master infoorg.apache.hadoop.yarn.exceptions.YarnException
IOException
public abstract void addContainerRequest(T req)
allocate
req
- Resource requestpublic abstract void removeContainerRequest(T req)
req
- Resource request@Deprecated public void requestContainerResourceChange(org.apache.hadoop.yarn.api.records.Container container, org.apache.hadoop.yarn.api.records.Resource capability)
requestContainerUpdate(Container, UpdateContainerRequest)
allocate
.
Any previous pending resource change request of the same container will be
removed.
Application that calls this method is expected to maintain the
Container
s 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.container
- The container returned from the last successful resource
allocation or resource changecapability
- The target resource capability of the containerpublic abstract void requestContainerUpdate(org.apache.hadoop.yarn.api.records.Container container, org.apache.hadoop.yarn.api.records.UpdateContainerRequest updateContainerRequest)
allocate
.
Any previous pending update request of the same container will be
removed.container
- The container returned from the last successful resource
allocation or updateupdateContainerRequest
- The UpdateContainerRequest
.public abstract void releaseAssignedContainer(org.apache.hadoop.yarn.api.records.ContainerId containerId)
containerId
- public abstract org.apache.hadoop.yarn.api.records.Resource getAvailableResources()
public abstract int getClusterNodeCount()
public void registerTimelineV2Client(org.apache.hadoop.yarn.client.api.TimelineV2Client timelineClient) throws org.apache.hadoop.yarn.exceptions.YarnException
timelineClient
- org.apache.hadoop.yarn.exceptions.YarnException
- when this method is invoked even when ATS V2 is not
configured.public org.apache.hadoop.yarn.client.api.TimelineV2Client getRegisteredTimelineV2Client()
public abstract void updateBlacklist(List<String> blacklistAdditions, List<String> blacklistRemovals)
blacklistAdditions
- list of resources which should be added to the
application blacklistblacklistRemovals
- list of resources which should be removed from the
application blacklistpublic void waitFor(Supplier<Boolean> check) throws InterruptedException
check
to return true for each 1000 ms.
See also waitFor(java.util.function.Supplier, int)
and waitFor(java.util.function.Supplier, int, int)
check
- the condition for which it should waitInterruptedException
public void waitFor(Supplier<Boolean> check, int checkEveryMillis) throws InterruptedException
check
to return true for each
checkEveryMillis
ms.
See also waitFor(java.util.function.Supplier, int, int)
check
- user defined checkercheckEveryMillis
- interval to call check
InterruptedException
public void waitFor(Supplier<Boolean> check, int checkEveryMillis, int logInterval) throws InterruptedException
check
to return true for each
checkEveryMillis
ms. In the main loop, this method will log
the message "waiting in main loop" for each logInterval
times
iteration to confirm the thread is alive.check
- user defined checkercheckEveryMillis
- interval to call check
logInterval
- interval to log for eachInterruptedException
Copyright © 2008–2018 Apache Software Foundation. All rights reserved.