public Object execute()

in gateway-shell/src/main/java/org/apache/knox/gateway/shell/commands/WebHDFSCommand.java [62:146]


  public Object execute(List<String> args) {
    Map<String, String> mounts = getMountPoints();
    if (args.isEmpty()) {
      args.add("ls");
    }
    if (args.get(0).equalsIgnoreCase("mount")) {
      String url = args.get(1);
      String mountPoint = args.get(2);
      return mount(mounts, url, mountPoint);
    }
    else if (args.get(0).equalsIgnoreCase("unmount")) {
      String mountPoint = args.get(1);
      unmount(mounts, mountPoint);
    }
    else if (args.get(0).equalsIgnoreCase("mounts")) {
      return listMounts(mounts);
    }
    else if (args.get(0).equalsIgnoreCase("ls")) {
      String path = args.get(1);
      return listStatus(mounts, path);
    }
    else if (args.get(0).equalsIgnoreCase("put")) {
      // Hdfs.put( session ).file( dataFile ).to( dataDir + "/" + dataFile ).now()
      // :fs put from-path to-path
      String localFile = args.get(1);
      String path = args.get(2);
      int permission = 755;
      if (args.size() >= 4) {
        permission = Integer.parseInt(args.get(3));
      }

      return put(mounts, localFile, path, permission);
    }
    else if (args.get(0).equalsIgnoreCase("rm")) {
      // Hdfs.rm( session ).file( dataFile ).now()
      // :fs rm target-path
      String path = args.get(1);
      return remove(mounts, path);
    }
    else if (args.get(0).equalsIgnoreCase("cat")) {
      // println Hdfs.get( session ).from( dataDir + "/" + dataFile ).now().string
      // :fs cat target-path
      String path = args.get(1);
      return cat(mounts, path);
    }
    else if (args.get(0).equalsIgnoreCase("mkdir")) {
      // println Hdfs.mkdir( session ).dir( directoryPath ).perm( "777" ).now().string
      // :fs mkdir target-path [perms]
      String path = args.get(1);
      String perms = null;
      if (args.size() == 3) {
        perms = args.get(2);
      }

      return mkdir(mounts, path, perms);
    }
    else if (args.get(0).equalsIgnoreCase("get")) {
      // println Hdfs.get( session ).from( dataDir + "/" + dataFile ).now().string
      // :fs get from-path [to-path]
      String path = args.get(1);

      String mountPoint = determineMountPoint(path);
      KnoxSession session = getSessionForMountPoint(mounts, mountPoint);
      if (session != null) {
        String from = determineTargetPath(path, mountPoint);
        String to = null;
        if (args.size() > 2) {
          to = args.get(2);
        }
        else {
          to = System.getProperty("user.home") + File.separator +
              path.substring(path.lastIndexOf(File.separator));
        }
        return get(mountPoint, from, to);
      }
      else {
        return "No session established for mountPoint: " + mountPoint + " Use :fs mount {topology-url} {mountpoint-name}";
      }
    }
    else {
      System.out.println("Unknown filesystem command");
      System.out.println(getUsage());
    }
    return "";
  }