Search in sources :

Example 36 with FileInStream

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

the class S3RestServiceHandler method getObject.

private Response getObject(final FileSystem fs, final String bucket, final String object, final String range) {
    return S3RestUtils.call(bucket, () -> {
        String bucketPath = S3RestUtils.parsePath(AlluxioURI.SEPARATOR + bucket);
        S3RestUtils.checkPathIsAlluxioDirectory(fs, bucketPath);
        String objectPath = bucketPath + AlluxioURI.SEPARATOR + object;
        AlluxioURI objectURI = new AlluxioURI(objectPath);
        try {
            URIStatus status = fs.getStatus(objectURI);
            FileInStream is = fs.openFile(objectURI);
            S3RangeSpec s3Range = S3RangeSpec.Factory.create(range);
            RangeFileInStream ris = RangeFileInStream.Factory.create(is, status.getLength(), s3Range);
            // TODO(cc): Consider how to respond with the object's ETag.
            return Response.ok(ris).lastModified(new Date(status.getLastModificationTimeMs())).header(S3Constants.S3_ETAG_HEADER, "\"" + status.getLastModificationTimeMs() + "\"").header(S3Constants.S3_CONTENT_LENGTH_HEADER, s3Range.getLength(status.getLength())).build();
        } catch (Exception e) {
            throw S3RestUtils.toObjectS3Exception(e, objectPath);
        }
    });
}
Also used : FileInStream(alluxio.client.file.FileInStream) URIStatus(alluxio.client.file.URIStatus) Date(java.util.Date) AlluxioException(alluxio.exception.AlluxioException) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) DirectoryNotEmptyException(alluxio.exception.DirectoryNotEmptyException) FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) IOException(java.io.IOException) AlluxioURI(alluxio.AlluxioURI)

Example 37 with FileInStream

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

the class AlluxioJniFuseFileSystem method flushInternal.

private int flushInternal(String path, FuseFileInfo fi) {
    final long fd = fi.fh.get();
    FileInStream is = mOpenFileEntries.get(fd);
    CreateFileEntry<FileOutStream> ce = mCreateFileEntries.getFirstByField(ID_INDEX, fd);
    if (ce == null && is == null) {
        LOG.error("Cannot find fd for {} in table", path);
        return -ErrorCodes.EBADFD();
    }
    if (ce == null) {
        // flush() may be called in places other than write
        return 0;
    }
    try {
        synchronized (ce) {
            ce.getOut().flush();
        }
    } catch (Throwable e) {
        LOG.error("Failed to flush {}", path, e);
        return -ErrorCodes.EIO();
    }
    return 0;
}
Also used : FileInStream(alluxio.client.file.FileInStream) FileOutStream(alluxio.client.file.FileOutStream)

Example 38 with FileInStream

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

the class AlluxioFuseFileSystemTest method openWithoutDelay.

@Test
public void openWithoutDelay() throws Exception {
    AlluxioURI expectedPath = BASE_EXPECTED_URI.join("/foo/bar");
    setUpOpenMock(expectedPath);
    FileInStream is = mock(FileInStream.class);
    when(mFileSystem.openFile(expectedPath)).thenReturn(is);
    mFuseFs.open("/foo/bar", mFileInfo);
    verify(mFileSystem).openFile(expectedPath);
}
Also used : FileInStream(alluxio.client.file.FileInStream) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 39 with FileInStream

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

the class TailCommand method runPlainPath.

@Override
protected void runPlainPath(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException {
    URIStatus status = mFileSystem.getStatus(path);
    int numOfBytes = Constants.KB;
    if (cl.hasOption('c')) {
        numOfBytes = (int) FormatUtils.parseSpaceSize(cl.getOptionValue('c'));
        Preconditions.checkArgument(numOfBytes > 0, "specified bytes must be > 0");
    }
    if (status.isFolder()) {
        throw new IOException(ExceptionMessage.PATH_MUST_BE_FILE.getMessage(path));
    }
    try (FileInStream is = mFileSystem.openFile(path)) {
        byte[] buf = new byte[numOfBytes];
        long bytesToRead;
        if (status.getLength() > numOfBytes) {
            bytesToRead = numOfBytes;
        } else {
            bytesToRead = status.getLength();
        }
        is.skip(status.getLength() - bytesToRead);
        int read = is.read(buf);
        if (read != -1) {
            System.out.write(buf, 0, read);
        }
    }
}
Also used : FileInStream(alluxio.client.file.FileInStream) IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus)

Example 40 with FileInStream

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

the class CpCommandIntegrationTest method copyFromLocalLarge.

@Test
public void copyFromLocalLarge() throws Exception {
    File testFile = new File(sLocalAlluxioCluster.getAlluxioHome() + "/testFile");
    testFile.delete();
    testFile.createNewFile();
    FileOutputStream fos = new FileOutputStream(testFile);
    byte[] toWrite = BufferUtils.getIncreasingByteArray(SIZE_BYTES);
    fos.write(toWrite);
    fos.close();
    String[] cmd = new String[] { "cp", "file://" + testFile.getAbsolutePath(), "/testFile" };
    sFsShell.run(cmd);
    Assert.assertEquals(getCommandOutput(cmd), mOutput.toString());
    AlluxioURI uri = new AlluxioURI("/testFile");
    URIStatus status = sFileSystem.getStatus(uri);
    Assert.assertNotNull(status);
    Assert.assertEquals(SIZE_BYTES, status.getLength());
    try (FileInStream tfis = sFileSystem.openFile(uri, OpenFilePOptions.newBuilder().setReadType(ReadPType.NO_CACHE).build())) {
        byte[] read = new byte[SIZE_BYTES];
        tfis.read(read);
        Assert.assertTrue(BufferUtils.equalIncreasingByteArray(SIZE_BYTES, read));
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) FileInStream(alluxio.client.file.FileInStream) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) URIStatus(alluxio.client.file.URIStatus) File(java.io.File) AlluxioURI(alluxio.AlluxioURI) AbstractFileSystemShellTest(alluxio.client.cli.fs.AbstractFileSystemShellTest) Test(org.junit.Test) FileSystemShellUtilsTest(alluxio.client.cli.fs.FileSystemShellUtilsTest)

Aggregations

FileInStream (alluxio.client.file.FileInStream)179 AlluxioURI (alluxio.AlluxioURI)148 Test (org.junit.Test)132 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)67 URIStatus (alluxio.client.file.URIStatus)44 CreateFilePOptions (alluxio.grpc.CreateFilePOptions)31 FileOutStream (alluxio.client.file.FileOutStream)25 CreateFileOptions (alluxio.client.file.options.CreateFileOptions)21 FileSystem (alluxio.client.file.FileSystem)17 ByteBuffer (java.nio.ByteBuffer)16 ArrayList (java.util.ArrayList)14 IOException (java.io.IOException)13 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)11 File (java.io.File)11 OpenFileOptions (alluxio.client.file.options.OpenFileOptions)10 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)8 FileInfo (alluxio.wire.FileInfo)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 InstancedConfiguration (alluxio.conf.InstancedConfiguration)5 FileIncompleteException (alluxio.exception.FileIncompleteException)5