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
@@ -7,57 +7,6 @@ require 'securerandom'
|
|
7
7
|
# time constants
|
8
8
|
t4h = 4 * 60 * 60 * 1000
|
9
9
|
|
10
|
-
# more or less generic method common for all metric types (counters, gauges, availabilities)
|
11
|
-
def create_metric_using_hash(endpoint, id)
|
12
|
-
endpoint.create(id: id, dataRetention: 123, tags: { some: 'value' }, tenantId: @tenant)
|
13
|
-
metric = endpoint.get(id)
|
14
|
-
|
15
|
-
expect(metric).to be_a(Hawkular::Metrics::MetricDefinition)
|
16
|
-
expect(metric.id).to eql(id)
|
17
|
-
expect(metric.data_retention).to eql(123)
|
18
|
-
expect(metric.tenant_id).to eql(@tenant)
|
19
|
-
end
|
20
|
-
|
21
|
-
def create_metric_using_md(endpoint, id)
|
22
|
-
metric = Hawkular::Metrics::MetricDefinition.new
|
23
|
-
metric.id = id
|
24
|
-
metric.data_retention = 90
|
25
|
-
metric.tags = { tag: 'value' }
|
26
|
-
endpoint.create(metric)
|
27
|
-
|
28
|
-
created = endpoint.get(metric.id)
|
29
|
-
expect(created).to be_a(Hawkular::Metrics::MetricDefinition)
|
30
|
-
expect(created.id).to eql(metric.id)
|
31
|
-
expect(created.data_retention).to eql(metric.data_retention)
|
32
|
-
end
|
33
|
-
|
34
|
-
def push_data_to_non_existing_metric(endpoint, data, id)
|
35
|
-
# push one value without timestamp (which means now)
|
36
|
-
endpoint.push_data(id, data)
|
37
|
-
|
38
|
-
data = endpoint.get_data(id)
|
39
|
-
expect(data.size).to be 1
|
40
|
-
|
41
|
-
# verify metric was auto-created
|
42
|
-
counter = endpoint.get(id)
|
43
|
-
expect(counter).to be_a(Hawkular::Metrics::MetricDefinition)
|
44
|
-
expect(counter.id).to eql(id)
|
45
|
-
end
|
46
|
-
|
47
|
-
def update_metric_by_tags(endpoint, id)
|
48
|
-
endpoint.create(id: id, tags: { myTag: id })
|
49
|
-
metric = endpoint.get(id)
|
50
|
-
metric.tags = { newTag: 'newValue' }
|
51
|
-
endpoint.update_tags(metric)
|
52
|
-
|
53
|
-
metric = endpoint.get(id)
|
54
|
-
expect(metric.tags).to include('newTag' => 'newValue', 'myTag' => id)
|
55
|
-
|
56
|
-
# query API for a metric with given tag
|
57
|
-
data = endpoint.query(myTag: id)
|
58
|
-
expect(data.size).to be 1
|
59
|
-
end
|
60
|
-
|
61
10
|
describe 'Simple', :vcr do
|
62
11
|
it 'Should be Cool' do
|
63
12
|
Net::HTTP.get_response(URI('http://localhost:8080/'))
|
@@ -153,7 +102,7 @@ describe 'Counter metrics' do
|
|
153
102
|
VCR.use_cassette('Counter_metrics/Should create and return counter using Hash parameter',
|
154
103
|
erb: { id: id }, record: :none
|
155
104
|
) do
|
156
|
-
create_metric_using_hash @client.counters, id
|
105
|
+
create_metric_using_hash @client.counters, id, @tenant
|
157
106
|
end
|
158
107
|
end
|
159
108
|
|
@@ -200,18 +149,19 @@ describe 'Counter metrics' do
|
|
200
149
|
|
201
150
|
it 'Should get metrics with limit and order' do
|
202
151
|
@client = setup_client(username: 'jdoe', password: 'password')
|
203
|
-
id =
|
204
|
-
now =
|
152
|
+
id = SecureRandom.uuid
|
153
|
+
now = 1_462_872_284_000
|
205
154
|
|
206
155
|
VCR.use_cassette('Counter_metrics/Should get metrics with limit and order',
|
156
|
+
decode_compressed_response: true,
|
207
157
|
erb: { id: id, ends: now - t4h, starts: now - (2 * t4h),
|
208
|
-
|
158
|
+
minus10: now - 10, minus20: now - 20, minus30: now - 30,
|
209
159
|
now: now }, record: :none
|
210
160
|
) do
|
211
161
|
# create counter
|
212
162
|
@client.counters.create(id: id)
|
213
163
|
|
214
|
-
# push 3
|
164
|
+
# push 3 values with timestamps
|
215
165
|
@client.counters.push_data(id, [{ value: 1, timestamp: now - 30 },
|
216
166
|
{ value: 2, timestamp: now - 20 },
|
217
167
|
{ value: 3, timestamp: now - 10 }])
|
@@ -225,8 +175,9 @@ describe 'Counter metrics' do
|
|
225
175
|
expect(data.size).to be 4
|
226
176
|
|
227
177
|
# retrieve values with limit
|
228
|
-
data = @client.counters.get_data(id, limit: 1)
|
178
|
+
data = @client.counters.get_data(id, limit: 1, order: 'DESC')
|
229
179
|
expect(data.size).to be 1
|
180
|
+
expect(data.first['value']).to be 4
|
230
181
|
|
231
182
|
# retrieve values from past
|
232
183
|
data = @client.counters.get_data(id, starts: now - (2 * t4h), ends: now - t4h)
|
@@ -234,6 +185,48 @@ describe 'Counter metrics' do
|
|
234
185
|
end
|
235
186
|
end
|
236
187
|
|
188
|
+
it 'Should get metrics as bucketed results' do
|
189
|
+
@client = setup_client(username: 'jdoe', password: 'password')
|
190
|
+
id = SecureRandom.uuid
|
191
|
+
now = @client.now
|
192
|
+
|
193
|
+
VCR.use_cassette('Counter_metrics/Should get metrics as bucketed results',
|
194
|
+
decode_compressed_response: true,
|
195
|
+
erb: { id: id, now: now }, record: :none
|
196
|
+
) do
|
197
|
+
# create counter
|
198
|
+
@client.counters.create(id: id)
|
199
|
+
|
200
|
+
# push 10 values with timestamps
|
201
|
+
@client.counters.push_data(id, [{ value: 110, timestamp: now - 110 },
|
202
|
+
{ value: 100, timestamp: now - 100 },
|
203
|
+
{ value: 90, timestamp: now - 90 },
|
204
|
+
{ value: 80, timestamp: now - 80 },
|
205
|
+
{ value: 70, timestamp: now - 70 },
|
206
|
+
{ value: 60, timestamp: now - 60 },
|
207
|
+
{ value: 50, timestamp: now - 50 },
|
208
|
+
{ value: 40, timestamp: now - 40 },
|
209
|
+
{ value: 30, timestamp: now - 30 },
|
210
|
+
{ value: 20, timestamp: now - 20 },
|
211
|
+
{ value: 10, timestamp: now - 10 }])
|
212
|
+
ERR = 0.001
|
213
|
+
data = @client.counters.get_data(id, starts: now - 105, ends: now - 5, buckets: 5)
|
214
|
+
expect(data.size).to be 5
|
215
|
+
expect(data.first['avg']).to be_within(ERR).of(95.0)
|
216
|
+
expect(data.first['max']).to be_within(ERR).of(100.0)
|
217
|
+
expect(data.first['samples']).to be 2
|
218
|
+
|
219
|
+
data = @client.counters.get_data(id, starts: now - 105, ends: now - 5, buckets: 2)
|
220
|
+
expect(data.size).to be 2
|
221
|
+
expect(data.first['avg']).to be_within(ERR).of(80.0)
|
222
|
+
expect(data.first['samples']).to be 5
|
223
|
+
|
224
|
+
data = @client.counters.get_data(id, starts: now - 105, ends: now - 5, bucketDuration: '50ms')
|
225
|
+
expect(data.size).to be 2
|
226
|
+
expect(data.first['avg']).to be_within(ERR).of(80.0)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
237
230
|
it 'Should push metric data to non-existing counter' do
|
238
231
|
id = SecureRandom.uuid
|
239
232
|
|
@@ -256,7 +249,7 @@ describe 'Availability metrics' do
|
|
256
249
|
'Availability_metrics/Should create and return Availability using Hash parameter',
|
257
250
|
erb: { id: id }, record: :none
|
258
251
|
) do
|
259
|
-
create_metric_using_hash @client.avail, id
|
252
|
+
create_metric_using_hash @client.avail, id, @tenant
|
260
253
|
end
|
261
254
|
end
|
262
255
|
|
@@ -312,7 +305,7 @@ describe 'Gauge metrics' do
|
|
312
305
|
VCR.use_cassette('Gauge_metrics/Should create gauge definition using Hash',
|
313
306
|
erb: { id: id }, record: :none
|
314
307
|
) do
|
315
|
-
create_metric_using_hash @client.gauges, id
|
308
|
+
create_metric_using_hash @client.gauges, id, @tenant
|
316
309
|
end
|
317
310
|
end
|
318
311
|
|
@@ -5,40 +5,71 @@ require 'securerandom'
|
|
5
5
|
include Hawkular::Inventory
|
6
6
|
include Hawkular::Operations
|
7
7
|
|
8
|
-
#
|
8
|
+
# examples for operations, it uses the websocket communication
|
9
9
|
module Hawkular::Operations::RSpec
|
10
10
|
HOST = 'localhost:8080'
|
11
|
-
describe 'Websocket connection' do
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
11
|
+
describe 'Operation/Websocket connection', vcr: { decode_compressed_response: true } do
|
12
|
+
let(:example) do |e|
|
13
|
+
e
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should be established' do
|
17
|
+
WebSocketVCR.configure do |c|
|
18
|
+
c.hook_uris = [HOST]
|
19
|
+
end
|
20
|
+
|
21
|
+
WebSocketVCR.record(example, self) do
|
22
|
+
client = OperationsClient.new(host: HOST,
|
23
|
+
wait_time: WebSocketVCR.live? ? 1.5 : 0,
|
24
|
+
credentials: {
|
25
|
+
username: 'jdoe',
|
26
|
+
password: 'password'
|
27
|
+
})
|
28
|
+
ws = client.ws
|
29
|
+
expect(ws).not_to be nil
|
30
|
+
expect(ws.open?).to be true
|
31
|
+
end
|
21
32
|
end
|
22
33
|
end
|
23
34
|
|
24
|
-
describe 'Operation', :websocket do
|
35
|
+
describe 'Operation/Operation', :websocket, vcr: { decode_compressed_response: true } do
|
36
|
+
let(:example) do |e|
|
37
|
+
e
|
38
|
+
end
|
39
|
+
|
25
40
|
before(:all) do
|
26
|
-
VCR.
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
41
|
+
VCR.use_cassette('Operation/Helpers/get_tenant', decode_compressed_response: true) do
|
42
|
+
@creds = { username: 'jdoe', password: 'password' }
|
43
|
+
inventory_client = InventoryClient.create(credentials: @creds)
|
44
|
+
@tenant_id = inventory_client.get_tenant
|
45
|
+
VCR.use_cassette('Operation/Helpers/get_feed', decode_compressed_response: true) do
|
46
|
+
@feed_id = inventory_client.list_feeds[0]
|
47
|
+
end
|
48
|
+
@random_uuid = 'random'
|
49
|
+
end
|
33
50
|
end
|
34
51
|
|
35
52
|
before(:each) do |ex|
|
36
53
|
unless ex.metadata[:skip_open]
|
37
|
-
@client = OperationsClient.new(credentials: @creds
|
54
|
+
@client = OperationsClient.new(credentials: @creds,
|
55
|
+
wait_time: WebSocketVCR.live? ? 1.5 : 0)
|
38
56
|
@ws = @client.ws
|
39
57
|
end
|
40
58
|
end
|
41
59
|
|
60
|
+
around(:each) do |ex|
|
61
|
+
if ex.metadata[:websocket]
|
62
|
+
WebSocketVCR.configure do |c|
|
63
|
+
c.hook_uris = [HOST]
|
64
|
+
end
|
65
|
+
WebSocketVCR.record(ex, self) do
|
66
|
+
ex.run
|
67
|
+
end
|
68
|
+
else
|
69
|
+
ex.run
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
42
73
|
after(:each) do |ex|
|
43
74
|
unless ex.metadata[:skip_close]
|
44
75
|
@client.close_connection!
|
@@ -47,13 +78,6 @@ module Hawkular::Operations::RSpec
|
|
47
78
|
end
|
48
79
|
end
|
49
80
|
|
50
|
-
after(:all) do
|
51
|
-
if ENV['VCR_OFF'] != '1'
|
52
|
-
VCR.turn_on!
|
53
|
-
WebMock.disable_net_connect!
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
81
|
it 'Add JDBC driver should add the driver' do
|
58
82
|
wf_server_resource_id = 'Local~~'
|
59
83
|
driver_name = 'CreatedByRubyDriver' + @random_uuid
|
@@ -137,7 +161,7 @@ module Hawkular::Operations::RSpec
|
|
137
161
|
expect(actual_data[:error]).to start_with('Could not perform [Redeploy] on')
|
138
162
|
end
|
139
163
|
|
140
|
-
it '
|
164
|
+
it 'Undeploy should be performed and eventually respond with success' do
|
141
165
|
wf_server_resource_id = 'Local~~'
|
142
166
|
alerts_war_resource_id = 'Local~%2Fdeployment%3Dhawkular-alerts-actions-email.war'
|
143
167
|
path = CanonicalPath.new(tenant_id: @tenant_id,
|
@@ -267,7 +291,7 @@ module Hawkular::Operations::RSpec
|
|
267
291
|
expect(actual_data['message']).to start_with('Performed [Redeploy] on')
|
268
292
|
end
|
269
293
|
|
270
|
-
it '
|
294
|
+
it 'Add deployment should be doable' do
|
271
295
|
wf_server_resource_id = 'Local~~'
|
272
296
|
app_name = 'sample.war'
|
273
297
|
war_file = IO.binread("#{File.dirname(__FILE__)}/../resources/#{app_name}")
|
data/spec/spec_helper.rb
CHANGED
@@ -2,12 +2,14 @@
|
|
2
2
|
require 'coveralls'
|
3
3
|
Coveralls.wear!
|
4
4
|
# Now the application requires.
|
5
|
-
require '
|
5
|
+
require 'hawkular/hawkular_client'
|
6
|
+
require 'hawkular/hawkular_client_utils'
|
6
7
|
require 'rspec/core'
|
7
8
|
require 'rspec/mocks'
|
8
9
|
require 'socket'
|
9
10
|
require 'uri'
|
10
11
|
require 'yaml'
|
12
|
+
require 'json'
|
11
13
|
|
12
14
|
module Hawkular::Metrics::RSpec
|
13
15
|
def setup_client(options = {})
|
@@ -31,14 +33,66 @@ module Hawkular::Metrics::RSpec
|
|
31
33
|
File.read(File.expand_path('endpoint.yml', File.dirname(__FILE__)))
|
32
34
|
)
|
33
35
|
end
|
36
|
+
|
37
|
+
# more or less generic method common for all metric types (counters, gauges, availabilities)
|
38
|
+
def create_metric_using_hash(endpoint, id, tenant_id)
|
39
|
+
endpoint.create(id: id, dataRetention: 123, tags: { some: 'value' }, tenantId: tenant_id)
|
40
|
+
metric = endpoint.get(id)
|
41
|
+
|
42
|
+
expect(metric).to be_a(Hawkular::Metrics::MetricDefinition)
|
43
|
+
expect(metric.id).to eql(id)
|
44
|
+
expect(metric.data_retention).to eql(123)
|
45
|
+
expect(metric.tenant_id).to eql(tenant_id)
|
46
|
+
end
|
47
|
+
|
48
|
+
def create_metric_using_md(endpoint, id)
|
49
|
+
metric = Hawkular::Metrics::MetricDefinition.new
|
50
|
+
metric.id = id
|
51
|
+
metric.data_retention = 90
|
52
|
+
metric.tags = { tag: 'value' }
|
53
|
+
endpoint.create(metric)
|
54
|
+
|
55
|
+
created = endpoint.get(metric.id)
|
56
|
+
expect(created).to be_a(Hawkular::Metrics::MetricDefinition)
|
57
|
+
expect(created.id).to eql(metric.id)
|
58
|
+
expect(created.data_retention).to eql(metric.data_retention)
|
59
|
+
end
|
60
|
+
|
61
|
+
def push_data_to_non_existing_metric(endpoint, data, id)
|
62
|
+
# push one value without timestamp (which means now)
|
63
|
+
endpoint.push_data(id, data)
|
64
|
+
|
65
|
+
data = endpoint.get_data(id)
|
66
|
+
expect(data.size).to be 1
|
67
|
+
|
68
|
+
# verify metric was auto-created
|
69
|
+
counter = endpoint.get(id)
|
70
|
+
expect(counter).to be_a(Hawkular::Metrics::MetricDefinition)
|
71
|
+
expect(counter.id).to eql(id)
|
72
|
+
end
|
73
|
+
|
74
|
+
def update_metric_by_tags(endpoint, id)
|
75
|
+
endpoint.create(id: id, tags: { myTag: id })
|
76
|
+
metric = endpoint.get(id)
|
77
|
+
metric.tags = { newTag: 'newValue' }
|
78
|
+
endpoint.update_tags(metric)
|
79
|
+
|
80
|
+
metric = endpoint.get(id)
|
81
|
+
expect(metric.tags).to include('newTag' => 'newValue', 'myTag' => id)
|
82
|
+
|
83
|
+
# query API for a metric with given tag
|
84
|
+
data = endpoint.query(myTag: id)
|
85
|
+
expect(data.size).to be 1
|
86
|
+
end
|
34
87
|
end
|
35
88
|
|
36
89
|
module Hawkular::Operations::RSpec
|
37
|
-
SLEEP_SECONDS = 0.
|
38
|
-
MAX_ATTEMPTS =
|
90
|
+
SLEEP_SECONDS = 0.04
|
91
|
+
MAX_ATTEMPTS = 60
|
39
92
|
|
40
93
|
def wait_for(object)
|
41
|
-
|
94
|
+
fast = WebSocketVCR.cassette && !WebSocketVCR.cassette.recording?
|
95
|
+
sleep_interval = SLEEP_SECONDS * (fast ? 1 : 10)
|
42
96
|
attempt = 0
|
43
97
|
sleep sleep_interval while object[:data].nil? && (attempt += 1) < MAX_ATTEMPTS
|
44
98
|
if attempt == MAX_ATTEMPTS
|
@@ -50,14 +104,60 @@ module Hawkular::Operations::RSpec
|
|
50
104
|
end
|
51
105
|
end
|
52
106
|
|
107
|
+
# globally used helper functions
|
108
|
+
module Helpers
|
109
|
+
def make_template(base_directory, cassette_name, bindings)
|
110
|
+
cassette = cassette_name.gsub(/\s+/, '_')
|
111
|
+
input_file_path = "#{VCR.configuration.cassette_library_dir}/#{base_directory}/tmp/#{cassette}.yml"
|
112
|
+
return unless File.exist? input_file_path
|
113
|
+
output_file_path = "#{VCR.configuration.cassette_library_dir}/#{base_directory}/Templates/#{cassette}.yml"
|
114
|
+
|
115
|
+
dirname = File.dirname(output_file_path)
|
116
|
+
# make sure the directory structure is there
|
117
|
+
FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
|
118
|
+
|
119
|
+
text = File.read(input_file_path)
|
120
|
+
bindings.select { |_, v| v.size >= 3 }.each do |k, v|
|
121
|
+
text.gsub! v, "<%= #{k} %>"
|
122
|
+
end
|
123
|
+
|
124
|
+
File.open(output_file_path, 'w') { |file| file.write text }
|
125
|
+
File.delete(input_file_path)
|
126
|
+
end
|
127
|
+
|
128
|
+
def record(prefix, bindings, explicit_cassette_name, example: nil)
|
129
|
+
run = lambda do
|
130
|
+
example.run unless example.nil?
|
131
|
+
yield if block_given?
|
132
|
+
end
|
133
|
+
|
134
|
+
if (!example.nil? && example.metadata[:update_template]) || ENV['VCR_UPDATE'] == '1'
|
135
|
+
VCR.use_cassette(prefix + '/tmp/' + explicit_cassette_name,
|
136
|
+
decode_compressed_response: true,
|
137
|
+
record: :all) do
|
138
|
+
run.call
|
139
|
+
end
|
140
|
+
make_template prefix, explicit_cassette_name, bindings
|
141
|
+
else
|
142
|
+
VCR.use_cassette(prefix + '/Templates/' + explicit_cassette_name,
|
143
|
+
decode_compressed_response: true,
|
144
|
+
erb: bindings,
|
145
|
+
record: :none) do
|
146
|
+
run.call
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
53
152
|
RSpec.configure do |config|
|
153
|
+
config.include Helpers
|
54
154
|
config.include Hawkular::Metrics::RSpec
|
55
155
|
config.include Hawkular::Operations::RSpec
|
156
|
+
config.include HawkularUtilsMixin
|
157
|
+
config.include Hawkular::Inventory
|
56
158
|
|
57
|
-
# skip the tests that
|
58
|
-
|
59
|
-
config.filter_run_excluding :websocket
|
60
|
-
end
|
159
|
+
# skip the tests that have the :skip metadata on them
|
160
|
+
config.filter_run_excluding :skip
|
61
161
|
|
62
162
|
# Sometimes one wants to check if the real api has
|
63
163
|
# changed, so turn off VCR and use live connections
|
@@ -65,6 +165,7 @@ RSpec.configure do |config|
|
|
65
165
|
if ENV['VCR_OFF'] == '1'
|
66
166
|
VCR.eject_cassette
|
67
167
|
VCR.turn_off!(ignore_cassettes: true)
|
168
|
+
WebSocketVCR.turn_off!
|
68
169
|
WebMock.allow_net_connect!
|
69
170
|
puts 'VCR is turned off!'
|
70
171
|
end
|
data/spec/unit/base_spec.rb
CHANGED
@@ -75,4 +75,13 @@ describe 'Base Spec' do
|
|
75
75
|
|
76
76
|
expect(ret).to eq('a1%252%203%7c45%2f')
|
77
77
|
end
|
78
|
+
|
79
|
+
it 'should pass http_proxy_uri to rest_client' do
|
80
|
+
proxy_uri = 'http://myproxy.com'
|
81
|
+
c = Hawkular::BaseClient.new('not-needed-for-this-test', {},
|
82
|
+
http_proxy_uri: proxy_uri)
|
83
|
+
rc = c.rest_client('myurl')
|
84
|
+
|
85
|
+
expect(rc.options[:proxy]).to eq(proxy_uri)
|
86
|
+
end
|
78
87
|
end
|