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());
}
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;
}
Aggregations