Search in sources :

Example 6 with OzoneVolume

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());
}
Also used : Path(org.apache.hadoop.fs.Path) OFSPath(org.apache.hadoop.ozone.OFSPath) OzoneVolume(org.apache.hadoop.ozone.client.OzoneVolume) OFSPath(org.apache.hadoop.ozone.OFSPath)

Example 7 with OzoneVolume

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);
}
Also used : Path(org.apache.hadoop.fs.Path) OFSPath(org.apache.hadoop.ozone.OFSPath) OzoneVolume(org.apache.hadoop.ozone.client.OzoneVolume) Test(org.junit.Test)

Example 8 with OzoneVolume

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());
}
Also used : OzoneManagerProtocol(org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) OzoneClientConfig(org.apache.hadoop.hdds.scm.OzoneClientConfig) MD5MD5CRC32GzipFileChecksum(org.apache.hadoop.fs.MD5MD5CRC32GzipFileChecksum) MockXceiverClientFactory(org.apache.hadoop.ozone.client.MockXceiverClientFactory) XceiverClientFactory(org.apache.hadoop.hdds.scm.XceiverClientFactory) OmKeyLocationInfo(org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo) MD5MD5CRC32GzipFileChecksum(org.apache.hadoop.fs.MD5MD5CRC32GzipFileChecksum) FileChecksum(org.apache.hadoop.fs.FileChecksum) Pipeline(org.apache.hadoop.hdds.scm.pipeline.Pipeline) OzoneVolume(org.apache.hadoop.ozone.client.OzoneVolume) OzoneBucket(org.apache.hadoop.ozone.client.OzoneBucket) OmKeyLocationInfoGroup(org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) XceiverClientGrpc(org.apache.hadoop.hdds.scm.XceiverClientGrpc) OmKeyInfo(org.apache.hadoop.ozone.om.helpers.OmKeyInfo) BlockID(org.apache.hadoop.hdds.client.BlockID) RpcClient(org.apache.hadoop.ozone.client.rpc.RpcClient) Test(org.junit.Test)

Example 9 with OzoneVolume

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;
    }
}
Also used : OzoneVolume(org.apache.hadoop.ozone.client.OzoneVolume) OzoneBucket(org.apache.hadoop.ozone.client.OzoneBucket)

Example 10 with OzoneVolume

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;
    }
}
Also used : OzoneVolume(org.apache.hadoop.ozone.client.OzoneVolume) OzoneBucket(org.apache.hadoop.ozone.client.OzoneBucket) ArrayList(java.util.ArrayList)

Aggregations

OzoneVolume (org.apache.hadoop.ozone.client.OzoneVolume)244 OzoneBucket (org.apache.hadoop.ozone.client.OzoneBucket)190 Test (org.junit.Test)88 Test (org.junit.jupiter.api.Test)78 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)72 OzoneOutputStream (org.apache.hadoop.ozone.client.io.OzoneOutputStream)62 BucketArgs (org.apache.hadoop.ozone.client.BucketArgs)36 ObjectStore (org.apache.hadoop.ozone.client.ObjectStore)36 IOException (java.io.IOException)28 OMException (org.apache.hadoop.ozone.om.exceptions.OMException)27 OzoneClient (org.apache.hadoop.ozone.client.OzoneClient)26 ArrayList (java.util.ArrayList)23 OzoneInputStream (org.apache.hadoop.ozone.client.io.OzoneInputStream)23 Path (org.apache.hadoop.fs.Path)19 OzoneKey (org.apache.hadoop.ozone.client.OzoneKey)19 OmMultipartInfo (org.apache.hadoop.ozone.om.helpers.OmMultipartInfo)19 HashMap (java.util.HashMap)18 OzoneAcl (org.apache.hadoop.ozone.OzoneAcl)17 OzoneKeyDetails (org.apache.hadoop.ozone.client.OzoneKeyDetails)16 VolumeArgs (org.apache.hadoop.ozone.client.VolumeArgs)16