Search in sources :

Example 1 with OFSPath

use of org.apache.hadoop.ozone.OFSPath in project ozone by apache.

the class TestRootedOzoneFileSystem method getKey.

private OzoneKeyDetails getKey(Path keyPath, boolean isDirectory) throws IOException {
    String key = ofs.pathToKey(keyPath);
    if (isDirectory) {
        key = key + OZONE_URI_DELIMITER;
    }
    OFSPath ofsPath = new OFSPath(key);
    String keyInBucket = ofsPath.getKeyName();
    return cluster.getClient().getObjectStore().getVolume(volumeName).getBucket(bucketName).getKey(keyInBucket);
}
Also used : OFSPath(org.apache.hadoop.ozone.OFSPath)

Example 2 with OFSPath

use of org.apache.hadoop.ozone.OFSPath in project ozone by apache.

the class TestRootedOzoneFileSystem method teardownVolumeBucketWithDir.

private void teardownVolumeBucketWithDir(Path bucketPath1) throws IOException {
    fs.delete(new Path(bucketPath1, "dir1"), true);
    fs.delete(new Path(bucketPath1, "dir2"), true);
    OFSPath ofsPath = new OFSPath(bucketPath1);
    OzoneVolume volume = objectStore.getVolume(ofsPath.getVolumeName());
    volume.deleteBucket(ofsPath.getBucketName());
    objectStore.deleteVolume(ofsPath.getVolumeName());
}
Also used : Path(org.apache.hadoop.fs.Path) OFSPath(org.apache.hadoop.ozone.OFSPath) OzoneVolume(org.apache.hadoop.ozone.client.OzoneVolume) OFSPath(org.apache.hadoop.ozone.OFSPath)

Example 3 with OFSPath

use of org.apache.hadoop.ozone.OFSPath in project ozone by apache.

the class TestOzoneShellHA method testDeleteTrashNoSkipTrash.

@Test
public void testDeleteTrashNoSkipTrash() throws Exception {
    // Test delete from Trash directory removes item from filesystem
    // setup configuration to use TrashPolicyOzone
    // (default is TrashPolicyDefault)
    final String hostPrefix = OZONE_OFS_URI_SCHEME + "://" + omServiceId;
    OzoneConfiguration clientConf = getClientConfForOzoneTrashPolicy(hostPrefix, conf);
    OzoneFsShell shell = new OzoneFsShell(clientConf);
    int res;
    // create volume: vol1 with bucket: bucket1
    final String testVolBucket = "/vol1/bucket1";
    final String testKey = testVolBucket + "/key1";
    final String[] volBucketArgs = new String[] { "-mkdir", "-p", testVolBucket };
    final String[] keyArgs = new String[] { "-touch", testKey };
    final String[] listArgs = new String[] { "key", "list", testVolBucket };
    LOG.info("Executing testDeleteTrashNoSkipTrash: FsShell with args {}", Arrays.asList(volBucketArgs));
    res = ToolRunner.run(shell, volBucketArgs);
    Assert.assertEquals(0, res);
    // create key: key1 belonging to bucket1
    res = ToolRunner.run(shell, keyArgs);
    Assert.assertEquals(0, res);
    // check directory listing for bucket1 contains 1 key
    out.reset();
    execute(ozoneShell, listArgs);
    Assert.assertEquals(1, getNumOfKeys());
    // Test deleting items in trash are discarded (removed from filesystem)
    // 1.) remove key1 from bucket1 with fs shell rm command
    // 2.) on rm, item is placed in Trash
    // 3.) remove Trash directory and all contents,
    // check directory listing = 0 items
    final String[] rmKeyArgs = new String[] { "-rm", "-R", testKey };
    final String[] rmTrashArgs = new String[] { "-rm", "-R", testVolBucket + "/.Trash" };
    final Path trashPathKey1 = Path.mergePaths(new Path(new OFSPath(testKey).getTrashRoot(), new Path("Current")), new Path(testKey));
    FileSystem fs = FileSystem.get(clientConf);
    try {
        // on delete key, item is placed in trash
        LOG.info("Executing testDeleteTrashNoSkipTrash: FsShell with args {}", Arrays.asList(rmKeyArgs));
        res = ToolRunner.run(shell, rmKeyArgs);
        Assert.assertEquals(0, res);
        LOG.info("Executing testDeleteTrashNoSkipTrash: key1 deleted moved to" + " Trash: " + trashPathKey1.toString());
        fs.getFileStatus(trashPathKey1);
        LOG.info("Executing testDeleteTrashNoSkipTrash: deleting trash FsShell " + "with args{}: ", Arrays.asList(rmTrashArgs));
        res = ToolRunner.run(shell, rmTrashArgs);
        Assert.assertEquals(0, res);
        out.reset();
        // once trash is is removed, trash should be deleted from filesystem
        execute(ozoneShell, listArgs);
        Assert.assertEquals(0, getNumOfKeys());
    } finally {
        shell.close();
        fs.close();
    }
}
Also used : Path(org.apache.hadoop.fs.Path) OFSPath(org.apache.hadoop.ozone.OFSPath) OzoneFsShell(org.apache.hadoop.fs.ozone.OzoneFsShell) OFSPath(org.apache.hadoop.ozone.OFSPath) FileSystem(org.apache.hadoop.fs.FileSystem) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) Test(org.junit.Test)

Example 4 with OFSPath

use of org.apache.hadoop.ozone.OFSPath in project ozone by apache.

the class BasicRootedOzoneClientAdapterImpl method listStatus.

/**
 * OFS listStatus implementation.
 *
 * @param pathStr Path for the listStatus to operate on.
 *                This takes an absolute path from OFS root.
 * @param recursive Set to true to get keys inside subdirectories.
 * @param startPath Start path of next batch of result for continuation.
 *                  This takes an absolute path from OFS root. e.g.
 *                  /volumeA/bucketB/dirC/fileD
 *                  Note startPath can optionally begin with uri, e.g.
 *                  when uri=ofs://svc1
 *                  startPath=ofs://svc1/volumeA/bucketB/dirC/fileD
 *                  will be accepted, but NOT startPath=ofs://svc2/volumeA/...
 * @param numEntries Number of maximum entries in the batch.
 * @param uri URI of OFS root.
 *            Used in making the return path qualified.
 * @param workingDir Working directory.
 *                   Used in making the return path qualified.
 * @param username User name.
 *                 Used in making the return path qualified.
 * @return A list of FileStatusAdapter.
 * @throws IOException Bucket exception or FileNotFoundException.
 */
@Override
public List<FileStatusAdapter> listStatus(String pathStr, boolean recursive, String startPath, long numEntries, URI uri, Path workingDir, String username) throws IOException {
    incrementCounter(Statistic.OBJECTS_LIST, 1);
    // Remove authority from startPath if it exists
    if (startPath.startsWith(uri.toString())) {
        try {
            startPath = new URI(startPath).getPath();
        } catch (URISyntaxException ex) {
            throw new IOException(ex);
        }
    }
    // Note: startPath could still have authority at this point if it's
    // authority doesn't match uri. This is by design. In this case,
    // OFSPath initializer will error out.
    // The goal is to refuse processing startPaths from other authorities.
    OFSPath ofsPath = new OFSPath(pathStr);
    if (ofsPath.isRoot()) {
        return listStatusRoot(recursive, startPath, numEntries, uri, workingDir, username);
    }
    OFSPath ofsStartPath = new OFSPath(startPath);
    if (ofsPath.isVolume()) {
        String startBucket = ofsStartPath.getBucketName();
        return listStatusVolume(ofsPath.getVolumeName(), recursive, startBucket, numEntries, uri, workingDir, username);
    }
    String keyName = ofsPath.getKeyName();
    // Internally we need startKey to be passed into bucket.listStatus
    String startKey = ofsStartPath.getKeyName();
    try {
        OzoneBucket bucket = getBucket(ofsPath, false);
        List<OzoneFileStatus> statuses = bucket.listStatus(keyName, recursive, startKey, numEntries);
        // Note: result in statuses above doesn't have volume/bucket path since
        // they are from the server.
        String ofsPathPrefix = ofsPath.getNonKeyPath();
        List<FileStatusAdapter> result = new ArrayList<>();
        for (OzoneFileStatus status : statuses) {
            result.add(toFileStatusAdapter(status, username, uri, workingDir, ofsPathPrefix));
        }
        return result;
    } catch (OMException e) {
        if (e.getResult() == OMException.ResultCodes.FILE_NOT_FOUND) {
            throw new FileNotFoundException(e.getMessage());
        }
        throw e;
    }
}
Also used : ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) OzoneBucket(org.apache.hadoop.ozone.client.OzoneBucket) OFSPath(org.apache.hadoop.ozone.OFSPath) OzoneFileStatus(org.apache.hadoop.ozone.om.helpers.OzoneFileStatus) OMException(org.apache.hadoop.ozone.om.exceptions.OMException)

Example 5 with OFSPath

use of org.apache.hadoop.ozone.OFSPath in project ozone by apache.

the class BasicRootedOzoneClientAdapterImpl method listKeys.

@Override
public Iterator<BasicKeyInfo> listKeys(String pathStr) throws IOException {
    incrementCounter(Statistic.OBJECTS_LIST, 1);
    OFSPath ofsPath = new OFSPath(pathStr);
    String key = ofsPath.getKeyName();
    OzoneBucket bucket;
    try {
        bucket = getBucket(ofsPath, false);
    } catch (IOException ex) {
        // return an empty list on error
        return new IteratorAdapter(Collections.emptyIterator());
    }
    return new IteratorAdapter(bucket.listKeys(key));
}
Also used : OzoneBucket(org.apache.hadoop.ozone.client.OzoneBucket) OFSPath(org.apache.hadoop.ozone.OFSPath) IOException(java.io.IOException)

Aggregations

OFSPath (org.apache.hadoop.ozone.OFSPath)38 OzoneBucket (org.apache.hadoop.ozone.client.OzoneBucket)16 Test (org.junit.Test)14 IOException (java.io.IOException)13 Path (org.apache.hadoop.fs.Path)12 OzoneVolume (org.apache.hadoop.ozone.client.OzoneVolume)8 OMException (org.apache.hadoop.ozone.om.exceptions.OMException)8 FileNotFoundException (java.io.FileNotFoundException)7 FileStatus (org.apache.hadoop.fs.FileStatus)6 ArrayList (java.util.ArrayList)4 FileAlreadyExistsException (org.apache.hadoop.fs.FileAlreadyExistsException)3 FileSystem (org.apache.hadoop.fs.FileSystem)3 PathIsNotEmptyDirectoryException (org.apache.hadoop.fs.PathIsNotEmptyDirectoryException)3 OzoneConfiguration (org.apache.hadoop.hdds.conf.OzoneConfiguration)3 OzoneKeyDetails (org.apache.hadoop.ozone.client.OzoneKeyDetails)3 OzoneFileStatus (org.apache.hadoop.ozone.om.helpers.OzoneFileStatus)3 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)3 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 FileChecksum (org.apache.hadoop.fs.FileChecksum)2