hawkular-client 0.2.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/.yardopts +1 -0
- data/CHANGES.rdoc +17 -4
- data/README.rdoc +15 -6
- data/api_breaking_changes.rdoc +79 -0
- data/hawkularclient.gemspec +6 -5
- data/lib/{alerts → hawkular/alerts}/alerts_api.rb +168 -7
- data/lib/{hawkular.rb → hawkular/base_client.rb} +7 -44
- data/lib/hawkular/hawkular_client.rb +60 -0
- data/lib/hawkular/hawkular_client_utils.rb +40 -0
- data/lib/{inventory → hawkular/inventory}/inventory_api.rb +167 -142
- data/lib/{metrics → hawkular/metrics}/metric_api.rb +1 -0
- data/lib/{metrics → hawkular/metrics}/metrics_client.rb +4 -4
- data/lib/{metrics → hawkular/metrics}/tenant_api.rb +0 -0
- data/lib/{metrics → hawkular/metrics}/types.rb +0 -0
- data/lib/{operations → hawkular/operations}/operations_api.rb +11 -8
- data/lib/{tokens → hawkular/tokens}/tokens_api.rb +1 -1
- data/lib/{version.rb → hawkular/version.rb} +1 -1
- data/spec/integration/alerts_spec.rb +200 -0
- data/spec/integration/hawkular_client_spec.rb +228 -0
- data/spec/integration/inventory_spec.rb +246 -160
- data/spec/integration/metric_spec.rb +52 -59
- data/spec/integration/operations_spec.rb +53 -29
- data/spec/spec_helper.rb +109 -8
- data/spec/unit/base_spec.rb +9 -0
- data/spec/unit/canonical_path_spec.rb +2 -2
- data/spec/vcr/vcr_setup.rb +6 -0
- data/spec/vcr_cassettes/Alert/Events/Should_create_an_event.yml +50 -0
- data/spec/vcr_cassettes/Alert/Groups/Should_operate_a_complex_group_trigger.yml +1726 -0
- data/spec/vcr_cassettes/Counter_metrics/Should_get_metrics_as_bucketed_results.yml +190 -0
- data/spec/vcr_cassettes/Counter_metrics/Should_get_metrics_with_limit_and_order.yml +30 -42
- data/spec/vcr_cassettes/HawkularClient/and_Inventory_client/Should_both_create_and_delete_feed.yml +287 -0
- data/spec/vcr_cassettes/{Inventory/Should_list_URLs.yml → HawkularClient/and_Inventory_client/Should_both_list_WildFlys.yml} +35 -33
- 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
- data/spec/vcr_cassettes/HawkularClient/and_Inventory_client/Should_list_same_types_when_param_is_given.yml +245 -0
- data/spec/vcr_cassettes/{Inventory/Should_list_feeds.yml → HawkularClient/and_Inventory_client/Should_list_the_same_feeds.yml} +20 -20
- data/spec/vcr_cassettes/HawkularClient/and_Inventory_client/Should_list_the_same_resource_types.yml +249 -0
- data/spec/vcr_cassettes/HawkularClient/and_Metrics_client/Should_both_create_and_retrieve_tags_for_Availability.yml +155 -0
- data/spec/vcr_cassettes/HawkularClient/and_Metrics_client/Should_both_create_and_return_Availability_using_Hash_parameter.yml +155 -0
- data/spec/vcr_cassettes/HawkularClient/and_Metrics_client/Should_both_return_the_version.yml +89 -0
- 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
- data/spec/vcr_cassettes/{Inventory/Should_list_WildFlys_with_props.yml → HawkularClient/and_Operations_client/Should_both_work_the_same_way.yml} +28 -50
- data/spec/vcr_cassettes/HawkularClient/and_Operations_client_Should_both_work_the_same_way.json +44 -0
- data/spec/vcr_cassettes/Inventory/Helpers/create_url.yml +48 -0
- data/spec/vcr_cassettes/Inventory/Helpers/generate_some_events_for_websocket.yml +4446 -0
- data/spec/vcr_cassettes/Inventory/Helpers/get_feeds.yml +54 -0
- data/spec/vcr_cassettes/Inventory/Templates/Client_should_listen_on_various_inventory_events.json +47 -0
- data/spec/vcr_cassettes/Inventory/{Should_create_a_resourcetype.yml → Templates/Client_should_listen_on_various_inventory_events.yml} +47 -61
- data/spec/vcr_cassettes/Inventory/Templates/Helpers/generate_some_events_for_websocket.yml +542 -0
- data/spec/vcr_cassettes/Inventory/{Should_List_datasources_with_no_props.yml → Templates/Should_List_datasources_with_no_props.yml} +26 -85
- data/spec/vcr_cassettes/Inventory/Templates/Should_create_a_feed.yml +54 -0
- data/spec/vcr_cassettes/Inventory/Templates/Should_create_a_feed_again.yml +164 -0
- 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
- data/spec/vcr_cassettes/Inventory/{Should_create_a_resource_.yml → Templates/Should_create_a_resource.yml} +103 -76
- data/spec/vcr_cassettes/Inventory/{Should_create_a_resource_with_metric.yml → Templates/Should_create_a_resource_with_metric.yml} +91 -197
- data/spec/vcr_cassettes/Inventory/Templates/Should_create_a_resourcetype.yml +154 -0
- data/spec/vcr_cassettes/Inventory/Templates/Should_create_and_delete_feed.yml +145 -0
- data/spec/vcr_cassettes/Inventory/{Should_create_and_get_a_resource.yml → Templates/Should_create_and_get_a_resource.yml} +35 -20
- data/spec/vcr_cassettes/Inventory/Templates/Should_list_URLs.yml +65 -0
- data/spec/vcr_cassettes/Inventory/Templates/Should_list_WildFlys.yml +61 -0
- data/spec/vcr_cassettes/Inventory/{Should_list_WildFlys.yml → Templates/Should_list_WildFlys_with_props.yml} +36 -33
- data/spec/vcr_cassettes/Inventory/Templates/Should_list_all_the_resource_types.yml +126 -0
- data/spec/vcr_cassettes/Inventory/{Should_list_children_of_WildFly.yml → Templates/Should_list_children_of_WildFly.yml} +66 -112
- data/spec/vcr_cassettes/Inventory/{Should_list_children_of_nested_resource.yml → Templates/Should_list_children_of_nested_resource.yml} +13 -13
- data/spec/vcr_cassettes/Inventory/Templates/Should_list_feeds.yml +54 -0
- data/spec/vcr_cassettes/Inventory/Templates/Should_list_heap_metrics_for_WildFlys.yml +712 -0
- data/spec/vcr_cassettes/Inventory/Templates/Should_list_metrics_for_WildFlys.yml +278 -0
- data/spec/vcr_cassettes/Inventory/Templates/Should_list_metrics_of_given_metric_type.yml +530 -0
- data/spec/vcr_cassettes/Inventory/Templates/Should_list_metrics_of_given_resource_type.yml +278 -0
- data/spec/vcr_cassettes/Inventory/Templates/Should_list_operation_definitions_of_given_resource.yml +185 -0
- data/spec/vcr_cassettes/Inventory/Templates/Should_list_operation_definitions_of_given_resource_type.yml +126 -0
- data/spec/vcr_cassettes/Inventory/Templates/Should_list_recursive_children_of_WildFly.yml +2369 -0
- data/spec/vcr_cassettes/Inventory/Templates/Should_list_relationships_of_WildFly.yml +415 -0
- data/spec/vcr_cassettes/Inventory/Templates/Should_list_types_with_bad_feed.yml +51 -0
- data/spec/vcr_cassettes/Inventory/Templates/Should_list_types_with_feed.yml +124 -0
- data/spec/vcr_cassettes/Inventory/{Should_not_find_an_unknown_resource.yml → Templates/Should_not_find_an_unknown_resource.yml} +14 -13
- 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
- data/spec/vcr_cassettes/Inventory/{Should_return_config_data_of_given_resource.yml → Templates/Should_return_config_data_of_given_resource.yml} +4 -4
- data/spec/vcr_cassettes/Inventory/Tenants/Should_Get_Tenant_For_Explicit_Credentials.yml +50 -0
- data/spec/vcr_cassettes/Inventory/Tenants/Should_Get_Tenant_For_Implicit_Credentials.yml +50 -0
- data/spec/vcr_cassettes/Operation/Helpers/get_feed.yml +54 -0
- data/spec/vcr_cassettes/Operation/Helpers/get_tenant.yml +50 -0
- data/spec/vcr_cassettes/Operation/Operation/Add_JDBC_driver_should_add_the_driver.json +26 -0
- data/spec/vcr_cassettes/Operation/Operation/Add_datasource_should_be_doable.json +26 -0
- data/spec/vcr_cassettes/Operation/Operation/Add_deployment_should_be_doable.json +26 -0
- data/spec/vcr_cassettes/Operation/Operation/Redeploy_can_be_run_multiple_times_in_parallel.json +40 -0
- data/spec/vcr_cassettes/Operation/Operation/Redeploy_should_be_performed_and_eventually_respond_with_success.json +26 -0
- data/spec/vcr_cassettes/Operation/Operation/Redeploy_should_not_be_performed_if_resource_path_is_wrong.json +26 -0
- data/spec/vcr_cassettes/Operation/Operation/Remove_JDBC_driver_should_be_performed_and_eventually_respond_with_success.json +26 -0
- data/spec/vcr_cassettes/Operation/Operation/Remove_datasource_should_be_performed_and_eventually_respond_with_success.json +26 -0
- data/spec/vcr_cassettes/Operation/Operation/Remove_deployment_should_be_performed_and_eventually_respond_with_success.json +26 -0
- data/spec/vcr_cassettes/Operation/Operation/Undeploy_should_be_performed_and_eventually_respond_with_success.json +26 -0
- data/spec/vcr_cassettes/Operation/Operation/should_not_be_possible_to_perform_on_closed_client.json +12 -0
- data/spec/vcr_cassettes/Operation/Websocket_connection/should_be_established.json +9 -0
- metadata +171 -72
- data/lib/hawkular_all.rb +0 -9
- data/spec/vcr_cassettes/Inventory/Should_create_a_feed.yml +0 -107
- data/spec/vcr_cassettes/Inventory/Should_create_a_feed_again.yml +0 -211
- data/spec/vcr_cassettes/Inventory/Should_create_and_delete_feed.yml +0 -201
- data/spec/vcr_cassettes/Inventory/Should_list_all_the_resource_types.yml +0 -177
- data/spec/vcr_cassettes/Inventory/Should_list_heap_metrics_for_WildFlys.yml +0 -775
- data/spec/vcr_cassettes/Inventory/Should_list_metrics_for_WildFlys.yml +0 -333
- data/spec/vcr_cassettes/Inventory/Should_list_metrics_of_given_metric_type.yml +0 -613
- data/spec/vcr_cassettes/Inventory/Should_list_metrics_of_given_resource_type.yml +0 -333
- data/spec/vcr_cassettes/Inventory/Should_list_recursive_children_of_WildFly.yml +0 -2064
- data/spec/vcr_cassettes/Inventory/Should_list_relationships_of_WildFly.yml +0 -460
- 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
|
-
|
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'
|
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
|
-
|
36
|
-
|
37
|
-
|
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(
|
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(
|
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(
|
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']).
|
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
|
-
|
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
|
-
|
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
|
-
|
98
|
-
expect(
|
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(
|
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(
|
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(
|
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
|
-
|
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(
|
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(
|
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(
|
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(
|
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(
|
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
|
-
|
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(
|
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
|
-
|
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
|
-
|
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
|
-
|
198
|
-
ret = @client.create_feed
|
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(
|
269
|
+
expect(ret['id']).to eq(new_feed_id)
|
201
270
|
end
|
202
271
|
|
203
272
|
it 'Should create and delete feed' do
|
204
|
-
|
205
|
-
ret = @client.create_feed
|
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(
|
276
|
+
expect(ret['id']).to eq(new_feed_id)
|
208
277
|
|
209
|
-
@client.delete_feed
|
278
|
+
@client.delete_feed new_feed_id
|
210
279
|
|
211
280
|
feed_list = @client.list_feeds
|
212
|
-
expect(feed_list).not_to include(
|
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
|
-
|
217
|
-
@client.create_feed
|
218
|
-
@client.create_feed
|
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
|
-
|
223
|
-
@client.create_feed
|
291
|
+
new_feed_id = 'feed_may_exist'
|
292
|
+
@client.create_feed new_feed_id
|
224
293
|
|
225
|
-
ret = @client.create_resource_type
|
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
|
233
|
-
|
234
|
-
@client.create_feed
|
235
|
-
ret = @client.create_resource_type
|
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
|
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(
|
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
|
-
|
247
|
-
@client.create_feed
|
248
|
-
ret = @client.create_resource_type
|
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
|
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(
|
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
|
-
|
258
|
-
expect(
|
259
|
-
expect(
|
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
|
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
|
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
|
279
|
-
nested_resource = @client.create_resource_under_resource
|
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
|
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
|
-
|
298
|
-
@client.create_feed
|
299
|
-
ret = @client.create_resource_type
|
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
|
374
|
+
r1 = @client.create_resource type_path, 'r125', 'My Resource', 'version' => 1.0
|
303
375
|
|
304
|
-
|
305
|
-
expect(
|
306
|
-
expect(
|
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
|
-
|
311
|
-
|
312
|
-
expect { @client.get_resource(
|
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
|
-
|
390
|
+
new_feed_id = 'feed_may_exist'
|
318
391
|
|
319
|
-
expect { @client.create_metric_type
|
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
|
-
|
323
|
-
|
324
|
-
|
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
|
-
|
349
|
-
|
350
|
-
|
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
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
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
|
|