tools-cf-plugin 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,127 @@
1
+ require "cf/cli"
2
+ require "nats/client"
3
+
4
+ module CFTools
5
+ class DEAApps < CF::App::Base
6
+ def precondition; end
7
+
8
+ desc "Show an overview of DEA advertisements over time."
9
+ group :admin
10
+ input :host, :alias => "-h", :default => "127.0.0.1",
11
+ :desc => "NATS server address"
12
+ input :port, :alias => "-P", :default => 4222, :type => :integer,
13
+ :desc => "NATS server port"
14
+ input :user, :alias => "-u", :default => "nats",
15
+ :desc => "NATS server user"
16
+ input :password, :alias => "-p", :default => "nats",
17
+ :desc => "NATS server password"
18
+ def dea_apps
19
+ @seen_apps = {}
20
+
21
+ host = input[:host]
22
+ port = input[:port]
23
+ user = input[:user]
24
+ pass = input[:password]
25
+
26
+ NATS.start(:uri => "nats://#{user}:#{pass}@#{host}:#{port}") do
27
+ NATS.subscribe("dea.advertise") do |msg|
28
+ payload = JSON.parse(msg)
29
+ dea_id = payload["id"]
30
+ advertisements[dea_id] = payload["app_id_to_count"]
31
+ end
32
+
33
+ EM.add_periodic_timer(3) do
34
+ render_table
35
+ end
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def client_app(guid)
42
+ existing_app =
43
+ if @seen_apps.key?(guid)
44
+ @seen_apps[guid]
45
+ else
46
+ app = client.app(guid, :depth => 2)
47
+ app if app.exists?
48
+ end
49
+
50
+ @seen_apps[guid] = existing_app
51
+ end
52
+
53
+ def advertisements
54
+ @advertisements ||= {}
55
+ end
56
+
57
+ def render_table
58
+ app_counts = Hash.new(0)
59
+ app_deas = Hash.new { |h, k| h[k] = [] }
60
+
61
+ advertisements.each do |dea_id, counts|
62
+ counts.each do |app_guid, count|
63
+ app_counts[app_guid] += count
64
+ app_deas[app_guid] << dea_id
65
+ end
66
+ end
67
+
68
+ rows = app_counts.sort_by { |app_guid, count|
69
+ app = client_app(app_guid)
70
+ app ? app.memory * count : 0
71
+ }.reverse.collect do |app_guid, count|
72
+ app = client_app(app_guid)
73
+
74
+ deas = list(app_deas[app_guid].collect(&:to_i).sort)
75
+
76
+ if app
77
+ [
78
+ "#{b(deas)}",
79
+ "#{c(app.name, :name)}",
80
+ "#{app.guid}",
81
+ "#{c(app.space.organization.name, :name)} / #{c(app.space.name, :name)}",
82
+ "#{human_mb(app.memory * count)}",
83
+ "(#{human_mb(app.memory)} x #{count})"
84
+ ]
85
+ else
86
+ [
87
+ "#{b(deas)}",
88
+ c("unknown", :warning),
89
+ "#{app_guid}",
90
+ "?",
91
+ "?",
92
+ "(? x #{count})"
93
+ ]
94
+ end
95
+ end
96
+
97
+ table(["dea", "app_name", "app_guid", "org/space", "reserved", "math"], rows)
98
+ end
99
+
100
+ def human_mb(mem)
101
+ human_size(mem * 1024 * 1024)
102
+ end
103
+
104
+ def human_size(num, precision = 0)
105
+ abs = num.abs
106
+
107
+ sizes = %w(T G M K)
108
+ sizes.each.with_index do |suf, i|
109
+ pow = sizes.size - i
110
+ unit = 1024.0 ** pow
111
+ if abs >= unit
112
+ return format("%.#{precision}f%s", num / unit, suf)
113
+ end
114
+ end
115
+
116
+ format("%.#{precision}fB", num)
117
+ end
118
+
119
+ def list(vals)
120
+ if vals.empty?
121
+ d("none")
122
+ else
123
+ vals.join(",")
124
+ end
125
+ end
126
+ end
127
+ end
@@ -1,5 +1,6 @@
1
1
  require "tools-cf-plugin/watch"
2
2
  require "tools-cf-plugin/shell"
3
3
  require "tools-cf-plugin/dea-ads"
4
+ require "tools-cf-plugin/dea-apps"
4
5
  require "tools-cf-plugin/tunnel/tunnel-nats"
5
6
  require "tools-cf-plugin/tunnel/watch-logs"
@@ -26,6 +26,12 @@ module CFTools
26
26
  rescue JSON::ParserError
27
27
  end
28
28
 
29
+ def data
30
+ json = JSON.parse(@line)
31
+ json["data"]
32
+ rescue JSON::ParserError
33
+ end
34
+
29
35
  def timestamp
30
36
  json = JSON.parse(@line)
31
37
 
@@ -44,6 +44,9 @@ module CFTools::Tunnel
44
44
  tunnel_to(nats["address"], nats["port"], gateway)
45
45
  end
46
46
 
47
+ line "port: #{nport}"
48
+ line "creds: #{nats}"
49
+
47
50
  with_progress("Logging in as admin user") do
48
51
  login_as_admin(manifest)
49
52
  end
@@ -66,7 +66,8 @@ module CFTools::Tunnel
66
66
  [ c(entry.label.ljust(max_label_size), :name),
67
67
  entry.timestamp.strftime("%r"),
68
68
  "#{pretty_log_level(log_level)}#{level_padding}",
69
- level_colored_message(entry)
69
+ level_colored_message(entry),
70
+ entry.data ? entry.data.inspect : ""
70
71
  ].join(" ")
71
72
  end
72
73
 
@@ -1,3 +1,3 @@
1
1
  module CFTools
2
- VERSION = "2.1.0".freeze
2
+ VERSION = "2.1.1".freeze
3
3
  end
@@ -65,47 +65,50 @@ module CFTools
65
65
  def process_message(sub, reply, msg, app)
66
66
  register_request(sub, reply) if reply
67
67
 
68
+ payload = JSON.parse(msg) # rescue msg
69
+
68
70
  case sub
69
71
  when "dea.advertise"
70
72
  return if app
71
- sub, msg = pretty_dea_advertise(sub, msg)
73
+ sub, payload = pretty_dea_advertise(sub, payload)
72
74
  when "staging.advertise"
73
75
  return if app
74
- sub, msg = pretty_staging_advertise(sub, msg)
76
+ sub, payload = pretty_staging_advertise(sub, payload)
75
77
  when "droplet.exited"
76
- sub, msg = pretty_exited(sub, msg)
78
+ sub, payload = pretty_exited(sub, payload)
77
79
  when "dea.heartbeat"
78
- sub, msg = pretty_heartbeat(sub, msg, app)
80
+ sub, payload = pretty_heartbeat(sub, payload, app)
79
81
  when "router.start"
80
- sub, msg = pretty_router_start(sub, msg)
82
+ sub, payload = pretty_router_start(sub, payload)
81
83
  when "router.register"
82
- sub, msg = pretty_register(sub, msg)
84
+ return if !app && payload.has_key?("dea")
85
+ sub, payload = pretty_register(sub, payload)
83
86
  when "router.unregister"
84
- sub, msg = pretty_unregister(sub, msg)
87
+ sub, payload = pretty_unregister(sub, payload)
85
88
  when /^dea\.(\d+)-.*\.start$/
86
- sub, msg = pretty_start(sub, msg, $1)
89
+ sub, payload = pretty_start(payload, $1)
87
90
  when "dea.stop"
88
- sub, msg = pretty_stop(sub, msg)
91
+ sub, payload = pretty_stop(sub, payload)
89
92
  when "droplet.updated"
90
- sub, msg = pretty_updated(sub, msg)
93
+ sub, payload = pretty_updated(sub, payload)
91
94
  when "dea.update"
92
- sub, msg = pretty_dea_update(sub, msg)
95
+ sub, payload = pretty_dea_update(sub, payload)
93
96
  when "dea.find.droplet"
94
- sub, msg = pretty_find_droplet(sub, msg)
97
+ sub, payload = pretty_find_droplet(sub, payload)
95
98
  when "healthmanager.status"
96
- sub, msg = pretty_healthmanager_status(sub, msg)
99
+ sub, payload = pretty_healthmanager_status(sub, payload)
97
100
  when "healthmanager.health"
98
- sub, msg = pretty_healthmanager_health(sub, msg)
101
+ sub, payload = pretty_healthmanager_health(sub, payload)
99
102
  when "dea.shutdown"
100
- sub, msg = pretty_dea_shutdown(sub, msg)
103
+ sub, payload = pretty_dea_shutdown(sub, payload)
101
104
  when /^cloudcontrollers\.hm\.requests\.\w+$/
102
- sub, msg = process_cloudcontrollers_hm_request(sub, msg)
105
+ sub, payload = process_cloudcontrollers_hm_request(payload)
103
106
  when /^([^.]+)\.announce$/
104
- sub, msg = pretty_service_announcement(sub, msg)
107
+ sub, payload = pretty_service_announcement(sub, payload)
105
108
  when "vcap.component.announce"
106
- sub, msg = pretty_component_announcement(sub, msg)
109
+ sub, payload = pretty_component_announcement(sub, payload)
107
110
  when "vcap.component.discover"
108
- sub, msg = pretty_component_discover(sub, msg)
111
+ sub, payload = pretty_component_discover(sub, payload)
109
112
  end
110
113
 
111
114
  if reply
@@ -114,28 +117,29 @@ module CFTools
114
117
  end
115
118
 
116
119
  sub = sub.ljust(COLUMN_WIDTH)
117
- line "#{timestamp}\t#{sub}\t#{msg}"
120
+ line "#{timestamp}\t#{sub}\t#{payload}"
118
121
  end
119
122
 
120
123
  def process_response(sub, _, msg, _)
124
+ payload = JSON.parse(msg) # rescue msg
125
+
121
126
  sub, id = @requests[sub]
122
127
 
123
128
  case sub
124
129
  when "dea.find.droplet"
125
- sub, msg = pretty_find_droplet_response(sub, msg)
130
+ sub, payload = pretty_find_droplet_response(sub, payload)
126
131
  when "healthmanager.status"
127
- sub, msg = pretty_healthmanager_status_response(sub, msg)
132
+ sub, payload = pretty_healthmanager_status_response(sub, payload)
128
133
  when "healthmanager.health"
129
- sub, msg = pretty_healthmanager_health_response(sub, msg)
134
+ sub, payload = pretty_healthmanager_health_response(sub, payload)
130
135
  when "vcap.component.discover"
131
- sub, msg = pretty_component_discover_response(sub, msg)
136
+ sub, payload = pretty_component_discover_response(sub, payload)
132
137
  end
133
138
 
134
- line "#{timestamp}\t#{REPLY_PREFIX}#{sub} (#{c(id, :error)})\t#{msg}"
139
+ line "#{timestamp}\t#{REPLY_PREFIX}#{sub} (#{c(id, :error)})\t#{payload}"
135
140
  end
136
141
 
137
- def pretty_dea_advertise(sub, msg)
138
- payload = JSON.parse(msg)
142
+ def pretty_dea_advertise(sub, payload)
139
143
  dea, _ = payload["id"].split("-", 2)
140
144
  [ d(sub),
141
145
  [ "dea: #{dea}",
@@ -146,8 +150,7 @@ module CFTools
146
150
  ]
147
151
  end
148
152
 
149
- def pretty_staging_advertise(sub, msg)
150
- payload = JSON.parse(msg)
153
+ def pretty_staging_advertise(sub, payload)
151
154
  dea, _ = payload["id"].split("-", 2)
152
155
  [ d(sub),
153
156
  [ "dea: #{dea}",
@@ -161,8 +164,7 @@ module CFTools
161
164
  list(counts.collect { |g, c| "#{c} x #{pretty_app(g)}" })
162
165
  end
163
166
 
164
- def pretty_exited(sub, msg)
165
- payload = JSON.parse(msg)
167
+ def pretty_exited(sub, payload)
166
168
  [ c(sub, :bad),
167
169
  [ "app: #{pretty_app(payload["droplet"])}",
168
170
  "reason: #{payload["reason"]}",
@@ -171,8 +173,7 @@ module CFTools
171
173
  ]
172
174
  end
173
175
 
174
- def pretty_heartbeat(sub, msg, app)
175
- payload = JSON.parse(msg)
176
+ def pretty_heartbeat(sub, payload, app)
176
177
 
177
178
  dea, _ = payload["dea"].split("-", 2)
178
179
 
@@ -189,14 +190,11 @@ module CFTools
189
190
  ]
190
191
  end
191
192
 
192
- def pretty_router_start(sub, msg)
193
- payload = JSON.parse(msg)
193
+ def pretty_router_start(sub, payload)
194
194
  [c(sub, :neutral), "hosts: #{list(payload["hosts"])}"]
195
195
  end
196
196
 
197
- def pretty_register(sub, msg)
198
- payload = JSON.parse(msg)
199
-
197
+ def pretty_register(sub, payload)
200
198
  message = []
201
199
 
202
200
  if (dea_id = payload["dea"])
@@ -213,9 +211,7 @@ module CFTools
213
211
  [c(sub, :neutral), message.join(", ")]
214
212
  end
215
213
 
216
- def pretty_unregister(sub, msg)
217
- payload = JSON.parse(msg)
218
-
214
+ def pretty_unregister(sub, payload)
219
215
  message = []
220
216
 
221
217
  if (dea_id = payload["dea"])
@@ -232,8 +228,7 @@ module CFTools
232
228
  [c(sub, :warning), message.join(", ")]
233
229
  end
234
230
 
235
- def pretty_start(sub, msg, dea)
236
- payload = JSON.parse(msg)
231
+ def pretty_start(payload, dea)
237
232
  [ c("dea.#{dea}.start", :good),
238
233
  [ "app: #{pretty_app(payload["droplet"])}",
239
234
  "dea: #{dea}",
@@ -243,9 +238,7 @@ module CFTools
243
238
  ]
244
239
  end
245
240
 
246
- def pretty_stop(sub, msg)
247
- payload = JSON.parse(msg)
248
-
241
+ def pretty_stop(sub, payload)
249
242
  message = ["app: #{pretty_app(payload["droplet"])}"]
250
243
 
251
244
  if (indices = payload["indices"])
@@ -259,8 +252,7 @@ module CFTools
259
252
  [c(sub, :warning), message.join(", ")]
260
253
  end
261
254
 
262
- def pretty_dea_update(sub, msg)
263
- payload = JSON.parse(msg)
255
+ def pretty_dea_update(sub, payload)
264
256
  [ d(sub),
265
257
  [ "app: #{pretty_app(payload["droplet"])}",
266
258
  "uris: #{list(payload["uris"])}"
@@ -268,8 +260,7 @@ module CFTools
268
260
  ]
269
261
  end
270
262
 
271
- def pretty_find_droplet(sub, msg)
272
- payload = JSON.parse(msg)
263
+ def pretty_find_droplet(sub, payload)
273
264
  states = payload["states"].collect { |s| c(s.downcase, state_color(s))}
274
265
  [ d(sub),
275
266
  [ "app: #{pretty_app(payload["droplet"])}",
@@ -278,8 +269,7 @@ module CFTools
278
269
  ]
279
270
  end
280
271
 
281
- def pretty_find_droplet_response(sub, msg)
282
- payload = JSON.parse(msg)
272
+ def pretty_find_droplet_response(sub, payload)
283
273
  dea, _ = payload["dea"].split("-", 2)
284
274
  index = payload["index"]
285
275
  state = payload["state"]
@@ -293,8 +283,7 @@ module CFTools
293
283
  ]
294
284
  end
295
285
 
296
- def pretty_healthmanager_status(sub, msg)
297
- payload = JSON.parse(msg)
286
+ def pretty_healthmanager_status(sub, payload)
298
287
  state = payload["state"]
299
288
  [ d(sub),
300
289
  [ "app: #{pretty_app(payload["droplet"])}",
@@ -303,19 +292,16 @@ module CFTools
303
292
  ]
304
293
  end
305
294
 
306
- def pretty_healthmanager_status_response(sub, msg)
307
- payload = JSON.parse(msg)
295
+ def pretty_healthmanager_status_response(sub, payload)
308
296
  [sub, "indices: #{list(payload["indices"])}"]
309
297
  end
310
298
 
311
- def pretty_healthmanager_health(sub, msg)
312
- payload = JSON.parse(msg)
299
+ def pretty_healthmanager_health(sub, payload)
313
300
  apps = payload["droplets"].collect { |d| pretty_app(d["droplet"]) }
314
301
  [d(sub), "querying health for: #{list(apps)}"]
315
302
  end
316
303
 
317
- def pretty_healthmanager_health_response(sub, msg)
318
- payload = JSON.parse(msg)
304
+ def pretty_healthmanager_health_response(sub, payload)
319
305
  [ sub,
320
306
  [ "app: #{pretty_app(payload["droplet"])}",
321
307
  "healthy: #{payload["healthy"]}"
@@ -323,14 +309,11 @@ module CFTools
323
309
  ]
324
310
  end
325
311
 
326
- def pretty_updated(sub, msg)
327
- payload = JSON.parse(msg)
312
+ def pretty_updated(sub, payload)
328
313
  [d(sub), "app: #{pretty_app(payload["droplet"])}"]
329
314
  end
330
315
 
331
- def pretty_dea_shutdown(sub, msg)
332
- payload = JSON.parse(msg)
333
-
316
+ def pretty_dea_shutdown(sub, payload)
334
317
  dea, _ = payload["id"].split("-", 2)
335
318
 
336
319
  apps = payload["app_id_to_count"].collect do |guid, count|
@@ -340,8 +323,7 @@ module CFTools
340
323
  [c(sub, :error), "dea: #{dea}, apps: #{list(apps)}"]
341
324
  end
342
325
 
343
- def process_cloudcontrollers_hm_request(sub, msg)
344
- payload = JSON.parse(msg)
326
+ def process_cloudcontrollers_hm_request(payload)
345
327
  last_updated = Time.at(payload["last_updated"])
346
328
 
347
329
  op = payload["op"]
@@ -362,8 +344,7 @@ module CFTools
362
344
  [c("hm.request", :warning), message.join(", ")]
363
345
  end
364
346
 
365
- def pretty_service_announcement(sub, msg)
366
- payload = JSON.parse(msg)
347
+ def pretty_service_announcement(sub, payload)
367
348
  id = payload["id"]
368
349
  plan = payload["plan"]
369
350
  c_unit = payload["capacity_unit"]
@@ -380,8 +361,7 @@ module CFTools
380
361
  ]
381
362
  end
382
363
 
383
- def pretty_component_announcement(sub, msg)
384
- payload = JSON.parse(msg)
364
+ def pretty_component_announcement(sub, payload)
385
365
  type = payload["type"]
386
366
  index = payload["index"]
387
367
  uuid = payload["uuid"]
@@ -396,12 +376,11 @@ module CFTools
396
376
  ]
397
377
  end
398
378
 
399
- def pretty_component_discover(sub, msg)
400
- [d(sub), msg]
379
+ def pretty_component_discover(sub, payload)
380
+ [d(sub), payload]
401
381
  end
402
382
 
403
- def pretty_component_discover_response(sub, msg)
404
- payload = JSON.parse(msg)
383
+ def pretty_component_discover_response(sub, payload)
405
384
  type = payload["type"]
406
385
  index = payload["index"]
407
386
  host = payload["host"]
@@ -440,7 +419,7 @@ module CFTools
440
419
  end
441
420
 
442
421
  if existing_app
443
- @seen_apps[guid] = existing_app
422
+ #@seen_apps[guid] = existing_app
444
423
  c(existing_app.name, :name)
445
424
  else
446
425
  @seen_apps[guid] = nil
@@ -0,0 +1,54 @@
1
+ require "spec_helper"
2
+
3
+ describe CFTools::DEAApps do
4
+ let(:app1) { fake :app, :name => "myapp1", :guid => "myappguid-1", :memory => 128, :total_instances => 4 }
5
+ let(:app2) { fake :app, :name => "myapp2", :guid => "myappguid-2", :memory => 256, :total_instances => 4 }
6
+ let(:app3) { fake :app, :name => "myapp3", :guid => "myappguid-3", :memory => 1024, :total_instances => 4 }
7
+ let(:client) { fake_client :apps => [app1, app2, app3] }
8
+
9
+ before { stub_client }
10
+
11
+ before {
12
+ app1.stub(:exists? => true)
13
+ app2.stub(:exists? => true)
14
+ app3.stub(:exists? => true)
15
+ }
16
+
17
+ before do
18
+ NATS.stub(:start).and_yield
19
+ NATS.stub(:subscribe)
20
+ EM.stub(:add_periodic_timer).and_yield
21
+ end
22
+
23
+ context "When a NATS message is recieved" do
24
+ let(:advertise) { <<PAYLOAD }
25
+ {
26
+ "app_id_to_count": {
27
+ "#{app1.guid}": #{app1.total_instances},
28
+ "#{app2.guid}": #{app2.total_instances},
29
+ "#{app3.guid}": #{app3.total_instances}
30
+ },
31
+ "available_memory": 1256,
32
+ "stacks": [
33
+ "lucid64",
34
+ "lucid86"
35
+ ],
36
+ "prod": false,
37
+ "id": "2-1d0cf3bcd994d9f2c5ea22b9b624d77b"
38
+ }
39
+ PAYLOAD
40
+
41
+ before do
42
+ NATS.stub(:subscribe).and_yield(advertise)
43
+ end
44
+
45
+ it "outputs the list of apps, memory and math" do
46
+ cf %W[dea-apps]
47
+ expect(output).to say(%r{app_name\s+app_guid\s+org/space\s+reserved\s+math})
48
+ expect(output).to say(%r{myapp3\s+myappguid-3\s+organization-\w+ / space-\w+\s+4G\s+\(1G\s+x\s+4\)})
49
+ expect(output).to say(%r{myapp2\s+myappguid-2\s+organization-\w+ / space-\w+\s+1G\s+\(256M\s+x\s+4\)})
50
+ expect(output).to say(%r{myapp1\s+myappguid-1\s+organization-\w+ / space-\w+\s+512M\s+\(128M\s+x\s+4\)})
51
+ end
52
+ end
53
+
54
+ end
@@ -91,7 +91,7 @@ module CFTools::Tunnel
91
91
 
92
92
  entry2 = LogEntry.new(
93
93
  "dea_next/1",
94
- %Q[{"message":"b","timestamp":#{entry2_time.to_f},"log_level":"warn"}],
94
+ %Q[{"message":"b","timestamp":#{entry2_time.to_f},"log_level":"warn","data":{"foo":"bar"}}],
95
95
  :stdout)
96
96
 
97
97
  entry3 = LogEntry.new(
@@ -103,9 +103,9 @@ module CFTools::Tunnel
103
103
 
104
104
  cf %W[watch-logs some-director.com]
105
105
 
106
- expect(output).to say("cloud_controller/0 01:02:03 AM info a\n")
107
- expect(output).to say("dea_next/1 01:02:04 AM warn b\n")
108
- expect(output).to say("dea_next/0 01:02:05 AM error c\n")
106
+ expect(output).to say("cloud_controller/0 01:02:03 AM info a \n")
107
+ expect(output).to say("dea_next/1 01:02:04 AM warn b {\"foo\"=>\"bar\"}\n")
108
+ expect(output).to say("dea_next/0 01:02:05 AM error c \n")
109
109
  end
110
110
 
111
111
  context "and components were specified" do
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe CFTools::Watch do
4
- let(:app) { fake :app, :name => "myapp", :guid => "myappguid" }
4
+ let!(:app) { fake :app, :name => "myapp", :guid => "myappguid" }
5
5
 
6
6
  let(:client) { fake_client :apps => [app] }
7
7
 
@@ -36,12 +36,12 @@ describe CFTools::Watch do
36
36
  context "when no application is given" do
37
37
  around { |example| Timecop.freeze(&example) }
38
38
 
39
- let(:messages) { [["some-message", nil, "some.subject"]] }
39
+ let(:messages) { [['{"some-message":"bar"}', nil, "some.subject"]] }
40
40
 
41
41
  it "prints a timestamp, message, and raw body" do
42
42
  cf %W[watch]
43
43
 
44
- expect(output).to say(/#{Time.now.strftime("%r")}\s*some.subject\s*some-message/)
44
+ expect(output).to say(/#{Time.now.strftime("%r")}\s*some.subject\s*{"some-message"=>"bar"}/)
45
45
  end
46
46
  end
47
47
 
@@ -79,16 +79,16 @@ describe CFTools::Watch do
79
79
  context "when a message comes in with a reply channel, followed by a reply" do
80
80
  let(:messages) do
81
81
  [
82
- ["foo", "some-reply", "some.subject"],
83
- ["some-response", nil, "some-reply"]
82
+ ['{"foo":"bar"}', "some-reply", "some.subject"],
83
+ ['{"some-response":"other"}', nil, "some-reply"]
84
84
  ]
85
85
  end
86
86
 
87
87
  it "registers it in #requests" do
88
88
  cf %W[watch]
89
89
 
90
- expect(output).to say(/some\.subject \(1\)\s*foo/)
91
- expect(output).to say(/`- reply to some\.subject \(1\)\s+some-response/)
90
+ expect(output).to say(/some\.subject \(1\)\s*{"foo"=>"bar"}/)
91
+ expect(output).to say(/`- reply to some\.subject \(1\)\s+{"some-response"=>"other"}/)
92
92
  end
93
93
  end
94
94
 
@@ -107,12 +107,12 @@ describe CFTools::Watch do
107
107
  context "and a message containing the app's GUID is seen" do
108
108
  around { |example| Timecop.freeze(&example) }
109
109
 
110
- let(:messages) { [["some-message-mentioning-#{app.guid}", nil, "some.subject"]] }
110
+ let(:messages) { [["{\"foo\":\"some-message-mentioning-#{app.guid}\"}", nil, "some.subject"]] }
111
111
 
112
112
  it "prints a timestamp, message, and raw body" do
113
113
  cf %W[watch myapp]
114
114
 
115
- expect(output).to say(/#{Time.now.strftime("%r")}\s*some.subject\s*some-message-mentioning-#{app.guid}/)
115
+ expect(output).to say(/#{Time.now.strftime("%r")}\s*some.subject\s*{"foo"=>"some-message-mentioning-#{app.guid}"}/)
116
116
  end
117
117
  end
118
118
 
@@ -303,8 +303,9 @@ PAYLOAD
303
303
  context "when a message is seen with subject router.register" do
304
304
  let(:subject) { "router.register" }
305
305
 
306
- context "when there's an associated DEA" do
307
- let(:payload) { <<PAYLOAD }
306
+ context "when the app flag is passed in" do
307
+ context "when there's an associated DEA" do
308
+ let(:payload) { <<PAYLOAD }
308
309
  {
309
310
  "private_instance_id": "e4a5ee2330c81fd7611eba7dbedbb499a00ae1b79f97f40a3603c8bff6fbcc6f",
310
311
  "tags": {},
@@ -319,10 +320,34 @@ PAYLOAD
319
320
  }
320
321
  PAYLOAD
321
322
 
322
- it "prints the uris, host, and port" do
323
+ it "prints the uris, host, and port" do
324
+ cf %W[watch --app #{app.name}]
325
+
326
+ expect(output).to say("app: myapp, dea: 1, uris: my-app.com, my-app-2.com, host: 192.0.43.10, port: 61111")
327
+ end
328
+ end
329
+ end
330
+
331
+ context "when the app flag is not passed in" do
332
+ let(:payload) { <<PAYLOAD }
333
+ {
334
+ "private_instance_id": "e4a5ee2330c81fd7611eba7dbedbb499a00ae1b79f97f40a3603c8bff6fbcc6f",
335
+ "tags": {},
336
+ "port": 61111,
337
+ "host": "192.0.43.10",
338
+ "uris": [
339
+ "my-app.com",
340
+ "my-app-2.com"
341
+ ],
342
+ "app": "some_unkown_guid",
343
+ "dea": "1-4b293b726167fbc895af5a7927c0973a"
344
+ }
345
+ PAYLOAD
346
+
347
+ it "does not print anything" do
323
348
  cf %W[watch]
324
349
 
325
- expect(output).to say("app: myapp, dea: 1, uris: my-app.com, my-app-2.com, host: 192.0.43.10, port: 61111")
350
+ expect(output).to_not say("uris: my-app.com, my-app-2.com, host: 192.0.43.10, port: 61111")
326
351
  end
327
352
  end
328
353
 
@@ -881,8 +906,8 @@ PAYLOAD
881
906
  {
882
907
  "start": "2013-05-24 17:58:08 +0000",
883
908
  "credentials": [
884
- "d34f205a31232eef040d1e39ebdd631a",
885
- "701e1a68a811a1ac8c137a70db08c1a8"
909
+ "user",
910
+ "pass"
886
911
  ],
887
912
  "host": "1.2.3.4:8080",
888
913
  "uuid": "1-deadbeef",
@@ -894,7 +919,7 @@ PAYLOAD
894
919
  it "does not include it in the message" do
895
920
  cf %W[watch]
896
921
 
897
- expect(output).to say("reply to vcap.component.discover (1)\ttype: login, index: 1, host: 1.2.3.4:8080")
922
+ expect(output).to say("reply to vcap.component.discover (1)\ttype: login, index: 1, uri: user:pass@1.2.3.4:8080")
898
923
  end
899
924
  end
900
925
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tools-cf-plugin
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-12 00:00:00.000000000 Z
12
+ date: 2013-06-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cfoundry
@@ -272,6 +272,7 @@ extra_rdoc_files: []
272
272
  files:
273
273
  - Rakefile
274
274
  - lib/tools-cf-plugin/dea-ads.rb
275
+ - lib/tools-cf-plugin/dea-apps.rb
275
276
  - lib/tools-cf-plugin/plugin.rb
276
277
  - lib/tools-cf-plugin/shell.rb
277
278
  - lib/tools-cf-plugin/tunnel/base.rb
@@ -283,6 +284,7 @@ files:
283
284
  - lib/tools-cf-plugin/version.rb
284
285
  - lib/tools-cf-plugin/watch.rb
285
286
  - spec/dea-ads_spec.rb
287
+ - spec/dea-apps_spec.rb
286
288
  - spec/shell_spec.rb
287
289
  - spec/spec_helper.rb
288
290
  - spec/tunnel/base_spec.rb
@@ -318,6 +320,7 @@ specification_version: 3
318
320
  summary: Cloud Foundry tooling commands.
319
321
  test_files:
320
322
  - spec/dea-ads_spec.rb
323
+ - spec/dea-apps_spec.rb
321
324
  - spec/shell_spec.rb
322
325
  - spec/spec_helper.rb
323
326
  - spec/tunnel/base_spec.rb
@@ -327,3 +330,4 @@ test_files:
327
330
  - spec/tunnel/tunnel-nats_spec.rb
328
331
  - spec/tunnel/watch-logs_spec.rb
329
332
  - spec/watch_spec.rb
333
+ has_rdoc: