use of org.apache.hadoop.ozone.om.helpers.OmPrefixInfo in project ozone by apache.
the class PrefixManagerImpl method setAcl.
/**
* Acls to be set for given Ozone object. This operations reset ACL for given
* object to list of ACLs provided in argument.
*
* @param obj Ozone object.
* @param acls List of acls.
* @throws IOException if there is error.
*/
@Override
public boolean setAcl(OzoneObj obj, List<OzoneAcl> acls) throws IOException {
validateOzoneObj(obj);
String prefixPath = obj.getPath();
metadataManager.getLock().acquireWriteLock(PREFIX_LOCK, prefixPath);
try {
OmPrefixInfo prefixInfo = metadataManager.getPrefixTable().get(prefixPath);
OMPrefixAclOpResult omPrefixAclOpResult = setAcl(obj, acls, prefixInfo, 0L);
return omPrefixAclOpResult.isSuccess();
} catch (IOException ex) {
if (!(ex instanceof OMException)) {
LOG.error("Set prefix acl operation failed for prefix path:{} acls:{}", prefixPath, acls, ex);
}
throw ex;
} finally {
metadataManager.getLock().releaseWriteLock(PREFIX_LOCK, prefixPath);
}
}
use of org.apache.hadoop.ozone.om.helpers.OmPrefixInfo in project ozone by apache.
the class PrefixManagerImpl method inheritParentAcl.
private void inheritParentAcl(OzoneObj ozoneObj, OmPrefixInfo prefixInfo) throws IOException {
List<OzoneAcl> aclsToBeSet = prefixInfo.getAcls();
// Inherit DEFAULT acls from prefix.
boolean prefixParentFound = false;
List<OmPrefixInfo> prefixList = getLongestPrefixPathHelper(prefixTree.getLongestPrefix(ozoneObj.getPath()));
if (prefixList.size() > 0) {
// Add all acls from direct parent to key.
OmPrefixInfo parentPrefixInfo = prefixList.get(prefixList.size() - 1);
if (parentPrefixInfo != null) {
prefixParentFound = OzoneAclUtil.inheritDefaultAcls(aclsToBeSet, parentPrefixInfo.getAcls());
}
}
// If no parent prefix is found inherit DEFAULT acls from bucket.
if (!prefixParentFound) {
String bucketKey = metadataManager.getBucketKey(ozoneObj.getVolumeName(), ozoneObj.getBucketName());
OmBucketInfo bucketInfo = metadataManager.getBucketTable().get(bucketKey);
if (bucketInfo != null) {
OzoneAclUtil.inheritDefaultAcls(aclsToBeSet, bucketInfo.getAcls());
}
}
}
use of org.apache.hadoop.ozone.om.helpers.OmPrefixInfo in project ozone by apache.
the class PrefixManagerImpl method addAcl.
/**
* Add acl for Ozone object. Return true if acl is added successfully else
* false.
*
* @param obj Ozone object for which acl should be added.
* @param acl ozone acl to be added.
* @throws IOException if there is error.
*/
@Override
public boolean addAcl(OzoneObj obj, OzoneAcl acl) throws IOException {
validateOzoneObj(obj);
String prefixPath = obj.getPath();
metadataManager.getLock().acquireWriteLock(PREFIX_LOCK, prefixPath);
try {
OmPrefixInfo prefixInfo = metadataManager.getPrefixTable().get(prefixPath);
OMPrefixAclOpResult omPrefixAclOpResult = addAcl(obj, acl, prefixInfo, 0L);
return omPrefixAclOpResult.isSuccess();
} catch (IOException ex) {
if (!(ex instanceof OMException)) {
LOG.error("Add acl operation failed for prefix path:{} acl:{}", prefixPath, acl, ex);
}
throw ex;
} finally {
metadataManager.getLock().releaseWriteLock(PREFIX_LOCK, prefixPath);
}
}
use of org.apache.hadoop.ozone.om.helpers.OmPrefixInfo in project ozone by apache.
the class PrefixManagerImpl method removeAcl.
/**
* Remove acl for Ozone object. Return true if acl is removed successfully
* else false.
*
* @param obj Ozone object.
* @param acl Ozone acl to be removed.
* @throws IOException if there is error.
*/
@Override
public boolean removeAcl(OzoneObj obj, OzoneAcl acl) throws IOException {
validateOzoneObj(obj);
String prefixPath = obj.getPath();
metadataManager.getLock().acquireWriteLock(PREFIX_LOCK, prefixPath);
try {
OmPrefixInfo prefixInfo = metadataManager.getPrefixTable().get(prefixPath);
OMPrefixAclOpResult omPrefixAclOpResult = removeAcl(obj, acl, prefixInfo);
if (!omPrefixAclOpResult.isSuccess()) {
if (LOG.isDebugEnabled()) {
LOG.debug("acl {} does not exist for prefix path {} ", acl, prefixPath);
}
return false;
}
return omPrefixAclOpResult.isSuccess();
} catch (IOException ex) {
if (!(ex instanceof OMException)) {
LOG.error("Remove prefix acl operation failed for prefix path:{}" + " acl:{}", prefixPath, acl, ex);
}
throw ex;
} finally {
metadataManager.getLock().releaseWriteLock(PREFIX_LOCK, prefixPath);
}
}
use of org.apache.hadoop.ozone.om.helpers.OmPrefixInfo in project ozone by apache.
the class TestKeyManagerImpl method testLongestPrefixPath.
@Test
public void testLongestPrefixPath() throws IOException {
String volumeName = "vol1";
String bucketName = "bucket1";
String prefix1 = "pf1/pf11/pf111/pf1111/";
String file1 = "pf1/pf11/file1";
String file2 = "pf1/pf11/pf111/pf1111/file2";
OzoneObj ozPrefix1 = new OzoneObjInfo.Builder().setVolumeName(volumeName).setBucketName(bucketName).setPrefixName(prefix1).setResType(OzoneObj.ResourceType.PREFIX).setStoreType(OzoneObj.StoreType.OZONE).build();
OzoneAcl ozAcl1 = new OzoneAcl(ACLIdentityType.USER, "user1", ACLType.READ, ACCESS);
prefixManager.addAcl(ozPrefix1, ozAcl1);
OzoneObj ozFile1 = new OzoneObjInfo.Builder().setVolumeName(volumeName).setBucketName(bucketName).setKeyName(file1).setResType(OzoneObj.ResourceType.KEY).setStoreType(OzoneObj.StoreType.OZONE).build();
List<OmPrefixInfo> prefixInfos = prefixManager.getLongestPrefixPath(ozFile1.getPath());
Assert.assertEquals(5, prefixInfos.size());
OzoneObj ozFile2 = new OzoneObjInfo.Builder().setVolumeName(volumeName).setBucketName(bucketName).setPrefixName(file2).setResType(OzoneObj.ResourceType.KEY).setStoreType(OzoneObj.StoreType.OZONE).build();
prefixInfos = prefixManager.getLongestPrefixPath(ozFile2.getPath());
Assert.assertEquals(7, prefixInfos.size());
// Only the last node has acl on it
Assert.assertEquals(ozAcl1, prefixInfos.get(6).getAcls().get(0));
// All other nodes don't have acl value associate with it
for (int i = 0; i < 6; i++) {
Assert.assertEquals(null, prefixInfos.get(i));
}
}
Aggregations