Search in sources :

Example 66 with URIStatus

use of alluxio.client.file.URIStatus in project alluxio by Alluxio.

the class PersistMultipleMountsIntegrationTest method syncMultipleMountsMountedPersist.

@Test
public void syncMultipleMountsMountedPersist() throws Exception {
    // Skip non-local and non-HDFS UFSs.
    Assume.assumeTrue(UnderFileSystemUtils.isLocal(mUfs) || UnderFileSystemUtils.isHdfs(mUfs));
    String path = PathUtils.uniqPath();
    AlluxioURI filePath = new AlluxioURI(MOUNT_PATH + path);
    FileOutStream os = mFileSystem.createFile(filePath, CreateFileOptions.defaults().setWriteType(WriteType.CACHE_THROUGH));
    os.write((byte) 0);
    os.write((byte) 1);
    os.close();
    // Check the file is persisted
    URIStatus status = mFileSystem.getStatus(filePath);
    Assert.assertEquals(PersistenceState.PERSISTED.toString(), status.getPersistenceState());
    Assert.assertTrue(status.isCompleted());
    Assert.assertFalse(mUfs.exists(PathUtils.concatPath(mUfsRoot, path)));
    Assert.assertTrue(mMountedUfs.exists(PathUtils.concatPath(mMountedUfsRoot, path)));
}
Also used : FileOutStream(alluxio.client.file.FileOutStream) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 67 with URIStatus

use of alluxio.client.file.URIStatus in project alluxio by Alluxio.

the class CountCommand method countHelper.

private long[] countHelper(AlluxioURI path) throws AlluxioException, IOException {
    URIStatus status = mFileSystem.getStatus(path);
    if (!status.isFolder()) {
        return new long[] { 1L, 0L, status.getLength() };
    }
    long[] rtn = new long[] { 0L, 1L, 0L };
    List<URIStatus> statuses;
    try {
        statuses = mFileSystem.listStatus(path);
    } catch (AlluxioException e) {
        throw new IOException(e.getMessage());
    }
    for (URIStatus uriStatus : statuses) {
        long[] toAdd = countHelper(new AlluxioURI(uriStatus.getPath()));
        rtn[0] += toAdd[0];
        rtn[1] += toAdd[1];
        rtn[2] += toAdd[2];
    }
    return rtn;
}
Also used : IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus) AlluxioException(alluxio.exception.AlluxioException) AlluxioURI(alluxio.AlluxioURI)

Example 68 with URIStatus

use of alluxio.client.file.URIStatus in project alluxio by Alluxio.

the class CpCommand method copyToLocal.

/**
   * Copies a file or a directory from the Alluxio filesystem to the local filesystem.
   *
   * @param srcPath the source {@link AlluxioURI} (could be a file or a directory)
   * @param dstPath the {@link AlluxioURI} of the destination in the local filesystem
   * @throws AlluxioException when Alluxio exception occurs
   * @throws IOException when non-Alluxio exception occurs
   */
private void copyToLocal(AlluxioURI srcPath, AlluxioURI dstPath) throws AlluxioException, IOException {
    URIStatus srcStatus = mFileSystem.getStatus(srcPath);
    File dstFile = new File(dstPath.getPath());
    if (srcStatus.isFolder()) {
        // make a local directory
        if (!dstFile.exists()) {
            if (!dstFile.mkdirs()) {
                throw new IOException("mkdir failure for directory: " + dstPath);
            } else {
                System.out.println("Create directory: " + dstPath);
            }
        }
        List<URIStatus> statuses;
        try {
            statuses = mFileSystem.listStatus(srcPath);
        } catch (AlluxioException e) {
            throw new IOException(e.getMessage());
        }
        List<String> errorMessages = new ArrayList<>();
        for (URIStatus status : statuses) {
            try {
                File subDstFile = new File(dstFile.getAbsolutePath(), status.getName());
                copyToLocal(new AlluxioURI(srcPath.getScheme(), srcPath.getAuthority(), status.getPath()), new AlluxioURI(dstPath.getScheme(), dstPath.getAuthority(), subDstFile.getPath()));
            } catch (IOException e) {
                errorMessages.add(e.getMessage());
            }
        }
        if (errorMessages.size() != 0) {
            throw new IOException(Joiner.on('\n').join(errorMessages));
        }
    } else {
        copyFileToLocal(srcPath, dstPath);
    }
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus) File(java.io.File) AlluxioException(alluxio.exception.AlluxioException) AlluxioURI(alluxio.AlluxioURI)

Example 69 with URIStatus

use of alluxio.client.file.URIStatus in project alluxio by Alluxio.

the class PersistPermissionIntegrationTest method asyncPersistEmptyFilePermission.

@Test
public void asyncPersistEmptyFilePermission() throws Exception {
    // Skip non-local and non-HDFS UFSs.
    Assume.assumeTrue(UnderFileSystemUtils.isLocal(mUfs) || UnderFileSystemUtils.isHdfs(mUfs));
    AlluxioURI filePath = new AlluxioURI(PathUtils.uniqPath());
    mFileSystem.createFile(filePath, CreateFileOptions.defaults().setWriteType(WriteType.ASYNC_THROUGH)).close();
    // check the file is completed but not persisted
    URIStatus status = mFileSystem.getStatus(filePath);
    Assert.assertNotEquals(PersistenceState.PERSISTED, status.getPersistenceState());
    Assert.assertTrue(status.isCompleted());
    short fileMode = (short) status.getMode();
    short parentMode = (short) mFileSystem.getStatus(filePath.getParent()).getMode();
    IntegrationTestUtils.waitForPersist(mLocalAlluxioClusterResource, filePath);
    status = mFileSystem.getStatus(filePath);
    Assert.assertEquals(PersistenceState.PERSISTED.toString(), status.getPersistenceState());
    // Check the permission of the created file and parent dir are in-sync between Alluxio and UFS.
    Assert.assertEquals(fileMode, mUfs.getMode(PathUtils.concatPath(mUfsRoot, filePath)));
    Assert.assertEquals(parentMode, mUfs.getMode(PathUtils.concatPath(mUfsRoot, filePath.getParent())));
}
Also used : URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 70 with URIStatus

use of alluxio.client.file.URIStatus in project alluxio by Alluxio.

the class FileOutStreamAsyncWriteIntegrationTest method asyncWrite.

@Test
public void asyncWrite() throws Exception {
    AlluxioURI filePath = new AlluxioURI(PathUtils.uniqPath());
    final int length = 2;
    FileOutStream os = mFileSystem.createFile(filePath, CreateFileOptions.defaults().setWriteType(WriteType.ASYNC_THROUGH));
    os.write((byte) 0);
    os.write((byte) 1);
    os.close();
    CommonUtils.sleepMs(1);
    // check the file is completed but not persisted
    URIStatus status = mFileSystem.getStatus(filePath);
    Assert.assertEquals(PersistenceState.TO_BE_PERSISTED.toString(), status.getPersistenceState());
    Assert.assertTrue(status.isCompleted());
    IntegrationTestUtils.waitForPersist(mLocalAlluxioClusterResource, filePath);
    status = mFileSystem.getStatus(filePath);
    Assert.assertEquals(PersistenceState.PERSISTED.toString(), status.getPersistenceState());
    checkFileInAlluxio(filePath, length);
    checkFileInUnderStorage(filePath, length);
}
Also used : FileOutStream(alluxio.client.file.FileOutStream) 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