Search in sources :

Example 1 with S3RevokeSecretResponse

use of org.apache.hadoop.ozone.om.response.s3.security.S3RevokeSecretResponse in project ozone by apache.

the class S3RevokeSecretRequest method validateAndUpdateCache.

@Override
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, long transactionLogIndex, OzoneManagerDoubleBufferHelper ozoneManagerDoubleBufferHelper) {
    OMClientResponse omClientResponse = null;
    OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(getOmRequest());
    boolean acquiredLock = false;
    IOException exception = null;
    OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
    final RevokeS3SecretRequest revokeS3SecretRequest = getOmRequest().getRevokeS3SecretRequest();
    String kerberosID = revokeS3SecretRequest.getKerberosID();
    try {
        acquiredLock = omMetadataManager.getLock().acquireWriteLock(S3_SECRET_LOCK, kerberosID);
        // Remove if entry exists in table
        if (omMetadataManager.getS3SecretTable().isExist(kerberosID)) {
            // Invalid entry in table cache immediately
            omMetadataManager.getS3SecretTable().addCacheEntry(new CacheKey<>(kerberosID), new CacheValue<>(Optional.absent(), transactionLogIndex));
            omClientResponse = new S3RevokeSecretResponse(kerberosID, omResponse.setStatus(Status.OK).build());
        } else {
            omClientResponse = new S3RevokeSecretResponse(null, omResponse.setStatus(Status.S3_SECRET_NOT_FOUND).build());
        }
    } catch (IOException ex) {
        exception = ex;
        omClientResponse = new S3RevokeSecretResponse(null, createErrorOMResponse(omResponse, ex));
    } finally {
        addResponseToDoubleBuffer(transactionLogIndex, omClientResponse, ozoneManagerDoubleBufferHelper);
        if (acquiredLock) {
            omMetadataManager.getLock().releaseWriteLock(S3_SECRET_LOCK, kerberosID);
        }
    }
    Map<String, String> auditMap = new HashMap<>();
    auditMap.put(OzoneConsts.S3_REVOKESECRET_USER, kerberosID);
    auditLog(ozoneManager.getAuditLogger(), buildAuditMessage(OMAction.REVOKE_S3_SECRET, auditMap, exception, getOmRequest().getUserInfo()));
    if (exception == null) {
        if (omResponse.getStatus() == Status.OK) {
            LOG.info("Secret for {} is revoked.", kerberosID);
        } else {
            LOG.info("Secret for {} doesn't exist.", kerberosID);
        }
    } else {
        LOG.error("Error when revoking secret for {}.", kerberosID, exception);
    }
    return omClientResponse;
}
Also used : OMClientResponse(org.apache.hadoop.ozone.om.response.OMClientResponse) HashMap(java.util.HashMap) IOException(java.io.IOException) OMResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse) S3RevokeSecretResponse(org.apache.hadoop.ozone.om.response.s3.security.S3RevokeSecretResponse) OMMetadataManager(org.apache.hadoop.ozone.om.OMMetadataManager) RevokeS3SecretRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.RevokeS3SecretRequest)

Aggregations

IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 OMMetadataManager (org.apache.hadoop.ozone.om.OMMetadataManager)1 OMClientResponse (org.apache.hadoop.ozone.om.response.OMClientResponse)1 S3RevokeSecretResponse (org.apache.hadoop.ozone.om.response.s3.security.S3RevokeSecretResponse)1 OMResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse)1 RevokeS3SecretRequest (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.RevokeS3SecretRequest)1