Search in sources :

Example 41 with FsShell

use of org.apache.hadoop.fs.FsShell in project hadoop by apache.

the class DFSTestUtil method FsShellRun.

public static void FsShellRun(String cmd, int retcode, String contain, Configuration conf) throws Exception {
    FsShell shell = new FsShell(new Configuration(conf));
    toolRun(shell, cmd, retcode, contain);
}
Also used : FsShell(org.apache.hadoop.fs.FsShell) Configuration(org.apache.hadoop.conf.Configuration)

Example 42 with FsShell

use of org.apache.hadoop.fs.FsShell in project hadoop by apache.

the class TestDFSShellGenericOptions method execute.

private void execute(String[] args, String namenode) {
    FsShell shell = new FsShell();
    FileSystem fs = null;
    try {
        ToolRunner.run(shell, args);
        fs = FileSystem.get(NameNode.getUri(NameNode.getAddress(namenode)), shell.getConf());
        assertTrue("Directory does not get created", fs.isDirectory(new Path("/data")));
        fs.delete(new Path("/data"), true);
    } catch (Exception e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
    } finally {
        if (fs != null) {
            try {
                fs.close();
            } catch (IOException ignored) {
            }
        }
    }
}
Also used : FsShell(org.apache.hadoop.fs.FsShell) Path(org.apache.hadoop.fs.Path) FileSystem(org.apache.hadoop.fs.FileSystem) IOException(java.io.IOException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 43 with FsShell

use of org.apache.hadoop.fs.FsShell in project hadoop by apache.

the class TestHadoopArchives method testRelativePath.

@Test
public void testRelativePath() throws Exception {
    final Path sub1 = new Path(inputPath, "dir1");
    fs.mkdirs(sub1);
    createFile(inputPath, fs, sub1.getName(), "a");
    final FsShell shell = new FsShell(conf);
    final List<String> originalPaths = lsr(shell, "input");
    System.out.println("originalPaths: " + originalPaths);
    // make the archive:
    final String fullHarPathStr = makeArchive();
    // compare results:
    final List<String> harPaths = lsr(shell, fullHarPathStr);
    Assert.assertEquals(originalPaths, harPaths);
}
Also used : Path(org.apache.hadoop.fs.Path) FsShell(org.apache.hadoop.fs.FsShell) Test(org.junit.Test)

Example 44 with FsShell

use of org.apache.hadoop.fs.FsShell in project hadoop by apache.

the class TestHadoopArchives method testPathWithSpaces.

@Test
public void testPathWithSpaces() throws Exception {
    // create files/directories with spaces
    createFile(inputPath, fs, "c c");
    final Path sub1 = new Path(inputPath, "sub 1");
    fs.mkdirs(sub1);
    createFile(sub1, fs, "file x y z");
    createFile(sub1, fs, "file");
    createFile(sub1, fs, "x");
    createFile(sub1, fs, "y");
    createFile(sub1, fs, "z");
    final Path sub2 = new Path(inputPath, "sub 1 with suffix");
    fs.mkdirs(sub2);
    createFile(sub2, fs, "z");
    final FsShell shell = new FsShell(conf);
    final String inputPathStr = inputPath.toUri().getPath();
    final List<String> originalPaths = lsr(shell, inputPathStr);
    // make the archive:
    final String fullHarPathStr = makeArchive();
    // compare results
    final List<String> harPaths = lsr(shell, fullHarPathStr);
    Assert.assertEquals(originalPaths, harPaths);
}
Also used : Path(org.apache.hadoop.fs.Path) FsShell(org.apache.hadoop.fs.FsShell) Test(org.junit.Test)

Example 45 with FsShell

use of org.apache.hadoop.fs.FsShell in project hadoop by apache.

the class TestHadoopArchives method testGlobFiles.

@Test
public void testGlobFiles() throws Exception {
    final Path sub1 = new Path(inputPath, "dir1");
    final Path sub2 = new Path(inputPath, "dir2");
    fs.mkdirs(sub1);
    String fileName = "a";
    createFile(inputPath, fs, sub1.getName(), fileName);
    createFile(inputPath, fs, sub2.getName(), fileName);
    // not part of result
    createFile(inputPath, fs, sub1.getName(), "b");
    final String glob = "dir{1,2}/a";
    final FsShell shell = new FsShell(conf);
    final List<String> originalPaths = lsr(shell, inputPath.toString(), inputPath + "/" + glob);
    System.out.println("originalPaths: " + originalPaths);
    // make the archive:
    final String fullHarPathStr = makeArchive(inputPath, glob);
    // compare results:
    final List<String> harPaths = lsr(shell, fullHarPathStr, fullHarPathStr + "/" + glob);
    Assert.assertEquals(originalPaths, harPaths);
}
Also used : Path(org.apache.hadoop.fs.Path) FsShell(org.apache.hadoop.fs.FsShell) Test(org.junit.Test)

Aggregations

FsShell (org.apache.hadoop.fs.FsShell)52 Path (org.apache.hadoop.fs.Path)38 Test (org.junit.Test)31 Configuration (org.apache.hadoop.conf.Configuration)28 FileSystem (org.apache.hadoop.fs.FileSystem)21 FileStatus (org.apache.hadoop.fs.FileStatus)14 IOException (java.io.IOException)10 FsPermission (org.apache.hadoop.fs.permission.FsPermission)6 HdfsAdmin (org.apache.hadoop.hdfs.client.HdfsAdmin)6 PrintStream (java.io.PrintStream)5 MiniDFSCluster (org.apache.hadoop.hdfs.MiniDFSCluster)5 Text (org.apache.hadoop.io.Text)4 Mockito.anyString (org.mockito.Mockito.anyString)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Builder (org.apache.hadoop.hdfs.MiniDFSCluster.Builder)3 BufferedOutputStream (java.io.BufferedOutputStream)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2