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

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

我创建了一个php项目,将json格式转换为avro格式。最初的项目需要php libs,我不知道如何添加到emr中。
这是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.

下面是Map器的主要代码:


# !/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();

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

odopli94

odopli941#

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

相关问题