Oozie Java代码运行Job

相关代码:
OozieClient oozieClient = new OozieClient("http://namenode:11000/oozie");
Properties conf = oozieClient.createConfiguration();
conf.setProperty(OozieClient.APP_PATH, "hdfs://namenode:49000/user/hadoop/examples/apps/map-reduce-1");
conf.setProperty("jobTracker", "namenode:49001");
conf.setProperty("nameNode", "hdfs://namenode:49000");
conf.setProperty("queueName", "default");
conf.setProperty("examplesRoot", "examples");
conf.setProperty("outputDir", "map-reduce-out-001");
try {
    String jobId = oozieClient.run(conf);
    System.out.println("workflow job has submitted");
    while (WorkflowJob.Status.RUNNING ==    oozieClient.getJobInfo(jobId).getStatus()) {
    System.out.println("workflow job running");
    Thread.sleep(10 * 1000);
    }
    System.out.println("workflow job completed");
    System.out.println(oozieClient.getJobInfo(jobId));
} catch (Exception e) {
    System.out.println("Errors");
    e.printStackTrace();
}
也可以加载相关的job.properties文件
OozieClient oozieClient = new OozieClient("http://namenode:11000/oozie");
Properties conf = oozieClient.createConfiguration();
conf.setProperty(OozieClient.APP_PATH, "hdfs://namenode:49000/user/hadoop/examples/apps/map-reduce-1");
InputStream inStream = null;
try {
     inStream=MyClient002.class.getClassLoader().getResourceAsStream(
     "job/job.properties");
    conf.load(inStream);
    String jobId = oozieClient.run(conf);
    System.out.println("workflow job has submitted");
    while (WorkflowJob.Status.RUNNING == oozieClient.getJobInfo(jobId).getStatus()) {
    System.out.println("workflow job running");
    Thread.sleep(10 * 1000);
    }
    System.out.println("workflow job completed");
    System.out.println(oozieClient.getJobInfo(jobId));
} catch (Exception e) {
    System.out.println("Errors");
    e.printStackTrace();
} finally {
    if (null != inStream) {
try {
    inStream.close();
} catch (IOException e) {
    e.printStackTrace();
}
    }
}

你可能感兴趣的:(hadoop,oozie)