| 1 |
lars |
1 |
<?php
|
|
|
2 |
/*
|
|
|
3 |
* Copyright 2010-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
|
4 |
*
|
|
|
5 |
* Licensed under the Apache License, Version 2.0 (the "License").
|
|
|
6 |
* You may not use this file except in compliance with the License.
|
|
|
7 |
* A copy of the License is located at
|
|
|
8 |
*
|
|
|
9 |
* http://aws.amazon.com/apache2.0
|
|
|
10 |
*
|
|
|
11 |
* or in the "license" file accompanying this file. This file is distributed
|
|
|
12 |
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
|
|
13 |
* express or implied. See the License for the specific language governing
|
|
|
14 |
* permissions and limitations under the License.
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
/*%******************************************************************************************%*/
|
|
|
19 |
// CLASS
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* Contains a set of pre-built Amazon EMR Hadoop Bootstrap Actions.
|
|
|
23 |
*
|
|
|
24 |
* @version 2011.05.03
|
|
|
25 |
* @license See the included NOTICE.md file for more information.
|
|
|
26 |
* @copyright See the included NOTICE.md file for more information.
|
|
|
27 |
* @link http://aws.amazon.com/php/ PHP Developer Center
|
|
|
28 |
* @link http://hadoop.apache.org Apache Hadoop
|
|
|
29 |
*/
|
|
|
30 |
class CFHadoopBootstrap extends CFHadoopBase
|
|
|
31 |
{
|
|
|
32 |
// Config file types
|
|
|
33 |
const CONFIG_SITE = 'S';
|
|
|
34 |
const CONFIG_DEFAULT = 'D';
|
|
|
35 |
const CONFIG_CORE = 'C';
|
|
|
36 |
const CONFIG_HDFS = 'H';
|
|
|
37 |
const CONFIG_MAPREDUCE = 'M';
|
|
|
38 |
|
|
|
39 |
// Daemon types
|
|
|
40 |
const DAEMON_NAME_NODE = 'namenode';
|
|
|
41 |
const DAEMON_DATA_NODE = 'datanode';
|
|
|
42 |
const DAEMON_JOB_TRACKER = 'jobtracker';
|
|
|
43 |
const DAEMON_TASK_TRACKER = 'tasktracker';
|
|
|
44 |
const DAEMON_CLIENT = 'client';
|
|
|
45 |
|
|
|
46 |
/**
|
|
|
47 |
* Create a new run-if bootstrap action which lets you conditionally run bootstrap actions.
|
|
|
48 |
*
|
|
|
49 |
* @param string $condition (Required) The condition to evaluate. If <code>true</code>, the bootstrap action executes.
|
|
|
50 |
* @param array $args (Optional) An indexed array of arguments to pass to the script.
|
|
|
51 |
* @return array A configuration set to be provided when running a job flow.
|
|
|
52 |
*/
|
|
|
53 |
public static function run_if($condition, $args = null)
|
|
|
54 |
{
|
|
|
55 |
if (!$args) $args = array();
|
|
|
56 |
$args = is_array($args) ? $args : array($args);
|
|
|
57 |
|
|
|
58 |
return self::script_runner('s3://us-east-1.elasticmapreduce/bootstrap-actions/run-if', $args);
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
/**
|
|
|
62 |
* Specify options to merge with Hadoop's default configuration.
|
|
|
63 |
*
|
|
|
64 |
* @param string $file (Required) The Hadoop configuration file to merge with. [Allowed values: <code>CFHadoopBootstrap::CONFIG_SITE</code>, <code>CFHadoopBootstrap::CONFIG_DEFAULT</code>, <code>CFHadoopBootstrap::CONFIG_CORE</code>, <code>CFHadoopBootstrap::CONFIG_HDFS</code>, <code>CFHadoopBootstrap::CONFIG_MAPREDUCE</code>]
|
|
|
65 |
* @param string|array $config (Required) This can either be an XML file in S3 (as <code>s3://bucket/path</code>), or an associative array of key-value pairs.
|
|
|
66 |
* @return array A configuration set to be provided when running a job flow.
|
|
|
67 |
*/
|
|
|
68 |
public static function configure($file, $config)
|
|
|
69 |
{
|
|
|
70 |
$args = array();
|
|
|
71 |
$file_arg = '-' . $file;
|
|
|
72 |
|
|
|
73 |
if (is_string($config))
|
|
|
74 |
{
|
|
|
75 |
$args[] = $file_arg;
|
|
|
76 |
$args[] = $config;
|
|
|
77 |
}
|
|
|
78 |
elseif (is_array($config))
|
|
|
79 |
{
|
|
|
80 |
foreach ($config as $key => $value)
|
|
|
81 |
{
|
|
|
82 |
$args[] = $file_arg;
|
|
|
83 |
$args[] = $key . '=' . $value;
|
|
|
84 |
}
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
return self::script_runner('s3://us-east-1.elasticmapreduce/bootstrap-actions/configure-hadoop', $args);
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
/**
|
|
|
91 |
* Create a new bootstrap action which lets you configure Hadoop's daemons. The options are written to
|
|
|
92 |
* the <code>hadoop-user-env.sh</code> file.
|
|
|
93 |
*
|
|
|
94 |
* @param string $daemon_type (Required) The Hadoop daemon to configure.
|
|
|
95 |
* @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
|
|
|
96 |
* <li><code>HeapSize</code> - <code>integer</code> - Optional - The requested heap size of the daemon, in megabytes.</li>
|
|
|
97 |
* <li><code>CLIOptions</code> - <code>string</code> - Optional - Additional Java command line arguments to pass to the daemon.</li>
|
|
|
98 |
* <li><code>Replace</code> - <code>boolean</code> - Optional - Whether or not the file should be replaced. A value of <code>true</code> will replace the existing configuration file. A value of <code>false</code> will append the options to the configuration file.</li></ul>
|
|
|
99 |
* @return array A configuration set to be provided when running a job flow.
|
|
|
100 |
*/
|
|
|
101 |
public static function daemon($daemon_type, $opt = null)
|
|
|
102 |
{
|
|
|
103 |
if (!$opt) $opt = array();
|
|
|
104 |
$args = array();
|
|
|
105 |
|
|
|
106 |
foreach ($opt as $key => $value)
|
|
|
107 |
{
|
|
|
108 |
switch ($key)
|
|
|
109 |
{
|
|
|
110 |
case 'HeapSize':
|
|
|
111 |
$args[] = '--' . $daemon_type . '-heap-size=' . $value;
|
|
|
112 |
break;
|
|
|
113 |
case 'CLIOptions':
|
|
|
114 |
$args[] = '--' . $daemon_type . '-opts="' . $value . '"';
|
|
|
115 |
break;
|
|
|
116 |
case 'Replace':
|
|
|
117 |
if ((is_string($value) && $value === 'true') || (is_bool($value) && $value === true))
|
|
|
118 |
{
|
|
|
119 |
$args[] = '--replace';
|
|
|
120 |
}
|
|
|
121 |
break;
|
|
|
122 |
}
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
return self::script_runner('s3://us-east-1.elasticmapreduce/bootstrap-actions/configure-daemons', $args);
|
|
|
126 |
}
|
|
|
127 |
}
|