简体   繁体   English

AWS EMR HadoopJarStepConfig 步骤 function arguments 不工作

[英]AWS EMR HadoopJarStepConfig step function arguments not working

I am working on adding step functions to AWS EMR which will add an extra line in "crontab -e".我正在努力向 AWS EMR 添加步骤函数,这将在“crontab -e”中添加额外的一行。 As I don't want to append directly to the crontab file as I might have duplicate cron jobs, I am fetching all the existing jobs, adding the new job and removing the duplicate like so:因为我不想 append 直接到 crontab 文件,因为我可能有重复的 cron 作业,所以我正在获取所有现有作业,添加新作业并删除重复作业,如下所示:

HadoopJarStepConfig turnOnCronJob1 = new HadoopJarStepConfig()
                .withJar("command-runner.jar")
                .withArgs("bash", "-c", "\"(crontab -l; echo '*/5 * * * * /mnt/" + scriptName + "')", "|", "sort -u", "|", "crontab -\"");

But, the function is failing with an exit code 1. I have ran this command directly on my EMR cluster as:但是,function 失败,退出代码为 1。我直接在我的 EMR 集群上运行了这个命令:

hadoop jar /var/lib/aws/emr/step-runner/hadoop-jars/command-runner.jar bash -c "(crontab -l; echo '*/5 * * * * /mnt/reademrpushmetrics.sh') | sort -u | crontab -"

And, this is working fine with no errors.而且,这工作正常,没有错误。 I have tried following HadoopJarStepConfig, but they are not working either:我试过遵循 HadoopJarStepConfig,但它们也不起作用:

HadoopJarStepConfig turnOnCronJob2 = new HadoopJarStepConfig()
                .withJar("command-runner.jar")
                .withArgs("(crontab -l; echo '*/5 * * * * /mnt/" + scriptName + "')", "|", "sort -u", "|", "crontab -");
HadoopJarStepConfig copyOldCronTabToNew1 = new HadoopJarStepConfig()
                .withJar("command-runner.jar")
                .withArgs("crontab -l", ">", "/mnt/newCronTab");
HadoopJarStepConfig copyOldCronTabToNew2 = new HadoopJarStepConfig()
                .withJar("command-runner.jar")
                .withArgs("crontab", "-l", ">", "/mnt/newCronTab");
HadoopJarStepConfig copyOldCronTabToNew3 = new HadoopJarStepConfig()
                .withJar("command-runner.jar")
                .withArgs("bash", "-c", "\"crontab -l > /mnt/newCronTab\"");

The last three code config file was an alternative method that I was trying by creating a new "newCronTab" file and storing my new crontab jobs before adding all of them to the "crontab -e".最后三个代码配置文件是我尝试创建一个新的“newCronTab”文件并存储我的新 crontab 作业的替代方法,然后再将它们全部添加到“crontab -e”。 The last config actually gives a different exitCode error 127, and not 1 like others as shown here:最后一个配置实际上给出了不同的 exitCode 错误 127,而不是 1,如下所示: 在此处输入图像描述 在此处输入图像描述 All of these command seems to work if I run them directly on EMR cluster with hadoop command.如果我使用 hadoop 命令直接在 EMR 集群上运行它们,所有这些命令似乎都有效。 I am 99% sure that the problem is in the arguments that I am passing with not escaping certain characters properly.我 99% 确定问题出在我传递的 arguments 中,但某些字符不正确 escaping 。 If anyone has encountered this, how did you fix it?如果有人遇到过这种情况,您是如何解决的? Thank you!谢谢!

The problem was that in the arguments of HadoopJarStepConfig , you are not supposed to add an extra double quotes.问题是在 HadoopJarStepConfig 的HadoopJarStepConfig中,您不应该添加额外的双引号。 So, the correct format for turnOnCronJob1 and copyOldCronTabToNew3 looks like:因此, turnOnCronJob1copyOldCronTabToNew3的正确格式如下所示:

HadoopJarStepConfig turnOnCronJob1 = new HadoopJarStepConfig()
                    .withJar("command-runner.jar")
                    .withArgs("bash", "-c", "(crontab -l; echo '*/5 * * * * /mnt/" + scriptName + "') | sort -u | crontab -");
HadoopJarStepConfig copyOldCronTabToNew3 = new HadoopJarStepConfig()
                    .withJar("command-runner.jar")
                    .withArgs("bash", "-c", "crontab -l > /mnt/newCronTab");

Also, things to note is that turnOnCronJob2 and copyOldCronTabToNew1 config arguments are invalid ways of passing arguments. But, copyOldCronTabToNew2 config arguments are correct.另外,需要注意的是, turnOnCronJob2copyOldCronTabToNew1 config arguments 是传递 arguments 的无效方式。但是, copyOldCronTabToNew2 config arguments 是正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM