mortar-api-ruby 0.8.7 → 0.8.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mortar/api/jobs.rb +43 -6
- data/lib/mortar/api/version.rb +1 -1
- data/spec/mortar/api/jobs_spec.rb +89 -12
- metadata +4 -4
data/lib/mortar/api/jobs.rb
CHANGED
@@ -50,11 +50,15 @@ module Mortar
|
|
50
50
|
CLUSTER_TYPE__SINGLE_JOB = 'single_job'
|
51
51
|
CLUSTER_TYPE__PERSISTENT = 'persistent'
|
52
52
|
CLUSTER_TYPE__PERMANENT = 'permanent'
|
53
|
+
|
54
|
+
JOB_TYPE_ALL = 'all'
|
55
|
+
JOB_TYPE_PIG = 'pig'
|
56
|
+
JOB_TYPE_LUIGI = 'luigi'
|
53
57
|
end
|
54
58
|
|
55
59
|
|
56
60
|
# POST /vX/jobs
|
57
|
-
def
|
61
|
+
def post_pig_job_existing_cluster(project_name, script_name, git_ref, cluster_id, options={})
|
58
62
|
parameters = options[:parameters] || {}
|
59
63
|
notify_on_job_finish = options[:notify_on_job_finish].nil? ? true : options[:notify_on_job_finish]
|
60
64
|
is_control_script = options[:is_control_script] || false
|
@@ -63,7 +67,8 @@ module Mortar
|
|
63
67
|
"git_ref" => git_ref,
|
64
68
|
"cluster_id" => cluster_id,
|
65
69
|
"parameters" => parameters,
|
66
|
-
"notify_on_job_finish" => notify_on_job_finish
|
70
|
+
"notify_on_job_finish" => notify_on_job_finish,
|
71
|
+
"job_type" => Jobs::JOB_TYPE_PIG
|
67
72
|
}
|
68
73
|
|
69
74
|
if is_control_script
|
@@ -88,9 +93,8 @@ module Mortar
|
|
88
93
|
:body => json_encode(body))
|
89
94
|
end
|
90
95
|
|
91
|
-
|
92
96
|
# POST /vX/jobs
|
93
|
-
def
|
97
|
+
def post_pig_job_new_cluster(project_name, script_name, git_ref, cluster_size, options={})
|
94
98
|
cluster_type = options[:cluster_type].nil? ? Jobs::CLUSTER_TYPE__PERSISTENT : options[:cluster_type]
|
95
99
|
notify_on_job_finish = options[:notify_on_job_finish].nil? ? true : options[:notify_on_job_finish]
|
96
100
|
use_spot_instances = options[:use_spot_instances].nil? ? false : options[:use_spot_instances]
|
@@ -103,6 +107,7 @@ module Mortar
|
|
103
107
|
"cluster_type" => cluster_type,
|
104
108
|
"parameters" => parameters,
|
105
109
|
"notify_on_job_finish" => notify_on_job_finish,
|
110
|
+
"job_type" => Jobs::JOB_TYPE_PIG,
|
106
111
|
"use_spot_instances" => use_spot_instances
|
107
112
|
}
|
108
113
|
if is_control_script
|
@@ -127,14 +132,33 @@ module Mortar
|
|
127
132
|
:body => json_encode(body))
|
128
133
|
end
|
129
134
|
|
135
|
+
def post_luigi_job(project_name, luigiscript_name, git_ref, options={})
|
136
|
+
parameters = options[:parameters] || {}
|
137
|
+
body = { "project_name" => project_name,
|
138
|
+
"git_ref" => git_ref,
|
139
|
+
"luigiscript_name" => luigiscript_name,
|
140
|
+
"parameters" => parameters,
|
141
|
+
"job_type" => Jobs::JOB_TYPE_LUIGI
|
142
|
+
}
|
143
|
+
unless options[:project_script_path].nil?
|
144
|
+
body["project_script_path"] = options[:project_script_path]
|
145
|
+
end
|
146
|
+
|
147
|
+
request(
|
148
|
+
:expects => 200,
|
149
|
+
:method => :post,
|
150
|
+
:path => versioned_path("/jobs"),
|
151
|
+
:body => json_encode(body))
|
152
|
+
end
|
153
|
+
|
130
154
|
# GET /vX/jobs
|
131
|
-
def get_jobs(skip, limit)
|
155
|
+
def get_jobs(skip, limit, job_type=Jobs::JOB_TYPE_PIG)
|
132
156
|
request(
|
133
157
|
:expects => 200,
|
134
158
|
:idempotent => true,
|
135
159
|
:method => :get,
|
136
160
|
:path => versioned_path("/jobs"),
|
137
|
-
:query => { :skip => skip, :limit => limit }
|
161
|
+
:query => { job_type => job_type, :skip => skip, :limit => limit }
|
138
162
|
)
|
139
163
|
end
|
140
164
|
|
@@ -157,5 +181,18 @@ module Mortar
|
|
157
181
|
:path => versioned_path("/jobs/#{job_id}")
|
158
182
|
)
|
159
183
|
end
|
184
|
+
|
185
|
+
# <b>DEPRECATED:</b> Please use <tt>post_pig_job_existing_cluster</tt> instead.
|
186
|
+
def post_job_existing_cluster(project_name, script_name, git_ref, cluster_id, options={})
|
187
|
+
warn "[DEPRECATION] 'post_job_existing_cluster' is deprecated. Please use 'post_pig_job_existing_cluster' instead."
|
188
|
+
post_pig_job_existing_cluster(project_name, script_name, git_ref, cluster_id, options=options)
|
189
|
+
end
|
190
|
+
|
191
|
+
# <b>DEPRECATED:</b> Please use <tt>post_pig_job_new_cluster</tt> instead.
|
192
|
+
def post_job_new_cluster(project_name, script_name, git_ref, cluster_size, options={})
|
193
|
+
warn "[DEPRECATION] 'post_job_new_cluster' is deprecated. Please use 'post_pig_job_new_cluster' instead."
|
194
|
+
post_pig_job_new_cluster(project_name, script_name, git_ref, cluster_size, options=options)
|
195
|
+
end
|
196
|
+
|
160
197
|
end
|
161
198
|
end
|
data/lib/mortar/api/version.rb
CHANGED
@@ -30,7 +30,33 @@ describe Mortar::API do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
context "jobs" do
|
33
|
-
it "posts a job
|
33
|
+
it "posts a luigi job" do
|
34
|
+
job_id = "7b93e4d3ab034188a0c2be418d3d24ed"
|
35
|
+
project_name = "my_project"
|
36
|
+
pigscript_name = "my_luigiscript"
|
37
|
+
project_script_path = "luigiscripts/"
|
38
|
+
git_ref = "e20395b8b06fbf52e86665b0660209673f311d1a"
|
39
|
+
parameters = {"my-first-param" => 1, "MY-SECOND-PARAM" => "TWO"}
|
40
|
+
body = Mortar::API::OkJson.encode({"project_name" => project_name,
|
41
|
+
"git_ref" => git_ref,
|
42
|
+
"luigiscript_name" => pigscript_name,
|
43
|
+
"parameters" => parameters,
|
44
|
+
"job_type" => "luigi",
|
45
|
+
"project_script_path" => project_script_path})
|
46
|
+
Excon.stub({:method => :post, :path => "/v2/jobs", :body => body}) do |params|
|
47
|
+
{:body => Mortar::API::OkJson.encode({'job_id' => job_id}), :status => 200}
|
48
|
+
end
|
49
|
+
|
50
|
+
response = @api.post_luigi_job(
|
51
|
+
project_name,
|
52
|
+
pigscript_name,
|
53
|
+
git_ref,
|
54
|
+
:parameters => parameters,
|
55
|
+
:project_script_path => project_script_path)
|
56
|
+
response.body['job_id'].should == job_id
|
57
|
+
end
|
58
|
+
|
59
|
+
it "posts a pig job for an existing cluster" do
|
34
60
|
job_id = "7b93e4d3ab034188a0c2be418d3d24ed"
|
35
61
|
project_name = "my_project"
|
36
62
|
pigscript_name = "my_pigscript"
|
@@ -43,15 +69,30 @@ describe Mortar::API do
|
|
43
69
|
"cluster_id" => cluster_id,
|
44
70
|
"parameters" => parameters,
|
45
71
|
"notify_on_job_finish" => true,
|
72
|
+
"job_type" => "pig",
|
46
73
|
"pigscript_name" => pigscript_name,
|
47
|
-
"project_script_path" => project_script_path
|
48
|
-
|
49
|
-
})
|
74
|
+
"project_script_path" => project_script_path})
|
50
75
|
Excon.stub({:method => :post, :path => "/v2/jobs", :body => body}) do |params|
|
51
76
|
{:body => Mortar::API::OkJson.encode({'job_id' => job_id}), :status => 200}
|
52
77
|
end
|
53
|
-
|
78
|
+
|
79
|
+
response = @api.post_pig_job_existing_cluster(
|
80
|
+
project_name,
|
81
|
+
pigscript_name,
|
82
|
+
git_ref,
|
83
|
+
cluster_id,
|
84
|
+
:parameters => parameters,
|
85
|
+
:project_script_path => project_script_path)
|
54
86
|
response.body['job_id'].should == job_id
|
87
|
+
|
88
|
+
response_deprecated = @api.post_job_existing_cluster(
|
89
|
+
project_name,
|
90
|
+
pigscript_name,
|
91
|
+
git_ref,
|
92
|
+
cluster_id,
|
93
|
+
:parameters => parameters,
|
94
|
+
:project_script_path => project_script_path)
|
95
|
+
response_deprecated.body['job_id'].should == job_id
|
55
96
|
end
|
56
97
|
|
57
98
|
it "posts a job for a new cluster, defaulting cluster_type to persistent" do
|
@@ -67,14 +108,17 @@ describe Mortar::API do
|
|
67
108
|
"cluster_type" => cluster_type,
|
68
109
|
"parameters" => {},
|
69
110
|
"notify_on_job_finish" => true,
|
111
|
+
"job_type" => "pig",
|
70
112
|
"use_spot_instances" => false,
|
71
|
-
"pigscript_name" => pigscript_name
|
72
|
-
})
|
113
|
+
"pigscript_name" => pigscript_name})
|
73
114
|
Excon.stub({:method => :post, :path => "/v2/jobs", :body => body}) do |params|
|
74
115
|
{:body => Mortar::API::OkJson.encode({'job_id' => job_id}), :status => 200}
|
75
116
|
end
|
76
|
-
response = @api.
|
117
|
+
response = @api.post_pig_job_new_cluster(project_name, pigscript_name, git_ref, cluster_size)
|
77
118
|
response.body['job_id'].should == job_id
|
119
|
+
|
120
|
+
response_deprecated = @api.post_job_new_cluster(project_name, pigscript_name, git_ref, cluster_size)
|
121
|
+
response_deprecated.body['job_id'].should == job_id
|
78
122
|
end
|
79
123
|
|
80
124
|
it "posts a job for a new cluster, defaulting to notify_on_job_finish of true" do
|
@@ -91,6 +135,7 @@ describe Mortar::API do
|
|
91
135
|
"cluster_type" => cluster_type,
|
92
136
|
"parameters" => {},
|
93
137
|
"notify_on_job_finish" => true,
|
138
|
+
"job_type" => "pig",
|
94
139
|
"use_spot_instances" => false,
|
95
140
|
"pigscript_name" => pigscript_name,
|
96
141
|
"project_script_path" => project_script_path,
|
@@ -98,8 +143,11 @@ describe Mortar::API do
|
|
98
143
|
Excon.stub({:method => :post, :path => "/v2/jobs", :body => body}) do |params|
|
99
144
|
{:body => Mortar::API::OkJson.encode({'job_id' => job_id}), :status => 200}
|
100
145
|
end
|
101
|
-
response = @api.
|
146
|
+
response = @api.post_pig_job_new_cluster(project_name, pigscript_name, git_ref, cluster_size, :project_script_path => project_script_path)
|
102
147
|
response.body['job_id'].should == job_id
|
148
|
+
|
149
|
+
response_deprecated = @api.post_job_new_cluster(project_name, pigscript_name, git_ref, cluster_size, :project_script_path => project_script_path)
|
150
|
+
response_deprecated.body['job_id'].should == job_id
|
103
151
|
end
|
104
152
|
|
105
153
|
it "accepts non-default params for notify_on_job_finish and use_spot_instances" do
|
@@ -116,6 +164,7 @@ describe Mortar::API do
|
|
116
164
|
"cluster_type" => cluster_type,
|
117
165
|
"parameters" => {},
|
118
166
|
"notify_on_job_finish" => false,
|
167
|
+
"job_type" => "pig",
|
119
168
|
"use_spot_instances" => true,
|
120
169
|
"pigscript_name" => pigscript_name,
|
121
170
|
"project_script_path" => project_script_path,
|
@@ -123,11 +172,16 @@ describe Mortar::API do
|
|
123
172
|
Excon.stub({:method => :post, :path => "/v2/jobs", :body => body}) do |params|
|
124
173
|
{:body => Mortar::API::OkJson.encode({'job_id' => job_id}), :status => 200}
|
125
174
|
end
|
126
|
-
response = @api.
|
175
|
+
response = @api.post_pig_job_new_cluster(project_name, pigscript_name, git_ref, cluster_size,
|
127
176
|
:cluster_type => cluster_type, :notify_on_job_finish => false,
|
128
177
|
:use_spot_instances => true,
|
129
178
|
:project_script_path => project_script_path)
|
130
179
|
response.body['job_id'].should == job_id
|
180
|
+
response_deprecated = @api.post_job_new_cluster(project_name, pigscript_name, git_ref, cluster_size,
|
181
|
+
:cluster_type => cluster_type, :notify_on_job_finish => false,
|
182
|
+
:use_spot_instances => true,
|
183
|
+
:project_script_path => project_script_path)
|
184
|
+
response_deprecated.body['job_id'].should == job_id
|
131
185
|
end
|
132
186
|
|
133
187
|
it "accepts cluster_type of single_job" do
|
@@ -144,6 +198,7 @@ describe Mortar::API do
|
|
144
198
|
"cluster_type" => cluster_type,
|
145
199
|
"parameters" => {},
|
146
200
|
"notify_on_job_finish" => true,
|
201
|
+
"job_type" => "pig",
|
147
202
|
"use_spot_instances" => false,
|
148
203
|
"pigscript_name" => pigscript_name,
|
149
204
|
"project_script_path" => project_script_path,
|
@@ -151,8 +206,11 @@ describe Mortar::API do
|
|
151
206
|
Excon.stub({:method => :post, :path => "/v2/jobs", :body => body}) do |params|
|
152
207
|
{:body => Mortar::API::OkJson.encode({'job_id' => job_id}), :status => 200}
|
153
208
|
end
|
154
|
-
response = @api.
|
209
|
+
response = @api.post_pig_job_new_cluster(project_name, pigscript_name, git_ref, cluster_size, :cluster_type => cluster_type, :project_script_path => project_script_path)
|
155
210
|
response.body['job_id'].should == job_id
|
211
|
+
|
212
|
+
response_deprecated = @api.post_job_new_cluster(project_name, pigscript_name, git_ref, cluster_size, :cluster_type => cluster_type, :project_script_path => project_script_path)
|
213
|
+
response_deprecated.body['job_id'].should == job_id
|
156
214
|
end
|
157
215
|
|
158
216
|
it "accepts cluster_type of permanent" do
|
@@ -169,6 +227,7 @@ describe Mortar::API do
|
|
169
227
|
"cluster_type" => cluster_type,
|
170
228
|
"parameters" => {},
|
171
229
|
"notify_on_job_finish" => true,
|
230
|
+
"job_type" => "pig",
|
172
231
|
"use_spot_instances" => false,
|
173
232
|
"pigscript_name" => pigscript_name,
|
174
233
|
"project_script_path" => project_script_path,
|
@@ -176,8 +235,11 @@ describe Mortar::API do
|
|
176
235
|
Excon.stub({:method => :post, :path => "/v2/jobs", :body => body}) do |params|
|
177
236
|
{:body => Mortar::API::OkJson.encode({'job_id' => job_id}), :status => 200}
|
178
237
|
end
|
179
|
-
response = @api.
|
238
|
+
response = @api.post_pig_job_new_cluster(project_name, pigscript_name, git_ref, cluster_size, :cluster_type => cluster_type, :project_script_path => project_script_path)
|
180
239
|
response.body['job_id'].should == job_id
|
240
|
+
|
241
|
+
response_deprecated = @api.post_job_new_cluster(project_name, pigscript_name, git_ref, cluster_size, :cluster_type => cluster_type, :project_script_path => project_script_path)
|
242
|
+
response_deprecated.body['job_id'].should == job_id
|
181
243
|
end
|
182
244
|
|
183
245
|
it "gets a job" do
|
@@ -199,6 +261,21 @@ describe Mortar::API do
|
|
199
261
|
jobs = response.body["jobs"]
|
200
262
|
jobs.nil?.should be_false
|
201
263
|
jobs.length.should == 2
|
264
|
+
|
265
|
+
response = @api.get_jobs(0, 10, "all")
|
266
|
+
jobs = response.body["jobs"]
|
267
|
+
jobs.nil?.should be_false
|
268
|
+
jobs.length.should == 2
|
269
|
+
|
270
|
+
response = @api.get_jobs(0, 10, "pig")
|
271
|
+
jobs = response.body["jobs"]
|
272
|
+
jobs.nil?.should be_false
|
273
|
+
jobs.length.should == 2
|
274
|
+
|
275
|
+
response = @api.get_jobs(0, 10, "luigi")
|
276
|
+
jobs = response.body["jobs"]
|
277
|
+
jobs.nil?.should be_false
|
278
|
+
jobs.length.should == 2
|
202
279
|
end
|
203
280
|
|
204
281
|
it "stops a running job" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mortar-api-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 47
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 8
|
9
|
-
-
|
10
|
-
version: 0.8.
|
9
|
+
- 8
|
10
|
+
version: 0.8.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Mortar Data
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2014-
|
18
|
+
date: 2014-10-06 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: excon
|