如何创建一个带有 EL 表达式的变量以用于 oozie 工作流的所有操作?

How to create a variable with EL expression to use in all the actions oozie workflow?

我想创建一个变量,该变量应可用于 Oozie 工作流中的所有操作。我尝试创建它,如下所示。但是 EL 表达式没有得到评估,导致变量 current_ts 值作为 EL 表达式本身。有人可以解释一下吗?

<workflow-app xmlns="uri:oozie:workflow:0.4" name="no-op-wf">
  <parameters>
    <property>
      <name>current_ts</name>
      <value>${replaceAll((replaceAll((replaceAll((timestamp()),"-","")),"T","_")),":","")}</value>
    </property>
  </parameters>
  <start to="test"/>
  <kill name="test">
    <!--message Just to show that this expression works if used here>Timestamp - [${replaceAll((replaceAll((replaceAll((timestamp()),"-","")),"T","_")),":","")}</message-->
    <message>Timestamp - ${current_ts}</message> <!-- this will print expression but not evaluate it -->
  </kill>
  <end name="end"/>
</workflow-app>

Parameterization of Workflows中提到:

EL expressions can be used in the configuration values of action and decision nodes. They can be used in XML attribute values and in XML element and attribute values.

它们不能用在 XML 元素和属性名称中。它们不能用在节点的名称中,也不能用在节点的过渡元素中。

但你可以在协调器中使用它

如果我在工作流中创建一个全局->配置->属性 并在 wf 的其他操作中引用它,那么 属性 中的 EL 表达式将不会被计算。

作为解决方法,我将 wf 包装为子 wf,并在父 wf 中创建了 global->configuation->属性,然后将其传递给 subwf。使用此变通方法,EL 表达式得到了评估。

家长 WF :

<workflow-app xmlns="uri:oozie:workflow:0.4" name="main-wf">
  <global>
    <configuration>
      <property>
        <name>run_ts</name>
        <value>${replaceAll((replaceAll((replaceAll((timestamp()),"-","")),"T","_")),":","")}</value>
      </property>
    </configuration>
  </global>

 <action name="tbl-subwf">
    <sub-workflow>
      <app-path>${AppPath}</app-path>
      <propagate-configuration/>
 </sub-workflow>
    <ok to="join-node"/>
    <error to="fail"/>
  </action>
 <kill name="fail">
    <message>Sub workflow failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
  </kill>
  <end name="end"/>
</workflow-app>