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);
}
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());
}
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();
}
}
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;
}
}
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));
}
Aggregations