use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class AbstractFileSystem method rename.
@Override
public boolean rename(Path src, Path dst) throws IOException {
LOG.debug("rename({}, {})", src, dst);
if (mStatistics != null) {
mStatistics.incrementWriteOps(1);
}
AlluxioURI srcPath = new AlluxioURI(HadoopUtils.getPathWithoutScheme(src));
AlluxioURI dstPath = new AlluxioURI(HadoopUtils.getPathWithoutScheme(dst));
try {
mFileSystem.rename(srcPath, dstPath);
} catch (FileDoesNotExistException e) {
LOG.error("Failed to rename {} to {}", src, dst);
return false;
} catch (AlluxioException e) {
ensureExists(srcPath);
URIStatus dstStatus;
try {
dstStatus = mFileSystem.getStatus(dstPath);
} catch (IOException | AlluxioException e2) {
LOG.error("Failed to rename {} to {}", src, dst);
return false;
}
// If the destination is an existing folder, try to move the src into the folder
if (dstStatus != null && dstStatus.isFolder()) {
dstPath = dstPath.join(srcPath.getName());
} else {
LOG.error("Failed to rename {} to {}", src, dst);
return false;
}
try {
mFileSystem.rename(srcPath, dstPath);
} catch (IOException | AlluxioException e2) {
LOG.error("Failed to rename {} to {}", src, dst, e2);
return false;
}
} catch (IOException e) {
LOG.error("Failed to rename {} to {}", src, dst, e);
return false;
}
return true;
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class FileSystemTestUtils method listFiles.
/**
* Returns a list of files at a given {@code path}.
*
* @param fs a {@link FileSystem} handler
* @param path a path in alluxio file system
* @return a list of strings representing the file names under the given path
* @throws IOException if {@code path} does not exist or is invalid
*/
public static List<String> listFiles(FileSystem fs, String path) throws IOException {
try {
List<URIStatus> statuses = fs.listStatus(new AlluxioURI(path));
List<String> res = new ArrayList<>();
for (URIStatus status : statuses) {
res.add(status.getPath());
if (status.isFolder()) {
res.addAll(listFiles(fs, status.getPath()));
}
}
return res;
} catch (AlluxioException e) {
throw new IOException(e.getMessage());
}
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class ClusterInitializationTest method startCluster.
/**
* When a user starts a new cluster, an empty root dir is created and owned by the user.
*/
@Test
@LocalAlluxioClusterResource.Config(confParams = { PropertyKey.Name.SECURITY_LOGIN_USERNAME, SUPER_USER })
public void startCluster() throws Exception {
FileSystem fs = mLocalAlluxioClusterResource.get().getClient();
URIStatus status = fs.getStatus(ROOT);
Assert.assertEquals(SUPER_USER, status.getOwner());
Assert.assertEquals(0755, status.getMode());
Assert.assertEquals(0, fs.listStatus(new AlluxioURI("/")).size());
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class LineageMasterIntegrationTest method lineageCreation.
@Test
public void lineageCreation() throws Exception {
try (LineageMasterClient lineageMasterClient = getLineageMasterClient()) {
ArrayList<String> outFiles = new ArrayList<>();
Collections.addAll(outFiles, OUT_FILE);
lineageMasterClient.createLineage(new ArrayList<String>(), outFiles, mJob);
List<LineageInfo> infos = lineageMasterClient.getLineageInfoList();
Assert.assertEquals(1, infos.size());
AlluxioURI uri = new AlluxioURI(infos.get(0).getOutputFiles().get(0));
URIStatus status = getFileSystemMasterClient().getStatus(uri);
Assert.assertEquals(PersistenceState.NOT_PERSISTED.toString(), status.getPersistenceState());
Assert.assertFalse(status.isCompleted());
}
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class ConcurrentFileSystemMasterTest method sameFileConcurrentRename.
/**
* Tests that many threads concurrently renaming the same file will only succeed once.
*/
@Test
public void sameFileConcurrentRename() throws Exception {
int numThreads = CONCURRENCY_FACTOR;
final AlluxioURI[] srcs = new AlluxioURI[numThreads];
final AlluxioURI[] dsts = new AlluxioURI[numThreads];
for (int i = 0; i < numThreads; i++) {
srcs[i] = new AlluxioURI("/file");
dsts[i] = new AlluxioURI("/renamed" + i);
}
// Create the one source file
mFileSystem.createFile(srcs[0], sCreatePersistedFileOptions).close();
int errors = concurrentRename(srcs, dsts);
// We should get an error for all but 1 rename
Assert.assertEquals(numThreads - 1, errors);
List<URIStatus> files = mFileSystem.listStatus(new AlluxioURI("/"));
// Only one renamed file should exist
Assert.assertEquals(1, files.size());
Assert.assertTrue(files.get(0).getName().startsWith("renamed"));
}
Aggregations