Search in sources :

Example 1 with BucketInfo

use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.BucketInfo in project ozone by apache.

the class OzoneManagerProtocolClientSideTranslatorPB method createBucket.

/**
 * Creates a bucket.
 *
 * @param bucketInfo - BucketInfo to create bucket.
 * @throws IOException
 */
@Override
public void createBucket(OmBucketInfo bucketInfo) throws IOException {
    CreateBucketRequest.Builder req = CreateBucketRequest.newBuilder();
    BucketInfo bucketInfoProtobuf = bucketInfo.getProtobuf();
    req.setBucketInfo(bucketInfoProtobuf);
    OMRequest omRequest = createOMRequest(Type.CreateBucket).setCreateBucketRequest(req).build();
    handleError(submitRequest(omRequest));
}
Also used : OMRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest) CreateBucketRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.CreateBucketRequest) OmBucketInfo(org.apache.hadoop.ozone.om.helpers.OmBucketInfo) BucketInfo(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.BucketInfo)

Example 2 with BucketInfo

use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.BucketInfo in project ozone by apache.

the class MockOmTransport method createBucket.

private CreateBucketResponse createBucket(CreateBucketRequest createBucketRequest) {
    final BucketInfo bucketInfo = BucketInfo.newBuilder(createBucketRequest.getBucketInfo()).setCreationTime(System.currentTimeMillis()).build();
    buckets.get(bucketInfo.getVolumeName()).put(bucketInfo.getBucketName(), bucketInfo);
    openKeys.get(bucketInfo.getVolumeName()).put(bucketInfo.getBucketName(), new HashMap<>());
    keys.get(bucketInfo.getVolumeName()).put(bucketInfo.getBucketName(), new HashMap<>());
    return CreateBucketResponse.newBuilder().build();
}
Also used : BucketInfo(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.BucketInfo)

Example 3 with BucketInfo

use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.BucketInfo 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;
    }
}
Also used : OmBucketInfo(org.apache.hadoop.ozone.om.helpers.OmBucketInfo) AuditLogger(org.apache.hadoop.ozone.audit.AuditLogger) OMClientResponse(org.apache.hadoop.ozone.om.response.OMClientResponse) OmVolumeArgs(org.apache.hadoop.ozone.om.helpers.OmVolumeArgs) CreateBucketRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.CreateBucketRequest) BucketLayout(org.apache.hadoop.ozone.om.helpers.BucketLayout) IOException(java.io.IOException) OMMetrics(org.apache.hadoop.ozone.om.OMMetrics) OMResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse) OzoneManagerProtocolProtos(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos) OMMetadataManager(org.apache.hadoop.ozone.om.OMMetadataManager) OMBucketCreateResponse(org.apache.hadoop.ozone.om.response.bucket.OMBucketCreateResponse) OmBucketInfo(org.apache.hadoop.ozone.om.helpers.OmBucketInfo) BucketInfo(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.BucketInfo) OMException(org.apache.hadoop.ozone.om.exceptions.OMException)

Example 4 with BucketInfo

use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.BucketInfo 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();
}
Also used : CreateBucketRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.CreateBucketRequest) OmBucketInfo(org.apache.hadoop.ozone.om.helpers.OmBucketInfo) BucketInfo(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.BucketInfo) KeyProviderCryptoExtension(org.apache.hadoop.crypto.key.KeyProviderCryptoExtension) OMException(org.apache.hadoop.ozone.om.exceptions.OMException)

Aggregations

BucketInfo (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.BucketInfo)4 OmBucketInfo (org.apache.hadoop.ozone.om.helpers.OmBucketInfo)3 CreateBucketRequest (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.CreateBucketRequest)3 OMException (org.apache.hadoop.ozone.om.exceptions.OMException)2 IOException (java.io.IOException)1 KeyProviderCryptoExtension (org.apache.hadoop.crypto.key.KeyProviderCryptoExtension)1 AuditLogger (org.apache.hadoop.ozone.audit.AuditLogger)1 OMMetadataManager (org.apache.hadoop.ozone.om.OMMetadataManager)1 OMMetrics (org.apache.hadoop.ozone.om.OMMetrics)1 BucketLayout (org.apache.hadoop.ozone.om.helpers.BucketLayout)1 OmVolumeArgs (org.apache.hadoop.ozone.om.helpers.OmVolumeArgs)1 OMClientResponse (org.apache.hadoop.ozone.om.response.OMClientResponse)1 OMBucketCreateResponse (org.apache.hadoop.ozone.om.response.bucket.OMBucketCreateResponse)1 OzoneManagerProtocolProtos (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos)1 OMRequest (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest)1 OMResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse)1