使用 oozie 的 Python 子进程

标签 python shell hadoop oozie

我正在尝试在 python 脚本中使用 subprocess,我在 oozie shell 操作中调用该脚本。 子进程应该读取存储在 Hadoop HDFS 中的文件。

我在伪分布式模式下使用hadoop-1.2.1和oozie-3.3.2。

这是python脚本,名为connected_subprocess.py:

#!/usr/bin/python

import subprocess
import networkx as nx

liste=subprocess.check_output("hadoop fs -cat /user/root/output-data/calcul-proba/final.txt",shell=True).split('\n')
G=nx.DiGraph()
f=open("/home/rlk/liste_strongly_connected.txt","wb")
for item in liste:
    try:
        app1,app2=item.split('\t')
        G.add_edge(app1,app2)
    except:
        pass
liste_connected=nx.strongly_connected_components(G)
for item in liste_connected:
    if len(item)>1:
        f.write('{}\n'.format('\t'.join(item)))
f.close()

Oozie的workflow.xml中相应的shell操作如下:

 <action name="final">
        <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>connected_subprocess.py</exec>
            <file>connected_subprocess.py</file>
         </shell>
         <ok to="end" />
         <error to="kill" />
    </action>

当我运行 oozie 作业时,tasktracker 日志会读取这些错误:

Error: Could not find or load main class org.apache.hadoop.fs.FsShell
Traceback (most recent call last):
  File "./connected_subprocess.py", line 6, in <module>
    liste=subprocess.check_output("hadoop fs -cat /user/root/output-data/calcul-proba/final.txt",shell=True).split('\n')
  File "/usr/lib64/python2.7/subprocess.py", line 575, in check_output
    raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command 'hadoop fs -cat /user/root/output-data/calcul-proba/final.txt' returned non-zero exit status 1
Failing Oozie Launcher, Main class [org.apache.oozie.action.hadoop.ShellMain], exit code [1]

当 python 脚本嵌入到 oozie 操作中时,我似乎无法在 python 脚本中运行 shell 命令行,因为当我在交互式 shell 中运行 python 脚本时一切正常。

有什么办法可以绕过这个限制吗?

最佳答案

我想知道您的脚本是否无法访问 PATH 环境变量(通过 Oozie 执行时)并且在定位“hadoop”命令时遇到问题。您可以尝试修改 python 脚本的 subprocess.check_output 调用并将完整路径添加到 hadoop fs 命令吗?

关于使用 oozie 的 Python 子进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18588495/

相关文章:

hadoop - Cloudera Hive : Where to add json-serde-1. 3.7 jar文件

hadoop - 如何访问 S3 上的 aws 公共(public)数据集?

python - 删除大 CSV 文件的第一行?

python - 无法在 Windows 中使用 solr、haystack 和 django 创建索引文件

python - 使用corner.corner隐藏角图中的样本点

node.js - 使用带有 Fish shell 的调试 NPM 模块

java - 执行包含 java -jar Runtime.exec() 的 shell 脚本,它将使用哪个 java,操作系统级别还是应用程序级别

python - 为所有类方法打印 python 文档字符串

shell - 如何在接收端打开一个没有 SSHD 的 shell?

debugging - 为什么一个mapreduce作业的本地字节写值比其他大?