Search in sources :

Example 26 with OzoneKey

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

the class TestListKeysWithFSO method checkKeyList.

private void checkKeyList(String keyPrefix, String startKey, List<String> keys) throws Exception {
    Iterator<? extends OzoneKey> ozoneKeyIterator = fsoOzoneBucket.listKeys(keyPrefix, startKey);
    TreeSet<String> outputKeys = new TreeSet<>();
    while (ozoneKeyIterator.hasNext()) {
        OzoneKey ozoneKey = ozoneKeyIterator.next();
        outputKeys.add(ozoneKey.getName());
    }
    LinkedList outputKeysList = new LinkedList(outputKeys);
    System.out.println("BEGIN:::keyPrefix---> " + keyPrefix + ":::---> " + startKey);
    for (String key : keys) {
        System.out.println(" " + key);
    }
    System.out.println("END:::keyPrefix---> " + keyPrefix + ":::---> " + startKey);
    Assert.assertEquals(keys, outputKeysList);
}
Also used : TreeSet(java.util.TreeSet) OzoneKey(org.apache.hadoop.ozone.client.OzoneKey) LinkedList(java.util.LinkedList)

Example 27 with OzoneKey

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

the class TestListKeysWithFSO method getExpectedKeyList.

private static List<String> getExpectedKeyList(String keyPrefix, String startKey) throws Exception {
    Iterator<? extends OzoneKey> ozoneKeyIterator = legacyOzoneBucket.listKeys(keyPrefix, startKey);
    List<String> keys = new LinkedList<>();
    while (ozoneKeyIterator.hasNext()) {
        OzoneKey ozoneKey = ozoneKeyIterator.next();
        keys.add(ozoneKey.getName());
    }
    return keys;
}
Also used : OzoneKey(org.apache.hadoop.ozone.client.OzoneKey) LinkedList(java.util.LinkedList)

Example 28 with OzoneKey

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

the class TestObjectStoreWithFSO method checkKeyList.

private void checkKeyList(Iterator<? extends OzoneKey> ozoneKeyIterator, List<String> keys) {
    LinkedList<String> outputKeys = new LinkedList<>();
    while (ozoneKeyIterator.hasNext()) {
        OzoneKey ozoneKey = ozoneKeyIterator.next();
        outputKeys.add(ozoneKey.getName());
    }
    Assert.assertEquals(keys, outputKeys);
}
Also used : OzoneKey(org.apache.hadoop.ozone.client.OzoneKey) LinkedList(java.util.LinkedList)

Example 29 with OzoneKey

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

the class TestObjectStoreWithFSO method testRenameKey.

@Test
public void testRenameKey() throws IOException {
    String fromKeyName = UUID.randomUUID().toString();
    String value = "sample value";
    OzoneClient client = cluster.getClient();
    ObjectStore objectStore = client.getObjectStore();
    OzoneVolume volume = objectStore.getVolume(volumeName);
    OzoneBucket bucket = volume.getBucket(bucketName);
    createTestKey(bucket, fromKeyName, value);
    // Rename to empty string should fail.
    String toKeyName = "";
    try {
        bucket.renameKey(fromKeyName, toKeyName);
        fail("Rename to empty string should fail!");
    } catch (OMException ome) {
        Assert.assertEquals(OMException.ResultCodes.INVALID_KEY_NAME, ome.getResult());
    }
    toKeyName = UUID.randomUUID().toString();
    bucket.renameKey(fromKeyName, toKeyName);
    // Lookup for old key should fail.
    try {
        bucket.getKey(fromKeyName);
        fail("Lookup for old from key name should fail!");
    } catch (OMException ome) {
        Assert.assertEquals(KEY_NOT_FOUND, ome.getResult());
    }
    OzoneKey key = bucket.getKey(toKeyName);
    Assert.assertEquals(toKeyName, key.getName());
}
Also used : OzoneVolume(org.apache.hadoop.ozone.client.OzoneVolume) OzoneBucket(org.apache.hadoop.ozone.client.OzoneBucket) ObjectStore(org.apache.hadoop.ozone.client.ObjectStore) OzoneKey(org.apache.hadoop.ozone.client.OzoneKey) OzoneClient(org.apache.hadoop.ozone.client.OzoneClient) OMException(org.apache.hadoop.ozone.om.exceptions.OMException) Test(org.junit.Test)

Example 30 with OzoneKey

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

the class TestObjectStoreWithFSO method createTestKey.

private void createTestKey(OzoneBucket bucket, String keyName, String keyValue) throws IOException {
    OzoneOutputStream out = bucket.createKey(keyName, keyValue.getBytes(StandardCharsets.UTF_8).length, RATIS, ONE, new HashMap<>());
    out.write(keyValue.getBytes(StandardCharsets.UTF_8));
    out.close();
    OzoneKey key = bucket.getKey(keyName);
    Assert.assertEquals(keyName, key.getName());
}
Also used : OzoneKey(org.apache.hadoop.ozone.client.OzoneKey) OzoneOutputStream(org.apache.hadoop.ozone.client.io.OzoneOutputStream)

Aggregations

OzoneKey (org.apache.hadoop.ozone.client.OzoneKey)31 OzoneOutputStream (org.apache.hadoop.ozone.client.io.OzoneOutputStream)20 OzoneBucket (org.apache.hadoop.ozone.client.OzoneBucket)19 OzoneVolume (org.apache.hadoop.ozone.client.OzoneVolume)18 OzoneInputStream (org.apache.hadoop.ozone.client.io.OzoneInputStream)15 Test (org.junit.jupiter.api.Test)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 IOException (java.io.IOException)8 Instant (java.time.Instant)7 HddsDatanodeService (org.apache.hadoop.ozone.HddsDatanodeService)7 Container (org.apache.hadoop.ozone.container.common.interfaces.Container)6 OMException (org.apache.hadoop.ozone.om.exceptions.OMException)6 Test (org.junit.Test)6 OzoneKeyDetails (org.apache.hadoop.ozone.client.OzoneKeyDetails)5 HashMap (java.util.HashMap)4 LinkedList (java.util.LinkedList)4 File (java.io.File)3 ObjectStore (org.apache.hadoop.ozone.client.ObjectStore)3 OzoneContainer (org.apache.hadoop.ozone.container.ozoneimpl.OzoneContainer)3 ArrayList (java.util.ArrayList)2