mortar-api-ruby 0.8.11 → 0.8.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZGQ4MDJlY2NjODJlYzFiZmVhNzc0MWQ1ZjhmN2NlN2JmYzRhYzA2NQ==
5
+ data.tar.gz: !binary |-
6
+ ZjA0ODA2ZWM2MWM0YTY3NzIxYmE5NThlYmZhYzkwNGYwMzdkNGU2Mw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OTJmZGIxOWY2MzVkODA5MzRjMGE1MmE2NTNhYzFkM2U5MjIwNjBhZjQ0OWNk
10
+ YjBlMTc3YmE3MDFjODRkMmNlMGZhMDE1YzU5ZTYxMGU2NjhjZGM1Njk2OGUy
11
+ MDYzZjQ4ZDliNjY0ZTQ2NDE2YjM0NDY5NTkxMWZiZjA5YjY3MmU=
12
+ data.tar.gz: !binary |-
13
+ MDQyMWUxYzliNWRhMjg3OTUwYWNlOTExZmM2Yjc4ODA2MjI0OTY5ZDM3ZGEx
14
+ YTdjMWExOGRlYmU5ODk4Y2MyMmFhNDNhZTRjZmZlNTlhM2MxODg4ZTM0YWZj
15
+ ZjhkNWQ2OGIxMjRhZTJmOTI5YmQ1ZTc1NmZhMWViM2IxNDEwMWI=
@@ -28,12 +28,13 @@ module Mortar
28
28
  end
29
29
 
30
30
  # GET /vX/clusters
31
- def get_clusters()
31
+ def get_clusters(cluster_backend=Mortar::API::Jobs::CLUSTER_BACKEND__EMR_HADOOP_1)
32
32
  request(
33
33
  :expects => 200,
34
34
  :idempotent => true,
35
35
  :method => :get,
36
- :path => versioned_path("/clusters")
36
+ :path => "#{versioned_path("/clusters")}",
37
+ :query => {:cluster_backend => cluster_backend}
37
38
  )
38
39
  end
39
40
 
@@ -40,6 +40,11 @@ module Mortar
40
40
  LUIGI_JOB_STATUS__STOPPED = 'stopped'
41
41
  LUIGI_JOB_STATUS__STOPPING = 'stopping'
42
42
 
43
+ SPARK_JOB_STATUS__PENDING = "pending"
44
+ SPARK_JOB_STATUS__STARTING = "starting"
45
+ SPARK_JOB_STATUS__RUNNING = "running"
46
+ SPARK_JOB_STATUS__FINISHED = "finished"
47
+
43
48
 
44
49
  STATUSES_IN_PROGRESS = Set.new([STATUS_STARTING,
45
50
  STATUS_GATEWAY_STARTING,
@@ -50,7 +55,10 @@ module Mortar
50
55
  LUIGI_JOB_STATUS__PENDING,
51
56
  LUIGI_JOB_STATUS__STARTING,
52
57
  LUIGI_JOB_STATUS__RUNNING,
53
- LUIGI_JOB_STATUS__STOPPING])
58
+ LUIGI_JOB_STATUS__STOPPING,
59
+ SPARK_JOB_STATUS__PENDING,
60
+ SPARK_JOB_STATUS__STARTING,
61
+ SPARK_JOB_STATUS__RUNNING])
54
62
 
55
63
  STATUSES_COMPLETE = Set.new([STATUS_SCRIPT_ERROR,
56
64
  STATUS_PLAN_ERROR,
@@ -59,15 +67,21 @@ module Mortar
59
67
  STATUS_SERVICE_ERROR,
60
68
  STATUS_STOPPED,
61
69
  LUIGI_JOB_STATUS__FINISHED,
62
- LUIGI_JOB_STATUS__STOPPED])
70
+ LUIGI_JOB_STATUS__STOPPED,
71
+ SPARK_JOB_STATUS__FINISHED])
63
72
 
64
73
  CLUSTER_TYPE__SINGLE_JOB = 'single_job'
65
74
  CLUSTER_TYPE__PERSISTENT = 'persistent'
66
75
  CLUSTER_TYPE__PERMANENT = 'permanent'
67
76
 
77
+ CLUSTER_BACKEND__EMR_HADOOP_1 = "EMR_HADOOP_1"
78
+ CLUSTER_BACKEND__EMR_HADOOP_2 = "EMR_HADOOP_2"
79
+ CLUSTER_BACKEND__ALL = "ALL"
80
+
68
81
  JOB_TYPE_ALL = 'all'
69
82
  JOB_TYPE_PIG = 'pig'
70
83
  JOB_TYPE_LUIGI = 'luigi'
84
+ JOB_TYPE_SPARK = 'spark'
71
85
  end
72
86
 
73
87
 
@@ -119,6 +133,7 @@ module Mortar
119
133
  "git_ref" => git_ref,
120
134
  "cluster_size" => cluster_size,
121
135
  "cluster_type" => cluster_type,
136
+ "cluster_backend" => Jobs::CLUSTER_BACKEND__EMR_HADOOP_1,
122
137
  "parameters" => parameters,
123
138
  "notify_on_job_finish" => notify_on_job_finish,
124
139
  "job_type" => Jobs::JOB_TYPE_PIG,
@@ -165,6 +180,56 @@ module Mortar
165
180
  :body => json_encode(body))
166
181
  end
167
182
 
183
+ def post_spark_job_new_cluster(project_name, sparkscript_name, git_ref, cluster_size, options={})
184
+ script_arguments = options[:script_arguments] || ""
185
+ use_spot_instances = options[:use_spot_instances].nil? ? false : options[:use_spot_instances]
186
+ cluster_type = options[:cluster_type].nil? ? Jobs::CLUSTER_TYPE__PERSISTENT : options[:cluster_type]
187
+
188
+
189
+ body = { "project_name" => project_name,
190
+ "git_ref" => git_ref,
191
+ "cluster_size" => cluster_size,
192
+ "cluster_type" => cluster_type,
193
+ "cluster_backend" => Jobs::CLUSTER_BACKEND__EMR_HADOOP_2,
194
+ "script_arguments" => script_arguments,
195
+ "job_type" => Jobs::JOB_TYPE_SPARK,
196
+ "use_spot_instances" => use_spot_instances,
197
+ "sparkscript_name" => sparkscript_name
198
+ }
199
+
200
+ unless options[:project_script_path].nil?
201
+ body["project_script_path"] = options[:project_script_path]
202
+ end
203
+
204
+ request(
205
+ :expects => 200,
206
+ :method => :post,
207
+ :path => versioned_path("/jobs"),
208
+ :body => json_encode(body))
209
+ end
210
+
211
+ def post_spark_job_existing_cluster(project_name, sparkscript_name, git_ref, cluster_id, options={})
212
+ script_arguments = options[:script_arguments] || ""
213
+
214
+ body = {"project_name" => project_name,
215
+ "git_ref" => git_ref,
216
+ "cluster_id" => cluster_id,
217
+ "script_arguments" => script_arguments,
218
+ "job_type" => Jobs::JOB_TYPE_SPARK,
219
+ "sparkscript_name" => sparkscript_name
220
+ }
221
+
222
+ unless options[:project_script_path].nil?
223
+ body["project_script_path"] = options[:project_script_path]
224
+ end
225
+
226
+ request(
227
+ :expects => 200,
228
+ :method => :post,
229
+ :path => versioned_path("/jobs"),
230
+ :body => json_encode(body))
231
+ end
232
+
168
233
  # GET /vX/jobs
169
234
  def get_jobs(skip, limit, job_type=Jobs::JOB_TYPE_PIG)
170
235
  request(
@@ -18,7 +18,7 @@ module Mortar
18
18
  class API
19
19
  # client version
20
20
  # see http://semver.org/
21
- VERSION = "0.8.11"
21
+ VERSION = "0.8.12"
22
22
 
23
23
  SERVER_API_VERSION = "2"
24
24
  end
@@ -30,8 +30,8 @@ describe Mortar::API do
30
30
 
31
31
  context "clusters" do
32
32
 
33
- it "gets recent and running clusters" do
34
- Excon.stub({:method => :get, :path => "/v2/clusters"}) do |params|
33
+ it "gets recent and running clusters - no cluster backend" do
34
+ Excon.stub({:method => :get, :path => "/v2/clusters", :query => {:cluster_backend => Mortar::API::Jobs::CLUSTER_BACKEND__EMR_HADOOP_1}}) do |params|
35
35
  {:body => Mortar::API::OkJson.encode({"clusters" => [{'cluster_id' => '1', 'status_code' => 'running'}, {'cluster_id' => '2', 'status_code' => 'running'}]}), :status => 200}
36
36
  end
37
37
  response = @api.get_clusters()
@@ -40,6 +40,16 @@ describe Mortar::API do
40
40
  clusters.length.should == 2
41
41
  end
42
42
 
43
+ it "gets recent and running clusters for hadoop 2 clusters" do
44
+ Excon.stub({:method => :get, :path => "/v2/clusters", :query => {:cluster_backend => Mortar::API::Jobs::CLUSTER_BACKEND__EMR_HADOOP_2}}) do |params|
45
+ {:body => Mortar::API::OkJson.encode({"clusters" => [{'cluster_id' => '1', 'status_code' => 'running'}, {'cluster_id' => '2', 'status_code' => 'running'}]}), :status => 200}
46
+ end
47
+ response = @api.get_clusters(Mortar::API::Jobs::CLUSTER_BACKEND__EMR_HADOOP_2)
48
+ clusters = response.body["clusters"]
49
+ clusters.nil?.should be_false
50
+ clusters.length.should == 2
51
+ end
52
+
43
53
  it "stops a running cluster" do
44
54
  cluster_id = "1234abc342221abc"
45
55
  Excon.stub({:method => :delete, :path => "/v2/clusters/#{cluster_id}"}) do |params|
@@ -106,6 +106,7 @@ describe Mortar::API do
106
106
  "git_ref" => git_ref,
107
107
  "cluster_size" => cluster_size,
108
108
  "cluster_type" => cluster_type,
109
+ "cluster_backend" => Mortar::API::Jobs::CLUSTER_BACKEND__EMR_HADOOP_1,
109
110
  "parameters" => {},
110
111
  "notify_on_job_finish" => true,
111
112
  "job_type" => "pig",
@@ -133,6 +134,7 @@ describe Mortar::API do
133
134
  "git_ref" => git_ref,
134
135
  "cluster_size" => cluster_size,
135
136
  "cluster_type" => cluster_type,
137
+ "cluster_backend" => Mortar::API::Jobs::CLUSTER_BACKEND__EMR_HADOOP_1,
136
138
  "parameters" => {},
137
139
  "notify_on_job_finish" => true,
138
140
  "job_type" => "pig",
@@ -162,6 +164,7 @@ describe Mortar::API do
162
164
  "git_ref" => git_ref,
163
165
  "cluster_size" => cluster_size,
164
166
  "cluster_type" => cluster_type,
167
+ "cluster_backend" => Mortar::API::Jobs::CLUSTER_BACKEND__EMR_HADOOP_1,
165
168
  "parameters" => {},
166
169
  "notify_on_job_finish" => false,
167
170
  "job_type" => "pig",
@@ -196,6 +199,7 @@ describe Mortar::API do
196
199
  "git_ref" => git_ref,
197
200
  "cluster_size" => cluster_size,
198
201
  "cluster_type" => cluster_type,
202
+ "cluster_backend" => Mortar::API::Jobs::CLUSTER_BACKEND__EMR_HADOOP_1,
199
203
  "parameters" => {},
200
204
  "notify_on_job_finish" => true,
201
205
  "job_type" => "pig",
@@ -225,6 +229,7 @@ describe Mortar::API do
225
229
  "git_ref" => git_ref,
226
230
  "cluster_size" => cluster_size,
227
231
  "cluster_type" => cluster_type,
232
+ "cluster_backend" => Mortar::API::Jobs::CLUSTER_BACKEND__EMR_HADOOP_1,
228
233
  "parameters" => {},
229
234
  "notify_on_job_finish" => true,
230
235
  "job_type" => "pig",
@@ -286,5 +291,57 @@ describe Mortar::API do
286
291
  response = @api.stop_job(job_id)
287
292
  response.body["success"].should be_true
288
293
  end
294
+
295
+ it "posts a spark job for a new cluster, defaulting cluster_type to persistent" do
296
+ job_id = "7b93e4d3ab034188a0c2be418d3d24ed"
297
+ project_name = "my_project"
298
+ sparkscript_name = "my_sparkscript"
299
+ git_ref = "e20395b8b06fbf52e86665b0660209673f311d1a"
300
+ cluster_size = 5
301
+ cluster_type = Mortar::API::Jobs::CLUSTER_TYPE__PERSISTENT
302
+ body = Mortar::API::OkJson.encode({"project_name" => project_name,
303
+ "git_ref" => git_ref,
304
+ "cluster_size" => cluster_size,
305
+ "cluster_type" => cluster_type,
306
+ "cluster_backend" => Mortar::API::Jobs::CLUSTER_BACKEND__EMR_HADOOP_2,
307
+ "script_arguments" => "",
308
+ "job_type" => "spark",
309
+ "use_spot_instances" => false,
310
+ "sparkscript_name" => sparkscript_name})
311
+ Excon.stub({:method => :post, :path => "/v2/jobs", :body => body}) do |params|
312
+ {:body => Mortar::API::OkJson.encode({'job_id' => job_id}), :status => 200}
313
+ end
314
+ response = @api.post_spark_job_new_cluster(project_name, sparkscript_name, git_ref, cluster_size)
315
+ response.body['job_id'].should == job_id
316
+ end
317
+
318
+ it "posts a spark job for an existing cluster" do
319
+ job_id = "7b93e4d3ab034188a0c2be418d3d24ed"
320
+ project_name = "my_project"
321
+ sparkscript_name = "my_sparkscript"
322
+ project_script_path = "sparkscripts/"
323
+ git_ref = "e20395b8b06fbf52e86665b0660209673f311d1a"
324
+ cluster_id = "f82c774f7ccd429e91db996838cb6c4a"
325
+ script_arguments = "some script args"
326
+ body = Mortar::API::OkJson.encode({"project_name" => project_name,
327
+ "git_ref" => git_ref,
328
+ "cluster_id" => cluster_id,
329
+ "script_arguments" => script_arguments,
330
+ "job_type" => "spark",
331
+ "sparkscript_name" => sparkscript_name,
332
+ "project_script_path" => project_script_path})
333
+ Excon.stub({:method => :post, :path => "/v2/jobs", :body => body}) do |params|
334
+ {:body => Mortar::API::OkJson.encode({'job_id' => job_id}), :status => 200}
335
+ end
336
+
337
+ response = @api.post_spark_job_existing_cluster(
338
+ project_name,
339
+ sparkscript_name,
340
+ git_ref,
341
+ cluster_id,
342
+ :script_arguments => script_arguments,
343
+ :project_script_path => project_script_path)
344
+ response.body['job_id'].should == job_id
345
+ end
289
346
  end
290
347
  end
metadata CHANGED
@@ -1,106 +1,91 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mortar-api-ruby
3
- version: !ruby/object:Gem::Version
4
- hash: 41
5
- prerelease:
6
- segments:
7
- - 0
8
- - 8
9
- - 11
10
- version: 0.8.11
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.12
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Mortar Data
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2014-10-24 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
11
+ date: 2015-01-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
21
14
  name: excon
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
26
17
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 51
29
- segments:
30
- - 0
31
- - 28
32
- version: "0.28"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.28'
33
20
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: gem-release
37
21
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
- version: "0"
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.28'
27
+ - !ruby/object:Gem::Dependency
28
+ name: gem-release
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
47
34
  type: :development
48
- version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
50
- name: rake
51
35
  prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
53
- none: false
54
- requirements:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
55
45
  - - ~>
56
- - !ruby/object:Gem::Version
57
- hash: 73
58
- segments:
59
- - 10
60
- - 1
61
- - 1
46
+ - !ruby/object:Gem::Version
62
47
  version: 10.1.1
63
48
  type: :development
64
- version_requirements: *id003
65
- - !ruby/object:Gem::Dependency
66
- name: rr
67
49
  prerelease: false
68
- requirement: &id004 !ruby/object:Gem::Requirement
69
- none: false
70
- requirements:
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
71
52
  - - ~>
72
- - !ruby/object:Gem::Version
73
- hash: 13
74
- segments:
75
- - 1
76
- - 1
77
- version: "1.1"
53
+ - !ruby/object:Gem::Version
54
+ version: 10.1.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.1'
78
62
  type: :development
79
- version_requirements: *id004
80
- - !ruby/object:Gem::Dependency
81
- name: rspec
82
63
  prerelease: false
83
- requirement: &id005 !ruby/object:Gem::Requirement
84
- none: false
85
- requirements:
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
86
66
  - - ~>
87
- - !ruby/object:Gem::Version
88
- hash: 3
89
- segments:
90
- - 2
91
- - 0
92
- version: "2.0"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
93
76
  type: :development
94
- version_requirements: *id005
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
95
83
  description: Client for Mortar API.
96
84
  email: support@mortardata.com
97
85
  executables: []
98
-
99
86
  extensions: []
100
-
101
87
  extra_rdoc_files: []
102
-
103
- files:
88
+ files:
104
89
  - .gitignore
105
90
  - .travis.yml
106
91
  - Gemfile
@@ -142,38 +127,40 @@ files:
142
127
  - spec/spec_helper.rb
143
128
  homepage: http://mortardata.com/
144
129
  licenses: []
145
-
130
+ metadata: {}
146
131
  post_install_message:
147
132
  rdoc_options: []
148
-
149
- require_paths:
133
+ require_paths:
150
134
  - lib
151
- required_ruby_version: !ruby/object:Gem::Requirement
152
- none: false
153
- requirements:
154
- - - ">="
155
- - !ruby/object:Gem::Version
156
- hash: 57
157
- segments:
158
- - 1
159
- - 8
160
- - 7
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
161
139
  version: 1.8.7
162
- required_rubygems_version: !ruby/object:Gem::Requirement
163
- none: false
164
- requirements:
165
- - - ">="
166
- - !ruby/object:Gem::Version
167
- hash: 3
168
- segments:
169
- - 0
170
- version: "0"
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ! '>='
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
171
145
  requirements: []
172
-
173
146
  rubyforge_project:
174
- rubygems_version: 1.8.15
147
+ rubygems_version: 2.2.2
175
148
  signing_key:
176
- specification_version: 3
149
+ specification_version: 4
177
150
  summary: Client for Mortar API
178
- test_files: []
179
-
151
+ test_files:
152
+ - spec/mortar/api/basicauth_spec.rb
153
+ - spec/mortar/api/clusters_spec.rb
154
+ - spec/mortar/api/config_spec.rb
155
+ - spec/mortar/api/describe_spec.rb
156
+ - spec/mortar/api/errors_spec.rb
157
+ - spec/mortar/api/illustrate_spec.rb
158
+ - spec/mortar/api/jobs_spec.rb
159
+ - spec/mortar/api/login_spec.rb
160
+ - spec/mortar/api/projects_spec.rb
161
+ - spec/mortar/api/tasks_spec.rb
162
+ - spec/mortar/api/user_spec.rb
163
+ - spec/mortar/api/validate_spec.rb
164
+ - spec/mortar/api_spec.rb
165
+ - spec/spec.opts
166
+ - spec/spec_helper.rb