Oozie的coordinator有啥用?
The Oozie Coordinator system allows the user to define and execute recurrent and interdependent workflow jobs (data application pipelines).
說白了就是可以把各個 workflow作業組織起來。比如,A作業執行完成之后,會有輸出,該輸出觸發B作業的執行。那么 A B 這兩個workflow作業就可以通過一個coordinator作業組織起來。
什么是coordinator作業?
Coordinator Job: A coordinator job is an executable instance of a coordination definition. A job submission is done by submitting a job configuration that resolves all parameters in the application definition.
這說明coordinator作業也是需要配置相應的參數的。與提交workflow作業時配置 workflow.xml類似,coordinator作業也有一個名為coordinator.xml的配置文件。
什么是coordinator action?
Coordinator Action: A coordinator action is a workflow job that is started when a set of conditions are met (input dataset instances are available).
coordinator action本質上是一個workflow 作業!
Coordinator Application: A coordinator application defines the conditions under which coordinator actions should be created (the frequency) and when the actions can be started. The coordinator application also defines a start and an end time. Normally, coordinator applications are parameterized. A Coordinator application is written in XML.
coordinator application 負責管理各個coordinator action。有start time 和 end time,負責其中定義的action的起動與終止。
前面一直在糾結這個問題:oozie coordinator 作業如何配置???
現在記錄如下:
Oozie提供的一個官方的關於定時作業配置文件,內容如下:
<coordinator-app name="cron-coord" frequency="${coord:minutes(10)}" start="${start}" end="${end}" timezone="UTC" xmlns="uri:oozie:coordinator:0.2"> <action> <workflow> <app-path>${workflowAppUri}</app-path> <configuration> <property> <name>jobTracker</name> <value>${jobTracker}</value> </property> <property> <name>nameNode</name> <value>${nameNode}</value> </property> </configuration> </workflow> </action> </coordinator-app>
從上面可以看出, frequency已經寫死了,指定為每十分鍾執行一次。其中啟動時間和結束時間以變量的形式給出,如start="${start}" end="${end}"
這兩個變量可以通過job.properties 文件或者在命令行提交時指定參數即可。此外,還可以通過HTTP POST請求的形式,帶着相關的參數進行作業提交(Oozie 提供了WebService API。)
其實,frequency和 start、end 一樣,也可以用變量來代替,這樣就可以實現我前面帖子里面的問題了---定時提交作業,且只運行一次。
但是,需要注意的是 frequency的格式問題:它只能是 cron expression。否則就會報以下的錯誤:
Invalid coordinator application attributes, parameter [frequency] = [10 * ? ? ?] must be an integer or a cron syntax. Parsing error For input string: "10 * ? ? ?"
關於 cron expression可以參考Quartz,因為Oozie的定時功能是基於它實現的。
此外,我還碰到了一個這樣的問題:
Coordinator job with frequency '10 * * * *' materializes no actions between start and end time.
從Oozie的源代碼可以看出,拋出該異常的程序代碼如下:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
if (nextTime == null) {
throw new IllegalArgumentException("Invalid coordinator cron frequency: " + coordJob.getFrequency());
}
if (!nextTime.before(coordJob.getEndTime())) {
throw new IllegalArgumentException("Coordinator job with frequency '" +
coordJob.getFrequency() + "' materializes no actions between start and end time.");
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
這是因為我的start time 和 end time設置的不合理,下一次作業的運行時間在結束時間之前了,就會出現下面的錯誤。
Coordinator job with frequency '10 * * * *' materializes no actions between start and end time.
文章開頭說了Coordinator作業可以把其他作業組織起來。因此,提交一個Coordinator作業時,會生成一個 父作業ID 和 若干子作業的ID,子作業就是Coordinator作業的配置文件中的 <workflow>標簽中指定的子作業。比如:
生成的一個父作業ID:0000033-160516121313115-oozie-oozi-C
相應的子作業ID:0000033-160516121313115-oozie-oozi-C@1
由於該子作業是一個workflow作業,workflow作業的ID:0000034-160516121313115-oozie-oozi-W
另外,相關的具體規則可參考Oozie官網文檔
