Example usage for org.apache.hadoop.util Tool run

List of usage examples for org.apache.hadoop.util Tool run

Introduction

In this page you can find the example usage for org.apache.hadoop.util Tool run.

Prototype

int run(String[] args) throws Exception;

Source Link

Document

Execute the command with the given arguments.

Usage

From source file:cmd.freebase2rdf4mr.java

License:Apache License

@Override
public int run(String[] args) throws Exception {
    if (args.length != 2) {
        System.err.printf("Usage: %s [generic options] <input> <output>\n", getClass().getName());
        ToolRunner.printGenericCommandUsage(System.err);
        return -1;
    }//w w  w.ja  v  a 2s .co m

    Configuration configuration = getConf();
    boolean overrideOutput = configuration.getBoolean(OPTION_OVERRIDE_OUTPUT, OPTION_OVERRIDE_OUTPUT_DEFAULT);

    FileSystem fs = FileSystem.get(new Path(args[1]).toUri(), configuration);
    if (overrideOutput) {
        fs.delete(new Path(args[1]), true);
    }

    Tool driver = new Freebase2RDFDriver(configuration);
    driver.run(new String[] { args[0], args[1] });

    return 0;
}

From source file:cmd.infer.java

License:Apache License

@Override
public int run(String[] args) throws Exception {
    if (args.length != 2) {
        System.err.printf("Usage: %s [generic options] <input> <output>\n", getClass().getName());
        ToolRunner.printGenericCommandUsage(System.err);
        return -1;
    }/*w w w  .  ja  v a  2 s  .  com*/

    Configuration configuration = getConf();
    boolean overrideOutput = configuration.getBoolean(Constants.OPTION_OVERRIDE_OUTPUT,
            Constants.OPTION_OVERRIDE_OUTPUT_DEFAULT);

    FileSystem fs = FileSystem.get(new Path(args[1]).toUri(), configuration);
    if (overrideOutput) {
        fs.delete(new Path(args[1]), true);
    }

    Tool infer = new InferDriver(configuration);
    infer.run(new String[] { args[0], args[1] });

    return 0;
}

From source file:cmd.rdf2adjacencylist.java

License:Apache License

@Override
public int run(String[] args) throws Exception {
    if (args.length != 2) {
        System.err.printf("Usage: %s [generic options] <input> <output>\n", getClass().getName());
        ToolRunner.printGenericCommandUsage(System.err);
        return -1;
    }/*w w w .j a  v a2  s . c  om*/

    Configuration configuration = getConf();
    boolean overrideOutput = configuration.getBoolean(Constants.OPTION_OVERWRITE_OUTPUT,
            Constants.OPTION_OVERWRITE_OUTPUT_DEFAULT);

    FileSystem fs = FileSystem.get(new Path(args[1]).toUri(), configuration);
    if (overrideOutput) {
        fs.delete(new Path(args[1]), true);
    }

    Tool tool = new Rdf2AdjacencyListDriver(configuration);
    tool.run(new String[] { args[0], args[1] });

    return 0;
}

From source file:cmd.stats.java

License:Apache License

@Override
public int run(String[] args) throws Exception {
    if (args.length != 2) {
        System.err.printf("Usage: %s [generic options] <input> <output>\n", getClass().getName());
        ToolRunner.printGenericCommandUsage(System.err);
        return -1;
    }//from  ww w  .  ja v a2s .  c  o m

    Configuration configuration = getConf();
    boolean overrideOutput = configuration.getBoolean(Constants.OPTION_OVERRIDE_OUTPUT,
            Constants.OPTION_OVERRIDE_OUTPUT_DEFAULT);

    FileSystem fs = FileSystem.get(new Path(args[1]).toUri(), configuration);
    if (overrideOutput) {
        fs.delete(new Path(args[1]), true);
    }

    Tool stats = new StatsDriver(configuration);
    stats.run(new String[] { args[0], args[1] });

    return 0;
}

From source file:cmd.tdbloader4.java

License:Apache License

@Override
public int run(String[] args) throws Exception {
    if (args.length != 2) {
        System.err.printf("Usage: %s [generic options] <input> <output>\n", getClass().getName());
        ToolRunner.printGenericCommandUsage(System.err);
        return -1;
    }//from   w ww  .  jav  a2  s  . co  m

    Configuration configuration = getConf();
    configuration.set(Constants.RUN_ID, String.valueOf(System.currentTimeMillis()));
    boolean overrideOutput = configuration.getBoolean(Constants.OPTION_OVERRIDE_OUTPUT,
            Constants.OPTION_OVERRIDE_OUTPUT_DEFAULT);
    boolean copyToLocal = configuration.getBoolean(Constants.OPTION_COPY_TO_LOCAL,
            Constants.OPTION_COPY_TO_LOCAL_DEFAULT);
    boolean verify = configuration.getBoolean(Constants.OPTION_VERIFY, Constants.OPTION_VERIFY_DEFAULT);
    boolean runLocal = configuration.getBoolean(Constants.OPTION_RUN_LOCAL, Constants.OPTION_RUN_LOCAL_DEFAULT);

    FileSystem fs = FileSystem.get(new Path(args[1]).toUri(), configuration);
    if (overrideOutput) {
        fs.delete(new Path(args[1]), true);
        fs.delete(new Path(args[1] + OUTPUT_PATH_POSTFIX_1), true);
        fs.delete(new Path(args[1] + OUTPUT_PATH_POSTFIX_2), true);
        fs.delete(new Path(args[1] + OUTPUT_PATH_POSTFIX_3), true);
        fs.delete(new Path(args[1] + OUTPUT_PATH_POSTFIX_4), true);
    }

    if ((copyToLocal) || (runLocal)) {
        File path = new File(args[1]);
        path.mkdirs();
    }

    Tool first = new FirstDriver(configuration);
    int status = first.run(new String[] { args[0], args[1] + OUTPUT_PATH_POSTFIX_1 });
    if (status != 0) {
        return status;
    }

    createOffsetsFile(fs, args[1] + OUTPUT_PATH_POSTFIX_1, args[1] + OUTPUT_PATH_POSTFIX_1);
    Path offsets = new Path(args[1] + OUTPUT_PATH_POSTFIX_1, Constants.OFFSETS_FILENAME);
    DistributedCache.addCacheFile(offsets.toUri(), configuration);

    Tool second = new SecondDriver(configuration);
    status = second.run(new String[] { args[0], args[1] + OUTPUT_PATH_POSTFIX_2 });
    if (status != 0) {
        return status;
    }

    Tool third = new ThirdDriver(configuration);
    status = third.run(new String[] { args[1] + OUTPUT_PATH_POSTFIX_2, args[1] + OUTPUT_PATH_POSTFIX_3 });
    if (status != 0) {
        return status;
    }

    Tool fourth = new FourthDriver(configuration);
    status = fourth.run(new String[] { args[1] + OUTPUT_PATH_POSTFIX_3, args[1] + OUTPUT_PATH_POSTFIX_4 });
    if (status != 0) {
        return status;
    }

    if (copyToLocal) {
        Tool download = new download(configuration);
        download.run(
                new String[] { args[1] + OUTPUT_PATH_POSTFIX_2, args[1] + OUTPUT_PATH_POSTFIX_4, args[1] });
    }

    if (verify) {
        DatasetGraphTDB dsgMem = load(args[0]);
        Location location = new Location(args[1]);

        if (!copyToLocal) {
            // TODO: this is a sort of a cheat and it could go away (if it turns out to be too slow)!
            download.fixNodeTable2(location);
        }

        DatasetGraphTDB dsgDisk = SetupTDB.buildDataset(location);
        boolean isomorphic = isomorphic(dsgMem, dsgDisk);
        System.out.println("> " + isomorphic);
    }

    return status;
}

From source file:com.asakusafw.dag.compiler.codegen.CleanupStageClientGeneratorTest.java

License:Apache License

private void run(ClassDescription generated, String executionId) {
    Configuration conf = new Configuration();
    conf.set(StageConstants.PROP_USER, "testing");
    conf.set(StageConstants.PROP_EXECUTION_ID, executionId);
    loading(generated, c -> {/*from   w w  w .ja  v  a  2  s. c  o  m*/
        Tool t = ReflectionUtils.newInstance(c.asSubclass(Tool.class), conf);
        assertThat(t.run(new String[0]), is(0));
    });
}

From source file:com.asakusafw.lang.compiler.mapreduce.testing.MapReduceRunner.java

License:Apache License

private static int execute0(Configuration conf, ClassLoader classLoader, ClassDescription clientClass,
        String executionId, Map<String, String> batchArguments) throws Exception {
    try (ClassLoaderContext context = new ClassLoaderContext(classLoader)) {
        Configuration copy = new Configuration(conf);
        copy.setClassLoader(classLoader);
        Tool tool = resolveClient(copy, clientClass);
        configure(copy, executionId, batchArguments);
        return tool.run(EMPTY_ARGUMENTS);
    }/*from w  w  w .  ja  va  2  s.c om*/
}

From source file:com.asakusafw.operation.tools.hadoop.fs.Clean.java

License:Apache License

/**
 * Program entry.//  w  w w .j  a va2  s.c  om
 * @param args arguments
 * @throws Exception if failed to execute command
 */
public static void main(String... args) throws Exception {
    LOG.info("[OT-CLEAN-I00000] Start Hadoop FS cleaning tool");
    long start = System.currentTimeMillis();
    Tool tool = new Clean();
    tool.setConf(new Configuration());
    int exit = tool.run(args); // no generic options
    long end = System.currentTimeMillis();
    LOG.info(MessageFormat.format(
            "[OT-CLEAN-I00999] Finish Hadoop FS cleaning tool (exit-code={0}, elapsed={1}ms)", exit,
            end - start));
    if (exit != 0) {
        System.exit(exit);
    }
}

From source file:com.cloudera.cdk.examples.common.TestUtil.java

License:Apache License

public static void run(Matcher<Integer> exitCodeMatcher, Matcher<String> stdOutMatcher, Tool tool,
        String... args) throws Exception {
    PrintStream oldStdOut = System.out;
    try {/*from   w  w  w.ja va2  s  . c  o  m*/
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        System.setOut(new PrintStream(out));
        int rc = tool.run(args);
        assertThat(rc, exitCodeMatcher);
        assertThat(out.toString(), stdOutMatcher);
    } finally {
        System.setOut(oldStdOut);
    }
}

From source file:com.ery.server.util.ToolRunner.java

License:Apache License

/**
 * Runs the given <code>Tool</code> by {@link Tool#run(String[])}, after
 * parsing with the given generic arguments. Uses the given
 * <code>Configuration</code>, or builds one if null.
 * /*from   www  .jav  a 2  s  . c  om*/
 * Sets the <code>Tool</code>'s configuration with the possibly modified
 * version of the <code>conf</code>.
 * 
 * @param conf
 *            <code>Configuration</code> for the <code>Tool</code>.
 * @param tool
 *            <code>Tool</code> to run.
 * @param args
 *            command-line arguments to the tool.
 * @return exit code of the {@link Tool#run(String[])} method.
 */
public static int run(Configuration conf, Tool tool, String[] args) throws Exception {
    if (conf == null) {
        conf = new Configuration();
    }
    // set the configuration back, so that Tool can configure itself
    tool.setConf(conf);

    // get the args w/o generic hadoop args
    // String[] toolArgs = parser.getRemainingArgs();
    return tool.run(args);
}