Search in sources :

Example 1 with StorageType

use of org.apache.hadoop.hdds.protocol.StorageType in project ozone by apache.

the class BucketManagerImpl method setBucketProperty.

/**
 * Sets bucket property from args.
 *
 * @param args - BucketArgs.
 * @throws IOException - On Failure.
 */
@Override
public void setBucketProperty(OmBucketArgs args) throws IOException {
    Preconditions.checkNotNull(args);
    String volumeName = args.getVolumeName();
    String bucketName = args.getBucketName();
    metadataManager.getLock().acquireWriteLock(BUCKET_LOCK, volumeName, bucketName);
    try {
        String bucketKey = metadataManager.getBucketKey(volumeName, bucketName);
        OmBucketInfo oldBucketInfo = metadataManager.getBucketTable().get(bucketKey);
        // Check if bucket exist
        if (oldBucketInfo == null) {
            LOG.debug("bucket: {} not found ", bucketName);
            throw new OMException("Bucket doesn't exist", BUCKET_NOT_FOUND);
        }
        OmBucketInfo.Builder bucketInfoBuilder = OmBucketInfo.newBuilder();
        bucketInfoBuilder.setVolumeName(oldBucketInfo.getVolumeName()).setBucketName(oldBucketInfo.getBucketName());
        bucketInfoBuilder.addAllMetadata(args.getMetadata());
        // Check StorageType to update
        StorageType storageType = args.getStorageType();
        if (storageType != null) {
            bucketInfoBuilder.setStorageType(storageType);
            LOG.debug("Updating bucket storage type for bucket: {} in volume: {}", bucketName, volumeName);
        } else {
            bucketInfoBuilder.setStorageType(oldBucketInfo.getStorageType());
        }
        // Check Versioning to update
        Boolean versioning = args.getIsVersionEnabled();
        if (versioning != null) {
            bucketInfoBuilder.setIsVersionEnabled(versioning);
            LOG.debug("Updating bucket versioning for bucket: {} in volume: {}", bucketName, volumeName);
        } else {
            bucketInfoBuilder.setIsVersionEnabled(oldBucketInfo.getIsVersionEnabled());
        }
        bucketInfoBuilder.setCreationTime(oldBucketInfo.getCreationTime());
        // Set acls from oldBucketInfo if it has any.
        if (oldBucketInfo.getAcls() != null) {
            bucketInfoBuilder.setAcls(oldBucketInfo.getAcls());
        }
        OmBucketInfo omBucketInfo = bucketInfoBuilder.build();
        commitBucketInfoToDB(omBucketInfo);
    } catch (IOException ex) {
        if (!(ex instanceof OMException)) {
            LOG.error("Setting bucket property failed for bucket:{} in volume:{}", bucketName, volumeName, ex);
        }
        throw ex;
    } finally {
        metadataManager.getLock().releaseWriteLock(BUCKET_LOCK, volumeName, bucketName);
    }
}
Also used : OmBucketInfo(org.apache.hadoop.ozone.om.helpers.OmBucketInfo) StorageType(org.apache.hadoop.hdds.protocol.StorageType) IOException(java.io.IOException) OMException(org.apache.hadoop.ozone.om.exceptions.OMException)

Example 2 with StorageType

use of org.apache.hadoop.hdds.protocol.StorageType 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());
        }
        DefaultReplicationConfig defaultReplicationConfig = omBucketArgs.getDefaultReplicationConfig();
        if (defaultReplicationConfig != null) {
            // Resetting the default replication config.
            bucketInfoBuilder.setDefaultReplicationConfig(defaultReplicationConfig);
        }
        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;
    }
}
Also used : OmBucketInfo(org.apache.hadoop.ozone.om.helpers.OmBucketInfo) AuditLogger(org.apache.hadoop.ozone.audit.AuditLogger) StorageType(org.apache.hadoop.hdds.protocol.StorageType) OMClientResponse(org.apache.hadoop.ozone.om.response.OMClientResponse) OmVolumeArgs(org.apache.hadoop.ozone.om.helpers.OmVolumeArgs) OmBucketArgs(org.apache.hadoop.ozone.om.helpers.OmBucketArgs) BucketArgs(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.BucketArgs) OMBucketSetPropertyResponse(org.apache.hadoop.ozone.om.response.bucket.OMBucketSetPropertyResponse) 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) OmBucketArgs(org.apache.hadoop.ozone.om.helpers.OmBucketArgs) OMMetadataManager(org.apache.hadoop.ozone.om.OMMetadataManager) DefaultReplicationConfig(org.apache.hadoop.hdds.client.DefaultReplicationConfig) OMException(org.apache.hadoop.ozone.om.exceptions.OMException) SetBucketPropertyRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.SetBucketPropertyRequest)

Example 3 with StorageType

use of org.apache.hadoop.hdds.protocol.StorageType in project ozone by apache.

the class RpcClient method createBucket.

@Override
public void createBucket(String volumeName, String bucketName, BucketArgs bucketArgs) throws IOException {
    verifyVolumeName(volumeName);
    verifyBucketName(bucketName);
    Preconditions.checkNotNull(bucketArgs);
    verifyCountsQuota(bucketArgs.getQuotaInNamespace());
    verifySpaceQuota(bucketArgs.getQuotaInBytes());
    if (omVersion.compareTo(OzoneManagerVersion.ERASURE_CODED_STORAGE_SUPPORT) < 0) {
        if (bucketArgs.getDefaultReplicationConfig() != null && bucketArgs.getDefaultReplicationConfig().getType() == ReplicationType.EC) {
            throw new IOException("Can not set the default replication of the" + " bucket to Erasure Coded replication, as OzoneManager does" + " not support Erasure Coded replication.");
        }
    }
    final String owner;
    // accessId. Similar to RpcClient#getDEK
    if (getThreadLocalS3Auth() != null) {
        final UserGroupInformation s3gUGI = UserGroupInformation.createRemoteUser(getThreadLocalS3Auth().getUserPrincipal());
        owner = s3gUGI.getShortUserName();
    } else {
        owner = bucketArgs.getOwner() == null ? ugi.getShortUserName() : bucketArgs.getOwner();
    }
    Boolean isVersionEnabled = bucketArgs.getVersioning() == null ? Boolean.FALSE : bucketArgs.getVersioning();
    StorageType storageType = bucketArgs.getStorageType() == null ? StorageType.DEFAULT : bucketArgs.getStorageType();
    BucketLayout bucketLayout = bucketArgs.getBucketLayout();
    BucketEncryptionKeyInfo bek = null;
    if (bucketArgs.getEncryptionKey() != null) {
        bek = new BucketEncryptionKeyInfo.Builder().setKeyName(bucketArgs.getEncryptionKey()).build();
    }
    List<OzoneAcl> listOfAcls = getAclList();
    // ACLs from BucketArgs
    if (bucketArgs.getAcls() != null) {
        listOfAcls.addAll(bucketArgs.getAcls());
    }
    OmBucketInfo.Builder builder = OmBucketInfo.newBuilder();
    builder.setVolumeName(volumeName).setBucketName(bucketName).setIsVersionEnabled(isVersionEnabled).addAllMetadata(bucketArgs.getMetadata()).setStorageType(storageType).setSourceVolume(bucketArgs.getSourceVolume()).setSourceBucket(bucketArgs.getSourceBucket()).setQuotaInBytes(bucketArgs.getQuotaInBytes()).setQuotaInNamespace(bucketArgs.getQuotaInNamespace()).setAcls(listOfAcls.stream().distinct().collect(Collectors.toList())).setBucketLayout(bucketLayout).setOwner(owner);
    if (bek != null) {
        builder.setBucketEncryptionKey(bek);
    }
    DefaultReplicationConfig defaultReplicationConfig = bucketArgs.getDefaultReplicationConfig();
    if (defaultReplicationConfig != null) {
        builder.setDefaultReplicationConfig(defaultReplicationConfig);
    }
    LOG.info("Creating Bucket: {}/{}, with the Bucket Layout {}, {} as " + "owner, Versioning {}, Storage Type set to {} and Encryption set " + "to {} ", volumeName, bucketName, bucketLayout, owner, isVersionEnabled, storageType, bek != null);
    ozoneManagerClient.createBucket(builder.build());
}
Also used : OmBucketInfo(org.apache.hadoop.ozone.om.helpers.OmBucketInfo) StorageType(org.apache.hadoop.hdds.protocol.StorageType) BucketEncryptionKeyInfo(org.apache.hadoop.ozone.om.helpers.BucketEncryptionKeyInfo) BucketLayout(org.apache.hadoop.ozone.om.helpers.BucketLayout) IOException(java.io.IOException) OzoneAcl(org.apache.hadoop.ozone.OzoneAcl) DefaultReplicationConfig(org.apache.hadoop.hdds.client.DefaultReplicationConfig) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Aggregations

IOException (java.io.IOException)3 StorageType (org.apache.hadoop.hdds.protocol.StorageType)3 OmBucketInfo (org.apache.hadoop.ozone.om.helpers.OmBucketInfo)3 DefaultReplicationConfig (org.apache.hadoop.hdds.client.DefaultReplicationConfig)2 OMException (org.apache.hadoop.ozone.om.exceptions.OMException)2 OzoneAcl (org.apache.hadoop.ozone.OzoneAcl)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 BucketEncryptionKeyInfo (org.apache.hadoop.ozone.om.helpers.BucketEncryptionKeyInfo)1 BucketLayout (org.apache.hadoop.ozone.om.helpers.BucketLayout)1 OmBucketArgs (org.apache.hadoop.ozone.om.helpers.OmBucketArgs)1 OmVolumeArgs (org.apache.hadoop.ozone.om.helpers.OmVolumeArgs)1 OMClientResponse (org.apache.hadoop.ozone.om.response.OMClientResponse)1 OMBucketSetPropertyResponse (org.apache.hadoop.ozone.om.response.bucket.OMBucketSetPropertyResponse)1 OzoneManagerProtocolProtos (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos)1 BucketArgs (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.BucketArgs)1 OMResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse)1 SetBucketPropertyRequest (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.SetBucketPropertyRequest)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1