java - 如何将 Jar 文件传递​​给 OOZIE shell 节点中的 shell 脚本

标签 java shell hadoop hdfs oozie

您好,我在 oozie shell 操作工作流中执行的脚本中运行 java 程序时出现以下错误。

Stdoutput 2015-08-25 03:36:02,636  INFO [pool-1-thread-1] (ProcessExecute.java:68) - Exception in thread "main" java.io.IOException: Error opening job jar: /tmp/jars/first.jar
Stdoutput 2015-08-25 03:36:02,636  INFO [pool-1-thread-1] (ProcessExecute.java:68) -    at org.apache.hadoop.util.RunJar.main(RunJar.java:124)
Stdoutput 2015-08-25 03:36:02,636  INFO [pool-1-thread-1] (ProcessExecute.java:68) - Caused by: java.io.FileNotFoundException: /tmp/jars/first.jar (No such file or directory)
Stdoutput 2015-08-25 03:36:02,636  INFO [pool-1-thread-1] (ProcessExecute.java:68) -    at java.util.zip.ZipFile.open(Native Method)
Stdoutput 2015-08-25 03:36:02,637  INFO [pool-1-thread-1] (ProcessExecute.java:68) -    at java.util.zip.ZipFile.<init>(ZipFile.java:215)
Stdoutput 2015-08-25 03:36:02,637  INFO [pool-1-thread-1] (ProcessExecute.java:68) -    at java.util.zip.ZipFile.<init>(ZipFile.java:145)
Stdoutput 2015-08-25 03:36:02,637  INFO [pool-1-thread-1] (ProcessExecute.java:68) -    at java.util.jar.JarFile.<init>(JarFile.java:154)
Stdoutput 2015-08-25 03:36:02,637  INFO [pool-1-thread-1] (ProcessExecute.java:68) -    at java.util.jar.JarFile.<init>(JarFile.java:91)
Stdoutput 2015-08-25 03:36:02,640  INFO [pool-1-thread-1] (ProcessExecute.java:68) -    at org.apache.hadoop.util.RunJar.main(RunJar.java:122)
Exit code of the Shell command 1

文件详情如下:

工作属性:

nameNode=maprfs:///
jobTracker=maprfs:///
queueName=nitin
EXEC=execution.jar
ozie.libpath=${nameNode}/user/oozie/share/lib
oozie.use.system.libpath=true

oozie.wf.application.path=maprfs:/dev/user/oozieTest

工作流.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<workflow-app name="test" xmlns="uri:oozie:workflow:0.4">
    <start to="first" />
    <action name="first">
        <shell xmlns="uri:oozie:shell-action:0.1">
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <configuration>
                <property>
                    <name>mapred.job.queue.name</name>
                    <value>${queueName}</value>
                </property>
                </configuration>
            <exec>script</exec>
        <argument>-type mine</argument>
        <argument>-cfg config.cfg</argument>
            <file>script</file>
            <file>${EXEC}#${EXEC}</file>
            <file>config.cfg</file>
            <file>first.jar#first.jar</file>
            <file>second.jar#second.jar</file>
        </shell>
        <ok to="end" />
        <error to="fail" />
    </action>
    <kill name="fail">
        <message>Workflow failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
    </kill>
    <end name="end" />
</workflow-app>

脚本:

#!/bin/bash
#get the user who executed the script
EXECUTING_USER="user1"

# get start time

NOW=$(date +"%T")

#get the host name

HOST="$HOSTNAME"

ARGUMENTSTRING="$@ -user user1 -startTime $NOW"
echo "Passing the following arguments : $ARGUMENTSTRING"

java -cp execution.jar com.hadoop.test.Main "$ARGUMENTSTRING"

exit $?

我正在从/tmp/jars 目录中获取我的 execution.jar 文件中的 first.jar,原因是该目录不会对 oozie 工作流用户产生任何权限问题。

任何方向/建议都会非常有帮助。

我的问题简而言之:

  • 我想在 oozie shell 操作节点中执行脚本。
  • 从 oozie shell 操作节点执行的脚本将运行 java 程序
  • 基于参数的 java 程序将运行 first.jar 或 second.jar

最佳答案

我建议您以某种方式将依赖项从 shell 脚本转移到 java 代码中,并使用 oozie java 操作节点运行它,这将简化流程以实现良好的扩展。

如果从 oozie shell 操作节点运行 Java jar 是您最后的选择,那么我们将很好地做到这一点,但据我所知它有点复杂。

主要关注的是,

  • 任何 Oozie 操作都不能引用本地文件系统上的内容 节点,这里只能引用HDFS上的内容
  • Java 二进制命令只能引用本地文件系统上的文件。

因此请按照以下步骤操作,这可能会帮助您协调您的期望。

  1. Place your Jar file on HDFS
  2. Pass the HDFS absolute path of the Jar as an argument to the shell script.
  3. From the shell script , copy the Jar from HDFS to local on the node , where the action is running, on a fixed location (may be /tmp as you preferred) using copyToLocal cmd.
  4. Invoke the Jar file using the Java command on that node
  5. On completion if any output produced by the Jar file to be conveyed to next action, then copy that output files from local to HDFS from the shell script using copyFromLocal.

关于java - 如何将 Jar 文件传递​​给 OOZIE shell 节点中的 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32202151/

相关文章:

java - 表示电话号码的正确方法是什么?

java - 从文件夹中检索图像,缩小它们,将它们保存到另一个文件夹中。如何? ( java )

java - 合并方法的内容

hadoop - 如何获取hadoop目录的绝对路径

hadoop - 如何将hbase表中的数据导入到hive表中?

java - 关闭/重新启动 TabHost 中的 Activity

linux - Shell:bash 3.2.57 到 4.3.41 在 read -t 选项中的区别?

linux - Bash 命令行参数通过 ssh 传递给 sed

shell - 如何在 KornShell (ksh) 中正确保存 IFS

file - 为什么在hadoop mapper生成的文件中生成tab space