Search in sources :

Example 96 with URIStatus

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

the class JournalIntegrationTest method pinTestUtil.

private void pinTestUtil(URIStatus directory, URIStatus file0, URIStatus file1) throws AccessControlException, IOException, InvalidPathException, FileDoesNotExistException {
    FileSystemMaster fsMaster = createFsMasterFromJournal();
    FileInfo info = fsMaster.getFileInfo(fsMaster.getFileId(new AlluxioURI("/myFolder")));
    Assert.assertEquals(directory, new URIStatus(info));
    Assert.assertTrue(info.isPinned());
    info = fsMaster.getFileInfo(fsMaster.getFileId(new AlluxioURI("/myFolder/file0")));
    Assert.assertEquals(file0, new URIStatus(info));
    Assert.assertFalse(info.isPinned());
    info = fsMaster.getFileInfo(fsMaster.getFileId(new AlluxioURI("/myFolder/file1")));
    Assert.assertEquals(file1, new URIStatus(info));
    Assert.assertTrue(info.isPinned());
    fsMaster.stop();
}
Also used : FileInfo(alluxio.wire.FileInfo) FileSystemMaster(alluxio.master.file.FileSystemMaster) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI)

Example 97 with URIStatus

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

the class FileDataManager method prepareUfsFilePath.

/**
   * Prepares the destination file path of the given file id. Also creates the parent folder if it
   * does not exist.
   *
   * @param fileId the file id
   * @return the path for persistence
   * @throws AlluxioException if an unexpected Alluxio exception is thrown
   * @throws IOException if the folder creation fails
   */
private String prepareUfsFilePath(long fileId) throws AlluxioException, IOException {
    FileInfo fileInfo = mBlockWorker.getFileInfo(fileId);
    AlluxioURI alluxioPath = new AlluxioURI(fileInfo.getPath());
    FileSystem fs = FileSystem.Factory.get();
    URIStatus status = fs.getStatus(alluxioPath);
    String ufsPath = status.getUfsPath();
    UnderFileSystem ufs = UnderFileSystem.Factory.get(ufsPath);
    UnderFileSystemUtils.prepareFilePath(alluxioPath, ufsPath, fs, ufs);
    return ufsPath;
}
Also used : FileInfo(alluxio.wire.FileInfo) FileSystem(alluxio.client.file.FileSystem) UnderFileSystem(alluxio.underfs.UnderFileSystem) URIStatus(alluxio.client.file.URIStatus) UnderFileSystem(alluxio.underfs.UnderFileSystem) AlluxioURI(alluxio.AlluxioURI)

Example 98 with URIStatus

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

the class BlockServiceHandlerIntegrationTest method lockBlock.

// Tests that lock block returns the correct path
@Test
public void lockBlock() throws Exception {
    final int blockSize = (int) WORKER_CAPACITY_BYTES / 2;
    CreateFileOptions options = CreateFileOptions.defaults().setBlockSizeBytes(blockSize).setWriteType(WriteType.MUST_CACHE);
    FileOutStream out = mFileSystem.createFile(new AlluxioURI("/testFile"), options);
    URIStatus file = mFileSystem.getStatus(new AlluxioURI("/testFile"));
    final long blockId = BlockId.createBlockId(BlockId.getContainerId(file.getFileId()), 0);
    out.write(BufferUtils.getIncreasingByteArray(blockSize));
    out.close();
    String localPath = mBlockWorkerServiceHandler.lockBlock(blockId, SESSION_ID, new LockBlockTOptions()).getBlockPath();
    // The local path should exist
    Assert.assertNotNull(localPath);
    UnderFileSystem ufs = UnderFileSystem.Factory.get(localPath);
    byte[] data = new byte[blockSize];
    InputStream in = ufs.open(localPath);
    int bytesRead = in.read(data);
    // The data in the local file should equal the data we wrote earlier
    Assert.assertEquals(blockSize, bytesRead);
    Assert.assertTrue(BufferUtils.equalIncreasingByteArray(bytesRead, data));
    mBlockWorkerServiceHandler.unlockBlock(blockId, SESSION_ID);
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) InputStream(java.io.InputStream) FileOutStream(alluxio.client.file.FileOutStream) URIStatus(alluxio.client.file.URIStatus) LockBlockTOptions(alluxio.thrift.LockBlockTOptions) UnderFileSystem(alluxio.underfs.UnderFileSystem) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 99 with URIStatus

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

the class BlockServiceHandlerIntegrationTest method cacheBlock.

// Tests that caching a block successfully persists the block if the block exists
@Test
public void cacheBlock() throws Exception {
    mFileSystem.createFile(new AlluxioURI("/testFile")).close();
    URIStatus file = mFileSystem.getStatus(new AlluxioURI("/testFile"));
    final int writeTier = Constants.FIRST_TIER;
    final int blockSize = (int) WORKER_CAPACITY_BYTES / 10;
    // Construct the block ids for the file.
    final long blockId0 = BlockId.createBlockId(BlockId.getContainerId(file.getFileId()), 0);
    final long blockId1 = BlockId.createBlockId(BlockId.getContainerId(file.getFileId()), 1);
    String filename = mBlockWorkerServiceHandler.requestBlockLocation(SESSION_ID, blockId0, blockSize, writeTier);
    createBlockFile(filename, blockSize);
    mBlockWorkerServiceHandler.cacheBlock(SESSION_ID, blockId0);
    // The master should be immediately updated with the persisted block
    Assert.assertEquals(blockSize, mBlockMasterClient.getUsedBytes());
    // Attempting to cache a non existent block should throw an exception
    Exception exception = null;
    try {
        mBlockWorkerServiceHandler.cacheBlock(SESSION_ID, blockId1);
    } catch (TException e) {
        exception = e;
    }
    Assert.assertNotNull(exception);
}
Also used : AlluxioTException(alluxio.thrift.AlluxioTException) TException(org.apache.thrift.TException) URIStatus(alluxio.client.file.URIStatus) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioTException(alluxio.thrift.AlluxioTException) TException(org.apache.thrift.TException) IOException(java.io.IOException) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 100 with URIStatus

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

the class DataServerIntegrationTest method readThroughClientNonExistent.

// TODO(calvin): Make this work with the new BlockReader.
// @Test
public void readThroughClientNonExistent() throws Exception {
    final int length = 10;
    FileSystemTestUtils.createByteFile(mFileSystem, "/file", WriteType.MUST_CACHE, length);
    BlockInfo block = getFirstBlockInfo(new AlluxioURI("/file"));
    // Get the maximum block id, for use in determining a non-existent block id.
    URIStatus status = mFileSystem.getStatus(new AlluxioURI("/file"));
    long maxBlockId = block.getBlockId();
    for (long blockId : status.getBlockIds()) {
        if (blockId > maxBlockId) {
            maxBlockId = blockId;
        }
    }
    RemoteBlockReader client = RemoteBlockReader.Factory.create(FileSystemContext.INSTANCE);
    block.setBlockId(maxBlockId + 1);
    ByteBuffer result = readRemotely(client, block, length);
    Assert.assertNull(result);
}
Also used : RemoteBlockReader(alluxio.client.RemoteBlockReader) BlockInfo(alluxio.wire.BlockInfo) URIStatus(alluxio.client.file.URIStatus) ByteBuffer(java.nio.ByteBuffer) AlluxioURI(alluxio.AlluxioURI)

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