elasticity 0.3 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.mediawiki CHANGED
@@ -1,10 +1,12 @@
1
1
  Elasticity provides programmatic access to Amazon's Elastic Map Reduce service.
2
2
 
3
- There are five API actions in the [http://docs.amazonwebservices.com/ElasticMapReduce/latest/DeveloperGuide/index.html EMR API], described below. Please see the Amazon guide for details on these operations because the default values aren't obvious (e.g. the meaning of DescribeJobFlows without parameters).
3
+ There are five API actions in the [http://docs.amazonwebservices.com/ElasticMapReduce/latest/DeveloperGuide/index.html EMR API], described below. Please see the Amazon guide for details on these operations because the default values aren't obvious (e.g. the meaning of <code>DescribeJobFlows</code> without parameters).
4
4
 
5
- Alternatively, you may opt for "direct" access to the API where you specify the params and Elasticity takes care of the signing for you. Direct access is described below the API catalog.
5
+ Each Elasticity call provides some level of wrapping to save you the trouble of having to parse XML and deal with common status codes.
6
6
 
7
- '''NOTE''': The AWS plumbing (especially signing/authentication) was used from [http://www.rightscale.com/ RightScale's] amazing [https://github.com/rightscale/right_aws right_aws gem] which works extraordinarily well!
7
+ Alternatively, you may opt for "direct" access to the API where you specify the params and Elasticity takes care of the signing for you, responding with the XML from Amazon. Direct access is described below the API catalog.
8
+
9
+ '''CREDITS''': AWS signing was used from [http://www.rightscale.com/ RightScale's] amazing [https://github.com/rightscale/right_aws right_aws gem] which works extraordinarily well! If you need access to any AWS service (EC2, S3, etc.), have a look.
8
10
 
9
11
  == AddInstanceGroups ==
10
12
 
@@ -16,6 +18,8 @@ Alternatively, you may opt for "direct" access to the API where you specify the
16
18
 
17
19
  == DescribeJobFlows ==
18
20
 
21
+ DescribeJobFlows returns detailed information as to the state of all jobs. Currently this is wrapped in an <code>Elasticity::JobFlow</code> that contains the <code>name</code>, <code>jobflow_id</code> and <code>state</code>.
22
+
19
23
  <pre>
20
24
  > emr = Elasticity::EMR.new(ENV["aws_access_key_id"], ENV["aws_secret_key"])
21
25
  > jobflows = emr.describe_jobflows
@@ -33,11 +37,11 @@ Alternatively, you may opt for "direct" access to the API where you specify the
33
37
 
34
38
  == TerminateJobFlows ==
35
39
 
36
- When the job flow '''exists''', you will receive no output. This is because Amazon does not return anything other than a 200 when you terminate a job flow :) You'll want to continually poll with DescribeJobFlows to see when the job was actually terminated.
40
+ When the job flow '''exists''', you will receive no output. This is because Amazon does not return anything other than a 200 when you terminate a job flow :) You'll want to continuously poll with DescribeJobFlows to see when the job was actually terminated.
37
41
 
38
42
  <pre>
39
43
  > emr = Elasticity::EMR.new(ENV["aws_access_key_id"], ENV["aws_secret_key"])
40
- > emr.terminate_jobflows("no-flow")
44
+ > emr.terminate_jobflows("j-BOWBV7884XD0")
41
45
  >
42
46
  </pre>
43
47
 
@@ -49,16 +53,26 @@ When the job flow '''doesn't exist''':
49
53
  ArgumentError: Job flow 'no-flow' does not exist.
50
54
  </pre>
51
55
 
52
- = Direct Access =
56
+ = Direct Response Access =
57
+
58
+ If you're fine with Elasticity's invocation wrapping and would prefer to get at the resulting XML rather than the wrapped response, throw a block our way and we'll yield the result. This still saves you the trouble of having to create the params and sign the request yet gives you direct access to the response XML for your parsing pleasure.
59
+
60
+ <pre>
61
+ > emr = Elasticity::EMR.new(ENV["aws_access_key_id"], ENV["aws_secret_key"])
62
+ > emr.describe_jobflows{|xml| puts xml[0..77]}
63
+ <DescribeJobFlowsResponse xmlns="http://elasticmapreduce.amazonaws.com/doc/200
64
+ </pre>
65
+
66
+ = Direct Request/Response Access =
53
67
 
54
- If you're chomping at the bit to get at some EMR functionality that isn't wrapped (or isn't wrapped in a way you prefer :) feel free to access the AWS EMR API directly by using <code>EMR.direct()</code>. You can find the allowed values in Amazon's EMR API [http://docs.amazonwebservices.com/ElasticMapReduce/latest/DeveloperGuide/index.html developer documentation].
68
+ If you're chomping at the bit to initiate some EMR functionality that isn't wrapped (or isn't wrapped in a way you prefer :) feel free to access the AWS EMR API directly by using <code>EMR.direct()</code>. You can find the allowed values in Amazon's EMR API [http://docs.amazonwebservices.com/ElasticMapReduce/latest/DeveloperGuide/index.html developer documentation].
55
69
 
56
70
  <pre>
57
71
  > emr = Elasticity::EMR.new(ENV["aws_access_key_id"], ENV["aws_secret_key"])
58
72
  > params = {"Operation" => "DescribeJobFlows"}
59
73
  > result_xml = emr.direct(params)
60
- > result_xml[0..42]
61
- <DescribeJobFlowsResponse xmlns=\"http://ela"
74
+ > result_xml[0..78]
75
+ <DescribeJobFlowsResponse xmlns="http://elasticmapreduce.amazonaws.com/doc/2009
62
76
  </pre>
63
77
 
64
78
  <!-- __NOTOC__ -->
@@ -11,6 +11,7 @@ module Elasticity
11
11
  aws_result = @aws_request.aws_emr_request({"Operation" => "DescribeJobFlows"})
12
12
  xml_doc = Nokogiri::XML(aws_result)
13
13
  xml_doc.remove_namespaces!
14
+ yield aws_result if block_given?
14
15
  JobFlow.from_members_nodeset(xml_doc.xpath("/DescribeJobFlowsResponse/DescribeJobFlowsResult/JobFlows/member"))
15
16
  end
16
17
 
@@ -20,10 +21,11 @@ module Elasticity
20
21
  # flow does not exist.
21
22
  def terminate_jobflows(jobflow_id)
22
23
  begin
23
- @aws_request.aws_emr_request({
24
+ aws_result = @aws_request.aws_emr_request({
24
25
  "Operation" => "TerminateJobFlows",
25
26
  "JobFlowIds.member.1" => jobflow_id
26
27
  })
28
+ yield aws_result if block_given?
27
29
  rescue RestClient::BadRequest
28
30
  raise ArgumentError, "Job flow '#{jobflow_id}' does not exist."
29
31
  end
@@ -1,3 +1,3 @@
1
1
  module Elasticity
2
- VERSION = "0.3"
2
+ VERSION = "0.3.5"
3
3
  end
@@ -40,6 +40,7 @@ describe Elasticity::EMR do
40
40
  </DescribeJobFlowsResponse>
41
41
  JOBFLOWS
42
42
  end
43
+
43
44
  it "should return the names of all running job flows" do
44
45
  aws_request = Elasticity::AwsRequest.new("aws_access_key_id", "aws_secret_key")
45
46
  aws_request.should_receive(:aws_emr_request).with({"Operation" => "DescribeJobFlows"}).and_return(@describe_jobflows_xml)
@@ -48,6 +49,20 @@ describe Elasticity::EMR do
48
49
  jobflows = emr.describe_jobflows
49
50
  jobflows.map(&:name).should == ["Pig Job", "Hive Job"]
50
51
  end
52
+
53
+ context "when a block is provided" do
54
+ it "should yield the XML result" do
55
+ aws_request = Elasticity::AwsRequest.new("aws_access_key_id", "aws_secret_key")
56
+ aws_request.should_receive(:aws_emr_request).with({"Operation" => "DescribeJobFlows"}).and_return(@describe_jobflows_xml)
57
+ Elasticity::AwsRequest.should_receive(:new).and_return(aws_request)
58
+ emr = Elasticity::EMR.new("aws_access_key_id", "aws_secret_key")
59
+ xml_result = nil
60
+ emr.describe_jobflows do |xml|
61
+ xml_result = xml
62
+ end
63
+ xml_result.should == @describe_jobflows_xml
64
+ end
65
+ end
51
66
  end
52
67
 
53
68
  end
@@ -86,6 +101,22 @@ describe Elasticity::EMR do
86
101
  emr = Elasticity::EMR.new("aws_access_key_id", "aws_secret_key")
87
102
  emr.terminate_jobflows("j-1")
88
103
  end
104
+ context "when a block is given" do
105
+ it "should yield the XML result" do
106
+ aws_request = Elasticity::AwsRequest.new("aws_access_key_id", "aws_secret_key")
107
+ aws_request.should_receive(:aws_emr_request).with({
108
+ "Operation" => "TerminateJobFlows",
109
+ "JobFlowIds.member.1" => "j-1"
110
+ }).and_return(@terminate_jobflows_xml)
111
+ Elasticity::AwsRequest.should_receive(:new).and_return(aws_request)
112
+ emr = Elasticity::EMR.new("aws_access_key_id", "aws_secret_key")
113
+ xml_result = nil
114
+ emr.terminate_jobflows("j-1") do |xml|
115
+ xml_result = xml
116
+ end
117
+ xml_result.should == @terminate_jobflows_xml
118
+ end
119
+ end
89
120
  end
90
121
 
91
122
  context "when the jobflow does not exist" do
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticity
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- version: "0.3"
9
+ - 5
10
+ version: 0.3.5
10
11
  platform: ruby
11
12
  authors:
12
13
  - Robert Slifka
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-04-10 00:00:00 -07:00
18
+ date: 2011-04-11 00:00:00 -07:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency