Search in sources :

Example 1 with VolumeArgs

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

the class TestOzoneManagerHA method createKeyTest.

protected void createKeyTest(boolean checkSuccess) throws Exception {
    String userName = "user" + RandomStringUtils.randomNumeric(5);
    String adminName = "admin" + RandomStringUtils.randomNumeric(5);
    String volumeName = "volume" + RandomStringUtils.randomNumeric(5);
    VolumeArgs createVolumeArgs = VolumeArgs.newBuilder().setOwner(userName).setAdmin(adminName).build();
    try {
        getObjectStore().createVolume(volumeName, createVolumeArgs);
        OzoneVolume retVolumeinfo = getObjectStore().getVolume(volumeName);
        Assert.assertTrue(retVolumeinfo.getName().equals(volumeName));
        Assert.assertTrue(retVolumeinfo.getOwner().equals(userName));
        Assert.assertTrue(retVolumeinfo.getAdmin().equals(adminName));
        String bucketName = UUID.randomUUID().toString();
        String keyName = UUID.randomUUID().toString();
        retVolumeinfo.createBucket(bucketName);
        OzoneBucket ozoneBucket = retVolumeinfo.getBucket(bucketName);
        Assert.assertTrue(ozoneBucket.getName().equals(bucketName));
        Assert.assertTrue(ozoneBucket.getVolumeName().equals(volumeName));
        String value = "random data";
        OzoneOutputStream ozoneOutputStream = ozoneBucket.createKey(keyName, value.length(), ReplicationType.RATIS, ReplicationFactor.ONE, new HashMap<>());
        ozoneOutputStream.write(value.getBytes(UTF_8), 0, value.length());
        ozoneOutputStream.close();
        OzoneInputStream ozoneInputStream = ozoneBucket.readKey(keyName);
        byte[] fileContent = new byte[value.getBytes(UTF_8).length];
        ozoneInputStream.read(fileContent);
        Assert.assertEquals(value, new String(fileContent, UTF_8));
    } catch (ConnectException | RemoteException e) {
        if (!checkSuccess) {
            // last running OM as it would fail to get a quorum.
            if (e instanceof RemoteException) {
                GenericTestUtils.assertExceptionContains("OMNotLeaderException", e);
            }
        } else {
            throw e;
        }
    }
}
Also used : OzoneVolume(org.apache.hadoop.ozone.client.OzoneVolume) OzoneBucket(org.apache.hadoop.ozone.client.OzoneBucket) OzoneInputStream(org.apache.hadoop.ozone.client.io.OzoneInputStream) VolumeArgs(org.apache.hadoop.ozone.client.VolumeArgs) OzoneOutputStream(org.apache.hadoop.ozone.client.io.OzoneOutputStream) RemoteException(org.apache.hadoop.ipc.RemoteException) ConnectException(java.net.ConnectException)

Example 2 with VolumeArgs

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

the class TestOzoneManagerHA method setupBucket.

protected OzoneBucket setupBucket() throws Exception {
    String userName = "user" + RandomStringUtils.randomNumeric(5);
    String adminName = "admin" + RandomStringUtils.randomNumeric(5);
    String volumeName = "volume" + RandomStringUtils.randomNumeric(5);
    VolumeArgs createVolumeArgs = VolumeArgs.newBuilder().setOwner(userName).setAdmin(adminName).build();
    objectStore.createVolume(volumeName, createVolumeArgs);
    OzoneVolume retVolumeinfo = objectStore.getVolume(volumeName);
    Assert.assertTrue(retVolumeinfo.getName().equals(volumeName));
    Assert.assertTrue(retVolumeinfo.getOwner().equals(userName));
    Assert.assertTrue(retVolumeinfo.getAdmin().equals(adminName));
    String bucketName = UUID.randomUUID().toString();
    retVolumeinfo.createBucket(bucketName);
    OzoneBucket ozoneBucket = retVolumeinfo.getBucket(bucketName);
    Assert.assertTrue(ozoneBucket.getName().equals(bucketName));
    Assert.assertTrue(ozoneBucket.getVolumeName().equals(volumeName));
    return ozoneBucket;
}
Also used : OzoneVolume(org.apache.hadoop.ozone.client.OzoneVolume) OzoneBucket(org.apache.hadoop.ozone.client.OzoneBucket) VolumeArgs(org.apache.hadoop.ozone.client.VolumeArgs)

Example 3 with VolumeArgs

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

the class TestDataUtil method createVolumeAndBucket.

public static OzoneBucket createVolumeAndBucket(MiniOzoneCluster cluster, String volumeName, String bucketName, BucketLayout bucketLayout) throws IOException {
    String userName = "user" + RandomStringUtils.randomNumeric(5);
    String adminName = "admin" + RandomStringUtils.randomNumeric(5);
    OzoneClient client = cluster.getClient();
    VolumeArgs volumeArgs = VolumeArgs.newBuilder().setAdmin(adminName).setOwner(userName).build();
    ObjectStore objectStore = client.getObjectStore();
    objectStore.createVolume(volumeName, volumeArgs);
    OzoneVolume volume = objectStore.getVolume(volumeName);
    BucketArgs omBucketArgs;
    BucketArgs.Builder builder = BucketArgs.newBuilder();
    builder.setStorageType(StorageType.DISK);
    builder.setBucketLayout(bucketLayout);
    omBucketArgs = builder.build();
    volume.createBucket(bucketName, omBucketArgs);
    return volume.getBucket(bucketName);
}
Also used : OzoneVolume(org.apache.hadoop.ozone.client.OzoneVolume) ObjectStore(org.apache.hadoop.ozone.client.ObjectStore) BucketArgs(org.apache.hadoop.ozone.client.BucketArgs) VolumeArgs(org.apache.hadoop.ozone.client.VolumeArgs) OzoneClient(org.apache.hadoop.ozone.client.OzoneClient)

Example 4 with VolumeArgs

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

the class TestOzoneRpcClientAbstract method testSetVolumeQuotaIllegal.

@Test
public void testSetVolumeQuotaIllegal() throws Exception {
    String volumeName = UUID.randomUUID().toString();
    VolumeArgs volumeArgs = VolumeArgs.newBuilder().addMetadata("key1", "val1").setQuotaInNamespace(0).setQuotaInBytes(0).build();
    LambdaTestUtils.intercept(IllegalArgumentException.class, "Invalid values for quota", () -> store.createVolume(volumeName, volumeArgs));
    store.createVolume(volumeName);
    // test volume set quota 0
    LambdaTestUtils.intercept(IllegalArgumentException.class, "Invalid values for space quota", () -> store.getVolume(volumeName).setQuota(OzoneQuota.parseQuota("0GB", "10")));
    LambdaTestUtils.intercept(IllegalArgumentException.class, "Invalid values for namespace quota", () -> store.getVolume(volumeName).setQuota(OzoneQuota.parseQuota("10GB", "0")));
    // The unit should be legal.
    LambdaTestUtils.intercept(IllegalArgumentException.class, "Invalid values for quota", () -> store.getVolume(volumeName).setQuota(OzoneQuota.parseQuota("1TEST", "1000")));
    // The setting value cannot be greater than LONG.MAX_VALUE BYTES.
    LambdaTestUtils.intercept(IllegalArgumentException.class, "Invalid values for quota", () -> store.getVolume(volumeName).setQuota(OzoneQuota.parseQuota("9223372036854775808 B", "1000")));
    // The value cannot be negative.
    LambdaTestUtils.intercept(IllegalArgumentException.class, "Invalid values for space quota", () -> store.getVolume(volumeName).setQuota(OzoneQuota.parseQuota("-10GB", "1000")));
}
Also used : VolumeArgs(org.apache.hadoop.ozone.client.VolumeArgs) OmVolumeArgs(org.apache.hadoop.ozone.om.helpers.OmVolumeArgs) Test(org.junit.Test)

Example 5 with VolumeArgs

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

the class TestOzoneRpcClientAbstract method testCreateVolumeWithMetadata.

@Test
public void testCreateVolumeWithMetadata() throws IOException, OzoneClientException {
    String volumeName = UUID.randomUUID().toString();
    VolumeArgs volumeArgs = VolumeArgs.newBuilder().addMetadata("key1", "val1").build();
    store.createVolume(volumeName, volumeArgs);
    OzoneVolume volume = store.getVolume(volumeName);
    Assert.assertEquals(OzoneConsts.QUOTA_RESET, volume.getQuotaInNamespace());
    Assert.assertEquals(OzoneConsts.QUOTA_RESET, volume.getQuotaInBytes());
    Assert.assertEquals("val1", volume.getMetadata().get("key1"));
    Assert.assertEquals(volumeName, volume.getName());
}
Also used : OzoneVolume(org.apache.hadoop.ozone.client.OzoneVolume) VolumeArgs(org.apache.hadoop.ozone.client.VolumeArgs) OmVolumeArgs(org.apache.hadoop.ozone.om.helpers.OmVolumeArgs) Test(org.junit.Test)

Aggregations

VolumeArgs (org.apache.hadoop.ozone.client.VolumeArgs)18 OzoneVolume (org.apache.hadoop.ozone.client.OzoneVolume)13 Test (org.junit.Test)12 OzoneBucket (org.apache.hadoop.ozone.client.OzoneBucket)6 ObjectStore (org.apache.hadoop.ozone.client.ObjectStore)5 OzoneAcl (org.apache.hadoop.ozone.OzoneAcl)4 IOException (java.io.IOException)3 ConnectException (java.net.ConnectException)2 Path (org.apache.hadoop.fs.Path)2 RemoteException (org.apache.hadoop.ipc.RemoteException)2 OFSPath (org.apache.hadoop.ozone.OFSPath)2 ClientProtocol (org.apache.hadoop.ozone.client.protocol.ClientProtocol)2 OmVolumeArgs (org.apache.hadoop.ozone.om.helpers.OmVolumeArgs)2 ACLType (org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType)2 OzoneAclConfig (org.apache.hadoop.ozone.security.acl.OzoneAclConfig)2 OzoneObj (org.apache.hadoop.ozone.security.acl.OzoneObj)2 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1 FileStatus (org.apache.hadoop.fs.FileStatus)1