use of org.apache.hadoop.ozone.om.exceptions.OMException in project ozone by apache.
the class OzoneBucketStub method completeMultipartUpload.
@Override
public OmMultipartUploadCompleteInfo completeMultipartUpload(String key, String uploadID, Map<Integer, String> partsMap) throws IOException {
if (multipartUploadIdMap.get(key) == null) {
throw new OMException(ResultCodes.NO_SUCH_MULTIPART_UPLOAD_ERROR);
} else {
final Map<Integer, Part> partsList = partList.get(key);
int count = 1;
ByteArrayOutputStream output = new ByteArrayOutputStream();
int prevPartNumber = 0;
for (Map.Entry<Integer, String> part : partsMap.entrySet()) {
int currentPartNumber = part.getKey();
if (currentPartNumber <= prevPartNumber) {
throw new OMException(OMException.ResultCodes.INVALID_PART_ORDER);
}
prevPartNumber = currentPartNumber;
}
for (Map.Entry<Integer, String> part : partsMap.entrySet()) {
Part recordedPart = partsList.get(part.getKey());
if (recordedPart == null || !recordedPart.getPartName().equals(part.getValue())) {
throw new OMException(ResultCodes.INVALID_PART);
} else {
output.write(recordedPart.getContent());
}
keyContents.put(key, output.toByteArray());
}
}
return new OmMultipartUploadCompleteInfo(getVolumeName(), getName(), key, DigestUtils.sha256Hex(key));
}
use of org.apache.hadoop.ozone.om.exceptions.OMException in project ozone by apache.
the class OzoneBucketStub method listParts.
@Override
public OzoneMultipartUploadPartListParts listParts(String key, String uploadID, int partNumberMarker, int maxParts) throws IOException {
if (multipartUploadIdMap.get(key) == null) {
throw new OMException(ResultCodes.NO_SUCH_MULTIPART_UPLOAD_ERROR);
}
List<PartInfo> partInfoList = new ArrayList<>();
if (partList.get(key) == null) {
return new OzoneMultipartUploadPartListParts(ReplicationType.RATIS, ReplicationFactor.ONE, 0, false);
} else {
Map<Integer, Part> partMap = partList.get(key);
Iterator<Map.Entry<Integer, Part>> partIterator = partMap.entrySet().iterator();
int count = 0;
int nextPartNumberMarker = 0;
boolean truncated = false;
while (count < maxParts && partIterator.hasNext()) {
Map.Entry<Integer, Part> partEntry = partIterator.next();
nextPartNumberMarker = partEntry.getKey();
if (partEntry.getKey() > partNumberMarker) {
PartInfo partInfo = new PartInfo(partEntry.getKey(), partEntry.getValue().getPartName(), partEntry.getValue().getContent().length, Time.now());
partInfoList.add(partInfo);
count++;
}
}
if (partIterator.hasNext()) {
truncated = true;
} else {
truncated = false;
nextPartNumberMarker = 0;
}
OzoneMultipartUploadPartListParts ozoneMultipartUploadPartListParts = new OzoneMultipartUploadPartListParts(ReplicationType.RATIS, ReplicationFactor.ONE, nextPartNumberMarker, truncated);
ozoneMultipartUploadPartListParts.addAllParts(partInfoList);
return ozoneMultipartUploadPartListParts;
}
}
use of org.apache.hadoop.ozone.om.exceptions.OMException in project ozone by apache.
the class OMBucketDeleteRequest method validateAndUpdateCache.
@Override
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, long transactionLogIndex, OzoneManagerDoubleBufferHelper ozoneManagerDoubleBufferHelper) {
OMMetrics omMetrics = ozoneManager.getMetrics();
omMetrics.incNumBucketDeletes();
OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
OMRequest omRequest = getOmRequest();
DeleteBucketRequest deleteBucketRequest = omRequest.getDeleteBucketRequest();
String volumeName = deleteBucketRequest.getVolumeName();
String bucketName = deleteBucketRequest.getBucketName();
// Generate end user response
OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(getOmRequest());
AuditLogger auditLogger = ozoneManager.getAuditLogger();
Map<String, String> auditMap = buildVolumeAuditMap(volumeName);
auditMap.put(OzoneConsts.BUCKET, bucketName);
OzoneManagerProtocolProtos.UserInfo userInfo = getOmRequest().getUserInfo();
IOException exception = null;
boolean acquiredBucketLock = false, acquiredVolumeLock = false;
boolean success = true;
OMClientResponse omClientResponse = null;
try {
// check Acl
if (ozoneManager.getAclsEnabled()) {
checkAcls(ozoneManager, OzoneObj.ResourceType.BUCKET, OzoneObj.StoreType.OZONE, IAccessAuthorizer.ACLType.DELETE, volumeName, bucketName, null);
}
// acquire lock
acquiredVolumeLock = omMetadataManager.getLock().acquireReadLock(VOLUME_LOCK, volumeName);
acquiredBucketLock = omMetadataManager.getLock().acquireWriteLock(BUCKET_LOCK, volumeName, bucketName);
// No need to check volume exists here, as bucket cannot be created
// with out volume creation. Check if bucket exists
String bucketKey = omMetadataManager.getBucketKey(volumeName, bucketName);
OmBucketInfo omBucketInfo = omMetadataManager.getBucketTable().get(bucketKey);
if (omBucketInfo == null) {
LOG.debug("bucket: {} not found ", bucketName);
throw new OMException("Bucket not exists", BUCKET_NOT_FOUND);
}
// Check if bucket is empty
if (!omMetadataManager.isBucketEmpty(volumeName, bucketName)) {
LOG.debug("bucket: {} is not empty ", bucketName);
throw new OMException("Bucket is not empty", OMException.ResultCodes.BUCKET_NOT_EMPTY);
}
if (omBucketInfo.getBucketLayout().isFileSystemOptimized()) {
omMetrics.incNumFSOBucketDeletes();
}
omMetrics.decNumBuckets();
// Update table cache.
omMetadataManager.getBucketTable().addCacheEntry(new CacheKey<>(bucketKey), new CacheValue<>(Optional.absent(), transactionLogIndex));
omResponse.setDeleteBucketResponse(DeleteBucketResponse.newBuilder().build());
// update used namespace for volume
String volumeKey = omMetadataManager.getVolumeKey(volumeName);
OmVolumeArgs omVolumeArgs = omMetadataManager.getVolumeTable().getReadCopy(volumeKey);
if (omVolumeArgs == null) {
throw new OMException("Volume " + volumeName + " is not found", OMException.ResultCodes.VOLUME_NOT_FOUND);
}
omVolumeArgs.incrUsedNamespace(-1L);
// Update table cache.
omMetadataManager.getVolumeTable().addCacheEntry(new CacheKey<>(volumeKey), new CacheValue<>(Optional.of(omVolumeArgs), transactionLogIndex));
// Add to double buffer.
omClientResponse = new OMBucketDeleteResponse(omResponse.build(), volumeName, bucketName, omVolumeArgs.copyObject());
} catch (IOException ex) {
success = false;
exception = ex;
omClientResponse = new OMBucketDeleteResponse(createErrorOMResponse(omResponse, exception));
} finally {
addResponseToDoubleBuffer(transactionLogIndex, omClientResponse, ozoneManagerDoubleBufferHelper);
if (acquiredBucketLock) {
omMetadataManager.getLock().releaseWriteLock(BUCKET_LOCK, volumeName, bucketName);
}
if (acquiredVolumeLock) {
omMetadataManager.getLock().releaseReadLock(VOLUME_LOCK, volumeName);
}
}
// Performing audit logging outside of the lock.
auditLog(auditLogger, buildAuditMessage(OMAction.DELETE_BUCKET, auditMap, exception, userInfo));
// return response.
if (success) {
LOG.debug("Deleted bucket:{} in volume:{}", bucketName, volumeName);
return omClientResponse;
} else {
omMetrics.incNumBucketDeleteFails();
LOG.error("Delete bucket failed for bucket:{} in volume:{}", bucketName, volumeName, exception);
return omClientResponse;
}
}
use of org.apache.hadoop.ozone.om.exceptions.OMException in project ozone by apache.
the class OMBucketSetOwnerRequest method validateAndUpdateCache.
@Override
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, long transactionLogIndex, OzoneManagerDoubleBufferHelper ozoneManagerDoubleBufferHelper) {
SetBucketPropertyRequest setBucketPropertyRequest = getOmRequest().getSetBucketPropertyRequest();
Preconditions.checkNotNull(setBucketPropertyRequest);
OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(getOmRequest());
if (!setBucketPropertyRequest.getBucketArgs().hasOwnerName()) {
omResponse.setStatus(OzoneManagerProtocolProtos.Status.INVALID_REQUEST).setSuccess(false);
return new OMBucketSetOwnerResponse(omResponse.build());
}
OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
OMMetrics omMetrics = ozoneManager.getMetrics();
omMetrics.incNumBucketUpdates();
BucketArgs bucketArgs = setBucketPropertyRequest.getBucketArgs();
OmBucketArgs omBucketArgs = OmBucketArgs.getFromProtobuf(bucketArgs);
String volumeName = bucketArgs.getVolumeName();
String bucketName = bucketArgs.getBucketName();
String newOwner = bucketArgs.getOwnerName();
String oldOwner = null;
AuditLogger auditLogger = ozoneManager.getAuditLogger();
OzoneManagerProtocolProtos.UserInfo userInfo = getOmRequest().getUserInfo();
IOException exception = null;
boolean acquiredBucketLock = false, success = true;
OMClientResponse omClientResponse = null;
try {
// check Acl
if (ozoneManager.getAclsEnabled()) {
checkAcls(ozoneManager, OzoneObj.ResourceType.BUCKET, OzoneObj.StoreType.OZONE, IAccessAuthorizer.ACLType.WRITE_ACL, volumeName, bucketName, null);
}
// acquire lock.
acquiredBucketLock = omMetadataManager.getLock().acquireWriteLock(BUCKET_LOCK, volumeName, bucketName);
String bucketKey = omMetadataManager.getBucketKey(volumeName, bucketName);
OmBucketInfo omBucketInfo = omMetadataManager.getBucketTable().get(bucketKey);
// Check if bucket exist
if (omBucketInfo == null) {
LOG.debug("Bucket: {} not found ", bucketName);
throw new OMException("Bucket doesnt exist", OMException.ResultCodes.BUCKET_NOT_FOUND);
}
oldOwner = omBucketInfo.getOwner();
if (oldOwner.equals(newOwner)) {
LOG.warn("Bucket '{}/{}' owner is already user '{}'.", volumeName, bucketName, oldOwner);
omResponse.setStatus(OzoneManagerProtocolProtos.Status.OK).setMessage("Bucket '" + volumeName + "/" + bucketName + "' owner is already '" + newOwner + "'.").setSuccess(false);
omResponse.setSetBucketPropertyResponse(SetBucketPropertyResponse.newBuilder().setResponse(false).build());
omClientResponse = new OMBucketSetOwnerResponse(omResponse.build());
return omClientResponse;
}
omBucketInfo.setOwner(newOwner);
LOG.debug("Updating bucket owner to {} for bucket: {} in volume: {}", newOwner, bucketName, volumeName);
omBucketInfo.setModificationTime(setBucketPropertyRequest.getModificationTime());
// Set the updateID to current transaction log index
omBucketInfo.setUpdateID(transactionLogIndex, ozoneManager.isRatisEnabled());
// Update table cache.
omMetadataManager.getBucketTable().addCacheEntry(new CacheKey<>(bucketKey), new CacheValue<>(Optional.of(omBucketInfo), transactionLogIndex));
omResponse.setSetBucketPropertyResponse(SetBucketPropertyResponse.newBuilder().setResponse(true).build());
omClientResponse = new OMBucketSetOwnerResponse(omResponse.build(), omBucketInfo);
} catch (IOException ex) {
success = false;
exception = ex;
omClientResponse = new OMBucketSetOwnerResponse(createErrorOMResponse(omResponse, exception));
} finally {
addResponseToDoubleBuffer(transactionLogIndex, omClientResponse, ozoneManagerDoubleBufferHelper);
if (acquiredBucketLock) {
omMetadataManager.getLock().releaseWriteLock(BUCKET_LOCK, volumeName, bucketName);
}
}
// Performing audit logging outside of the lock.
auditLog(auditLogger, buildAuditMessage(OMAction.SET_OWNER, omBucketArgs.toAuditMap(), exception, userInfo));
// return response.
if (success) {
LOG.debug("Successfully changed Owner of Bucket {}/{} from {} -> {}", volumeName, bucketName, oldOwner, newOwner);
return omClientResponse;
} else {
LOG.error("Setting Owner failed for bucket:{} in volume:{}", bucketName, volumeName, exception);
omMetrics.incNumBucketUpdateFails();
return omClientResponse;
}
}
use of org.apache.hadoop.ozone.om.exceptions.OMException in project ozone by apache.
the class OMBucketSetPropertyRequest method validateAndUpdateCache.
@Override
@SuppressWarnings("methodlength")
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, long transactionLogIndex, OzoneManagerDoubleBufferHelper ozoneManagerDoubleBufferHelper) {
SetBucketPropertyRequest setBucketPropertyRequest = getOmRequest().getSetBucketPropertyRequest();
Preconditions.checkNotNull(setBucketPropertyRequest);
OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
OMMetrics omMetrics = ozoneManager.getMetrics();
omMetrics.incNumBucketUpdates();
BucketArgs bucketArgs = setBucketPropertyRequest.getBucketArgs();
OmBucketArgs omBucketArgs = OmBucketArgs.getFromProtobuf(bucketArgs);
String volumeName = bucketArgs.getVolumeName();
String bucketName = bucketArgs.getBucketName();
OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(getOmRequest());
OmBucketInfo omBucketInfo = null;
AuditLogger auditLogger = ozoneManager.getAuditLogger();
OzoneManagerProtocolProtos.UserInfo userInfo = getOmRequest().getUserInfo();
IOException exception = null;
boolean acquiredBucketLock = false, success = true;
OMClientResponse omClientResponse = null;
try {
// check Acl
if (ozoneManager.getAclsEnabled()) {
checkAcls(ozoneManager, OzoneObj.ResourceType.BUCKET, OzoneObj.StoreType.OZONE, IAccessAuthorizer.ACLType.WRITE, volumeName, bucketName, null);
}
// acquire lock.
acquiredBucketLock = omMetadataManager.getLock().acquireWriteLock(BUCKET_LOCK, volumeName, bucketName);
String bucketKey = omMetadataManager.getBucketKey(volumeName, bucketName);
OmBucketInfo dbBucketInfo = omMetadataManager.getBucketTable().get(bucketKey);
// Check if bucket exist
if (dbBucketInfo == null) {
LOG.debug("bucket: {} not found ", bucketName);
throw new OMException("Bucket doesn't exist", OMException.ResultCodes.BUCKET_NOT_FOUND);
}
OmBucketInfo.Builder bucketInfoBuilder = OmBucketInfo.newBuilder();
bucketInfoBuilder.setVolumeName(dbBucketInfo.getVolumeName()).setBucketName(dbBucketInfo.getBucketName()).setObjectID(dbBucketInfo.getObjectID()).setUpdateID(transactionLogIndex);
bucketInfoBuilder.addAllMetadata(KeyValueUtil.getFromProtobuf(bucketArgs.getMetadataList()));
// Check StorageType to update
StorageType storageType = omBucketArgs.getStorageType();
if (storageType != null) {
bucketInfoBuilder.setStorageType(storageType);
LOG.debug("Updating bucket storage type for bucket: {} in volume: {}", bucketName, volumeName);
} else {
bucketInfoBuilder.setStorageType(dbBucketInfo.getStorageType());
}
// Check Versioning to update
Boolean versioning = omBucketArgs.getIsVersionEnabled();
if (versioning != null) {
bucketInfoBuilder.setIsVersionEnabled(versioning);
LOG.debug("Updating bucket versioning for bucket: {} in volume: {}", bucketName, volumeName);
} else {
bucketInfoBuilder.setIsVersionEnabled(dbBucketInfo.getIsVersionEnabled());
}
// Check quotaInBytes and quotaInNamespace to update
String volumeKey = omMetadataManager.getVolumeKey(volumeName);
OmVolumeArgs omVolumeArgs = omMetadataManager.getVolumeTable().get(volumeKey);
if (checkQuotaBytesValid(omMetadataManager, omVolumeArgs, omBucketArgs)) {
bucketInfoBuilder.setQuotaInBytes(omBucketArgs.getQuotaInBytes());
} else {
bucketInfoBuilder.setQuotaInBytes(dbBucketInfo.getQuotaInBytes());
}
if (checkQuotaNamespaceValid(omVolumeArgs, omBucketArgs)) {
bucketInfoBuilder.setQuotaInNamespace(omBucketArgs.getQuotaInNamespace());
} else {
bucketInfoBuilder.setQuotaInNamespace(dbBucketInfo.getQuotaInNamespace());
}
bucketInfoBuilder.setCreationTime(dbBucketInfo.getCreationTime());
bucketInfoBuilder.setModificationTime(setBucketPropertyRequest.getModificationTime());
// Set acls from dbBucketInfo if it has any.
if (dbBucketInfo.getAcls() != null) {
bucketInfoBuilder.setAcls(dbBucketInfo.getAcls());
}
// Set the objectID to dbBucketInfo objectID, if present
if (dbBucketInfo.getObjectID() != 0) {
bucketInfoBuilder.setObjectID(dbBucketInfo.getObjectID());
}
// Set the updateID to current transaction log index
bucketInfoBuilder.setUpdateID(transactionLogIndex);
// Quota used remains unchanged
bucketInfoBuilder.setUsedBytes(dbBucketInfo.getUsedBytes());
bucketInfoBuilder.setUsedNamespace(dbBucketInfo.getUsedNamespace());
omBucketInfo = bucketInfoBuilder.build();
// Update table cache.
omMetadataManager.getBucketTable().addCacheEntry(new CacheKey<>(bucketKey), new CacheValue<>(Optional.of(omBucketInfo), transactionLogIndex));
omResponse.setSetBucketPropertyResponse(SetBucketPropertyResponse.newBuilder().build());
omClientResponse = new OMBucketSetPropertyResponse(omResponse.build(), omBucketInfo);
} catch (IOException ex) {
success = false;
exception = ex;
omClientResponse = new OMBucketSetPropertyResponse(createErrorOMResponse(omResponse, exception));
} finally {
addResponseToDoubleBuffer(transactionLogIndex, omClientResponse, ozoneManagerDoubleBufferHelper);
if (acquiredBucketLock) {
omMetadataManager.getLock().releaseWriteLock(BUCKET_LOCK, volumeName, bucketName);
}
}
// Performing audit logging outside of the lock.
auditLog(auditLogger, buildAuditMessage(OMAction.UPDATE_BUCKET, omBucketArgs.toAuditMap(), exception, userInfo));
// return response.
if (success) {
LOG.debug("Setting bucket property for bucket:{} in volume:{}", bucketName, volumeName);
return omClientResponse;
} else {
LOG.error("Setting bucket property failed for bucket:{} in volume:{}", bucketName, volumeName, exception);
omMetrics.incNumBucketUpdateFails();
return omClientResponse;
}
}
Aggregations