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