Search in sources :

Example 26 with OzoneKeyDetails

use of org.apache.hadoop.ozone.client.OzoneKeyDetails in project ozone by apache.

the class TestSCMPipelineBytesWrittenMetrics method writeNumBytes.

private void writeNumBytes(int numBytes) throws Exception {
    ObjectStore store = OzoneClientFactory.getRpcClient(conf).getObjectStore();
    String volumeName = UUID.randomUUID().toString();
    String bucketName = UUID.randomUUID().toString();
    String value = RandomStringUtils.randomAlphabetic(numBytes);
    store.createVolume(volumeName);
    OzoneVolume volume = store.getVolume(volumeName);
    volume.createBucket(bucketName);
    OzoneBucket bucket = volume.getBucket(bucketName);
    String keyName = UUID.randomUUID().toString();
    OzoneOutputStream out = bucket.createKey(keyName, value.getBytes(UTF_8).length, ReplicationType.RATIS, ReplicationFactor.THREE, new HashMap<>());
    out.write(value.getBytes(UTF_8));
    out.close();
    OmKeyArgs.Builder builder = new OmKeyArgs.Builder();
    builder.setVolumeName(volumeName).setBucketName(bucketName).setKeyName(keyName).setRefreshPipeline(true);
    OzoneKeyDetails keyDetails = bucket.getKey(keyName);
    Assert.assertEquals(keyName, keyDetails.getName());
    Assert.assertEquals(value.getBytes(UTF_8).length, keyDetails.getOzoneKeyLocations().get(0).getLength());
}
Also used : OzoneVolume(org.apache.hadoop.ozone.client.OzoneVolume) OzoneBucket(org.apache.hadoop.ozone.client.OzoneBucket) ObjectStore(org.apache.hadoop.ozone.client.ObjectStore) OzoneKeyDetails(org.apache.hadoop.ozone.client.OzoneKeyDetails) MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder) OzoneOutputStream(org.apache.hadoop.ozone.client.io.OzoneOutputStream) OmKeyArgs(org.apache.hadoop.ozone.om.helpers.OmKeyArgs)

Aggregations

OzoneKeyDetails (org.apache.hadoop.ozone.client.OzoneKeyDetails)26 OzoneBucket (org.apache.hadoop.ozone.client.OzoneBucket)17 OzoneOutputStream (org.apache.hadoop.ozone.client.io.OzoneOutputStream)16 OzoneVolume (org.apache.hadoop.ozone.client.OzoneVolume)15 Test (org.junit.Test)15 OzoneInputStream (org.apache.hadoop.ozone.client.io.OzoneInputStream)12 IOException (java.io.IOException)9 HashMap (java.util.HashMap)8 OzoneKey (org.apache.hadoop.ozone.client.OzoneKey)6 LinkedHashMap (java.util.LinkedHashMap)5 HddsDatanodeService (org.apache.hadoop.ozone.HddsDatanodeService)5 ArrayList (java.util.ArrayList)4 Path (org.apache.hadoop.fs.Path)4 OzoneKeyLocation (org.apache.hadoop.ozone.client.OzoneKeyLocation)4 Container (org.apache.hadoop.ozone.container.common.interfaces.Container)4 RepeatedOmKeyInfo (org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo)4 Instant (java.time.Instant)3 OFSPath (org.apache.hadoop.ozone.OFSPath)3 BucketArgs (org.apache.hadoop.ozone.client.BucketArgs)3 OMMetadataManager (org.apache.hadoop.ozone.om.OMMetadataManager)3