Search in sources :

Example 16 with OzoneClient

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

the class TestOzoneManagerRestart method testRestartOMWithVolumeOperation.

@Test
public void testRestartOMWithVolumeOperation() throws Exception {
    String volumeName = "volume" + RandomStringUtils.randomNumeric(5);
    OzoneClient client = cluster.getClient();
    ObjectStore objectStore = client.getObjectStore();
    objectStore.createVolume(volumeName);
    OzoneVolume ozoneVolume = objectStore.getVolume(volumeName);
    Assert.assertTrue(ozoneVolume.getName().equals(volumeName));
    cluster.restartOzoneManager();
    cluster.restartStorageContainerManager(true);
    // After restart, try to create same volume again, it should fail.
    try {
        objectStore.createVolume(volumeName);
        fail("testRestartOM failed");
    } catch (IOException ex) {
        GenericTestUtils.assertExceptionContains("VOLUME_ALREADY_EXISTS", ex);
    }
    // Get Volume.
    ozoneVolume = objectStore.getVolume(volumeName);
    Assert.assertTrue(ozoneVolume.getName().equals(volumeName));
}
Also used : OzoneVolume(org.apache.hadoop.ozone.client.OzoneVolume) ObjectStore(org.apache.hadoop.ozone.client.ObjectStore) OzoneClient(org.apache.hadoop.ozone.client.OzoneClient) IOException(java.io.IOException) Test(org.junit.Test)

Example 17 with OzoneClient

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

the class TestOzoneManagerRestart method testRestartOMWithBucketOperation.

@Test
public void testRestartOMWithBucketOperation() throws Exception {
    String volumeName = "volume" + RandomStringUtils.randomNumeric(5);
    String bucketName = "bucket" + RandomStringUtils.randomNumeric(5);
    OzoneClient client = cluster.getClient();
    ObjectStore objectStore = client.getObjectStore();
    objectStore.createVolume(volumeName);
    OzoneVolume ozoneVolume = objectStore.getVolume(volumeName);
    Assert.assertTrue(ozoneVolume.getName().equals(volumeName));
    ozoneVolume.createBucket(bucketName);
    OzoneBucket ozoneBucket = ozoneVolume.getBucket(bucketName);
    Assert.assertTrue(ozoneBucket.getName().equals(bucketName));
    cluster.restartOzoneManager();
    cluster.restartStorageContainerManager(true);
    // After restart, try to create same bucket again, it should fail.
    try {
        ozoneVolume.createBucket(bucketName);
        fail("testRestartOMWithBucketOperation failed");
    } catch (IOException ex) {
        GenericTestUtils.assertExceptionContains("BUCKET_ALREADY_EXISTS", ex);
    }
    // Get bucket.
    ozoneBucket = ozoneVolume.getBucket(bucketName);
    Assert.assertTrue(ozoneBucket.getName().equals(bucketName));
}
Also used : OzoneVolume(org.apache.hadoop.ozone.client.OzoneVolume) OzoneBucket(org.apache.hadoop.ozone.client.OzoneBucket) ObjectStore(org.apache.hadoop.ozone.client.ObjectStore) OzoneClient(org.apache.hadoop.ozone.client.OzoneClient) IOException(java.io.IOException) Test(org.junit.Test)

Example 18 with OzoneClient

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

the class TestRecursiveAclWithFSO method testKeyDeleteAndRenameWithoutPermission.

@Test
public void testKeyDeleteAndRenameWithoutPermission() throws Exception {
    List<String> keys = new ArrayList<>();
    // Create volumes with user1
    OzoneClient client = cluster.getClient();
    ObjectStore objectStore = client.getObjectStore();
    /* r = READ, w = WRITE, c = CREATE, d = DELETE
       l = LIST, a = ALL, n = NONE, x = READ_ACL, y = WRITE_ACL */
    String aclWorldAll = "world::a";
    createVolumeWithOwnerAndAcl(objectStore, "volume1", "user1", aclWorldAll);
    // Login as user1, create directories and keys
    UserGroupInformation.setLoginUser(user1);
    client = cluster.getClient();
    objectStore = client.getObjectStore();
    OzoneVolume volume = objectStore.getVolume("volume1");
    BucketArgs omBucketArgs = BucketArgs.newBuilder().setStorageType(StorageType.DISK).build();
    // create bucket with user1
    volume.createBucket("bucket1", omBucketArgs);
    setBucketAcl(objectStore, volume.getName(), "bucket1", aclWorldAll);
    OzoneBucket ozoneBucket = volume.getBucket("bucket1");
    /**
     *                       buck-1
     *                        |
     *                        a
     *                        |
     *          ------------------------------------
     *         |           |              |        |
     *         b1          b2             b3      file1
     *       -----       ------           -----
     *       |    |      |    |          |    |
     *      c1   c2     d1   d2          e1   e2
     *       |    |      |    |           |    |
     *       f1   f2     f3  --------     f5   f6
     *                      |        |
     *                    d21        file2
     *                     |
     *                     f4
     *
     *     Test Case 1 :
     *     Remove delete acl from file File2
     *     Try deleting b2
     *
     *     Test case 2:
     *     Remove delete acl fro dir c2
     *     Try deleting b1
     *
     *     Test case 3
     *     try deleting b3
     */
    String keyf1 = "a/b1/c1/f1";
    String keyf2 = "a/b1/c2/f2";
    String keyf3 = "a/b2/d1/f3";
    String keyf4 = "a/b2/d2/d21/f4";
    String keyf5 = "/a/b3/e1/f5";
    String keyf6 = "/a/b3/e2/f6";
    String file1 = "a/" + "file" + RandomStringUtils.randomNumeric(5);
    String file2 = "a/b2/d2/" + "file" + RandomStringUtils.randomNumeric(5);
    keys.add(keyf1);
    keys.add(keyf2);
    keys.add(keyf3);
    keys.add(keyf4);
    keys.add(keyf5);
    keys.add(keyf6);
    keys.add(file1);
    keys.add(file2);
    createKeys(objectStore, ozoneBucket, keys);
    // Test case 1
    // Remove acls from file2
    // Delete/Rename on directory a/b2 should throw permission denied
    // (since file2 is a child)
    removeAclsFromKey(objectStore, ozoneBucket, file2);
    OzoneObj ozoneObj;
    List<OzoneAcl> aclList1;
    UserGroupInformation.setLoginUser(user2);
    client = cluster.getClient();
    objectStore = client.getObjectStore();
    volume = objectStore.getVolume("volume1");
    ozoneBucket = volume.getBucket("bucket1");
    // perform  delete
    try {
        ozoneBucket.deleteDirectory("a/b2", true);
        Assert.fail("Should throw permission denied !");
    } catch (OMException ome) {
        // expect permission error
        Assert.assertEquals("Permission check failed", OMException.ResultCodes.PERMISSION_DENIED, ome.getResult());
    }
    // perform rename
    try {
        ozoneBucket.renameKey("a/b2", "a/b2_renamed");
        Assert.fail("Should throw permission denied !");
    } catch (OMException ome) {
        // expect permission error
        Assert.assertEquals("Permission check failed", OMException.ResultCodes.PERMISSION_DENIED, ome.getResult());
    }
    // Test case 2
    // Remove acl from directory c2, delete/rename a/b1 should throw
    // permission denied since c2 is a subdirectory
    UserGroupInformation.setLoginUser(user1);
    removeAclsFromKey(objectStore, ozoneBucket, "a/b1/c2");
    UserGroupInformation.setLoginUser(user2);
    // perform  delete
    try {
        ozoneBucket.deleteDirectory("a/b1", true);
        Assert.fail("Should throw permission denied !");
    } catch (OMException ome) {
        // expect permission error
        Assert.assertEquals("Permission check failed", OMException.ResultCodes.PERMISSION_DENIED, ome.getResult());
    }
    // perform rename
    try {
        ozoneBucket.renameKey("a/b1", "a/b1_renamed");
        Assert.fail("Should throw permission denied !");
    } catch (OMException ome) {
        // expect permission error
        Assert.assertEquals("Permission check failed", OMException.ResultCodes.PERMISSION_DENIED, ome.getResult());
    }
    // Test case 3
    // delete b3 and this shouldn't throw exception because acls have not
    // been removed from subpaths.
    ozoneBucket.deleteDirectory("a/b3", true);
}
Also used : OzoneVolume(org.apache.hadoop.ozone.client.OzoneVolume) OzoneBucket(org.apache.hadoop.ozone.client.OzoneBucket) OzoneObj(org.apache.hadoop.ozone.security.acl.OzoneObj) ObjectStore(org.apache.hadoop.ozone.client.ObjectStore) OzoneAcl(org.apache.hadoop.ozone.OzoneAcl) BucketArgs(org.apache.hadoop.ozone.client.BucketArgs) ArrayList(java.util.ArrayList) OzoneClient(org.apache.hadoop.ozone.client.OzoneClient) OMException(org.apache.hadoop.ozone.om.exceptions.OMException) Test(org.junit.Test)

Example 19 with OzoneClient

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

the class TestObjectStore method testCreateBucketWithBucketLayout.

@Test
public void testCreateBucketWithBucketLayout() throws Exception {
    String sampleVolumeName = UUID.randomUUID().toString();
    String sampleBucketName = UUID.randomUUID().toString();
    OzoneClient client = cluster.getClient();
    ObjectStore store = client.getObjectStore();
    store.createVolume(sampleVolumeName);
    OzoneVolume volume = store.getVolume(sampleVolumeName);
    // Case 1: Bucket layout: Empty and OM default bucket layout: LEGACY
    BucketArgs.Builder builder = BucketArgs.newBuilder();
    volume.createBucket(sampleBucketName, builder.build());
    OzoneBucket bucket = volume.getBucket(sampleBucketName);
    Assert.assertEquals(sampleBucketName, bucket.getName());
    Assert.assertEquals(BucketLayout.LEGACY, bucket.getBucketLayout());
    // Case 2: Bucket layout: OBJECT_STORE
    sampleBucketName = UUID.randomUUID().toString();
    builder.setBucketLayout(BucketLayout.OBJECT_STORE);
    volume.createBucket(sampleBucketName, builder.build());
    bucket = volume.getBucket(sampleBucketName);
    Assert.assertEquals(sampleBucketName, bucket.getName());
    Assert.assertEquals(BucketLayout.OBJECT_STORE, bucket.getBucketLayout());
    // Case 3: Bucket layout: LEGACY
    sampleBucketName = UUID.randomUUID().toString();
    builder.setBucketLayout(BucketLayout.LEGACY);
    volume.createBucket(sampleBucketName, builder.build());
    bucket = volume.getBucket(sampleBucketName);
    Assert.assertEquals(sampleBucketName, bucket.getName());
    Assert.assertEquals(BucketLayout.LEGACY, bucket.getBucketLayout());
    // Case 3: Bucket layout: FILE_SYSTEM_OPTIMIZED
    sampleBucketName = UUID.randomUUID().toString();
    builder.setBucketLayout(BucketLayout.FILE_SYSTEM_OPTIMIZED);
    volume.createBucket(sampleBucketName, builder.build());
    bucket = volume.getBucket(sampleBucketName);
    Assert.assertEquals(sampleBucketName, bucket.getName());
    Assert.assertEquals(BucketLayout.FILE_SYSTEM_OPTIMIZED, bucket.getBucketLayout());
}
Also used : OzoneVolume(org.apache.hadoop.ozone.client.OzoneVolume) OzoneBucket(org.apache.hadoop.ozone.client.OzoneBucket) ObjectStore(org.apache.hadoop.ozone.client.ObjectStore) BucketArgs(org.apache.hadoop.ozone.client.BucketArgs) OzoneClient(org.apache.hadoop.ozone.client.OzoneClient) Test(org.junit.Test)

Example 20 with OzoneClient

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

the class TestObjectStore method testCreateLinkBucketWithBucketLayout.

/**
 * Ensure Link Buckets have same BucketLayout as source buckets.
 * @throws Exception
 */
@Test
public void testCreateLinkBucketWithBucketLayout() throws Exception {
    String volumeName = UUID.randomUUID().toString();
    String sourceBucket1Name = UUID.randomUUID().toString();
    BucketLayout sourceBucket1Layout = BucketLayout.FILE_SYSTEM_OPTIMIZED;
    String sourceBucket2Name = UUID.randomUUID().toString();
    BucketLayout sourceBucket2Layout = BucketLayout.OBJECT_STORE;
    String linkBucket1Name = UUID.randomUUID().toString();
    String linkBucket2Name = UUID.randomUUID().toString();
    // Chained link bucket
    String linkBucket3Name = UUID.randomUUID().toString();
    OzoneClient client = cluster.getClient();
    ObjectStore store = client.getObjectStore();
    // Create volume
    store.createVolume(volumeName);
    OzoneVolume volume = store.getVolume(volumeName);
    // Create source buckets
    BucketArgs.Builder builder = BucketArgs.newBuilder();
    builder.setBucketLayout(sourceBucket1Layout);
    volume.createBucket(sourceBucket1Name, builder.build());
    builder.setBucketLayout(sourceBucket2Layout);
    volume.createBucket(sourceBucket2Name, builder.build());
    // Create link buckets
    createLinkBucket(volume, sourceBucket1Name, linkBucket1Name);
    createLinkBucket(volume, sourceBucket2Name, linkBucket2Name);
    // linkBucket3 is chained onto linkBucket1
    createLinkBucket(volume, linkBucket1Name, linkBucket3Name);
    // Check that Link Buckets' layouts match source bucket layouts
    OzoneBucket bucket = volume.getBucket(linkBucket1Name);
    Assert.assertEquals(sourceBucket1Layout, bucket.getBucketLayout());
    bucket = volume.getBucket(linkBucket2Name);
    Assert.assertEquals(sourceBucket2Layout, bucket.getBucketLayout());
    // linkBucket3 is chained onto linkBucket1, hence its bucket layout matches
    // linkBucket1's source bucket.
    bucket = volume.getBucket(linkBucket3Name);
    Assert.assertEquals(sourceBucket1Layout, bucket.getBucketLayout());
    Assert.assertEquals(linkBucket1Name, bucket.getSourceBucket());
}
Also used : OzoneVolume(org.apache.hadoop.ozone.client.OzoneVolume) OzoneBucket(org.apache.hadoop.ozone.client.OzoneBucket) ObjectStore(org.apache.hadoop.ozone.client.ObjectStore) BucketArgs(org.apache.hadoop.ozone.client.BucketArgs) BucketLayout(org.apache.hadoop.ozone.om.helpers.BucketLayout) OzoneClient(org.apache.hadoop.ozone.client.OzoneClient) Test(org.junit.Test)

Aggregations

OzoneClient (org.apache.hadoop.ozone.client.OzoneClient)67 Test (org.junit.Test)42 ObjectStore (org.apache.hadoop.ozone.client.ObjectStore)31 OzoneVolume (org.apache.hadoop.ozone.client.OzoneVolume)25 OzoneBucket (org.apache.hadoop.ozone.client.OzoneBucket)23 OzoneConfiguration (org.apache.hadoop.hdds.conf.OzoneConfiguration)18 OzoneClientStub (org.apache.hadoop.ozone.client.OzoneClientStub)11 OzoneOutputStream (org.apache.hadoop.ozone.client.io.OzoneOutputStream)11 OMException (org.apache.hadoop.ozone.om.exceptions.OMException)9 IOException (java.io.IOException)7 HttpHeaders (javax.ws.rs.core.HttpHeaders)6 BucketArgs (org.apache.hadoop.ozone.client.BucketArgs)6 Response (javax.ws.rs.core.Response)5 OmKeyInfo (org.apache.hadoop.ozone.om.helpers.OmKeyInfo)5 BeforeClass (org.junit.BeforeClass)5 OmKeyArgs (org.apache.hadoop.ozone.om.helpers.OmKeyArgs)4 OzoneKey (org.apache.hadoop.ozone.client.OzoneKey)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2