java - 在 java 代码中设置 job.properties 文件以启动 oozie 操作

标签 java hadoop workflow oozie

我正在尝试使用 Java 代码启动 oozie 操作。使用命令行时,我们通过“-config job.properties”指定属性文件,它知道选择哪个工作流程。我们如何在 java 代码中定义“job.properties”文件来完成相同的任务?

    conf.setProperty(OozieClient.APP_PATH,"hdfs://clusterdb05.com:8020/user/apps/merge-logs/workflow.xml");
    conf.setProperty("jobTracker", "jobtracker.com:8021");
    conf.setProperty("nameNode", "hdfs://namenode.com:8020");
    conf.setProperty("queueName", "jobtracker.com:8021");
    conf.setProperty("appsRoot", "hdfs://namenode.com:8020/user/apps");

    try {
        String jobId = wc.run(conf);

        System.out.println("Workflow job 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 (OozieClientException oozieClientException) {
        oozieClientException.printStackTrace();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

最佳答案

它是ResourceBundel 的示例。尝试与您的程序集成。

public class BundleTest {
    private ResourceBundle bundle;

    public BundleTest() {
        bundle = ResourceBundle.getBundle("job");
    }

    public String getMessage(String id, Object... params) {
        String text = null;
        try {
            text = bundle.getString(id);
        } catch (MissingResourceException e) {
            text = "!! key " + id + " not found !!";
        }
        if (params != null) {
            MessageFormat mf = new MessageFormat(text);
            text = mf.format(params, new StringBuffer(), null).toString();
        }
        return text;
    }

    public static void main(String[] args) {
      BundleTest test = new BundleTest();
        String jobTracker = test.getMessage("jobTracker");
        String nameNode = test.getMessage("nameNode");
        String queueName = test.getMessage("queueName");
        String appsRoot = test.getMessage("appsRoot");
        System.out.println(jobTracker);
        System.out.println(nameNode);
        System.out.println(queueName);
        System.out.println(appsRoot);

        String message2 = test.getMessage("JOB_KEY_2", "Your First");
        System.out.println(message2);
    }
}

工作属性

jobTracker=jobtracker.com:8021
nameNode=hdfs://namenode.com:8020
queueName=jobtracker.com:8021
appsRoot=hdfs://namenode.com:8020/user/apps;
#With Parameter
JOB_KEY_2= {0} Job

输出:

jobtracker.com:8021
hdfs://namenode.com:8020
jobtracker.com:8021
hdfs://namenode.com:8020/user/apps;
Your First Job

关于java - 在 java 代码中设置 job.properties 文件以启动 oozie 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12928272/

相关文章:

java - Spark NullPointerException 与 saveAsTextFile

java - JsonMappingException : Can not deserialize instance of java. util.List 超出 START_OBJECT token

hadoop - 如何在 HIVE 中从长结构到宽结构?

workflow - 组织生物信息学项目的最佳方式?

java - Android应用程式在手机启动时持续当机

java - 解密Android RSA : Invalid Ciphertext Exception

hadoop - HBaseTestingUtility在Windows 10上失败并显示UnsatisfiedLinkError

hadoop - 如何提高Hive的速度

python - 使用异步事件实现状态引擎的正确方法是什么?

JavaScript流程图/流程图库