Package org.apache.hadoop.fs

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


      if (oldPath != null) {
        try {
          FileSystem fs2 = oldPath.getFileSystem(conf);
          if (fs2.exists(oldPath)) {
            // use FsShell to move data to .Trash first rather than delete permanently
            FsShell fshell = new FsShell();
            fshell.setConf(conf);
            fshell.run(new String[]{"-rmr", oldPath.toString()});
          }
        } catch (Exception e) {
          //swallow the exception
          LOG.warn("Directory " + oldPath.toString() + " canot be removed.");
        }
View Full Code Here


        console.printInfo("Copying " + copySource + " to " + copyDest);
        FileSystem srcFs = FileSystem.get(sourceDir.toUri(), conf);
        srcFs.initialize(sourceDir.toUri(), conf);

        FsShell fss = new FsShell(conf);
        int ret = 0;
        try {
          ret = ToolRunner.run(fss, args.toArray(new String[0]));
        } catch (Exception e) {
          e.printStackTrace();
View Full Code Here

    Path testdir = TEST_UTIL.getDataTestDir("TestNamespaceUpgrade");
    // Untar our test dir.
    File untar = untar(new File(testdir.toString()));
    // Now copy the untar up into hdfs so when we start hbase, we'll run from it.
    Configuration conf = TEST_UTIL.getConfiguration();
    FsShell shell = new FsShell(conf);
    FileSystem fs = FileSystem.get(conf);
    // find where hbase will root itself, so we can copy filesystem there
    Path hbaseRootDir = TEST_UTIL.getDefaultRootDirPath();
    if (!fs.isDirectory(hbaseRootDir.getParent())) {
      // mkdir at first
View Full Code Here

    Path testdir = TEST_UTIL.getDataTestDir("TestMetaMigrationRemovingHTD");
    // Untar our test dir.
    File untar = untar(new File(testdir.toString()));
    // Now copy the untar up into hdfs so when we start hbase, we'll run from it.
    Configuration conf = TEST_UTIL.getConfiguration();
    FsShell shell = new FsShell(conf);
    FileSystem fs = FileSystem.get(conf);
    // Minihbase roots itself in user home directory up in minidfs.
    Path homedir = fs.getHomeDirectory();
    doFsCommand(shell,
      new String [] {"-put", untar.toURI().toString(), homedir.toString()});
View Full Code Here

    Path testdir = TEST_UTIL.getDataTestDir("TestMetaMigrationConvertToPB");
    // Untar our test dir.
    File untar = untar(new File(testdir.toString()));
    // Now copy the untar up into hdfs so when we start hbase, we'll run from it.
    Configuration conf = TEST_UTIL.getConfiguration();
    FsShell shell = new FsShell(conf);
    FileSystem fs = FileSystem.get(conf);
    // find where hbase will root itself, so we can copy filesystem there
    Path hbaseRootDir = TEST_UTIL.getDefaultRootDirPath();
    if (!fs.isDirectory(hbaseRootDir.getParent())) {
      // mkdir at first
View Full Code Here

  }

  @Override
  protected CommandExecutor.Result execute(CLICommand cmd) throws Exception {
    if (cmd.getType() instanceof CLICommandFS) {
      CommandExecutor cmdExecutor = new FSCmdExecutor(nn, new FsShell(conf));
      return cmdExecutor.executeCommand(cmd.getCmd());
    } else {
      throw new IllegalArgumentException("Unknown type of test command: " + cmd.getType());
    }
  }
View Full Code Here

    MiniDFSCluster cluster = new MiniDFSCluster(65312, conf, 2, false);
    FileSystem fs = cluster.getFileSystem();
    assertTrue("Not a HDFS: "+fs.getUri(),
            fs instanceof DistributedFileSystem);
    DistributedFileSystem fileSys = (DistributedFileSystem)fs;
    FsShell shell = new FsShell();
    shell.setConf(conf);

    try {
      // First create a new directory with mkdirs
      Path myPath = new Path("/test/mkdirs");
      assertTrue(fileSys.mkdirs(myPath));
      assertTrue(fileSys.exists(myPath));
      assertTrue(fileSys.mkdirs(myPath));

      // Second, create a file in that directory.
      Path myFile = new Path("/test/mkdirs/myFile");
      writeFile(fileSys, myFile);
        assertTrue(fileSys.exists(myFile));

        // Verify that we can read the file
        {
          String[] args = new String[2];
          args[0] = "-cat";
          args[1] = "/test/mkdirs/myFile";
          int val = -1;
          try {
            val = shell.run(args);
            } catch (Exception e) {
            System.err.println("Exception raised from DFSShell.run: " +
                               StringUtils.stringifyException(e));
          }
          assertTrue(val == 0);
        }

        // Verify that we can get with and without crc
        {
          File testFile = new File(TEST_ROOT_DIR, "myFile");
          File checksumFile = new File(fileSys.getChecksumFile(
              new Path(testFile.getAbsolutePath())).toString());
          testFile.delete();
          checksumFile.delete();
         
          String[] args = new String[3];
          args[0] = "-get";
          args[1] = "/test/mkdirs";
          args[2] = TEST_ROOT_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);
          assertTrue("Copying failed.", testFile.exists());
          assertTrue("Checksum file " + checksumFile+" is copied.", !checksumFile.exists());
          testFile.delete();
        }
        {
          File testFile = new File(TEST_ROOT_DIR, "myFile");
          File checksumFile = new File(fileSys.getChecksumFile(
              new Path(testFile.getAbsolutePath())).toString());
          testFile.delete();
          checksumFile.delete();
         
          String[] args = new String[4];
          args[0] = "-get";
          args[1] = "-crc";
          args[2] = "/test/mkdirs";
          args[3] = TEST_ROOT_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);
         
          assertTrue("Copying data file failed.", testFile.exists());
          assertTrue("Checksum file " + checksumFile+" not copied.", checksumFile.exists());
          testFile.delete();
          checksumFile.delete();
        }
        // Verify that we get an error while trying to read an nonexistent file
        {
          String[] args = new String[2];
          args[0] = "-cat";
          args[1] = "/test/mkdirs/myFile1";
          int val = -1;
          try {
            val = shell.run(args);
          } catch (Exception e) {
            System.err.println("Exception raised from DFSShell.run " +
                               e.getLocalizedMessage());
          }
          assertTrue(val != 0);
        }

        // Verify that we get an error while trying to delete an nonexistent file
        {
          String[] args = new String[2];
          args[0] = "-rm";
          args[1] = "/test/mkdirs/myFile1";
          int val = -1;
          try {
            val = shell.run(args);
          } catch (Exception e) {
            System.err.println("Exception raised from DFSShell.run " +
                               e.getLocalizedMessage());
          }
          assertTrue(val != 0);
        }

        // Verify that we succeed in removing the file we created
        {
          String[] args = new String[2];
          args[0] = "-rm";
          args[1] = "/test/mkdirs/myFile";
          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

  }

  void lsr() {
    try {
      System.out.println("lsr /");
      FsShell shell = new FsShell();
      shell.setConf(conf_);
      shell.init();
      shell.ls("/", true);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
View Full Code Here

        mPigServer = pigServer;
       
        mDfs = mPigServer.getPigContext().getDfs();
        mLfs = mPigServer.getPigContext().getLfs();
        mConf = mPigServer.getPigContext().getProperties();
        shell = new FsShell(ConfigurationUtil.toConfiguration(mConf));
       
        // TODO: this violates the abstraction layer decoupling between
        // front end and back end and needs to be changed.
        // Right now I am not clear on how the Job Id comes from to tell
        // the back end to kill a given job (mJobClient is used only in
View Full Code Here

        args.add("-cp");
        args.add(copySource);
        args.add(copyDest);

        console.printInfo("Copying " + copySource + " to " + copyDest);
        FsShell fss = new FsShell(conf);
        int ret = 0;
        try {
          ret = ToolRunner.run(fss, args.toArray(new String[0]));
        } catch (Exception e) {
          throw new HiveException(e);
View Full Code Here

TOP

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

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.