Search in sources :

Example 11 with URIStatus

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;
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Example 12 with URIStatus

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());
    }
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Example 13 with URIStatus

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());
}
Also used : FileSystem(alluxio.client.file.FileSystem) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 14 with URIStatus

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());
    }
}
Also used : ArrayList(java.util.ArrayList) LineageMasterClient(alluxio.client.lineage.LineageMasterClient) URIStatus(alluxio.client.file.URIStatus) LineageInfo(alluxio.wire.LineageInfo) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 15 with URIStatus

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"));
}
Also used : URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Aggregations

URIStatus (alluxio.client.file.URIStatus)119 AlluxioURI (alluxio.AlluxioURI)111 Test (org.junit.Test)78 AbstractAlluxioShellTest (alluxio.shell.AbstractAlluxioShellTest)23 IOException (java.io.IOException)19 FileInStream (alluxio.client.file.FileInStream)17 ArrayList (java.util.ArrayList)15 AlluxioException (alluxio.exception.AlluxioException)13 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)13 AlluxioShellUtilsTest (alluxio.shell.AlluxioShellUtilsTest)12 FileInfo (alluxio.wire.FileInfo)12 File (java.io.File)10 FileOutStream (alluxio.client.file.FileOutStream)9 FileSystem (alluxio.client.file.FileSystem)7 InvalidPathException (alluxio.exception.InvalidPathException)7 ByteBuffer (java.nio.ByteBuffer)7 CreateFileOptions (alluxio.client.file.options.CreateFileOptions)6 OpenFileOptions (alluxio.client.file.options.OpenFileOptions)5 FileSystemMaster (alluxio.master.file.FileSystemMaster)5 UnderFileSystem (alluxio.underfs.UnderFileSystem)5