Example usage for org.apache.hadoop.mapred RunningJob waitForCompletion

List of usage examples for org.apache.hadoop.mapred RunningJob waitForCompletion

Introduction

In this page you can find the example usage for org.apache.hadoop.mapred RunningJob waitForCompletion.

Prototype

public void waitForCompletion() throws IOException;

Source Link

Document

Blocks until the job is complete.

Usage

From source file:org.hbasene.index.create.mapred.BuildTableIndex.java

License:Apache License

/**
 * Block and do not return until the job is complete.
 * /*from w w  w.  ja va2s.  c o m*/
 * @param args
 * @throws IOException
 */
public void run(String[] args) throws IOException {
    if (args.length < 6) {
        printUsage("Too few arguments");
    }

    int numMapTasks = 1;
    int numReduceTasks = 1;
    String iconfFile = null;
    String indexDir = null;
    String tableName = null;
    StringBuilder columnNames = null;

    // parse args
    for (int i = 0; i < args.length - 1; i++) {
        if ("-m".equals(args[i])) {
            numMapTasks = Integer.parseInt(args[++i]);
        } else if ("-r".equals(args[i])) {
            numReduceTasks = Integer.parseInt(args[++i]);
        } else if ("-indexConf".equals(args[i])) {
            iconfFile = args[++i];
        } else if ("-indexDir".equals(args[i])) {
            indexDir = args[++i];
        } else if ("-table".equals(args[i])) {
            tableName = args[++i];
        } else if ("-columns".equals(args[i])) {
            columnNames = new StringBuilder(args[++i]);
            while (i + 1 < args.length && !args[i + 1].startsWith("-")) {
                columnNames.append(" ");
                columnNames.append(args[++i]);
            }
        } else {
            printUsage("Unsupported option " + args[i]);
        }
    }

    if (indexDir == null || tableName == null || columnNames == null) {
        printUsage("Index directory, table name and at least one column must " + "be specified");
    }

    Configuration conf = new HBaseConfiguration();
    if (iconfFile != null) {
        // set index configuration content from a file
        String content = readContent(iconfFile);
        IndexConfiguration iconf = new IndexConfiguration();
        // purely to validate, exception will be thrown if not valid
        iconf.addFromXML(content);
        conf.set("hbase.index.conf", content);
    }

    if (columnNames != null) {
        JobConf jobConf = createJob(conf, numMapTasks, numReduceTasks, indexDir, tableName,
                columnNames.toString());
        RunningJob runningJob = JobClient.runJob(jobConf);
        runningJob.waitForCompletion();
    }
}

From source file:uk.bl.wa.hadoop.mapreduce.warcstats.WARCStatsTool.java

License:Open Source License

@Override
public int run(String[] args) throws Exception {
    // Set up the base conf:
    JobConf conf = new JobConf(getConf(), WARCStatsTool.class);

    // Get the job configuration:
    this.createJobConf(conf, args);

    // Submit it:
    JobClient client = new JobClient(conf);
    RunningJob job = client.submitJob(conf);

    // And await completion before exiting...
    job.waitForCompletion();

    return 0;/*  w  w  w . j  a va 2s  .co  m*/
}