cfoundry 0.3.14 → 0.3.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -62,6 +62,7 @@ module CFoundry::V1
62
62
  @name = name
63
63
  @client = client
64
64
  @manifest = manifest
65
+ @diff = {}
65
66
  end
66
67
 
67
68
  # Show string representing the application.
@@ -76,9 +77,8 @@ module CFoundry::V1
76
77
  @client.base.delete_app(@name)
77
78
 
78
79
  if @manifest
79
- @manifest.delete :meta
80
- @manifest.delete :version
81
- @manifest.delete :state
80
+ @diff = read_manifest
81
+ @manifest = nil
82
82
  end
83
83
  end
84
84
 
@@ -86,8 +86,8 @@ module CFoundry::V1
86
86
  #
87
87
  # Call this after setting the various attributes.
88
88
  def create!
89
- @client.base.create_app(@manifest.merge(:name => @name))
90
- @manifest = nil
89
+ @client.base.create_app(write_manifest)
90
+ @diff = {}
91
91
  end
92
92
 
93
93
  # Check if the application exists on the target.
@@ -112,13 +112,16 @@ module CFoundry::V1
112
112
 
113
113
  # Update application attributes. Does not restart the application.
114
114
  def update!(what = {})
115
- # bleh. have to set these here (normally in :meta) or they'll get lost.
116
- what[:debug] = debug_mode
117
- what[:staging] = (what[:staging] || {}).merge(manifest[:staging] || {})
118
- what[:staging][:command] = command if command
115
+ what.each do |k, v|
116
+ send(:"#{k}=", v)
117
+ end
118
+
119
+ @client.base.update_app(@name, write_manifest)
119
120
 
120
- @client.base.update_app(@name, manifest.merge(what))
121
121
  @manifest = nil
122
+ @diff = {}
123
+
124
+ self
122
125
  end
123
126
 
124
127
  # Stop the application.
@@ -146,8 +149,8 @@ module CFoundry::V1
146
149
  def health
147
150
  s = state
148
151
  if s == "STARTED"
149
- healthy_count = manifest[:runningInstances]
150
- expected = manifest[:instances]
152
+ healthy_count = running_instances
153
+ expected = total_instances
151
154
  if healthy_count && expected > 0
152
155
  ratio = healthy_count / expected.to_f
153
156
  if ratio == 1.0
@@ -184,51 +187,41 @@ module CFoundry::V1
184
187
  state == "STARTED"
185
188
  end
186
189
 
187
- def env
188
- e = manifest[:env] || []
189
-
190
- env = {}
191
- e.each do |pair|
192
- name, val = pair.split("=", 2)
193
- env[name] = val
194
- end
195
-
196
- CFoundry::ChattyHash.new(method(:env=), env)
197
- end
198
-
199
- def env=(hash)
200
- @manifest ||= {}
201
- @manifest[:env] = hash.collect { |k, v| "#{k}=#{v}" }
202
- end
203
-
204
- def services
205
- manifest[:services].collect do |name|
206
- @client.service_instance(name)
207
- end
208
- end
209
-
210
- def services=(instances)
211
- @manifest ||= {}
212
- @manifest[:services] = instances.collect(&:name)
213
- end
214
-
215
190
 
216
191
  { :total_instances => :instances,
192
+ :running_instances => :running_instances,
193
+ :runtime_name => :runtime,
194
+ :framework_name => :framework,
195
+ :service_names => :services,
196
+ :env_array => :env,
217
197
  :state => :state,
218
198
  :status => :state,
219
199
  :uris => :uris,
220
- :urls => :uris
200
+ :urls => :uris,
201
+ :command => :command,
202
+ :console => :console,
203
+ :memory => :memory,
204
+ :disk => :disk,
205
+ :fds => :fds,
206
+ :debug_mode => :debug,
207
+ :version => :version,
208
+ :meta_version => :meta_version,
209
+ :created => :created
221
210
  }.each do |meth, attr|
222
211
  define_method(meth) do
223
- manifest[attr]
212
+ if @diff.key?(attr)
213
+ @diff[attr]
214
+ else
215
+ read_manifest[attr]
216
+ end
224
217
  end
225
218
 
226
219
  define_method(:"#{meth}=") do |v|
227
- @manifest ||= {}
228
- @manifest[attr] = v
220
+ @diff[attr] = v
229
221
  end
230
222
  end
231
223
 
224
+
232
225
  # Shortcut for uris[0]
233
226
  def uri
234
227
  uris[0]
@@ -244,90 +237,48 @@ module CFoundry::V1
244
237
 
245
238
  # Application framework.
246
239
  def framework
247
- return unless manifest[:staging]
248
-
249
- Framework.new(
250
- manifest[:staging][:framework] ||
251
- manifest[:staging][:model])
240
+ Framework.new(framework_name)
252
241
  end
253
242
 
254
243
  def framework=(v) # :nodoc:
255
244
  v = v.name if v.is_a?(Framework)
256
-
257
- @manifest ||= {}
258
- @manifest[:staging] ||= {}
259
-
260
- if @manifest[:staging].key? :model
261
- @manifest[:staging][:model] = v
262
- else
263
- @manifest[:staging][:framework] = v
264
- end
245
+ self.framework_name = v
265
246
  end
266
247
 
267
248
  # Application runtime.
268
249
  def runtime
269
- return unless manifest[:staging]
270
-
271
- Framework.new(
272
- manifest[:staging][:runtime] ||
273
- manifest[:staging][:stack])
250
+ Runtime.new(runtime_name)
274
251
  end
275
252
 
276
253
  def runtime=(v) # :nodoc:
277
254
  v = v.name if v.is_a?(Runtime)
278
-
279
- @manifest ||= {}
280
- @manifest[:staging] ||= {}
281
-
282
- if @manifest[:staging].key? :stack
283
- @manifest[:staging][:stack] = v
284
- else
285
- @manifest[:staging][:runtime] = v
286
- end
287
- end
288
-
289
-
290
- # Application startup command.
291
- #
292
- # Used for standalone apps.
293
- def command
294
- return unless manifest[:staging] || manifest[:meta]
295
-
296
- manifest[:staging][:command] ||
297
- manifest[:meta][:command]
298
- end
299
-
300
- def command=(v) # :nodoc:
301
- @manifest ||= {}
302
- @manifest[:staging] ||= {}
303
- @manifest[:staging][:command] = v
255
+ self.runtime_name = v
304
256
  end
305
257
 
258
+ def env
259
+ e = env_array || []
306
260
 
307
- # Application memory.
308
- def memory
309
- return unless manifest[:resources]
261
+ env = {}
262
+ e.each do |pair|
263
+ name, val = pair.split("=", 2)
264
+ env[name] = val
265
+ end
310
266
 
311
- manifest[:resources][:memory]
267
+ CFoundry::ChattyHash.new(method(:env=), env)
312
268
  end
313
269
 
314
- def memory=(v) # :nodoc:
315
- @manifest ||= {}
316
- @manifest[:resources] ||= {}
317
- @manifest[:resources][:memory] = v
270
+ def env=(hash)
271
+ self.env_array = hash.collect { |k, v| "#{k}=#{v}" }
318
272
  end
319
273
 
320
-
321
- # Application debug mode.
322
- def debug_mode
323
- manifest.fetch(:debug) do
324
- manifest[:meta] && manifest[:meta][:debug]
274
+ def services
275
+ service_names.collect do |name|
276
+ @client.service_instance(name)
325
277
  end
326
278
  end
327
279
 
328
- def debug_mode=(v) # :nodoc:
329
- @manifest ||= {}
330
- @manifest[:debug] = v
280
+ def services=(instances)
281
+ self.service_names = instances.collect(&:name)
331
282
  end
332
283
 
333
284
 
@@ -415,6 +366,55 @@ module CFoundry::V1
415
366
  @manifest ||= @client.base.app(@name)
416
367
  end
417
368
 
369
+ def write_manifest
370
+ { :name => @name,
371
+ :instances => total_instances,
372
+ :state => state,
373
+ :env => env_array,
374
+ :uris => uris,
375
+ :version => version,
376
+ :services => service_names,
377
+ :staging => {
378
+ :model => framework_name,
379
+ :stack => runtime_name,
380
+ :command => command
381
+ },
382
+ :meta => {
383
+ :console => console,
384
+ :version => meta_version,
385
+ :debug => debug_mode,
386
+ :created => created
387
+ },
388
+ :resources => {
389
+ :memory => memory,
390
+ :disk => disk,
391
+ :fds => fds
392
+ },
393
+ :debug => debug_mode
394
+ }
395
+ end
396
+
397
+ def read_manifest
398
+ { :name => @name,
399
+ :instances => manifest[:instances],
400
+ :running_instances => manifest[:runningInstances],
401
+ :state => manifest[:state],
402
+ :env => manifest[:env],
403
+ :uris => manifest[:uris],
404
+ :version => manifest[:version],
405
+ :services => manifest[:services],
406
+ :framework => manifest[:staging][:model],
407
+ :runtime => manifest[:staging][:stack],
408
+ :console => manifest[:meta][:console],
409
+ :meta_version => manifest[:meta][:version],
410
+ :debug => manifest[:meta][:debug],
411
+ :created => manifest[:meta][:created],
412
+ :memory => manifest[:resources][:memory],
413
+ :disk => manifest[:resources][:disk],
414
+ :fds => manifest[:resources][:fds]
415
+ }
416
+ end
417
+
418
418
  def prepare_package(path, to)
419
419
  if path =~ /\.(jar|war|zip)$/
420
420
  CFoundry::Zip.unpack(path, to)
@@ -7,6 +7,6 @@ module CFoundry::V2
7
7
  to_one :service_plan
8
8
  to_many :service_bindings
9
9
  attribute :credentials
10
- attribute :vendor_data, :default => ""
10
+ attribute :gateway_data, :default => {}
11
11
  end
12
12
  end
@@ -1,4 +1,4 @@
1
1
  module CFoundry # :nodoc:
2
2
  # CFoundry library version number.
3
- VERSION = "0.3.14"
3
+ VERSION = "0.3.15"
4
4
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfoundry
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 14
10
- version: 0.3.14
9
+ - 15
10
+ version: 0.3.15
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Suraci
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-07-26 00:00:00 Z
18
+ date: 2012-07-29 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rest-client