use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse in project ozone by apache.
the class TestOMDirectoryCreateResponseWithFSO method testAddToDBBatch.
@Test
public void testAddToDBBatch() throws Exception {
String keyName = UUID.randomUUID().toString();
long parentID = 100;
OmDirectoryInfo omDirInfo = OMRequestTestUtils.createOmDirectoryInfo(keyName, 500, parentID);
OMResponse omResponse = OMResponse.newBuilder().setCreateDirectoryResponse(OzoneManagerProtocolProtos.CreateDirectoryResponse.getDefaultInstance()).setStatus(OzoneManagerProtocolProtos.Status.OK).setCmdType(OzoneManagerProtocolProtos.Type.CreateDirectory).build();
OMDirectoryCreateResponseWithFSO omDirectoryCreateResponseWithFSO = new OMDirectoryCreateResponseWithFSO(omResponse, omDirInfo, new ArrayList<>(), OMDirectoryCreateRequestWithFSO.Result.SUCCESS, BucketLayout.FILE_SYSTEM_OPTIMIZED);
omDirectoryCreateResponseWithFSO.addToDBBatch(omMetadataManager, batchOperation);
// Do manual commit and see whether addToBatch is successful or not.
omMetadataManager.getStore().commitBatchOperation(batchOperation);
Assert.assertNotNull(omMetadataManager.getDirectoryTable().get(omMetadataManager.getOzonePathKey(parentID, keyName)));
}
use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse in project ozone by apache.
the class TestOMKeyAclRequest method testKeyRemoveAclRequest.
@Test
public void testKeyRemoveAclRequest() throws Exception {
OMRequestTestUtils.addVolumeAndBucketToDB(volumeName, bucketName, omMetadataManager, getBucketLayout());
String ozoneKey = addKeyToTable();
OmKeyInfo omKeyInfo = omMetadataManager.getKeyTable(getBucketLayout()).get(ozoneKey);
// As we added manually to key table.
Assert.assertNotNull(omKeyInfo);
OzoneAcl acl = OzoneAcl.parseAcl("user:bilbo:rwdlncxy[ACCESS]");
// Add acl.
OMRequest addAclRequest = createAddAclkeyRequest(acl);
OMKeyAclRequest omKeyAddAclRequest = getOmKeyAddAclRequest(addAclRequest);
omKeyAddAclRequest.preExecute(ozoneManager);
OMClientResponse omClientAddAclResponse = omKeyAddAclRequest.validateAndUpdateCache(ozoneManager, 100L, ozoneManagerDoubleBufferHelper);
OMResponse omAddAclResponse = omClientAddAclResponse.getOMResponse();
Assert.assertNotNull(omAddAclResponse.getAddAclResponse());
Assert.assertEquals(OzoneManagerProtocolProtos.Status.OK, omAddAclResponse.getStatus());
// Verify result of adding acl.
List<OzoneAcl> keyAcls = omMetadataManager.getKeyTable(getBucketLayout()).get(ozoneKey).getAcls();
Assert.assertEquals(1, keyAcls.size());
Assert.assertEquals(acl, keyAcls.get(0));
// Remove acl.
OMRequest removeAclRequest = createRemoveAclKeyRequest(acl);
OMKeyAclRequest omKeyRemoveAclRequest = getOmKeyRemoveAclRequest(removeAclRequest);
OMRequest preExecuteRequest = omKeyRemoveAclRequest.preExecute(ozoneManager);
// When preExecute() of removing acl,
// the new modification time is greater than origin one.
long originModTime = removeAclRequest.getRemoveAclRequest().getModificationTime();
long newModTime = preExecuteRequest.getRemoveAclRequest().getModificationTime();
Assert.assertTrue(newModTime > originModTime);
OMClientResponse omClientRemoveAclResponse = omKeyRemoveAclRequest.validateAndUpdateCache(ozoneManager, 100L, ozoneManagerDoubleBufferHelper);
OMResponse omRemoveAclResponse = omClientRemoveAclResponse.getOMResponse();
Assert.assertNotNull(omRemoveAclResponse.getRemoveAclResponse());
Assert.assertEquals(OzoneManagerProtocolProtos.Status.OK, omRemoveAclResponse.getStatus());
// Verify result of removing acl.
List<OzoneAcl> newAcls = omMetadataManager.getKeyTable(getBucketLayout()).get(ozoneKey).getAcls();
Assert.assertEquals(0, newAcls.size());
}
use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse in project ozone by apache.
the class TestOMKeyAclRequest method testKeySetAclRequest.
@Test
public void testKeySetAclRequest() throws Exception {
OMRequestTestUtils.addVolumeAndBucketToDB(volumeName, bucketName, omMetadataManager, getBucketLayout());
String ozoneKey = addKeyToTable();
OmKeyInfo omKeyInfo = omMetadataManager.getKeyTable(getBucketLayout()).get(ozoneKey);
// As we added manually to key table.
Assert.assertNotNull(omKeyInfo);
OzoneAcl acl = OzoneAcl.parseAcl("user:bilbo:rwdlncxy[ACCESS]");
OMRequest setAclRequest = createSetAclKeyRequest(acl);
OMKeyAclRequest omKeySetAclRequest = getOmKeySetAclRequest(setAclRequest);
OMRequest preExecuteRequest = omKeySetAclRequest.preExecute(ozoneManager);
// When preExecute() of setting acl,
// the new modification time is greater than origin one.
long originModTime = setAclRequest.getSetAclRequest().getModificationTime();
long newModTime = preExecuteRequest.getSetAclRequest().getModificationTime();
Assert.assertTrue(newModTime > originModTime);
OMClientResponse omClientResponse = omKeySetAclRequest.validateAndUpdateCache(ozoneManager, 100L, ozoneManagerDoubleBufferHelper);
OMResponse omSetAclResponse = omClientResponse.getOMResponse();
Assert.assertNotNull(omSetAclResponse.getSetAclResponse());
Assert.assertEquals(OzoneManagerProtocolProtos.Status.OK, omSetAclResponse.getStatus());
// Verify result of setting acl.
List<OzoneAcl> newAcls = omMetadataManager.getKeyTable(getBucketLayout()).get(ozoneKey).getAcls();
Assert.assertEquals(newAcls.get(0), acl);
}
use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse in project ozone by apache.
the class TestOMVolumeAddAclRequest method testValidateAndUpdateCacheWithVolumeNotFound.
@Test
public void testValidateAndUpdateCacheWithVolumeNotFound() throws Exception {
String volumeName = UUID.randomUUID().toString();
OzoneAcl acl = OzoneAcl.parseAcl("user:bilbo:rw");
OMRequest originalRequest = OMRequestTestUtils.createVolumeAddAclRequest(volumeName, acl);
OMVolumeAddAclRequest omVolumeAddAclRequest = new OMVolumeAddAclRequest(originalRequest);
omVolumeAddAclRequest.preExecute(ozoneManager);
OMClientResponse omClientResponse = omVolumeAddAclRequest.validateAndUpdateCache(ozoneManager, 1, ozoneManagerDoubleBufferHelper);
OMResponse omResponse = omClientResponse.getOMResponse();
Assert.assertNotNull(omResponse.getAddAclResponse());
Assert.assertEquals(OzoneManagerProtocolProtos.Status.VOLUME_NOT_FOUND, omResponse.getStatus());
}
use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse in project ozone by apache.
the class TestOMVolumeAddAclRequest method testValidateAndUpdateCacheSuccess.
@Test
public void testValidateAndUpdateCacheSuccess() throws Exception {
String volumeName = UUID.randomUUID().toString();
String ownerName = "user1";
OMRequestTestUtils.addUserToDB(volumeName, ownerName, omMetadataManager);
OMRequestTestUtils.addVolumeToDB(volumeName, ownerName, omMetadataManager);
OzoneAcl acl = OzoneAcl.parseAcl("user:bilbo:rwdlncxy[ACCESS]");
OMRequest originalRequest = OMRequestTestUtils.createVolumeAddAclRequest(volumeName, acl);
OMVolumeAddAclRequest omVolumeAddAclRequest = new OMVolumeAddAclRequest(originalRequest);
omVolumeAddAclRequest.preExecute(ozoneManager);
String volumeKey = omMetadataManager.getVolumeKey(volumeName);
// Get Acl before validateAndUpdateCache.
OmVolumeArgs omVolumeArgs = omMetadataManager.getVolumeTable().get(volumeKey);
// As request is valid volume table should have entry.
Assert.assertNotNull(omVolumeArgs);
OMClientResponse omClientResponse = omVolumeAddAclRequest.validateAndUpdateCache(ozoneManager, 1, ozoneManagerDoubleBufferHelper);
OMResponse omResponse = omClientResponse.getOMResponse();
Assert.assertNotNull(omResponse.getAddAclResponse());
Assert.assertEquals(OzoneManagerProtocolProtos.Status.OK, omResponse.getStatus());
List<OzoneAcl> aclsAfterSet = omMetadataManager.getVolumeTable().get(volumeKey).getAcls();
// acl is added to aclMapAfterSet
Assert.assertEquals(1, aclsAfterSet.size());
Assert.assertEquals(acl, aclsAfterSet.get(0));
}
Aggregations