Search in sources :

Example 1 with OMResponse

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)));
}
Also used : OmDirectoryInfo(org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo) OMResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse) Test(org.junit.Test)

Example 2 with OMResponse

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());
}
Also used : OMRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest) OzoneAcl(org.apache.hadoop.ozone.OzoneAcl) OMClientResponse(org.apache.hadoop.ozone.om.response.OMClientResponse) OMKeyAclRequest(org.apache.hadoop.ozone.om.request.key.acl.OMKeyAclRequest) OmKeyInfo(org.apache.hadoop.ozone.om.helpers.OmKeyInfo) OMResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse) Test(org.junit.Test)

Example 3 with OMResponse

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);
}
Also used : OMRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest) OzoneAcl(org.apache.hadoop.ozone.OzoneAcl) OMClientResponse(org.apache.hadoop.ozone.om.response.OMClientResponse) OMKeyAclRequest(org.apache.hadoop.ozone.om.request.key.acl.OMKeyAclRequest) OmKeyInfo(org.apache.hadoop.ozone.om.helpers.OmKeyInfo) OMResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse) Test(org.junit.Test)

Example 4 with OMResponse

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());
}
Also used : OMRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest) OzoneAcl(org.apache.hadoop.ozone.OzoneAcl) OMClientResponse(org.apache.hadoop.ozone.om.response.OMClientResponse) OMResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse) Test(org.junit.Test)

Example 5 with OMResponse

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));
}
Also used : OMRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest) OzoneAcl(org.apache.hadoop.ozone.OzoneAcl) OmVolumeArgs(org.apache.hadoop.ozone.om.helpers.OmVolumeArgs) OMClientResponse(org.apache.hadoop.ozone.om.response.OMClientResponse) OMResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse) Test(org.junit.Test)

Aggregations

OMResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse)99 OMClientResponse (org.apache.hadoop.ozone.om.response.OMClientResponse)61 IOException (java.io.IOException)51 OMMetadataManager (org.apache.hadoop.ozone.om.OMMetadataManager)39 Test (org.junit.Test)37 OmKeyInfo (org.apache.hadoop.ozone.om.helpers.OmKeyInfo)31 OMException (org.apache.hadoop.ozone.om.exceptions.OMException)30 OMRequest (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest)28 OMMetrics (org.apache.hadoop.ozone.om.OMMetrics)25 OmBucketInfo (org.apache.hadoop.ozone.om.helpers.OmBucketInfo)25 OzoneAcl (org.apache.hadoop.ozone.OzoneAcl)19 AuditLogger (org.apache.hadoop.ozone.audit.AuditLogger)18 OzoneManagerProtocolProtos (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos)18 KeyArgs (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.KeyArgs)17 OmVolumeArgs (org.apache.hadoop.ozone.om.helpers.OmVolumeArgs)16 ArrayList (java.util.ArrayList)15 OmKeyLocationInfo (org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo)10 RepeatedOmKeyInfo (org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo)9 OmMultipartKeyInfo (org.apache.hadoop.ozone.om.helpers.OmMultipartKeyInfo)6 ServiceException (com.google.protobuf.ServiceException)4