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;
}
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);
}
Aggregations