-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HDDS-1969. Implement OM GetDelegationToken request to use Cache and D…
…oubleBuffer. (#1296)
- Loading branch information
1 parent
e356e4f
commit 8943e13
Showing
9 changed files
with
301 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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 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
156 changes: 156 additions & 0 deletions
156
...rc/main/java/org/apache/hadoop/ozone/om/request/security/OMGetDelegationTokenRequest.java
This file contains 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,156 @@ | ||
/** | ||
* 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.io.Text; | ||
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.OMDelegationTokenResponse; | ||
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos; | ||
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.GetDelegationTokenResponseProto; | ||
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.UpdateGetDelegationTokenRequest; | ||
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.GetDelegationTokenRequestProto; | ||
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 GetDelegationToken Request. | ||
*/ | ||
public class OMGetDelegationTokenRequest extends OMClientRequest { | ||
|
||
private static final Logger LOG = | ||
LoggerFactory.getLogger(OMGetDelegationTokenRequest.class); | ||
|
||
public OMGetDelegationTokenRequest(OMRequest omRequest) { | ||
super(omRequest); | ||
} | ||
|
||
@Override | ||
public OMRequest preExecute(OzoneManager ozoneManager) throws IOException { | ||
GetDelegationTokenRequestProto getDelegationTokenRequest = | ||
getOmRequest().getGetDelegationTokenRequest(); | ||
|
||
// Call OM to create token | ||
Token<OzoneTokenIdentifier> token = ozoneManager | ||
.getDelegationToken(new Text(getDelegationTokenRequest.getRenewer())); | ||
|
||
|
||
// Client issues GetDelegationToken request, when received by OM leader will | ||
// it generate Token. Original GetDelegationToken request is converted to | ||
// UpdateGetDelegationToken request with the generated token information. | ||
// This updated request will be submitted to Ratis. In this way delegation | ||
// token created by leader, will be replicated across all OMs. | ||
// And also original GetDelegationToken request from client does not need | ||
// any proto changes. | ||
|
||
// Create UpdateGetDelegationTokenRequest with token response. | ||
OMRequest.Builder omRequest = OMRequest.newBuilder() | ||
.setUserInfo(getUserInfo()) | ||
.setUpdateGetDelegationTokenRequest( | ||
UpdateGetDelegationTokenRequest.newBuilder() | ||
.setGetDelegationTokenResponse( | ||
GetDelegationTokenResponseProto.newBuilder() | ||
.setResponse(SecurityProtos.GetDelegationTokenResponseProto | ||
.newBuilder().setToken(OMPBHelper | ||
.convertToTokenProto(token)).build()).build())) | ||
.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) { | ||
|
||
UpdateGetDelegationTokenRequest updateGetDelegationTokenRequest = | ||
getOmRequest().getUpdateGetDelegationTokenRequest(); | ||
|
||
SecurityProtos.TokenProto tokenProto = updateGetDelegationTokenRequest | ||
.getGetDelegationTokenResponse().getResponse().getToken(); | ||
|
||
Token<OzoneTokenIdentifier> ozoneTokenIdentifierToken = | ||
OMPBHelper.convertToDelegationToken(tokenProto); | ||
|
||
OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager(); | ||
|
||
OMClientResponse omClientResponse = null; | ||
OMResponse.Builder omResponse = | ||
OMResponse.newBuilder() | ||
.setCmdType(OzoneManagerProtocolProtos.Type.GetDelegationToken) | ||
.setStatus(OzoneManagerProtocolProtos.Status.OK) | ||
.setSuccess(true); | ||
try { | ||
OzoneTokenIdentifier ozoneTokenIdentifier = | ||
ozoneTokenIdentifierToken.decodeIdentifier(); | ||
|
||
// Update in memory map of token. | ||
long renewTime = ozoneManager.getDelegationTokenMgr() | ||
.updateToken(ozoneTokenIdentifierToken, ozoneTokenIdentifier); | ||
|
||
// Update Cache. | ||
omMetadataManager.getDelegationTokenTable().addCacheEntry( | ||
new CacheKey<>(ozoneTokenIdentifier), | ||
new CacheValue<>(Optional.of(renewTime), transactionLogIndex)); | ||
|
||
omClientResponse = | ||
new OMDelegationTokenResponse(ozoneTokenIdentifier, renewTime, | ||
omResponse.setGetDelegationTokenResponse( | ||
updateGetDelegationTokenRequest | ||
.getGetDelegationTokenResponse()).build()); | ||
} catch (IOException ex) { | ||
LOG.error("Error in Updating DelegationToken {} to DB", | ||
ozoneTokenIdentifierToken, ex); | ||
omClientResponse = new OMDelegationTokenResponse(null, -1L, | ||
createErrorOMResponse(omResponse, ex)); | ||
} finally { | ||
if (omClientResponse != null) { | ||
omClientResponse.setFlushFuture( | ||
ozoneManagerDoubleBufferHelper.add(omClientResponse, | ||
transactionLogIndex)); | ||
} | ||
} | ||
|
||
if (LOG.isDebugEnabled()) { | ||
LOG.debug("Updated delegation token to OM DB: {}", | ||
ozoneTokenIdentifierToken); | ||
} | ||
|
||
return omClientResponse; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/security/package-info.java
This file contains 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,22 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* This package contains classes which handle security requests. | ||
*/ | ||
package org.apache.hadoop.ozone.om.request.security; |
54 changes: 54 additions & 0 deletions
54
...src/main/java/org/apache/hadoop/ozone/om/response/security/OMDelegationTokenResponse.java
This file contains 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,54 @@ | ||
/** | ||
* 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 java.io.IOException; | ||
|
||
/** | ||
* Handle response for DelegationToken request. | ||
*/ | ||
public class OMDelegationTokenResponse extends OMClientResponse { | ||
|
||
private OzoneTokenIdentifier ozoneTokenIdentifier; | ||
private long renewTime; | ||
public OMDelegationTokenResponse(OzoneTokenIdentifier ozoneTokenIdentifier, | ||
long renewTime, OMResponse omResponse) { | ||
super(omResponse); | ||
this.ozoneTokenIdentifier = ozoneTokenIdentifier; | ||
this.renewTime = renewTime; | ||
} | ||
|
||
@Override | ||
public void addToDBBatch(OMMetadataManager omMetadataManager, | ||
BatchOperation batchOperation) throws IOException { | ||
|
||
if (getOMResponse().getStatus() == OzoneManagerProtocolProtos.Status.OK) { | ||
omMetadataManager.getDelegationTokenTable().putWithBatch(batchOperation, | ||
ozoneTokenIdentifier, renewTime); | ||
} | ||
} | ||
} | ||
|
22 changes: 22 additions & 0 deletions
22
...zone-manager/src/main/java/org/apache/hadoop/ozone/om/response/security/package-info.java
This file contains 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,22 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* This package contains classes which handle security request responses. | ||
*/ | ||
package org.apache.hadoop.ozone.om.response.security; |
This file contains 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