Oozie 集成 Ssh

1) prepare ssh case
$ cd ~/work/oozie-5.2.1
$ tree oozie/apps/ssh

├── job.properties
├── mushishi.sh
└── workflow.xml

$ cat oozie/apps/ssh/mushishi.sh

#!/bin/sh

rm /tmp/mushishi_*.txt
echo "$1 $JAVA_HOME" > /tmp/mushishi_$$.txt
# env >> /tmp/mushishi_$$.txt
echo "Mushishi=$1"

$ cat oozie/apps/ssh/job.properties

nameNode=hdfs://localhost:9000
resourceManager=localhost:8032
queueName=default
oozieRoot=user/${user.name}/oozie

oozie.wf.application.path=${nameNode}/${oozieRoot}/apps/ssh

$ cat oozie/apps/ssh/workflow.xml

<workflow-app xmlns="uri:oozie:workflow:1.0" name="ssh-wf">
    <start to="ssh-node"/>
    <action name="ssh-node">
        <ssh xmlns="uri:oozie:ssh-action:0.1">
            <host>localhost</host>
            <command>~/work/oozie-5.2.1/oozie/apps/ssh/mushishi.sh</command>
            <args>"Ginko"</args>
            <capture-output/>
        </ssh>
        <ok to="check-output"/>
        <error to="fail"/>
    </action>
    <decision name="check-output">
        <switch>
            <case to="end">
                ${wf:actionData('ssh-node')['Mushishi'] eq 'Ginko'}
            </case>
            <default to="fail-output"/>
        </switch>
    </decision>
    <kill name="fail-output">
        <message>Incorrect output, expected [Ginko] but was [${wf:actionData('ssh-node')['Mushishi']}]</message>
    </kill>
    <kill name="fail">
        <message>SSH action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
    </kill>
    <end name="end"/>
</workflow-app>

2) test the script
## run locally
$ ~/work/oozie-5.2.1/oozie/apps/ssh/mushishi.sh anonymous
Mushishi=anonymous
$ cat /tmp/mushishi_*.txt
anonymous /Library/Java/JavaVirtualMachines/jdk1.8.0_321.jdk/Contents/Home
## run remotely
$ ssh localhost ~/work/oozie-5.2.1/oozie/apps/ssh/mushishi.sh anonymous
Mushishi=anonymous
$ cat /tmp/mushishi_*.txt
anonymous
## Note: environment variables are missing on remote

3) run by oozie
## Note: it doesn't need to upload to hdfs
## submit and run
$ bin/oozie job -config oozie/apps/ssh/job.properties -run
job: 0000000-220713195559163-oozie-sun_-W
## check result
$ bin/oozie job -info 0000000-220713195559163-oozie-sun_-W

Job ID : 0000000-220713195559163-oozie-sun_-W
------------------------------------------------------------------------------------------------------------------------------------
Workflow Name : ssh-wf
App Path      : hdfs://localhost:9000/user/sun_xo/oozie/apps/ssh
Status        : SUCCEEDED
Run           : 0
User          : sun_xo
Group         : -
Created       : 2022-07-13 12:37 GMT
Started       : 2022-07-13 12:37 GMT
Last Modified : 2022-07-13 12:37 GMT
Ended         : 2022-07-13 12:37 GMT
CoordAction ID: -

Actions
------------------------------------------------------------------------------------------------------------------------------------
ID                                                                            Status    Ext ID                 Ext Status Err Code  
------------------------------------------------------------------------------------------------------------------------------------
0000000-220713195559163-oozie-sun_-W@:start:                                  OK        -                      OK         -         
------------------------------------------------------------------------------------------------------------------------------------
0000000-220713195559163-oozie-sun_-W@ssh-node                                 OK        59990                  OK         -         
------------------------------------------------------------------------------------------------------------------------------------
0000000-220713195559163-oozie-sun_-W@check-output                             OK        -                      end        -         
------------------------------------------------------------------------------------------------------------------------------------
0000000-220713195559163-oozie-sun_-W@end                                      OK        -                      OK         -         
------------------------------------------------------------------------------------------------------------------------------------

$ cat /tmp/mushishi_*.txt                                 
Ginko

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值