java调用oozie接口,使用Java代码生成Oozie工作流

Looking through Oozie examples and documentation, it looks like you need a workflow file in order to run an oozie job from Java code. Is ther any way to submit a job directly fro Java code, without needing a workflow file? Is there any pre-existing way to dynamically generate these files through java code? Are there any pre-existing tools that will make generating them easier? Or will I have to write the entirety of the code to generate the file?

Current Situation

OozieClient wc = new OozieClient("http://bar:8080/oozie");

Properties conf = wc.createConfiguration();

conf.setProperty(OozieClient.APP_PATH, "workflow file path");

// set other properties

...

// submit and start the workflow job

wc.run(conf);

Ideal situation is something vaguely like this.

OozieAction action = new OozieAction("actionName");

action.setOkDestination("nextAction");

action.setErrorDestination("errorDestination");

//Rest of config for action

OozieWorkflow workflow = new Oozieworkflow();

workfow.setStartAction(action);

workflow.addAction(otherAction);

//rest of conf

OozieClient wc = new OozieClient("http://bar:8080/oozie");

wc.runWorkflow(workflow);

Another situation that would be desirable if the former is impossibble is:

OozieAction action = new OozieAction("actionName");

action.setOkDestination("nextAction");

action.setErrorDestination("errorDestination");

//Rest of config for action

OozieWorkflow workflow = new Oozieworkflow();

workfow.setStartAction(action);

workflow.addAction(otherAction);

//rest of conf

workflow.writeToFile("some localFile")

//load file to HDFS

//This would also work

// workflow.writeToHDFS("someHdfsLocation");

OozieClient wc = new OozieClient("http://bar:8080/oozie");

//run with created workflow

解决方案

Oozie 5.1.0 added support for Fluent Job API which makes it possible to write java code instead of workflow XML files (under the hood, Oozie will generate the XML file for you).

Simple example for the java code which creates a workflow similar to the shell action demo of Oozie:

public class MyFirstWorkflowFactory implements WorkflowFactory {

@Override

public Workflow create() {

final ShellAction shellAction = ShellActionBuilder.create()

.withName("shell-action")

.withResourceManager("${resourceManager}")

.withNameNode("${nameNode}")

.withConfigProperty("mapred.job.queue.name", "${queueName}")

.withExecutable("echo")

.withArgument("my_output=Hello Oozie")

.withCaptureOutput(true)

.build();

final Workflow shellWorkflow = new WorkflowBuilder()

.withName("shell-workflow")

.withDagContainingNode(shellAction).build();

return shellWorkflow;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值