如何 create/declare oozie 中的全局变量?

how to create/declare global variables in oozie?

我正在创建一个 oozie 工作流程,我需要在其中执行多个 shell 操作,但我面临的问题是,对于我的工作流程中的每个 shell 操作,我都必须声明一个环境变量意味着如果我有 10 个 shell 操作我需要声明 10 次,我的问题是:如果有任何方法我可以 declare/create 全局变量以避免重复的变量做同样的事情?

示例:

    jon.properties
    oozie.use.system.libpath=true
    security_enabled=False
    dryrun=False
    nameNode=hdfs://localhost:8020
    user_name=test
    jobTracker=localhost::8032

<workflow-app name="My_Workflow" xmlns="uri:oozie:workflow:0.5">
<start to="shell-a0a5"/>
<kill name="Kill">
    <message>Error [${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>
<action name="shell-a0a5">
    <shell xmlns="uri:oozie:shell-action:0.1">
        <job-tracker>${jobTracker}</job-tracker>
        <name-node>${nameNode}</name-node>
        <exec>script1.sh</exec>
        <file>/user/hive/script1.sh#script1.sh</file>
    </shell>
    <ok to="End"/>
    <error to="Kill"/>
</action>
<end name="End"/>

我的 script1.sh 需要一个名为 user_name 的参数,我已将其声明到 job.properties 中,但它在我的工作流程中不起作用 我缺少参数用户名

我想知道如何从全局配置文件向 shell 脚本发送参数

谢谢

我无法创建全局参数以便将值传递为:用户和密码,HADOOP_USER_NAME(在我的 ase 中)但我能够使用 shell 脚本解决它,所以在 shell 中,我为我的提案定义了以下参数:

export HADOOP_USER_NAME=admin;
connection=$(hdfs dfs -cat /user/connection.txt)

其中 connection.txt 包含连接字符串的所有信息 然后使用 sqoop 我在 shell 文件中以这种方式传递信息:

sqoop $connection --table test --target-dir /user/hive/warehouse/Jeff.db/test/ --m 1 --delete-target-dir

这样我就能够解决我的问题,我必须声明一些全局变量,但这些变量是使用 & 并行执行 sqoop 所必需的。

无法将全局参数传递给 shell 操作。 全局部分仅用于属性。有关详细信息,请参阅此问题的答案:

要在 shell 操作中传递 parameters/variables,您可以通过 shell 操作将这些值作为 arguments 传递(您仍然可以在您的 job.properties 文件中声明它们:

<action name="shell-<name>">
  <shell xmlns="uri:oozie:shell-action:0.3">
    <exec>script1.sh</exec>
    <argument>${user_name}</argument>
    <argument>${database}</argument>
    <argument>${etc}</argument>
    <file>/user/hive/script1.sh#script1.sh</file>
  </shell>
    <ok to="End"/>
    <error to="Kill"/>    
</action>

在您的 shell 脚本中,您可以这样调用这些变量:

#!/bin/bash -e
user_name=
database=
etc=
<your shell commands>

然后您可以在 shell 脚本中使用这些变量。您也可以只使用 $1、$2 等,但为了便于阅读,最好先命名您的参数。

为了防止向每个 shell 操作传递大量参数,您还可以向 shell 操作添加一个 config file,并使用所有这些参数,然后导入在您的实际 shell 脚本中文件:

<action name="shell-<name>">
  <shell xmlns="uri:oozie:shell-action:0.3">
    <exec>script1.sh</exec>
    <file>/user/hive/script1.sh#script1.sh</file>
    <file>/user/hive/CONFIG_FILE</file>
  </shell>
    <ok to="End"/>
    <error to="Kill"/>    
</action>

shell 脚本:

#!/bin/bash
. CONFIG_FILE

<your shell commands>