Search in sources :

Example 6 with PersistedUserVolumeInfo

use of org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos.PersistedUserVolumeInfo 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)

Example 7 with PersistedUserVolumeInfo

use of org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos.PersistedUserVolumeInfo in project ozone by apache.

the class TestOMVolumeDeleteResponse method testAddToDBBatch.

@Test
public void testAddToDBBatch() throws Exception {
    String volumeName = UUID.randomUUID().toString();
    String userName = "user1";
    PersistedUserVolumeInfo volumeList = PersistedUserVolumeInfo.newBuilder().setObjectID(1).setUpdateID(1).addVolumeNames(volumeName).build();
    OMResponse omResponse = OMResponse.newBuilder().setCmdType(OzoneManagerProtocolProtos.Type.DeleteVolume).setStatus(OzoneManagerProtocolProtos.Status.OK).setSuccess(true).setCreateVolumeResponse(CreateVolumeResponse.getDefaultInstance()).build();
    OmVolumeArgs omVolumeArgs = OmVolumeArgs.newBuilder().setOwnerName(userName).setAdminName(userName).setVolume(volumeName).setCreationTime(Time.now()).build();
    OMVolumeCreateResponse omVolumeCreateResponse = new OMVolumeCreateResponse(omResponse, omVolumeArgs, volumeList);
    // As we are deleting updated volume list should be empty.
    PersistedUserVolumeInfo updatedVolumeList = PersistedUserVolumeInfo.newBuilder().setObjectID(1).setUpdateID(1).build();
    OMVolumeDeleteResponse omVolumeDeleteResponse = new OMVolumeDeleteResponse(omResponse, volumeName, userName, updatedVolumeList);
    omVolumeCreateResponse.addToDBBatch(omMetadataManager, batchOperation);
    omVolumeDeleteResponse.addToDBBatch(omMetadataManager, batchOperation);
    // Do manual commit and see whether addToBatch is successful or not.
    omMetadataManager.getStore().commitBatchOperation(batchOperation);
    Assert.assertNull(null, omMetadataManager.getVolumeTable().get(omMetadataManager.getVolumeKey(volumeName)));
    Assert.assertEquals(null, omMetadataManager.getUserTable().get(omMetadataManager.getUserKey(userName)));
}
Also used : OmVolumeArgs(org.apache.hadoop.ozone.om.helpers.OmVolumeArgs) PersistedUserVolumeInfo(org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos.PersistedUserVolumeInfo) OMResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse) Test(org.junit.Test)

Example 8 with PersistedUserVolumeInfo

use of org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos.PersistedUserVolumeInfo in project ozone by apache.

the class OMVolumeRequest method delVolumeFromOwnerList.

/**
 * Delete volume from user volume list. This method should be called after
 * acquiring user lock.
 * @param volumeList - current volume list owned by user.
 * @param volume - volume which needs to deleted from the volume list.
 * @param owner - Name of the Owner.
 * @param txID - The transaction ID that is updating this value.
 * @return UserVolumeInfo - updated UserVolumeInfo.
 * @throws IOException
 */
protected PersistedUserVolumeInfo delVolumeFromOwnerList(PersistedUserVolumeInfo volumeList, String volume, String owner, long txID) throws IOException {
    List<String> prevVolList = new ArrayList<>();
    if (volumeList != null) {
        prevVolList.addAll(volumeList.getVolumeNamesList());
    } else {
        // No Volumes for this user
        throw new OMException("User not found: " + owner, OMException.ResultCodes.USER_NOT_FOUND);
    }
    // Remove the volume from the list
    prevVolList.remove(volume);
    PersistedUserVolumeInfo newVolList = PersistedUserVolumeInfo.newBuilder().addAllVolumeNames(prevVolList).setObjectID(volumeList.getObjectID()).setUpdateID(txID).build();
    return newVolList;
}
Also used : ArrayList(java.util.ArrayList) OMException(org.apache.hadoop.ozone.om.exceptions.OMException) PersistedUserVolumeInfo(org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos.PersistedUserVolumeInfo)

Aggregations

PersistedUserVolumeInfo (org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos.PersistedUserVolumeInfo)8 OmVolumeArgs (org.apache.hadoop.ozone.om.helpers.OmVolumeArgs)6 OMResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse)4 Test (org.junit.Test)3 OMException (org.apache.hadoop.ozone.om.exceptions.OMException)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 CertificateSignRequest.getEncodedString (org.apache.hadoop.hdds.security.x509.certificates.utils.CertificateSignRequest.getEncodedString)1 BatchOperation (org.apache.hadoop.hdds.utils.db.BatchOperation)1 DBStoreBuilder (org.apache.hadoop.hdds.utils.db.DBStoreBuilder)1 Table (org.apache.hadoop.hdds.utils.db.Table)1 OzoneAcl (org.apache.hadoop.ozone.OzoneAcl)1 OMMetadataManager (org.apache.hadoop.ozone.om.OMMetadataManager)1 OMMetrics (org.apache.hadoop.ozone.om.OMMetrics)1 OmBucketInfo (org.apache.hadoop.ozone.om.helpers.OmBucketInfo)1 Builder (org.apache.hadoop.ozone.om.helpers.OmKeyInfo.Builder)1 OMClientResponse (org.apache.hadoop.ozone.om.response.OMClientResponse)1 OMVolumeCreateResponse (org.apache.hadoop.ozone.om.response.volume.OMVolumeCreateResponse)1 CreateVolumeRequest (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.CreateVolumeRequest)1 VolumeInfo (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.VolumeInfo)1