fleet-api 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fc67d53034f0f63cc50eb450214eb215f3a8066a
4
- data.tar.gz: fa261735dc741aee77142943541075964e1b08d5
3
+ metadata.gz: a3632dd50614806a6d05b70c954da24146cebf83
4
+ data.tar.gz: 94458c2c48317cab5e2e7e18c8ea1ea0aae1c9c6
5
5
  SHA512:
6
- metadata.gz: 7830f480923b8f7a1c6c854afe89483f02d7fd611e66c1a9d757aa26e37696c50726512720388e1b9887caa54298d0ff1360543d99cc4867c0209b6eaff60a23
7
- data.tar.gz: 781530a7570c4389ecf4fe8966a33933d89d1f3fcb7300b0f98c3c5af4a8d64a8676a80e219665efd73e919ddc36cdaa906d7a8a20f765845599dcbed298b7bf
6
+ metadata.gz: c55fa3e17aa13c9167d048196d373295ad39dfeb334567299b9f1b9e4a54a92c02dc4d9d695ded62aee0f173d1bd312925eb76fba5cf66197dc615f6f9be0e54
7
+ data.tar.gz: e82ec57fd09b71077a5b48e8f74d8daf053f4519ec263da0f3b729f728a1e445c60459eb07ea92188080ed7877276ffa061eabff9391edfd83eb01addaa38b49
data/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ 0.6.1 - 2014-09-20
5
+ ------------------
6
+
7
+ ### Fixed
8
+ - Default to async operations to address performance issues
9
+
4
10
  0.6.0 - 2014-09-05
5
11
  ------------------
6
12
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fleet-api (0.6.0)
4
+ fleet-api (0.6.1)
5
5
  faraday (= 0.8.9)
6
6
  faraday_middleware (= 0.9.0)
7
7
 
data/README.md CHANGED
@@ -10,7 +10,7 @@ The client allows programmatic access to most of the *fleetctl* commands includi
10
10
 
11
11
  At this point, there is no official Fleet API (though one is [in the works](https://github.com/coreos/fleet/blob/master/Documentation/api-v1-alpha.md)) so this library mimcs the behavior of the *fleetctl* command line tool and simply writes data to the [etcd]() key-value-store. The Fleet daemon reads data out of specific keys in etcd and processes it as appropiate.
12
12
 
13
- As work on the actual Fleet API progresses, this library will be refactored to use the real API.
13
+ As work on the actual Fleet API progresses, this library will be refactored to use the real API. An initial pass at implementing a client for the official Fleet API can be found on the [feature/official-api](https://github.com/CenturyLinkLabs/fleet-api/tree/feature/official-api) branch.
14
14
 
15
15
  An alternative implementation is available in the [cloudspace/ruby-fleetctl](https://github.com/cloudspace/ruby-fleetctl) gem. The *ruby-fleetctl* gem takes a different approach and uses SSH to interact directly with the *fleetctl* binary to send commands. Our approach of writing directly to etcd cuts out the *fleetctl* middleman but is in more danger of being broken by future releases since we're effectively using a "private API".
16
16
 
data/lib/fleet/client.rb CHANGED
@@ -32,7 +32,7 @@ module Fleet
32
32
  include Fleet::Client::State
33
33
  include Fleet::Client::Unit
34
34
 
35
- def load(name, service_def=nil)
35
+ def load(name, service_def=nil, sync=false)
36
36
 
37
37
  if service_def
38
38
  unless service_def.is_a?(ServiceDefinition)
@@ -51,26 +51,26 @@ module Fleet
51
51
  end
52
52
 
53
53
  update_job_target_state(name, :loaded)
54
- wait_for_load_state(name, 'loaded')
54
+ wait_for_load_state(name, 'loaded') if sync
55
55
  end
56
56
 
57
57
  def start(service_name)
58
58
  update_job_target_state(service_name, :launched)
59
59
  end
60
60
 
61
- def stop(service_name)
61
+ def stop(service_name, sync=false)
62
62
  update_job_target_state(service_name, :loaded)
63
- wait_for_load_state(service_name, 'loaded')
63
+ wait_for_load_state(service_name, 'loaded') if sync
64
64
  end
65
65
 
66
- def unload(service_name)
66
+ def unload(service_name, sync=false)
67
67
  update_job_target_state(service_name, :inactive)
68
- wait_for_load_state(service_name, :no_state)
68
+ wait_for_load_state(service_name, :no_state) if sync
69
69
  end
70
70
 
71
- def destroy(service_name)
71
+ def destroy(service_name, sync=false)
72
72
  delete_job(service_name)
73
- wait_for_load_state(service_name, :no_state)
73
+ wait_for_load_state(service_name, :no_state) if sync
74
74
  end
75
75
 
76
76
  def status(service_name)
data/lib/fleet/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fleet
2
- VERSION = '0.6.0'.freeze unless defined?(Fleet::VERSION)
2
+ VERSION = '0.6.1'.freeze unless defined?(Fleet::VERSION)
3
3
  end
@@ -28,16 +28,12 @@ describe Fleet::Client do
28
28
  let(:name) { 'foo.service' }
29
29
  let(:service_def) { { 'Unit' => { 'Description' => 'bar' } } }
30
30
  let(:sd) { Fleet::ServiceDefinition.new(name, service_def) }
31
- let(:fleet_state) do
32
- { 'node' => { 'value' => '{ "loadState": "loaded" }' } }
33
- end
34
31
 
35
32
  context 'when a service definition is provided' do
36
33
  before do
37
34
  allow(subject).to receive(:create_unit).and_return(nil)
38
35
  allow(subject).to receive(:create_job).and_return(nil)
39
36
  allow(subject).to receive(:update_job_target_state).and_return(nil)
40
- allow(subject).to receive(:get_state).and_return(fleet_state)
41
37
  allow(Fleet::ServiceDefinition).to receive(:new).and_return(sd)
42
38
  end
43
39
 
@@ -62,9 +58,20 @@ describe Fleet::Client do
62
58
  subject.load(name, service_def)
63
59
  end
64
60
 
65
- it 'checks the job state' do
66
- expect(subject).to receive(:get_state).with(sd.name)
67
- subject.load(name, service_def)
61
+ context 'when sync=true is set' do
62
+
63
+ let(:fleet_state) do
64
+ { 'node' => { 'value' => '{ "loadState": "loaded" }' } }
65
+ end
66
+
67
+ before do
68
+ allow(subject).to receive(:get_state).and_return(fleet_state)
69
+ end
70
+
71
+ it 'checks the job state' do
72
+ expect(subject).to receive(:get_state).with(sd.name)
73
+ subject.load(name, service_def, sync=true)
74
+ end
68
75
  end
69
76
 
70
77
  context 'when #create_unit raises PreconditionFailed' do
@@ -120,7 +127,6 @@ describe Fleet::Client do
120
127
 
121
128
  before do
122
129
  allow(subject).to receive(:update_job_target_state).and_return(nil)
123
- allow(subject).to receive(:get_state).and_return(fleet_state)
124
130
  end
125
131
 
126
132
  it 'does NOT invoke #create_unit' do
@@ -140,9 +146,20 @@ describe Fleet::Client do
140
146
  subject.load(name)
141
147
  end
142
148
 
143
- it 'checks the job state' do
144
- expect(subject).to receive(:get_state).with(sd.name)
145
- subject.load(name)
149
+ context 'when sync=true is set' do
150
+
151
+ let(:fleet_state) do
152
+ { 'node' => { 'value' => '{ "loadState": "loaded" }' } }
153
+ end
154
+
155
+ before do
156
+ allow(subject).to receive(:get_state).and_return(fleet_state)
157
+ end
158
+
159
+ it 'checks the job state' do
160
+ expect(subject).to receive(:get_state).with(sd.name)
161
+ subject.load(name, nil, sync=true)
162
+ end
146
163
  end
147
164
  end
148
165
  end
@@ -165,13 +182,8 @@ describe Fleet::Client do
165
182
  describe '#stop' do
166
183
  let(:service_name) { 'foo.service' }
167
184
 
168
- let(:fleet_state) do
169
- { 'node' => { 'value' => '{ "load_state": "loaded" }' } }
170
- end
171
-
172
185
  before do
173
186
  allow(subject).to receive(:update_job_target_state)
174
- allow(subject).to receive(:get_state).and_return(fleet_state)
175
187
  end
176
188
 
177
189
  it 'invokes #update_job_target_state' do
@@ -181,9 +193,20 @@ describe Fleet::Client do
181
193
  subject.stop(service_name)
182
194
  end
183
195
 
184
- it 'checks the job state' do
185
- expect(subject).to receive(:get_state).with(service_name)
186
- subject.stop(service_name)
196
+ context 'when sync=true is set' do
197
+
198
+ let(:fleet_state) do
199
+ { 'node' => { 'value' => '{ "load_state": "loaded" }' } }
200
+ end
201
+
202
+ before do
203
+ allow(subject).to receive(:get_state).and_return(fleet_state)
204
+ end
205
+
206
+ it 'checks the job state' do
207
+ expect(subject).to receive(:get_state).with(service_name)
208
+ subject.stop(service_name, sync=true)
209
+ end
187
210
  end
188
211
  end
189
212
 
@@ -192,7 +215,6 @@ describe Fleet::Client do
192
215
 
193
216
  before do
194
217
  allow(subject).to receive(:update_job_target_state)
195
- allow(subject).to receive(:get_state).and_raise(Fleet::NotFound, 'boom')
196
218
  end
197
219
 
198
220
  it 'invokes #update_job_target_state' do
@@ -202,33 +224,40 @@ describe Fleet::Client do
202
224
  subject.unload(service_name)
203
225
  end
204
226
 
205
- it 'checks the job state' do
206
- expect(subject).to receive(:get_state).with(service_name)
207
- subject.unload(service_name)
208
- end
209
-
210
- context 'when the unload state cannot be achieved' do
211
-
212
- let(:fleet_state) do
213
- { 'node' => { 'value' => '{ "load_state": "loaded" }' } }
214
- end
227
+ context 'when sync=true is set' do
215
228
 
216
229
  before do
217
- allow(subject).to receive(:get_state).and_return(fleet_state)
218
- allow(subject).to receive(:sleep)
230
+ allow(subject).to receive(:get_state).and_raise(Fleet::NotFound, 'boom')
219
231
  end
220
232
 
221
- it 're-checks the state 20 times' do
222
- expect(subject).to receive(:get_state).exactly(20).times
223
- subject.unload(service_name) rescue nil
233
+ it 'checks the job state' do
234
+ expect(subject).to receive(:get_state).with(service_name)
235
+ subject.unload(service_name, sync=true)
224
236
  end
225
237
 
226
- it 'raises an error' do
227
- expect do
228
- subject.unload(service_name)
229
- end.to raise_error(Fleet::Error)
230
- end
238
+ context 'when the unload state cannot be achieved' do
239
+
240
+ let(:fleet_state) do
241
+ { 'node' => { 'value' => '{ "load_state": "loaded" }' } }
242
+ end
231
243
 
244
+ before do
245
+ allow(subject).to receive(:get_state).and_return(fleet_state)
246
+ allow(subject).to receive(:sleep)
247
+ end
248
+
249
+ it 're-checks the state 20 times' do
250
+ expect(subject).to receive(:get_state).exactly(20).times
251
+ subject.unload(service_name, sync=true) rescue nil
252
+ end
253
+
254
+ it 'raises an error' do
255
+ expect do
256
+ subject.unload(service_name, sync=true)
257
+ end.to raise_error(Fleet::Error)
258
+ end
259
+
260
+ end
232
261
  end
233
262
  end
234
263
 
@@ -237,7 +266,6 @@ describe Fleet::Client do
237
266
 
238
267
  before do
239
268
  allow(subject).to receive(:delete_job).and_return(nil)
240
- allow(subject).to receive(:get_state).and_raise(Fleet::NotFound, 'boom')
241
269
  end
242
270
 
243
271
  it 'invokes #delete_job' do
@@ -249,9 +277,16 @@ describe Fleet::Client do
249
277
  subject.destroy(service_name)
250
278
  end
251
279
 
252
- it 'checks the job state' do
253
- expect(subject).to receive(:get_state).with(service_name)
254
- subject.destroy(service_name)
280
+ context 'when sync=true is set' do
281
+
282
+ before do
283
+ allow(subject).to receive(:get_state).and_raise(Fleet::NotFound, 'boom')
284
+ end
285
+
286
+ it 'checks the job state' do
287
+ expect(subject).to receive(:get_state).with(service_name)
288
+ subject.destroy(service_name, sync=true)
289
+ end
255
290
  end
256
291
  end
257
292
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fleet-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - CenturyLink
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-05 00:00:00.000000000 Z
11
+ date: 2014-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -156,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
156
  version: '0'
157
157
  requirements: []
158
158
  rubyforge_project:
159
- rubygems_version: 2.2.0
159
+ rubygems_version: 2.2.2
160
160
  signing_key:
161
161
  specification_version: 4
162
162
  summary: A simple REST client for the CoreOS Fleet API