Search in sources :

Example 66 with OMException

use of org.apache.hadoop.ozone.om.exceptions.OMException in project ozone by apache.

the class TestOzoneManagerHAWithData method testFileOperationsWithRecursive.

private void testFileOperationsWithRecursive() throws Exception {
    OzoneBucket ozoneBucket = setupBucket();
    String data = "random data";
    // one level key name
    String keyName = UUID.randomUUID().toString();
    testCreateFile(ozoneBucket, keyName, data, true, false);
    // multi level key name
    keyName = "dir1/dir2/dir3/file1";
    testCreateFile(ozoneBucket, keyName, data, true, false);
    data = "random data random data";
    // multi level key name with over write set.
    testCreateFile(ozoneBucket, keyName, data, true, true);
    try {
        testCreateFile(ozoneBucket, keyName, data, true, false);
        fail("testFileOperationsWithRecursive");
    } catch (OMException ex) {
        Assert.assertEquals(FILE_ALREADY_EXISTS, ex.getResult());
    }
    // Try now with a file name which is same as a directory.
    try {
        keyName = "folder/folder2";
        ozoneBucket.createDirectory(keyName);
        testCreateFile(ozoneBucket, keyName, data, true, false);
        fail("testFileOperationsWithNonRecursive");
    } catch (OMException ex) {
        Assert.assertEquals(NOT_A_FILE, ex.getResult());
    }
}
Also used : OzoneBucket(org.apache.hadoop.ozone.client.OzoneBucket) OMException(org.apache.hadoop.ozone.om.exceptions.OMException)

Example 67 with OMException

use of org.apache.hadoop.ozone.om.exceptions.OMException in project ozone by apache.

the class TestOzoneManagerHAWithData method testKeysDelete.

private void testKeysDelete() throws Exception {
    OzoneBucket ozoneBucket = setupBucket();
    String data = "random data";
    String keyName1 = "dir/file1";
    String keyName2 = "dir/file2";
    String keyName3 = "dir/file3";
    String keyName4 = "dir/file4";
    List<String> keyList1 = new ArrayList<>();
    keyList1.add(keyName2);
    keyList1.add(keyName3);
    testCreateFile(ozoneBucket, keyName1, data, true, false);
    testCreateFile(ozoneBucket, keyName2, data, true, false);
    testCreateFile(ozoneBucket, keyName3, data, true, false);
    testCreateFile(ozoneBucket, keyName4, data, true, false);
    // Delete keyName1 use deleteKey api.
    ozoneBucket.deleteKey(keyName1);
    // Delete keyName2 and keyName3 in keyList1 using the deleteKeys api.
    ozoneBucket.deleteKeys(keyList1);
    // In keyList2 keyName3 was previously deleted and KeyName4 exists .
    List<String> keyList2 = new ArrayList<>();
    keyList2.add(keyName3);
    keyList2.add(keyName4);
    // exception. In this case, we test for deletion failure.
    try {
        ozoneBucket.deleteKeys(keyList2);
        fail("testFilesDelete");
    } catch (OMException ex) {
        // The expected exception PARTIAL_DELETE, as if not able to delete, we
        // return error codee PARTIAL_DElETE.
        Assert.assertEquals(PARTIAL_DELETE, ex.getResult());
    }
}
Also used : OzoneBucket(org.apache.hadoop.ozone.client.OzoneBucket) ArrayList(java.util.ArrayList) OMException(org.apache.hadoop.ozone.om.exceptions.OMException)

Example 68 with OMException

use of org.apache.hadoop.ozone.om.exceptions.OMException 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 69 with OMException

use of org.apache.hadoop.ozone.om.exceptions.OMException in project ozone by apache.

the class TestObjectStoreWithFSO method testLookupKey.

@Test
public void testLookupKey() throws Exception {
    String parent = "a/b/c/";
    String fileName = "key" + RandomStringUtils.randomNumeric(5);
    String key = parent + fileName;
    OzoneClient client = cluster.getClient();
    ObjectStore objectStore = client.getObjectStore();
    OzoneVolume ozoneVolume = objectStore.getVolume(volumeName);
    Assert.assertTrue(ozoneVolume.getName().equals(volumeName));
    OzoneBucket ozoneBucket = ozoneVolume.getBucket(bucketName);
    Assert.assertTrue(ozoneBucket.getName().equals(bucketName));
    Table<String, OmKeyInfo> openFileTable = cluster.getOzoneManager().getMetadataManager().getOpenKeyTable(getBucketLayout());
    String data = "random data";
    OzoneOutputStream ozoneOutputStream = ozoneBucket.createKey(key, data.length(), ReplicationType.RATIS, ReplicationFactor.ONE, new HashMap<>());
    KeyOutputStream keyOutputStream = (KeyOutputStream) ozoneOutputStream.getOutputStream();
    long clientID = keyOutputStream.getClientID();
    OmDirectoryInfo dirPathC = getDirInfo(parent);
    Assert.assertNotNull("Failed to find dir path: a/b/c", dirPathC);
    // after file creation
    verifyKeyInOpenFileTable(openFileTable, clientID, fileName, dirPathC.getObjectID(), false);
    ozoneOutputStream.write(data.getBytes(StandardCharsets.UTF_8), 0, data.length());
    // open key
    try {
        ozoneBucket.getKey(key);
        fail("Should throw exception as fileName is not visible and its still " + "open for writing!");
    } catch (OMException ome) {
        // expected
        assertEquals(ome.getResult(), OMException.ResultCodes.KEY_NOT_FOUND);
    }
    ozoneOutputStream.close();
    OzoneKeyDetails keyDetails = ozoneBucket.getKey(key);
    Assert.assertEquals(key, keyDetails.getName());
    Table<String, OmKeyInfo> fileTable = cluster.getOzoneManager().getMetadataManager().getKeyTable(getBucketLayout());
    // When closing the key, entry should be removed from openFileTable
    // and it should be added to fileTable.
    verifyKeyInFileTable(fileTable, fileName, dirPathC.getObjectID(), false);
    verifyKeyInOpenFileTable(openFileTable, clientID, fileName, dirPathC.getObjectID(), true);
    ozoneBucket.deleteKey(key);
    // get deleted key
    try {
        ozoneBucket.getKey(key);
        fail("Should throw exception as fileName not exists!");
    } catch (OMException ome) {
        // expected
        assertEquals(ome.getResult(), OMException.ResultCodes.KEY_NOT_FOUND);
    }
    // after key delete
    verifyKeyInFileTable(fileTable, fileName, dirPathC.getObjectID(), true);
    verifyKeyInOpenFileTable(openFileTable, clientID, fileName, dirPathC.getObjectID(), true);
}
Also used : ObjectStore(org.apache.hadoop.ozone.client.ObjectStore) OzoneOutputStream(org.apache.hadoop.ozone.client.io.OzoneOutputStream) OzoneClient(org.apache.hadoop.ozone.client.OzoneClient) OzoneVolume(org.apache.hadoop.ozone.client.OzoneVolume) OzoneBucket(org.apache.hadoop.ozone.client.OzoneBucket) OzoneKeyDetails(org.apache.hadoop.ozone.client.OzoneKeyDetails) OmKeyInfo(org.apache.hadoop.ozone.om.helpers.OmKeyInfo) OmDirectoryInfo(org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo) KeyOutputStream(org.apache.hadoop.ozone.client.io.KeyOutputStream) OMException(org.apache.hadoop.ozone.om.exceptions.OMException) Test(org.junit.Test)

Example 70 with OMException

use of org.apache.hadoop.ozone.om.exceptions.OMException in project ozone by apache.

the class TestOzoneManagerRatisRequest method testRequestWithNonExistentBucket.

@Test(timeout = 300_000)
public void testRequestWithNonExistentBucket() throws Exception {
    ozoneManager = Mockito.mock(OzoneManager.class);
    ozoneConfiguration.set(OMConfigKeys.OZONE_OM_DB_DIRS, folder.newFolder().getAbsolutePath());
    omMetadataManager = new OmMetadataManagerImpl(ozoneConfiguration);
    when(ozoneManager.getMetadataManager()).thenReturn(omMetadataManager);
    String volumeName = "vol1";
    String bucketName = "invalidBuck";
    // Add entry to Volume Table.
    omMetadataManager.getVolumeTable().addCacheEntry(new CacheKey<>(omMetadataManager.getVolumeKey(volumeName)), new CacheValue<>(Optional.of(OmVolumeArgs.newBuilder().setVolume(volumeName).setOwnerName("owner").setAdminName("admin").build()), 100L));
    OzoneManagerProtocolProtos.OMRequest omRequest = OMRequestTestUtils.createCompleteMPURequest(volumeName, bucketName, "mpuKey", "mpuKeyID", new ArrayList<>());
    try {
        // Request creation flow should throw exception if the bucket associated
        // with the request doesn't exist.
        OzoneManagerRatisUtils.createClientRequest(omRequest, ozoneManager);
        fail("Expected OMException: Bucket not found");
    } catch (OMException oe) {
        // Expected exception.
        Assert.assertEquals(OMException.ResultCodes.BUCKET_NOT_FOUND, oe.getResult());
    }
}
Also used : OmMetadataManagerImpl(org.apache.hadoop.ozone.om.OmMetadataManagerImpl) OzoneManager(org.apache.hadoop.ozone.om.OzoneManager) OzoneManagerProtocolProtos(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos) OMException(org.apache.hadoop.ozone.om.exceptions.OMException) Test(org.junit.Test)

Aggregations

OMException (org.apache.hadoop.ozone.om.exceptions.OMException)211 IOException (java.io.IOException)109 OmBucketInfo (org.apache.hadoop.ozone.om.helpers.OmBucketInfo)45 OzoneBucket (org.apache.hadoop.ozone.client.OzoneBucket)44 OMMetadataManager (org.apache.hadoop.ozone.om.OMMetadataManager)39 OmKeyInfo (org.apache.hadoop.ozone.om.helpers.OmKeyInfo)39 OMClientResponse (org.apache.hadoop.ozone.om.response.OMClientResponse)37 OMResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse)37 ArrayList (java.util.ArrayList)33 Test (org.junit.Test)32 OzoneVolume (org.apache.hadoop.ozone.client.OzoneVolume)29 OMMetrics (org.apache.hadoop.ozone.om.OMMetrics)27 OmVolumeArgs (org.apache.hadoop.ozone.om.helpers.OmVolumeArgs)23 HashMap (java.util.HashMap)21 OzoneFileStatus (org.apache.hadoop.ozone.om.helpers.OzoneFileStatus)19 OzoneOutputStream (org.apache.hadoop.ozone.client.io.OzoneOutputStream)18 OzoneManagerProtocolProtos (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos)18 OmKeyLocationInfo (org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo)17 RepeatedOmKeyInfo (org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo)17 KeyArgs (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.KeyArgs)16