Search in sources :

Example 1 with ObjectParser

use of org.apache.hadoop.ozone.om.request.util.ObjectParser in project ozone by apache.

the class OMKeyAclRequest method initializeBucketLayout.

public void initializeBucketLayout(OzoneManager ozoneManager) {
    OmBucketInfo buckInfo;
    try {
        ObjectParser objectParser = new ObjectParser(getPath(), OzoneManagerProtocolProtos.OzoneObj.ObjectType.KEY);
        String volume = objectParser.getVolume();
        String bucket = objectParser.getBucket();
        String buckKey = ozoneManager.getMetadataManager().getBucketKey(volume, bucket);
        try {
            buckInfo = ozoneManager.getMetadataManager().getBucketTable().get(buckKey);
            if (buckInfo == null) {
                LOG.error("Bucket not found: {}/{} ", volume, bucket);
                // defaulting to BucketLayout.DEFAULT
                return;
            }
            bucketLayout = buckInfo.getBucketLayout();
        } catch (IOException e) {
            LOG.error("Failed to get bucket for the key: " + buckKey, e);
        }
    } catch (OMException ome) {
        LOG.error("Invalid Path: " + getPath(), ome);
        // defaulting to BucketLayout.DEFAULT
        return;
    }
}
Also used : OmBucketInfo(org.apache.hadoop.ozone.om.helpers.OmBucketInfo) ObjectParser(org.apache.hadoop.ozone.om.request.util.ObjectParser) IOException(java.io.IOException) OMException(org.apache.hadoop.ozone.om.exceptions.OMException)

Example 2 with ObjectParser

use of org.apache.hadoop.ozone.om.request.util.ObjectParser in project ozone by apache.

the class OMKeyAclRequest method validateAndUpdateCache.

@Override
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
    OmKeyInfo omKeyInfo = 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;
    boolean operationResult = false;
    Result result = null;
    try {
        ObjectParser objectParser = new ObjectParser(getPath(), ObjectType.KEY);
        volume = objectParser.getVolume();
        bucket = objectParser.getBucket();
        key = objectParser.getKey();
        // check Acl
        if (ozoneManager.getAclsEnabled()) {
            checkAcls(ozoneManager, OzoneObj.ResourceType.VOLUME, OzoneObj.StoreType.OZONE, IAccessAuthorizer.ACLType.WRITE_ACL, volume, bucket, key);
        }
        lockAcquired = omMetadataManager.getLock().acquireWriteLock(BUCKET_LOCK, volume, bucket);
        String dbKey = omMetadataManager.getOzoneKey(volume, bucket, key);
        omKeyInfo = omMetadataManager.getKeyTable(getBucketLayout()).get(dbKey);
        if (omKeyInfo == null) {
            throw new OMException(OMException.ResultCodes.KEY_NOT_FOUND);
        }
        operationResult = apply(omKeyInfo, trxnLogIndex);
        omKeyInfo.setUpdateID(trxnLogIndex, ozoneManager.isRatisEnabled());
        // Update the modification time when updating ACLs of Key.
        long modificationTime = omKeyInfo.getModificationTime();
        if (getOmRequest().getAddAclRequest().hasObj() && operationResult) {
            modificationTime = getOmRequest().getAddAclRequest().getModificationTime();
        } else if (getOmRequest().getSetAclRequest().hasObj() && operationResult) {
            modificationTime = getOmRequest().getSetAclRequest().getModificationTime();
        } else if (getOmRequest().getRemoveAclRequest().hasObj() && operationResult) {
            modificationTime = getOmRequest().getRemoveAclRequest().getModificationTime();
        }
        omKeyInfo.setModificationTime(modificationTime);
        // update cache.
        omMetadataManager.getKeyTable(getBucketLayout()).addCacheEntry(new CacheKey<>(dbKey), new CacheValue<>(Optional.of(omKeyInfo), trxnLogIndex));
        omClientResponse = onSuccess(omResponse, omKeyInfo, operationResult);
        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(BUCKET_LOCK, volume, bucket);
        }
    }
    OzoneObj obj = getObject();
    Map<String, String> auditMap = obj.toAuditMap();
    onComplete(result, operationResult, exception, 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) OMClientResponse(org.apache.hadoop.ozone.om.response.OMClientResponse) IOException(java.io.IOException) OMResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse) OmKeyInfo(org.apache.hadoop.ozone.om.helpers.OmKeyInfo) OMMetadataManager(org.apache.hadoop.ozone.om.OMMetadataManager) OMException(org.apache.hadoop.ozone.om.exceptions.OMException)

Example 3 with ObjectParser

use of org.apache.hadoop.ozone.om.request.util.ObjectParser in project ozone by apache.

the class OMBucketAclRequest method validateAndUpdateCache.

@Override
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, long transactionLogIndex, OzoneManagerDoubleBufferHelper ozoneManagerDoubleBufferHelper) {
    // protobuf guarantees acls are non-null.
    List<OzoneAcl> ozoneAcls = getAcls();
    OMMetrics omMetrics = ozoneManager.getMetrics();
    omMetrics.incNumBucketUpdates();
    OmBucketInfo omBucketInfo = null;
    OMResponse.Builder omResponse = onInit();
    OMClientResponse omClientResponse = null;
    IOException exception = null;
    OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
    boolean lockAcquired = false;
    String volume = null;
    String bucket = null;
    boolean operationResult = false;
    try {
        ObjectParser objectParser = new ObjectParser(getPath(), ObjectType.BUCKET);
        volume = objectParser.getVolume();
        bucket = objectParser.getBucket();
        // check Acl
        if (ozoneManager.getAclsEnabled()) {
            checkAcls(ozoneManager, OzoneObj.ResourceType.VOLUME, OzoneObj.StoreType.OZONE, IAccessAuthorizer.ACLType.WRITE_ACL, volume, null, null);
        }
        lockAcquired = omMetadataManager.getLock().acquireWriteLock(BUCKET_LOCK, volume, bucket);
        String dbBucketKey = omMetadataManager.getBucketKey(volume, bucket);
        omBucketInfo = omMetadataManager.getBucketTable().get(dbBucketKey);
        if (omBucketInfo == null) {
            throw new OMException(OMException.ResultCodes.BUCKET_NOT_FOUND);
        }
        operationResult = omBucketAclOp.apply(ozoneAcls, omBucketInfo);
        omBucketInfo.setUpdateID(transactionLogIndex, ozoneManager.isRatisEnabled());
        if (operationResult) {
            // Update the modification time when updating ACLs of Bucket.
            long modificationTime = omBucketInfo.getModificationTime();
            if (getOmRequest().getAddAclRequest().hasObj()) {
                modificationTime = getOmRequest().getAddAclRequest().getModificationTime();
            } else if (getOmRequest().getSetAclRequest().hasObj()) {
                modificationTime = getOmRequest().getSetAclRequest().getModificationTime();
            } else if (getOmRequest().getRemoveAclRequest().hasObj()) {
                modificationTime = getOmRequest().getRemoveAclRequest().getModificationTime();
            }
            omBucketInfo = omBucketInfo.toBuilder().setModificationTime(modificationTime).build();
            // update cache.
            omMetadataManager.getBucketTable().addCacheEntry(new CacheKey<>(dbBucketKey), new CacheValue<>(Optional.of(omBucketInfo), transactionLogIndex));
        }
        omClientResponse = onSuccess(omResponse, omBucketInfo, operationResult);
    } catch (IOException ex) {
        exception = ex;
        omClientResponse = onFailure(omResponse, ex);
    } finally {
        addResponseToDoubleBuffer(transactionLogIndex, omClientResponse, ozoneManagerDoubleBufferHelper);
        if (lockAcquired) {
            omMetadataManager.getLock().releaseWriteLock(BUCKET_LOCK, volume, bucket);
        }
    }
    OzoneObj obj = getObject();
    Map<String, String> auditMap = obj.toAuditMap();
    if (ozoneAcls != null) {
        auditMap.put(OzoneConsts.ACL, ozoneAcls.toString());
    }
    onComplete(operationResult, exception, ozoneManager.getMetrics(), ozoneManager.getAuditLogger(), auditMap);
    return omClientResponse;
}
Also used : OmBucketInfo(org.apache.hadoop.ozone.om.helpers.OmBucketInfo) ObjectParser(org.apache.hadoop.ozone.om.request.util.ObjectParser) OzoneObj(org.apache.hadoop.ozone.security.acl.OzoneObj) OMClientResponse(org.apache.hadoop.ozone.om.response.OMClientResponse) IOException(java.io.IOException) OMMetrics(org.apache.hadoop.ozone.om.OMMetrics) OMResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse) OzoneAcl(org.apache.hadoop.ozone.OzoneAcl) OMMetadataManager(org.apache.hadoop.ozone.om.OMMetadataManager) OMException(org.apache.hadoop.ozone.om.exceptions.OMException)

Example 4 with ObjectParser

use of org.apache.hadoop.ozone.om.request.util.ObjectParser in project ozone by apache.

the class OMKeyAclRequestWithFSO method validateAndUpdateCache.

@Override
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
    OmKeyInfo omKeyInfo = null;
    OzoneManagerProtocolProtos.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;
    boolean operationResult = false;
    Result result = null;
    try {
        ObjectParser objectParser = new ObjectParser(getPath(), OzoneManagerProtocolProtos.OzoneObj.ObjectType.KEY);
        volume = objectParser.getVolume();
        bucket = objectParser.getBucket();
        key = objectParser.getKey();
        // check Acl
        if (ozoneManager.getAclsEnabled()) {
            checkAcls(ozoneManager, OzoneObj.ResourceType.VOLUME, OzoneObj.StoreType.OZONE, IAccessAuthorizer.ACLType.WRITE_ACL, volume, bucket, key);
        }
        lockAcquired = omMetadataManager.getLock().acquireWriteLock(BUCKET_LOCK, volume, bucket);
        OzoneFileStatus keyStatus = OMFileRequest.getOMKeyInfoIfExists(omMetadataManager, volume, bucket, key, 0);
        if (keyStatus == null) {
            throw new OMException("Key not found. Key:" + key, KEY_NOT_FOUND);
        }
        omKeyInfo = keyStatus.getKeyInfo();
        String dbKey = omKeyInfo.getPath();
        boolean isDirectory = keyStatus.isDirectory();
        operationResult = apply(omKeyInfo, trxnLogIndex);
        omKeyInfo.setUpdateID(trxnLogIndex, ozoneManager.isRatisEnabled());
        // Update the modification time when updating ACLs of Key.
        long modificationTime = omKeyInfo.getModificationTime();
        if (getOmRequest().getAddAclRequest().hasObj() && operationResult) {
            modificationTime = getOmRequest().getAddAclRequest().getModificationTime();
        } else if (getOmRequest().getSetAclRequest().hasObj()) {
            modificationTime = getOmRequest().getSetAclRequest().getModificationTime();
        } else if (getOmRequest().getRemoveAclRequest().hasObj() && operationResult) {
            modificationTime = getOmRequest().getRemoveAclRequest().getModificationTime();
        }
        omKeyInfo.setModificationTime(modificationTime);
        // update cache.
        if (isDirectory) {
            Table<String, OmDirectoryInfo> dirTable = omMetadataManager.getDirectoryTable();
            dirTable.addCacheEntry(new CacheKey<>(dbKey), new CacheValue<>(Optional.of(OMFileRequest.getDirectoryInfo(omKeyInfo)), trxnLogIndex));
        } else {
            omMetadataManager.getKeyTable(getBucketLayout()).addCacheEntry(new CacheKey<>(dbKey), new CacheValue<>(Optional.of(omKeyInfo), trxnLogIndex));
        }
        omClientResponse = onSuccess(omResponse, omKeyInfo, operationResult, isDirectory);
        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(BUCKET_LOCK, volume, bucket);
        }
    }
    OzoneObj obj = getObject();
    Map<String, String> auditMap = obj.toAuditMap();
    onComplete(result, operationResult, exception, 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) OMClientResponse(org.apache.hadoop.ozone.om.response.OMClientResponse) IOException(java.io.IOException) OmKeyInfo(org.apache.hadoop.ozone.om.helpers.OmKeyInfo) OMMetadataManager(org.apache.hadoop.ozone.om.OMMetadataManager) OmDirectoryInfo(org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo) OzoneFileStatus(org.apache.hadoop.ozone.om.helpers.OzoneFileStatus) OMException(org.apache.hadoop.ozone.om.exceptions.OMException)

Example 5 with ObjectParser

use of org.apache.hadoop.ozone.om.request.util.ObjectParser 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)5 ObjectParser (org.apache.hadoop.ozone.om.request.util.ObjectParser)5 OMMetadataManager (org.apache.hadoop.ozone.om.OMMetadataManager)4 OMException (org.apache.hadoop.ozone.om.exceptions.OMException)4 OMClientResponse (org.apache.hadoop.ozone.om.response.OMClientResponse)4 OzoneObj (org.apache.hadoop.ozone.security.acl.OzoneObj)4 OMResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse)3 OmBucketInfo (org.apache.hadoop.ozone.om.helpers.OmBucketInfo)2 OmKeyInfo (org.apache.hadoop.ozone.om.helpers.OmKeyInfo)2 OzoneAcl (org.apache.hadoop.ozone.OzoneAcl)1 OMMetrics (org.apache.hadoop.ozone.om.OMMetrics)1 PrefixManagerImpl (org.apache.hadoop.ozone.om.PrefixManagerImpl)1 OMPrefixAclOpResult (org.apache.hadoop.ozone.om.PrefixManagerImpl.OMPrefixAclOpResult)1 OmDirectoryInfo (org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo)1 OmPrefixInfo (org.apache.hadoop.ozone.om.helpers.OmPrefixInfo)1 OzoneFileStatus (org.apache.hadoop.ozone.om.helpers.OzoneFileStatus)1