Search in sources :

Example 6 with OmVolumeArgs

use of org.apache.hadoop.ozone.om.helpers.OmVolumeArgs in project ozone by apache.

the class TestKeyManagerUnit method testLookupFileWithDnFailure.

@Test
public void testLookupFileWithDnFailure() throws IOException {
    final DatanodeDetails dnOne = MockDatanodeDetails.randomDatanodeDetails();
    final DatanodeDetails dnTwo = MockDatanodeDetails.randomDatanodeDetails();
    final DatanodeDetails dnThree = MockDatanodeDetails.randomDatanodeDetails();
    final DatanodeDetails dnFour = MockDatanodeDetails.randomDatanodeDetails();
    final DatanodeDetails dnFive = MockDatanodeDetails.randomDatanodeDetails();
    final DatanodeDetails dnSix = MockDatanodeDetails.randomDatanodeDetails();
    final Pipeline pipelineOne = Pipeline.newBuilder().setId(PipelineID.randomId()).setReplicationConfig(RatisReplicationConfig.getInstance(ReplicationFactor.THREE)).setState(Pipeline.PipelineState.OPEN).setLeaderId(dnOne.getUuid()).setNodes(Arrays.asList(dnOne, dnTwo, dnThree)).build();
    final Pipeline pipelineTwo = Pipeline.newBuilder().setId(PipelineID.randomId()).setReplicationConfig(RatisReplicationConfig.getInstance(ReplicationFactor.THREE)).setState(Pipeline.PipelineState.OPEN).setLeaderId(dnFour.getUuid()).setNodes(Arrays.asList(dnFour, dnFive, dnSix)).build();
    List<Long> containerIDs = new ArrayList<>();
    containerIDs.add(1L);
    List<ContainerWithPipeline> cps = new ArrayList<>();
    ContainerInfo ci = Mockito.mock(ContainerInfo.class);
    when(ci.getContainerID()).thenReturn(1L);
    cps.add(new ContainerWithPipeline(ci, pipelineTwo));
    when(containerClient.getContainerWithPipelineBatch(containerIDs)).thenReturn(cps);
    final OmVolumeArgs volumeArgs = OmVolumeArgs.newBuilder().setVolume("volumeOne").setAdminName("admin").setOwnerName("admin").build();
    OMRequestTestUtils.addVolumeToOM(metadataManager, volumeArgs);
    final OmBucketInfo bucketInfo = OmBucketInfo.newBuilder().setVolumeName("volumeOne").setBucketName("bucketOne").build();
    OMRequestTestUtils.addBucketToOM(metadataManager, bucketInfo);
    final OmKeyLocationInfo keyLocationInfo = new OmKeyLocationInfo.Builder().setBlockID(new BlockID(1L, 1L)).setPipeline(pipelineOne).setOffset(0).setLength(256000).build();
    final OmKeyInfo keyInfo = new OmKeyInfo.Builder().setVolumeName("volumeOne").setBucketName("bucketOne").setKeyName("keyOne").setOmKeyLocationInfos(singletonList(new OmKeyLocationInfoGroup(0, singletonList(keyLocationInfo)))).setCreationTime(Time.now()).setModificationTime(Time.now()).setDataSize(256000).setReplicationConfig(RatisReplicationConfig.getInstance(ReplicationFactor.THREE)).setAcls(Collections.emptyList()).build();
    OMRequestTestUtils.addKeyToOM(metadataManager, keyInfo);
    final OmKeyArgs.Builder keyArgs = new OmKeyArgs.Builder().setVolumeName("volumeOne").setBucketName("bucketOne").setKeyName("keyOne");
    final OmKeyInfo newKeyInfo = keyManager.lookupFile(keyArgs.build(), "test");
    final OmKeyLocationInfo newBlockLocation = newKeyInfo.getLatestVersionLocations().getBlocksLatestVersionOnly().get(0);
    Assert.assertEquals(1L, newBlockLocation.getContainerID());
    Assert.assertEquals(1L, newBlockLocation.getBlockID().getLocalID());
    Assert.assertEquals(pipelineTwo.getId(), newBlockLocation.getPipeline().getId());
    Assert.assertTrue(newBlockLocation.getPipeline().getNodes().contains(dnFour));
    Assert.assertTrue(newBlockLocation.getPipeline().getNodes().contains(dnFive));
    Assert.assertTrue(newBlockLocation.getPipeline().getNodes().contains(dnSix));
}
Also used : OmBucketInfo(org.apache.hadoop.ozone.om.helpers.OmBucketInfo) OmVolumeArgs(org.apache.hadoop.ozone.om.helpers.OmVolumeArgs) Builder(org.apache.hadoop.ozone.om.helpers.OmKeyArgs.Builder) Builder(org.apache.hadoop.ozone.om.helpers.OmKeyArgs.Builder) ArrayList(java.util.ArrayList) ContainerWithPipeline(org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline) OmKeyArgs(org.apache.hadoop.ozone.om.helpers.OmKeyArgs) OmKeyLocationInfo(org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo) MockPipeline(org.apache.hadoop.hdds.scm.pipeline.MockPipeline) ContainerWithPipeline(org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline) Pipeline(org.apache.hadoop.hdds.scm.pipeline.Pipeline) OmKeyLocationInfoGroup(org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup) MockDatanodeDetails(org.apache.hadoop.hdds.protocol.MockDatanodeDetails) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) ContainerInfo(org.apache.hadoop.hdds.scm.container.ContainerInfo) OmKeyInfo(org.apache.hadoop.ozone.om.helpers.OmKeyInfo) BlockID(org.apache.hadoop.hdds.client.BlockID) Test(org.junit.Test)

Example 7 with OmVolumeArgs

use of org.apache.hadoop.ozone.om.helpers.OmVolumeArgs in project ozone by apache.

the class OMRequestTestUtils method addVolumeToDB.

/**
 * Add volume creation entry to OM DB.
 * @param volumeName
 * @param omMetadataManager
 * @param quotaInBytes
 * @throws Exception
 */
public static void addVolumeToDB(String volumeName, OMMetadataManager omMetadataManager, long quotaInBytes) throws Exception {
    OmVolumeArgs omVolumeArgs = OmVolumeArgs.newBuilder().setCreationTime(Time.now()).setVolume(volumeName).setAdminName(volumeName).setOwnerName(volumeName).setQuotaInBytes(quotaInBytes).setQuotaInNamespace(10000L).build();
    omMetadataManager.getVolumeTable().put(omMetadataManager.getVolumeKey(volumeName), omVolumeArgs);
    // Add to cache.
    omMetadataManager.getVolumeTable().addCacheEntry(new CacheKey<>(omMetadataManager.getVolumeKey(volumeName)), new CacheValue<>(Optional.of(omVolumeArgs), 1L));
}
Also used : OmVolumeArgs(org.apache.hadoop.ozone.om.helpers.OmVolumeArgs)

Example 8 with OmVolumeArgs

use of org.apache.hadoop.ozone.om.helpers.OmVolumeArgs in project ozone by apache.

the class OMRequestTestUtils method addVolumeToDB.

/**
 * Add volume creation entry to OM DB.
 * @param volumeName
 * @param ownerName
 * @param omMetadataManager
 * @throws Exception
 */
public static void addVolumeToDB(String volumeName, String ownerName, OMMetadataManager omMetadataManager) throws Exception {
    OmVolumeArgs omVolumeArgs = OmVolumeArgs.newBuilder().setCreationTime(Time.now()).setVolume(volumeName).setAdminName(ownerName).setOwnerName(ownerName).setQuotaInBytes(Long.MAX_VALUE).setQuotaInNamespace(10000L).build();
    omMetadataManager.getVolumeTable().put(omMetadataManager.getVolumeKey(volumeName), omVolumeArgs);
    // Add to cache.
    omMetadataManager.getVolumeTable().addCacheEntry(new CacheKey<>(omMetadataManager.getVolumeKey(volumeName)), new CacheValue<>(Optional.of(omVolumeArgs), 1L));
}
Also used : OmVolumeArgs(org.apache.hadoop.ozone.om.helpers.OmVolumeArgs)

Example 9 with OmVolumeArgs

use of org.apache.hadoop.ozone.om.helpers.OmVolumeArgs in project ozone by apache.

the class TestBucketManagerImpl method testGetBucketInfo.

@Test
public void testGetBucketInfo() throws Exception {
    final String volumeName = "sampleVol";
    final String bucketName = "bucketOne";
    OmMetadataManagerImpl metaMgr = createSampleVol();
    BucketManager bucketManager = new BucketManagerImpl(metaMgr);
    // Check exception thrown when volume does not exist
    try {
        bucketManager.getBucketInfo(volumeName, bucketName);
        Assert.fail("Should have thrown OMException");
    } catch (OMException omEx) {
        Assert.assertEquals("getBucketInfo() should have thrown " + "VOLUME_NOT_FOUND as the parent volume is not created!", ResultCodes.VOLUME_NOT_FOUND, omEx.getResult());
    }
    OmBucketInfo bucketInfo = OmBucketInfo.newBuilder().setVolumeName(volumeName).setBucketName(bucketName).setStorageType(StorageType.DISK).setIsVersionEnabled(false).build();
    // Note: the helper method createBucket() in this scope won't create the
    // parent volume DB entry. In order to verify getBucketInfo's behavior, we
    // need to create the volume entry in DB manually.
    OmVolumeArgs args = OmVolumeArgs.newBuilder().setVolume(volumeName).setAdminName("bilbo").setOwnerName("bilbo").build();
    OMRequestTestUtils.addVolumeToOM(metaMgr, args);
    // Create bucket
    createBucket(metaMgr, bucketInfo);
    // Check exception thrown when bucket does not exist
    try {
        bucketManager.getBucketInfo(volumeName, "bucketNotExist");
        Assert.fail("Should have thrown OMException");
    } catch (OMException omEx) {
        Assert.assertEquals("getBucketInfo() should have thrown " + "BUCKET_NOT_FOUND as the parent volume exists but bucket " + "doesn't!", ResultCodes.BUCKET_NOT_FOUND, omEx.getResult());
    }
    OmBucketInfo result = bucketManager.getBucketInfo(volumeName, bucketName);
    Assert.assertEquals(volumeName, result.getVolumeName());
    Assert.assertEquals(bucketName, result.getBucketName());
    Assert.assertEquals(StorageType.DISK, result.getStorageType());
    Assert.assertFalse(result.getIsVersionEnabled());
    metaMgr.getStore().close();
}
Also used : OmBucketInfo(org.apache.hadoop.ozone.om.helpers.OmBucketInfo) OmVolumeArgs(org.apache.hadoop.ozone.om.helpers.OmVolumeArgs) OMException(org.apache.hadoop.ozone.om.exceptions.OMException) Test(org.junit.Test)

Example 10 with OmVolumeArgs

use of org.apache.hadoop.ozone.om.helpers.OmVolumeArgs in project ozone by apache.

the class TestOzoneManagerDoubleBufferWithOMResponse method checkVolume.

/**
 * Verifies volume table data is matching with actual response added to
 * double buffer.
 */
private void checkVolume(String volumeName, OMVolumeCreateResponse omVolumeCreateResponse) throws Exception {
    OmVolumeArgs tableVolumeArgs = omMetadataManager.getVolumeTable().get(omMetadataManager.getVolumeKey(volumeName));
    Assert.assertNotNull(tableVolumeArgs);
    OmVolumeArgs omVolumeArgs = omVolumeCreateResponse.getOmVolumeArgs();
    Assert.assertEquals(omVolumeArgs.getVolume(), tableVolumeArgs.getVolume());
    Assert.assertEquals(omVolumeArgs.getAdminName(), tableVolumeArgs.getAdminName());
    Assert.assertEquals(omVolumeArgs.getOwnerName(), tableVolumeArgs.getOwnerName());
    Assert.assertEquals(omVolumeArgs.getCreationTime(), tableVolumeArgs.getCreationTime());
}
Also used : OmVolumeArgs(org.apache.hadoop.ozone.om.helpers.OmVolumeArgs)

Aggregations

OmVolumeArgs (org.apache.hadoop.ozone.om.helpers.OmVolumeArgs)70 OMException (org.apache.hadoop.ozone.om.exceptions.OMException)19 IOException (java.io.IOException)18 Test (org.junit.Test)18 OmBucketInfo (org.apache.hadoop.ozone.om.helpers.OmBucketInfo)16 OMResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse)15 OMClientResponse (org.apache.hadoop.ozone.om.response.OMClientResponse)13 OMMetadataManager (org.apache.hadoop.ozone.om.OMMetadataManager)12 ArrayList (java.util.ArrayList)9 OMMetrics (org.apache.hadoop.ozone.om.OMMetrics)8 OzoneManagerProtocolProtos (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos)7 OMRequest (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest)7 OzoneConfiguration (org.apache.hadoop.hdds.conf.OzoneConfiguration)6 OzoneAcl (org.apache.hadoop.ozone.OzoneAcl)6 PersistedUserVolumeInfo (org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos.PersistedUserVolumeInfo)6 AuditLogger (org.apache.hadoop.ozone.audit.AuditLogger)5 OmMetadataManagerImpl (org.apache.hadoop.ozone.om.OmMetadataManagerImpl)5 OmKeyInfo (org.apache.hadoop.ozone.om.helpers.OmKeyInfo)5 CertificateSignRequest.getEncodedString (org.apache.hadoop.hdds.security.x509.certificates.utils.CertificateSignRequest.getEncodedString)4 GET (javax.ws.rs.GET)3