【问题标题】:Python Oozie Shell Action Failing To Load FilePython Oozie Shell 操作无法加载文件
【发布时间】:2014-03-11 21:42:04
【问题描述】:

从前面的问题继续...

我有一个 Oozie 工作流,其中包含一个调用 Python 脚本的 shell 操作,该脚本失败并出现以下错误。

IOError: [Errno 13] Permission denied: '/home/test/myfile.txt'

所有 Python 脚本 (hello.py) 试图做的就是打开一个文件。此代码在 Hadoop 外部执行时可以正常工作。

if __name__ == '__main__':
    print ('Starting script')

    filein = '/home/test/myfile.txt'

    file = open(filein, 'r')

这是我的 Oozie 工作流程。

<workflow-app xmlns="uri:oozie:workflow:0.4" name="hello">
    <start to="shell-check-hour" />
    <action name="shell-check-hour">
        <shell xmlns="uri:oozie:shell-action:0.2">
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <configuration>
                <property>
                    <name>mapred.job.queue.name</name>
                    <value>${queueName}</value>
                </property>
            </configuration>
            <exec>hello.py</exec>
            <file>hdfs://localhost:8020/user/test/hello.py</file>
            <capture-output />
        </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>

如果我尝试给出文件所在位置的绝对路径,我会被拒绝。

filein = '/home/test/myfile.txt'

如果我只尝试文件名,我会得到文件未找到。我不明白这个,Python脚本和文件在同一个HDFS位置

filein = 'myfile.txt'

也许我需要修改我的 Oozie 脚本以将文件添加为参数?

【问题讨论】:

    标签: hadoop oozie


    【解决方案1】:

    事实证明,我需要对我的 Python 脚本进行轻微修改,以使其能够从 HDFS 打开文件。这是打开和读取文件的示例代码

    import subprocess
    
    ''''''
    
    cat = subprocess.Popen(["hadoop", "fs", "-cat", "/user/test/myfile.txt"], stdout=subprocess.PIPE)
        for line in cat.stdout:
            print line
    

    【讨论】:

    • 我知道这是旧的,但我想说感谢您回来并发布解决方案。效果很好!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-12
    • 1970-01-01
    相关资源
    最近更新 更多