Example usage for org.apache.hadoop.fs Path CUR_DIR

List of usage examples for org.apache.hadoop.fs Path CUR_DIR

Introduction

In this page you can find the example usage for org.apache.hadoop.fs Path CUR_DIR.

Prototype

String CUR_DIR

To view the source code for org.apache.hadoop.fs Path CUR_DIR.

Click Source Link

Document

The current directory, ".".

Usage

From source file:cn.ict.magicube.fs.shell.FixedLs.java

License:Apache License

@Override
protected void processOptions(LinkedList<String> args) throws IOException {
    CommandFormat cf = new CommandFormat(0, Integer.MAX_VALUE, "d", "h", "R");
    cf.parse(args);/*from ww w. ja  v a 2 s .com*/
    dirRecurse = !cf.getOpt("d");
    setRecursive(cf.getOpt("R") && dirRecurse);
    humanReadable = cf.getOpt("h");
    if (args.isEmpty())
        args.add(Path.CUR_DIR);
}

From source file:com.gruter.hadoop.customShell.CustomShell.java

License:Apache License

/**
 * run/*from   w  w w. j ava 2 s  .co m*/
 */
public int run(String argv[]) throws Exception {

    if (argv.length < 1) {
        printUsage("");
        return -1;
    }

    int exitCode = -1;
    int i = 0;
    String cmd = argv[i++];

    //
    // verify that we have enough command line parameters
    //

    if ("-cat".equals(cmd) || "-text".equals(cmd)) {
        if (argv.length < 2) {
            printUsage(cmd);
            return exitCode;
        }
    }

    // initialize CustomShell
    try {
        init();
    } catch (RPC.VersionMismatch v) {
        System.err.println("Version Mismatch between client and server" + "... command aborted.");
        return exitCode;
    } catch (IOException e) {
        System.err.println("Bad connection to FS. command aborted. exception: " + e.getLocalizedMessage());
        return exitCode;
    }

    exitCode = 0;
    try {
        if ("-cat".equals(cmd)) {
            exitCode = doall(cmd, argv, i);
        } else if ("-text".equals(cmd)) {
            exitCode = doall(cmd, argv, i);
        } else if ("-ls".equals(cmd)) {
            if (i < argv.length) {
                exitCode = doall(cmd, argv, i);
            } else {
                exitCode = ls(Path.CUR_DIR, false);
            }
        } else if ("-help".equals(cmd)) {
            if (i < argv.length) {
                printHelp(argv[i]);
            } else {
                printHelp("");
            }
        } else {
            exitCode = -1;
            System.err.println(cmd.substring(1) + ": Unknown command");
            printUsage("");
        }
    } catch (IllegalArgumentException arge) {
        exitCode = -1;
        System.err.println(cmd.substring(1) + ": " + arge.getLocalizedMessage());
        printUsage(cmd);
    } catch (RemoteException e) {
        //
        // This is a error returned by hadoop server. Print
        // out the first line of the error mesage, ignore the stack trace.
        exitCode = -1;
        try {
            String[] content;
            content = e.getLocalizedMessage().split("\n");
            System.err.println(cmd.substring(1) + ": " + content[0]);
        } catch (Exception ex) {
            System.err.println(cmd.substring(1) + ": " + ex.getLocalizedMessage());
        }
    } catch (IOException e) {
        //
        // IO exception encountered locally.
        // 
        exitCode = -1;
        System.err.println(cmd.substring(1) + ": " + e.getLocalizedMessage());
    } catch (Exception re) {
        exitCode = -1;
        System.err.println(cmd.substring(1) + ": " + re.getLocalizedMessage());
    } finally {
    }
    return exitCode;
}

From source file:com.ibm.stocator.fs.common.ObjectStoreGlobber.java

License:Open Source License

public FileStatus[] glob() throws IOException {
    // First we get the scheme and authority of the pattern that was passed
    // in.//from   w  w  w .  j  ava2  s.  c o  m
    LOG.debug("Welcome to glob : " + pathPattern.toString());
    String scheme = schemeFromPath(pathPattern);
    String authority = authorityFromPath(pathPattern);

    // Next we strip off everything except the pathname itself, and expand all
    // globs. Expansion is a process which turns "grouping" clauses,
    // expressed as brackets, into separate path patterns.
    String pathPatternString = pathPattern.toUri().getPath();
    List<String> flattenedPatterns = ObjectStoreGlobExpander.expand(pathPatternString);

    LOG.debug("expanded : " + pathPatternString);
    // Now loop over all flattened patterns. In every case, we'll be trying to
    // match them to entries in the filesystem.
    ArrayList<FileStatus> results = new ArrayList<FileStatus>(flattenedPatterns.size());
    boolean sawWildcard = false;
    for (String flatPattern : flattenedPatterns) {
        LOG.debug("pattern from list: " + flatPattern);
        Path absPattern = new Path(flatPattern.isEmpty() ? Path.CUR_DIR : flatPattern);
        List<String> components = getPathComponents(absPattern.toUri().getPath());
        ArrayList<FileStatus> candidates = new ArrayList<FileStatus>(1);
        FileStatus rootPlaceholder = new FileStatus(0, true, 0, 0, 0,
                new Path(scheme, authority, Path.SEPARATOR));
        LOG.debug("Going to add candidate: " + rootPlaceholder.getPath().toString());
        candidates.add(rootPlaceholder);
        String cmpCombined = "";
        ObjectStoreGlobFilter globFilter = null;
        for (int componentIdx = 0; componentIdx < components.size() && !sawWildcard; componentIdx++) {
            globFilter = new ObjectStoreGlobFilter(components.get(componentIdx));
            if (globFilter.hasPattern()) {
                sawWildcard = true;
            } else {
                cmpCombined = cmpCombined + "/" + components.get(componentIdx);
            }
        }
        String component = unescapePathComponent(cmpCombined);
        if (component != null && component.length() > 0) {
            for (FileStatus candidate : candidates) {
                candidate.setPath(new Path(candidate.getPath(), component));
            }
        } else {
            globFilter = new ObjectStoreGlobFilter(components.get(0));
        }
        ArrayList<FileStatus> newCandidates = new ArrayList<FileStatus>(candidates.size());
        for (FileStatus candidate : candidates) {
            if (globFilter.hasPattern()) {
                FileStatus[] children = listStatus(candidate.getPath());
                if (children.length == 1) {
                    if (!getFileStatus(candidate.getPath()).isDirectory()) {
                        continue;
                    }
                }
                for (FileStatus child : children) {
                    if (globFilter.accept(child.getPath())) {
                        newCandidates.add(child);
                    }
                }
            } else {
                FileStatus childStatus = null;
                childStatus = getFileStatus(new Path(candidate.getPath(), component));
                if (childStatus != null) {
                    newCandidates.add(childStatus);
                }
            }
        }
        candidates = newCandidates;
        for (FileStatus status : candidates) {
            if (status == rootPlaceholder) {
                status = getFileStatus(rootPlaceholder.getPath());
                if (status == null) {
                    continue;
                }
            }
            if (filter.accept(status.getPath())) {
                results.add(status);
            }
        }
    }
    if (!sawWildcard && results.isEmpty() && (flattenedPatterns.size() <= 1)) {
        return null;
    }
    return results.toArray(new FileStatus[0]);
}

From source file:es.tid.cosmos.platform.injection.server.HadoopFileSystemView.java

License:Open Source License

private HadoopSshFile getFile(String baseDir, String file) throws IOException, InterruptedException {
    String requestedDir = baseDir;
    String requestedFile = file;//  w  w  w .ja v a  2s  .  com

    if (requestedDir.isEmpty() && (requestedFile.isEmpty() || requestedFile.equals(Path.CUR_DIR))) {
        requestedDir = this.homePath;
        requestedFile = "";
        LOG.debug("redirecting to home path: " + this.homePath);
    } // if

    String wholePath = requestedDir + requestedFile;

    if (!requestedDir.endsWith(Path.SEPARATOR) && !requestedFile.startsWith(Path.SEPARATOR)) {
        wholePath = requestedDir + Path.SEPARATOR + requestedFile;
    } // if

    return new HadoopSshFile(wholePath, this.userName, this.hadoopFS);
}

From source file:es.tid.cosmos.platform.injection.server.HadoopSshFile.java

License:Open Source License

@Override
public List<SshFile> listSshFiles() {
    if (!this.isDirectory()) {
        return null;
    } // if/*ww  w  .j  av a2s. c o  m*/

    try {
        FileStatus[] fileStatuses = this.hadoopFS.listStatus(this.hadoopPath);
        LinkedList<SshFile> files = new LinkedList<SshFile>();

        for (FileStatus fileStatus : fileStatuses) {
            String fileName = fileStatus.getPath().getName();
            files.add(new HadoopSshFile(this.appendToPath(fileName), this.userName, this.hadoopFS));
        } // for

        return Collections.unmodifiableList(files);
    } catch (AccessControlException e) {
        LOG.error(e.getMessage(), e);

        try {
            return Collections
                    .singletonList((SshFile) new HadoopSshFile(Path.CUR_DIR, this.userName, this.hadoopFS));
        } catch (IOException e1) {
            LOG.error(e1.getMessage(), e);
        } catch (InterruptedException e1) {
            LOG.error(e1.getMessage(), e);
        } // try catch
    } catch (IOException e) {
        LOG.error(e.getMessage(), e);
    } catch (InterruptedException e) {
        LOG.error(e.getMessage());
    } // try catch

    return null;
}