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.
- 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
|
@@ -113,6 +113,7 @@ module Hawkular::Metrics
|
|
|
113
113
|
# @param id [String] metric definition id
|
|
114
114
|
# @param starts [Integer] optional timestamp (default now - 8h)
|
|
115
115
|
# @param ends [Integer] optional timestamp (default now)
|
|
116
|
+
# @param buckets [Integer] optional desired number of buckets over the specified timerange
|
|
116
117
|
# @param bucketDuration [String] optional interval (default no aggregation)
|
|
117
118
|
# @param percentiles [String] optional percentiles to calculate
|
|
118
119
|
# @param limit [Integer] optional limit the number of data points returned
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
|
-
require 'hawkular'
|
|
2
|
+
require 'hawkular/base_client'
|
|
3
3
|
require 'json'
|
|
4
4
|
require 'rest-client'
|
|
5
5
|
require 'English'
|
|
6
6
|
|
|
7
|
-
require 'metrics/types'
|
|
8
|
-
require 'metrics/tenant_api'
|
|
9
|
-
require 'metrics/metric_api'
|
|
7
|
+
require 'hawkular/metrics/types'
|
|
8
|
+
require 'hawkular/metrics/tenant_api'
|
|
9
|
+
require 'hawkular/metrics/metric_api'
|
|
10
10
|
|
|
11
11
|
# Metrics module provides access to Hawkular Metrics REST API
|
|
12
12
|
# @see http://www.hawkular.org/docs/rest/rest-metrics.html Hawkular Metrics REST API Documentation
|
|
File without changes
|
|
File without changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require 'hawkular'
|
|
1
|
+
require 'hawkular/base_client'
|
|
2
2
|
require 'websocket-client-simple'
|
|
3
3
|
require 'json'
|
|
4
4
|
|
|
@@ -20,13 +20,13 @@ class Proc
|
|
|
20
20
|
end
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
# Operations module allows invoking operation on the
|
|
23
|
+
# Operations module allows invoking operation on the WildFly agent.
|
|
24
24
|
module Hawkular::Operations
|
|
25
25
|
# Client class to interact with the agent via websockets
|
|
26
26
|
class OperationsClient < Hawkular::BaseClient
|
|
27
27
|
include WebSocket::Client
|
|
28
28
|
|
|
29
|
-
attr_accessor :ws
|
|
29
|
+
attr_accessor :ws, :session_id
|
|
30
30
|
|
|
31
31
|
# helper for parsing the "OperationName=json_payload" messages
|
|
32
32
|
class WebSocket::Frame::Data
|
|
@@ -46,13 +46,15 @@ module Hawkular::Operations
|
|
|
46
46
|
# @param [Hash] args Arguments for client
|
|
47
47
|
#
|
|
48
48
|
# @option args [String] :host base url of Hawkular - e.g http://localhost:8080
|
|
49
|
-
# @option args [Hash{String=>String}] :credentials Hash of
|
|
49
|
+
# @option args [Hash{String=>String}] :credentials Hash of (username password) or token
|
|
50
|
+
# @option args [Fixnum] :wait_time Time in seconds describing how long the constructor should block - handshake
|
|
50
51
|
#
|
|
51
52
|
# @example
|
|
52
53
|
# Hawkular::Operations::OperationsClient.new(credentials: {username: 'jdoe', password: 'password'})
|
|
53
54
|
def initialize(args)
|
|
54
55
|
args[:host] ||= 'localhost:8080'
|
|
55
56
|
args[:credentials] ||= {}
|
|
57
|
+
args[:wait_time] ||= 0.5
|
|
56
58
|
super(args[:host], args[:credentials])
|
|
57
59
|
# note: if we start using the secured WS, change the protocol to wss://
|
|
58
60
|
url = "ws://#{entrypoint}/hawkular/command-gateway/ui/ws"
|
|
@@ -66,7 +68,7 @@ module Hawkular::Operations
|
|
|
66
68
|
end
|
|
67
69
|
end
|
|
68
70
|
end
|
|
69
|
-
sleep
|
|
71
|
+
sleep args[:wait_time]
|
|
70
72
|
end
|
|
71
73
|
|
|
72
74
|
# Closes the WebSocket connection
|
|
@@ -74,7 +76,7 @@ module Hawkular::Operations
|
|
|
74
76
|
@ws.close
|
|
75
77
|
end
|
|
76
78
|
|
|
77
|
-
# Invokes a generic operation on the
|
|
79
|
+
# Invokes a generic operation on the WildFly agent
|
|
78
80
|
# (the operation name must be specified in the hash)
|
|
79
81
|
# Note: if success and failure callbacks are omitted, the client will not wait for the Response message
|
|
80
82
|
# @param hash [Hash{String=>Object}] a hash containing: resourcePath [String] denoting the resource on
|
|
@@ -87,7 +89,7 @@ module Hawkular::Operations
|
|
|
87
89
|
invoke_operation_helper(hash, &callback)
|
|
88
90
|
end
|
|
89
91
|
|
|
90
|
-
# Invokes operation on the
|
|
92
|
+
# Invokes operation on the WildFly agent that has it's own message type
|
|
91
93
|
# @param operation_payload [Hash{String=>Object}] a hash containing: resourcePath [String] denoting
|
|
92
94
|
# the resource on which the operation is about to run
|
|
93
95
|
# @param operation_name [String] the name of the operation. This must correspond with the message type, they can be
|
|
@@ -202,6 +204,7 @@ module Hawkular::Operations
|
|
|
202
204
|
end
|
|
203
205
|
|
|
204
206
|
def handle_message(operation_name, operation_payload, &callback)
|
|
207
|
+
client = @ws
|
|
205
208
|
# register a callback handler
|
|
206
209
|
@ws.on :message do |msg|
|
|
207
210
|
parsed = msg.data.to_msg_hash
|
|
@@ -233,7 +236,7 @@ module Hawkular::Operations
|
|
|
233
236
|
|
|
234
237
|
def prepare_payload_hash(ignored_params, hash)
|
|
235
238
|
# it filters out ignored params and convert keys from snake_case to camelCase
|
|
236
|
-
hash.select { |k, _| !ignored_params.include? k }.map { |k, v| [to_camel_case(k.to_s).to_sym, v] }
|
|
239
|
+
Hash[hash.select { |k, _| !ignored_params.include? k }.map { |k, v| [to_camel_case(k.to_s).to_sym, v] }]
|
|
237
240
|
end
|
|
238
241
|
|
|
239
242
|
def to_camel_case(str)
|
|
@@ -166,6 +166,189 @@ module Hawkular::Alerts::RSpec
|
|
|
166
166
|
end
|
|
167
167
|
end
|
|
168
168
|
|
|
169
|
+
describe 'Alert/Groups', vcr: { decode_compressed_response: true } do
|
|
170
|
+
before(:each) do
|
|
171
|
+
@client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, creds)
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
it 'Should operate a complex group trigger' do
|
|
175
|
+
# Create a group trigger
|
|
176
|
+
t = Hawkular::Alerts::Trigger.new({})
|
|
177
|
+
t.enabled = false
|
|
178
|
+
t.id = 'a-group-trigger'
|
|
179
|
+
t.name = 'A Group Trigger'
|
|
180
|
+
t.severity = :HIGH
|
|
181
|
+
t.description = 'A Group Trigger generated from test'
|
|
182
|
+
|
|
183
|
+
# Create a condition
|
|
184
|
+
c = Hawkular::Alerts::Trigger::Condition.new({})
|
|
185
|
+
c.trigger_mode = :FIRING
|
|
186
|
+
c.type = :THRESHOLD
|
|
187
|
+
c.data_id = 'my-metric-id'
|
|
188
|
+
c.operator = :LT
|
|
189
|
+
c.threshold = 5
|
|
190
|
+
|
|
191
|
+
# Create a group condition
|
|
192
|
+
# no members yet
|
|
193
|
+
gc = Hawkular::Alerts::Trigger::GroupConditionsInfo.new([c])
|
|
194
|
+
|
|
195
|
+
# Create a member
|
|
196
|
+
m1 = Hawkular::Alerts::Trigger::GroupMemberInfo.new
|
|
197
|
+
m1.group_id = 'a-group-trigger'
|
|
198
|
+
m1.member_id = 'member1'
|
|
199
|
+
m1.member_name = 'Member One'
|
|
200
|
+
m1.data_id_map = { 'my-metric-id' => 'my-metric-id-member1' }
|
|
201
|
+
|
|
202
|
+
# Create a second member
|
|
203
|
+
m2 = Hawkular::Alerts::Trigger::GroupMemberInfo.new
|
|
204
|
+
m2.group_id = 'a-group-trigger'
|
|
205
|
+
m2.member_id = 'member2'
|
|
206
|
+
m2.member_name = 'Member Two'
|
|
207
|
+
m2.data_id_map = { 'my-metric-id' => 'my-metric-id-member2' }
|
|
208
|
+
|
|
209
|
+
# Create a dampening for the group trigger
|
|
210
|
+
d = Hawkular::Alerts::Trigger::Dampening.new(
|
|
211
|
+
'triggerId' => 'a-group-trigger',
|
|
212
|
+
'triggerMode' => :FIRING,
|
|
213
|
+
'type' => :STRICT,
|
|
214
|
+
'evalTrueSetting' => 2,
|
|
215
|
+
'evalTotalSetting' => 2
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
# Create a second condition
|
|
219
|
+
c2 = Hawkular::Alerts::Trigger::Condition.new({})
|
|
220
|
+
c2.trigger_mode = :FIRING
|
|
221
|
+
c2.type = :THRESHOLD
|
|
222
|
+
c2.data_id = 'my-metric-id2'
|
|
223
|
+
c2.operator = :GT
|
|
224
|
+
c2.threshold = 50
|
|
225
|
+
|
|
226
|
+
# Create the second group condition
|
|
227
|
+
# member2 is an orphan so, no need to update it into the data_id_member_map
|
|
228
|
+
gc2 = Hawkular::Alerts::Trigger::GroupConditionsInfo.new([c, c2])
|
|
229
|
+
gc2.data_id_member_map = {
|
|
230
|
+
'my-metric-id' => { 'member1' => 'my-metric-id-member1' },
|
|
231
|
+
'my-metric-id2' => { 'member1' => 'my-metric-id2-member1' }
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
# Create a third condition of type compare
|
|
235
|
+
c3 = Hawkular::Alerts::Trigger::Condition.new({})
|
|
236
|
+
c3.trigger_mode = :FIRING
|
|
237
|
+
c3.type = :COMPARE
|
|
238
|
+
c3.data_id = 'my-metric-id3'
|
|
239
|
+
c3.operator = :GT
|
|
240
|
+
c3.data2_id = 'my-metric-id4'
|
|
241
|
+
c3.data2_multiplier = 1
|
|
242
|
+
|
|
243
|
+
# Create the thrid group condition
|
|
244
|
+
# member 2 is still an orphan, no need to update it into the data_id_member_map
|
|
245
|
+
gc3 = Hawkular::Alerts::Trigger::GroupConditionsInfo.new([c, c2, c3])
|
|
246
|
+
gc3.data_id_member_map = {
|
|
247
|
+
'my-metric-id' => { 'member1' => 'my-metric-id-member1' },
|
|
248
|
+
'my-metric-id2' => { 'member1' => 'my-metric-id2-member1' },
|
|
249
|
+
'my-metric-id3' => { 'member1' => 'my-metric-id3-member1' },
|
|
250
|
+
'my-metric-id4' => { 'member1' => 'my-metric-id4-member1' }
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
begin
|
|
254
|
+
group_trigger = @client.create_group_trigger t
|
|
255
|
+
expect(group_trigger).not_to be_nil
|
|
256
|
+
expect(group_trigger.type).to eq('GROUP')
|
|
257
|
+
|
|
258
|
+
created_conditions = @client.set_group_conditions t.id, :FIRING, gc
|
|
259
|
+
expect(created_conditions.size).to be(1)
|
|
260
|
+
|
|
261
|
+
member1 = @client.create_member_trigger m1
|
|
262
|
+
expect(member1.type).to eq('MEMBER')
|
|
263
|
+
|
|
264
|
+
full_member1 = @client.get_single_trigger member1.id, true
|
|
265
|
+
expect(full_member1).not_to be_nil
|
|
266
|
+
expect(full_member1.id).to eq('member1')
|
|
267
|
+
expect(full_member1.conditions.size).to be(1)
|
|
268
|
+
expect(full_member1.conditions[0].data_id).to eq('my-metric-id-member1')
|
|
269
|
+
|
|
270
|
+
members = @client.list_members t.id
|
|
271
|
+
expect(members.size).to be(1)
|
|
272
|
+
|
|
273
|
+
member2 = @client.create_member_trigger m2
|
|
274
|
+
expect(member2.type).to eq('MEMBER')
|
|
275
|
+
|
|
276
|
+
full_member2 = @client.get_single_trigger member2.id, true
|
|
277
|
+
expect(full_member2).not_to be_nil
|
|
278
|
+
expect(full_member2.id).to eq('member2')
|
|
279
|
+
expect(full_member2.conditions.size).to be(1)
|
|
280
|
+
expect(full_member2.conditions[0].data_id).to eq('my-metric-id-member2')
|
|
281
|
+
|
|
282
|
+
members = @client.list_members t.id
|
|
283
|
+
expect(members.size).to be(2)
|
|
284
|
+
|
|
285
|
+
member2 = @client.orphan_member member2.id
|
|
286
|
+
expect(member2.type).to eq('ORPHAN')
|
|
287
|
+
|
|
288
|
+
members = @client.list_members t.id
|
|
289
|
+
expect(members.size).to be(1)
|
|
290
|
+
|
|
291
|
+
orphans = @client.list_members t.id, true
|
|
292
|
+
expect(orphans.size).to be(2)
|
|
293
|
+
|
|
294
|
+
group_dampening = @client.create_group_dampening d
|
|
295
|
+
expect(group_dampening).not_to be_nil
|
|
296
|
+
expect(group_dampening.type).to eq('STRICT')
|
|
297
|
+
|
|
298
|
+
full_member1 = @client.get_single_trigger member1.id, true
|
|
299
|
+
expect(full_member1).not_to be_nil
|
|
300
|
+
expect(full_member1.id).to eq('member1')
|
|
301
|
+
expect(full_member1.dampenings.size).to be(1)
|
|
302
|
+
expect(full_member1.dampenings[0].eval_true_setting).to be(2)
|
|
303
|
+
expect(full_member1.dampenings[0].eval_total_setting).to be(2)
|
|
304
|
+
|
|
305
|
+
group_trigger.tags = { 'group-tname' => 'group-tvalue' }
|
|
306
|
+
group_trigger = @client.update_group_trigger group_trigger
|
|
307
|
+
|
|
308
|
+
full_member1 = @client.get_single_trigger member1.id, false
|
|
309
|
+
expect(full_member1).not_to be_nil
|
|
310
|
+
expect(full_member1.tags['group-tname']).to eq('group-tvalue')
|
|
311
|
+
|
|
312
|
+
created_conditions = @client.set_group_conditions t.id, :FIRING, gc2
|
|
313
|
+
expect(created_conditions.size).to be(2)
|
|
314
|
+
|
|
315
|
+
full_member1 = @client.get_single_trigger member1.id, true
|
|
316
|
+
expect(full_member1).not_to be_nil
|
|
317
|
+
expect(full_member1.conditions.size).to be(2)
|
|
318
|
+
|
|
319
|
+
group_dampening.type = :RELAXED_COUNT
|
|
320
|
+
group_dampening.eval_true_setting = 2
|
|
321
|
+
group_dampening.eval_total_setting = 4
|
|
322
|
+
group_dampening = @client.update_group_dampening group_dampening
|
|
323
|
+
|
|
324
|
+
group_trigger.context = { 'alert-profiles' => 'profile1' }
|
|
325
|
+
@client.update_group_trigger group_trigger
|
|
326
|
+
|
|
327
|
+
@client.delete_group_dampening group_dampening.trigger_id, group_dampening.dampening_id
|
|
328
|
+
|
|
329
|
+
full_member1 = @client.get_single_trigger member1.id, true
|
|
330
|
+
expect(full_member1).not_to be_nil
|
|
331
|
+
expect(full_member1.context['alert-profiles']).to eq('profile1')
|
|
332
|
+
expect(full_member1.dampenings.size).to be(0)
|
|
333
|
+
|
|
334
|
+
created_conditions = @client.set_group_conditions t.id, :FIRING, gc3
|
|
335
|
+
expect(created_conditions.size).to be(3)
|
|
336
|
+
|
|
337
|
+
full_member1 = @client.get_single_trigger member1.id, true
|
|
338
|
+
expect(full_member1).not_to be_nil
|
|
339
|
+
expect(full_member1.conditions.size).to be(3)
|
|
340
|
+
ensure
|
|
341
|
+
# rubocop:disable Lint/HandleExceptions
|
|
342
|
+
begin
|
|
343
|
+
@client.delete_group_trigger(t.id)
|
|
344
|
+
rescue
|
|
345
|
+
# I am not interested
|
|
346
|
+
end
|
|
347
|
+
# rubocop:enable Lint/HandleExceptions
|
|
348
|
+
end
|
|
349
|
+
end
|
|
350
|
+
end
|
|
351
|
+
|
|
169
352
|
describe 'Alert/Alerts', :vcr do
|
|
170
353
|
it 'Should list alerts' do
|
|
171
354
|
client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, creds)
|
|
@@ -286,6 +469,23 @@ module Hawkular::Alerts::RSpec
|
|
|
286
469
|
expect(events).to_not be_nil
|
|
287
470
|
expect(events.size).to be(0)
|
|
288
471
|
end
|
|
472
|
+
|
|
473
|
+
it 'Should create an event' do
|
|
474
|
+
the_id = "test-event@#{Time.new.to_i}"
|
|
475
|
+
VCR.use_cassette('Alert/Events/Should_create_an_event',
|
|
476
|
+
erb: { id: the_id }, record: :none,
|
|
477
|
+
decode_compressed_response: true
|
|
478
|
+
) do
|
|
479
|
+
client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, creds)
|
|
480
|
+
|
|
481
|
+
the_event = client.create_event(the_id, 'MyCategory', 'Li la lu',
|
|
482
|
+
context: { message: 'This is a test' },
|
|
483
|
+
tags: { tag_name: 'tag-value' })
|
|
484
|
+
|
|
485
|
+
expect(the_event['id']).to eql(the_id)
|
|
486
|
+
expect(the_event['category']).to eql('MyCategory')
|
|
487
|
+
end
|
|
488
|
+
end
|
|
289
489
|
end
|
|
290
490
|
|
|
291
491
|
describe 'Alert/EndToEnd', vcr: { decode_compressed_response: true } do
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../vcr/vcr_setup"
|
|
2
|
+
require "#{File.dirname(__FILE__)}/../spec_helper"
|
|
3
|
+
require 'securerandom'
|
|
4
|
+
|
|
5
|
+
# examples that tests the main client which delegates all the calls to Hawkular component clients
|
|
6
|
+
module Hawkular::Client::RSpec
|
|
7
|
+
describe 'HawkularClient' do
|
|
8
|
+
before(:all) do
|
|
9
|
+
@creds = {
|
|
10
|
+
username: 'jdoe',
|
|
11
|
+
password: 'password'
|
|
12
|
+
}
|
|
13
|
+
@hawkular_client = Hawkular::Client.new(credentials: @creds)
|
|
14
|
+
@state = {
|
|
15
|
+
hostname: 'localhost.localdomain',
|
|
16
|
+
feed: nil
|
|
17
|
+
}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'Should fail when calling method with unknown prefix' do
|
|
21
|
+
expect { @hawkular_client.ynventori_list_feeds }.to raise_error(RuntimeError)
|
|
22
|
+
expect { @hawkular_client.list_feeds }.to raise_error(RuntimeError)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'Should fail when calling unknown method with known client prefix' do
|
|
26
|
+
expect { @hawkular_client.inventory_lyst_feeds }.to raise_error(NoMethodError)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
context 'and Inventory client', vcr: { decode_compressed_response: true } do
|
|
30
|
+
before(:all) do
|
|
31
|
+
@client = Hawkular::Inventory::InventoryClient.create(credentials: @creds)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'Should list the same feeds' do
|
|
35
|
+
feeds1 = @client.list_feeds
|
|
36
|
+
feeds2 = @hawkular_client.inventory_list_feeds
|
|
37
|
+
|
|
38
|
+
expect(feeds1).to match_array(feeds2)
|
|
39
|
+
@state[:feed] = feeds1[0] unless feeds1[0].nil?
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'Should list the same resource types' do
|
|
43
|
+
types1 = @client.list_resource_types
|
|
44
|
+
types2 = @hawkular_client.inventory_list_resource_types
|
|
45
|
+
|
|
46
|
+
expect(types1).to match_array(types2)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it 'Should list same types when param is given' do
|
|
50
|
+
types1 = @client.list_resource_types(@state[:feed])
|
|
51
|
+
types2 = @hawkular_client.inventory_list_resource_types(@state[:feed])
|
|
52
|
+
|
|
53
|
+
expect(types1).to match_array(types2)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it 'Should both list types with bad feed' do
|
|
57
|
+
type = 'does not exist'
|
|
58
|
+
types1 = @client.list_resource_types(type)
|
|
59
|
+
types2 = @hawkular_client.inventory_list_resource_types(type)
|
|
60
|
+
|
|
61
|
+
expect(types1).to match_array(types2)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'Should both list WildFlys' do
|
|
65
|
+
path = Hawkular::Inventory::CanonicalPath.new(feed_id: @state[:feed],
|
|
66
|
+
resource_type_id: hawk_escape_id('WildFly Server'))
|
|
67
|
+
resources1 = @client.list_resources_for_type(path.to_s)
|
|
68
|
+
resources2 = @hawkular_client.inventory_list_resources_for_type(path)
|
|
69
|
+
|
|
70
|
+
expect(resources1).to match_array(resources2)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it 'Should both create and delete feed' do
|
|
74
|
+
feed_id1 = 'feed_1123sdn'
|
|
75
|
+
feed_id2 = 'feed_1124sdn'
|
|
76
|
+
@client.create_feed feed_id1
|
|
77
|
+
@hawkular_client.inventory_create_feed feed_id2
|
|
78
|
+
|
|
79
|
+
feed_list = @client.list_feeds
|
|
80
|
+
expect(feed_list).to include(feed_id1)
|
|
81
|
+
expect(feed_list).to include(feed_id2)
|
|
82
|
+
|
|
83
|
+
@client.delete_feed feed_id2
|
|
84
|
+
@hawkular_client.inventory.delete_feed feed_id1
|
|
85
|
+
|
|
86
|
+
feed_list = @hawkular_client.inventory_list_feeds
|
|
87
|
+
expect(feed_list).not_to include(feed_id1)
|
|
88
|
+
expect(feed_list).not_to include(feed_id2)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
context 'and Metrics client' do
|
|
93
|
+
include Hawkular::Metrics::RSpec
|
|
94
|
+
|
|
95
|
+
before(:all) do
|
|
96
|
+
@client = Hawkular::Metrics::Client.new('http://localhost:8080/hawkular/metrics', @creds)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it 'Should both work the same way when pushing metric data to non-existing counter' do
|
|
100
|
+
id = SecureRandom.uuid
|
|
101
|
+
|
|
102
|
+
VCR.use_cassette('HawkularClient/and_Metrics_client/Should both work the same way when' \
|
|
103
|
+
' pushing metric data to non-existing counter',
|
|
104
|
+
erb: { id: id }, record: :none, decode_compressed_response: true
|
|
105
|
+
) do
|
|
106
|
+
@client.counters.push_data(id, value: 4)
|
|
107
|
+
|
|
108
|
+
data = @hawkular_client.metrics.counters.get_data(id)
|
|
109
|
+
expect(data.size).to be 1
|
|
110
|
+
counter = @hawkular_client.metrics.counters.get(id)
|
|
111
|
+
expect(counter.id).to eql(id)
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it 'Should both create and return Availability using Hash parameter' do
|
|
116
|
+
id1 = SecureRandom.uuid
|
|
117
|
+
id2 = SecureRandom.uuid
|
|
118
|
+
VCR.use_cassette(
|
|
119
|
+
'HawkularClient/and_Metrics_client/Should both create and return Availability using Hash parameter',
|
|
120
|
+
erb: { id1: id1, id2: id2 }, record: :none, decode_compressed_response: true
|
|
121
|
+
) do
|
|
122
|
+
@client.avail.create(id: id1, dataRetention: 123, tags: { some: 'value' })
|
|
123
|
+
metric = @hawkular_client.metrics.avail.get(id1)
|
|
124
|
+
expect(metric.id).to eql(id1)
|
|
125
|
+
expect(metric.data_retention).to eql(123)
|
|
126
|
+
|
|
127
|
+
@hawkular_client.metrics.avail.create(id: id2, dataRetention: 321, tags: { some: 'value' })
|
|
128
|
+
metric = @client.avail.get(id2)
|
|
129
|
+
expect(metric.id).to eql(id2)
|
|
130
|
+
expect(metric.data_retention).to eql(321)
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it 'Should both update tags for Availability' do
|
|
135
|
+
id1 = SecureRandom.uuid
|
|
136
|
+
id2 = SecureRandom.uuid
|
|
137
|
+
|
|
138
|
+
VCR.use_cassette('HawkularClient/and_Metrics_client/Should both create and retrieve tags for Availability',
|
|
139
|
+
erb: { id1: id1, id2: id2 }, record: :none, decode_compressed_response: true
|
|
140
|
+
) do
|
|
141
|
+
@client.avail.create(id: id1, tags: { myTag: id1 })
|
|
142
|
+
metric = @hawkular_client.metrics.avail.get(id1)
|
|
143
|
+
expect(metric.id).to eql(id1)
|
|
144
|
+
|
|
145
|
+
@hawkular_client.metrics.avail.create(id: id2, tags: { myTag: id2 })
|
|
146
|
+
metric = @client.avail.get(id2)
|
|
147
|
+
expect(metric.id).to eql(id2)
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
it 'Should both return the version' do
|
|
152
|
+
VCR.use_cassette('HawkularClient/and_Metrics_client/Should both return the version') do
|
|
153
|
+
data1 = @client.fetch_version_and_status
|
|
154
|
+
data2 = @hawkular_client.metrics.fetch_version_and_status
|
|
155
|
+
expect(data1).to eql(data2)
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
context 'and Operations client', vcr: { decode_compressed_response: true } do
|
|
161
|
+
include Hawkular::Operations::RSpec
|
|
162
|
+
|
|
163
|
+
WebSocketVCR.configure do |c|
|
|
164
|
+
c.hook_uris = ['localhost:8080']
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
let(:example) do |e|
|
|
168
|
+
e
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
it 'Should both work the same way', :websocket do
|
|
172
|
+
tenant_id = @hawkular_client.inventory_get_tenant
|
|
173
|
+
tenant_id2 = @hawkular_client.inventory.get_tenant
|
|
174
|
+
expect(tenant_id).to eql(tenant_id2)
|
|
175
|
+
|
|
176
|
+
feed_id = @hawkular_client.inventory.list_feeds.first
|
|
177
|
+
wf_server_resource_id = 'Local~~'
|
|
178
|
+
alerts_war_resource_id = 'Local~%2Fdeployment%3Dhawkular-alerts-actions-email.war'
|
|
179
|
+
|
|
180
|
+
WebSocketVCR.record(example, self) do
|
|
181
|
+
path = Hawkular::Inventory::CanonicalPath.new(tenant_id: tenant_id,
|
|
182
|
+
feed_id: feed_id,
|
|
183
|
+
resource_ids: [wf_server_resource_id, alerts_war_resource_id])
|
|
184
|
+
|
|
185
|
+
redeploy = {
|
|
186
|
+
operationName: 'Redeploy',
|
|
187
|
+
resourcePath: path.to_s
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
actual_data = {}
|
|
191
|
+
client = Hawkular::Operations::OperationsClient.new(credentials: @creds)
|
|
192
|
+
client.invoke_generic_operation(redeploy) do |on|
|
|
193
|
+
on.success do |data|
|
|
194
|
+
actual_data[:data] = data
|
|
195
|
+
end
|
|
196
|
+
on.failure do |error|
|
|
197
|
+
actual_data[:data] = {}
|
|
198
|
+
puts 'error callback was called, reason: ' + error.to_s
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
actual_data = wait_for actual_data
|
|
203
|
+
expect(actual_data['status']).to eq('OK')
|
|
204
|
+
|
|
205
|
+
# now do the same on the main client
|
|
206
|
+
actual_data = {}
|
|
207
|
+
@hawkular_client.operations_invoke_generic_operation(redeploy) do |on|
|
|
208
|
+
on.success do |data|
|
|
209
|
+
actual_data[:data] = data
|
|
210
|
+
end
|
|
211
|
+
on.failure do |error|
|
|
212
|
+
actual_data[:data] = {}
|
|
213
|
+
puts 'error callback was called, reason: ' + error.to_s
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
actual_data = wait_for actual_data
|
|
218
|
+
expect(actual_data['status']).to eq('OK')
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
xit 'Should both reuse the websocket connection', :websocket do
|
|
223
|
+
WebSocketVCR.record(example, self) do
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
end
|