Search in sources :

Example 46 with URIStatus

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

the class IsolatedFileSystemIntegrationTest method lockBlockTest3.

@Test
public void lockBlockTest3() throws Exception {
    String uniqPath = PathUtils.uniqPath();
    FileInStream is;
    ByteBuffer buf;
    int numOfFiles = 5;
    int fileSize = WORKER_CAPACITY_BYTES / numOfFiles;
    List<AlluxioURI> files = new ArrayList<>();
    for (int k = 0; k < numOfFiles; k++) {
        FileSystemTestUtils.createByteFile(mFileSystem, uniqPath + k, fileSize, mWriteBoth);
        files.add(new AlluxioURI(uniqPath + k));
    }
    for (int k = 0; k < numOfFiles; k++) {
        URIStatus info = mFileSystem.getStatus(files.get(k));
        Assert.assertTrue(info.getInMemoryPercentage() == 100);
        is = mFileSystem.openFile(files.get(k), FileSystemTestUtils.toOpenFileOptions(mWriteBoth));
        buf = ByteBuffer.allocate((int) info.getBlockSizeBytes());
        int r = is.read(buf.array());
        if (k < numOfFiles - 1) {
            Assert.assertTrue(r != -1);
        }
        is.close();
    }
    FileSystemTestUtils.createByteFile(mFileSystem, uniqPath + numOfFiles, fileSize, mWriteBoth);
    files.add(new AlluxioURI(uniqPath + numOfFiles));
    HeartbeatScheduler.execute(HeartbeatContext.WORKER_BLOCK_SYNC);
    URIStatus info = mFileSystem.getStatus(files.get(0));
    Assert.assertFalse(info.getInMemoryPercentage() == 100);
    for (int k = 1; k <= numOfFiles; k++) {
        info = mFileSystem.getStatus(files.get(k));
        Assert.assertTrue(info.getInMemoryPercentage() == 100);
    }
}
Also used : FileInStream(alluxio.client.file.FileInStream) ArrayList(java.util.ArrayList) URIStatus(alluxio.client.file.URIStatus) ByteBuffer(java.nio.ByteBuffer) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 47 with URIStatus

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

the class IsolatedFileSystemIntegrationTest method unlockBlockTest3.

@Test
public void unlockBlockTest3() throws Exception {
    String uniqPath = PathUtils.uniqPath();
    FileInStream is;
    ByteBuffer buf1;
    ByteBuffer buf2;
    int numOfFiles = 5;
    int fileSize = WORKER_CAPACITY_BYTES / numOfFiles;
    List<AlluxioURI> files = new ArrayList<>();
    for (int k = 0; k < numOfFiles; k++) {
        FileSystemTestUtils.createByteFile(mFileSystem, uniqPath + k, fileSize, mWriteBoth);
        files.add(new AlluxioURI(uniqPath + k));
    }
    for (int k = 0; k < numOfFiles; k++) {
        URIStatus info = mFileSystem.getStatus(files.get(k));
        Assert.assertTrue(info.getInMemoryPercentage() == 100);
        is = mFileSystem.openFile(files.get(k), FileSystemTestUtils.toOpenFileOptions(mWriteBoth));
        buf1 = ByteBuffer.allocate((int) info.getBlockSizeBytes());
        Assert.assertTrue(is.read(buf1.array()) != -1);
        buf2 = ByteBuffer.allocate((int) info.getBlockSizeBytes());
        is.seek(0);
        Assert.assertTrue(is.read(buf2.array()) != -1);
        is.close();
    }
    FileSystemTestUtils.createByteFile(mFileSystem, uniqPath + numOfFiles, fileSize, mWriteBoth);
    files.add(new AlluxioURI(uniqPath + numOfFiles));
    HeartbeatScheduler.execute(HeartbeatContext.WORKER_BLOCK_SYNC);
    URIStatus info = mFileSystem.getStatus(files.get(0));
    Assert.assertFalse(info.getInMemoryPercentage() == 100);
    for (int k = 1; k <= numOfFiles; k++) {
        URIStatus in = mFileSystem.getStatus(files.get(k));
        Assert.assertTrue(in.getInMemoryPercentage() == 100);
    }
}
Also used : FileInStream(alluxio.client.file.FileInStream) ArrayList(java.util.ArrayList) URIStatus(alluxio.client.file.URIStatus) ByteBuffer(java.nio.ByteBuffer) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 48 with URIStatus

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

the class CpCommand method copy.

/**
   * Copies a file or a directory in the Alluxio filesystem.
   *
   * @param srcPath the source {@link AlluxioURI} (could be a file or a directory)
   * @param dstPath the {@link AlluxioURI} of the destination path in the Alluxio filesystem
   * @param recursive indicates whether directories should be copied recursively
   * @throws AlluxioException when Alluxio exception occurs
   * @throws IOException when non-Alluxio exception occurs
   */
private void copy(AlluxioURI srcPath, AlluxioURI dstPath, boolean recursive) throws AlluxioException, IOException {
    URIStatus srcStatus = mFileSystem.getStatus(srcPath);
    URIStatus dstStatus = null;
    try {
        dstStatus = mFileSystem.getStatus(dstPath);
    } catch (FileDoesNotExistException e) {
    // if the destination does not exist, it will be created
    }
    if (!srcStatus.isFolder()) {
        if (dstStatus != null && dstStatus.isFolder()) {
            dstPath = new AlluxioURI(PathUtils.concatPath(dstPath.getPath(), srcPath.getName()));
        }
        copyFile(srcPath, dstPath);
    } else {
        if (!recursive) {
            throw new IOException(srcPath.getPath() + " is a directory, to copy it please use \"cp -R <src> <dst>\"");
        }
        List<URIStatus> statuses;
        statuses = mFileSystem.listStatus(srcPath);
        if (dstStatus != null) {
            if (!dstStatus.isFolder()) {
                throw new InvalidPathException(ExceptionMessage.DESTINATION_CANNOT_BE_FILE.getMessage());
            }
            // subdirectory of the destination
            if (srcStatus.isFolder()) {
                dstPath = new AlluxioURI(PathUtils.concatPath(dstPath.getPath(), srcPath.getName()));
                mFileSystem.createDirectory(dstPath);
                System.out.println("Created directory: " + dstPath);
            }
        }
        if (dstStatus == null) {
            mFileSystem.createDirectory(dstPath);
            System.out.println("Created directory: " + dstPath);
        }
        List<String> errorMessages = new ArrayList<>();
        for (URIStatus status : statuses) {
            try {
                copy(new AlluxioURI(srcPath.getScheme(), srcPath.getAuthority(), status.getPath()), new AlluxioURI(dstPath.getScheme(), dstPath.getAuthority(), PathUtils.concatPath(dstPath.getPath(), status.getName())), recursive);
            } catch (IOException e) {
                errorMessages.add(e.getMessage());
            }
        }
        if (errorMessages.size() != 0) {
            throw new IOException(Joiner.on('\n').join(errorMessages));
        }
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

Example 49 with URIStatus

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

the class CpCommand method copyWildcard.

/**
   * Copies a list of files or directories specified by srcPaths to the destination specified by
   * dstPath. This method is used when the original source path contains wildcards.
   *
   * @param srcPaths a list of files or directories in the Alluxio filesystem
   * @param dstPath the destination in the Alluxio filesystem
   * @param recursive indicates whether directories should be copied recursively
   * @throws AlluxioException when Alluxio exception occurs
   * @throws IOException when non-Alluxio exception occurs
   */
private void copyWildcard(List<AlluxioURI> srcPaths, AlluxioURI dstPath, boolean recursive) throws AlluxioException, IOException {
    URIStatus dstStatus = null;
    try {
        dstStatus = mFileSystem.getStatus(dstPath);
    } catch (FileDoesNotExistException e) {
    // if the destination does not exist, it will be created
    }
    if (dstStatus != null && !dstStatus.isFolder()) {
        throw new InvalidPathException(ExceptionMessage.DESTINATION_CANNOT_BE_FILE.getMessage());
    }
    if (dstStatus == null) {
        mFileSystem.createDirectory(dstPath);
        System.out.println("Created directory: " + dstPath);
    }
    List<String> errorMessages = new ArrayList<>();
    for (AlluxioURI srcPath : srcPaths) {
        try {
            copy(srcPath, new AlluxioURI(dstPath.getScheme(), dstPath.getAuthority(), PathUtils.concatPath(dstPath.getPath(), srcPath.getName())), recursive);
        } catch (AlluxioException | IOException e) {
            errorMessages.add(e.getMessage());
        }
    }
    if (errorMessages.size() != 0) {
        throw new IOException(Joiner.on('\n').join(errorMessages));
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Example 50 with URIStatus

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

the class AbstractFileOutStreamIntegrationTest method checkFileInAlluxio.

/**
   * Checks the given file exists in Alluxio 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 checkFileInAlluxio(AlluxioURI filePath, int fileLen) throws Exception {
    URIStatus status = mFileSystem.getStatus(filePath);
    Assert.assertEquals(fileLen, status.getLength());
    try (FileInStream is = mFileSystem.openFile(filePath, OpenFileOptions.defaults().setReadType(ReadType.NO_CACHE))) {
        byte[] res = new byte[(int) status.getLength()];
        Assert.assertEquals((int) status.getLength(), is.read(res));
        Assert.assertTrue(BufferUtils.equalIncreasingByteArray(fileLen, res));
    }
}
Also used : FileInStream(alluxio.client.file.FileInStream) URIStatus(alluxio.client.file.URIStatus)

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