如何在aws emr流集群中包含php所需的lib

4zcjmb1e  于 2021-05-30  发布在  Hadoop
关注(0)|答案(1)|浏览(323)

我创建了一个php项目,将json格式转换为avro格式。最初的项目需要php libs,我不知道如何添加到emr中。
这是emr接收到的stderr日志:

  1. PHP Warning: require_once(vendor/autoload.php): failed to open stream: No such file or directory in /mnt/var/lib/hadoop/tmp/nm-local-dir/usercache/hadoop/filecache/12/convert-json-to-avro.php on line 3
  2. PHP Fatal error: require_once(): Failed opening required 'vendor/autoload.php' (include_path='.:/usr/share/pear:/usr/share/php') in /mnt/var/lib/hadoop/tmp/nm-local- dir/usercache/hadoop/filecache/12/convert-json-to-avro.php on line 3
  3. log4j:WARN No appenders could be found for logger (amazon.emr.metrics.MetricsUtil).
  4. log4j:WARN Please initialize the log4j system properly.
  5. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

下面是Map器的主要代码:

  1. # !/usr/bin/php
  2. <?php
  3. require_once 'vendor/autoload.php';
  4. error_reporting(E_ALL);
  5. ini_set('display_errors', 1);
  6. $outputFile = __DIR__ . '/test_avro_out.avr';
  7. $avroJsonSchema = file_get_contents(__DIR__ . '/HttpRequestEvent.avsc');
  8. // Open $file_name for writing, using the given writer's schema
  9. $avroWriter = AvroDataIO::open_file($outputFile, 'w', $avroJsonSchema);
  10. $counter = 1;
  11. while (($buf = fgets(STDIN)) !== false) {
  12. try {
  13. //replace ,null: with ,"null": to prevent map keys which are not strings.
  14. $original = array("null:","userIp");
  15. $replaceWith = array("\"null\":", "userIP");
  16. $data = json_decode(str_replace($original, $replaceWith, $buf), true);
  17. //print_r($buf);
  18. if ($data === false || $data == null ) {
  19. throw new InvalidArgumentException("Unable to parse JSON line");
  20. }
  21. $mapped = map_request_event($data);
  22. var_dump($mapped);
  23. //$avroWriter->append($mapped);
  24. //echo json_encode($mapped), "\n";
  25. } catch (Exception $ex) {
  26. fprintf(STDERR, "Caught exception: %s\n", $ex->getMessage());
  27. fprintf(STDERR, "Line num: %s\n",$counter);
  28. fprintf(STDERR, "buf: %s\n", $buf);
  29. }
  30. $counter++;
  31. }
  32. $avroWriter->close();

注意我用的是 require_once 'vendor/autoload.php'; 这说明 autoload.php 在文件夹供应商下。
将供应商文件夹加载到emr集群的正确方法是什么(那里有所需的文件)?应该 require_once 路径改变?
谢谢。

odopli94

odopli941#

在这家伙的评论之后,我使用了一个bash脚本,类似于您可以在这里找到的脚本。
我改变了主意 require_once 'vendor/autoload.php' 代码中的行,以指向我放置文件的位置( /home/hadoop/contents 工作完美)。最后,我添加了一个emr引导自定义步骤,您可以在其中添加bash脚本,以便它可以在php流式处理步骤之前运行。

相关问题