-
Notifications
You must be signed in to change notification settings - Fork 9.2k
YARN-11158. Support (Create/Renew/Cancel) DelegationToken API's for Federation. #5104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 13 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
2bd1730
YARN-11158. Support getDelegationToken, renewDelegationToken, cancelD…
b5d3ecd
YARN-11158. Fix CheckStyle.
5524803
YARN-11158. Fix CheckStyle.
aa134f8
YARN-11158. Fix CheckStyle.
15ad090
YARN-11158. Fix CheckStyle.
070759f
YARN-11158. Add Junit Test.
45479a9
YARN-11158. Fix CheckStyle.
09dcc8c
Merge branch 'trunk' into YARN-11158-V3
slfan1989 966b0a7
YARN-11158. Fix CheckStyle.
3877ee8
YARN-11350. [Federation] Router Support DelegationToken With ZK.
8e5a381
Merge branch 'apache:trunk' into YARN-11158-V3
slfan1989 829d87c
YARN-11158. Fix CheckStyle.
193fe06
Merge branch 'apache:trunk' into YARN-11158-V3
slfan1989 c7742c6
YARN-11358. Fix CheckStyle.
d0cf014
Merge branch 'trunk' into YARN-11158-V3
slfan1989 6d85eb9
YARN-11158. Fix CheckStyle.
c025e79
Merge branch 'apache:trunk' into YARN-11158-V3
slfan1989 f841715
Merge branch 'trunk' into YARN-11158-V3
slfan1989 6e09b66
YARN-11158. Fix CheckStyle.
639bd17
Merge branch 'apache:trunk' into YARN-11158-V3
slfan1989 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.apache.commons.lang3.tuple.Pair; | ||
| import org.apache.hadoop.io.Text; | ||
| import org.apache.hadoop.thirdparty.com.google.common.util.concurrent.ThreadFactoryBuilder; | ||
| import java.io.IOException; | ||
| import java.lang.reflect.Method; | ||
|
|
@@ -40,7 +41,6 @@ | |
| import java.util.concurrent.ThreadFactory; | ||
| import java.util.concurrent.ThreadPoolExecutor; | ||
| import java.util.concurrent.TimeUnit; | ||
| import org.apache.commons.lang3.NotImplementedException; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.fs.CommonConfigurationKeys; | ||
| import org.apache.hadoop.security.UserGroupInformation; | ||
|
|
@@ -118,9 +118,13 @@ | |
| import org.apache.hadoop.yarn.api.records.ApplicationId; | ||
| import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext; | ||
| import org.apache.hadoop.yarn.api.records.ReservationId; | ||
| import org.apache.hadoop.security.token.Token; | ||
| import org.apache.hadoop.yarn.server.utils.BuilderUtils; | ||
|
|
||
| import org.apache.hadoop.yarn.conf.YarnConfiguration; | ||
| import org.apache.hadoop.yarn.exceptions.YarnException; | ||
| import org.apache.hadoop.yarn.exceptions.YarnRuntimeException; | ||
| import org.apache.hadoop.yarn.security.client.RMDelegationTokenIdentifier; | ||
| import org.apache.hadoop.yarn.server.federation.failover.FederationProxyProviderUtil; | ||
| import org.apache.hadoop.yarn.server.federation.policies.FederationPolicyUtils; | ||
| import org.apache.hadoop.yarn.server.federation.policies.RouterPolicyFacade; | ||
|
|
@@ -136,6 +140,7 @@ | |
| import org.apache.hadoop.yarn.server.router.RouterServerUtil; | ||
| import org.apache.hadoop.yarn.util.Clock; | ||
| import org.apache.hadoop.yarn.util.MonotonicClock; | ||
| import org.apache.hadoop.yarn.util.Records; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
|
|
@@ -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 { | ||
|
|
||
| // Verify that the connection is kerberos authenticated | ||
| if (!RouterServerUtil.isAllowedDelegationTokenOp()) { | ||
| routerMetrics.incrGetDelegationTokenFailedRetrieved(); | ||
| throw new IOException( | ||
| "Delegation Token can be issued only with kerberos authentication."); | ||
| } | ||
|
|
||
| long startTime = clock.getTime(); | ||
| UserGroupInformation ugi = UserGroupInformation.getCurrentUser(); | ||
| Text owner = new Text(ugi.getUserName()); | ||
| Text realUser = null; | ||
| if (ugi.getRealUser() != null) { | ||
| realUser = new Text(ugi.getRealUser().getUserName()); | ||
| } | ||
|
|
||
| RMDelegationTokenIdentifier tokenIdentifier = | ||
| new RMDelegationTokenIdentifier(owner, new Text(request.getRenewer()), realUser); | ||
| Token<RMDelegationTokenIdentifier> realRMDToken = | ||
| new Token<>(tokenIdentifier, this.getTokenSecretManager()); | ||
|
|
||
| org.apache.hadoop.yarn.api.records.Token routerRMDTToken = | ||
| BuilderUtils.newDelegationToken(realRMDToken.getIdentifier(), | ||
| realRMDToken.getKind().toString(), | ||
| realRMDToken.getPassword(), realRMDToken.getService().toString()); | ||
|
|
||
| long stopTime = clock.getTime(); | ||
| routerMetrics.succeededGetDelegationTokenRetrieved((stopTime - startTime)); | ||
| return GetDelegationTokenResponse.newInstance(routerRMDTToken); | ||
| } catch(IOException e) { | ||
| routerMetrics.incrGetDelegationTokenFailedRetrieved(); | ||
| throw new YarnException(e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public RenewDelegationTokenResponse renewDelegationToken( | ||
| RenewDelegationTokenRequest request) throws YarnException, IOException { | ||
| throw new NotImplementedException("Code is not implemented"); | ||
| try { | ||
|
|
||
| if (!RouterServerUtil.isAllowedDelegationTokenOp()) { | ||
| routerMetrics.incrRenewDelegationTokenFailedRetrieved(); | ||
| throw new IOException( | ||
| "Delegation Token can be renewed only with kerberos authentication"); | ||
| } | ||
|
|
||
| long startTime = clock.getTime(); | ||
| org.apache.hadoop.yarn.api.records.Token protoToken = request.getDelegationToken(); | ||
| Token<RMDelegationTokenIdentifier> token = new Token<>( | ||
| protoToken.getIdentifier().array(), protoToken.getPassword().array(), | ||
| new Text(protoToken.getKind()), new Text(protoToken.getService())); | ||
| String user = RouterServerUtil.getRenewerForToken(token); | ||
| long nextExpTime = this.getTokenSecretManager().renewToken(token, user); | ||
| RenewDelegationTokenResponse renewResponse = | ||
| Records.newRecord(RenewDelegationTokenResponse.class); | ||
| renewResponse.setNextExpirationTime(nextExpTime); | ||
| long stopTime = clock.getTime(); | ||
| routerMetrics.succeededRenewDelegationTokenRetrieved((stopTime - startTime)); | ||
| return renewResponse; | ||
|
|
||
| } catch (IOException e) { | ||
| routerMetrics.incrRenewDelegationTokenFailedRetrieved(); | ||
| throw new YarnException(e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public CancelDelegationTokenResponse cancelDelegationToken( | ||
| CancelDelegationTokenRequest request) throws YarnException, IOException { | ||
| throw new NotImplementedException("Code is not implemented"); | ||
| try { | ||
| if (!RouterServerUtil.isAllowedDelegationTokenOp()) { | ||
| routerMetrics.incrCancelDelegationTokenFailedRetrieved(); | ||
| throw new IOException( | ||
| "Delegation Token can be cancelled only with kerberos authentication"); | ||
| } | ||
|
|
||
| long startTime = clock.getTime(); | ||
| org.apache.hadoop.yarn.api.records.Token protoToken = request.getDelegationToken(); | ||
| Token<RMDelegationTokenIdentifier> token = new Token<>( | ||
| protoToken.getIdentifier().array(), protoToken.getPassword().array(), | ||
| new Text(protoToken.getKind()), new Text(protoToken.getService())); | ||
| String user = UserGroupInformation.getCurrentUser().getUserName(); | ||
| this.getTokenSecretManager().cancelToken(token, user); | ||
| long stopTime = clock.getTime(); | ||
| routerMetrics.succeededCancelDelegationTokenRetrieved((stopTime - startTime)); | ||
| return Records.newRecord(CancelDelegationTokenResponse.class); | ||
| } catch (IOException e) { | ||
| routerMetrics.incrCancelDelegationTokenFailedRetrieved(); | ||
| throw new YarnException(e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -1998,4 +2088,5 @@ protected int getNumMaxThreads(Configuration conf) { | |
| public void setNumSubmitRetries(int numSubmitRetries) { | ||
| this.numSubmitRetries = numSubmitRetries; | ||
| } | ||
|
|
||
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid this empty line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will fix it.