use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.CreateVolumeRequest in project ozone by apache.
the class TestOMVolumeRequest method createVolumeRequest.
/**
* Create OMRequest for create volume.
* @param volumeName
* @param adminName
* @param ownerName
* @return OMRequest
*/
static OMRequest createVolumeRequest(String volumeName, String adminName, String ownerName) {
VolumeInfo volumeInfo = VolumeInfo.newBuilder().setVolume(volumeName).setAdminName(adminName).setOwnerName(ownerName).build();
CreateVolumeRequest createVolumeRequest = CreateVolumeRequest.newBuilder().setVolumeInfo(volumeInfo).build();
return OMRequest.newBuilder().setClientId(UUID.randomUUID().toString()).setCmdType(OzoneManagerProtocolProtos.Type.CreateVolume).setCreateVolumeRequest(createVolumeRequest).build();
}
use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.CreateVolumeRequest in project ozone by apache.
the class OMVolumeCreateRequest method validateAndUpdateCache.
@Override
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, long transactionLogIndex, OzoneManagerDoubleBufferHelper ozoneManagerDoubleBufferHelper) {
CreateVolumeRequest createVolumeRequest = getOmRequest().getCreateVolumeRequest();
Preconditions.checkNotNull(createVolumeRequest);
VolumeInfo volumeInfo = createVolumeRequest.getVolumeInfo();
OMMetrics omMetrics = ozoneManager.getMetrics();
omMetrics.incNumVolumeCreates();
String volume = volumeInfo.getVolume();
String owner = volumeInfo.getOwnerName();
OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(getOmRequest());
OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
// Doing this here, so we can do protobuf conversion outside of lock.
boolean acquiredVolumeLock = false;
boolean acquiredUserLock = false;
IOException exception = null;
OMClientResponse omClientResponse = null;
OmVolumeArgs omVolumeArgs = null;
Map<String, String> auditMap = null;
try {
omVolumeArgs = OmVolumeArgs.getFromProtobuf(volumeInfo);
// when you create a volume, we set both Object ID and update ID.
// The Object ID will never change, but update
// ID will be set to transactionID each time we update the object.
omVolumeArgs.setObjectID(ozoneManager.getObjectIdFromTxId(transactionLogIndex));
omVolumeArgs.setUpdateID(transactionLogIndex, ozoneManager.isRatisEnabled());
auditMap = omVolumeArgs.toAuditMap();
// check acl
if (ozoneManager.getAclsEnabled()) {
checkAcls(ozoneManager, OzoneObj.ResourceType.VOLUME, OzoneObj.StoreType.OZONE, IAccessAuthorizer.ACLType.CREATE, volume, null, null);
}
// acquire lock.
acquiredVolumeLock = omMetadataManager.getLock().acquireWriteLock(VOLUME_LOCK, volume);
acquiredUserLock = omMetadataManager.getLock().acquireWriteLock(USER_LOCK, owner);
String dbVolumeKey = omMetadataManager.getVolumeKey(volume);
PersistedUserVolumeInfo volumeList = null;
if (omMetadataManager.getVolumeTable().isExist(dbVolumeKey)) {
LOG.debug("volume:{} already exists", omVolumeArgs.getVolume());
throw new OMException("Volume already exists", OMException.ResultCodes.VOLUME_ALREADY_EXISTS);
} else {
String dbUserKey = omMetadataManager.getUserKey(owner);
volumeList = omMetadataManager.getUserTable().get(dbUserKey);
volumeList = addVolumeToOwnerList(volumeList, volume, owner, ozoneManager.getMaxUserVolumeCount(), transactionLogIndex);
createVolume(omMetadataManager, omVolumeArgs, volumeList, dbVolumeKey, dbUserKey, transactionLogIndex);
omResponse.setCreateVolumeResponse(CreateVolumeResponse.newBuilder().build());
omClientResponse = new OMVolumeCreateResponse(omResponse.build(), omVolumeArgs, volumeList);
LOG.debug("volume:{} successfully created", omVolumeArgs.getVolume());
}
} catch (IOException ex) {
exception = ex;
omClientResponse = new OMVolumeCreateResponse(createErrorOMResponse(omResponse, exception));
} finally {
if (omClientResponse != null) {
omClientResponse.setFlushFuture(ozoneManagerDoubleBufferHelper.add(omClientResponse, transactionLogIndex));
}
if (acquiredUserLock) {
omMetadataManager.getLock().releaseWriteLock(USER_LOCK, owner);
}
if (acquiredVolumeLock) {
omMetadataManager.getLock().releaseWriteLock(VOLUME_LOCK, volume);
}
}
// Performing audit logging outside of the lock.
auditLog(ozoneManager.getAuditLogger(), buildAuditMessage(OMAction.CREATE_VOLUME, auditMap, exception, getOmRequest().getUserInfo()));
// return response after releasing lock.
if (exception == null) {
LOG.info("created volume:{} for user:{}", volume, owner);
omMetrics.incNumVolumes();
} else {
LOG.error("Volume creation failed for user:{} volume:{}", owner, volume, exception);
omMetrics.incNumVolumeCreateFails();
}
return omClientResponse;
}
Aggregations