Search in sources :

Example 1 with DeleteTenantResponse

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

the class OMTenantDeleteRequest method validateAndUpdateCache.

@Override
@SuppressWarnings("methodlength")
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, long transactionLogIndex, OzoneManagerDoubleBufferHelper ozoneManagerDoubleBufferHelper) {
    final OMMultiTenantManager multiTenantManager = ozoneManager.getMultiTenantManager();
    final OMMetrics omMetrics = ozoneManager.getMetrics();
    omMetrics.incNumTenantDeletes();
    OMClientResponse omClientResponse = null;
    final OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(getOmRequest());
    boolean acquiredVolumeLock = false;
    final Map<String, String> auditMap = new HashMap<>();
    OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
    final DeleteTenantRequest request = getOmRequest().getDeleteTenantRequest();
    final String tenantId = request.getTenantId();
    String volumeName = null;
    boolean decVolumeRefCount = true;
    IOException exception = null;
    OmVolumeArgs omVolumeArgs = null;
    try {
        // Check tenant existence in tenantStateTable
        if (!omMetadataManager.getTenantStateTable().isExist(tenantId)) {
            LOG.debug("tenant: {} does not exist", tenantId);
            throw new OMException("Tenant '" + tenantId + "' does not exist", TENANT_NOT_FOUND);
        }
        // Reading the TenantStateTable without lock as we don't have or need
        // a TENANT_LOCK. The assumption is that OmDBTenantState is read-only
        // once it is set during tenant creation.
        final OmDBTenantState dbTenantState = omMetadataManager.getTenantStateTable().get(tenantId);
        volumeName = dbTenantState.getBucketNamespaceName();
        Preconditions.checkNotNull(volumeName);
        LOG.debug("Tenant '{}' has volume '{}'", tenantId, volumeName);
        // decVolumeRefCount is true if volumeName is not empty string
        decVolumeRefCount = volumeName.length() > 0;
        // Acquire the volume lock
        acquiredVolumeLock = omMetadataManager.getLock().acquireWriteLock(VOLUME_LOCK, volumeName);
        // Check if there are any accessIds in the tenant
        if (!ozoneManager.getMultiTenantManager().isTenantEmpty(tenantId)) {
            LOG.warn("tenant: '{}' is not empty. Unable to delete the tenant", tenantId);
            throw new OMException("Tenant '" + tenantId + "' is not empty. " + "All accessIds associated to this tenant must be revoked before " + "the tenant can be deleted. See `ozone tenant user revoke`", TENANT_NOT_EMPTY);
        }
        // Invalidate cache entry
        omMetadataManager.getTenantStateTable().addCacheEntry(new CacheKey<>(tenantId), new CacheValue<>(Optional.absent(), transactionLogIndex));
        // Decrement volume refCount
        if (decVolumeRefCount) {
            // Check Acl
            if (ozoneManager.getAclsEnabled()) {
                checkAcls(ozoneManager, OzoneObj.ResourceType.VOLUME, OzoneObj.StoreType.OZONE, IAccessAuthorizer.ACLType.WRITE_ACL, volumeName, null, null);
            }
            omVolumeArgs = getVolumeInfo(omMetadataManager, volumeName);
            // Decrement volume ref count
            omVolumeArgs.decRefCount();
            // Update omVolumeArgs
            final String dbVolumeKey = omMetadataManager.getVolumeKey(volumeName);
            omMetadataManager.getVolumeTable().addCacheEntry(new CacheKey<>(dbVolumeKey), new CacheValue<>(Optional.of(omVolumeArgs), transactionLogIndex));
        // TODO: Set response dbVolumeKey?
        }
        // Update tenant cache
        multiTenantManager.getCacheOp().deleteTenant(new OzoneTenant(tenantId));
        // Compose response
        // 
        // If decVolumeRefCount is false, return -1 to the client, otherwise
        // return the actual volume refCount. Note if the actual volume refCount
        // becomes negative somehow, omVolumeArgs.decRefCount() would have thrown
        // earlier.
        final DeleteTenantResponse.Builder deleteTenantResponse = DeleteTenantResponse.newBuilder().setVolumeName(volumeName).setVolRefCount(omVolumeArgs == null ? -1 : omVolumeArgs.getRefCount());
        omClientResponse = new OMTenantDeleteResponse(omResponse.setDeleteTenantResponse(deleteTenantResponse).build(), volumeName, omVolumeArgs, tenantId);
    } catch (IOException ex) {
        exception = ex;
        omClientResponse = new OMTenantDeleteResponse(createErrorOMResponse(omResponse, exception));
    } finally {
        addResponseToDoubleBuffer(transactionLogIndex, omClientResponse, ozoneManagerDoubleBufferHelper);
        if (acquiredVolumeLock) {
            omMetadataManager.getLock().releaseWriteLock(VOLUME_LOCK, volumeName);
        }
        // Release authorizer write lock
        multiTenantManager.getAuthorizerLock().unlockWriteInOMRequest();
    }
    // Perform audit logging
    auditMap.put(OzoneConsts.TENANT, tenantId);
    // Audit volume ref count update
    if (decVolumeRefCount) {
        auditLog(ozoneManager.getAuditLogger(), buildAuditMessage(OMAction.UPDATE_VOLUME, buildVolumeAuditMap(volumeName), exception, getOmRequest().getUserInfo()));
    }
    // Audit tenant deletion
    auditLog(ozoneManager.getAuditLogger(), buildAuditMessage(OMAction.DELETE_TENANT, auditMap, exception, getOmRequest().getUserInfo()));
    if (exception == null) {
        LOG.info("Deleted tenant '{}' and volume '{}'", tenantId, volumeName);
        omMetrics.decNumTenants();
    } else {
        LOG.error("Failed to delete tenant '{}'", tenantId, exception);
        omMetrics.incNumTenantDeleteFails();
    }
    return omClientResponse;
}
Also used : OMClientResponse(org.apache.hadoop.ozone.om.response.OMClientResponse) OmVolumeArgs(org.apache.hadoop.ozone.om.helpers.OmVolumeArgs) HashMap(java.util.HashMap) OMMultiTenantManager(org.apache.hadoop.ozone.om.OMMultiTenantManager) OzoneTenant(org.apache.hadoop.ozone.om.multitenant.OzoneTenant) IOException(java.io.IOException) OMTenantDeleteResponse(org.apache.hadoop.ozone.om.response.s3.tenant.OMTenantDeleteResponse) DeleteTenantRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.DeleteTenantRequest) OMMetrics(org.apache.hadoop.ozone.om.OMMetrics) OMResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse) OmDBTenantState(org.apache.hadoop.ozone.om.helpers.OmDBTenantState) DeleteTenantResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.DeleteTenantResponse) OMMetadataManager(org.apache.hadoop.ozone.om.OMMetadataManager) OMException(org.apache.hadoop.ozone.om.exceptions.OMException)

Example 2 with DeleteTenantResponse

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

the class OzoneManagerProtocolClientSideTranslatorPB method deleteTenant.

/**
 * {@inheritDoc}
 */
@Override
public DeleteTenantState deleteTenant(String tenantId) throws IOException {
    final DeleteTenantRequest.Builder requestBuilder = DeleteTenantRequest.newBuilder().setTenantId(tenantId);
    final OMRequest omRequest = createOMRequest(Type.DeleteTenant).setDeleteTenantRequest(requestBuilder).build();
    final OMResponse omResponse = submitRequest(omRequest);
    final DeleteTenantResponse resp = handleError(omResponse).getDeleteTenantResponse();
    return DeleteTenantState.fromProtobuf(resp);
}
Also used : OMRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest) DeleteTenantResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.DeleteTenantResponse) DeleteTenantRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.DeleteTenantRequest) OMResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse)

Aggregations

DeleteTenantRequest (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.DeleteTenantRequest)2 DeleteTenantResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.DeleteTenantResponse)2 OMResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 OMMetadataManager (org.apache.hadoop.ozone.om.OMMetadataManager)1 OMMetrics (org.apache.hadoop.ozone.om.OMMetrics)1 OMMultiTenantManager (org.apache.hadoop.ozone.om.OMMultiTenantManager)1 OMException (org.apache.hadoop.ozone.om.exceptions.OMException)1 OmDBTenantState (org.apache.hadoop.ozone.om.helpers.OmDBTenantState)1 OmVolumeArgs (org.apache.hadoop.ozone.om.helpers.OmVolumeArgs)1 OzoneTenant (org.apache.hadoop.ozone.om.multitenant.OzoneTenant)1 OMClientResponse (org.apache.hadoop.ozone.om.response.OMClientResponse)1 OMTenantDeleteResponse (org.apache.hadoop.ozone.om.response.s3.tenant.OMTenantDeleteResponse)1 OMRequest (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest)1