hawkular-client 0.2.2 → 1.0.0

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.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/.yardopts +1 -0
  4. data/CHANGES.rdoc +17 -4
  5. data/README.rdoc +15 -6
  6. data/api_breaking_changes.rdoc +79 -0
  7. data/hawkularclient.gemspec +6 -5
  8. data/lib/{alerts → hawkular/alerts}/alerts_api.rb +168 -7
  9. data/lib/{hawkular.rb → hawkular/base_client.rb} +7 -44
  10. data/lib/hawkular/hawkular_client.rb +60 -0
  11. data/lib/hawkular/hawkular_client_utils.rb +40 -0
  12. data/lib/{inventory → hawkular/inventory}/inventory_api.rb +167 -142
  13. data/lib/{metrics → hawkular/metrics}/metric_api.rb +1 -0
  14. data/lib/{metrics → hawkular/metrics}/metrics_client.rb +4 -4
  15. data/lib/{metrics → hawkular/metrics}/tenant_api.rb +0 -0
  16. data/lib/{metrics → hawkular/metrics}/types.rb +0 -0
  17. data/lib/{operations → hawkular/operations}/operations_api.rb +11 -8
  18. data/lib/{tokens → hawkular/tokens}/tokens_api.rb +1 -1
  19. data/lib/{version.rb → hawkular/version.rb} +1 -1
  20. data/spec/integration/alerts_spec.rb +200 -0
  21. data/spec/integration/hawkular_client_spec.rb +228 -0
  22. data/spec/integration/inventory_spec.rb +246 -160
  23. data/spec/integration/metric_spec.rb +52 -59
  24. data/spec/integration/operations_spec.rb +53 -29
  25. data/spec/spec_helper.rb +109 -8
  26. data/spec/unit/base_spec.rb +9 -0
  27. data/spec/unit/canonical_path_spec.rb +2 -2
  28. data/spec/vcr/vcr_setup.rb +6 -0
  29. data/spec/vcr_cassettes/Alert/Events/Should_create_an_event.yml +50 -0
  30. data/spec/vcr_cassettes/Alert/Groups/Should_operate_a_complex_group_trigger.yml +1726 -0
  31. data/spec/vcr_cassettes/Counter_metrics/Should_get_metrics_as_bucketed_results.yml +190 -0
  32. data/spec/vcr_cassettes/Counter_metrics/Should_get_metrics_with_limit_and_order.yml +30 -42
  33. data/spec/vcr_cassettes/HawkularClient/and_Inventory_client/Should_both_create_and_delete_feed.yml +287 -0
  34. data/spec/vcr_cassettes/{Inventory/Should_list_URLs.yml → HawkularClient/and_Inventory_client/Should_both_list_WildFlys.yml} +35 -33
  35. data/spec/vcr_cassettes/{Inventory/Should_list_types_with_bad_feed.yml → HawkularClient/and_Inventory_client/Should_both_list_types_with_bad_feed.yml} +16 -19
  36. data/spec/vcr_cassettes/HawkularClient/and_Inventory_client/Should_list_same_types_when_param_is_given.yml +245 -0
  37. data/spec/vcr_cassettes/{Inventory/Should_list_feeds.yml → HawkularClient/and_Inventory_client/Should_list_the_same_feeds.yml} +20 -20
  38. data/spec/vcr_cassettes/HawkularClient/and_Inventory_client/Should_list_the_same_resource_types.yml +249 -0
  39. data/spec/vcr_cassettes/HawkularClient/and_Metrics_client/Should_both_create_and_retrieve_tags_for_Availability.yml +155 -0
  40. data/spec/vcr_cassettes/HawkularClient/and_Metrics_client/Should_both_create_and_return_Availability_using_Hash_parameter.yml +155 -0
  41. data/spec/vcr_cassettes/HawkularClient/and_Metrics_client/Should_both_return_the_version.yml +89 -0
  42. data/spec/vcr_cassettes/HawkularClient/and_Metrics_client/Should_both_work_the_same_way_when_pushing_metric_data_to_non-existing_counter.yml +114 -0
  43. data/spec/vcr_cassettes/{Inventory/Should_list_WildFlys_with_props.yml → HawkularClient/and_Operations_client/Should_both_work_the_same_way.yml} +28 -50
  44. data/spec/vcr_cassettes/HawkularClient/and_Operations_client_Should_both_work_the_same_way.json +44 -0
  45. data/spec/vcr_cassettes/Inventory/Helpers/create_url.yml +48 -0
  46. data/spec/vcr_cassettes/Inventory/Helpers/generate_some_events_for_websocket.yml +4446 -0
  47. data/spec/vcr_cassettes/Inventory/Helpers/get_feeds.yml +54 -0
  48. data/spec/vcr_cassettes/Inventory/Templates/Client_should_listen_on_various_inventory_events.json +47 -0
  49. data/spec/vcr_cassettes/Inventory/{Should_create_a_resourcetype.yml → Templates/Client_should_listen_on_various_inventory_events.yml} +47 -61
  50. data/spec/vcr_cassettes/Inventory/Templates/Helpers/generate_some_events_for_websocket.yml +542 -0
  51. data/spec/vcr_cassettes/Inventory/{Should_List_datasources_with_no_props.yml → Templates/Should_List_datasources_with_no_props.yml} +26 -85
  52. data/spec/vcr_cassettes/Inventory/Templates/Should_create_a_feed.yml +54 -0
  53. data/spec/vcr_cassettes/Inventory/Templates/Should_create_a_feed_again.yml +164 -0
  54. data/spec/vcr_cassettes/Inventory/{Should_create_a_nested_resource_and_metric_on_it.yml → Templates/Should_create_a_nested_resource_and_metric_on_it.yml} +93 -74
  55. data/spec/vcr_cassettes/Inventory/{Should_create_a_resource_.yml → Templates/Should_create_a_resource.yml} +103 -76
  56. data/spec/vcr_cassettes/Inventory/{Should_create_a_resource_with_metric.yml → Templates/Should_create_a_resource_with_metric.yml} +91 -197
  57. data/spec/vcr_cassettes/Inventory/Templates/Should_create_a_resourcetype.yml +154 -0
  58. data/spec/vcr_cassettes/Inventory/Templates/Should_create_and_delete_feed.yml +145 -0
  59. data/spec/vcr_cassettes/Inventory/{Should_create_and_get_a_resource.yml → Templates/Should_create_and_get_a_resource.yml} +35 -20
  60. data/spec/vcr_cassettes/Inventory/Templates/Should_list_URLs.yml +65 -0
  61. data/spec/vcr_cassettes/Inventory/Templates/Should_list_WildFlys.yml +61 -0
  62. data/spec/vcr_cassettes/Inventory/{Should_list_WildFlys.yml → Templates/Should_list_WildFlys_with_props.yml} +36 -33
  63. data/spec/vcr_cassettes/Inventory/Templates/Should_list_all_the_resource_types.yml +126 -0
  64. data/spec/vcr_cassettes/Inventory/{Should_list_children_of_WildFly.yml → Templates/Should_list_children_of_WildFly.yml} +66 -112
  65. data/spec/vcr_cassettes/Inventory/{Should_list_children_of_nested_resource.yml → Templates/Should_list_children_of_nested_resource.yml} +13 -13
  66. data/spec/vcr_cassettes/Inventory/Templates/Should_list_feeds.yml +54 -0
  67. data/spec/vcr_cassettes/Inventory/Templates/Should_list_heap_metrics_for_WildFlys.yml +712 -0
  68. data/spec/vcr_cassettes/Inventory/Templates/Should_list_metrics_for_WildFlys.yml +278 -0
  69. data/spec/vcr_cassettes/Inventory/Templates/Should_list_metrics_of_given_metric_type.yml +530 -0
  70. data/spec/vcr_cassettes/Inventory/Templates/Should_list_metrics_of_given_resource_type.yml +278 -0
  71. data/spec/vcr_cassettes/Inventory/Templates/Should_list_operation_definitions_of_given_resource.yml +185 -0
  72. data/spec/vcr_cassettes/Inventory/Templates/Should_list_operation_definitions_of_given_resource_type.yml +126 -0
  73. data/spec/vcr_cassettes/Inventory/Templates/Should_list_recursive_children_of_WildFly.yml +2369 -0
  74. data/spec/vcr_cassettes/Inventory/Templates/Should_list_relationships_of_WildFly.yml +415 -0
  75. data/spec/vcr_cassettes/Inventory/Templates/Should_list_types_with_bad_feed.yml +51 -0
  76. data/spec/vcr_cassettes/Inventory/Templates/Should_list_types_with_feed.yml +124 -0
  77. data/spec/vcr_cassettes/Inventory/{Should_not_find_an_unknown_resource.yml → Templates/Should_not_find_an_unknown_resource.yml} +14 -13
  78. data/spec/vcr_cassettes/Inventory/{Should_return_config_data_of_given_nested_resource.yml → Templates/Should_return_config_data_of_given_nested_resource.yml} +4 -4
  79. data/spec/vcr_cassettes/Inventory/{Should_return_config_data_of_given_resource.yml → Templates/Should_return_config_data_of_given_resource.yml} +4 -4
  80. data/spec/vcr_cassettes/Inventory/Tenants/Should_Get_Tenant_For_Explicit_Credentials.yml +50 -0
  81. data/spec/vcr_cassettes/Inventory/Tenants/Should_Get_Tenant_For_Implicit_Credentials.yml +50 -0
  82. data/spec/vcr_cassettes/Operation/Helpers/get_feed.yml +54 -0
  83. data/spec/vcr_cassettes/Operation/Helpers/get_tenant.yml +50 -0
  84. data/spec/vcr_cassettes/Operation/Operation/Add_JDBC_driver_should_add_the_driver.json +26 -0
  85. data/spec/vcr_cassettes/Operation/Operation/Add_datasource_should_be_doable.json +26 -0
  86. data/spec/vcr_cassettes/Operation/Operation/Add_deployment_should_be_doable.json +26 -0
  87. data/spec/vcr_cassettes/Operation/Operation/Redeploy_can_be_run_multiple_times_in_parallel.json +40 -0
  88. data/spec/vcr_cassettes/Operation/Operation/Redeploy_should_be_performed_and_eventually_respond_with_success.json +26 -0
  89. data/spec/vcr_cassettes/Operation/Operation/Redeploy_should_not_be_performed_if_resource_path_is_wrong.json +26 -0
  90. data/spec/vcr_cassettes/Operation/Operation/Remove_JDBC_driver_should_be_performed_and_eventually_respond_with_success.json +26 -0
  91. data/spec/vcr_cassettes/Operation/Operation/Remove_datasource_should_be_performed_and_eventually_respond_with_success.json +26 -0
  92. data/spec/vcr_cassettes/Operation/Operation/Remove_deployment_should_be_performed_and_eventually_respond_with_success.json +26 -0
  93. data/spec/vcr_cassettes/Operation/Operation/Undeploy_should_be_performed_and_eventually_respond_with_success.json +26 -0
  94. data/spec/vcr_cassettes/Operation/Operation/should_not_be_possible_to_perform_on_closed_client.json +12 -0
  95. data/spec/vcr_cassettes/Operation/Websocket_connection/should_be_established.json +9 -0
  96. metadata +171 -72
  97. data/lib/hawkular_all.rb +0 -9
  98. data/spec/vcr_cassettes/Inventory/Should_create_a_feed.yml +0 -107
  99. data/spec/vcr_cassettes/Inventory/Should_create_a_feed_again.yml +0 -211
  100. data/spec/vcr_cassettes/Inventory/Should_create_and_delete_feed.yml +0 -201
  101. data/spec/vcr_cassettes/Inventory/Should_list_all_the_resource_types.yml +0 -177
  102. data/spec/vcr_cassettes/Inventory/Should_list_heap_metrics_for_WildFlys.yml +0 -775
  103. data/spec/vcr_cassettes/Inventory/Should_list_metrics_for_WildFlys.yml +0 -333
  104. data/spec/vcr_cassettes/Inventory/Should_list_metrics_of_given_metric_type.yml +0 -613
  105. data/spec/vcr_cassettes/Inventory/Should_list_metrics_of_given_resource_type.yml +0 -333
  106. data/spec/vcr_cassettes/Inventory/Should_list_recursive_children_of_WildFly.yml +0 -2064
  107. data/spec/vcr_cassettes/Inventory/Should_list_relationships_of_WildFly.yml +0 -460
  108. data/spec/vcr_cassettes/Inventory/Should_list_types_with_feed.yml +0 -175
@@ -3,7 +3,8 @@ require "#{File.dirname(__FILE__)}/../spec_helper"
3
3
  require 'securerandom'
4
4
 
5
5
  module Hawkular::Inventory::RSpec
6
- describe 'Tenants', :vcr do
6
+ include Hawkular::Inventory
7
+ describe 'Inventory/Tenants', vcr: { decode_compressed_response: true } do
7
8
  it 'Should Get Tenant For Explicit Credentials' do
8
9
  # get the client for given endpoint for given credentials
9
10
  creds = { username: 'jdoe', password: 'password' }
@@ -25,24 +26,71 @@ module Hawkular::Inventory::RSpec
25
26
  end
26
27
  end
27
28
 
28
- describe 'Inventory', vcr: { decode_compressed_response: true } do
29
+ describe 'Inventory' do
30
+ URL_RESOURCE = 'http://bsd.de'
31
+
29
32
  before(:all) do
30
33
  @creds = {
31
34
  username: 'jdoe',
32
35
  password: 'password'
33
36
  }
34
37
  @client = Hawkular::Inventory::InventoryClient.create(credentials: @creds)
35
- @state = {
36
- hostname: 'localhost.localdomain',
37
- feed: nil
38
- }
38
+ options = { decode_compressed_response: true }
39
+ options[:record] = :all if ENV['VCR_UPDATE'] == '1'
40
+ VCR.use_cassette('Inventory/Helpers/get_feeds', options) do
41
+ feeds = @client.list_feeds
42
+ @state = {
43
+ feed_uuid: feeds[0]
44
+ }
45
+ end
46
+
47
+ # create 1 URL resource and its metrics
48
+ VCR.use_cassette('Inventory/Helpers/create_url', options) do
49
+ rest_client = RestClient::Resource.new('http://localhost:8080/hawkular/api/urls',
50
+ user: @creds[:username],
51
+ password: @creds[:password]
52
+ )
53
+ url_json = {
54
+ url: URL_RESOURCE
55
+ }.to_json
56
+
57
+ begin
58
+ rest_client.post(url_json, content_type: 'application/json')
59
+ rescue
60
+ puts 'failed to create the url'
61
+ # no big deal, the url is probably already there
62
+ end
63
+ end
64
+
65
+ sleep 2 if ENV['VCR_UPDATE'] == '1' || ENV['VCR_OFF'] == '1'
66
+ end
67
+
68
+ after(:all) do
69
+ require 'fileutils'
70
+ FileUtils.rm_rf "#{VCR.configuration.cassette_library_dir}/Inventory/tmp"
71
+ end
72
+
73
+ let(:cassette_name) do |example|
74
+ description = example.description
75
+ description
76
+ end
77
+
78
+ let(:feed_id) do
79
+ @state[:feed_uuid]
80
+ end
81
+
82
+ let(:wildfly_type) do
83
+ CanonicalPath.new(feed_id: feed_id, resource_type_id: hawk_escape_id('WildFly Server'))
84
+ end
85
+
86
+ around(:each) do |example|
87
+ record('Inventory', @state, cassette_name, example: example)
39
88
  end
40
89
 
41
90
  it 'Should list feeds' do
42
91
  feeds = @client.list_feeds
43
92
 
44
93
  expect(feeds.size).to be(1)
45
- @state[:feed] = feeds[0] unless feeds[0].nil?
46
94
  end
47
95
 
48
96
  it 'Should list all the resource types' do
@@ -51,7 +99,7 @@ module Hawkular::Inventory::RSpec
51
99
  end
52
100
 
53
101
  it 'Should list types with feed' do
54
- types = @client.list_resource_types(@state[:feed])
102
+ types = @client.list_resource_types(feed_id)
55
103
 
56
104
  expect(types.size).to be(18)
57
105
  end
@@ -65,7 +113,7 @@ module Hawkular::Inventory::RSpec
65
113
  end
66
114
 
67
115
  it 'Should list WildFlys' do
68
- resources = @client.list_resources_for_type(@state[:feed], 'WildFly Server')
116
+ resources = @client.list_resources_for_type(wildfly_type.to_s)
69
117
 
70
118
  expect(resources.size).to be(1)
71
119
  wf = resources.first
@@ -73,15 +121,16 @@ module Hawkular::Inventory::RSpec
73
121
  end
74
122
 
75
123
  it 'Should list WildFlys with props' do
76
- resources = @client.list_resources_for_type(@state[:feed], 'WildFly Server', true)
124
+ resources = @client.list_resources_for_type(wildfly_type.to_s, fetch_properties: true)
77
125
 
78
126
  expect(resources.size).to be(1)
79
127
  wf = resources.first
80
- expect(wf.properties['Hostname']).to eq(@state[:hostname])
128
+ expect(wf.properties['Hostname']).not_to be_empty
81
129
  end
82
130
 
83
131
  it 'Should List datasources with no props' do
84
- resources = @client.list_resources_for_type(@state[:feed], 'Datasource', true)
132
+ type_path = CanonicalPath.new(feed_id: feed_id, resource_type_id: hawk_escape_id('Datasource'))
133
+ resources = @client.list_resources_for_type(type_path.to_s, fetch_properties: true)
85
134
 
86
135
  expect(resources.size).to be(2)
87
136
  wf = resources.first
@@ -89,181 +138,204 @@ module Hawkular::Inventory::RSpec
89
138
  end
90
139
 
91
140
  it 'Should list URLs' do
92
- resources = @client.list_resources_for_type(nil, 'URL')
141
+ type_path = CanonicalPath.new(resource_type_id: hawk_escape_id('URL'))
142
+ resources = @client.list_resources_for_type(type_path.to_s)
93
143
 
94
144
  expect(resources.size).to be(1)
95
145
  resource = resources[0]
96
146
  expect(resource.instance_of? Hawkular::Inventory::Resource).to be_truthy
97
- expect(resource.properties.size).to be(6)
98
- expect(resource.properties['url']).to eq('http://bsd.de')
147
+ # depends how pinger is fast
148
+ expect(2..6).to cover(resource.properties.size)
149
+ expect(resource.properties['url']).to eq(URL_RESOURCE)
99
150
  end
100
151
 
101
152
  it 'Should list metrics for WildFlys' do
102
- resources = @client.list_resources_for_type(@state[:feed], 'WildFly Server')
103
- expect(resources.size).to be(1)
104
-
153
+ resources = @client.list_resources_for_type(wildfly_type.to_s)
105
154
  wild_fly = resources[0]
106
155
 
107
- metrics = @client.list_metrics_for_resource(wild_fly)
156
+ metrics = @client.list_metrics_for_resource(wild_fly.path)
108
157
 
109
158
  expect(metrics.size).to be(14)
110
159
  end
111
160
 
112
161
  it 'Should list children of WildFly' do
113
- resources = @client.list_resources_for_type(@state[:feed], 'WildFly Server')
114
- expect(resources.size).to be(1)
115
-
162
+ resources = @client.list_resources_for_type(wildfly_type.to_s)
116
163
  wild_fly = resources[0]
117
164
 
118
- children = @client.list_child_resources(wild_fly)
165
+ children = @client.list_child_resources(wild_fly.path)
119
166
 
120
- expect(children.size).to be(21)
167
+ expect(children.size).to be(22)
121
168
  end
122
169
 
123
170
  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])
171
+ wildfly_res_id = hawk_escape_id 'Local~~'
172
+ datasource_res_id = hawk_escape_id 'Local~/subsystem=datasources/data-source=ExampleDS'
173
+ resource_path = CanonicalPath.new(feed_id: feed_id, resource_ids: [wildfly_res_id, datasource_res_id])
174
+ datasource = @client.get_resource(resource_path.to_s)
127
175
  expect(datasource.name).to eq('ExampleDS')
128
176
 
129
- children = @client.list_child_resources(datasource)
177
+ children = @client.list_child_resources(datasource.path)
130
178
 
131
179
  expect(children.size).to be(0)
132
180
  end
133
181
 
134
182
  it 'Should list recursive children of WildFly' do
135
- resources = @client.list_resources_for_type(@state[:feed], 'WildFly Server')
183
+ resources = @client.list_resources_for_type(wildfly_type.to_s)
136
184
  wild_fly = resources[0]
137
185
 
138
- children = @client.list_child_resources(wild_fly, recursive: true)
186
+ children = @client.list_child_resources(wild_fly.path, recursive: true)
139
187
 
140
- expect(children.size).to be(211)
188
+ expect(children.size).to be(251)
141
189
  end
142
190
 
143
191
  it 'Should list relationships of WildFly' do
144
- resources = @client.list_resources_for_type(@state[:feed], 'WildFly Server')
192
+ resources = @client.list_resources_for_type(wildfly_type.to_s)
145
193
  wild_fly = resources[0]
146
194
 
147
- rels = @client.list_relationships(wild_fly)
195
+ rels = @client.list_relationships(wild_fly.path)
148
196
 
149
- expect(rels.size).to be(59)
197
+ expect(rels.size).to be(61)
150
198
  end
151
199
 
152
200
  it 'Should list heap metrics for WildFlys' do
153
- resources = @client.list_resources_for_type(@state[:feed], 'WildFly Server')
154
- expect(resources.size).to be(1)
155
-
201
+ resources = @client.list_resources_for_type(wildfly_type.to_s)
156
202
  wild_fly = resources[0]
157
203
 
158
- metrics = @client.list_metrics_for_resource(wild_fly, type: 'GAUGE', match: 'Metrics~Heap')
204
+ metrics = @client.list_metrics_for_resource(wild_fly.path, type: 'GAUGE', match: 'Metrics~Heap')
159
205
  expect(metrics.size).to be(3)
160
206
 
161
- metrics = @client.list_metrics_for_resource(wild_fly, match: 'Metrics~Heap')
207
+ metrics = @client.list_metrics_for_resource(wild_fly.path, match: 'Metrics~Heap')
162
208
  expect(metrics.size).to be(3)
163
209
 
164
- metrics = @client.list_metrics_for_resource(wild_fly, type: 'GAUGE')
210
+ metrics = @client.list_metrics_for_resource(wild_fly.path, type: 'GAUGE')
165
211
  expect(metrics.size).to be(8)
166
212
  end
167
213
 
168
214
  it 'Should list metrics of given metric type' do
169
- metrics = @client.list_metrics_for_metric_type(@state[:feed], 'Total Space')
215
+ type_path = CanonicalPath.new(feed_id: feed_id, metric_type_id: hawk_escape_id('Total Space'))
216
+ metrics = @client.list_metrics_for_metric_type(type_path)
170
217
 
171
218
  expect(metrics.size).to be(7)
172
219
  end
173
220
 
174
221
  it 'Should list metrics of given resource type' do
175
- metrics = @client.list_metrics_for_resource_type(@state[:feed], 'WildFly Server')
222
+ metrics = @client.list_metrics_for_resource_type(wildfly_type.to_s)
176
223
 
177
224
  expect(metrics.size).to be(14)
178
225
  end
179
226
 
180
227
  it 'Should return config data of given resource' do
181
- config = @client.get_config_data_for_resource('Local~~', @state[:feed])
228
+ resource_path = CanonicalPath.new(feed_id: feed_id, resource_ids: [hawk_escape_id('Local~~')])
229
+ config = @client.get_config_data_for_resource(resource_path)
182
230
 
183
231
  expect(config['value']['Server State']).to eq('running')
184
232
  expect(config['value']['Product Name']).to eq('Hawkular')
185
233
  end
186
234
 
187
235
  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])
236
+ wildfly_res_id = hawk_escape_id 'Local~~'
237
+ datasource_res_id = hawk_escape_id 'Local~/subsystem=datasources/data-source=ExampleDS'
238
+ resource_path = CanonicalPath.new(feed_id: feed_id, resource_ids: [wildfly_res_id, datasource_res_id])
239
+
240
+ config = @client.get_config_data_for_resource(resource_path)
191
241
 
192
242
  expect(config['value']['Username']).to eq('sa')
193
243
  expect(config['value']['Driver Name']).to eq('h2')
194
244
  end
195
245
 
246
+ it 'Should list operation definitions of given resource type' do
247
+ operation_definitions = @client.list_operation_definitions(wildfly_type.to_s)
248
+
249
+ expect(operation_definitions).not_to be_empty
250
+ expect(operation_definitions).to include('JDR')
251
+ expect(operation_definitions).to include('Reload')
252
+ expect(operation_definitions).to include('Shutdown')
253
+ expect(operation_definitions).to include('Deploy')
254
+ end
255
+
256
+ it 'Should list operation definitions of given resource' do
257
+ resources = @client.list_resources_for_type(wildfly_type.to_s)
258
+ wild_fly = resources[0]
259
+ operation_definitions = @client.list_operation_definitions_for_resource(wild_fly.path.to_s)
260
+
261
+ expect(operation_definitions).not_to be_empty
262
+ expect(operation_definitions).to include('JDR')
263
+ end
264
+
196
265
  it 'Should create a feed' do
197
- feed_id = 'feed_1123sdncisud6237ui23hjbdscuzsad'
198
- ret = @client.create_feed feed_id
266
+ new_feed_id = 'feed_1123sdncisud6237ui23hjbdscuzsad'
267
+ ret = @client.create_feed new_feed_id
199
268
  expect(ret).to_not be_nil
200
- expect(ret['id']).to eq(feed_id)
269
+ expect(ret['id']).to eq(new_feed_id)
201
270
  end
202
271
 
203
272
  it 'Should create and delete feed' do
204
- feed_id = 'feed_1123sdn'
205
- ret = @client.create_feed feed_id
273
+ new_feed_id = 'feed_1123sdn'
274
+ ret = @client.create_feed new_feed_id
206
275
  expect(ret).to_not be_nil
207
- expect(ret['id']).to eq(feed_id)
276
+ expect(ret['id']).to eq(new_feed_id)
208
277
 
209
- @client.delete_feed feed_id
278
+ @client.delete_feed new_feed_id
210
279
 
211
280
  feed_list = @client.list_feeds
212
- expect(feed_list).not_to include(feed_id)
281
+ expect(feed_list).not_to include(new_feed_id)
213
282
  end
214
283
 
215
284
  it 'Should create a feed again' do
216
- feed_id = 'feed_1123sdncisud6237ui2378789vvgX'
217
- @client.create_feed feed_id
218
- @client.create_feed feed_id
285
+ new_feed_id = 'feed_1123sdncisud6237ui2378789vvgX'
286
+ @client.create_feed new_feed_id
287
+ @client.create_feed new_feed_id
219
288
  end
220
289
 
221
290
  it 'Should create a resourcetype' do
222
- feed_id = 'feed_may_exist'
223
- @client.create_feed feed_id
291
+ new_feed_id = 'feed_may_exist'
292
+ @client.create_feed new_feed_id
224
293
 
225
- ret = @client.create_resource_type feed_id, 'rt-123', 'ResourceType'
294
+ ret = @client.create_resource_type new_feed_id, 'rt-123', 'ResourceType'
226
295
  expect(ret.id).to eq('rt-123')
227
296
  expect(ret.name).to eq('ResourceType')
228
297
  expect(ret.path).to include('/rt;rt-123')
229
298
  expect(ret.path).to include('/f;feed_may_exist')
230
299
  end
231
300
 
232
- it 'Should create a resource ' do
233
- feed_id = 'feed_may_exist'
234
- @client.create_feed feed_id
235
- ret = @client.create_resource_type feed_id, 'rt-123', 'ResourceType'
301
+ it 'Should create a resource' do
302
+ new_feed_id = 'feed_may_exist'
303
+ @client.create_feed new_feed_id
304
+ ret = @client.create_resource_type new_feed_id, 'rt-123', 'ResourceType'
236
305
  type_path = ret.path
237
306
 
238
- @client.create_resource feed_id, type_path, 'r123', 'My Resource', 'version' => 1.0
307
+ @client.create_resource type_path, 'r123', 'My Resource', 'version' => 1.0
308
+
309
+ resource_path = CanonicalPath.new(feed_id: new_feed_id, resource_ids: ['r123'])
239
310
 
240
- r = @client.get_resource(feed_id, 'r123', false)
311
+ r = @client.get_resource(resource_path, false)
241
312
  expect(r.id).to eq('r123')
242
313
  expect(r.properties).not_to be_empty
243
314
  end
244
315
 
245
316
  it 'Should create a resource with metric' do
246
- feed_id = 'feed_may_exist'
247
- @client.create_feed feed_id
248
- ret = @client.create_resource_type feed_id, 'rt-123', 'ResourceType'
317
+ new_feed_id = 'feed_may_exist'
318
+ @client.create_feed new_feed_id
319
+ ret = @client.create_resource_type new_feed_id, 'rt-123', 'ResourceType'
249
320
  type_path = ret.path
250
321
 
251
- @client.create_resource feed_id, type_path, 'r124', 'My Resource', 'version' => 1.0
322
+ @client.create_resource type_path, 'r124', 'My Resource', 'version' => 1.0
323
+ resource_path = CanonicalPath.new(feed_id: new_feed_id, resource_ids: ['r124'])
252
324
 
253
- r = @client.get_resource(feed_id, 'r124', false)
325
+ r = @client.get_resource(resource_path, false)
254
326
  expect(r.id).to eq('r124')
255
327
  expect(r.properties).not_to be_empty
256
328
 
257
- r = @client.create_metric_type feed_id, 'mt-124'
258
- expect(r).not_to be_nil
259
- expect(r.id).to eq('mt-124')
329
+ mt = @client.create_metric_type new_feed_id, 'mt-124'
330
+ expect(mt).not_to be_nil
331
+ expect(mt.id).to eq('mt-124')
260
332
 
261
- m = @client.create_metric_for_resource feed_id, 'm-124', r.path, 'r124'
333
+ m = @client.create_metric_for_resource mt.path, r.path, 'm-124'
262
334
  expect(m).not_to be_nil
263
335
  expect(m.id).to eq('m-124')
264
336
  expect(m.name).to eq('m-124')
265
337
 
266
- m = @client.create_metric_for_resource feed_id, 'm-124-1', r.path, 'r124', 'Metric1'
338
+ m = @client.create_metric_for_resource mt.path, r.path, 'm-124-1', 'Metric1'
267
339
  expect(m).not_to be_nil
268
340
  expect(m.id).to eq('m-124-1')
269
341
  expect(m.name).to eq('Metric1')
@@ -275,8 +347,8 @@ module Hawkular::Inventory::RSpec
275
347
  ret = @client.create_resource_type new_feed_id, 'rt-123-1', 'ResourceType'
276
348
  type_path = ret.path
277
349
 
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'
350
+ parent = @client.create_resource type_path, 'r124-a', 'Res-a'
351
+ nested_resource = @client.create_resource_under_resource type_path, parent.path, 'r124-b', 'Res-a'
280
352
  expect(nested_resource.path).to include('r;r124-a/r;r124-b')
281
353
 
282
354
  mt = @client.create_metric_type new_feed_id, 'mt-124-a'
@@ -284,111 +356,125 @@ module Hawkular::Inventory::RSpec
284
356
  expect(mt.id).to eq('mt-124-a')
285
357
 
286
358
  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
359
+ m = @client.create_metric_for_resource mt.path, nested_resource.path, 'm-124-a', m_name
288
360
  expect(m.id).to eq('m-124-a')
289
361
  expect(m.name).to eq(m_name)
290
362
 
291
- metrics = @client.list_metrics_for_resource nested_resource
363
+ metrics = @client.list_metrics_for_resource nested_resource.path
292
364
  expect(metrics.size).to eq(1)
293
365
  expect(metrics[0].id).to eq(m.id)
294
366
  end
295
367
 
296
368
  it 'Should create and get a resource' do
297
- feed_id = 'feed_may_exist'
298
- @client.create_feed feed_id
299
- ret = @client.create_resource_type feed_id, 'rt-123', 'ResourceType'
369
+ new_feed_id = 'feed_may_exist'
370
+ @client.create_feed new_feed_id
371
+ ret = @client.create_resource_type new_feed_id, 'rt-123', 'ResourceType'
300
372
  type_path = ret.path
301
373
 
302
- @client.create_resource feed_id, type_path, 'r125', 'My Resource', 'version' => 1.0
374
+ r1 = @client.create_resource type_path, 'r125', 'My Resource', 'version' => 1.0
303
375
 
304
- r = @client.get_resource(feed_id, 'r125', true)
305
- expect(r.id).to eq('r125')
306
- expect(r.properties).not_to be_empty
376
+ r2 = @client.get_resource(r1.path, true)
377
+ expect(r2.id).to eq('r125')
378
+ expect(r1.id).to eq(r2.id)
379
+ expect(r2.properties).not_to be_empty
307
380
  end
308
381
 
309
382
  it 'Should not find an unknown resource' do
310
- feed_id = 'feed_may_exist'
311
-
312
- expect { @client.get_resource(feed_id, '*bla does not exist*') }
383
+ new_feed_id = 'feed_may_exist'
384
+ path = CanonicalPath.new(feed_id: new_feed_id, resource_ids: [hawk_escape_id('*bla does not exist*')])
385
+ expect { @client.get_resource(path) }
313
386
  .to raise_error(Hawkular::BaseClient::HawkularException, /No Resource found/)
314
387
  end
315
388
 
316
389
  it 'Should reject unknown metric type' do
317
- feed_id = 'feed_may_exist'
390
+ new_feed_id = 'feed_may_exist'
318
391
 
319
- expect { @client.create_metric_type feed_id, 'abc', 'FOOBaR' }.to raise_error(RuntimeError, /Unknown type FOOBAR/)
392
+ expect { @client.create_metric_type new_feed_id, 'abc', 'FOOBaR' }.to raise_error(RuntimeError,
393
+ /Unknown type FOOBAR/)
320
394
  end
321
395
 
322
- it 'Client should listen on various inventory events', :websocket do
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
346
- end
396
+ let(:example) do |e|
397
+ e
398
+ end
347
399
 
348
- registered_feed_events = {}
349
- feeds_closable = @client.events('feed', 'created') do |feed|
350
- registered_feed_events[feed.id] = feed
400
+ it 'Client should listen on various inventory events', :websocket do
401
+ WebSocketVCR.configure do |c|
402
+ c.hook_uris = ['localhost:8080']
351
403
  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!
404
+ uuid_prefix = SecureRandom.uuid
405
+ vcr_options = {
406
+ decode_compressed_response: true,
407
+ erb: {
408
+ uuid_prefix: uuid_prefix
409
+ },
410
+ reverse_substitution: true
411
+ }
412
+ vcr_options[:record] = :all if ENV['VCR_UPDATE'] == '1'
413
+ cassette_name = 'Inventory/Templates/Client_should_listen_on_various_inventory_events'
414
+ WebSocketVCR.use_cassette(cassette_name, vcr_options) do
415
+ id_1 = uuid_prefix + '-r126'
416
+ id_2 = uuid_prefix + '-r127'
417
+ id_3 = uuid_prefix + '-r128'
418
+
419
+ new_resource_events = {}
420
+ resources_closable = @client.events do |resource|
421
+ new_resource_events[resource.id] = resource
422
+ end
423
+
424
+ deleted_feed_events = {}
425
+ feed_deleted_closable = @client.events('feed', 'deleted') do |feed|
426
+ deleted_feed_events[feed.id] = feed
427
+ end
428
+
429
+ new_resource_types_events = {}
430
+ resource_type_closable = @client.events('resourcetype') do |resource_type|
431
+ new_resource_types_events[resource_type.id] = resource_type
432
+ end
433
+
434
+ registered_feed_events = {}
435
+ feeds_closable = @client.events('feed', 'created') do |feed|
436
+ registered_feed_events[feed.id] = feed
437
+ end
438
+
439
+ new_feed_id = uuid_prefix + '-feed'
440
+ resource_type_id = uuid_prefix + '-rt-123'
441
+ resource_type_name = 'ResourceType'
442
+
443
+ record('Inventory',
444
+ { uuid_prefix: uuid_prefix },
445
+ 'Helpers/generate_some_events_for_websocket') do
446
+ @client.create_feed new_feed_id
447
+ ret = @client.create_resource_type new_feed_id, resource_type_id, resource_type_name
448
+ type_path = ret.path
449
+
450
+ # create 3 resources
451
+ @client.create_resource type_path, id_1, 'My Resource 1', 'version' => 1.0
452
+ @client.create_resource type_path, id_2, 'My Resource 2', 'version' => 1.1
453
+ resources_closable.close
454
+ @client.create_resource type_path, id_3, 'My Resource 3', 'version' => 1.2
455
+
456
+ @client.delete_feed new_feed_id
457
+ end
458
+
459
+ # wait for the data
460
+ sleep 2 if !WebSocketVCR.cassette || WebSocketVCR.cassette.recording?
461
+ [feed_deleted_closable, resource_type_closable, feeds_closable].each(&:close)
462
+ expect(new_resource_events[id_1]).not_to be_nil
463
+ expect(new_resource_events[id_1].properties['version']).to eq(1.0)
464
+ expect(new_resource_events[id_2]).not_to be_nil
465
+ expect(new_resource_events[id_2].properties['version']).to eq(1.1)
466
+ # resource with id_3 should not be among events, because we stopped listening before creating the 3rd one
467
+ expect(new_resource_events[id_3]).to be_nil
468
+
469
+ expect(registered_feed_events[new_feed_id]).not_to be_nil
470
+ expect(registered_feed_events[new_feed_id].id).to eq(new_feed_id)
471
+
472
+ expect(deleted_feed_events[new_feed_id]).not_to be_nil
473
+ expect(deleted_feed_events[new_feed_id].id).to eq(new_feed_id)
474
+
475
+ expect(new_resource_types_events[resource_type_id]).not_to be_nil
476
+ expect(new_resource_types_events[resource_type_id].id).to eq(resource_type_id)
477
+ expect(new_resource_types_events[resource_type_id].name).to eq(resource_type_name)
392
478
  end
393
479
  end
394
480