Search in sources :

Example 1 with CreateVolumeRequest

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();
}
Also used : CreateVolumeRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.CreateVolumeRequest) VolumeInfo(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.VolumeInfo)

Example 2 with CreateVolumeRequest

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;
}
Also used : CreateVolumeRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.CreateVolumeRequest) OMClientResponse(org.apache.hadoop.ozone.om.response.OMClientResponse) OmVolumeArgs(org.apache.hadoop.ozone.om.helpers.OmVolumeArgs) VolumeInfo(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.VolumeInfo) PersistedUserVolumeInfo(org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos.PersistedUserVolumeInfo) IOException(java.io.IOException) PersistedUserVolumeInfo(org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos.PersistedUserVolumeInfo) OMMetrics(org.apache.hadoop.ozone.om.OMMetrics) OMResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse) OMVolumeCreateResponse(org.apache.hadoop.ozone.om.response.volume.OMVolumeCreateResponse) OMMetadataManager(org.apache.hadoop.ozone.om.OMMetadataManager) OMException(org.apache.hadoop.ozone.om.exceptions.OMException)

Aggregations

CreateVolumeRequest (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.CreateVolumeRequest)2 VolumeInfo (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.VolumeInfo)2 IOException (java.io.IOException)1 OMMetadataManager (org.apache.hadoop.ozone.om.OMMetadataManager)1 OMMetrics (org.apache.hadoop.ozone.om.OMMetrics)1 OMException (org.apache.hadoop.ozone.om.exceptions.OMException)1 OmVolumeArgs (org.apache.hadoop.ozone.om.helpers.OmVolumeArgs)1 OMClientResponse (org.apache.hadoop.ozone.om.response.OMClientResponse)1 OMVolumeCreateResponse (org.apache.hadoop.ozone.om.response.volume.OMVolumeCreateResponse)1 OMResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse)1 PersistedUserVolumeInfo (org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos.PersistedUserVolumeInfo)1