Search in sources :

Example 1 with Command

use of org.apache.hadoop.fs.shell.Command in project hadoop by apache.

the class FsShell method printInfo.

private void printInfo(PrintStream out, String cmd, boolean showHelp) {
    if (cmd != null) {
        // display help or usage for one command
        Command instance = commandFactory.getInstance("-" + cmd);
        if (instance == null) {
            throw new UnknownCommandException(cmd);
        }
        if (showHelp) {
            printInstanceHelp(out, instance);
        } else {
            printInstanceUsage(out, instance);
        }
    } else {
        // display help or usage for all commands 
        out.println(getUsagePrefix());
        // display list of short usages
        ArrayList<Command> instances = new ArrayList<Command>();
        for (String name : commandFactory.getNames()) {
            Command instance = commandFactory.getInstance(name);
            if (!instance.isDeprecated()) {
                out.println("\t[" + instance.getUsage() + "]");
                instances.add(instance);
            }
        }
        // display long descriptions for each command
        if (showHelp) {
            for (Command instance : instances) {
                out.println();
                printInstanceHelp(out, instance);
            }
        }
        out.println();
        ToolRunner.printGenericCommandUsage(out);
    }
}
Also used : Command(org.apache.hadoop.fs.shell.Command) FsCommand(org.apache.hadoop.fs.shell.FsCommand) ArrayList(java.util.ArrayList)

Example 2 with Command

use of org.apache.hadoop.fs.shell.Command in project hadoop by apache.

the class FsShell method run.

/**
   * run
   */
@Override
public int run(String[] argv) throws Exception {
    // initialize FsShell
    init();
    Tracer tracer = new Tracer.Builder("FsShell").conf(TraceUtils.wrapHadoopConf(SHELL_HTRACE_PREFIX, getConf())).build();
    int exitCode = -1;
    if (argv.length < 1) {
        printUsage(System.err);
    } else {
        String cmd = argv[0];
        Command instance = null;
        try {
            instance = commandFactory.getInstance(cmd);
            if (instance == null) {
                throw new UnknownCommandException();
            }
            TraceScope scope = tracer.newScope(instance.getCommandName());
            if (scope.getSpan() != null) {
                String args = StringUtils.join(" ", argv);
                if (args.length() > 2048) {
                    args = args.substring(0, 2048);
                }
                scope.getSpan().addKVAnnotation("args", args);
            }
            try {
                exitCode = instance.run(Arrays.copyOfRange(argv, 1, argv.length));
            } finally {
                scope.close();
            }
        } catch (IllegalArgumentException e) {
            if (e.getMessage() == null) {
                displayError(cmd, "Null exception message");
                e.printStackTrace(System.err);
            } else {
                displayError(cmd, e.getLocalizedMessage());
            }
            printUsage(System.err);
            if (instance != null) {
                printInstanceUsage(System.err, instance);
            }
        } catch (Exception e) {
            // instance.run catches IOE, so something is REALLY wrong if here
            LOG.debug("Error", e);
            displayError(cmd, "Fatal internal error");
            e.printStackTrace(System.err);
        }
    }
    tracer.close();
    return exitCode;
}
Also used : Command(org.apache.hadoop.fs.shell.Command) FsCommand(org.apache.hadoop.fs.shell.FsCommand) Tracer(org.apache.htrace.core.Tracer) TraceScope(org.apache.htrace.core.TraceScope) IOException(java.io.IOException)

Example 3 with Command

use of org.apache.hadoop.fs.shell.Command in project SSM by Intel-bigdata.

the class SmartShell method run.

/**
   * run
   */
@Override
public int run(String[] argv) throws Exception {
    init();
    int exitCode = -1;
    if (argv.length < 1) {
        printUsage(System.err);
    } else {
        String cmd = argv[0];
        Command instance = null;
        try {
            instance = commandFactory.getInstance(cmd);
            if (instance == null) {
                throw new UnknownCommandException();
            }
            exitCode = instance.run(Arrays.copyOfRange(argv, 1, argv.length));
        } catch (IllegalArgumentException e) {
            if (e.getMessage() == null) {
                displayError(cmd, "Null exception message");
                e.printStackTrace(System.err);
            } else {
                displayError(cmd, e.getLocalizedMessage());
            }
            printUsage(System.err);
            if (instance != null) {
                printInstanceUsage(System.err, instance);
            }
        } catch (Exception e) {
            // instance.run catches IOE, so something is REALLY wrong if here
            LOG.debug("Error", e);
            displayError(cmd, "Fatal internal error");
            e.printStackTrace(System.err);
        }
    }
    return exitCode;
}
Also used : Command(org.apache.hadoop.fs.shell.Command) IOException(java.io.IOException)

Example 4 with Command

use of org.apache.hadoop.fs.shell.Command in project SSM by Intel-bigdata.

the class SmartShell method displayError.

private void displayError(String cmd, String message) {
    for (String line : message.split("\n")) {
        System.err.println(cmd + ": " + line);
        if (cmd.charAt(0) != '-') {
            Command instance = null;
            instance = commandFactory.getInstance("-" + cmd);
            if (instance != null) {
                System.err.println("Did you mean -" + cmd + "?  This command " + "begins with a dash.");
            }
        }
    }
}
Also used : Command(org.apache.hadoop.fs.shell.Command)

Example 5 with Command

use of org.apache.hadoop.fs.shell.Command in project SSM by Intel-bigdata.

the class SmartShell method printInfo.

private void printInfo(PrintStream out, String cmd, boolean showHelp) {
    if (cmd != null) {
        // display help or usage for one command
        Command instance = commandFactory.getInstance("-" + cmd);
        if (instance == null) {
            throw new UnknownCommandException(cmd);
        }
        if (showHelp) {
            printInstanceHelp(out, instance);
        } else {
            printInstanceUsage(out, instance);
        }
    } else {
        // display help or usage for all commands
        out.println(getUsagePrefix());
        // display list of short usages
        ArrayList<Command> instances = new ArrayList<Command>();
        for (String name : commandFactory.getNames()) {
            Command instance = commandFactory.getInstance(name);
            if (!instance.isDeprecated()) {
                out.println("\t[" + instance.getUsage() + "]");
                instances.add(instance);
            }
        }
        // display long descriptions for each command
        if (showHelp) {
            for (Command instance : instances) {
                out.println();
                printInstanceHelp(out, instance);
            }
        }
        out.println();
        ToolRunner.printGenericCommandUsage(out);
    }
}
Also used : Command(org.apache.hadoop.fs.shell.Command) ArrayList(java.util.ArrayList)

Aggregations

Command (org.apache.hadoop.fs.shell.Command)7 FsCommand (org.apache.hadoop.fs.shell.FsCommand)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Configuration (org.apache.hadoop.conf.Configuration)1 CommandFactory (org.apache.hadoop.fs.shell.CommandFactory)1 GenericTestUtils (org.apache.hadoop.test.GenericTestUtils)1 TraceScope (org.apache.htrace.core.TraceScope)1 Tracer (org.apache.htrace.core.Tracer)1 Test (org.junit.Test)1