-
Notifications
You must be signed in to change notification settings - Fork 9.1k
HDDS-1973. Implement OM RenewDelegationToken request to use Cache and DoubleBuffer. #1316
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 all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
164 changes: 164 additions & 0 deletions
164
.../main/java/org/apache/hadoop/ozone/om/request/security/OMRenewDelegationTokenRequest.java
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 |
---|---|---|
@@ -0,0 +1,164 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.hadoop.ozone.om.request.security; | ||
|
||
import java.io.IOException; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.google.common.base.Optional; | ||
import org.apache.hadoop.ozone.om.OMMetadataManager; | ||
import org.apache.hadoop.ozone.om.OzoneManager; | ||
import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper; | ||
import org.apache.hadoop.ozone.om.request.OMClientRequest; | ||
import org.apache.hadoop.ozone.om.response.OMClientResponse; | ||
import org.apache.hadoop.ozone.om.response.security.OMRenewDelegationTokenResponse; | ||
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos; | ||
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest; | ||
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse; | ||
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.RenewDelegationTokenResponseProto; | ||
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.UpdateRenewDelegationTokenRequest; | ||
import org.apache.hadoop.ozone.protocolPB.OMPBHelper; | ||
import org.apache.hadoop.ozone.security.OzoneTokenIdentifier; | ||
import org.apache.hadoop.security.proto.SecurityProtos.RenewDelegationTokenRequestProto; | ||
import org.apache.hadoop.security.token.Token; | ||
import org.apache.hadoop.utils.db.cache.CacheKey; | ||
import org.apache.hadoop.utils.db.cache.CacheValue; | ||
|
||
/** | ||
* Handle RenewDelegationToken Request. | ||
*/ | ||
public class OMRenewDelegationTokenRequest extends OMClientRequest { | ||
|
||
private static final Logger LOG = | ||
LoggerFactory.getLogger(OMRenewDelegationTokenRequest.class); | ||
|
||
public OMRenewDelegationTokenRequest(OMRequest omRequest) { | ||
super(omRequest); | ||
} | ||
|
||
@Override | ||
public OMRequest preExecute(OzoneManager ozoneManager) throws IOException { | ||
RenewDelegationTokenRequestProto renewDelegationTokenRequest = | ||
getOmRequest().getRenewDelegationTokenRequest(); | ||
|
||
// Call OM to renew token | ||
long renewTime = ozoneManager.renewDelegationToken( | ||
OMPBHelper.convertToDelegationToken( | ||
renewDelegationTokenRequest.getToken())); | ||
|
||
RenewDelegationTokenResponseProto.Builder renewResponse = | ||
RenewDelegationTokenResponseProto.newBuilder(); | ||
|
||
renewResponse.setResponse(org.apache.hadoop.security.proto.SecurityProtos | ||
.RenewDelegationTokenResponseProto.newBuilder() | ||
.setNewExpiryTime(renewTime)); | ||
|
||
|
||
// Client issues RenewDelegationToken request, when received by OM leader | ||
// it will renew the token. Original RenewDelegationToken request is | ||
// converted to UpdateRenewDelegationToken request with the token and renew | ||
// information. This updated request will be submitted to Ratis. In this | ||
// way delegation token renewd by leader, will be replicated across all | ||
// OMs. With this approach, original RenewDelegationToken request from | ||
// client does not need any proto changes. | ||
|
||
// Create UpdateRenewDelegationTokenRequest with original request and | ||
// expiry time. | ||
OMRequest.Builder omRequest = OMRequest.newBuilder() | ||
.setUserInfo(getUserInfo()) | ||
.setUpdatedRenewDelegationTokenRequest( | ||
UpdateRenewDelegationTokenRequest.newBuilder() | ||
.setRenewDelegationTokenRequest(renewDelegationTokenRequest) | ||
.setRenewDelegationTokenResponse(renewResponse)) | ||
.setCmdType(getOmRequest().getCmdType()) | ||
.setClientId(getOmRequest().getClientId()); | ||
|
||
if (getOmRequest().hasTraceID()) { | ||
omRequest.setTraceID(getOmRequest().getTraceID()); | ||
} | ||
|
||
return omRequest.build(); | ||
} | ||
|
||
@Override | ||
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, | ||
long transactionLogIndex, | ||
OzoneManagerDoubleBufferHelper ozoneManagerDoubleBufferHelper) { | ||
|
||
UpdateRenewDelegationTokenRequest updateRenewDelegationTokenRequest = | ||
getOmRequest().getUpdatedRenewDelegationTokenRequest(); | ||
|
||
Token<OzoneTokenIdentifier> ozoneTokenIdentifierToken = | ||
OMPBHelper.convertToDelegationToken(updateRenewDelegationTokenRequest | ||
.getRenewDelegationTokenRequest().getToken()); | ||
|
||
long renewTime = updateRenewDelegationTokenRequest | ||
.getRenewDelegationTokenResponse().getResponse().getNewExpiryTime(); | ||
|
||
OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager(); | ||
|
||
OMClientResponse omClientResponse = null; | ||
OMResponse.Builder omResponse = | ||
OMResponse.newBuilder() | ||
.setCmdType(OzoneManagerProtocolProtos.Type.RenewDelegationToken) | ||
.setStatus(OzoneManagerProtocolProtos.Status.OK) | ||
.setSuccess(true); | ||
try { | ||
|
||
OzoneTokenIdentifier ozoneTokenIdentifier = | ||
ozoneTokenIdentifierToken.decodeIdentifier(); | ||
|
||
// Update in memory map of token. | ||
ozoneManager.getDelegationTokenMgr() | ||
.updateRenewToken(ozoneTokenIdentifierToken, ozoneTokenIdentifier, | ||
renewTime); | ||
|
||
// Update Cache. | ||
omMetadataManager.getDelegationTokenTable().addCacheEntry( | ||
new CacheKey<>(ozoneTokenIdentifier), | ||
new CacheValue<>(Optional.of(renewTime), transactionLogIndex)); | ||
|
||
omClientResponse = | ||
new OMRenewDelegationTokenResponse(ozoneTokenIdentifier, renewTime, | ||
omResponse.setRenewDelegationTokenResponse( | ||
updateRenewDelegationTokenRequest | ||
.getRenewDelegationTokenResponse()).build()); | ||
} catch (IOException ex) { | ||
LOG.error("Error in Updating Renew DelegationToken {}", | ||
ozoneTokenIdentifierToken, ex); | ||
omClientResponse = new OMRenewDelegationTokenResponse(null, -1L, | ||
createErrorOMResponse(omResponse, ex)); | ||
} finally { | ||
if (omClientResponse != null) { | ||
omClientResponse.setFlushFuture( | ||
ozoneManagerDoubleBufferHelper.add(omClientResponse, | ||
transactionLogIndex)); | ||
} | ||
} | ||
|
||
if (LOG.isDebugEnabled()) { | ||
LOG.debug("Updated renew delegation token in-memory map: {} with expiry" + | ||
" time {}", ozoneTokenIdentifierToken, renewTime); | ||
} | ||
|
||
return omClientResponse; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...ain/java/org/apache/hadoop/ozone/om/response/security/OMRenewDelegationTokenResponse.java
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.hadoop.ozone.om.response.security; | ||
|
||
import org.apache.hadoop.ozone.om.OMMetadataManager; | ||
import org.apache.hadoop.ozone.om.response.OMClientResponse; | ||
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos; | ||
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse; | ||
import org.apache.hadoop.ozone.security.OzoneTokenIdentifier; | ||
import org.apache.hadoop.utils.db.BatchOperation; | ||
import org.apache.hadoop.utils.db.Table; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Handle response for RenewDelegationToken request. | ||
*/ | ||
public class OMRenewDelegationTokenResponse extends OMClientResponse { | ||
|
||
private OzoneTokenIdentifier ozoneTokenIdentifier; | ||
private long renewTime = -1L; | ||
|
||
public OMRenewDelegationTokenResponse( | ||
@Nullable OzoneTokenIdentifier ozoneTokenIdentifier, | ||
long renewTime, @Nonnull OMResponse omResponse) { | ||
super(omResponse); | ||
this.ozoneTokenIdentifier = ozoneTokenIdentifier; | ||
this.renewTime = renewTime; | ||
} | ||
|
||
@Override | ||
public void addToDBBatch(OMMetadataManager omMetadataManager, | ||
BatchOperation batchOperation) throws IOException { | ||
Table table = omMetadataManager.getDelegationTokenTable(); | ||
if (getOMResponse().getStatus() == OzoneManagerProtocolProtos.Status.OK) { | ||
table.putWithBatch(batchOperation, ozoneTokenIdentifier, renewTime); | ||
} | ||
} | ||
} | ||
|
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Should we use the cmd type of UpdateRenewDelegationTokenRequest
Uh oh!
There was an error while loading. Please reload this page.
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.
This is being done intentionally so that we don't need new class or some special handling in OMRatisUtils createOMClientRequest().
Same is explained in the code comments.
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.
An UpdateRenewDelegationTokenRequest body with RenewDelegationTokenRequest type in OMRequest is a bit hacky. But I'm OK with it if otherwise takes too much changes.
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.
Ya can understand that. Otherwise, we need some changes in createClientRequest in ratis to act upon UpdateRenewDelegationTokenRequest or RenewDelegationTokenRequest to return OMGetDelegationTokenRequest object or have separate new classes for both of them. And for one only preExecute will be needed, for other validateAndUpdateCache only will be needed. So, I will leave this as it is.
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 agree this is a bit hard to follow. I also had a long discussion with Bharat while reviewing the createDelegationToken patch. I am okay to live with for now to avoid creating yet another request class.