use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.CreateBucketRequest in project ozone by apache.
the class OMBucketCreateRequest method validateAndUpdateCache.
@Override
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, long transactionLogIndex, OzoneManagerDoubleBufferHelper ozoneManagerDoubleBufferHelper) {
OMMetrics omMetrics = ozoneManager.getMetrics();
omMetrics.incNumBucketCreates();
OMMetadataManager metadataManager = ozoneManager.getMetadataManager();
CreateBucketRequest createBucketRequest = getOmRequest().getCreateBucketRequest();
BucketInfo bucketInfo = createBucketRequest.getBucketInfo();
String volumeName = bucketInfo.getVolumeName();
String bucketName = bucketInfo.getBucketName();
OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(getOmRequest());
OmBucketInfo omBucketInfo = null;
if (bucketInfo.getBucketLayout() == null || bucketInfo.getBucketLayout().equals(BucketLayoutProto.LEGACY)) {
// Bucket Layout argument was not passed during bucket creation.
String omDefaultBucketLayout = ozoneManager.getOMDefaultBucketLayout();
BucketLayout defaultType = BucketLayout.fromString(omDefaultBucketLayout);
omBucketInfo = OmBucketInfo.getFromProtobuf(bucketInfo, defaultType);
} else {
omBucketInfo = OmBucketInfo.getFromProtobuf(bucketInfo);
}
if (omBucketInfo.getBucketLayout().isFileSystemOptimized()) {
omMetrics.incNumFSOBucketCreates();
}
AuditLogger auditLogger = ozoneManager.getAuditLogger();
OzoneManagerProtocolProtos.UserInfo userInfo = getOmRequest().getUserInfo();
String volumeKey = metadataManager.getVolumeKey(volumeName);
String bucketKey = metadataManager.getBucketKey(volumeName, bucketName);
IOException exception = null;
boolean acquiredBucketLock = false;
boolean acquiredVolumeLock = false;
OMClientResponse omClientResponse = null;
try {
// check Acl
if (ozoneManager.getAclsEnabled()) {
checkAcls(ozoneManager, OzoneObj.ResourceType.BUCKET, OzoneObj.StoreType.OZONE, IAccessAuthorizer.ACLType.CREATE, volumeName, bucketName, null);
}
acquiredVolumeLock = metadataManager.getLock().acquireReadLock(VOLUME_LOCK, volumeName);
acquiredBucketLock = metadataManager.getLock().acquireWriteLock(BUCKET_LOCK, volumeName, bucketName);
OmVolumeArgs omVolumeArgs = metadataManager.getVolumeTable().getReadCopy(volumeKey);
// Check if the volume exists
if (omVolumeArgs == null) {
LOG.debug("volume: {} not found ", volumeName);
throw new OMException("Volume doesn't exist", VOLUME_NOT_FOUND);
}
// Check if bucket already exists
if (metadataManager.getBucketTable().isExist(bucketKey)) {
LOG.debug("bucket: {} already exists ", bucketName);
throw new OMException("Bucket already exist", BUCKET_ALREADY_EXISTS);
}
// Check quotaInBytes to update
checkQuotaBytesValid(metadataManager, omVolumeArgs, omBucketInfo, volumeKey);
// Add objectID and updateID
omBucketInfo.setObjectID(ozoneManager.getObjectIdFromTxId(transactionLogIndex));
omBucketInfo.setUpdateID(transactionLogIndex, ozoneManager.isRatisEnabled());
// Add default acls from volume.
addDefaultAcls(omBucketInfo, omVolumeArgs);
// check namespace quota
checkQuotaInNamespace(omVolumeArgs, 1L);
// update used namespace for volume
omVolumeArgs.incrUsedNamespace(1L);
// Update table cache.
metadataManager.getVolumeTable().addCacheEntry(new CacheKey<>(volumeKey), new CacheValue<>(Optional.of(omVolumeArgs), transactionLogIndex));
metadataManager.getBucketTable().addCacheEntry(new CacheKey<>(bucketKey), new CacheValue<>(Optional.of(omBucketInfo), transactionLogIndex));
omResponse.setCreateBucketResponse(CreateBucketResponse.newBuilder().build());
omClientResponse = new OMBucketCreateResponse(omResponse.build(), omBucketInfo, omVolumeArgs.copyObject());
} catch (IOException ex) {
exception = ex;
omClientResponse = new OMBucketCreateResponse(createErrorOMResponse(omResponse, exception));
} finally {
addResponseToDoubleBuffer(transactionLogIndex, omClientResponse, ozoneManagerDoubleBufferHelper);
if (acquiredBucketLock) {
metadataManager.getLock().releaseWriteLock(BUCKET_LOCK, volumeName, bucketName);
}
if (acquiredVolumeLock) {
metadataManager.getLock().releaseReadLock(VOLUME_LOCK, volumeName);
}
}
// Performing audit logging outside of the lock.
auditLog(auditLogger, buildAuditMessage(OMAction.CREATE_BUCKET, omBucketInfo.toAuditMap(), exception, userInfo));
// return response.
if (exception == null) {
LOG.debug("created bucket: {} in volume: {}", bucketName, volumeName);
omMetrics.incNumBuckets();
return omClientResponse;
} else {
omMetrics.incNumBucketCreateFails();
LOG.error("Bucket creation failed for bucket:{} in volume:{}", bucketName, volumeName, exception);
return omClientResponse;
}
}
use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.CreateBucketRequest in project ozone by apache.
the class OMBucketCreateRequest method preExecute.
@Override
public OMRequest preExecute(OzoneManager ozoneManager) throws IOException {
// Get original request.
CreateBucketRequest createBucketRequest = getOmRequest().getCreateBucketRequest();
BucketInfo bucketInfo = createBucketRequest.getBucketInfo();
// Verify resource name
OmUtils.validateBucketName(bucketInfo.getBucketName());
// Get KMS provider.
KeyProviderCryptoExtension kmsProvider = ozoneManager.getKmsProvider();
// Create new Bucket request with new bucket info.
CreateBucketRequest.Builder newCreateBucketRequest = createBucketRequest.toBuilder();
BucketInfo.Builder newBucketInfo = bucketInfo.toBuilder();
// Set creation time & modification time.
long initialTime = Time.now();
newBucketInfo.setCreationTime(initialTime).setModificationTime(initialTime);
if (bucketInfo.hasBeinfo()) {
newBucketInfo.setBeinfo(getBeinfo(kmsProvider, bucketInfo));
}
boolean hasSourceVolume = bucketInfo.hasSourceVolume();
boolean hasSourceBucket = bucketInfo.hasSourceBucket();
if (hasSourceBucket != hasSourceVolume) {
throw new OMException("Both source volume and source bucket are " + "required for bucket links", OMException.ResultCodes.INVALID_REQUEST);
}
if (hasSourceBucket && bucketInfo.hasBeinfo()) {
throw new OMException("Encryption cannot be set for bucket links", OMException.ResultCodes.INVALID_REQUEST);
}
newCreateBucketRequest.setBucketInfo(newBucketInfo.build());
return getOmRequest().toBuilder().setUserInfo(getUserInfo()).setCreateBucketRequest(newCreateBucketRequest.build()).build();
}
Aggregations