QAnyang 2014-01-01
相关代码:
OozieClientoozieClient=newOozieClient("http://namenode:11000/oozie");
Propertiesconf=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{
StringjobId=oozieClient.run(conf);
System.out.println("workflowjobhassubmitted");
while(WorkflowJob.Status.RUNNING==oozieClient.getJobInfo(jobId).getStatus()){
System.out.println("workflowjobrunning");
Thread.sleep(10*1000);
}
System.out.println("workflowjobcompleted");
System.out.println(oozieClient.getJobInfo(jobId));
}catch(Exceptione){
System.out.println("Errors");
e.printStackTrace();
}
也可以加载相关的job.properties文件
OozieClientoozieClient=newOozieClient("http://namenode:11000/oozie");
Propertiesconf=oozieClient.createConfiguration();
conf.setProperty(OozieClient.APP_PATH,"hdfs://namenode:49000/user/hadoop/examples/apps/map-reduce-1");
InputStreaminStream=null;
try{
inStream=MyClient002.class.getClassLoader().getResourceAsStream(
"job/job.properties");
conf.load(inStream);
StringjobId=oozieClient.run(conf);
System.out.println("workflowjobhassubmitted");
while(WorkflowJob.Status.RUNNING==oozieClient.getJobInfo(jobId).getStatus()){
System.out.println("workflowjobrunning");
Thread.sleep(10*1000);
}
System.out.println("workflowjobcompleted");
System.out.println(oozieClient.getJobInfo(jobId));
}catch(Exceptione){
System.out.println("Errors");
e.printStackTrace();
}finally{
if(null!=inStream){
try{
inStream.close();
}catch(IOExceptione){
e.printStackTrace();
}
}
}