Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
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
 * This is the <em>Amazon Elastic MapReduce API Reference</em>. This guide provides descriptions
19
 * and samples of the Amazon Elastic MapReduce APIs.
20
 *
21
 * Amazon Elastic MapReduce is a web service that makes it easy to process large amounts of data
22
 * efficiently. Elastic MapReduce uses Hadoop processing combined with several AWS products to do
23
 * tasks such as web indexing, data mining, log file analysis, machine learning, scientific
24
 * simulation, and data warehousing.
25
 *
26
 * @version 2012.01.16
27
 * @license See the included NOTICE.md file for complete information.
28
 * @copyright See the included NOTICE.md file for complete information.
29
 * @link http://aws.amazon.com/elasticmapreduce/ Amazon Elastic MapReduce
30
 * @link http://aws.amazon.com/elasticmapreduce/documentation/ Amazon Elastic MapReduce documentation
31
 */
32
class AmazonEMR extends CFRuntime
33
{
34
	/*%******************************************************************************************%*/
35
	// CLASS CONSTANTS
36
 
37
	/**
38
	 * Specify the queue URL for the United States East (Northern Virginia) Region.
39
	 */
40
	const REGION_US_E1 = 'elasticmapreduce.us-east-1.amazonaws.com';
41
 
42
	/**
43
	 * Specify the queue URL for the United States East (Northern Virginia) Region.
44
	 */
45
	const REGION_VIRGINIA = self::REGION_US_E1;
46
 
47
	/**
48
	 * Specify the queue URL for the United States West (Northern California) Region.
49
	 */
50
	const REGION_US_W1 = 'elasticmapreduce.us-west-1.amazonaws.com';
51
 
52
	/**
53
	 * Specify the queue URL for the United States West (Northern California) Region.
54
	 */
55
	const REGION_CALIFORNIA = self::REGION_US_W1;
56
 
57
	/**
58
	 * Specify the queue URL for the United States West (Oregon) Region.
59
	 */
60
	const REGION_US_W2 = 'elasticmapreduce.us-west-2.amazonaws.com';
61
 
62
	/**
63
	 * Specify the queue URL for the United States West (Oregon) Region.
64
	 */
65
	const REGION_OREGON = self::REGION_US_W2;
66
 
67
	/**
68
	 * Specify the queue URL for the Europe West (Ireland) Region.
69
	 */
70
	const REGION_EU_W1 = 'elasticmapreduce.eu-west-1.amazonaws.com';
71
 
72
	/**
73
	 * Specify the queue URL for the Europe West (Ireland) Region.
74
	 */
75
	const REGION_IRELAND = self::REGION_EU_W1;
76
 
77
	/**
78
	 * Specify the queue URL for the Asia Pacific Southeast (Singapore) Region.
79
	 */
80
	const REGION_APAC_SE1 = 'elasticmapreduce.ap-southeast-1.amazonaws.com';
81
 
82
	/**
83
	 * Specify the queue URL for the Asia Pacific Southeast (Singapore) Region.
84
	 */
85
	const REGION_SINGAPORE = self::REGION_APAC_SE1;
86
 
87
	/**
88
	 * Specify the queue URL for the Asia Pacific Northeast (Tokyo) Region.
89
	 */
90
	const REGION_APAC_NE1 = 'elasticmapreduce.ap-northeast-1.amazonaws.com';
91
 
92
	/**
93
	 * Specify the queue URL for the Asia Pacific Northeast (Tokyo) Region.
94
	 */
95
	const REGION_TOKYO = self::REGION_APAC_NE1;
96
 
97
	/**
98
	 * Specify the queue URL for the South America (Sao Paulo) Region.
99
	 */
100
	const REGION_SA_E1 = 'elasticmapreduce.sa-east-1.amazonaws.com';
101
 
102
	/**
103
	 * Specify the queue URL for the South America (Sao Paulo) Region.
104
	 */
105
	const REGION_SAO_PAULO = self::REGION_SA_E1;
106
 
107
	/**
108
	 * Default service endpoint.
109
	 */
110
	const DEFAULT_URL = self::REGION_US_E1;
111
 
112
 
113
	/*%******************************************************************************************%*/
114
	// CONSTRUCTOR
115
 
116
	/**
117
	 * Constructs a new instance of <AmazonEMR>.
118
	 *
119
	 * @param array $options (Optional) An associative array of parameters that can have the following keys: <ul>
120
	 * 	<li><code>certificate_authority</code> - <code>boolean</code> - Optional - Determines which Cerificate Authority file to use. A value of boolean <code>false</code> will use the Certificate Authority file available on the system. A value of boolean <code>true</code> will use the Certificate Authority provided by the SDK. Passing a file system path to a Certificate Authority file (chmodded to <code>0755</code>) will use that. Leave this set to <code>false</code> if you're not sure.</li>
121
	 * 	<li><code>credentials</code> - <code>string</code> - Optional - The name of the credential set to use for authentication.</li>
122
	 * 	<li><code>default_cache_config</code> - <code>string</code> - Optional - This option allows a preferred storage type to be configured for long-term caching. This can be changed later using the <set_cache_config()> method. Valid values are: <code>apc</code>, <code>xcache</code>, or a file system path such as <code>./cache</code> or <code>/tmp/cache/</code>.</li>
123
	 * 	<li><code>key</code> - <code>string</code> - Optional - Your AWS key, or a session key. If blank, the default credential set will be used.</li>
124
	 * 	<li><code>secret</code> - <code>string</code> - Optional - Your AWS secret key, or a session secret key. If blank, the default credential set will be used.</li>
125
	 * 	<li><code>token</code> - <code>string</code> - Optional - An AWS session token.</li></ul>
126
	 * @return void
127
	 */
128
	public function __construct(array $options = array())
129
	{
130
		$this->api_version = '2009-03-31';
131
		$this->hostname = self::DEFAULT_URL;
132
		$this->auth_class = 'AuthV2Query';
133
 
134
		return parent::__construct($options);
135
	}
136
 
137
 
138
	/*%******************************************************************************************%*/
139
	// SETTERS
140
 
141
	/**
142
	 * This allows you to explicitly sets the region for the service to use.
143
	 *
144
	 * @param string $region (Required) The region to explicitly set. Available options are <REGION_US_E1>, <REGION_US_W1>, <REGION_US_W2>, <REGION_EU_W1>, <REGION_APAC_SE1>, <REGION_APAC_NE1>, <REGION_SA_E1>.
145
	 * @return $this A reference to the current instance.
146
	 */
147
	public function set_region($region)
148
	{
149
		// @codeCoverageIgnoreStart
150
		$this->set_hostname($region);
151
		return $this;
152
		// @codeCoverageIgnoreEnd
153
	}
154
 
155
 
156
	/*%******************************************************************************************%*/
157
	// SERVICE METHODS
158
 
159
	/**
160
	 * AddInstanceGroups adds an instance group to a running cluster.
161
	 *
162
	 * @param array $instance_groups (Required) Instance Groups to add. <ul>
163
	 * 	<li><code>x</code> - <code>array</code> - Optional - This represents a simple array index. <ul>
164
	 * 		<li><code>Name</code> - <code>string</code> - Optional - Friendly name given to the instance group. [Constraints: The value must be between 0 and 256 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]</li>
165
	 * 		<li><code>Market</code> - <code>string</code> - Optional - Market type of the Amazon EC2 instances used to create a cluster node. [Allowed values: <code>ON_DEMAND</code>, <code>SPOT</code>]</li>
166
	 * 		<li><code>InstanceRole</code> - <code>string</code> - Required - The role of the instance group in the cluster. [Allowed values: <code>MASTER</code>, <code>CORE</code>, <code>TASK</code>]</li>
167
	 * 		<li><code>BidPrice</code> - <code>string</code> - Optional - Bid price for each Amazon EC2 instance in the instance group when launching nodes as Spot Instances, expressed in USD. [Constraints: The value must be between 0 and 256 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]</li>
168
	 * 		<li><code>InstanceType</code> - <code>string</code> - Required - The Amazon EC2 instance type for all instances in the instance group. [Constraints: The value must be between 1 and 256 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]</li>
169
	 * 		<li><code>InstanceCount</code> - <code>integer</code> - Required - Target number of instances for the instance group.</li>
170
	 * 	</ul></li>
171
	 * </ul>
172
	 * @param string $job_flow_id (Required) Job flow in which to add the instance groups. [Constraints: The value must be between 0 and 256 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]
173
	 * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
174
	 * 	<li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
175
	 * 	<li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul>
176
	 * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
177
	 */
178
	public function add_instance_groups($instance_groups, $job_flow_id, $opt = null)
179
	{
180
		if (!$opt) $opt = array();
181
		$opt['JobFlowId'] = $job_flow_id;
182
 
183
		// Required list + map
184
		$opt = array_merge($opt, CFComplexType::map(array(
185
			'InstanceGroups' => (is_array($instance_groups) ? $instance_groups : array($instance_groups))
186
		), 'member'));
187
 
188
		return $this->authenticate('AddInstanceGroups', $opt);
189
	}
190
 
191
	/**
192
	 * AddJobFlowSteps adds new steps to a running job flow. A maximum of 256 steps are allowed in
193
	 * each job flow.
194
	 *
195
	 * If your job flow is long-running (such as a Hive data warehouse) or complex, you may require
196
	 * more than 256 steps to process your data. You can bypass the 256-step limitation in various
197
	 * ways, including using the SSH shell to connect to the master node and submitting queries
198
	 * directly to the software running on the master node, such as Hive and Hadoop. For more
199
	 * information on how to do this, go to <a href=
200
	 * "http://docs.amazonwebservices.com/ElasticMapReduce/latest/DeveloperGuide/AddMoreThan256Steps.html">
201
	 * Add More than 256 Steps to a Job Flow</a> in the <em>Amazon Elastic MapReduce Developer's
202
	 * Guide</em>.
203
	 *
204
	 * A step specifies the location of a JAR file stored either on the master node of the job flow or
205
	 * in Amazon S3. Each step is performed by the main function of the main class of the JAR file.
206
	 * The main class can be specified either in the manifest of the JAR or by using the MainFunction
207
	 * parameter of the step.
208
	 *
209
	 * Elastic MapReduce executes each step in the order listed. For a step to be considered complete,
210
	 * the main function must exit with a zero exit code and all Hadoop jobs started while the step
211
	 * was running must have completed and run successfully.
212
	 *
213
	 * You can only add steps to a job flow that is in one of the following states: STARTING,
214
	 * BOOTSTRAPPING, RUNNING, or WAITING.
215
	 *
216
	 * @param string $job_flow_id (Required) A string that uniquely identifies the job flow. This identifier is returned by <code>RunJobFlow</code> and can also be obtained from <code>DescribeJobFlows</code>. [Constraints: The value must be between 0 and 256 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]
217
	 * @param array $steps (Required) A list of <code>StepConfig</code> to be executed by the job flow. <ul>
218
	 * 	<li><code>x</code> - <code>array</code> - Optional - This represents a simple array index. <ul>
219
	 * 		<li><code>Name</code> - <code>string</code> - Required - The name of the job flow step. [Constraints: The value must be between 0 and 256 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]</li>
220
	 * 		<li><code>ActionOnFailure</code> - <code>string</code> - Optional - Specifies the action to take if the job flow step fails. [Allowed values: <code>TERMINATE_JOB_FLOW</code>, <code>CANCEL_AND_WAIT</code>, <code>CONTINUE</code>]</li>
221
	 * 		<li><code>HadoopJarStep</code> - <code>array</code> - Required - Specifies the JAR file used for the job flow step. <ul>
222
	 * 			<li><code>x</code> - <code>array</code> - Optional - This represents a simple array index. <ul>
223
	 * 				<li><code>Properties</code> - <code>array</code> - Optional - A list of Java properties that are set when the step runs. You can use these properties to pass key value pairs to your main function. <ul>
224
	 * 					<li><code>x</code> - <code>array</code> - Optional - This represents a simple array index. <ul>
225
	 * 						<li><code>Key</code> - <code>string</code> - Optional - The unique identifier of a key value pair. [Constraints: The value must be between 0 and 10280 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]</li>
226
	 * 						<li><code>Value</code> - <code>string</code> - Optional - The value part of the identified key. [Constraints: The value must be between 0 and 10280 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]</li>
227
	 * 					</ul></li>
228
	 * 				</ul></li>
229
	 * 				<li><code>Jar</code> - <code>string</code> - Required - A path to a JAR file run during the step. [Constraints: The value must be between 0 and 10280 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]</li>
230
	 * 				<li><code>MainClass</code> - <code>string</code> - Optional - The name of the main class in the specified Java file. If not specified, the JAR file should specify a Main-Class in its manifest file. [Constraints: The value must be between 0 and 10280 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]</li>
231
	 * 				<li><code>Args</code> - <code>string|array</code> - Optional - A list of command line arguments passed to the JAR file's main function when executed. Pass a string for a single value, or an indexed array for multiple values.</li>
232
	 * 			</ul></li>
233
	 * 		</ul></li>
234
	 * 	</ul></li>
235
	 * </ul>
236
	 * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
237
	 * 	<li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
238
	 * 	<li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul>
239
	 * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
240
	 */
241
	public function add_job_flow_steps($job_flow_id, $steps, $opt = null)
242
	{
243
		if (!$opt) $opt = array();
244
		$opt['JobFlowId'] = $job_flow_id;
245
 
246
		// Required list + map
247
		$opt = array_merge($opt, CFComplexType::map(array(
248
			'Steps' => (is_array($steps) ? $steps : array($steps))
249
		), 'member'));
250
 
251
		return $this->authenticate('AddJobFlowSteps', $opt);
252
	}
253
 
254
	/**
255
	 * DescribeJobFlows returns a list of job flows that match all of the supplied parameters. The
256
	 * parameters can include a list of job flow IDs, job flow states, and restrictions on job flow
257
	 * creation date and time.
258
	 *
259
	 * Regardless of supplied parameters, only job flows created within the last two months are
260
	 * returned.
261
	 *
262
	 * If no parameters are supplied, then job flows matching either of the following criteria are
263
	 * returned:
264
	 *
265
	 * <ul>
266
	 * 	<li>Job flows created and completed in the last two weeks</li>
267
	 * 	<li>Job flows created within the last two months that are in one of the following states:
268
	 * <code>RUNNING</code>, <code>WAITING</code>, <code>SHUTTING_DOWN</code>, <code>STARTING</code></li>
269
	 * </ul>
270
	 *
271
	 * Amazon Elastic MapReduce can return a maximum of 512 job flow descriptions.
272
	 *
273
	 * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
274
	 * 	<li><code>CreatedAfter</code> - <code>string</code> - Optional - Return only job flows created after this date and time. May be passed as a number of seconds since UNIX Epoch, or any string compatible with <php:strtotime()>.</li>
275
	 * 	<li><code>CreatedBefore</code> - <code>string</code> - Optional - Return only job flows created before this date and time. May be passed as a number of seconds since UNIX Epoch, or any string compatible with <php:strtotime()>.</li>
276
	 * 	<li><code>JobFlowIds</code> - <code>string|array</code> - Optional - Return only job flows whose job flow ID is contained in this list. Pass a string for a single value, or an indexed array for multiple values.</li>
277
	 * 	<li><code>JobFlowStates</code> - <code>string|array</code> - Optional - Return only job flows whose state is contained in this list. Pass a string for a single value, or an indexed array for multiple values.</li>
278
	 * 	<li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
279
	 * 	<li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul>
280
	 * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
281
	 */
282
	public function describe_job_flows($opt = null)
283
	{
284
		if (!$opt) $opt = array();
285
 
286
		// Optional DateTime
287
		if (isset($opt['CreatedAfter']))
288
		{
289
			$opt['CreatedAfter'] = $this->util->convert_date_to_iso8601($opt['CreatedAfter']);
290
		}
291
 
292
		// Optional DateTime
293
		if (isset($opt['CreatedBefore']))
294
		{
295
			$opt['CreatedBefore'] = $this->util->convert_date_to_iso8601($opt['CreatedBefore']);
296
		}
297
 
298
		// Optional list (non-map)
299
		if (isset($opt['JobFlowIds']))
300
		{
301
			$opt = array_merge($opt, CFComplexType::map(array(
302
				'JobFlowIds' => (is_array($opt['JobFlowIds']) ? $opt['JobFlowIds'] : array($opt['JobFlowIds']))
303
			), 'member'));
304
			unset($opt['JobFlowIds']);
305
		}
306
 
307
		// Optional list (non-map)
308
		if (isset($opt['JobFlowStates']))
309
		{
310
			$opt = array_merge($opt, CFComplexType::map(array(
311
				'JobFlowStates' => (is_array($opt['JobFlowStates']) ? $opt['JobFlowStates'] : array($opt['JobFlowStates']))
312
			), 'member'));
313
			unset($opt['JobFlowStates']);
314
		}
315
 
316
		return $this->authenticate('DescribeJobFlows', $opt);
317
	}
318
 
319
	/**
320
	 * ModifyInstanceGroups modifies the number of nodes and configuration settings of an instance
321
	 * group. The input parameters include the new target instance count for the group and the
322
	 * instance group ID. The call will either succeed or fail atomically.
323
	 *
324
	 * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
325
	 * 	<li><code>InstanceGroups</code> - <code>array</code> - Optional - Instance groups to change. <ul>
326
	 * 		<li><code>x</code> - <code>array</code> - Optional - This represents a simple array index. <ul>
327
	 * 			<li><code>InstanceGroupId</code> - <code>string</code> - Required - Unique ID of the instance group to expand or shrink. [Constraints: The value must be between 0 and 256 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]</li>
328
	 * 			<li><code>InstanceCount</code> - <code>integer</code> - Required - Target size for the instance group.</li>
329
	 * 		</ul></li>
330
	 * 	</ul></li>
331
	 * 	<li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
332
	 * 	<li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul>
333
	 * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
334
	 */
335
	public function modify_instance_groups($opt = null)
336
	{
337
		if (!$opt) $opt = array();
338
 
339
		// Optional list + map
340
		if (isset($opt['InstanceGroups']))
341
		{
342
			$opt = array_merge($opt, CFComplexType::map(array(
343
				'InstanceGroups' => $opt['InstanceGroups']
344
			), 'member'));
345
			unset($opt['InstanceGroups']);
346
		}
347
 
348
		return $this->authenticate('ModifyInstanceGroups', $opt);
349
	}
350
 
351
	/**
352
	 * RunJobFlow creates and starts running a new job flow. The job flow will run the steps
353
	 * specified. Once the job flow completes, the cluster is stopped and the HDFS partition is lost.
354
	 * To prevent loss of data, configure the last step of the job flow to store results in Amazon S3.
355
	 * If the <code>JobFlowInstancesConfig</code> <code>KeepJobFlowAliveWhenNoSteps</code> parameter
356
	 * is set to <code>TRUE</code>, the job flow will transition to the WAITING state rather than
357
	 * shutting down once the steps have completed.
358
	 *
359
	 * For additional protection, you can set the <code>JobFlowInstancesConfig</code>
360
	 * <code>TerminationProtected</code> parameter to <code>TRUE</code> to lock the job flow and
361
	 * prevent it from being terminated by API call, user intervention, or in the event of a job flow
362
	 * error.
363
	 *
364
	 * A maximum of 256 steps are allowed in each job flow.
365
	 *
366
	 * If your job flow is long-running (such as a Hive data warehouse) or complex, you may require
367
	 * more than 256 steps to process your data. You can bypass the 256-step limitation in various
368
	 * ways, including using the SSH shell to connect to the master node and submitting queries
369
	 * directly to the software running on the master node, such as Hive and Hadoop. For more
370
	 * information on how to do this, go to <a href=
371
	 * "http://docs.amazonwebservices.com/ElasticMapReduce/latest/DeveloperGuide/AddMoreThan256Steps.html">
372
	 * Add More than 256 Steps to a Job Flow</a> in the <em>Amazon Elastic MapReduce Developer's
373
	 * Guide</em>.
374
	 *
375
	 * For long running job flows, we recommend that you periodically store your results.
376
	 *
377
	 * @param string $name (Required) The name of the job flow. [Constraints: The value must be between 0 and 256 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]
378
	 * @param array $instances (Required) A specification of the number and type of Amazon EC2 instances on which to run the job flow. <ul>
379
	 * 	<li><code>x</code> - <code>array</code> - Optional - This represents a simple array index. <ul>
380
	 * 		<li><code>MasterInstanceType</code> - <code>string</code> - Optional - The EC2 instance type of the master node. [Constraints: The value must be between 1 and 256 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]</li>
381
	 * 		<li><code>SlaveInstanceType</code> - <code>string</code> - Optional - The EC2 instance type of the slave nodes. [Constraints: The value must be between 1 and 256 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]</li>
382
	 * 		<li><code>InstanceCount</code> - <code>integer</code> - Optional - The number of Amazon EC2 instances used to execute the job flow.</li>
383
	 * 		<li><code>InstanceGroups</code> - <code>array</code> - Optional - Configuration for the job flow's instance groups. <ul>
384
	 * 			<li><code>x</code> - <code>array</code> - Optional - This represents a simple array index. <ul>
385
	 * 				<li><code>Name</code> - <code>string</code> - Optional - Friendly name given to the instance group. [Constraints: The value must be between 0 and 256 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]</li>
386
	 * 				<li><code>Market</code> - <code>string</code> - Optional - Market type of the Amazon EC2 instances used to create a cluster node. [Allowed values: <code>ON_DEMAND</code>, <code>SPOT</code>]</li>
387
	 * 				<li><code>InstanceRole</code> - <code>string</code> - Required - The role of the instance group in the cluster. [Allowed values: <code>MASTER</code>, <code>CORE</code>, <code>TASK</code>]</li>
388
	 * 				<li><code>BidPrice</code> - <code>string</code> - Optional - Bid price for each Amazon EC2 instance in the instance group when launching nodes as Spot Instances, expressed in USD. [Constraints: The value must be between 0 and 256 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]</li>
389
	 * 				<li><code>InstanceType</code> - <code>string</code> - Required - The Amazon EC2 instance type for all instances in the instance group. [Constraints: The value must be between 1 and 256 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]</li>
390
	 * 				<li><code>InstanceCount</code> - <code>integer</code> - Required - Target number of instances for the instance group.</li>
391
	 * 			</ul></li>
392
	 * 		</ul></li>
393
	 * 		<li><code>Ec2KeyName</code> - <code>string</code> - Optional - Specifies the name of the Amazon EC2 key pair that can be used to ssh to the master node as the user called "hadoop." [Constraints: The value must be between 0 and 256 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]</li>
394
	 * 		<li><code>Placement</code> - <code>array</code> - Optional - Specifies the Availability Zone the job flow will run in. <ul>
395
	 * 			<li><code>x</code> - <code>array</code> - Optional - This represents a simple array index. <ul>
396
	 * 				<li><code>AvailabilityZone</code> - <code>string</code> - Required - The Amazon EC2 Availability Zone for the job flow. [Constraints: The value must be between 0 and 10280 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]</li>
397
	 * 			</ul></li>
398
	 * 		</ul></li>
399
	 * 		<li><code>KeepJobFlowAliveWhenNoSteps</code> - <code>boolean</code> - Optional - Specifies whether the job flow should terminate after completing all steps.</li>
400
	 * 		<li><code>TerminationProtected</code> - <code>boolean</code> - Optional - Specifies whether to lock the job flow to prevent the Amazon EC2 instances from being terminated by API call, user intervention, or in the event of a job flow error.</li>
401
	 * 		<li><code>HadoopVersion</code> - <code>string</code> - Optional - Specifies the Hadoop version for the job flow. Valid inputs are "0.18", "0.20", or "0.20.205". If you do not set this value, the default of 0.18 is used, unless the AmiVersion parameter is set in the RunJobFlow call, in which case the default version of Hadoop for that AMI version is used. [Constraints: The value must be between 0 and 256 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]</li>
402
	 * 		<li><code>Ec2SubnetId</code> - <code>string</code> - Optional - To launch the job flow in Amazon Virtual Private Cloud (Amazon VPC), set this parameter to the identifier of the Amazon VPC subnet where you want the job flow to launch. If you do not specify this value, the job flow is launched in the normal Amazon Web Services cloud, outside of an Amazon VPC. Amazon VPC currently does not support cluster compute quadruple extra large (cc1.4xlarge) instances. Thus you cannot specify the cc1.4xlarge instance type for nodes of a job flow launched in a Amazon VPC. [Constraints: The value must be between 0 and 256 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]</li>
403
	 * 	</ul></li>
404
	 * </ul>
405
	 * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
406
	 * 	<li><code>LogUri</code> - <code>string</code> - Optional - Specifies the location in Amazon S3 to write the log files of the job flow. If a value is not provided, logs are not created. [Constraints: The value must be between 0 and 10280 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]</li>
407
	 * 	<li><code>AdditionalInfo</code> - <code>string</code> - Optional - A JSON string for selecting additional features. [Constraints: The value must be between 0 and 10280 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]</li>
408
	 * 	<li><code>AmiVersion</code> - <code>string</code> - Optional - The version of the Amazon Machine Image (AMI) to use when launching Amazon EC2 instances in the job flow. The following values ane valid:<ul><li>"latest" (latest AMI version; currently AMI 2.0, Hadoop 0.20.205)</li><li>"2.0" (AMI 2.0, Hadoop 0.20.205)</li><li>"1.0" (AMI 1.0, Hadoop 0.18)</li></ul>If this value is not specified, the job flow uses the default of (AMI 1.0, Hadoop 0.18). If the AMI supports multiple versions of Hadoop (for example, AMI 1.0 supports both Hadoop 0.18 and 0.20) you can use the <code>JobFlowInstancesConfig</code> <code>HadoopVersion</code> parameter to modify the version of Hadoop from the defaults shown above. For details about the AMI versions currently supported by Amazon ElasticMapReduce, go to <a href="http://docs.amazonwebservices.com/ElasticMapReduce/latest/DeveloperGuide/EnvironmentConfig_AMIVersion.html#ami-versions-supported">AMI Versions Supported in Elastic MapReduce</a> in the <em>Amazon Elastic MapReduce Developer's Guide.</em> [Constraints: The value must be between 0 and 256 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]</li>
409
	 * 	<li><code>Steps</code> - <code>array</code> - Optional - A list of steps to be executed by the job flow. <ul>
410
	 * 		<li><code>x</code> - <code>array</code> - Optional - This represents a simple array index. <ul>
411
	 * 			<li><code>Name</code> - <code>string</code> - Required - The name of the job flow step. [Constraints: The value must be between 0 and 256 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]</li>
412
	 * 			<li><code>ActionOnFailure</code> - <code>string</code> - Optional - Specifies the action to take if the job flow step fails. [Allowed values: <code>TERMINATE_JOB_FLOW</code>, <code>CANCEL_AND_WAIT</code>, <code>CONTINUE</code>]</li>
413
	 * 			<li><code>HadoopJarStep</code> - <code>array</code> - Required - Specifies the JAR file used for the job flow step. <ul>
414
	 * 				<li><code>x</code> - <code>array</code> - Optional - This represents a simple array index. <ul>
415
	 * 					<li><code>Properties</code> - <code>array</code> - Optional - A list of Java properties that are set when the step runs. You can use these properties to pass key value pairs to your main function. <ul>
416
	 * 						<li><code>x</code> - <code>array</code> - Optional - This represents a simple array index. <ul>
417
	 * 							<li><code>Key</code> - <code>string</code> - Optional - The unique identifier of a key value pair. [Constraints: The value must be between 0 and 10280 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]</li>
418
	 * 							<li><code>Value</code> - <code>string</code> - Optional - The value part of the identified key. [Constraints: The value must be between 0 and 10280 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]</li>
419
	 * 						</ul></li>
420
	 * 					</ul></li>
421
	 * 					<li><code>Jar</code> - <code>string</code> - Required - A path to a JAR file run during the step. [Constraints: The value must be between 0 and 10280 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]</li>
422
	 * 					<li><code>MainClass</code> - <code>string</code> - Optional - The name of the main class in the specified Java file. If not specified, the JAR file should specify a Main-Class in its manifest file. [Constraints: The value must be between 0 and 10280 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]</li>
423
	 * 					<li><code>Args</code> - <code>string|array</code> - Optional - A list of command line arguments passed to the JAR file's main function when executed. Pass a string for a single value, or an indexed array for multiple values.</li>
424
	 * 				</ul></li>
425
	 * 			</ul></li>
426
	 * 		</ul></li>
427
	 * 	</ul></li>
428
	 * 	<li><code>BootstrapActions</code> - <code>array</code> - Optional - A list of bootstrap actions that will be run before Hadoop is started on the cluster nodes. <ul>
429
	 * 		<li><code>x</code> - <code>array</code> - Optional - This represents a simple array index. <ul>
430
	 * 			<li><code>Name</code> - <code>string</code> - Required - The name of the bootstrap action. [Constraints: The value must be between 0 and 256 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]</li>
431
	 * 			<li><code>ScriptBootstrapAction</code> - <code>array</code> - Required - The script run by the bootstrap action. <ul>
432
	 * 				<li><code>x</code> - <code>array</code> - Optional - This represents a simple array index. <ul>
433
	 * 					<li><code>Path</code> - <code>string</code> - Required - Location of the script to run during a bootstrap action. Can be either a location in Amazon S3 or on a local file system. [Constraints: The value must be between 0 and 10280 characters, and must match the following regular expression pattern: <code>[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*</code>]</li>
434
	 * 					<li><code>Args</code> - <code>string|array</code> - Optional - A list of command line arguments to pass to the bootstrap action script. Pass a string for a single value, or an indexed array for multiple values.</li>
435
	 * 				</ul></li>
436
	 * 			</ul></li>
437
	 * 		</ul></li>
438
	 * 	</ul></li>
439
	 * 	<li><code>SupportedProducts</code> - <code>string|array</code> - Optional - A list of strings used by third-party software to tag the job flow. Currently the only valid value is "karmasphere-enterprise-utility", which tags the job flow for management by <a href="http://aws.amazon.com/elasticmapreduce/karmasphere/">Karmasphere.</a> Pass a string for a single value, or an indexed array for multiple values.</li>
440
	 * 	<li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
441
	 * 	<li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul>
442
	 * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
443
	 */
444
	public function run_job_flow($name, $instances, $opt = null)
445
	{
446
		if (!$opt) $opt = array();
447
		$opt['Name'] = $name;
448
 
449
		// Required map (non-list)
450
		$opt = array_merge($opt, CFComplexType::map(array(
451
			'Instances' => (is_array($instances) ? $instances : array($instances))
452
		), 'member'));
453
 
454
		// Optional list + map
455
		if (isset($opt['Steps']))
456
		{
457
			$opt = array_merge($opt, CFComplexType::map(array(
458
				'Steps' => $opt['Steps']
459
			), 'member'));
460
			unset($opt['Steps']);
461
		}
462
 
463
		// Optional list + map
464
		if (isset($opt['BootstrapActions']))
465
		{
466
			$opt = array_merge($opt, CFComplexType::map(array(
467
				'BootstrapActions' => $opt['BootstrapActions']
468
			), 'member'));
469
			unset($opt['BootstrapActions']);
470
		}
471
 
472
		// Optional list (non-map)
473
		if (isset($opt['SupportedProducts']))
474
		{
475
			$opt = array_merge($opt, CFComplexType::map(array(
476
				'SupportedProducts' => (is_array($opt['SupportedProducts']) ? $opt['SupportedProducts'] : array($opt['SupportedProducts']))
477
			), 'member'));
478
			unset($opt['SupportedProducts']);
479
		}
480
 
481
		return $this->authenticate('RunJobFlow', $opt);
482
	}
483
 
484
	/**
485
	 * SetTerminationProtection locks a job flow so the Amazon EC2 instances in the cluster cannot be
486
	 * terminated by user intervention, an API call, or in the event of a job-flow error. The cluster
487
	 * still terminates upon successful completion of the job flow. Calling SetTerminationProtection
488
	 * on a job flow is analogous to calling the Amazon EC2 DisableAPITermination API on all of the
489
	 * EC2 instances in a cluster.
490
	 *
491
	 * SetTerminationProtection is used to prevent accidental termination of a job flow and to ensure
492
	 * that in the event of an error, the instances will persist so you can recover any data stored in
493
	 * their ephemeral instance storage.
494
	 *
495
	 * To terminate a job flow that has been locked by setting SetTerminationProtection to
496
	 * <code>true</code>, you must first unlock the job flow by a subsequent call to
497
	 * SetTerminationProtection in which you set the value to <code>false</code>.
498
	 *
499
	 * For more information, go to <a href=
500
	 * "http://docs.amazonwebservices.com/ElasticMapReduce/latest/DeveloperGuide/UsingEMR_TerminationProtection.html">
501
	 * Protecting a Job Flow from Termination</a> in the <em>Amazon Elastic MapReduce Developer's
502
	 * Guide.</em>
503
	 *
504
	 * @param string|array $job_flow_ids (Required) A list of strings that uniquely identify the job flows to protect. This identifier is returned by <code>RunJobFlow</code> and can also be obtained from <code>DescribeJobFlows</code>. Pass a string for a single value, or an indexed array for multiple values.
505
	 * @param boolean $termination_protected (Required) A Boolean that indicates whether to protect the job flow and prevent the Amazon EC2 instances in the cluster from shutting down due to API calls, user intervention, or job-flow error.
506
	 * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
507
	 * 	<li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
508
	 * 	<li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul>
509
	 * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
510
	 */
511
	public function set_termination_protection($job_flow_ids, $termination_protected, $opt = null)
512
	{
513
		if (!$opt) $opt = array();
514
		$opt['TerminationProtected'] = $termination_protected;
515
 
516
		// Required list (non-map)
517
		$opt = array_merge($opt, CFComplexType::map(array(
518
			'JobFlowIds' => (is_array($job_flow_ids) ? $job_flow_ids : array($job_flow_ids))
519
		), 'member'));
520
 
521
		return $this->authenticate('SetTerminationProtection', $opt);
522
	}
523
 
524
	/**
525
	 * TerminateJobFlows shuts a list of job flows down. When a job flow is shut down, any step not
526
	 * yet completed is canceled and the EC2 instances on which the job flow is running are stopped.
527
	 * Any log files not already saved are uploaded to Amazon S3 if a LogUri was specified when the
528
	 * job flow was created.
529
	 *
530
	 * @param string|array $job_flow_ids (Required) A list of job flows to be shutdown. Pass a string for a single value, or an indexed array for multiple values.
531
	 * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
532
	 * 	<li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
533
	 * 	<li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul>
534
	 * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
535
	 */
536
	public function terminate_job_flows($job_flow_ids, $opt = null)
537
	{
538
		if (!$opt) $opt = array();
539
 
540
		// Required list (non-map)
541
		$opt = array_merge($opt, CFComplexType::map(array(
542
			'JobFlowIds' => (is_array($job_flow_ids) ? $job_flow_ids : array($job_flow_ids))
543
		), 'member'));
544
 
545
		return $this->authenticate('TerminateJobFlows', $opt);
546
	}
547
}
548
 
549
 
550
/*%******************************************************************************************%*/
551
// EXCEPTIONS
552
 
553
class EMR_Exception extends Exception {}