Search in sources :

Example 1 with PersistedUserVolumeInfo

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

the class GeneratorOm method writeOmBucketVolume.

private void writeOmBucketVolume() throws IOException {
    Table<String, OmVolumeArgs> volTable = omDb.getTable(OmMetadataManagerImpl.VOLUME_TABLE, String.class, OmVolumeArgs.class);
    String admin = getUserId();
    String owner = getUserId();
    OmVolumeArgs omVolumeArgs = new OmVolumeArgs.Builder().setVolume(volumeName).setAdminName(admin).setCreationTime(Time.now()).setOwnerName(owner).setObjectID(1L).setUpdateID(1L).setQuotaInBytes(100L).addOzoneAcls(new OzoneAcl(IAccessAuthorizer.ACLIdentityType.WORLD, "", IAccessAuthorizer.ACLType.ALL, ACCESS)).addOzoneAcls(new OzoneAcl(IAccessAuthorizer.ACLIdentityType.USER, getUserId(), IAccessAuthorizer.ACLType.ALL, ACCESS)).build();
    volTable.put("/" + volumeName, omVolumeArgs);
    final Table<String, PersistedUserVolumeInfo> userTable = omDb.getTable(OmMetadataManagerImpl.USER_TABLE, String.class, PersistedUserVolumeInfo.class);
    PersistedUserVolumeInfo currentUserVolumeInfo = userTable.get(getUserId());
    if (currentUserVolumeInfo == null) {
        currentUserVolumeInfo = PersistedUserVolumeInfo.newBuilder().addVolumeNames(volumeName).build();
    } else if (!currentUserVolumeInfo.getVolumeNamesList().contains(volumeName)) {
        currentUserVolumeInfo = PersistedUserVolumeInfo.newBuilder().addAllVolumeNames(currentUserVolumeInfo.getVolumeNamesList()).addVolumeNames(volumeName).build();
    }
    userTable.put(getUserId(), currentUserVolumeInfo);
    Table<String, OmBucketInfo> bucketTable = omDb.getTable(OmMetadataManagerImpl.BUCKET_TABLE, String.class, OmBucketInfo.class);
    OmBucketInfo omBucketInfo = new OmBucketInfo.Builder().setBucketName(bucketName).setVolumeName(volumeName).build();
    bucketTable.put("/" + volumeName + "/" + bucketName, omBucketInfo);
}
Also used : OmBucketInfo(org.apache.hadoop.ozone.om.helpers.OmBucketInfo) OzoneAcl(org.apache.hadoop.ozone.OzoneAcl) OmVolumeArgs(org.apache.hadoop.ozone.om.helpers.OmVolumeArgs) Builder(org.apache.hadoop.ozone.om.helpers.OmKeyInfo.Builder) DBStoreBuilder(org.apache.hadoop.hdds.utils.db.DBStoreBuilder) PersistedUserVolumeInfo(org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos.PersistedUserVolumeInfo)

Example 2 with PersistedUserVolumeInfo

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

the class OMVolumeDeleteResponse method addToDBBatch.

@Override
protected void addToDBBatch(OMMetadataManager omMetadataManager, BatchOperation batchOperation) throws IOException {
    String dbUserKey = omMetadataManager.getUserKey(owner);
    PersistedUserVolumeInfo volumeList = updatedVolumeList;
    if (updatedVolumeList.getVolumeNamesList().size() == 0) {
        omMetadataManager.getUserTable().deleteWithBatch(batchOperation, dbUserKey);
    } else {
        omMetadataManager.getUserTable().putWithBatch(batchOperation, dbUserKey, volumeList);
    }
    omMetadataManager.getVolumeTable().deleteWithBatch(batchOperation, omMetadataManager.getVolumeKey(volume));
}
Also used : PersistedUserVolumeInfo(org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos.PersistedUserVolumeInfo)

Example 3 with PersistedUserVolumeInfo

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

the class TestOMVolumeCreateResponse 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.CreateVolume).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);
    omVolumeCreateResponse.addToDBBatch(omMetadataManager, batchOperation);
    // Do manual commit and see whether addToBatch is successful or not.
    omMetadataManager.getStore().commitBatchOperation(batchOperation);
    Assert.assertEquals(1, omMetadataManager.countRowsInTable(omMetadataManager.getVolumeTable()));
    Assert.assertEquals(omVolumeArgs, omMetadataManager.getVolumeTable().iterator().next().getValue());
    Assert.assertEquals(volumeList, 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 4 with PersistedUserVolumeInfo

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

the class TestOMVolumeSetOwnerResponse method testAddToDBBatch.

@Test
public void testAddToDBBatch() throws Exception {
    String volumeName = UUID.randomUUID().toString();
    String oldOwner = "user1";
    PersistedUserVolumeInfo volumeList = PersistedUserVolumeInfo.newBuilder().setObjectID(1).setUpdateID(1).addVolumeNames(volumeName).build();
    OMResponse omResponse = OMResponse.newBuilder().setCmdType(OzoneManagerProtocolProtos.Type.SetVolumeProperty).setStatus(OzoneManagerProtocolProtos.Status.OK).setSuccess(true).setCreateVolumeResponse(CreateVolumeResponse.getDefaultInstance()).build();
    OmVolumeArgs omVolumeArgs = OmVolumeArgs.newBuilder().setOwnerName(oldOwner).setAdminName(oldOwner).setVolume(volumeName).setCreationTime(Time.now()).build();
    OMVolumeCreateResponse omVolumeCreateResponse = new OMVolumeCreateResponse(omResponse, omVolumeArgs, volumeList);
    String newOwner = "user2";
    PersistedUserVolumeInfo newOwnerVolumeList = PersistedUserVolumeInfo.newBuilder().setObjectID(1).setUpdateID(1).addVolumeNames(volumeName).build();
    PersistedUserVolumeInfo oldOwnerVolumeList = PersistedUserVolumeInfo.newBuilder().setObjectID(2).setUpdateID(2).build();
    OmVolumeArgs newOwnerVolumeArgs = OmVolumeArgs.newBuilder().setOwnerName(newOwner).setAdminName(newOwner).setVolume(volumeName).setCreationTime(omVolumeArgs.getCreationTime()).build();
    OMVolumeSetOwnerResponse omVolumeSetOwnerResponse = new OMVolumeSetOwnerResponse(omResponse, oldOwner, oldOwnerVolumeList, newOwnerVolumeList, newOwnerVolumeArgs);
    omVolumeCreateResponse.addToDBBatch(omMetadataManager, batchOperation);
    omVolumeSetOwnerResponse.addToDBBatch(omMetadataManager, batchOperation);
    // Do manual commit and see whether addToBatch is successful or not.
    omMetadataManager.getStore().commitBatchOperation(batchOperation);
    Assert.assertEquals(1, omMetadataManager.countRowsInTable(omMetadataManager.getVolumeTable()));
    Table.KeyValue<String, OmVolumeArgs> keyValue = omMetadataManager.getVolumeTable().iterator().next();
    Assert.assertEquals(omMetadataManager.getVolumeKey(volumeName), keyValue.getKey());
    Assert.assertEquals(newOwnerVolumeArgs, keyValue.getValue());
    Assert.assertEquals(volumeList, omMetadataManager.getUserTable().get(omMetadataManager.getUserKey(newOwner)));
}
Also used : Table(org.apache.hadoop.hdds.utils.db.Table) 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 5 with PersistedUserVolumeInfo

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

the class OzoneManager method addS3GVolumeToDB.

/**
 * Create volume which is required for S3Gateway operations.
 * @throws IOException
 */
private void addS3GVolumeToDB() throws IOException {
    String s3VolumeName = HddsClientUtils.getS3VolumeName(configuration);
    String dbVolumeKey = metadataManager.getVolumeKey(s3VolumeName);
    if (!s3VolumeName.equals(OzoneConfigKeys.OZONE_S3_VOLUME_NAME_DEFAULT)) {
        LOG.warn("Make sure that all S3Gateway use same volume name." + " Otherwise user need to manually create/configure Volume " + "configured by S3Gateway");
    }
    if (!metadataManager.getVolumeTable().isExist(dbVolumeKey)) {
        // the highest transaction ID is reserved for this operation.
        long transactionID = MAX_TRXN_ID + 1;
        long objectID = OmUtils.addEpochToTxId(metadataManager.getOmEpoch(), transactionID);
        String userName = UserGroupInformation.getCurrentUser().getShortUserName();
        // Add volume and user info to DB and cache.
        OmVolumeArgs omVolumeArgs = createS3VolumeInfo(s3VolumeName, objectID);
        String dbUserKey = metadataManager.getUserKey(userName);
        PersistedUserVolumeInfo userVolumeInfo = PersistedUserVolumeInfo.newBuilder().setObjectID(objectID).setUpdateID(transactionID).addVolumeNames(s3VolumeName).build();
        // Commit to DB.
        try (BatchOperation batchOperation = metadataManager.getStore().initBatchOperation()) {
            metadataManager.getVolumeTable().putWithBatch(batchOperation, dbVolumeKey, omVolumeArgs);
            metadataManager.getUserTable().putWithBatch(batchOperation, dbUserKey, userVolumeInfo);
            metadataManager.getStore().commitBatchOperation(batchOperation);
        }
        // Add to cache.
        metadataManager.getVolumeTable().addCacheEntry(new CacheKey<>(dbVolumeKey), new CacheValue<>(Optional.of(omVolumeArgs), transactionID));
        metadataManager.getUserTable().addCacheEntry(new CacheKey<>(dbUserKey), new CacheValue<>(Optional.of(userVolumeInfo), transactionID));
        LOG.info("Created Volume {} With Owner {} required for S3Gateway " + "operations.", s3VolumeName, userName);
    }
}
Also used : OmVolumeArgs(org.apache.hadoop.ozone.om.helpers.OmVolumeArgs) CertificateSignRequest.getEncodedString(org.apache.hadoop.hdds.security.x509.certificates.utils.CertificateSignRequest.getEncodedString) BatchOperation(org.apache.hadoop.hdds.utils.db.BatchOperation) 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