goiri commented on code in PR #5104:
URL: https://github.com/apache/hadoop/pull/5104#discussion_r1023348352
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestFederationClientInterceptor.java:
##########
@@ -181,6 +195,15 @@ public void setUp() {
interceptor.setConf(this.getConf());
interceptor.init(user);
+ RouterDelegationTokenSecretManager tokenSecretManager =
+ interceptor.createRouterRMDelegationTokenSecretManager(this.getConf());
+ try {
+ tokenSecretManager.startThreads();
+ interceptor.setTokenSecretManager(tokenSecretManager);
+ } catch (Exception e) {
+ LOG.error(e.getMessage());
+ Assert.fail();
Review Comment:
Why not just let the exception surface?
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestFederationClientInterceptor.java:
##########
@@ -1550,4 +1574,138 @@ public void testGetNumMaxThreads() {
int minThreads2 = interceptor.getNumMaxThreads(this.getConf());
Assert.assertEquals(8, minThreads2);
}
+
+ @Test
+ public void testGetDelegationToken() throws IOException, YarnException {
+
+ // We design such a unit test to check
+ // that the execution of the GetDelegationToken method is as expected.
+ //
+ // 1. Apply for a DelegationToken for renewer1,
+ // the Router returns the DelegationToken of the user, and the KIND of the
token is
+ // RM_DELEGATION_TOKEN
+ //
+ // 2. We maintain the compatibility with RMDelegationTokenIdentifier,
+ // we can serialize the token into RMDelegationTokenIdentifier.
+ //
+ // 3. We can get the issueDate, and compare the data in the StateStore,
+ // the data should be consistent.
+
+ // Step1. We apply for DelegationToken for renewer1
+ // Both response & delegationToken cannot be empty
+ GetDelegationTokenRequest request = mock(GetDelegationTokenRequest.class);
+ when(request.getRenewer()).thenReturn("renewer1");
+ GetDelegationTokenResponse response =
interceptor.getDelegationToken(request);
+ Assert.assertNotNull(response);
+ Token delegationToken = response.getRMDelegationToken();
+ Assert.assertNotNull(delegationToken);
+ Assert.assertEquals("RM_DELEGATION_TOKEN", delegationToken.getKind());
+
+ // Step2. Serialize the returned Token as RMDelegationTokenIdentifier.
+ org.apache.hadoop.security.token.Token<RMDelegationTokenIdentifier> token =
+ ConverterUtils.convertFromYarn(delegationToken, (Text) null);
+ RMDelegationTokenIdentifier rMDelegationTokenIdentifier =
token.decodeIdentifier();
+ Assert.assertNotNull(rMDelegationTokenIdentifier);
+
+ // Step3. Verify the returned data of the token.
+ String renewer = rMDelegationTokenIdentifier.getRenewer().toString();
+ long issueDate = rMDelegationTokenIdentifier.getIssueDate();
+ long maxDate = rMDelegationTokenIdentifier.getMaxDate();
+ Assert.assertEquals("renewer1", renewer);
+
+ long tokenMaxLifetime = this.getConf().getLong(
+ YarnConfiguration.RM_DELEGATION_TOKEN_MAX_LIFETIME_KEY,
+ YarnConfiguration.RM_DELEGATION_TOKEN_MAX_LIFETIME_DEFAULT);
+ Assert.assertEquals((issueDate + tokenMaxLifetime), maxDate);
+
+ RouterRMDTSecretManagerState managerState =
stateStore.getRouterRMSecretManagerState();
+ Assert.assertNotNull(managerState);
+
+ Map<RMDelegationTokenIdentifier, Long> delegationTokenState =
managerState.getTokenState();
+ Assert.assertNotNull(delegationTokenState);
+
Assert.assertTrue(delegationTokenState.containsKey(rMDelegationTokenIdentifier));
+
+ long tokenRenewInterval = this.getConf().getLong(
+ YarnConfiguration.RM_DELEGATION_TOKEN_RENEW_INTERVAL_KEY,
+ YarnConfiguration.RM_DELEGATION_TOKEN_RENEW_INTERVAL_DEFAULT);
+ long renewDate = delegationTokenState.get(rMDelegationTokenIdentifier);
+ Assert.assertEquals((issueDate + tokenRenewInterval), renewDate);
Review Comment:
No need for internal parenthesis.
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/FederationClientInterceptor.java:
##########
@@ -1998,4 +2088,5 @@ protected int getNumMaxThreads(Configuration conf) {
public void setNumSubmitRetries(int numSubmitRetries) {
this.numSubmitRetries = numSubmitRetries;
}
+
Review Comment:
Avoid
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/FederationClientInterceptor.java:
##########
@@ -1474,19 +1479,104 @@ public GetContainersResponse
getContainers(GetContainersRequest request)
@Override
public GetDelegationTokenResponse getDelegationToken(
GetDelegationTokenRequest request) throws YarnException, IOException {
- throw new NotImplementedException("Code is not implemented");
+
+ if (request == null || request.getRenewer() == null) {
+ routerMetrics.incrGetDelegationTokenFailedRetrieved();
+ RouterServerUtil.logAndThrowException(
+ "Missing getDelegationToken request or Renewer.", null);
+ }
+
+ try {
+
Review Comment:
Avoid this empty line
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]