通过Java API安排Oozie工作流程

时间:2015-12-22 16:33:41

标签: oozie oozie-coordinator

是否可以动态安排Oozie工作流 ?也就是说,通过Java API而不是配置文件指定参数?

例如,我希望能够在每天晚上10点安排工作流程执行,但是要通过Web界面指定时间,因为它可以更改。怎么做?

1 个答案:

答案 0 :(得分:0)

您好,您可以使用以下内容:

public class Oozie {

    public static void main(String[] args) {
        OozieClient wc = new OozieClient("http://oozieserver:11000/oozie");

        Properties conf = wc.createConfiguration();

        conf.setProperty("nameNode", "hdfs://namenode:8020");
        conf.setProperty("jobTracker", "resourcemanager:8032");
        conf.setProperty("queueName", "default");
        conf.setProperty("oozie.libpath", "${nameNode}/user/oozie/share/lib");
        conf.setProperty("oozie.use.system.libpath", "true");
        conf.setProperty("oozie.wf.rerun.failnodes", "true");

        conf.setProperty("oozieProjectRoot",
                "${nameNode}/user/bijoy/oozieProject");
        conf.setProperty("appPath",
                "${oozieProjectRoot}/workflowJavaMainAction");
        conf.setProperty(OozieClient.APP_PATH, "${appPath}");

        conf.setProperty("inputDir", "${oozieProjectRoot}/data/*/*/*/*/*");
        conf.setProperty("outputDir", "${appPath}/output");

        try {
            String jobId = wc.run(conf);
            System.out.println("Workflow job, " + jobId + " submitted");

            while (wc.getJobInfo(jobId).getStatus() == WorkflowJob.Status.RUNNING) {
                System.out.println("Workflow job running ...");
                Thread.sleep(10 * 1000);
            }
            System.out.println("Workflow job completed ...");
            System.out.println(wc.getJobInfo(jobId));
        } catch (Exception r) {
            System.out.println("Errors " + r.getLocalizedMessage());
        }
    }
}