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