Search in sources :

Example 1 with SetVolumePropertyRequest

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

the class OMVolumeSetQuotaRequest method validateAndUpdateCache.

@Override
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, long transactionLogIndex, OzoneManagerDoubleBufferHelper ozoneManagerDoubleBufferHelper) {
    SetVolumePropertyRequest setVolumePropertyRequest = getOmRequest().getSetVolumePropertyRequest();
    Preconditions.checkNotNull(setVolumePropertyRequest);
    OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(getOmRequest());
    // when we have quota in bytes is set in setVolumePropertyRequest.
    if (!setVolumePropertyRequest.hasQuotaInBytes()) {
        omResponse.setStatus(OzoneManagerProtocolProtos.Status.INVALID_REQUEST).setSuccess(false);
        return new OMVolumeSetQuotaResponse(omResponse.build());
    }
    String volume = setVolumePropertyRequest.getVolumeName();
    OMMetrics omMetrics = ozoneManager.getMetrics();
    omMetrics.incNumVolumeUpdates();
    AuditLogger auditLogger = ozoneManager.getAuditLogger();
    OzoneManagerProtocolProtos.UserInfo userInfo = getOmRequest().getUserInfo();
    Map<String, String> auditMap = buildVolumeAuditMap(volume);
    auditMap.put(OzoneConsts.QUOTA_IN_BYTES, String.valueOf(setVolumePropertyRequest.getQuotaInBytes()));
    OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
    IOException exception = null;
    boolean acquireVolumeLock = false;
    OMClientResponse omClientResponse = null;
    try {
        // check Acl
        if (ozoneManager.getAclsEnabled()) {
            checkAcls(ozoneManager, OzoneObj.ResourceType.VOLUME, OzoneObj.StoreType.OZONE, IAccessAuthorizer.ACLType.WRITE, volume, null, null);
        }
        acquireVolumeLock = omMetadataManager.getLock().acquireWriteLock(VOLUME_LOCK, volume);
        OmVolumeArgs omVolumeArgs = getVolumeInfo(omMetadataManager, volume);
        if (checkQuotaBytesValid(omMetadataManager, setVolumePropertyRequest.getQuotaInBytes(), volume)) {
            omVolumeArgs.setQuotaInBytes(setVolumePropertyRequest.getQuotaInBytes());
        } else {
            omVolumeArgs.setQuotaInBytes(omVolumeArgs.getQuotaInBytes());
        }
        if (checkQuotaNamespaceValid(setVolumePropertyRequest.getQuotaInNamespace())) {
            omVolumeArgs.setQuotaInNamespace(setVolumePropertyRequest.getQuotaInNamespace());
        } else {
            omVolumeArgs.setQuotaInNamespace(omVolumeArgs.getQuotaInNamespace());
        }
        omVolumeArgs.setUpdateID(transactionLogIndex, ozoneManager.isRatisEnabled());
        omVolumeArgs.setModificationTime(setVolumePropertyRequest.getModificationTime());
        // update cache.
        omMetadataManager.getVolumeTable().addCacheEntry(new CacheKey<>(omMetadataManager.getVolumeKey(volume)), new CacheValue<>(Optional.of(omVolumeArgs), transactionLogIndex));
        omResponse.setSetVolumePropertyResponse(SetVolumePropertyResponse.newBuilder().build());
        omClientResponse = new OMVolumeSetQuotaResponse(omResponse.build(), omVolumeArgs);
    } catch (IOException ex) {
        exception = ex;
        omClientResponse = new OMVolumeSetQuotaResponse(createErrorOMResponse(omResponse, exception));
    } finally {
        addResponseToDoubleBuffer(transactionLogIndex, omClientResponse, ozoneManagerDoubleBufferHelper);
        if (acquireVolumeLock) {
            omMetadataManager.getLock().releaseWriteLock(VOLUME_LOCK, volume);
        }
    }
    // Performing audit logging outside of the lock.
    auditLog(auditLogger, buildAuditMessage(OMAction.SET_QUOTA, auditMap, exception, userInfo));
    // return response after releasing lock.
    if (exception == null) {
        LOG.debug("Changing volume quota is successfully completed for volume: " + "{} quota:{}", volume, setVolumePropertyRequest.getQuotaInBytes());
    } else {
        omMetrics.incNumVolumeUpdateFails();
        LOG.error("Changing volume quota failed for volume:{} quota:{}", volume, setVolumePropertyRequest.getQuotaInBytes(), exception);
    }
    return omClientResponse;
}
Also used : AuditLogger(org.apache.hadoop.ozone.audit.AuditLogger) OMClientResponse(org.apache.hadoop.ozone.om.response.OMClientResponse) OmVolumeArgs(org.apache.hadoop.ozone.om.helpers.OmVolumeArgs) IOException(java.io.IOException) OMResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse) OMMetrics(org.apache.hadoop.ozone.om.OMMetrics) OMVolumeSetQuotaResponse(org.apache.hadoop.ozone.om.response.volume.OMVolumeSetQuotaResponse) SetVolumePropertyRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.SetVolumePropertyRequest) OzoneManagerProtocolProtos(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos) OMMetadataManager(org.apache.hadoop.ozone.om.OMMetadataManager)

Example 2 with SetVolumePropertyRequest

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

the class OMVolumeSetOwnerRequest method validateAndUpdateCache.

@Override
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, long transactionLogIndex, OzoneManagerDoubleBufferHelper ozoneManagerDoubleBufferHelper) {
    SetVolumePropertyRequest setVolumePropertyRequest = getOmRequest().getSetVolumePropertyRequest();
    Preconditions.checkNotNull(setVolumePropertyRequest);
    OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(getOmRequest());
    // when we have ownerName in setVolumePropertyRequest.
    if (!setVolumePropertyRequest.hasOwnerName()) {
        omResponse.setStatus(OzoneManagerProtocolProtos.Status.INVALID_REQUEST).setSuccess(false);
        return new OMVolumeSetOwnerResponse(omResponse.build());
    }
    OMMetrics omMetrics = ozoneManager.getMetrics();
    omMetrics.incNumVolumeUpdates();
    String volume = setVolumePropertyRequest.getVolumeName();
    String newOwner = setVolumePropertyRequest.getOwnerName();
    AuditLogger auditLogger = ozoneManager.getAuditLogger();
    OzoneManagerProtocolProtos.UserInfo userInfo = getOmRequest().getUserInfo();
    Map<String, String> auditMap = buildVolumeAuditMap(volume);
    auditMap.put(OzoneConsts.OWNER, newOwner);
    boolean acquiredUserLocks = false;
    boolean acquiredVolumeLock = false;
    IOException exception = null;
    OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
    String oldOwner = null;
    OMClientResponse omClientResponse = null;
    try {
        // check Acl
        if (ozoneManager.getAclsEnabled()) {
            checkAcls(ozoneManager, OzoneObj.ResourceType.VOLUME, OzoneObj.StoreType.OZONE, IAccessAuthorizer.ACLType.WRITE_ACL, volume, null, null);
        }
        long maxUserVolumeCount = ozoneManager.getMaxUserVolumeCount();
        OzoneManagerStorageProtos.PersistedUserVolumeInfo oldOwnerVolumeList;
        OzoneManagerStorageProtos.PersistedUserVolumeInfo newOwnerVolumeList;
        OmVolumeArgs omVolumeArgs = null;
        acquiredVolumeLock = omMetadataManager.getLock().acquireWriteLock(VOLUME_LOCK, volume);
        omVolumeArgs = getVolumeInfo(omMetadataManager, volume);
        oldOwner = omVolumeArgs.getOwnerName();
        // Return OK immediately if newOwner is the same as oldOwner.
        if (oldOwner.equals(newOwner)) {
            LOG.warn("Volume '{}' owner is already user '{}'.", volume, oldOwner);
            omResponse.setStatus(OzoneManagerProtocolProtos.Status.OK).setMessage("Volume '" + volume + "' owner is already '" + newOwner + "'.").setSuccess(false);
            omResponse.setSetVolumePropertyResponse(SetVolumePropertyResponse.newBuilder().setResponse(false).build());
            omClientResponse = new OMVolumeSetOwnerResponse(omResponse.build());
            // Note: addResponseToDoubleBuffer would be executed in finally block.
            return omClientResponse;
        }
        acquiredUserLocks = omMetadataManager.getLock().acquireMultiUserLock(newOwner, oldOwner);
        oldOwnerVolumeList = omMetadataManager.getUserTable().get(oldOwner);
        oldOwnerVolumeList = delVolumeFromOwnerList(oldOwnerVolumeList, volume, oldOwner, transactionLogIndex);
        newOwnerVolumeList = omMetadataManager.getUserTable().get(newOwner);
        newOwnerVolumeList = addVolumeToOwnerList(newOwnerVolumeList, volume, newOwner, maxUserVolumeCount, transactionLogIndex);
        // Set owner with new owner name.
        omVolumeArgs.setOwnerName(newOwner);
        omVolumeArgs.setUpdateID(transactionLogIndex, ozoneManager.isRatisEnabled());
        // Update modificationTime.
        omVolumeArgs.setModificationTime(setVolumePropertyRequest.getModificationTime());
        // Update cache.
        omMetadataManager.getUserTable().addCacheEntry(new CacheKey<>(omMetadataManager.getUserKey(newOwner)), new CacheValue<>(Optional.of(newOwnerVolumeList), transactionLogIndex));
        omMetadataManager.getUserTable().addCacheEntry(new CacheKey<>(omMetadataManager.getUserKey(oldOwner)), new CacheValue<>(Optional.of(oldOwnerVolumeList), transactionLogIndex));
        omMetadataManager.getVolumeTable().addCacheEntry(new CacheKey<>(omMetadataManager.getVolumeKey(volume)), new CacheValue<>(Optional.of(omVolumeArgs), transactionLogIndex));
        omResponse.setSetVolumePropertyResponse(SetVolumePropertyResponse.newBuilder().setResponse(true).build());
        omClientResponse = new OMVolumeSetOwnerResponse(omResponse.build(), oldOwner, oldOwnerVolumeList, newOwnerVolumeList, omVolumeArgs);
    } catch (IOException ex) {
        exception = ex;
        omClientResponse = new OMVolumeSetOwnerResponse(createErrorOMResponse(omResponse, exception));
    } finally {
        addResponseToDoubleBuffer(transactionLogIndex, omClientResponse, ozoneManagerDoubleBufferHelper);
        if (acquiredUserLocks) {
            omMetadataManager.getLock().releaseMultiUserLock(newOwner, oldOwner);
        }
        if (acquiredVolumeLock) {
            omMetadataManager.getLock().releaseWriteLock(VOLUME_LOCK, volume);
        }
    }
    // Performing audit logging outside of the lock.
    auditLog(auditLogger, buildAuditMessage(OMAction.SET_OWNER, auditMap, exception, userInfo));
    // return response after releasing lock.
    if (exception == null) {
        LOG.debug("Successfully changed Owner of Volume {} from {} -> {}", volume, oldOwner, newOwner);
    } else {
        LOG.error("Changing volume ownership failed for user:{} volume:{}", newOwner, volume, exception);
        omMetrics.incNumVolumeUpdateFails();
    }
    return omClientResponse;
}
Also used : OzoneManagerStorageProtos(org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos) AuditLogger(org.apache.hadoop.ozone.audit.AuditLogger) OMClientResponse(org.apache.hadoop.ozone.om.response.OMClientResponse) OmVolumeArgs(org.apache.hadoop.ozone.om.helpers.OmVolumeArgs) IOException(java.io.IOException) OMResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse) OMMetrics(org.apache.hadoop.ozone.om.OMMetrics) SetVolumePropertyRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.SetVolumePropertyRequest) OzoneManagerProtocolProtos(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos) OMMetadataManager(org.apache.hadoop.ozone.om.OMMetadataManager) OMVolumeSetOwnerResponse(org.apache.hadoop.ozone.om.response.volume.OMVolumeSetOwnerResponse)

Aggregations

IOException (java.io.IOException)2 AuditLogger (org.apache.hadoop.ozone.audit.AuditLogger)2 OMMetadataManager (org.apache.hadoop.ozone.om.OMMetadataManager)2 OMMetrics (org.apache.hadoop.ozone.om.OMMetrics)2 OmVolumeArgs (org.apache.hadoop.ozone.om.helpers.OmVolumeArgs)2 OMClientResponse (org.apache.hadoop.ozone.om.response.OMClientResponse)2 OzoneManagerProtocolProtos (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos)2 OMResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse)2 SetVolumePropertyRequest (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.SetVolumePropertyRequest)2 OMVolumeSetOwnerResponse (org.apache.hadoop.ozone.om.response.volume.OMVolumeSetOwnerResponse)1 OMVolumeSetQuotaResponse (org.apache.hadoop.ozone.om.response.volume.OMVolumeSetQuotaResponse)1 OzoneManagerStorageProtos (org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos)1