Search in sources :

Example 1 with FileSystemShell

use of alluxio.cli.fs.FileSystemShell in project alluxio by Alluxio.

the class JobServiceFaultToleranceShellTest method distributedCp.

@Test
public void distributedCp() throws Exception {
    FileSystem fs = FileSystem.Factory.create(ServerConfiguration.global());
    try (OutputStream out = fs.createFile(new AlluxioURI("/test"))) {
        out.write("Hello".getBytes());
    }
    try (FileSystemShell shell = new FileSystemShell(ServerConfiguration.global())) {
        int exitCode = shell.run("distributedCp", "/test", "/test2");
        assertEquals("Command failed, output: " + mOutput.toString(), 0, exitCode);
    }
    assertTrue(fs.exists(new AlluxioURI("/test2")));
}
Also used : FileSystem(alluxio.client.file.FileSystem) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileSystemShell(alluxio.cli.fs.FileSystemShell) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest)

Example 2 with FileSystemShell

use of alluxio.cli.fs.FileSystemShell in project alluxio by Alluxio.

the class CpCommandIntegrationTest method copyFileWithPreservedAttributes.

/**
 * Tests copying a file with attributes preserved.
 */
@Test
public void copyFileWithPreservedAttributes() throws Exception {
    InstancedConfiguration conf = new InstancedConfiguration(ServerConfiguration.global());
    // avoid chown on UFS since test might not be run with root
    conf.set(PropertyKey.USER_FILE_WRITE_TYPE_DEFAULT, "MUST_CACHE");
    try (FileSystemShell fsShell = new FileSystemShell(conf)) {
        String testDir = FileSystemShellUtilsTest.resetFileHierarchy(sFileSystem);
        AlluxioURI srcFile = new AlluxioURI(testDir + "/foobar4");
        String owner = TEST_USER_1.getUser();
        String group = "staff";
        short mode = 0422;
        List<AclEntry> entries = new ArrayList<>();
        entries.add(new AclEntry.Builder().setType(AclEntryType.NAMED_USER).setSubject(TEST_USER_2.getUser()).addAction(AclAction.READ).addAction(AclAction.WRITE).addAction(AclAction.EXECUTE).build());
        entries.add(new AclEntry.Builder().setType(AclEntryType.NAMED_GROUP).setSubject(group).addAction(AclAction.WRITE).addAction(AclAction.EXECUTE).build());
        sFileSystem.setAttribute(srcFile, SetAttributePOptions.newBuilder().setOwner(owner).setGroup(group).setMode(new Mode(mode).toProto()).setPinned(true).setReplicationMin(2).setReplicationMax(4).setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(12345)).build());
        sFileSystem.setAcl(srcFile, SetAclAction.MODIFY, entries);
        int ret = fsShell.run("cp", "-p", testDir + "/foobar4", testDir + "/bar");
        AlluxioURI dstFile = new AlluxioURI(testDir + "/bar/foobar4");
        Assert.assertEquals(0, ret);
        Assert.assertTrue(sFileSystem.exists(dstFile));
        verifyPreservedAttributes(srcFile, dstFile);
    }
}
Also used : InstancedConfiguration(alluxio.conf.InstancedConfiguration) Mode(alluxio.security.authorization.Mode) AclEntry(alluxio.security.authorization.AclEntry) ArrayList(java.util.ArrayList) FileSystemShell(alluxio.cli.fs.FileSystemShell) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) AlluxioURI(alluxio.AlluxioURI) AbstractFileSystemShellTest(alluxio.client.cli.fs.AbstractFileSystemShellTest) Test(org.junit.Test) FileSystemShellUtilsTest(alluxio.client.cli.fs.FileSystemShellUtilsTest)

Example 3 with FileSystemShell

use of alluxio.cli.fs.FileSystemShell in project alluxio by Alluxio.

the class CpCommandIntegrationTest method copyDirectoryWithPreservedAttributes.

/**
 * Tests copying a folder with attributes preserved.
 */
@Test
public void copyDirectoryWithPreservedAttributes() throws Exception {
    InstancedConfiguration conf = new InstancedConfiguration(ServerConfiguration.global());
    conf.set(PropertyKey.USER_FILE_WRITE_TYPE_DEFAULT, "MUST_CACHE");
    try (FileSystemShell fsShell = new FileSystemShell(conf)) {
        String testDir = FileSystemShellUtilsTest.resetFileHierarchy(sFileSystem);
        String newDir = "/copy";
        String subDir = "/foo";
        String file = "/foobar4";
        String owner = TEST_USER_1.getUser();
        String group = "staff";
        short mode = 0422;
        List<AclEntry> entries = new ArrayList<>();
        entries.add(new AclEntry.Builder().setType(AclEntryType.NAMED_USER).setSubject(TEST_USER_2.getUser()).addAction(AclAction.READ).addAction(AclAction.WRITE).addAction(AclAction.EXECUTE).build());
        entries.add(new AclEntry.Builder().setType(AclEntryType.NAMED_GROUP).setSubject(group).addAction(AclAction.WRITE).addAction(AclAction.EXECUTE).build());
        AlluxioURI srcDir = new AlluxioURI(testDir);
        sFileSystem.setAttribute(srcDir, SetAttributePOptions.newBuilder().setRecursive(true).setOwner(owner).setGroup(group).setMode(new Mode(mode).toProto()).setPinned(true).setReplicationMin(2).setReplicationMax(4).setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(12345)).build());
        sFileSystem.setAcl(srcDir, SetAclAction.MODIFY, entries, SetAclPOptions.newBuilder().setRecursive(true).build());
        int ret = fsShell.run("cp", "-R", "-p", testDir, newDir);
        AlluxioURI dstDir = new AlluxioURI(newDir);
        Assert.assertEquals(0, ret);
        Assert.assertTrue(sFileSystem.exists(dstDir));
        verifyPreservedAttributes(srcDir, dstDir);
        verifyPreservedAttributes(srcDir.join(subDir), dstDir.join(subDir));
        verifyPreservedAttributes(srcDir.join(file), dstDir.join(file));
    }
}
Also used : InstancedConfiguration(alluxio.conf.InstancedConfiguration) Mode(alluxio.security.authorization.Mode) AclEntry(alluxio.security.authorization.AclEntry) ArrayList(java.util.ArrayList) FileSystemShell(alluxio.cli.fs.FileSystemShell) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) AlluxioURI(alluxio.AlluxioURI) AbstractFileSystemShellTest(alluxio.client.cli.fs.AbstractFileSystemShellTest) Test(org.junit.Test) FileSystemShellUtilsTest(alluxio.client.cli.fs.FileSystemShellUtilsTest)

Example 4 with FileSystemShell

use of alluxio.cli.fs.FileSystemShell in project alluxio by Alluxio.

the class PersistCommandTest method persistOnRenameDirectory.

@Test
public void persistOnRenameDirectory() throws Exception {
    InstancedConfiguration conf = new InstancedConfiguration(ServerConfiguration.global());
    conf.set(PropertyKey.USER_FILE_WRITE_TYPE_DEFAULT, "MUST_CACHE");
    conf.set(PropertyKey.USER_FILE_PERSIST_ON_RENAME, true);
    try (FileSystemShell fsShell = new FileSystemShell(conf)) {
        String testDir = FileSystemShellUtilsTest.resetFileHierarchy(sFileSystem);
        String toPersist = testDir + "/foo";
        String persisted = testDir + "/foo_persisted";
        String doNotPersist = testDir + "/bar";
        assertFalse(sFileSystem.getStatus(new AlluxioURI(testDir)).isPersisted());
        assertFalse(sFileSystem.getStatus(new AlluxioURI(toPersist)).isPersisted());
        assertFalse(sFileSystem.getStatus(new AlluxioURI(doNotPersist)).isPersisted());
        int ret = fsShell.run("mv", toPersist, persisted);
        Assert.assertEquals(mOutput.toString(), 0, ret);
        CommonUtils.waitFor("Directory to be persisted", () -> {
            try {
                return sFileSystem.getStatus(new AlluxioURI(persisted)).isPersisted() && sFileSystem.getStatus(new AlluxioURI(persisted + "/foobar1")).isPersisted() && sFileSystem.getStatus(new AlluxioURI(persisted + "/foobar2")).isPersisted();
            } catch (Exception e) {
                return false;
            }
        }, WaitForOptions.defaults().setTimeoutMs(10000));
        assertFalse(sFileSystem.getStatus(new AlluxioURI(testDir + "/bar")).isPersisted());
        checkFilePersisted(new AlluxioURI(persisted + "/foobar1"), 10);
        checkFilePersisted(new AlluxioURI(persisted + "/foobar2"), 20);
    }
}
Also used : InstancedConfiguration(alluxio.conf.InstancedConfiguration) FileSystemShell(alluxio.cli.fs.FileSystemShell) AlluxioURI(alluxio.AlluxioURI) AbstractFileSystemShellTest(alluxio.client.cli.fs.AbstractFileSystemShellTest) Test(org.junit.Test) FileSystemShellUtilsTest(alluxio.client.cli.fs.FileSystemShellUtilsTest)

Example 5 with FileSystemShell

use of alluxio.cli.fs.FileSystemShell in project alluxio by Alluxio.

the class PinCommandMultipleMediaIntegrationTest method setPinToSpecificMedia.

@Test
public void setPinToSpecificMedia() throws Exception {
    FileSystem fileSystem = sLocalAlluxioClusterResource.get().getClient();
    FileSystemShell fsShell = new FileSystemShell(ServerConfiguration.global());
    AlluxioURI filePathA = new AlluxioURI("/testFileA");
    AlluxioURI filePathB = new AlluxioURI("/testFileB");
    int fileSize = SIZE_BYTES / 2;
    FileSystemTestUtils.createByteFile(fileSystem, filePathA, WritePType.CACHE_THROUGH, fileSize);
    assertTrue(fileSystem.exists(filePathA));
    assertEquals(0, fsShell.run("pin", filePathA.toString(), Constants.MEDIUM_SSD));
    CommonUtils.waitFor("File being moved", () -> sJobCluster.getMaster().getJobMaster().listDetailed().stream().anyMatch(x -> x.getName().equals("Move") && x.getStatus().equals(Status.COMPLETED) && x.getAffectedPaths().contains(filePathA.getPath())), sWaitOptions);
    assertTrue(fileSystem.getStatus(filePathA).getFileBlockInfos().get(0).getBlockInfo().getLocations().stream().anyMatch(x -> x.getMediumType().equals(Constants.MEDIUM_SSD)));
    assertEquals(-1, fsShell.run("pin", filePathB.toString(), "NVRAM"));
}
Also used : BeforeClass(org.junit.BeforeClass) TestRule(org.junit.rules.TestRule) FileSystemTestUtils(alluxio.client.file.FileSystemTestUtils) Status(alluxio.job.wire.Status) PropertyKey(alluxio.conf.PropertyKey) WaitForOptions(alluxio.util.WaitForOptions) FileSystem(alluxio.client.file.FileSystem) Constants(alluxio.Constants) Files(com.google.common.io.Files) AlluxioURI(alluxio.AlluxioURI) ClassRule(org.junit.ClassRule) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Before(org.junit.Before) WritePType(alluxio.grpc.WritePType) FileSystemShell(alluxio.cli.fs.FileSystemShell) ServerConfiguration(alluxio.conf.ServerConfiguration) LocalAlluxioClusterResource(alluxio.testutils.LocalAlluxioClusterResource) LocalAlluxioJobCluster(alluxio.master.LocalAlluxioJobCluster) Assert.assertTrue(org.junit.Assert.assertTrue) AlluxioException(alluxio.exception.AlluxioException) Test(org.junit.Test) IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus) Rule(org.junit.Rule) Assert.assertFalse(org.junit.Assert.assertFalse) Assert.assertEquals(org.junit.Assert.assertEquals) CommonUtils(alluxio.util.CommonUtils) FileSystem(alluxio.client.file.FileSystem) FileSystemShell(alluxio.cli.fs.FileSystemShell) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Aggregations

FileSystemShell (alluxio.cli.fs.FileSystemShell)11 AlluxioURI (alluxio.AlluxioURI)9 Test (org.junit.Test)9 InstancedConfiguration (alluxio.conf.InstancedConfiguration)6 AbstractFileSystemShellTest (alluxio.client.cli.fs.AbstractFileSystemShellTest)5 FileSystemShellUtilsTest (alluxio.client.cli.fs.FileSystemShellUtilsTest)5 FileSystem (alluxio.client.file.FileSystem)4 LocalAlluxioJobCluster (alluxio.master.LocalAlluxioJobCluster)4 BeforeClass (org.junit.BeforeClass)4 URIStatus (alluxio.client.file.URIStatus)3 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)3 Constants (alluxio.Constants)2 FileSystemTestUtils (alluxio.client.file.FileSystemTestUtils)2 PropertyKey (alluxio.conf.PropertyKey)2 ServerConfiguration (alluxio.conf.ServerConfiguration)2 AlluxioException (alluxio.exception.AlluxioException)2 WritePType (alluxio.grpc.WritePType)2 Status (alluxio.job.wire.Status)2 AclEntry (alluxio.security.authorization.AclEntry)2 Mode (alluxio.security.authorization.Mode)2