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