README.md in elasticity-2.1.1 vs README.md in elasticity-2.2

- old
+ new

@@ -7,27 +7,27 @@ * **Indirectly through a JobFlow-based API**. This README discusses the Elasticity API. * **Directly through access to the EMR REST API**. The less-discussed hidden darkside... I use this to enable the Elasticity API though it is not documented save for RubyDoc available at the the RubyGems [auto-generated documentation site](http://rubydoc.info/gems/elasticity/frames). Be forewarned: Making the calls directly requires that you understand how to structure EMR requests at the Amazon API level and from experience I can tell you there are more fun things you could be doing :) Scroll to the end for more information on the Amazon API. # Installation -``` +```ruby gem install elasticity ``` or in your Gemfile -``` +```ruby gem 'elasticity', '~> 2.0' ``` This will ensure that you protect yourself from API changes, which will only be made in major revisions. # Kicking Off a Job When using the EMR UI, there are several sample jobs that Amazon supplies. The assets for these sample jobs are hosted on S3 and publicly available meaning you can run this code as-is (supplying your AWS credentials appropriately) and ```JobFlow#run``` will return the ID of the job flow. -``` +```ruby require 'elasticity' # Create a job flow with your AWS credentials jobflow = Elasticity::JobFlow.new('AWS access key', 'AWS secret key') @@ -61,17 +61,17 @@ ## 1 - Create a Job Flow Only your AWS credentials are needed. -``` +```ruby jobflow = Elasticity::JobFlow.new('AWS access key', 'AWS secret key') ``` If you want to access a job flow that's already running: -``` +```ruby jobflow = Elasticity::JobFlow.from_jobflow_id('AWS access key', 'AWS secret key', 'jobflow ID') ``` This is useful if you'd like to attach to a running job flow and add more steps, etc. @@ -79,11 +79,11 @@ Configuration job flow options, shown below with default values. Note that these defaults are subject to change - they are reasonable defaults at the time(s) I work on them (e.g. the latest version of Hadoop). These options are sent up as part of job flow submission (i.e. ```JobFlow#run```), so be sure to configure these before running the job. -``` +```ruby jobflow.action_on_failure = 'TERMINATE_JOB_FLOW' jobflow.ami_version = 'latest' jobflow.ec2_key_name = 'default' jobflow.ec2_subnet_id = nil jobflow.hadoop_version = '0.20.205' @@ -101,11 +101,11 @@ ### The Easy Way™ If all you'd like to do is change the type or number of instances, ```JobFlow``` provides a few shortcuts to do just that. -``` +```ruby jobflow.instance_count = 10 jobflow.master_instance_type = 'm1.small' jobflow.slave_instance_type = 'c1.medium' ``` @@ -117,11 +117,11 @@ #### On-Demand Instance Groups These instances will be available for the life of your EMR job, versus Spot instances which are transient depending on your bid price (see below). -``` +```ruby ig = Elasticity::InstanceGroup.new ig.count = 10 # Provision 10 instances ig.type = 'c1.medium' # See the EMR docs for a list of supported types ig.set_on_demand_instances # This is the default setting @@ -131,11 +131,11 @@ #### Spot Instance Groups *When Amazon EC2 has unused capacity, it offers EC2 instances at a reduced cost, called the Spot Price. This price fluctuates based on availability and demand. You can purchase Spot Instances by placing a request that includes the highest bid price you are willing to pay for those instances. When the Spot Price is below your bid price, your Spot Instances are launched and you are billed the Spot Price. If the Spot Price rises above your bid price, Amazon EC2 terminates your Spot Instances.* - [EMR Developer Guide](http://docs.amazonwebservices.com/ElasticMapReduce/latest/DeveloperGuide/UsingEMR_SpotInstances.html) -``` +```ruby ig = Elasticity::InstanceGroup.new ig.count = 10 # Provision 10 instances ig.type = 'c1.medium' # See the EMR docs for a list of supported types ig.set_spot_instances(0.25) # Makes this a SPOT group with a $0.25 bid price @@ -145,11 +145,11 @@ ## 4 - Adding Bootstrap Actions (optional) Bootstrap actions are run as part of setting up the job flow, so be sure to configure these before running the job. -``` +```ruby [ Elasticity::HadoopBootstrapAction.new('-m', 'mapred.map.tasks=101'), Elasticity::HadoopBootstrapAction.new('-m', 'mapred.reduce.child.java.opts=-Xmx200m') Elasticity::HadoopBootstrapAction.new('-m', 'mapred.tasktracker.map.tasks.maximum=14') ].each do |action| @@ -157,15 +157,15 @@ end ``` ## 5 - Adding Steps -Each type of step has a default name that can be overridden (the :name field). Apart from that, steps are configured differently - exhaustively described below. +Each type of step has ```#name``` and ```#action_on_failure``` fields that can be overridden. Apart from that, steps are configured differently - exhaustively described below. ### Adding a Pig Step -``` +```ruby # Path to the Pig script pig_step = Elasticity::PigStep.new('s3n://mybucket/script.pig') # (optional) These variables are available during the execution of your script pig_step.variables = { @@ -180,11 +180,11 @@ Given the importance of specifying a reasonable value for [the number of parallel reducers](http://pig.apache.org/docs/r0.8.1/cookbook.html#Use+the+Parallel+Features PARALLEL), Elasticity calculates and passes through a reasonable default up with every invocation in the form of a script variable called E_PARALLELS. This default value is based off of the formula in the Pig Cookbook and the number of reducers AWS configures per instance. For example, if you had 8 instances in total and your slaves were m1.xlarge, the value is 26 (as shown below). -``` +```sh s3://elasticmapreduce/libs/pig/pig-script --run-pig-script --args -p INPUT=s3n://elasticmapreduce/samples/pig-apache/input -p OUTPUT=s3n://slif-elasticity/pig-apache/output/2011-05-04 @@ -192,19 +192,19 @@ s3n://elasticmapreduce/samples/pig-apache/do-reports.pig ``` Use this as you would any other Pig variable. -``` +```pig A = LOAD 'myfile' AS (t, u, v); B = GROUP A BY t PARALLEL $E_PARALLELS; ... ``` ### Adding a Hive Step -``` +```ruby # Path to the Hive Script hive_step = Elasticity::HiveStep.new('s3n://mybucket/script.hql') # (optional) These variables are available during the execution of your script hive_step.variables = { @@ -213,13 +213,22 @@ } jobflow.add_step(hive_step) ``` -### Adding a Custom Jar Step +### Adding a Streaming Step +```ruby +# Input bucket, output bucket, mapper and reducer scripts +streaming_step = Elasticity::StreamingStep.new('s3n://elasticmapreduce/samples/wordcount/input', 's3n://elasticityoutput/wordcount/output/2012-07-23', 's3n://elasticmapreduce/samples/wordcount/wordSplitter.py', 'aggregate') + +jobflow.add_step(streaming_step) ``` + +### Adding a Custom Jar Step + +```ruby # Path to your jar jar_step = Elasticity::CustomJarStep.new('s3n://mybucket/my.jar') # (optional) Arguments passed to the jar jar_step.arguments = ['arg1', 'arg2'] @@ -229,11 +238,11 @@ ## 6 - Running the Job Flow Submit the job flow to Amazon, storing the ID of the running job flow. -``` +```ruby jobflow_id = jobflow.run ``` ## 7 - Adding Additional Steps (optional) @@ -241,16 +250,16 @@ ## 8 - Shutting Down the Job Flow (optional) By default, job flows are set to terminate when there are no more running steps. You can tell the job flow to stay alive when it has nothing left to do: -``` +```ruby jobflow.keep_job_flow_alive_when_no_steps = true ``` If that's the case, or if you'd just like to terminate a running jobflow before waiting for it to finish: -``` +```ruby jobflow.shutdown ``` # Amazon EMR Documentation