Package org.apache.hadoop.fs

Examples of org.apache.hadoop.fs.FsShell$TextRecordInputStream


      final String localfcontent = DFSTestUtil.readFile(localf);
      final Path root = mkdir(dfs, new Path("/test/get"));
      final Path remotef = new Path(root, fname);
      dfs.copyFromLocalFile(false, false, new Path(localf.getPath()), remotef);

      final FsShell shell = new FsShell();
      shell.setConf(conf);
      TestGetRunner runner = new TestGetRunner() {
        private int count = 0;

        public String run(int exitcode, String... options) throws IOException {
          String dst = TEST_ROOT_DIR + "/" + fname+ ++count;
          String[] args = new String[options.length + 3];
          args[0] = "-get";
          args[args.length - 2] = remotef.toString();
          args[args.length - 1] = dst;
          for(int i = 0; i < options.length; i++) {
            args[i + 1] = options[i];
          }
          show("args=" + Arrays.asList(args));

          try {
            assertEquals(exitcode, shell.run(args));
          } catch (Exception e) {
            assertTrue(StringUtils.stringifyException(e), false);
          }
          return exitcode == 0? DFSTestUtil.readFile(new File(dst)): null;
        }
View Full Code Here


    try {
      final String root = createTree(dfs, "lsr");
      dfs.mkdirs(new Path(root, "zzz"));

      runLsr(new FsShell(conf), root, 0);

      final Path sub = new Path(root, "sub");
      dfs.setPermission(sub, new FsPermission((short)0));

      final UserGroupInformation ugi = UserGroupInformation.getCurrentUGI();
      final String tmpusername = ugi.getUserName() + "1";
      UnixUserGroupInformation tmpUGI = new UnixUserGroupInformation(
          tmpusername, new String[] {tmpusername});
      UnixUserGroupInformation.saveToConf(conf,
            UnixUserGroupInformation.UGI_PROPERTY_NAME, tmpUGI);
      String results = runLsr(new FsShell(conf), root, -1);
      assertTrue(results.contains("zzz"));
    } finally {
      cluster.shutdown();
    }
  }
View Full Code Here

      assertTrue(fs.mkdirs(directory));
      assertTrue(fs.exists(directory));
      writeFile(fs, tempFile);
      assertTrue(fs.exists(tempFile));

      FsShell shell = new FsShell();
      String argv[] = new String[3];
      argv[0] = "-rmdir";     
      argv[1] = "/dir";

      int ret = -100;
      try {
        ret = shell.run(argv);
        assertTrue(ret == -1);

        argv[1] = "-ignore-fail-on-non-empty";
        argv[2] = "/dir";
        ret = shell.run(argv);
        assertTrue(ret == 0);
        assertTrue(fs.exists(directory));

        assertTrue(fs.delete(tempFile, true));
        assertFalse(fs.exists(tempFile));

        argv[1] = "/dir";
        argv[2] = "";
        ret = shell.run(argv);
        assertTrue(ret == 0);
        assertFalse(fs.exists(directory));
      } catch (Exception e) {
        System.err.println("Exception raised from DFSShell.run " +
                            e.getLocalizedMessage());
View Full Code Here

      for (int i = 0; i < 32; i++) {
        filetmp.write(b);
      }
      filetmp.close();

      FsShell shell = new FsShell();
      String argv[]= new String[2];
      shell.setConf(conf);

      // head of large file, only contains AA
      argv[0] = "-head";
      argv[1] = fileNameLarge;
      ToolRunner.run(shell, argv);
View Full Code Here

    final DistributedFileSystem dfs = (DistributedFileSystem)fs;
    PrintStream psBackup = System.out;
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    PrintStream psOut = new PrintStream(out);
    System.setOut(psOut);
    FsShell shell = new FsShell();
    shell.setConf(conf);

    try {
      Path myPath = new Path("/test/dir");
      assertTrue(fs.mkdirs(myPath));
      assertTrue(fs.exists(myPath));
      Path myFile = new Path("/test/dir/file");
      writeFile(fs, myFile);
      assertTrue(fs.exists(myFile));
      Path myFile2 = new Path("/test/dir/file2");
      writeFile(fs, myFile2);
      assertTrue(fs.exists(myFile2));

      String[] args = new String[2];
      args[0] = "-du";
      args[1] = "/test/dir";
      int val = -1;
      try {
        val = shell.run(args);
      } catch (Exception e) {
        System.err.println("Exception raised from DFSShell.run " +
                            e.getLocalizedMessage());
      }
      assertTrue(val == 0);
View Full Code Here

      {
        Path path = new Path("test_file_1");
        writeFile(fs, path);
        assertTrue(fs.exists(path));

        FsShell shell = new FsShell();
        shell.setConf(conf);
        String argv[] = new String[2];

        argv[0] = "-rm";
        argv[1] = path.toString();
        assertTrue(shell.run(argv) == 0);
        assertTrue(!fs.exists(path));

        argv[0] = "-undelete";
        argv[1] = path.toString();
        assertTrue(shell.run(argv) == 0);
        assertTrue(fs.exists(path));
      }

      // test undelete of file that was deleted programatically
      {
        Path path = new Path("test_file_2");
        writeFile(fs, path);
        assertTrue(fs.exists(path));

        assertTrue(fs.delete(path, true));
        assertTrue(!fs.exists(path));

        FsShell shell = new FsShell();
        shell.setConf(conf);
        String argv[] = new String[2];
        argv[0] = "-undelete";
        argv[1] = path.toString();
        assertTrue(shell.run(argv) == 0);
        assertTrue(fs.exists(path));
      }

      // test undelete of directory that was deleted via shell
      {
        Path path = new Path("test_dir_1");
        assertTrue(fs.mkdirs(path));
        assertTrue(fs.exists(path));

        FsShell shell = new FsShell();
        shell.setConf(conf);
        String argv[] = new String[2];

        argv[0] = "-rmr";
        argv[1] = path.toString();
        assertTrue(shell.run(argv) == 0);
        assertTrue(!fs.exists(path));

        argv[0] = "-undelete";
        argv[1] = path.toString();
        assertTrue(shell.run(argv) == 0);
        assertTrue(fs.exists(path));
      }

      // test undelete of directory that was deleted programatically
      {
        Path path = new Path("test_dir_2");
        assertTrue(fs.mkdirs(path));
        assertTrue(fs.exists(path));

        assertTrue(fs.delete(path, true));
        assertTrue(!fs.exists(path));

        FsShell shell = new FsShell();
        shell.setConf(conf);
        String argv[] = new String[2];
        argv[0] = "-undelete";
        argv[1] = path.toString();
        assertTrue(shell.run(argv) == 0);
        assertTrue(fs.exists(path));
      }

      // test undelete of most recently deleted version
      {
        Path path = new Path("test_file_multiversion");

        writeFileContents(fs, path, "wrong version");
        assertTrue(fs.exists(path));
        assertTrue(fs.delete(path, true));
        assertTrue(!fs.exists(path));

        writeFileContents(fs, path, "right version");
        assertTrue(fs.exists(path));
        assertTrue(fs.delete(path, true));
        assertTrue(!fs.exists(path));

        FsShell shell = new FsShell();
        shell.setConf(conf);
        String argv[] = new String[2];
        argv[0] = "-undelete";
        argv[1] = path.toString();
        assertTrue(shell.run(argv) == 0);
        assertTrue(fs.exists(path));

        String verify = readFileContents(fs, path);
        System.err.println("verify=" + verify);
        assertTrue(verify.equals("right version"));
      }

      // test undelete of file from another user's trash
      {
        // make a fake trash for a different user
        Path path = new Path("my_file_in_joes_trash");
        Path joesTrashDir = new Path(
          "/user/joe/.Trash/Current/user/" + getUserName(fs));
        Path joesTrashFile = new Path(joesTrashDir, path);
        mkdir(fs, joesTrashDir);
        writeFileContents(fs, joesTrashFile, "some file contents");
        assertTrue(fs.exists(joesTrashFile));

        FsShell shell = new FsShell();
        shell.setConf(conf);
        String argv[] = new String[4];
        argv[0] = "-undelete";
        argv[1] = "-u";
        argv[2] = "joe";
        argv[3] = path.toString();
        assertTrue(shell.run(argv) == 0);
        assertTrue(fs.exists(path));
      }

      // test undelete of most recently deleted version across
      // checkpoint intervals
      {
        Path path = new Path("test_file_interval");

        writeFileContents(fs, path, "wrong version");
        assertTrue(fs.exists(path));
        assertTrue(fs.delete(path, true));
        assertTrue(!fs.exists(path));

        writeFileContents(fs, path, "right version");
        assertTrue(fs.exists(path));
        assertTrue(fs.delete(path, true));
        assertTrue(!fs.exists(path));

        // wait for the next interval before checking
        Thread.sleep(60500);

        FsShell shell = new FsShell();
        shell.setConf(conf);
        String argv[] = new String[2];
        argv[0] = "-undelete";
        argv[1] = path.toString();
        assertTrue(shell.run(argv) == 0);
        assertTrue(fs.exists(path));

        String verify = readFileContents(fs, path);
        System.err.println("verify=" + verify);
        assertTrue(verify.equals("right version"));
View Full Code Here

      PrintStream tmp = new PrintStream(out);
      System.setErr(tmp);
      String[] argv = new String[2];
      argv[0] = "-cat";
      argv[1] = root.toUri().getPath();
      int ret = ToolRunner.run(new FsShell(), argv);
      assertTrue(" -cat returned -1 ", 0>=ret);
      String returned = out.toString();
      assertTrue("cat does not print exceptions ",
          (returned.lastIndexOf("Exception") == -1));
      out.reset();
      argv[0] = "-rm";
      argv[1] = root.toString();
      FsShell shell = new FsShell();
      shell.setConf(conf);
      ret = ToolRunner.run(shell, argv);
      assertTrue(" -rm returned -1 ", 0>=ret);
      returned = out.toString();
      out.reset();
      assertTrue("rm prints reasonable error ",
View Full Code Here

      nameDir.mkdirs();
      System.setProperty("test.build.data", nameDir.toString());
      dstCluster = new MiniDFSCluster(dstConf, 2, true, null);
      FileSystem srcFs = srcCluster.getFileSystem();
      FileSystem dstFs = dstCluster.getFileSystem();
      FsShell shell = new FsShell();
      shell.setConf(srcConf);
      //check for ls
      String[] argv = new String[2];
      argv[0] = "-ls";
      argv[1] = dstFs.getUri().toString() + "/";
      int ret = ToolRunner.run(shell, argv);
View Full Code Here

      System.setOut(new PrintStream(out));

      String[] argv = new String[2];
      argv[0] = "-text";
      argv[1] = new Path(root, "file.gz").toUri().getPath();
      int ret = ToolRunner.run(new FsShell(), argv);
      assertTrue("-text returned -1", 0 >= ret);
      file.reset();
      out.reset();
      assertTrue("Output doesn't match input",
          Arrays.equals(file.toByteArray(), out.toByteArray()));
View Full Code Here

    MiniDFSCluster cluster = new MiniDFSCluster(conf, 2, true, null);
    FileSystem fs = cluster.getFileSystem();
    assertTrue("Not a HDFS: "+fs.getUri(),
               fs instanceof ChecksumDistributedFileSystem);
    ChecksumDistributedFileSystem dfs = (ChecksumDistributedFileSystem)fs;
    FsShell shell = new FsShell();
    shell.setConf(conf);

    try {
      String root = createTree(dfs, "copyToLocal");

      // Verify copying the tree
      {
        try {
          assertEquals(0,
              runCmd(shell, "-copyToLocal", root + "*", TEST_ROOT_DIR));
        } catch (Exception e) {
          System.err.println("Exception raised from DFSShell.run " +
                             e.getLocalizedMessage());
        }

        File localroot = new File(TEST_ROOT_DIR, "copyToLocal");
        File localroot2 = new File(TEST_ROOT_DIR, "copyToLocal2");

        File f1 = new File(localroot, "f1");
        assertTrue("Copying failed.", f1.isFile());

        File f2 = new File(localroot, "f2");
        assertTrue("Copying failed.", f2.isFile());

        File sub = new File(localroot, "sub");
        assertTrue("Copying failed.", sub.isDirectory());

        File f3 = new File(sub, "f3");
        assertTrue("Copying failed.", f3.isFile());

        File f4 = new File(sub, "f4");
        assertTrue("Copying failed.", f4.isFile());

        File f5 = new File(localroot2, "f1");
        assertTrue("Copying failed.", f5.isFile());

        f1.delete();
        f2.delete();
        f3.delete();
        f4.delete();
        f5.delete();
        sub.delete();
      }
      // Verify copying non existing sources do not create zero byte
      // destination files
      {
        String[] args = {"-copyToLocal", "nosuchfile", TEST_ROOT_DIR};
        try {
          assertEquals(-1, shell.run(args));
        } catch (Exception e) {
          System.err.println("Exception raised from DFSShell.run " +
                            e.getLocalizedMessage());
        }
        File f6 = new File(TEST_ROOT_DIR, "nosuchfile");
View Full Code Here

TOP

Related Classes of org.apache.hadoop.fs.FsShell$TextRecordInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.