Search in sources :

Example 31 with CreateFilePOptions

use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.

the class MultiUfsMountIntegrationTest method createFile.

@Test
public void createFile() throws Exception {
    CreateFilePOptions writeBoth = CreateFilePOptions.newBuilder().setWriteType(WritePType.CACHE_THROUGH).build();
    AlluxioURI file1 = mMountPoint1.join("file1");
    AlluxioURI file2 = mMountPoint2.join("file2");
    mFileSystem.createFile(file1, writeBoth).close();
    mFileSystem.createFile(file2, writeBoth).close();
    Assert.assertTrue(mLocalUfs.isFile(PathUtils.concatPath(mUfsUri1, "file1")));
    Assert.assertTrue(mLocalUfs.isFile(PathUtils.concatPath(mUfsUri2, "file2")));
}
Also used : CreateFilePOptions(alluxio.grpc.CreateFilePOptions) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 32 with CreateFilePOptions

use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.

the class CapacityUsageIntegrationTest method createAndWriteFile.

private void createAndWriteFile(AlluxioURI filePath, WritePType writeType, int len) throws IOException, AlluxioException {
    ByteBuffer buf = ByteBuffer.allocate(len);
    buf.order(ByteOrder.nativeOrder());
    for (int k = 0; k < len; k++) {
        buf.put((byte) k);
    }
    CreateFilePOptions options = CreateFilePOptions.newBuilder().setWriteType(writeType).build();
    FileOutStream os = mFileSystem.createFile(filePath, options);
    os.write(buf.array());
    os.close();
}
Also used : FileOutStream(alluxio.client.file.FileOutStream) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) ByteBuffer(java.nio.ByteBuffer)

Example 33 with CreateFilePOptions

use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.

the class SpecificTierWriteIntegrationTest method writeFileAndCheckUsage.

/**
 * Writes a file into a specified tier, and then verifies the expected bytes on each tier.
 *
 * @param writeTier the specific tier to write the file to
 * @param writeSize number of bytes to write
 * @param memBytes the expected number of bytes used in the MEM tier
 * @param ssdBytes the expected number of bytes used in the SSD tier
 * @param hddBytes the expected number of bytes used in the HDD tier
 */
private void writeFileAndCheckUsage(int writeTier, int writeSize, long memBytes, long ssdBytes, long hddBytes) throws Exception {
    CreateFilePOptions createOptions = CreateFilePOptions.newBuilder().setWriteTier(writeTier).setWriteType(WritePType.MUST_CACHE).build();
    FileOutStream os = mFileSystem.createFile(new AlluxioURI("/tier-" + writeTier + "_" + CommonUtils.randomAlphaNumString(5)), createOptions);
    os.write(BufferUtils.getIncreasingByteArray(writeSize));
    os.close();
    HeartbeatScheduler.execute(HeartbeatContext.WORKER_BLOCK_SYNC);
    long totalBytes = memBytes + ssdBytes + hddBytes;
    Assert.assertEquals("Total bytes used", totalBytes, mLocalAlluxioClusterResource.get().getLocalAlluxioMaster().getMasterProcess().getMaster(BlockMaster.class).getUsedBytes());
    Map<String, Long> bytesOnTiers = mLocalAlluxioClusterResource.get().getLocalAlluxioMaster().getMasterProcess().getMaster(BlockMaster.class).getUsedBytesOnTiers();
    Assert.assertEquals("MEM tier usage", memBytes, bytesOnTiers.get(Constants.MEDIUM_MEM).longValue());
    Assert.assertEquals("SSD tier usage", ssdBytes, bytesOnTiers.get(Constants.MEDIUM_SSD).longValue());
    Assert.assertEquals("HDD tier usage", hddBytes, bytesOnTiers.get(Constants.MEDIUM_HDD).longValue());
}
Also used : BlockMaster(alluxio.master.block.BlockMaster) FileOutStream(alluxio.client.file.FileOutStream) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) AlluxioURI(alluxio.AlluxioURI)

Example 34 with CreateFilePOptions

use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.

the class AbstractFileSystem method create.

/**
 * Attempts to create a file. Overwrite will not succeed if the path exists and is a folder.
 *
 * @param path path to create
 * @param permission permissions of the created file/folder
 * @param overwrite overwrite if file exists
 * @param bufferSize the size in bytes of the buffer to be used
 * @param replication under filesystem replication factor, this is ignored
 * @param blockSize block size in bytes
 * @param progress queryable progress
 * @return an {@link FSDataOutputStream} created at the indicated path of a file
 */
@Override
public FSDataOutputStream create(Path path, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException {
    LOG.debug("create({}, {}, {}, {}, {}, {}, {})", path, permission, overwrite, bufferSize, replication, blockSize, progress);
    if (mStatistics != null) {
        mStatistics.incrementWriteOps(1);
    }
    AlluxioURI uri = getAlluxioPath(path);
    CreateFilePOptions options = CreateFilePOptions.newBuilder().setBlockSizeBytes(blockSize).setMode(new Mode(permission.toShort()).toProto()).setRecursive(true).build();
    FileOutStream outStream;
    try {
        outStream = mFileSystem.createFile(uri, options);
    } catch (AlluxioException e) {
        // now we should consider the override parameter
        try {
            if (mFileSystem.exists(uri)) {
                if (!overwrite) {
                    throw new IOException("Not allowed to create() (overwrite=false) for existing Alluxio path: " + uri);
                }
                if (mFileSystem.getStatus(uri).isFolder()) {
                    throw new IOException(ExceptionMessage.FILE_CREATE_IS_DIRECTORY.getMessage(uri));
                }
                mFileSystem.delete(uri);
            }
            outStream = mFileSystem.createFile(uri, options);
        } catch (AlluxioException e2) {
            throw new IOException(e2);
        }
    }
    return new FSDataOutputStream(outStream, mStatistics);
}
Also used : Mode(alluxio.security.authorization.Mode) FileOutStream(alluxio.client.file.FileOutStream) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) IOException(java.io.IOException) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Example 35 with CreateFilePOptions

use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.

the class FileInStreamIntegrationTest method readTest2.

/**
 * Tests {@link FileInStream#read(byte[])}.
 */
@Test
@LocalAlluxioClusterResource.Config(confParams = { PropertyKey.Name.USER_STREAMING_READER_CHUNK_SIZE_BYTES, "64KB" })
public void readTest2() throws Exception {
    for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
        for (CreateFilePOptions op : getOptionSet()) {
            String filename = mTestPath + "/file_" + k + "_" + op.hashCode();
            AlluxioURI uri = new AlluxioURI(filename);
            FileInStream is = mFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op));
            byte[] ret = new byte[k];
            Assert.assertEquals(k, is.read(ret));
            Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
            is.close();
            is = mFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op));
            ret = new byte[k];
            Assert.assertEquals(k, is.read(ret));
            Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
            is.close();
        }
    }
}
Also used : FileInStream(alluxio.client.file.FileInStream) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Aggregations

CreateFilePOptions (alluxio.grpc.CreateFilePOptions)68 AlluxioURI (alluxio.AlluxioURI)61 Test (org.junit.Test)49 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)36 FileInStream (alluxio.client.file.FileInStream)27 FileOutStream (alluxio.client.file.FileOutStream)16 URIStatus (alluxio.client.file.URIStatus)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 FileSystem (alluxio.client.file.FileSystem)4 AlluxioException (alluxio.exception.AlluxioException)4 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)4 CreateDirectoryPOptions (alluxio.grpc.CreateDirectoryPOptions)4 IOException (java.io.IOException)4 DirectoryNotEmptyException (alluxio.exception.DirectoryNotEmptyException)3 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)3 ArrayList (java.util.ArrayList)3 ConfigurationRule (alluxio.ConfigurationRule)2 BlockMaster (alluxio.master.block.BlockMaster)2 Mode (alluxio.security.authorization.Mode)2 UnderFileSystem (alluxio.underfs.UnderFileSystem)2