Search in sources :

Example 76 with FileSystem

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

the class TestRunner method runTests.

/**
 * Runs combinations of tests of operation, read and write type.
 *
 * @return the number of failed tests
 */
private int runTests() throws Exception {
    mDirectory = PathUtils.concatPath(mDirectory, TEST_DIRECTORY_NAME);
    AlluxioURI testDir = new AlluxioURI(mDirectory);
    FileSystemContext fsContext = FileSystemContext.create(new InstancedConfiguration(ConfigurationUtils.defaults()));
    FileSystem fs = FileSystem.Factory.create(fsContext);
    if (fs.exists(testDir)) {
        fs.delete(testDir, DeletePOptions.newBuilder().setRecursive(true).setUnchecked(true).build());
    }
    int failed = 0;
    List<ReadType> readTypes = mReadType == null ? READ_TYPES : Lists.newArrayList(ReadType.valueOf(mReadType));
    List<WriteType> writeTypes = mWriteType == null ? WRITE_TYPES : Lists.newArrayList(WriteType.valueOf(mWriteType));
    List<OperationType> operations = mOperation == null ? Lists.newArrayList(OperationType.values()) : Lists.newArrayList(OperationType.valueOf(mOperation));
    for (ReadType readType : readTypes) {
        for (WriteType writeType : writeTypes) {
            for (OperationType opType : operations) {
                System.out.println(String.format("runTest --operation %s --readType %s --writeType %s", opType, readType, writeType));
                failed += runTest(opType, readType, writeType, fsContext);
            }
        }
    }
    if (failed > 0) {
        System.out.println("Number of failed tests: " + failed);
    }
    return failed;
}
Also used : InstancedConfiguration(alluxio.conf.InstancedConfiguration) ReadType(alluxio.client.ReadType) WriteType(alluxio.client.WriteType) FileSystem(alluxio.client.file.FileSystem) FileSystemContext(alluxio.client.file.FileSystemContext) AlluxioURI(alluxio.AlluxioURI)

Example 77 with FileSystem

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

the class FileInStreamRehydrationIntegrationTest method testRehydration.

@Test
public void testRehydration() throws Exception {
    FileSystem fs = FileSystem.Factory.create(ServerConfiguration.global());
    // Create a file with 10 blocks.
    AlluxioURI filePath = new AlluxioURI(PathUtils.uniqPath());
    CreateFilePOptions op = CreateFilePOptions.newBuilder().setWriteType(WritePType.CACHE_THROUGH).setRecursive(true).build();
    byte[] content = generateContent(BLOCK_BYTES * 10);
    try (FileOutStream os = fs.createFile(filePath, op)) {
        os.write(content);
    }
    // Validate file size and content.
    validateAndCloseFileStream(mFileSystem.openFile(filePath), content);
    // Grab the block master for emulating lost blocks.
    MasterProcess masterProcess = Whitebox.getInternalState(mLocalAlluxioClusterResource.get().getLocalAlluxioMaster(), "mMasterProcess");
    BlockMaster blockMaster = masterProcess.getMaster(BlockMaster.class);
    // Remove blocks externally from block-master.
    URIStatus status = fs.getStatus(filePath);
    blockMaster.removeBlocks(status.getBlockIds(), true);
    // Validate file size and content.
    validateAndCloseFileStream(mFileSystem.openFile(filePath), content);
}
Also used : BlockMaster(alluxio.master.block.BlockMaster) FileSystem(alluxio.client.file.FileSystem) FileOutStream(alluxio.client.file.FileOutStream) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) MasterProcess(alluxio.master.MasterProcess) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) AbstractFileOutStreamIntegrationTest(alluxio.client.fs.io.AbstractFileOutStreamIntegrationTest)

Example 78 with FileSystem

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

the class FileOutStreamAsyncWriteIntegrationTest method testLostAsyncBlocks.

/**
 * Test eviction against a file that is slow to persist in Alluxio. The test cluster should be
 * configured with a high initial wait time, or -1
 *
 * This test performs the following actions:
 * - creates a file with ASYNC_THROUGH which fills the entire capacity of a worker
 * - Tries to create another 1-byte file on top and expects it to fail
 * - persists the file to the UFS
 * - Tries to create 1-byte file again and it should succeed this time
 */
private void testLostAsyncBlocks() throws Exception {
    long cap = FormatUtils.parseSpaceSize(TINY_WORKER_MEM);
    FileSystem fs = mLocalAlluxioClusterResource.get().getClient();
    // Create a large-ish file in the UFS (relative to memory size)
    String p1 = "/test";
    FileSystemTestUtils.createByteFile(fs, p1, WritePType.ASYNC_THROUGH, (int) cap);
    URIStatus fstat = fs.listStatus(new AlluxioURI(p1)).get(0);
    int lostBlocks = fstat.getFileBlockInfos().stream().map(FileBlockInfo::getBlockInfo).filter(blk -> blk.getLocations().size() <= 0).mapToInt(blk -> 1).sum();
    assertEquals(cap, getClusterCapacity());
    assertEquals(cap, getUsedWorkerSpace());
    assertEquals(100, fstat.getInAlluxioPercentage());
    assertEquals(0, lostBlocks);
    // Try to create 1-byte file on top. Expect to fail.
    try {
        FileSystemTestUtils.createByteFile(fs, "/byte-file1", WritePType.MUST_CACHE, 1);
        assertTrue("Shouldn't reach here.", false);
    } catch (Exception e) {
    // expected.
    }
    FileSystemUtils.persistAndWait(fs, new AlluxioURI(p1), 0);
    fstat = fs.listStatus(new AlluxioURI(p1)).get(0);
    assertTrue(fstat.isPersisted());
    assertEquals(0, mLocalAlluxioClusterResource.get().getLocalAlluxioMaster().getMasterProcess().getMaster(FileSystemMaster.class).getPinIdList().size());
    // Try to create 1-byte file on top. Expect to succeed.
    FileSystemTestUtils.createByteFile(fs, "/byte-file2", WritePType.MUST_CACHE, 1);
}
Also used : CreateFilePOptions(alluxio.grpc.CreateFilePOptions) BlockWorker(alluxio.worker.block.BlockWorker) Arrays(java.util.Arrays) IntegrationTestUtils(alluxio.testutils.IntegrationTestUtils) FileSystemTestUtils(alluxio.client.file.FileSystemTestUtils) FileBlockInfo(alluxio.wire.FileBlockInfo) BlockMaster(alluxio.master.block.BlockMaster) FileOutStream(alluxio.client.file.FileOutStream) PropertyKey(alluxio.conf.PropertyKey) FileSystemMaster(alluxio.master.file.FileSystemMaster) PathUtils(alluxio.util.io.PathUtils) FileSystem(alluxio.client.file.FileSystem) Constants(alluxio.Constants) WorkerInfo(alluxio.wire.WorkerInfo) AlluxioURI(alluxio.AlluxioURI) FormatUtils(alluxio.util.FormatUtils) ClientContext(alluxio.ClientContext) AbstractFileOutStreamIntegrationTest(alluxio.client.fs.io.AbstractFileOutStreamIntegrationTest) WritePType(alluxio.grpc.WritePType) ServerConfiguration(alluxio.conf.ServerConfiguration) LocalAlluxioClusterResource(alluxio.testutils.LocalAlluxioClusterResource) Assert.assertTrue(org.junit.Assert.assertTrue) PersistenceState(alluxio.master.file.meta.PersistenceState) Test(org.junit.Test) URIStatus(alluxio.client.file.URIStatus) MasterClientContext(alluxio.master.MasterClientContext) FileSystemUtils(alluxio.client.file.FileSystemUtils) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) CommonUtils(alluxio.util.CommonUtils) UnavailableException(alluxio.exception.status.UnavailableException) FileSystem(alluxio.client.file.FileSystem) FileSystemMaster(alluxio.master.file.FileSystemMaster) URIStatus(alluxio.client.file.URIStatus) UnavailableException(alluxio.exception.status.UnavailableException) AlluxioURI(alluxio.AlluxioURI)

Example 79 with FileSystem

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

the class S3RestServiceHandler method getBucket.

/**
 * @summary gets a bucket and lists all the objects in it
 * @param authorization header parameter authorization
 * @param bucket the bucket name
 * @param markerParam the optional marker param
 * @param prefixParam the optional prefix param
 * @param delimiterParam the optional delimiter param
 * @param encodingTypeParam optional encoding type param
 * @param maxKeysParam the optional max keys param
 * @param listTypeParam if listObjectV2 request
 * @param continuationTokenParam the optional continuationToken param for listObjectV2
 * @param startAfterParam  the optional startAfter param for listObjectV2
 * @return the response object
 */
@GET
@Path(BUCKET_PARAM)
public Response getBucket(@HeaderParam("Authorization") String authorization, @PathParam("bucket") final String bucket, @QueryParam("marker") final String markerParam, @QueryParam("prefix") final String prefixParam, @QueryParam("delimiter") final String delimiterParam, @QueryParam("encoding-type") final String encodingTypeParam, @QueryParam("max-keys") final int maxKeysParam, @QueryParam("list-type") final int listTypeParam, @QueryParam("continuation-token") final String continuationTokenParam, @QueryParam("start-after") final String startAfterParam) {
    return S3RestUtils.call(bucket, () -> {
        Preconditions.checkNotNull(bucket, "required 'bucket' parameter is missing");
        String marker = markerParam == null ? "" : markerParam;
        String prefix = prefixParam == null ? "" : prefixParam;
        String encodingType = encodingTypeParam == null ? "url" : encodingTypeParam;
        int maxKeys = maxKeysParam <= 0 ? ListBucketOptions.DEFAULT_MAX_KEYS : maxKeysParam;
        String continuationToken = continuationTokenParam == null ? "" : continuationTokenParam;
        String startAfter = startAfterParam == null ? "" : startAfterParam;
        ListBucketOptions listBucketOptions = ListBucketOptions.defaults().setMarker(marker).setPrefix(prefix).setMaxKeys(maxKeys).setDelimiter(delimiterParam).setEncodingType(encodingType).setListType(listTypeParam).setContinuationToken(continuationToken).setStartAfter(startAfter);
        String path = S3RestUtils.parsePath(AlluxioURI.SEPARATOR + bucket);
        final FileSystem fs = getFileSystem(authorization);
        List<URIStatus> children;
        try {
            // only list the direct children if delimiter is not null
            if (delimiterParam != null) {
                path = parsePath(path, prefix, delimiterParam);
                children = fs.listStatus(new AlluxioURI(path));
            } else {
                ListStatusPOptions options = ListStatusPOptions.newBuilder().setRecursive(true).build();
                children = fs.listStatus(new AlluxioURI(path), options);
            }
        } catch (FileDoesNotExistException e) {
            // returned which does not match the S3 response behavior
            throw new S3Exception(e, bucket, S3ErrorCode.NO_SUCH_BUCKET);
        } catch (IOException | AlluxioException e) {
            throw new RuntimeException(e);
        }
        return new ListBucketResult(bucket, children, listBucketOptions);
    });
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus) ListStatusPOptions(alluxio.grpc.ListStatusPOptions) FileSystem(alluxio.client.file.FileSystem) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 80 with FileSystem

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

the class S3RestServiceHandler method createBucket.

/**
 * @summary creates a bucket
 * @param authorization header parameter authorization
 * @param bucket the bucket name
 * @return the response object
 */
@PUT
@Path(BUCKET_PARAM)
public Response createBucket(@HeaderParam("Authorization") String authorization, @PathParam("bucket") final String bucket) {
    return S3RestUtils.call(bucket, () -> {
        Preconditions.checkNotNull(bucket, "required 'bucket' parameter is missing");
        String bucketPath = S3RestUtils.parsePath(AlluxioURI.SEPARATOR + bucket);
        final FileSystem fs = getFileSystem(authorization);
        // Create the bucket.
        CreateDirectoryPOptions options = CreateDirectoryPOptions.newBuilder().setWriteType(S3RestUtils.getS3WriteType()).build();
        try {
            fs.createDirectory(new AlluxioURI(bucketPath), options);
        } catch (Exception e) {
            throw S3RestUtils.toBucketS3Exception(e, bucketPath);
        }
        return Response.Status.OK;
    });
}
Also used : CreateDirectoryPOptions(alluxio.grpc.CreateDirectoryPOptions) FileSystem(alluxio.client.file.FileSystem) AlluxioException(alluxio.exception.AlluxioException) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) DirectoryNotEmptyException(alluxio.exception.DirectoryNotEmptyException) FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) IOException(java.io.IOException) AlluxioURI(alluxio.AlluxioURI) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Aggregations

FileSystem (alluxio.client.file.FileSystem)122 AlluxioURI (alluxio.AlluxioURI)90 Test (org.junit.Test)75 URIStatus (alluxio.client.file.URIStatus)42 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)22 FileInStream (alluxio.client.file.FileInStream)13 IOException (java.io.IOException)12 AbstractFileSystemShellTest (alluxio.client.cli.fs.AbstractFileSystemShellTest)11 ArrayList (java.util.ArrayList)11 FileOutStream (alluxio.client.file.FileOutStream)10 AlluxioException (alluxio.exception.AlluxioException)9 File (java.io.File)9 Path (javax.ws.rs.Path)9 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)8 HashMap (java.util.HashMap)8 FileSystemContext (alluxio.client.file.FileSystemContext)7 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)6 CreateFilePOptions (alluxio.grpc.CreateFilePOptions)6 TestUserState (alluxio.security.user.TestUserState)6 InstancedConfiguration (alluxio.conf.InstancedConfiguration)5