-
Notifications
You must be signed in to change notification settings - Fork 9.1k
HDDS-1974. Implement OM CancelDelegationToken request to use Cache and DoubleBuffer. #1308
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
5 commits
Select commit
Hold shift + click to select a range
162565f
HDDS-1974. Implement OM CancelDelegationToken request to use Cache an…
bharatviswa504 787aa4c
minor change.
bharatviswa504 1d165c7
few minor changes.
bharatviswa504 e11e017
fix offline discussin comments.
bharatviswa504 08b1397
fix jenkins and cleanup changes not related to this PR.
bharatviswa504 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
125 changes: 125 additions & 0 deletions
125
...main/java/org/apache/hadoop/ozone/om/request/security/OMCancelDelegationTokenRequest.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,125 @@ | ||
/** | ||
* 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 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.OMCancelDelegationTokenResponse; | ||
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.CancelDelegationTokenResponseProto; | ||
import org.apache.hadoop.ozone.protocolPB.OMPBHelper; | ||
import org.apache.hadoop.ozone.security.OzoneTokenIdentifier; | ||
import org.apache.hadoop.security.proto.SecurityProtos; | ||
import org.apache.hadoop.security.proto.SecurityProtos.CancelDelegationTokenRequestProto; | ||
import org.apache.hadoop.security.token.Token; | ||
import org.apache.hadoop.utils.db.cache.CacheKey; | ||
import org.apache.hadoop.utils.db.cache.CacheValue; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Handle CancelDelegationToken Request. | ||
*/ | ||
public class OMCancelDelegationTokenRequest extends OMClientRequest { | ||
|
||
private static final Logger LOG = | ||
LoggerFactory.getLogger(OMGetDelegationTokenRequest.class); | ||
|
||
public OMCancelDelegationTokenRequest(OMRequest omRequest) { | ||
super(omRequest); | ||
} | ||
|
||
@Override | ||
public OMRequest preExecute(OzoneManager ozoneManager) throws IOException { | ||
|
||
// Call OM to cancel token, this does check whether we can cancel token | ||
// or not. This does not remove token from DB/in-memory. | ||
ozoneManager.cancelDelegationToken(getToken()); | ||
|
||
return super.preExecute(ozoneManager); | ||
} | ||
|
||
@Override | ||
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, | ||
long transactionLogIndex, | ||
OzoneManagerDoubleBufferHelper ozoneManagerDoubleBufferHelper) { | ||
|
||
OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager(); | ||
|
||
OMClientResponse omClientResponse = null; | ||
OMResponse.Builder omResponse = | ||
OMResponse.newBuilder() | ||
.setCmdType(OzoneManagerProtocolProtos.Type.CancelDelegationToken) | ||
.setStatus(OzoneManagerProtocolProtos.Status.OK) | ||
.setSuccess(true); | ||
OzoneTokenIdentifier ozoneTokenIdentifier = null; | ||
try { | ||
ozoneTokenIdentifier = | ||
OzoneTokenIdentifier.readProtoBuf(getToken().getIdentifier()); | ||
|
||
// Remove token from in-memory. | ||
ozoneManager.getDelegationTokenMgr().removeToken(ozoneTokenIdentifier); | ||
|
||
// Update Cache. | ||
omMetadataManager.getDelegationTokenTable().addCacheEntry( | ||
new CacheKey<>(ozoneTokenIdentifier), | ||
new CacheValue<>(Optional.absent(), transactionLogIndex)); | ||
|
||
omClientResponse = | ||
new OMCancelDelegationTokenResponse(ozoneTokenIdentifier, | ||
omResponse.setCancelDelegationTokenResponse( | ||
CancelDelegationTokenResponseProto.newBuilder().setResponse( | ||
SecurityProtos.CancelDelegationTokenResponseProto | ||
.newBuilder())).build()); | ||
} catch (IOException ex) { | ||
LOG.error("Error in cancel DelegationToken {}", ozoneTokenIdentifier, ex); | ||
omClientResponse = new OMCancelDelegationTokenResponse(null, | ||
createErrorOMResponse(omResponse, ex)); | ||
} finally { | ||
if (omClientResponse != null) { | ||
omClientResponse.setFlushFuture( | ||
ozoneManagerDoubleBufferHelper.add(omClientResponse, | ||
transactionLogIndex)); | ||
} | ||
} | ||
|
||
if (LOG.isDebugEnabled()) { | ||
LOG.debug("Cancelled delegation token: {}", ozoneTokenIdentifier); | ||
} | ||
|
||
return omClientResponse; | ||
} | ||
|
||
|
||
public Token<OzoneTokenIdentifier> getToken() { | ||
CancelDelegationTokenRequestProto cancelDelegationTokenRequest = | ||
getOmRequest().getCancelDelegationTokenRequest(); | ||
|
||
return OMPBHelper.convertToDelegationToken( | ||
cancelDelegationTokenRequest.getToken()); | ||
} | ||
} |
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
58 changes: 58 additions & 0 deletions
58
.../main/java/org/apache/hadoop/ozone/om/response/security/OMGetDelegationTokenResponse.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 GetDelegationToken request. | ||
*/ | ||
public class OMGetDelegationTokenResponse extends OMClientResponse { | ||
|
||
private OzoneTokenIdentifier ozoneTokenIdentifier; | ||
private long renewTime = -1L; | ||
|
||
public OMGetDelegationTokenResponse( | ||
@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); | ||
} | ||
} | ||
} | ||
|
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.