2014-09-03 15 views
2

我已经创建了一个将JSON格式转换为AVRO格式的PHP项目。 原始项目需要PHP库,我不知道如何添加EMR。如何在AWS EMR流式集群中包含PHP所需的库

这是EMR收到stderr日志:

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 
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 
log4j:WARN No appenders could be found for logger (amazon.emr.metrics.MetricsUtil). 
log4j:WARN Please initialize the log4j system properly. 
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. 

这里是映射器的主要代码:我使用的规定,autoload.php是下require_once 'vendor/autoload.php';

#!/usr/bin/php 
<?php 
require_once 'vendor/autoload.php'; 

error_reporting(E_ALL); 
ini_set('display_errors', 1); 

$outputFile = __DIR__ . '/test_avro_out.avr'; 
$avroJsonSchema = file_get_contents(__DIR__ . '/HttpRequestEvent.avsc'); 
// Open $file_name for writing, using the given writer's schema 
$avroWriter = AvroDataIO::open_file($outputFile, 'w', $avroJsonSchema); 
$counter = 1; 
while (($buf = fgets(STDIN)) !== false) { 
    try { 
     //replace ,null: with ,"null": to prevent map keys which are not strings. 
     $original = array("null:","userIp"); 
     $replaceWith = array("\"null\":", "userIP"); 
     $data = json_decode(str_replace($original, $replaceWith, $buf), true); 
     //print_r($buf); 
     if ($data === false || $data == null) { 
      throw new InvalidArgumentException("Unable to parse JSON line"); 

     } 

     $mapped = map_request_event($data); 
     var_dump($mapped); 

     //$avroWriter->append($mapped); 

     //echo json_encode($mapped), "\n"; 
    } catch (Exception $ex) { 
     fprintf(STDERR, "Caught exception: %s\n", $ex->getMessage()); 
     fprintf(STDERR, "Line num: %s\n",$counter); 
     fprintf(STDERR, "buf: %s\n", $buf); 
    } 
    $counter++; 
} 
$avroWriter->close(); 

公告文件夹供应商。

什么是将供应商文件夹加载到EMR集群中的正确方法(那里有需要的文件)? require_once路径应该改变吗?

谢谢。

+1

您是否检查了可以在作业之前添加的引导操作(http://docs.aws.amazon.com/ElasticMapReduce/latest/DeveloperGuide/emr-plan-bootstrap.html#bootstrapCustom)? – Guy 2014-09-06 13:02:03

+0

谢谢盖伊!那就是诀窍。尝试了许多其他方法,但这一个工作。 – dudu1982 2014-09-08 08:42:29

回答

0

以下Guy的评论我已经使用了一个类似于你可以找到的bash脚本here

我已将代码中的require_once 'vendor/autoload.php'行更改为指向放置文件的位置。 (/home/hadoop/contents工作完美)。 最后,我添加了EMR引导自定义步骤,您可以在其中添加bash脚本,以便它可以在PHP流式传输步骤之前运行。

相关问题