Skip to content

Commit d93e6f0

Browse files
authored
YARN-11295. [Federation] Router Support DelegationToken in MemoryStore mode. (#5032)
1 parent c4aa41a commit d93e6f0

File tree

7 files changed

+563
-1
lines changed

7 files changed

+563
-1
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/AbstractClientRequestInterceptor.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.hadoop.conf.Configuration;
2424
import org.apache.hadoop.security.UserGroupInformation;
2525
import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
26+
import org.apache.hadoop.yarn.server.router.security.RouterDelegationTokenSecretManager;
2627
import org.slf4j.Logger;
2728
import org.slf4j.LoggerFactory;
2829

@@ -44,6 +45,8 @@ public abstract class AbstractClientRequestInterceptor
4445
@SuppressWarnings("checkstyle:visibilitymodifier")
4546
protected UserGroupInformation user = null;
4647

48+
private RouterDelegationTokenSecretManager tokenSecretManager = null;
49+
4750
/**
4851
* Sets the {@link ClientRequestInterceptor} in the chain.
4952
*/
@@ -125,4 +128,13 @@ private void setupUser(String userName) {
125128
}
126129
}
127130

131+
@Override
132+
public RouterDelegationTokenSecretManager getTokenSecretManager() {
133+
return tokenSecretManager;
134+
}
135+
136+
@Override
137+
public void setTokenSecretManager(RouterDelegationTokenSecretManager tokenSecretManager) {
138+
this.tokenSecretManager = tokenSecretManager;
139+
}
128140
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/ClientRequestInterceptor.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import org.apache.hadoop.conf.Configurable;
2222
import org.apache.hadoop.yarn.api.ApplicationClientProtocol;
23+
import org.apache.hadoop.yarn.server.router.security.RouterDelegationTokenSecretManager;
2324

2425
/**
2526
* Defines the contract to be implemented by the request interceptor classes,
@@ -62,4 +63,18 @@ public interface ClientRequestInterceptor
6263
*/
6364
ClientRequestInterceptor getNextInterceptor();
6465

66+
/**
67+
* Set RouterDelegationTokenSecretManager for specific interceptor to support Token operations,
68+
* including create Token, update Token, and delete Token.
69+
*
70+
* @param tokenSecretManager Router DelegationTokenSecretManager
71+
*/
72+
void setTokenSecretManager(RouterDelegationTokenSecretManager tokenSecretManager);
73+
74+
/**
75+
* Get RouterDelegationTokenSecretManager.
76+
*
77+
* @return Router DelegationTokenSecretManager.
78+
*/
79+
RouterDelegationTokenSecretManager getTokenSecretManager();
6580
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/RouterClientRMService.java

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.net.InetSocketAddress;
2323
import java.util.Collections;
2424
import java.util.Map;
25+
import java.util.concurrent.TimeUnit;
2526

2627
import org.apache.hadoop.classification.InterfaceAudience.Private;
2728
import org.apache.hadoop.conf.Configuration;
@@ -105,6 +106,7 @@
105106
import org.apache.hadoop.yarn.exceptions.YarnException;
106107
import org.apache.hadoop.yarn.ipc.YarnRPC;
107108
import org.apache.hadoop.yarn.server.router.RouterServerUtil;
109+
import org.apache.hadoop.yarn.server.router.security.RouterDelegationTokenSecretManager;
108110
import org.apache.hadoop.yarn.server.router.security.authorize.RouterPolicyProvider;
109111
import org.apache.hadoop.yarn.util.LRUCacheHashMap;
110112
import org.slf4j.Logger;
@@ -136,6 +138,8 @@ public class RouterClientRMService extends AbstractService
136138
// and remove the oldest used ones.
137139
private Map<String, RequestInterceptorChainWrapper> userPipelineMap;
138140

141+
private RouterDelegationTokenSecretManager routerDTSecretManager;
142+
139143
public RouterClientRMService() {
140144
super(RouterClientRMService.class.getName());
141145
}
@@ -164,8 +168,12 @@ protected void serviceStart() throws Exception {
164168
serverConf.getInt(YarnConfiguration.RM_CLIENT_THREAD_COUNT,
165169
YarnConfiguration.DEFAULT_RM_CLIENT_THREAD_COUNT);
166170

171+
// Initialize RouterRMDelegationTokenSecretManager.
172+
routerDTSecretManager = createRouterRMDelegationTokenSecretManager(conf);
173+
routerDTSecretManager.startThreads();
174+
167175
this.server = rpc.getServer(ApplicationClientProtocol.class, this,
168-
listenerEndpoint, serverConf, null, numWorkerThreads);
176+
listenerEndpoint, serverConf, routerDTSecretManager, numWorkerThreads);
169177

170178
// Enable service authorization?
171179
if (conf.getBoolean(
@@ -508,6 +516,13 @@ private RequestInterceptorChainWrapper initializePipeline(String user) {
508516
ClientRequestInterceptor interceptorChain =
509517
this.createRequestInterceptorChain();
510518
interceptorChain.init(user);
519+
520+
// We set the RouterDelegationTokenSecretManager instance to the interceptorChain
521+
// and let the interceptor use it.
522+
if (routerDTSecretManager != null) {
523+
interceptorChain.setTokenSecretManager(routerDTSecretManager);
524+
}
525+
511526
chainWrapper.init(interceptorChain);
512527
} catch (Exception e) {
513528
LOG.error("Init ClientRequestInterceptor error for user: {}.", user, e);
@@ -558,4 +573,42 @@ protected void finalize() {
558573
public Map<String, RequestInterceptorChainWrapper> getUserPipelineMap() {
559574
return userPipelineMap;
560575
}
576+
577+
/**
578+
* Create RouterRMDelegationTokenSecretManager.
579+
* In the YARN federation, the Router will replace the RM to
580+
* manage the RMDelegationToken (generate, update, cancel),
581+
* so the relevant configuration parameters still obtain the configuration parameters of the RM.
582+
*
583+
* @param conf Configuration
584+
* @return RouterDelegationTokenSecretManager.
585+
*/
586+
protected RouterDelegationTokenSecretManager createRouterRMDelegationTokenSecretManager(
587+
Configuration conf) {
588+
589+
long secretKeyInterval = conf.getLong(
590+
YarnConfiguration.RM_DELEGATION_KEY_UPDATE_INTERVAL_KEY,
591+
YarnConfiguration.RM_DELEGATION_KEY_UPDATE_INTERVAL_DEFAULT);
592+
593+
long tokenMaxLifetime = conf.getLong(
594+
YarnConfiguration.RM_DELEGATION_TOKEN_MAX_LIFETIME_KEY,
595+
YarnConfiguration.RM_DELEGATION_TOKEN_MAX_LIFETIME_DEFAULT);
596+
597+
long tokenRenewInterval = conf.getLong(
598+
YarnConfiguration.RM_DELEGATION_TOKEN_RENEW_INTERVAL_KEY,
599+
YarnConfiguration.RM_DELEGATION_TOKEN_RENEW_INTERVAL_DEFAULT);
600+
601+
long removeScanInterval = conf.getTimeDuration(
602+
YarnConfiguration.RM_DELEGATION_TOKEN_REMOVE_SCAN_INTERVAL_KEY,
603+
YarnConfiguration.RM_DELEGATION_TOKEN_REMOVE_SCAN_INTERVAL_DEFAULT,
604+
TimeUnit.MILLISECONDS);
605+
606+
return new RouterDelegationTokenSecretManager(secretKeyInterval,
607+
tokenMaxLifetime, tokenRenewInterval, removeScanInterval);
608+
}
609+
610+
@VisibleForTesting
611+
public RouterDelegationTokenSecretManager getRouterDTSecretManager() {
612+
return routerDTSecretManager;
613+
}
561614
}

0 commit comments

Comments
 (0)