使用 oozie java api 读取 oozie 捕获输出元素

Reading oozie capture-output element using oozie java api

我正在使用 Oozie java 客户端 Api 从我的 java 程序启动 shell 操作。我想从我的 java 程序中读取 shell 操作的捕获输出元素。我尝试使用下面的功能。但是,我得到了一个 NullPointerException。

org.apache.oozie.DagELFunctions.wf_actionData(String actionName)

这是使用 Java 客户端 API 提交 Oozie 作业的 java 程序。

public class OozieSample {

public static void main(String[] args) throws OozieClientException, InterruptedException {
    // TODO Auto-generated method stub

    // get a OozieClient for local Oozie
    OozieClient wc = new OozieClient("http://bar:8080/oozie");

    // create a workflow job configuration and set the workflow application path
    Properties conf = wc.createConfiguration();
    conf.setProperty(OozieClient.APP_PATH, "hdfs://foo:9000/usr/tucu/my-wf-app");

    // setting workflow parameters
    conf.setProperty("jobTracker", "foo:9001");

    // submit and start the workflow job
    String jobId = wc.run(conf);
    System.out.println("Workflow job submitted");
    System.out.println(jobId);

    // wait until the workflow job finishes printing the status every 10 seconds
    while (wc.getJobInfo(jobId).getStatus() == WorkflowJob.Status.RUNNING) {
        System.out.println("Workflow job running ...");
        Thread.sleep(10 * 1000);
    }

    System.out.println(org.apache.oozie.DagELFunctions.wf_actionData("shell-5ed8"));

    // print the final status o the workflow job
    System.out.println("Workflow job completed ...");

    }

有没有办法从 java 程序中读取 oozie 捕获输出元素?

Shell动作capture-output在动作data字段中写成Properties(SshActionExecutor.java:142). This can be accessed via Oozie REST Api.

我用 curl 做了一些测试,它就在那里:

curl http://host:11000/oozie/v1/job/job-id?show=info

响应片段:

{
   //(...)
   "actions": [
     {
       //(...)
       "data": "#\n#Tue May 15 15:04:48 EEST 2018\nfoo=bar\n"
     }
   ]
}

这是一个使用 shell 脚本 echo "foo=bar" 的动作。

因为 OozieClient 是这个 API 的包装器,像这样的东西应该可以工作:

WorkflowJob job = oozieClient.getJobInfo("oozie-wf-id");

String data = job.getActions().stream()
        .filter(action -> "shell-5ed8".equals(action.getName()))
        .map(WorkflowAction::getData)
        .findFirst().orElse("");

Properties actionProperties = new Properties();
actionProperties.load(new StringReader(data));