Search in sources :

Example 71 with URIStatus

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

the class FileOutStreamAsyncWriteIntegrationTest method asyncWriteEmptyFile.

@Test
public void asyncWriteEmptyFile() throws Exception {
    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());
    IntegrationTestUtils.waitForPersist(mLocalAlluxioClusterResource, filePath);
    status = mFileSystem.getStatus(filePath);
    Assert.assertEquals(PersistenceState.PERSISTED.toString(), status.getPersistenceState());
    checkFileInAlluxio(filePath, 0);
    checkFileInUnderStorage(filePath, 0);
}
Also used : URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 72 with URIStatus

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

the class AbstractFileOutStreamIntegrationTest method checkFileInUnderStorage.

/**
   * Checks the given file exists in under storage and expects its content to be an increasing
   * array of the given length.
   *
   * @param filePath path of the tmp file
   * @param fileLen length of the file
   */
protected void checkFileInUnderStorage(AlluxioURI filePath, int fileLen) throws Exception {
    URIStatus status = mFileSystem.getStatus(filePath);
    String checkpointPath = status.getUfsPath();
    UnderFileSystem ufs = UnderFileSystem.Factory.get(checkpointPath);
    try (InputStream is = ufs.open(checkpointPath)) {
        byte[] res = new byte[(int) status.getLength()];
        String underFSClass = UnderFileSystemCluster.getUnderFSClass();
        if ((LocalMiniDFSCluster.class.getName().equals(underFSClass)) && 0 == res.length) {
            // Returns -1 for zero-sized byte array to indicate no more bytes available here.
            Assert.assertEquals(-1, is.read(res));
        } else {
            Assert.assertEquals((int) status.getLength(), is.read(res));
        }
        Assert.assertTrue(BufferUtils.equalIncreasingByteArray(fileLen, res));
    }
}
Also used : InputStream(java.io.InputStream) LocalMiniDFSCluster(alluxio.underfs.hdfs.LocalMiniDFSCluster) URIStatus(alluxio.client.file.URIStatus) UnderFileSystem(alluxio.underfs.UnderFileSystem)

Example 73 with URIStatus

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

the class FileSystemIntegrationTest method renameFileTest2.

@Test
public void renameFileTest2() throws Exception {
    AlluxioURI uniqUri = new AlluxioURI(PathUtils.uniqPath());
    mFileSystem.createFile(uniqUri, mWriteBoth).close();
    URIStatus f = mFileSystem.getStatus(uniqUri);
    long oldFileId = f.getFileId();
    mFileSystem.rename(uniqUri, uniqUri);
    Assert.assertEquals(oldFileId, mFileSystem.getStatus(uniqUri).getFileId());
}
Also used : URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 74 with URIStatus

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

the class DuCommand method getFileOrFolderSize.

/**
   * Calculates the size of a path (file or folder) specified by a {@link AlluxioURI}.
   *
   * @param fs a {@link FileSystem}
   * @param path a {@link AlluxioURI} denoting the path
   * @return total size of the specified path in byte
   * @throws AlluxioException when Alluxio exception occurs
   * @throws IOException when non-Alluxio exception occurs
   */
private long getFileOrFolderSize(FileSystem fs, AlluxioURI path) throws AlluxioException, IOException {
    long sizeInBytes = 0;
    List<URIStatus> statuses = fs.listStatus(path);
    for (URIStatus status : statuses) {
        if (status.isFolder()) {
            AlluxioURI subFolder = new AlluxioURI(status.getPath());
            sizeInBytes += getFileOrFolderSize(fs, subFolder);
        } else {
            sizeInBytes += status.getLength();
        }
    }
    return sizeInBytes;
}
Also used : URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI)

Example 75 with URIStatus

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

the class StatCommand method runCommand.

@Override
protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException {
    URIStatus status = mFileSystem.getStatus(path);
    if (status.isFolder()) {
        System.out.println(path + " is a directory path.");
        System.out.println(status);
    } else {
        System.out.println(path + " is a file path.");
        System.out.println(status);
        System.out.println("Containing the following blocks: ");
        AlluxioBlockStore blockStore = AlluxioBlockStore.create();
        for (long blockId : status.getBlockIds()) {
            System.out.println(blockStore.getInfo(blockId));
        }
    }
}
Also used : URIStatus(alluxio.client.file.URIStatus) AlluxioBlockStore(alluxio.client.block.AlluxioBlockStore)

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