hawkular-client 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGES.rdoc +5 -0
- data/README.rdoc +4 -4
- data/hawkularclient.gemspec +2 -3
- data/lib/hawkular.rb +14 -0
- data/lib/inventory/inventory_api.rb +67 -42
- data/lib/operations/operations_api.rb +2 -5
- data/lib/version.rb +1 -1
- data/spec/integration/inventory_spec.rb +119 -73
- data/spec/integration/operations_spec.rb +29 -54
- data/spec/spec_helper.rb +7 -7
- data/spec/vcr/vcr_setup.rb +0 -5
- data/spec/vcr_cassettes/Inventory/Should_create_a_nested_resource_and_metric_on_it.yml +731 -0
- data/spec/vcr_cassettes/Inventory/{Client_should_listen_on_various_inventory_events.yml → Should_list_children_of_nested_resource.yml} +36 -68
- data/spec/vcr_cassettes/Inventory/Should_return_config_data_of_given_nested_resource.yml +58 -0
- data/spec/vcr_cassettes/{Operation/Helpers/get_tenant.yml → Inventory/Should_return_config_data_of_given_resource.yml} +13 -6
- metadata +42 -87
- data/spec/vcr_cassettes/Inventory/Client_should_listen_on_various_inventory_events.json +0 -47
- data/spec/vcr_cassettes/Inventory/Helpers/generate_some_events_for_websocket.yml +0 -507
- data/spec/vcr_cassettes/Inventory/Tenants/Should_Get_Tenant_For_Explicit_Credentials.yml +0 -50
- data/spec/vcr_cassettes/Inventory/Tenants/Should_Get_Tenant_For_Implicit_Credentials.yml +0 -50
- data/spec/vcr_cassettes/Operation/Operation/Add_JDBC_driver_should_add_the_driver.json +0 -26
- data/spec/vcr_cassettes/Operation/Operation/Add_datasource_should_be_doable.json +0 -26
- data/spec/vcr_cassettes/Operation/Operation/Add_deployment_should_be_doable.json +0 -26
- data/spec/vcr_cassettes/Operation/Operation/Redeploy_can_be_run_multiple_times_in_parallel.json +0 -40
- data/spec/vcr_cassettes/Operation/Operation/Redeploy_should_be_performed_and_eventually_respond_with_success.json +0 -26
- data/spec/vcr_cassettes/Operation/Operation/Redeploy_should_not_be_performed_if_resource_path_is_wrong.json +0 -26
- data/spec/vcr_cassettes/Operation/Operation/Remove_JDBC_driver_should_be_performed_and_eventually_respond_with_success.json +0 -26
- data/spec/vcr_cassettes/Operation/Operation/Remove_datasource_should_be_performed_and_eventually_respond_with_success.json +0 -26
- data/spec/vcr_cassettes/Operation/Operation/Remove_deployment_should_be_performed_and_eventually_respond_with_success.json +0 -26
- data/spec/vcr_cassettes/Operation/Operation/Undeploy_should_be_performed_and_eventually_respond_with_success.json +0 -26
- data/spec/vcr_cassettes/Operation/Operation/should_not_be_possible_to_perform_on_closed_client.json +0 -12
- data/spec/vcr_cassettes/Operation/Websocket_connection/should_be_established.json +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3f91327af0cba7955ceeabb25999cafb2e29331
|
4
|
+
data.tar.gz: 8b6efcd11c9fbab70e57f4a36b6b4f8babafb38a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe4775cc86dff4e7778df1c6fafc48dda3da8581a2afcb02ed3f1be0a8c76ba251da0a7a49b60e17bcd816325b67fbaa0c9bfbd1f669a89679774f6d7b465ea6
|
7
|
+
data.tar.gz: 40143d8e9afefdb08eac2b1ff8ee0c6c9f4dd1116283cddf17a5fcb5869172380421d652ccebbdbb0f5e7899a4d157d682ac1230627e3cf842ef6575f9e2bc60
|
data/.travis.yml
CHANGED
data/CHANGES.rdoc
CHANGED
@@ -3,6 +3,11 @@
|
|
3
3
|
This document describes the relevant changes between releases of the
|
4
4
|
_hawkular-client_ project.
|
5
5
|
|
6
|
+
=== V 0.2.2
|
7
|
+
|
8
|
+
* Bug fix to correctly read resource info for resources that are not directly below a feed.
|
9
|
+
Issue #54[https://github.com/hawkular/hawkular-client-ruby/issues/54]
|
10
|
+
|
6
11
|
=== V 0.2.1
|
7
12
|
|
8
13
|
* Add support to create items in inventory
|
data/README.rdoc
CHANGED
@@ -13,7 +13,7 @@ A Ruby Hawkular Client.
|
|
13
13
|
* Start a feature/bugfix branch
|
14
14
|
* Commit and push until you are happy with your contribution
|
15
15
|
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
16
|
-
* Run your code through RuboCop (which is default when running
|
16
|
+
* Run your code through RuboCop (which is default when running `rake`) and fix complaints.
|
17
17
|
* When you open a pull request, watch out for failures on Travis.
|
18
18
|
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is
|
19
19
|
otherwise necessary, that is fine, but please isolate to its own commit so we can cherry-pick around it.
|
@@ -23,12 +23,12 @@ A Ruby Hawkular Client.
|
|
23
23
|
Integration tests are recorded and played against cassettes recorded with VCR
|
24
24
|
(http://www.relishapp.com/vcr/vcr/docs)
|
25
25
|
|
26
|
-
* Edit the endpoint properties in the file
|
26
|
+
* Edit the endpoint properties in the file `spec/endpoint.yml`(user, password and host name) if needed
|
27
27
|
* From command line run
|
28
28
|
rake spec
|
29
|
-
* To run the tests against a live server, set
|
29
|
+
* To run the tests against a live server, set VCR_OFF to 1 as in
|
30
30
|
VCR_OFF=1 rake spec
|
31
|
-
* To run the tests for operations against a live server using the WebSockets, set
|
31
|
+
* To run the tests for operations against a live server using the WebSockets, set WEBSOCKET_ON to 1 as in
|
32
32
|
WEBSOCKET_ON=1 rake spec
|
33
33
|
(WebSocket communication can't be recorded by VCR)
|
34
34
|
|
data/hawkularclient.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'version'
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = 'hawkular-client'
|
8
8
|
gem.version = Hawkular::VERSION
|
9
|
-
gem.authors = ['Libor Zoubek', 'Heiko W. Rupp', '
|
10
|
-
gem.email = %w(lzoubek@redhat.com hrupp@redhat.com
|
9
|
+
gem.authors = ['Libor Zoubek', 'Heiko W. Rupp', 'Federico Simoncelli']
|
10
|
+
gem.email = %w(lzoubek@redhat.com hrupp@redhat.com)
|
11
11
|
gem.homepage = 'https://github.com/hawkular/hawkular-client-ruby'
|
12
12
|
gem.summary = 'A Ruby client for Hawkular'
|
13
13
|
gem.license = 'ASL 2.0'
|
@@ -27,7 +27,6 @@ Gem::Specification.new do |gem|
|
|
27
27
|
gem.add_development_dependency('shoulda')
|
28
28
|
gem.add_development_dependency('rspec-rails', '~> 3.0')
|
29
29
|
gem.add_development_dependency('rake', '< 11')
|
30
|
-
gem.add_development_dependency('simple-websocket-vcr', '= 0.0.4')
|
31
30
|
gem.add_development_dependency('yard')
|
32
31
|
gem.add_development_dependency('webmock')
|
33
32
|
gem.add_development_dependency('vcr')
|
data/lib/hawkular.rb
CHANGED
@@ -47,6 +47,7 @@ module Hawkular
|
|
47
47
|
# as many ids inside Hawkular can contain characters
|
48
48
|
# that are invalid for an url/uri.
|
49
49
|
# The passed value is duplicated
|
50
|
+
# Does not escape the = character
|
50
51
|
# @param [String] url_part Part of an url to be escaped
|
51
52
|
# @return [String] escaped url_part as new string
|
52
53
|
def hawk_escape(url_part)
|
@@ -68,6 +69,19 @@ module Hawkular
|
|
68
69
|
sub_url
|
69
70
|
end
|
70
71
|
|
72
|
+
# Escapes the passed url part. This is necessary,
|
73
|
+
# as many ids inside Hawkular can contain characters
|
74
|
+
# that are invalid for an url/uri.
|
75
|
+
# The passed value is duplicated
|
76
|
+
# Does escape the = character
|
77
|
+
# @param [String] url_part Part of an url to be escaped
|
78
|
+
# @return [String] escaped url_part as new string
|
79
|
+
def hawk_escape_id(url_part)
|
80
|
+
sub_url = hawk_escape url_part
|
81
|
+
sub_url.gsub!('=', '%3d')
|
82
|
+
sub_url
|
83
|
+
end
|
84
|
+
|
71
85
|
def http_post(suburl, hash, headers = {})
|
72
86
|
body = JSON.generate(hash)
|
73
87
|
res = rest_client(suburl).post(body, http_headers(headers))
|
@@ -62,7 +62,7 @@ module Hawkular::Inventory
|
|
62
62
|
if feed.nil?
|
63
63
|
ret = http_get('/resourceTypes')
|
64
64
|
else
|
65
|
-
the_feed =
|
65
|
+
the_feed = hawk_escape_id feed
|
66
66
|
ret = http_get("/feeds/#{the_feed}/resourceTypes")
|
67
67
|
end
|
68
68
|
ret.map { |rt| ResourceType.new(rt) }
|
@@ -74,7 +74,7 @@ module Hawkular::Inventory
|
|
74
74
|
# @return [Array<Resource>] List of resources, which can be empty.
|
75
75
|
def list_resources_for_feed(feed, fetch_properties = false)
|
76
76
|
fail 'Feed must be given' unless feed
|
77
|
-
the_feed =
|
77
|
+
the_feed = hawk_escape_id feed
|
78
78
|
ret = http_get("/feeds/#{the_feed}/resources")
|
79
79
|
ret.map do |r|
|
80
80
|
if fetch_properties
|
@@ -95,12 +95,12 @@ module Hawkular::Inventory
|
|
95
95
|
# @return [Array<Resource>] List of resources. Can be empty
|
96
96
|
def list_resources_for_type(feed, type, fetch_properties = false)
|
97
97
|
fail 'Type must not be nil' unless type
|
98
|
-
the_type =
|
98
|
+
the_type = hawk_escape_id type
|
99
99
|
if feed.nil?
|
100
100
|
ret = http_get("resourceTypes/#{the_type}/resources")
|
101
101
|
else
|
102
102
|
|
103
|
-
the_feed =
|
103
|
+
the_feed = hawk_escape_id feed
|
104
104
|
ret = http_get("/feeds/#{the_feed}/resourceTypes/#{the_type}/resources")
|
105
105
|
end
|
106
106
|
ret.map do |r|
|
@@ -113,14 +113,18 @@ module Hawkular::Inventory
|
|
113
113
|
end
|
114
114
|
|
115
115
|
# Retrieve runtime properties for the passed resource
|
116
|
-
# @param [String]
|
117
|
-
# @param [String]
|
116
|
+
# @param [String] feed_id Feed of the resource
|
117
|
+
# @param [Array<String>] res_ids Ids of the resource to read properties from (parent to child order)
|
118
118
|
# @return [Hash<String,Object] Hash with additional data
|
119
|
-
def get_config_data_for_resource(
|
120
|
-
|
121
|
-
|
119
|
+
def get_config_data_for_resource(res_ids, feed_id)
|
120
|
+
resource_path = if res_ids.is_a?(Array)
|
121
|
+
res_ids.map { |id| hawk_escape_id id }.join('/')
|
122
|
+
else
|
123
|
+
hawk_escape_id res_ids
|
124
|
+
end
|
125
|
+
the_feed = hawk_escape_id feed_id
|
122
126
|
query = generate_query_params dataType: 'configuration'
|
123
|
-
http_get("feeds/#{the_feed}/resources/#{
|
127
|
+
http_get("feeds/#{the_feed}/resources/#{resource_path}/data#{query}")
|
124
128
|
rescue
|
125
129
|
{}
|
126
130
|
end
|
@@ -132,11 +136,11 @@ module Hawkular::Inventory
|
|
132
136
|
# @return [Array<Resource>] List of resources that are children of the given parent resource.
|
133
137
|
# Can be empty
|
134
138
|
def list_child_resources(parent_resource, recursive = false)
|
135
|
-
the_feed =
|
136
|
-
|
139
|
+
the_feed = hawk_escape_id parent_resource.feed
|
140
|
+
resource_path_escaped = CanonicalPath.parse(parent_resource.path).resource_ids.join('/')
|
137
141
|
|
138
142
|
which_children = (recursive ? '/recursiveChildren' : '/children')
|
139
|
-
ret = http_get("/feeds/#{the_feed}/resources/#{
|
143
|
+
ret = http_get("/feeds/#{the_feed}/resources/#{resource_path_escaped}#{which_children}")
|
140
144
|
ret.map { |r| Resource.new(r) }
|
141
145
|
end
|
142
146
|
|
@@ -155,7 +159,7 @@ module Hawkular::Inventory
|
|
155
159
|
# @param [String] named Name of the relationship
|
156
160
|
# @return [Array<Relationship>] List of relationships
|
157
161
|
def list_relationships_for_feed(feed_id, named = nil)
|
158
|
-
the_feed =
|
162
|
+
the_feed = hawk_escape_id feed_id
|
159
163
|
query = named.nil? ? '' : (generate_query_params named: named)
|
160
164
|
ret = http_get("/feeds/#{the_feed}/relationships#{query}")
|
161
165
|
ret.map { |r| Relationship.new(r) }
|
@@ -199,11 +203,11 @@ module Hawkular::Inventory
|
|
199
203
|
# @return [Array<Metric>] List of metrics. Can be empty
|
200
204
|
def list_metrics_for_metric_type(feed, type)
|
201
205
|
fail 'Type must not be nil' unless type
|
202
|
-
the_type =
|
206
|
+
the_type = hawk_escape_id type
|
203
207
|
if feed.nil?
|
204
208
|
type_hash = http_get("metricTypes/#{the_type}")
|
205
209
|
else
|
206
|
-
the_feed =
|
210
|
+
the_feed = hawk_escape_id feed
|
207
211
|
type_hash = http_get("/feeds/#{the_feed}/metricTypes/#{the_type}")
|
208
212
|
end
|
209
213
|
|
@@ -226,11 +230,11 @@ module Hawkular::Inventory
|
|
226
230
|
# @return [Array<Metric>] List of metrics. Can be empty
|
227
231
|
def list_metrics_for_resource_type(feed, type)
|
228
232
|
fail 'Type must not be nil' unless type
|
229
|
-
the_type =
|
233
|
+
the_type = hawk_escape_id type
|
230
234
|
if feed.nil?
|
231
235
|
ret = http_get("resourceTypes/#{the_type}/resources")
|
232
236
|
else
|
233
|
-
the_feed =
|
237
|
+
the_feed = hawk_escape_id feed
|
234
238
|
ret = http_get("feeds/#{the_feed}/resourceTypes/#{the_type}/resources")
|
235
239
|
end
|
236
240
|
ret.flat_map do |r|
|
@@ -259,10 +263,10 @@ module Hawkular::Inventory
|
|
259
263
|
# # Don't filter, return all metric definitions
|
260
264
|
# client.list_metrics_for_resource(wild_fly)
|
261
265
|
def list_metrics_for_resource(resource, filter = {})
|
262
|
-
the_feed =
|
263
|
-
|
266
|
+
the_feed = hawk_escape_id resource.feed
|
267
|
+
resource_path_escaped = CanonicalPath.parse(resource.path).resource_ids.join('/')
|
264
268
|
|
265
|
-
ret = http_get("/feeds/#{the_feed}/resources/#{
|
269
|
+
ret = http_get("/feeds/#{the_feed}/resources/#{resource_path_escaped}/metrics")
|
266
270
|
with_nils = ret.map do |m|
|
267
271
|
metric_new = Metric.new(m)
|
268
272
|
found = should_include?(metric_new, filter)
|
@@ -285,7 +289,7 @@ module Hawkular::Inventory
|
|
285
289
|
rescue HawkularException => error
|
286
290
|
# 409 We already exist -> that is ok
|
287
291
|
if error.status_code == 409
|
288
|
-
the_feed =
|
292
|
+
the_feed = hawk_escape_id feed_id
|
289
293
|
http_get("/feeds/#{the_feed}")
|
290
294
|
else
|
291
295
|
raise
|
@@ -296,7 +300,7 @@ module Hawkular::Inventory
|
|
296
300
|
# Delete the feed with the passed feed id.
|
297
301
|
# @param feed Id of the feed to be deleted.
|
298
302
|
def delete_feed(feed)
|
299
|
-
the_feed =
|
303
|
+
the_feed = hawk_escape_id feed
|
300
304
|
http_delete("/feeds/#{the_feed}")
|
301
305
|
end
|
302
306
|
|
@@ -306,7 +310,7 @@ module Hawkular::Inventory
|
|
306
310
|
# @param [String] type_name Name of the type
|
307
311
|
# @return [ResourceType] ResourceType object just created
|
308
312
|
def create_resource_type(feed_id, type_id, type_name)
|
309
|
-
the_feed =
|
313
|
+
the_feed = hawk_escape_id feed_id
|
310
314
|
|
311
315
|
type = create_blueprint
|
312
316
|
type[:id] = type_id
|
@@ -318,7 +322,7 @@ module Hawkular::Inventory
|
|
318
322
|
# 409 We already exist -> that is ok
|
319
323
|
raise unless error.status_code == 409
|
320
324
|
ensure
|
321
|
-
the_type =
|
325
|
+
the_type = hawk_escape_id type_id
|
322
326
|
res = http_get("/feeds/#{the_feed}/resourceTypes/#{the_type}")
|
323
327
|
end
|
324
328
|
ResourceType.new(res)
|
@@ -331,9 +335,22 @@ module Hawkular::Inventory
|
|
331
335
|
# @param [String] resource_id Id of the resource
|
332
336
|
# @param [String] resource_name Name of the resource
|
333
337
|
# @param [Hash<String,Object>] properties Additional properties. Those are not the config-properties
|
334
|
-
# TODO allow to create this as child of another resource
|
335
338
|
def create_resource(feed_id, type_path, resource_id, resource_name = nil, properties = {})
|
336
|
-
|
339
|
+
create_resource_under_resource(feed_id, type_path, [], resource_id, resource_name, properties)
|
340
|
+
end
|
341
|
+
|
342
|
+
# Create a resource of a given type under a given feed. To retrieve that resource
|
343
|
+
# you need to call {#get_resource}
|
344
|
+
# @param [String] feed_id Id of the feed to add the resource to
|
345
|
+
# @param [String] type_path Path of the resource type of this resource
|
346
|
+
# @param [Array<String>] parent_resource_ids Ids of the resources under which we create this resource
|
347
|
+
# (parent to child order)
|
348
|
+
# @param [String] resource_id Id of the resource
|
349
|
+
# @param [String] resource_name Name of the resource
|
350
|
+
# @param [Hash<String,Object>] properties Additional properties. Those are not the config-properties
|
351
|
+
def create_resource_under_resource(feed_id, type_path, parent_resource_ids, resource_id, resource_name = nil,
|
352
|
+
properties = {})
|
353
|
+
the_feed = hawk_escape_id feed_id
|
337
354
|
|
338
355
|
res = create_blueprint
|
339
356
|
res[:properties] = properties
|
@@ -342,26 +359,32 @@ module Hawkular::Inventory
|
|
342
359
|
res[:resourceTypePath] = type_path
|
343
360
|
|
344
361
|
begin
|
345
|
-
|
362
|
+
if parent_resource_ids.empty?
|
363
|
+
http_post("/feeds/#{the_feed}/resources", res)
|
364
|
+
else
|
365
|
+
parent_resource_path = parent_resource_ids.map { |id| hawk_escape_id id }.join('/')
|
366
|
+
http_post("/feeds/#{the_feed}/resources/#{parent_resource_path}", res)
|
367
|
+
end
|
346
368
|
rescue HawkularException => error
|
347
369
|
# 409 We already exist -> that is ok
|
348
370
|
raise unless error.status_code == 409
|
349
371
|
end
|
350
372
|
|
351
|
-
get_resource feed_id, resource_id, false
|
373
|
+
get_resource feed_id, parent_resource_ids << resource_id, false
|
352
374
|
end
|
353
375
|
|
354
376
|
# Return the resource object for the passed id
|
355
377
|
# @param [String] feed_id Id of the feed this resource belongs to
|
356
|
-
# @param [String]
|
378
|
+
# @param [Array<String>] res_ids Ids of the resource to fetch (parent to child order)
|
357
379
|
# @param [Boolean] fetch_resource_config Should the resource config data be fetched?
|
358
|
-
def get_resource(feed_id,
|
359
|
-
the_feed =
|
360
|
-
|
380
|
+
def get_resource(feed_id, res_ids, fetch_resource_config = true)
|
381
|
+
the_feed = hawk_escape_id feed_id
|
382
|
+
res_path = res_ids.is_a?(Array) ? (res_ids.map { |id| hawk_escape_id id }.join('/')) : hawk_escape_id(res_ids)
|
361
383
|
|
362
|
-
res = http_get("/feeds/#{the_feed}/resources/#{
|
384
|
+
res = http_get("/feeds/#{the_feed}/resources/#{res_path}")
|
363
385
|
if fetch_resource_config
|
364
|
-
p = get_config_data_for_resource(
|
386
|
+
p = get_config_data_for_resource(res_ids, feed_id)
|
387
|
+
res['properties'] ||= {}
|
365
388
|
res['properties'].merge p['value'] unless p['value'].nil?
|
366
389
|
end
|
367
390
|
Resource.new(res)
|
@@ -375,7 +398,7 @@ module Hawkular::Inventory
|
|
375
398
|
# @param [Numeric] collection_interval
|
376
399
|
# @return [MetricType] Type just created or the one from the server if it already existed.
|
377
400
|
def create_metric_type(feed_id, metric_type_id, type = 'GAUGE', unit = 'NONE', collection_interval = 60)
|
378
|
-
the_feed =
|
401
|
+
the_feed = hawk_escape_id feed_id
|
379
402
|
|
380
403
|
metric_kind = type.nil? ? 'GAUGE' : type.upcase
|
381
404
|
fail "Unknown type #{metric_kind}" unless %w(GAUGE COUNTER AVAILABILITY').include?(metric_kind)
|
@@ -398,16 +421,17 @@ module Hawkular::Inventory
|
|
398
421
|
# @param [String] feed_id Id of the feed
|
399
422
|
# @param [String] metric_id Id of the metric
|
400
423
|
# @param [String] type_path Full path of the MetricType
|
401
|
-
# @param [String]
|
424
|
+
# @param [Array<String>] res_ids Ids of the resource to associate the metric with (from parent to child)
|
402
425
|
# @param [String] metric_name a (display) name for the metric. If nil, #metric_id is used.
|
403
426
|
# @return [Metric] The metric created or if it already existed the version from the server
|
404
|
-
|
405
|
-
|
406
|
-
|
427
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
428
|
+
def create_metric_for_resource(feed_id, metric_id, type_path, res_ids, metric_name = nil)
|
429
|
+
the_feed = hawk_escape_id feed_id
|
430
|
+
res_path = res_ids.is_a?(Array) ? (res_ids.map { |id| hawk_escape_id id }.join('/')) : hawk_escape_id(res_ids)
|
407
431
|
|
408
432
|
m = {}
|
409
433
|
m['id'] = metric_id
|
410
|
-
m['name'] =
|
434
|
+
m['name'] = metric_name || metric_id
|
411
435
|
m['metricTypePath'] = type_path
|
412
436
|
|
413
437
|
begin
|
@@ -421,13 +445,14 @@ module Hawkular::Inventory
|
|
421
445
|
the_metric = Metric.new(ret)
|
422
446
|
|
423
447
|
begin
|
424
|
-
http_post("/feeds/#{the_feed}/resources/#{
|
448
|
+
http_post("/feeds/#{the_feed}/resources/#{res_path}/metrics", [the_metric.path])
|
425
449
|
rescue HawkularException => error
|
426
450
|
# 409 We already exist -> that is ok
|
427
451
|
raise unless error.status_code == 409
|
428
452
|
end
|
429
453
|
the_metric
|
430
454
|
end
|
455
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
431
456
|
|
432
457
|
# Listen on inventory changes
|
433
458
|
# @param [String] type Type of entity for which we want the events.
|
@@ -47,14 +47,12 @@ module Hawkular::Operations
|
|
47
47
|
#
|
48
48
|
# @option args [String] :host base url of Hawkular - e.g http://localhost:8080
|
49
49
|
# @option args [Hash{String=>String}] :credentials Hash of {username, password} or token
|
50
|
-
# @option args [Fixnum] :wait_time Time in seconds describing how long the constructor should block - handshake
|
51
50
|
#
|
52
51
|
# @example
|
53
52
|
# Hawkular::Operations::OperationsClient.new(credentials: {username: 'jdoe', password: 'password'})
|
54
53
|
def initialize(args)
|
55
54
|
args[:host] ||= 'localhost:8080'
|
56
55
|
args[:credentials] ||= {}
|
57
|
-
args[:wait_time] ||= 0.5
|
58
56
|
super(args[:host], args[:credentials])
|
59
57
|
# note: if we start using the secured WS, change the protocol to wss://
|
60
58
|
url = "ws://#{entrypoint}/hawkular/command-gateway/ui/ws"
|
@@ -68,7 +66,7 @@ module Hawkular::Operations
|
|
68
66
|
end
|
69
67
|
end
|
70
68
|
end
|
71
|
-
sleep
|
69
|
+
sleep 1
|
72
70
|
end
|
73
71
|
|
74
72
|
# Closes the WebSocket connection
|
@@ -204,7 +202,6 @@ module Hawkular::Operations
|
|
204
202
|
end
|
205
203
|
|
206
204
|
def handle_message(operation_name, operation_payload, &callback)
|
207
|
-
client = @ws
|
208
205
|
# register a callback handler
|
209
206
|
@ws.on :message do |msg|
|
210
207
|
parsed = msg.data.to_msg_hash
|
@@ -236,7 +233,7 @@ module Hawkular::Operations
|
|
236
233
|
|
237
234
|
def prepare_payload_hash(ignored_params, hash)
|
238
235
|
# it filters out ignored params and convert keys from snake_case to camelCase
|
239
|
-
|
236
|
+
hash.select { |k, _| !ignored_params.include? k }.map { |k, v| [to_camel_case(k.to_s).to_sym, v] }.to_h
|
240
237
|
end
|
241
238
|
|
242
239
|
def to_camel_case(str)
|
data/lib/version.rb
CHANGED
@@ -3,7 +3,7 @@ require "#{File.dirname(__FILE__)}/../spec_helper"
|
|
3
3
|
require 'securerandom'
|
4
4
|
|
5
5
|
module Hawkular::Inventory::RSpec
|
6
|
-
describe '
|
6
|
+
describe 'Tenants', :vcr do
|
7
7
|
it 'Should Get Tenant For Explicit Credentials' do
|
8
8
|
# get the client for given endpoint for given credentials
|
9
9
|
creds = { username: 'jdoe', password: 'password' }
|
@@ -120,6 +120,17 @@ module Hawkular::Inventory::RSpec
|
|
120
120
|
expect(children.size).to be(21)
|
121
121
|
end
|
122
122
|
|
123
|
+
it 'Should list children of nested resource' do
|
124
|
+
wildfly_res_id = 'Local~~'
|
125
|
+
datasource_res_id = 'Local~/subsystem=datasources/data-source=ExampleDS'
|
126
|
+
datasource = @client.get_resource(@state[:feed], [wildfly_res_id, datasource_res_id])
|
127
|
+
expect(datasource.name).to eq('ExampleDS')
|
128
|
+
|
129
|
+
children = @client.list_child_resources(datasource)
|
130
|
+
|
131
|
+
expect(children.size).to be(0)
|
132
|
+
end
|
133
|
+
|
123
134
|
it 'Should list recursive children of WildFly' do
|
124
135
|
resources = @client.list_resources_for_type(@state[:feed], 'WildFly Server')
|
125
136
|
wild_fly = resources[0]
|
@@ -166,6 +177,22 @@ module Hawkular::Inventory::RSpec
|
|
166
177
|
expect(metrics.size).to be(14)
|
167
178
|
end
|
168
179
|
|
180
|
+
it 'Should return config data of given resource' do
|
181
|
+
config = @client.get_config_data_for_resource('Local~~', @state[:feed])
|
182
|
+
|
183
|
+
expect(config['value']['Server State']).to eq('running')
|
184
|
+
expect(config['value']['Product Name']).to eq('Hawkular')
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'Should return config data of given nested resource' do
|
188
|
+
wildfly_res_id = 'Local~~'
|
189
|
+
datasource_res_id = 'Local~/subsystem=datasources/data-source=ExampleDS'
|
190
|
+
config = @client.get_config_data_for_resource([wildfly_res_id, datasource_res_id], @state[:feed])
|
191
|
+
|
192
|
+
expect(config['value']['Username']).to eq('sa')
|
193
|
+
expect(config['value']['Driver Name']).to eq('h2')
|
194
|
+
end
|
195
|
+
|
169
196
|
it 'Should create a feed' do
|
170
197
|
feed_id = 'feed_1123sdncisud6237ui23hjbdscuzsad'
|
171
198
|
ret = @client.create_feed feed_id
|
@@ -242,6 +269,30 @@ module Hawkular::Inventory::RSpec
|
|
242
269
|
expect(m.name).to eq('Metric1')
|
243
270
|
end
|
244
271
|
|
272
|
+
it 'Should create a nested resource and metric on it' do
|
273
|
+
new_feed_id = 'feed_may_exist'
|
274
|
+
@client.create_feed new_feed_id
|
275
|
+
ret = @client.create_resource_type new_feed_id, 'rt-123-1', 'ResourceType'
|
276
|
+
type_path = ret.path
|
277
|
+
|
278
|
+
@client.create_resource new_feed_id, type_path, 'r124-a', 'Res-a'
|
279
|
+
nested_resource = @client.create_resource_under_resource new_feed_id, type_path, ['r124-a'], 'r124-b', 'Res-a'
|
280
|
+
expect(nested_resource.path).to include('r;r124-a/r;r124-b')
|
281
|
+
|
282
|
+
mt = @client.create_metric_type new_feed_id, 'mt-124-a'
|
283
|
+
expect(mt).not_to be_nil
|
284
|
+
expect(mt.id).to eq('mt-124-a')
|
285
|
+
|
286
|
+
m_name = 'MetricUnderNestedResource'
|
287
|
+
m = @client.create_metric_for_resource new_feed_id, 'm-124-a', mt.path, %w(r124-a r124-b), m_name
|
288
|
+
expect(m.id).to eq('m-124-a')
|
289
|
+
expect(m.name).to eq(m_name)
|
290
|
+
|
291
|
+
metrics = @client.list_metrics_for_resource nested_resource
|
292
|
+
expect(metrics.size).to eq(1)
|
293
|
+
expect(metrics[0].id).to eq(m.id)
|
294
|
+
end
|
295
|
+
|
245
296
|
it 'Should create and get a resource' do
|
246
297
|
feed_id = 'feed_may_exist'
|
247
298
|
@client.create_feed feed_id
|
@@ -268,81 +319,76 @@ module Hawkular::Inventory::RSpec
|
|
268
319
|
expect { @client.create_metric_type feed_id, 'abc', 'FOOBaR' }.to raise_error(RuntimeError, /Unknown type FOOBAR/)
|
269
320
|
end
|
270
321
|
|
271
|
-
let(:example) do |e|
|
272
|
-
e
|
273
|
-
end
|
274
|
-
|
275
322
|
it 'Client should listen on various inventory events', :websocket do
|
276
|
-
VCR
|
277
|
-
|
323
|
+
# turn VCR off
|
324
|
+
VCR.eject_cassette
|
325
|
+
VCR.turn_off!(ignore_cassettes: true)
|
326
|
+
WebMock.allow_net_connect!
|
327
|
+
|
328
|
+
prefix = SecureRandom.uuid
|
329
|
+
id_1 = prefix + '-r126'
|
330
|
+
id_2 = prefix + '-r127'
|
331
|
+
id_3 = prefix + '-r128'
|
332
|
+
|
333
|
+
new_resource_events = {}
|
334
|
+
resources_closable = @client.events do |resource|
|
335
|
+
new_resource_events[resource.id] = resource
|
336
|
+
end
|
337
|
+
|
338
|
+
deleted_feed_events = {}
|
339
|
+
feed_deleted_closable = @client.events('feed', 'deleted') do |feed|
|
340
|
+
deleted_feed_events[feed.id] = feed
|
341
|
+
end
|
342
|
+
|
343
|
+
new_resource_types_events = {}
|
344
|
+
resource_type_closable = @client.events('resourcetype') do |resource_type|
|
345
|
+
new_resource_types_events[resource_type.id] = resource_type
|
278
346
|
end
|
279
347
|
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
@client.delete_feed feed_id
|
325
|
-
end
|
326
|
-
|
327
|
-
# wait for the data
|
328
|
-
sleep 2 if !VCR::WebSocket.cassette || VCR::WebSocket.cassette.recording?
|
329
|
-
[feed_deleted_closable, resource_type_closable, feeds_closable].each(&:close)
|
330
|
-
expect(new_resource_events[id_1]).not_to be_nil
|
331
|
-
expect(new_resource_events[id_1].properties['version']).to eq(1.0)
|
332
|
-
expect(new_resource_events[id_2]).not_to be_nil
|
333
|
-
expect(new_resource_events[id_2].properties['version']).to eq(1.1)
|
334
|
-
# resource with id_3 should not be among events, because we stopped listening before creating the 3rd one
|
335
|
-
expect(new_resource_events[id_3]).to be_nil
|
336
|
-
|
337
|
-
expect(registered_feed_events[feed_id]).not_to be_nil
|
338
|
-
expect(registered_feed_events[feed_id].id).to eq(feed_id)
|
339
|
-
|
340
|
-
expect(deleted_feed_events[feed_id]).not_to be_nil
|
341
|
-
expect(deleted_feed_events[feed_id].id).to eq(feed_id)
|
342
|
-
|
343
|
-
expect(new_resource_types_events[resource_type_id]).not_to be_nil
|
344
|
-
expect(new_resource_types_events[resource_type_id].id).to eq(resource_type_id)
|
345
|
-
expect(new_resource_types_events[resource_type_id].name).to eq(resource_type_name)
|
348
|
+
registered_feed_events = {}
|
349
|
+
feeds_closable = @client.events('feed', 'created') do |feed|
|
350
|
+
registered_feed_events[feed.id] = feed
|
351
|
+
end
|
352
|
+
|
353
|
+
feed_id = prefix + '-feed'
|
354
|
+
resource_type_id = prefix + '-rt-123'
|
355
|
+
resource_type_name = 'ResourceType'
|
356
|
+
@client.create_feed feed_id
|
357
|
+
ret = @client.create_resource_type feed_id, resource_type_id, resource_type_name
|
358
|
+
type_path = ret.path
|
359
|
+
|
360
|
+
# create 3 resources
|
361
|
+
@client.create_resource feed_id, type_path, id_1, 'My Resource 1', 'version' => 1.0
|
362
|
+
@client.create_resource feed_id, type_path, id_2, 'My Resource 2', 'version' => 1.1
|
363
|
+
resources_closable.close
|
364
|
+
@client.create_resource feed_id, type_path, id_3, 'My Resource 3', 'version' => 1.2
|
365
|
+
|
366
|
+
@client.delete_feed feed_id
|
367
|
+
|
368
|
+
# wait for the data
|
369
|
+
sleep 2
|
370
|
+
[feed_deleted_closable, resource_type_closable, feeds_closable].each(&:close)
|
371
|
+
expect(new_resource_events[id_1]).not_to be_nil
|
372
|
+
expect(new_resource_events[id_1].properties['version']).to eq(1.0)
|
373
|
+
expect(new_resource_events[id_2]).not_to be_nil
|
374
|
+
expect(new_resource_events[id_2].properties['version']).to eq(1.1)
|
375
|
+
# resource with id_3 should not be among events, because we stopped listening before creating the 3rd one
|
376
|
+
expect(new_resource_events[id_3]).to be_nil
|
377
|
+
|
378
|
+
expect(registered_feed_events[feed_id]).not_to be_nil
|
379
|
+
expect(registered_feed_events[feed_id].id).to eq(feed_id)
|
380
|
+
|
381
|
+
expect(deleted_feed_events[feed_id]).not_to be_nil
|
382
|
+
expect(deleted_feed_events[feed_id].id).to eq(feed_id)
|
383
|
+
|
384
|
+
expect(new_resource_types_events[resource_type_id]).not_to be_nil
|
385
|
+
expect(new_resource_types_events[resource_type_id].id).to eq(resource_type_id)
|
386
|
+
expect(new_resource_types_events[resource_type_id].name).to eq(resource_type_name)
|
387
|
+
|
388
|
+
# turn VCR on again if enabled
|
389
|
+
if ENV['VCR_OFF'] != '1'
|
390
|
+
VCR.turn_on!
|
391
|
+
WebMock.disable_net_connect!
|
346
392
|
end
|
347
393
|
end
|
348
394
|
|