Search in sources :

Example 56 with FileSystem

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

the class AddCommandIntegrationTest method immediatelyEffectiveForShellCommands.

@Test
public void immediatelyEffectiveForShellCommands() throws Exception {
    // Tests that after adding some path configuration, it's immediately effective for command
    // line calls afterwards.
    InstancedConfiguration conf = ServerConfiguration.global();
    try (FileSystemShell fsShell = new FileSystemShell(conf);
        FileSystemAdminShell fsAdminShell = new FileSystemAdminShell(conf)) {
        Assert.assertEquals(0, fsAdminShell.run("pathConf", "add", "--property", WRITE_TYPE_THROUGH, PATH1));
        Assert.assertEquals(0, fsAdminShell.run("pathConf", "add", "--property", WRITE_TYPE_CACHE_THROUGH, PATH2));
        FileSystem fs = sLocalAlluxioClusterResource.get().getClient();
        String file = "/file";
        FileSystemTestUtils.createByteFile(fs, file, 100, CreateFilePOptions.getDefaultInstance());
        fs.createDirectory(new AlluxioURI(PATH1), CreateDirectoryPOptions.newBuilder().setRecursive(true).build());
        fs.createDirectory(new AlluxioURI(PATH2), CreateDirectoryPOptions.newBuilder().setRecursive(true).build());
        AlluxioURI target = new AlluxioURI(PATH1 + file);
        Assert.assertEquals(0, fsShell.run("cp", file, target.toString()));
        URIStatus status = fs.getStatus(target);
        Assert.assertEquals(0, status.getInMemoryPercentage());
        Assert.assertEquals(PersistenceState.PERSISTED.toString(), status.getPersistenceState());
        target = new AlluxioURI(PATH2 + file);
        Assert.assertEquals(0, fsShell.run("cp", file, target.toString()));
        status = fs.getStatus(target);
        Assert.assertEquals(100, status.getInMemoryPercentage());
        Assert.assertEquals(PersistenceState.PERSISTED.toString(), status.getPersistenceState());
    }
}
Also used : InstancedConfiguration(alluxio.conf.InstancedConfiguration) FileSystem(alluxio.client.file.FileSystem) FileSystemShell(alluxio.cli.fs.FileSystemShell) FileSystemAdminShell(alluxio.cli.fsadmin.FileSystemAdminShell) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) AbstractShellIntegrationTest(alluxio.client.cli.fs.AbstractShellIntegrationTest)

Example 57 with FileSystem

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

the class LsCommandIntegrationTest method createFiles.

// Helper function to create a set of files in the file system
private void createFiles(String user) throws Exception {
    FileSystem fs = sFileSystem;
    if (user != null) {
        fs = sLocalAlluxioCluster.getClient(FileSystemContext.create(new TestUserState(user, ServerConfiguration.global()).getSubject(), ServerConfiguration.global()));
    }
    FileSystemTestUtils.createByteFile(fs, "/testRoot/testFileA", WritePType.MUST_CACHE, 10);
    FileSystemTestUtils.createByteFile(fs, "/testRoot/testDir/testFileB", WritePType.MUST_CACHE, 20);
    FileSystemTestUtils.createByteFile(fs, "/testRoot/testFileC", WritePType.THROUGH, 30);
}
Also used : FileSystem(alluxio.client.file.FileSystem) TestUserState(alluxio.security.user.TestUserState)

Example 58 with FileSystem

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

the class FileSystemContextReinitIntegrationTest method configHashSyncWithOpenStream.

@Test
public void configHashSyncWithOpenStream() throws Exception {
    // will be closed when restarting local masters, which in turn will close the contexts.
    try (FileSystem client = FileSystem.Factory.create(mContext);
        FileOutStream os = client.createFile(PATH_TO_UPDATE, CreateFilePOptions.newBuilder().setRecursive(true).build())) {
        checkClusterConfBeforeUpdate();
        checkPathConfBeforeUpdate();
        updateClusterConf();
        updatePathConf();
        ExecutorService service = Executors.newSingleThreadExecutor();
        Future future = service.submit(() -> {
            mExecutor.heartbeat();
        });
        TimeUnit.SECONDS.sleep(1);
        // Stream is open, so reinitialization should block until the stream is closed.
        Assert.assertFalse(future.isDone());
        future.cancel(true);
        checkHash(false, false);
        os.close();
        // Stream is closed, reinitialization should not be blocked.
        triggerAndWaitSync();
        checkClusterConfAfterUpdate();
        checkPathConfAfterUpdate();
        checkHash(true, true);
    }
}
Also used : FileSystem(alluxio.client.file.FileSystem) FileOutStream(alluxio.client.file.FileOutStream) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 59 with FileSystem

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

the class ImpersonationIntegrationTest method impersonationArbitraryUserDisallowed.

@Test
@LocalAlluxioClusterResource.Config(confParams = { IMPERSONATION_GROUPS_CONFIG, "*" })
public void impersonationArbitraryUserDisallowed() throws Exception {
    String arbitraryUser = "arbitrary_user";
    ServerConfiguration.set(PropertyKey.SECURITY_LOGIN_IMPERSONATION_USERNAME, arbitraryUser);
    FileSystemContext context = FileSystemContext.create(createHdfsSubject(), ServerConfiguration.global());
    FileSystem fs = mLocalAlluxioClusterResource.get().getClient(context);
    fs.createFile(new AlluxioURI("/impersonation-test")).close();
    List<URIStatus> listing = fs.listStatus(new AlluxioURI("/"));
    Assert.assertEquals(1, listing.size());
    URIStatus status = listing.get(0);
    Assert.assertNotEquals(arbitraryUser, status.getOwner());
}
Also used : FileSystem(alluxio.client.file.FileSystem) FileSystemContext(alluxio.client.file.FileSystemContext) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 60 with FileSystem

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

the class S3ClientRestApiTest method listAllMyBuckets.

@Test
public void listAllMyBuckets() throws Exception {
    Mode mode = ModeParser.parse("777");
    SetAttributePOptions options = SetAttributePOptions.newBuilder().setMode(mode.toProto()).setRecursive(true).build();
    mFileSystem.setAttribute(new AlluxioURI("/"), options);
    Subject subject = new Subject();
    subject.getPrincipals().add(new User("user0"));
    AlluxioURI bucketPath = new AlluxioURI("/bucket0");
    FileSystem fs1 = sResource.get().getClient(FileSystemContext.create(subject, ServerConfiguration.global()));
    fs1.createDirectory(bucketPath);
    SetAttributePOptions setAttributeOptions = SetAttributePOptions.newBuilder().setOwner("user0").build();
    mFileSystem.setAttribute(new AlluxioURI("/bucket0"), setAttributeOptions);
    URIStatus bucket0Status = fs1.getStatus(bucketPath);
    subject = new Subject();
    subject.getPrincipals().add(new User("user1"));
    AlluxioURI bucket1Path = new AlluxioURI("/bucket1");
    FileSystem fs2 = sResource.get().getClient(FileSystemContext.create(subject, ServerConfiguration.global()));
    fs2.createDirectory(bucket1Path);
    setAttributeOptions = SetAttributePOptions.newBuilder().setOwner("user1").build();
    mFileSystem.setAttribute(new AlluxioURI("/bucket1"), setAttributeOptions);
    URIStatus bucket1Status = fs2.getStatus(bucket1Path);
    ListAllMyBucketsResult expected = new ListAllMyBucketsResult(Collections.emptyList());
    final TestCaseOptions requestOptions = TestCaseOptions.defaults().setContentType(TestCaseOptions.XML_CONTENT_TYPE);
    new TestCase(mHostname, mPort, S3_SERVICE_PREFIX + "/", NO_PARAMS, HttpMethod.GET, expected, requestOptions).run();
    expected = new ListAllMyBucketsResult(Lists.newArrayList(bucket0Status));
    requestOptions.setAuthorization("AWS4-HMAC-SHA256 Credential=user0/20210631");
    new TestCase(mHostname, mPort, S3_SERVICE_PREFIX + "/", NO_PARAMS, HttpMethod.GET, expected, requestOptions).run();
    expected = new ListAllMyBucketsResult(Lists.newArrayList(bucket1Status));
    requestOptions.setAuthorization("AWS4-HMAC-SHA256 Credential=user1/20210631");
    new TestCase(mHostname, mPort, S3_SERVICE_PREFIX + "/", NO_PARAMS, HttpMethod.GET, expected, requestOptions).run();
}
Also used : User(alluxio.security.User) SetAttributePOptions(alluxio.grpc.SetAttributePOptions) Mode(alluxio.security.authorization.Mode) FileSystem(alluxio.client.file.FileSystem) URIStatus(alluxio.client.file.URIStatus) ListAllMyBucketsResult(alluxio.proxy.s3.ListAllMyBucketsResult) Subject(javax.security.auth.Subject) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

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