|
38 | 38 | import org.apache.hadoop.test.LambdaTestUtils; |
39 | 39 | import org.apache.hadoop.util.Time; |
40 | 40 | import org.apache.hadoop.yarn.MockApps; |
41 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptReportRequest; |
42 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptReportResponse; |
43 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest; |
44 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportResponse; |
45 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsRequest; |
46 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsResponse; |
47 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetClusterMetricsRequest; |
48 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetClusterMetricsResponse; |
49 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationRequest; |
50 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationResponse; |
51 | | -import org.apache.hadoop.yarn.api.protocolrecords.KillApplicationRequest; |
52 | | -import org.apache.hadoop.yarn.api.protocolrecords.KillApplicationResponse; |
53 | | -import org.apache.hadoop.yarn.api.protocolrecords.SubmitApplicationRequest; |
54 | | -import org.apache.hadoop.yarn.api.protocolrecords.SubmitApplicationResponse; |
55 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetClusterNodesResponse; |
56 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetClusterNodesRequest; |
57 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetNodesToLabelsResponse; |
58 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetNodesToLabelsRequest; |
59 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetLabelsToNodesResponse; |
60 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetLabelsToNodesRequest; |
61 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetClusterNodeLabelsResponse; |
62 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetClusterNodeLabelsRequest; |
63 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsRequest; |
64 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsResponse; |
65 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetQueueUserAclsInfoResponse; |
66 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetQueueUserAclsInfoRequest; |
67 | | -import org.apache.hadoop.yarn.api.protocolrecords.ReservationListResponse; |
68 | | -import org.apache.hadoop.yarn.api.protocolrecords.ReservationListRequest; |
69 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetContainersRequest; |
70 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetContainersResponse; |
71 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetContainerReportRequest; |
72 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetContainerReportResponse; |
73 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoResponse; |
74 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoRequest; |
75 | | -import org.apache.hadoop.yarn.api.protocolrecords.FailApplicationAttemptRequest; |
76 | | -import org.apache.hadoop.yarn.api.protocolrecords.FailApplicationAttemptResponse; |
77 | | -import org.apache.hadoop.yarn.api.protocolrecords.UpdateApplicationPriorityRequest; |
78 | | -import org.apache.hadoop.yarn.api.protocolrecords.UpdateApplicationPriorityResponse; |
79 | | -import org.apache.hadoop.yarn.api.protocolrecords.UpdateApplicationTimeoutsRequest; |
80 | | -import org.apache.hadoop.yarn.api.protocolrecords.UpdateApplicationTimeoutsResponse; |
81 | | -import org.apache.hadoop.yarn.api.protocolrecords.SignalContainerRequest; |
82 | | -import org.apache.hadoop.yarn.api.protocolrecords.SignalContainerResponse; |
83 | | -import org.apache.hadoop.yarn.api.protocolrecords.MoveApplicationAcrossQueuesRequest; |
84 | | -import org.apache.hadoop.yarn.api.protocolrecords.MoveApplicationAcrossQueuesResponse; |
85 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetQueueInfoRequest; |
86 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetQueueInfoResponse; |
87 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceProfilesRequest; |
88 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceProfilesResponse; |
89 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetResourceProfileRequest; |
90 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetResourceProfileResponse; |
91 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetAttributesToNodesRequest; |
92 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetAttributesToNodesResponse; |
93 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetClusterNodeAttributesRequest; |
94 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetClusterNodeAttributesResponse; |
95 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetNodesToAttributesRequest; |
96 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetNodesToAttributesResponse; |
97 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetNewReservationRequest; |
98 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetNewReservationResponse; |
99 | | -import org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionRequest; |
100 | | -import org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionResponse; |
101 | | -import org.apache.hadoop.yarn.api.protocolrecords.ReservationUpdateRequest; |
102 | | -import org.apache.hadoop.yarn.api.protocolrecords.ReservationUpdateResponse; |
103 | | -import org.apache.hadoop.yarn.api.protocolrecords.ReservationDeleteRequest; |
104 | | -import org.apache.hadoop.yarn.api.protocolrecords.ReservationDeleteResponse; |
105 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetDelegationTokenRequest; |
106 | | -import org.apache.hadoop.yarn.api.protocolrecords.GetDelegationTokenResponse; |
| 41 | +import org.apache.hadoop.yarn.api.protocolrecords.*; |
107 | 42 | import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; |
108 | 43 | import org.apache.hadoop.yarn.api.records.ApplicationId; |
109 | 44 | import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext; |
|
146 | 81 | import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppState; |
147 | 82 | import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttemptState; |
148 | 83 | import org.apache.hadoop.yarn.server.router.security.RouterDelegationTokenSecretManager; |
| 84 | +import org.apache.hadoop.yarn.server.utils.BuilderUtils; |
149 | 85 | import org.apache.hadoop.yarn.util.ConverterUtils; |
| 86 | +import org.apache.hadoop.yarn.util.Records; |
150 | 87 | import org.apache.hadoop.yarn.util.Times; |
151 | 88 | import org.apache.hadoop.yarn.util.resource.Resources; |
152 | 89 | import org.junit.Assert; |
@@ -1615,9 +1552,43 @@ public void testGetDelegationToken() throws IOException, YarnException { |
1615 | 1552 | RouterRMDTSecretManagerState managerState = stateStore.getRouterRMSecretManagerState(); |
1616 | 1553 | Map<RMDelegationTokenIdentifier, Long> delegationTokenState = managerState.getTokenState(); |
1617 | 1554 | long tokenRenewInterval = this.getConf().getLong( |
1618 | | - YarnConfiguration.RM_DELEGATION_TOKEN_RENEW_INTERVAL_KEY, |
1619 | | - YarnConfiguration.RM_DELEGATION_TOKEN_RENEW_INTERVAL_DEFAULT); |
| 1555 | + YarnConfiguration.RM_DELEGATION_TOKEN_RENEW_INTERVAL_KEY, |
| 1556 | + YarnConfiguration.RM_DELEGATION_TOKEN_RENEW_INTERVAL_DEFAULT); |
1620 | 1557 | long renewDate = delegationTokenState.get(rMDelegationTokenIdentifier); |
1621 | 1558 | Assert.assertEquals((issueDate + tokenRenewInterval), renewDate); |
1622 | 1559 | } |
| 1560 | + |
| 1561 | + @Test |
| 1562 | + public void testRenewDelegationToken() throws IOException, YarnException { |
| 1563 | + |
| 1564 | + // We design such a unit test to check |
| 1565 | + // that the execution of the GetDelegationToken method is as expected |
| 1566 | + // 1. Call GetDelegationToken to apply for delegationToken. |
| 1567 | + // 2. Call renewDelegationToken to refresh delegationToken. |
| 1568 | + // By looking at the code of AbstractDelegationTokenSecretManager#renewToken, |
| 1569 | + // we know that renewTime is calculated as Math.min(id.getMaxDate(), now + tokenRenewInterval) |
| 1570 | + // so renewTime will be less than or equal to maxDate |
| 1571 | + |
| 1572 | + GetDelegationTokenRequest request = mock(GetDelegationTokenRequest.class); |
| 1573 | + when(request.getRenewer()).thenReturn("renewer2"); |
| 1574 | + GetDelegationTokenResponse response = interceptor.getDelegationToken(request); |
| 1575 | + Assert.assertNotNull(response); |
| 1576 | + Token delegationToken = response.getRMDelegationToken(); |
| 1577 | + |
| 1578 | + // Step2. Serialize the returned Token as RMDelegationTokenIdentifier. |
| 1579 | + org.apache.hadoop.security.token.Token<RMDelegationTokenIdentifier> token = |
| 1580 | + ConverterUtils.convertFromYarn(delegationToken, (Text) null); |
| 1581 | + RMDelegationTokenIdentifier rMDelegationTokenIdentifier = token.decodeIdentifier(); |
| 1582 | + String renewer = rMDelegationTokenIdentifier.getRenewer().toString(); |
| 1583 | + long maxDate = rMDelegationTokenIdentifier.getMaxDate(); |
| 1584 | + Assert.assertEquals("renewer2", renewer); |
| 1585 | + |
| 1586 | + RenewDelegationTokenRequest renewRequest = Records.newRecord(RenewDelegationTokenRequest.class); |
| 1587 | + renewRequest.setDelegationToken(delegationToken); |
| 1588 | + RenewDelegationTokenResponse renewResponse = interceptor.renewDelegationToken(renewRequest); |
| 1589 | + Assert.assertNotNull(renewResponse); |
| 1590 | + |
| 1591 | + long expDate = renewResponse.getNextExpirationTime(); |
| 1592 | + Assert.assertTrue(expDate <= maxDate); |
| 1593 | + } |
1623 | 1594 | } |
0 commit comments