Search in sources :

Example 1 with PrefixManagerImpl

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

the class TestOMPrefixAclRequest method testAclRequest.

@Test
public void testAclRequest() throws Exception {
    PrefixManager prefixManager = new PrefixManagerImpl(ozoneManager.getMetadataManager(), true);
    when(ozoneManager.getPrefixManager()).thenReturn(prefixManager);
    // Manually add volume, bucket and key to DB
    OMRequestTestUtils.addVolumeAndBucketToDB(volumeName, bucketName, omMetadataManager);
    OMRequestTestUtils.addKeyToTable(false, false, volumeName, bucketName, keyName, clientID, replicationType, replicationFactor, 1L, omMetadataManager);
    OzoneAcl acl = OzoneAcl.parseAcl("user:bilbo:rwdlncxy[ACCESS]");
    // Create KeyAddAcl request
    OMRequest originalRequest = createAddAclkeyRequest(acl);
    OMPrefixAddAclRequest omKeyPrefixAclRequest = new OMPrefixAddAclRequest(originalRequest);
    omKeyPrefixAclRequest.preExecute(ozoneManager);
    // Execute original request
    OMClientResponse omClientResponse = omKeyPrefixAclRequest.validateAndUpdateCache(ozoneManager, 2, ozoneManagerDoubleBufferHelper);
    Assert.assertEquals(OzoneManagerProtocolProtos.Status.OK, omClientResponse.getOMResponse().getStatus());
}
Also used : PrefixManager(org.apache.hadoop.ozone.om.PrefixManager) OMRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest) PrefixManagerImpl(org.apache.hadoop.ozone.om.PrefixManagerImpl) OzoneAcl(org.apache.hadoop.ozone.OzoneAcl) OMClientResponse(org.apache.hadoop.ozone.om.response.OMClientResponse) OMPrefixAddAclRequest(org.apache.hadoop.ozone.om.request.key.acl.prefix.OMPrefixAddAclRequest) Test(org.junit.Test)

Example 2 with PrefixManagerImpl

use of org.apache.hadoop.ozone.om.PrefixManagerImpl 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

PrefixManagerImpl (org.apache.hadoop.ozone.om.PrefixManagerImpl)2 OMClientResponse (org.apache.hadoop.ozone.om.response.OMClientResponse)2 IOException (java.io.IOException)1 OzoneAcl (org.apache.hadoop.ozone.OzoneAcl)1 OMMetadataManager (org.apache.hadoop.ozone.om.OMMetadataManager)1 PrefixManager (org.apache.hadoop.ozone.om.PrefixManager)1 OMPrefixAclOpResult (org.apache.hadoop.ozone.om.PrefixManagerImpl.OMPrefixAclOpResult)1 OmPrefixInfo (org.apache.hadoop.ozone.om.helpers.OmPrefixInfo)1 OMPrefixAddAclRequest (org.apache.hadoop.ozone.om.request.key.acl.prefix.OMPrefixAddAclRequest)1 ObjectParser (org.apache.hadoop.ozone.om.request.util.ObjectParser)1 OMRequest (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest)1 OMResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse)1 OzoneObj (org.apache.hadoop.ozone.security.acl.OzoneObj)1 Test (org.junit.Test)1