use of org.apache.hadoop.ozone.client.OzoneVolume in project ozone by apache.
the class TestRootedOzoneFileSystem method teardownVolumeBucketWithDir.
private void teardownVolumeBucketWithDir(Path bucketPath1) throws IOException {
fs.delete(new Path(bucketPath1, "dir1"), true);
fs.delete(new Path(bucketPath1, "dir2"), true);
OFSPath ofsPath = new OFSPath(bucketPath1);
OzoneVolume volume = objectStore.getVolume(ofsPath.getVolumeName());
volume.deleteBucket(ofsPath.getBucketName());
objectStore.deleteVolume(ofsPath.getVolumeName());
}
use of org.apache.hadoop.ozone.client.OzoneVolume in project ozone by apache.
the class TestRootedOzoneFileSystem method testMkdirNonExistentVolume.
/**
* OFS: Test mkdir on a volume that doesn't exist.
*/
@Test
public void testMkdirNonExistentVolume() throws Exception {
String volumeNameLocal = getRandomNonExistVolumeName();
Path newVolume = new Path("/" + volumeNameLocal);
fs.mkdirs(newVolume);
// Verify with listVolumes and listBuckets
Iterator<? extends OzoneVolume> iterVol = objectStore.listVolumesByUser(null, volumeNameLocal, null);
OzoneVolume ozoneVolume = iterVol.next();
Assert.assertNotNull(ozoneVolume);
Assert.assertEquals(volumeNameLocal, ozoneVolume.getName());
// TODO: Use listStatus to check volume and bucket creation in HDDS-2928.
// Cleanup
objectStore.deleteVolume(volumeNameLocal);
}
use of org.apache.hadoop.ozone.client.OzoneVolume in project ozone by apache.
the class TestReplicatedFileChecksumHelper method testOneBlock.
@Test
public void testOneBlock() throws IOException {
// test the file checksum of a file with one block.
OzoneConfiguration conf = new OzoneConfiguration();
RpcClient mockRpcClient = Mockito.mock(RpcClient.class);
List<DatanodeDetails> dns = Arrays.asList(DatanodeDetails.newBuilder().setUuid(UUID.randomUUID()).build());
Pipeline pipeline;
pipeline = Pipeline.newBuilder().setId(PipelineID.randomId()).setReplicationConfig(RatisReplicationConfig.getInstance(HddsProtos.ReplicationFactor.THREE)).setState(Pipeline.PipelineState.CLOSED).setNodes(dns).build();
XceiverClientGrpc xceiverClientGrpc = new XceiverClientGrpc(pipeline, conf) {
@Override
public XceiverClientReply sendCommandAsync(ContainerProtos.ContainerCommandRequestProto request, DatanodeDetails dn) {
return buildValidResponse();
}
};
XceiverClientFactory factory = Mockito.mock(XceiverClientFactory.class);
when(factory.acquireClientForReadData(ArgumentMatchers.any())).thenReturn(xceiverClientGrpc);
when(mockRpcClient.getXceiverClientManager()).thenReturn(factory);
OzoneManagerProtocol om = Mockito.mock(OzoneManagerProtocol.class);
when(mockRpcClient.getOzoneManagerClient()).thenReturn(om);
BlockID blockID = new BlockID(1, 1);
OmKeyLocationInfo omKeyLocationInfo = new OmKeyLocationInfo.Builder().setPipeline(pipeline).setBlockID(blockID).build();
List<OmKeyLocationInfo> omKeyLocationInfoList = Arrays.asList(omKeyLocationInfo);
OmKeyInfo omKeyInfo = new OmKeyInfo.Builder().setVolumeName(null).setBucketName(null).setKeyName(null).setOmKeyLocationInfos(Collections.singletonList(new OmKeyLocationInfoGroup(0, omKeyLocationInfoList))).setCreationTime(Time.now()).setModificationTime(Time.now()).setDataSize(0).setReplicationConfig(RatisReplicationConfig.getInstance(HddsProtos.ReplicationFactor.ONE)).setFileEncryptionInfo(null).setAcls(null).build();
when(om.lookupKey(ArgumentMatchers.any())).thenReturn(omKeyInfo);
OzoneVolume mockVolume = Mockito.mock(OzoneVolume.class);
when(mockVolume.getName()).thenReturn("vol1");
OzoneBucket bucket = Mockito.mock(OzoneBucket.class);
when(bucket.getName()).thenReturn("bucket1");
OzoneClientConfig.ChecksumCombineMode combineMode = OzoneClientConfig.ChecksumCombineMode.MD5MD5CRC;
ReplicatedFileChecksumHelper helper = new ReplicatedFileChecksumHelper(mockVolume, bucket, "dummy", 10, combineMode, mockRpcClient);
helper.compute();
FileChecksum fileChecksum = helper.getFileChecksum();
assertTrue(fileChecksum instanceof MD5MD5CRC32GzipFileChecksum);
assertEquals(1, helper.getKeyLocationInfoList().size());
FileChecksum cachedChecksum = new MD5MD5CRC32GzipFileChecksum();
// / test cached checksum
OmKeyInfo omKeyInfoWithChecksum = new OmKeyInfo.Builder().setVolumeName(null).setBucketName(null).setKeyName(null).setOmKeyLocationInfos(Collections.singletonList(new OmKeyLocationInfoGroup(0, omKeyLocationInfoList))).setCreationTime(Time.now()).setModificationTime(Time.now()).setDataSize(0).setReplicationConfig(RatisReplicationConfig.getInstance(HddsProtos.ReplicationFactor.ONE)).setFileEncryptionInfo(null).setAcls(null).setFileChecksum(cachedChecksum).build();
when(om.lookupKey(ArgumentMatchers.any())).thenReturn(omKeyInfoWithChecksum);
helper = new ReplicatedFileChecksumHelper(mockVolume, bucket, "dummy", 10, combineMode, mockRpcClient);
helper.compute();
fileChecksum = helper.getFileChecksum();
assertTrue(fileChecksum instanceof MD5MD5CRC32GzipFileChecksum);
assertEquals(1, helper.getKeyLocationInfoList().size());
}
use of org.apache.hadoop.ozone.client.OzoneVolume in project ozone by apache.
the class RandomKeyGenerator method createBucket.
private boolean createBucket(int globalBucketNumber) {
int volumeNumber = globalBucketNumber % numOfVolumes;
int bucketNumber = globalBucketNumber / numOfVolumes;
OzoneVolume volume = getVolume(volumeNumber);
if (volume == null) {
LOG.error("Could not find volume {}", volumeNumber);
return false;
}
String bucketName = "bucket-" + bucketNumber + "-" + RandomStringUtils.randomNumeric(5);
LOG.trace("Creating bucket: {} in volume: {}", bucketName, volume.getName());
try (AutoCloseable scope = TracingUtil.createActivatedSpan("createBucket")) {
long start = System.nanoTime();
volume.createBucket(bucketName);
long bucketCreationDuration = System.nanoTime() - start;
histograms.get(FreonOps.BUCKET_CREATE.ordinal()).update(bucketCreationDuration);
bucketCreationTime.getAndAdd(bucketCreationDuration);
numberOfBucketsCreated.getAndIncrement();
OzoneBucket bucket = volume.getBucket(bucketName);
buckets.put(globalBucketNumber, bucket);
return true;
} catch (Throwable e) {
exception = e;
LOG.error("Could not create bucket ", e);
return false;
}
}
use of org.apache.hadoop.ozone.client.OzoneVolume in project ozone by apache.
the class RandomKeyGenerator method cleanBucket.
private boolean cleanBucket(int globalBucketNumber) {
int volumeNumber = globalBucketNumber % numOfVolumes;
OzoneVolume volume = getVolume(volumeNumber);
OzoneBucket bucket = getBucket(globalBucketNumber);
String bucketName = bucket.getName();
if (volume == null) {
LOG.error("Could not find volume {}", volumeNumber);
return false;
}
LOG.trace("Cleaning bucket: {} in volume: {}", bucketName, volume.getName());
ArrayList<String> keys = new ArrayList<>();
try {
bucket.listKeys(null).forEachRemaining(x -> keys.add(x.getName()));
bucket.deleteKeys(keys);
volume.deleteBucket(bucketName);
numberOfBucketsCleaned.getAndIncrement();
return true;
} catch (Throwable e) {
exception = e;
LOG.error("Could not clean bucket ", e);
return false;
}
}
Aggregations