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