Class NMTokenCache
java.lang.Object
org.apache.hadoop.yarn.client.api.NMTokenCache
NMTokenCache manages NMTokens required for an Application Master
communicating with individual NodeManagers.
By default YARN client libraries AMRMClient and NMClient use
getSingleton() instance of the cache.
- Using the singleton instance of the cache is appropriate when running a single ApplicationMaster in the same JVM.
-
When using the singleton, users don't need to do anything special,
AMRMClientandNMClientare already set up to use the default singletonNMTokenCache
-
If using the
AMRMClientand theNMClient, setting up and using an instance cache is as follows:NMTokenCache nmTokenCache = new NMTokenCache(); AMRMClient rmClient = AMRMClient.createAMRMClient(); NMClient nmClient = NMClient.createNMClient(); nmClient.setNMTokenCache(nmTokenCache); ...
-
If using the
AMRMClientAsyncand theNMClientAsync, setting up and using an instance cache is as follows:NMTokenCache nmTokenCache = new NMTokenCache(); AMRMClient rmClient = AMRMClient.createAMRMClient(); NMClient nmClient = NMClient.createNMClient(); nmClient.setNMTokenCache(nmTokenCache); AMRMClientAsync rmClientAsync = new AMRMClientAsync(rmClient, 1000, [AMRM_CALLBACK]); NMClientAsync nmClientAsync = new NMClientAsync("nmClient", nmClient, [NM_CALLBACK]); ... -
If using
ApplicationMasterProtocolandContainerManagementProtocoldirectly, setting up and using an instance cache is as follows:NMTokenCache nmTokenCache = new NMTokenCache(); ... ApplicationMasterProtocol amPro = ClientRMProxy.createRMProxy(conf, ApplicationMasterProtocol.class); ... AllocateRequest allocateRequest = ... ... AllocateResponse allocateResponse = rmClient.allocate(allocateRequest); for (NMToken token : allocateResponse.getNMTokens()) { nmTokenCache.setToken(token.getNodeId().toString(), token.getToken()); } ... ContainerManagementProtocolProxy nmPro = ContainerManagementProtocolProxy(conf, nmTokenCache); ... nmPro.startContainer(container, containerContext); ...
AMRMClient or
NMClient, or the async versions of them) with a protocol proxy
(ContainerManagementProtocolProxy or
ApplicationMasterProtocol).-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidIt will remove all the nm tokens from its cachebooleancontainsToken(String nodeAddr) Returns true if NMToken is present in cache.static org.apache.hadoop.yarn.api.records.TokengetNMToken(String nodeAddr) Returns NMToken, null if absent.static NMTokenCacheReturns the singleton NM token cache.org.apache.hadoop.yarn.api.records.TokenReturns NMToken, null if absentintReturns the number of NMTokens present in cache.voidremoveToken(String nodeAddr) Removes NMToken for specified node managerstatic voidsetNMToken(String nodeAddr, org.apache.hadoop.yarn.api.records.Token token) Sets the NMToken for node address only in the singleton obtained fromgetSingleton().voidSets the NMToken for node address
-
Constructor Details
-
NMTokenCache
public NMTokenCache()Creates a NM token cache instance.
-
-
Method Details
-
getSingleton
Returns the singleton NM token cache.- Returns:
- the singleton NM token cache.
-
getNMToken
Returns NMToken, null if absent. Only the singleton obtained fromgetSingleton()is looked at for the tokens. If you are using your own NMTokenCache that is different from the singleton, usegetToken(String)- Parameters:
nodeAddr-- Returns:
TokenNMToken required for communicating with node manager
-
setNMToken
@Public public static void setNMToken(String nodeAddr, org.apache.hadoop.yarn.api.records.Token token) Sets the NMToken for node address only in the singleton obtained fromgetSingleton(). If you are using your own NMTokenCache that is different from the singleton, usesetToken(String, Token)- Parameters:
nodeAddr- node address (host:port)token- NMToken
-
getToken
Returns NMToken, null if absent- Parameters:
nodeAddr-- Returns:
TokenNMToken required for communicating with node manager
-
setToken
@Public @Evolving public void setToken(String nodeAddr, org.apache.hadoop.yarn.api.records.Token token) Sets the NMToken for node address- Parameters:
nodeAddr- node address (host:port)token- NMToken
-
containsToken
Returns true if NMToken is present in cache. -
numberOfTokensInCache
@Private @VisibleForTesting public int numberOfTokensInCache()Returns the number of NMTokens present in cache. -
removeToken
Removes NMToken for specified node manager- Parameters:
nodeAddr- node address (host:port)
-
clearCache
@Private @VisibleForTesting public void clearCache()It will remove all the nm tokens from its cache
-