我正在尝试通过 oozie 执行 shell 脚本,但遇到了一些问题。
我有一个像这样的属性文件(import.properties):
startIndex=2000
chunkSize=2000
这个想法是,在每次执行中,startIndex 值都将根据块大小进行更新。所以如果我执行它,它应该有
startIndex=4000
chunkSize=2000
我已经单独测试了脚本,它工作正常。这是我的其他相关文件。
工作属性
nameNode=hdfs://192.168.56.101:8020
jobTracker=192.168.56.101:50300
wfeRoot=wfe
queueName=default
EXEC=script.sh
propertyLoc=import.properties
oozie.use.system.libpath=true
oozie.wf.application.path=${nameNode}/user/${user.name}/${wfeRoot}/coordinator
工作流.xml
<workflow-app xmlns='uri:oozie:workflow:0.2' name='shell-wf'>
<start to='shell1' />
<action name='shell1'>
<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>${EXEC}</exec>
<file>${EXEC}#${EXEC}</file>
<file>${propertyLoc}#${propertyLoc}</file>
</shell>
<ok to="end" />
<error to="fail" />
</action>
<kill name="fail">
<message>Script failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>
<end name='end' />
脚本.sh
#!/bin/sh
file=import.properties
. $file
SCRIPT=$(readlink -f $file)
SCRIPTPATH=$(dirname $SCRIPT)
echo $SCRIPTPATH
newStartIndex=`expr $chunkSize + $startIndex`
newStartIndexStr=startIndex=$newStartIndex
oldStartIndexStr=startIndex=$startIndex
chunkSizeStr=chunkSize=$chunkSize
sed -i "s|$oldStartIndexStr|$newStartIndexStr|g" $file
我将所有这些文件放在我的 HDFS 工作目录中:
[ambari_qa@sandbox coordinator]$ hadoop fs -lsr /user/ambari_qa/wfe/coordinator
-rw-rw-rw- 1 ambari_qa hdfs 32 2013-05-09 00:12 /user/ambari_qa/wfe/coordinator/import.properties
-rw-rw-rw- 1 ambari_qa hdfs 533 2013-05-09 01:19 /user/ambari_qa/wfe/coordinator/script.sh
-rw------- 1 ambari_qa hdfs 852 2013-05-09 00:50 /user/ambari_qa/wfe/coordinator/workflow.xml
我期望每次执行后都会更改 import.properties 文件。但我认为即使 oozie 工作成功,它也没有改变。出于调试目的,我在执行过程中打印了文件的位置,发现它复制到了另一个位置(从日志中):
>>> Invoking Shell command line now >>
Stdoutput /hadoop/mapred/taskTracker/ambari_qa/distcache/-5756672768810005023_889271025_125659265/192.168.56.101/user/ambari_qa/wfe/coordinator
Stdoutput startIndex=4000
Stdoutput startIndex=2000
Exit code of the Shell command 0
<<< Invocation of Shell command completed <<<
我需要做什么才能影响 HDFS 的工作目录?提前致谢。
更新:
根据 Chris 的建议更改脚本后,它变为(最后 3 行):
hadoop fs -rm hdfs://ip-10-0-0-92:8020/user/ambari_qa/wfe/shell-oozie/$file
sed -i "s|$oldStartIndexStr|$newStartIndexStr|g" $file
hadoop fs -put $file /user/ambari_qa/wfe/shell-oozie
但后来我开始面临许可问题。我给了那个文件和文件夹的写权限。
[ambari_qa@ip-10-0-0-91 shell-oozie]$ hadoop fs -ls /user/ambari_qa/wfe/shell-oozie
找到 3 项:
-rw-rw-rw- 3 ambari_qa hdfs 32 2013-05-10 16:55 /user/ambari_qa/wfe/shell-oozie/import.properties
-rw-rw-rw- 3 ambari_qa hdfs 540 2013-05-10 16:48 /user/ambari_qa/wfe/shell-oozie/script.sh
-rw-rw-rw- 3 ambari_qa hdfs 826 2013-05-10 15:29 /user/ambari_qa/wfe/shell-oozie/workflow.xml
这是错误日志:
rm: org.apache.hadoop.security.AccessControlException: Permission denied: user=mapred, access=EXECUTE, inode="ambari_qa":ambari_qa:hdfs:rwxrwx---
put: org.apache.hadoop.security.AccessControlException: Permission denied: user=mapred, access=EXECUTE, inode="ambari_qa":ambari_qa:hdfs:rwxrwx---
Failing Oozie Launcher, Main class [org.apache.oozie.action.hadoop.ShellMain], exit code [1]