Search in sources :

Example 1 with OMPrefixAclOpResult

use of org.apache.hadoop.ozone.om.PrefixManagerImpl.OMPrefixAclOpResult in project ozone by apache.

the class OMPrefixAclRequest method validateAndUpdateCache.

@Override
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
    OmPrefixInfo omPrefixInfo = null;
    OMResponse.Builder omResponse = onInit();
    OMClientResponse omClientResponse = null;
    IOException exception = null;
    OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
    boolean lockAcquired = false;
    String volume = null;
    String bucket = null;
    String key = null;
    OMPrefixAclOpResult operationResult = null;
    boolean opResult = false;
    Result result = null;
    PrefixManagerImpl prefixManager = (PrefixManagerImpl) ozoneManager.getPrefixManager();
    try {
        String prefixPath = getOzoneObj().getPath();
        ObjectParser objectParser = new ObjectParser(prefixPath, OzoneManagerProtocolProtos.OzoneObj.ObjectType.PREFIX);
        volume = objectParser.getVolume();
        bucket = objectParser.getBucket();
        key = objectParser.getKey();
        // check Acl
        if (ozoneManager.getAclsEnabled()) {
            checkAcls(ozoneManager, OzoneObj.ResourceType.PREFIX, OzoneObj.StoreType.OZONE, IAccessAuthorizer.ACLType.WRITE_ACL, volume, bucket, key);
        }
        lockAcquired = omMetadataManager.getLock().acquireWriteLock(PREFIX_LOCK, prefixPath);
        omPrefixInfo = omMetadataManager.getPrefixTable().get(prefixPath);
        try {
            operationResult = apply(prefixManager, omPrefixInfo, trxnLogIndex);
        } catch (IOException ex) {
            // In HA case this will never happen.
            // As in add/remove/setAcl method we have logic to update database,
            // that can throw exception. But in HA case we shall not update DB.
            // The code in prefixManagerImpl is being done, because update
            // in-memory should be done after DB update for Non-HA code path.
            operationResult = new OMPrefixAclOpResult(null, false);
        }
        omPrefixInfo = operationResult.getOmPrefixInfo();
        omPrefixInfo.setUpdateID(trxnLogIndex, ozoneManager.isRatisEnabled());
        // prefix from prefix table.
        if (getOmRequest().hasRemoveAclRequest() && omPrefixInfo.getAcls().size() == 0) {
            omMetadataManager.getPrefixTable().addCacheEntry(new CacheKey<>(prefixPath), new CacheValue<>(Optional.absent(), trxnLogIndex));
        } else {
            // update cache.
            omMetadataManager.getPrefixTable().addCacheEntry(new CacheKey<>(prefixPath), new CacheValue<>(Optional.of(omPrefixInfo), trxnLogIndex));
        }
        opResult = operationResult.isSuccess();
        omClientResponse = onSuccess(omResponse, omPrefixInfo, opResult);
        result = Result.SUCCESS;
    } catch (IOException ex) {
        result = Result.FAILURE;
        exception = ex;
        omClientResponse = onFailure(omResponse, ex);
    } finally {
        addResponseToDoubleBuffer(trxnLogIndex, omClientResponse, omDoubleBufferHelper);
        if (lockAcquired) {
            omMetadataManager.getLock().releaseWriteLock(PREFIX_LOCK, getOzoneObj().getPath());
        }
    }
    OzoneObj obj = getOzoneObj();
    Map<String, String> auditMap = obj.toAuditMap();
    onComplete(opResult, exception, ozoneManager.getMetrics(), result, trxnLogIndex, ozoneManager.getAuditLogger(), auditMap);
    return omClientResponse;
}
Also used : ObjectParser(org.apache.hadoop.ozone.om.request.util.ObjectParser) OzoneObj(org.apache.hadoop.ozone.security.acl.OzoneObj) PrefixManagerImpl(org.apache.hadoop.ozone.om.PrefixManagerImpl) OMClientResponse(org.apache.hadoop.ozone.om.response.OMClientResponse) OmPrefixInfo(org.apache.hadoop.ozone.om.helpers.OmPrefixInfo) OMPrefixAclOpResult(org.apache.hadoop.ozone.om.PrefixManagerImpl.OMPrefixAclOpResult) IOException(java.io.IOException) OMResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse) OMPrefixAclOpResult(org.apache.hadoop.ozone.om.PrefixManagerImpl.OMPrefixAclOpResult) OMMetadataManager(org.apache.hadoop.ozone.om.OMMetadataManager)

Aggregations

IOException (java.io.IOException)1 OMMetadataManager (org.apache.hadoop.ozone.om.OMMetadataManager)1 PrefixManagerImpl (org.apache.hadoop.ozone.om.PrefixManagerImpl)1 OMPrefixAclOpResult (org.apache.hadoop.ozone.om.PrefixManagerImpl.OMPrefixAclOpResult)1 OmPrefixInfo (org.apache.hadoop.ozone.om.helpers.OmPrefixInfo)1 ObjectParser (org.apache.hadoop.ozone.om.request.util.ObjectParser)1 OMClientResponse (org.apache.hadoop.ozone.om.response.OMClientResponse)1 OMResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse)1 OzoneObj (org.apache.hadoop.ozone.security.acl.OzoneObj)1