hawkular-client 2.8.0 → 2.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -4
  3. data/.travis/start_hawkular_services.sh +21 -0
  4. data/.travis/wait_for_services.rb +26 -10
  5. data/CHANGES.rdoc +26 -0
  6. data/README.rdoc +12 -1
  7. data/docker-compose.yml +4 -2
  8. data/hawkularclient.gemspec +2 -0
  9. data/lib/hawkular/alerts/alerts_api.rb +22 -1
  10. data/lib/hawkular/base_client.rb +29 -24
  11. data/lib/hawkular/client_utils.rb +42 -0
  12. data/lib/hawkular/env_config.rb +15 -0
  13. data/lib/hawkular/hawkular_client.rb +33 -25
  14. data/lib/hawkular/inventory/entities.rb +9 -0
  15. data/lib/hawkular/inventory/inventory_api.rb +13 -3
  16. data/lib/hawkular/logger.rb +14 -0
  17. data/lib/hawkular/metrics/metric_api.rb +24 -8
  18. data/lib/hawkular/operations/operations_api.rb +57 -25
  19. data/lib/hawkular/tokens/tokens_api.rb +4 -1
  20. data/lib/hawkular/version.rb +1 -1
  21. data/lib/hawkularclient.rb +8 -0
  22. data/spec/integration/alerts_spec.rb +50 -27
  23. data/spec/integration/env_config_spec.rb +39 -0
  24. data/spec/integration/hawkular_client_spec.rb +10 -7
  25. data/spec/integration/inventory_spec.rb +36 -3
  26. data/spec/integration/logger_spec.rb +36 -0
  27. data/spec/integration/metric_spec.rb +62 -3
  28. data/spec/integration/operations_spec.rb +112 -63
  29. data/spec/integration/tokens_spec.rb +6 -6
  30. data/spec/spec_helper.rb +20 -6
  31. data/spec/unit/base_spec.rb +25 -3
  32. data/spec/unit/canonical_path_spec.rb +2 -1
  33. data/spec/unit/client_spec.rb +2 -1
  34. data/spec/unit/deprecations_spec.rb +19 -0
  35. data/spec/vcr_cassettes/Alert/Alerts/Templates/Should_add_tags_to_existing_alert.yml +210 -0
  36. data/spec/vcr_cassettes/Alert/Alerts/Templates/Should_remove_tags_from_existing_alert.yml +257 -0
  37. data/spec/vcr_cassettes/Alert/Triggers/Templates/Should_get_the_action_definitions.yml +59 -22
  38. data/spec/vcr_cassettes/Inventory/NonSecure/inventory_0_17/Templates/Should_have_a_consistent_behaviour_when_creating_an_already_existing_resource.yml +714 -0
  39. data/spec/vcr_cassettes/Inventory/NonSecure/inventory_0_17/Templates/Should_return_data_from_get_entity.yml +230 -0
  40. data/spec/vcr_cassettes/Metrics/NonSecure/metrics_services/Templates/All_Tags_for_metrics/Should_fetch_all_metrics_with_some_tags.yml +1251 -0
  41. data/spec/vcr_cassettes/Metrics/NonSecure/metrics_services/Templates/Tags_Metrics/setup_client.yml +3 -3
  42. data/spec/vcr_cassettes/Operation/NonSecure/Helpers/Templates/agent_properties.yml +124 -0
  43. data/spec/vcr_cassettes/Operation/NonSecure/Helpers/Templates/get_feed.yml +7 -7
  44. data/spec/vcr_cassettes/Operation/NonSecure/Operation/Add_JDBC_driver_should_add_the_driver.json +4 -4
  45. data/spec/vcr_cassettes/Operation/NonSecure/Operation/Add_deployment_should_be_doable.json +4 -4
  46. data/spec/vcr_cassettes/Operation/NonSecure/Operation/Disable_should_be_performed_and_eventually_respond_with_success.json +4 -4
  47. data/spec/vcr_cassettes/Operation/NonSecure/Operation/Remove_JDBC_driver_should_be_performed_and_eventually_respond_with_success.json +3 -3
  48. data/spec/vcr_cassettes/Operation/NonSecure/Operation/Restart_can_be_run_multiple_times_in_parallel.json +5 -5
  49. data/spec/vcr_cassettes/Operation/NonSecure/Operation/Restart_should_be_performed_and_eventually_respond_with_success.json +4 -4
  50. data/spec/vcr_cassettes/Operation/NonSecure/Operation/Update_collection_intervals_should_be_performed_and_eventually_respond_with_success.json +23 -0
  51. metadata +57 -7
  52. data/lib/hawkular/hawkular_client_utils.rb +0 -41
@@ -193,6 +193,15 @@ module Hawkular::Inventory
193
193
  CanonicalPath.new(hash)
194
194
  end
195
195
 
196
+ # Adds a resource to the path.
197
+ # @return CanonicalPath referring to resource_id using current as its ancestor.
198
+ def to_resource(resource_id)
199
+ hash = to_h
200
+ hash[:resource_ids] = [] if hash[:resource_ids].nil?
201
+ hash[:resource_ids].push resource_id
202
+ CanonicalPath.new(hash)
203
+ end
204
+
196
205
  def ==(other)
197
206
  self.equal?(other) || other.class == self.class && other.state == state
198
207
  end
@@ -11,7 +11,7 @@ require 'hawkular/inventory/entities'
11
11
  # and thus set to 'test' as default value.
12
12
  module Hawkular::Inventory
13
13
  # Client class to interact with Hawkular Inventory
14
- class InventoryClient < Hawkular::BaseClient
14
+ class Client < Hawkular::BaseClient
15
15
  attr_reader :version
16
16
 
17
17
  # Create a new Inventory Client
@@ -35,7 +35,7 @@ module Hawkular::Inventory
35
35
  fail 'no parameter ":entrypoint" given' if hash[:entrypoint].nil?
36
36
  hash[:credentials] ||= {}
37
37
  hash[:options] ||= {}
38
- InventoryClient.new(hash[:entrypoint], hash[:credentials], hash[:options])
38
+ Client.new(hash[:entrypoint], hash[:credentials], hash[:options])
39
39
  end
40
40
 
41
41
  # Retrieve the tenant id for the passed credentials.
@@ -194,7 +194,7 @@ module Hawkular::Inventory
194
194
  # @return inventory entity
195
195
  def get_entity(path)
196
196
  c_path = path.is_a?(CanonicalPath) ? path : CanonicalPath.parse(path)
197
- http_get("/entity/#{c_path}")
197
+ http_get("/entity#{c_path}")
198
198
  end
199
199
 
200
200
  # List the metrics for the passed metric type. If feed is not passed in the path,
@@ -357,6 +357,13 @@ module Hawkular::Inventory
357
357
  rescue HawkularException => error
358
358
  # 409 We already exist -> that is ok
359
359
  raise unless error.status_code == 409
360
+ # Ensure we have a consistent behaviour if resource already exists Issue#180
361
+ if parent_res_path.nil?
362
+ hash = type_path.to_h
363
+ hash.delete(:metric_type_id)
364
+ path = CanonicalPath.new(hash)
365
+ end
366
+ res = get_resource(path.to_resource(resource_id)).to_h
360
367
  end
361
368
  Resource.new(res)
362
369
  end
@@ -558,4 +565,7 @@ module Hawkular::Inventory
558
565
  end
559
566
  end
560
567
  end
568
+
569
+ InventoryClient = Client
570
+ deprecate_constant :InventoryClient if self.respond_to? :deprecate_constant
561
571
  end
@@ -0,0 +1,14 @@
1
+ require 'logger'
2
+ require 'hawkular/env_config'
3
+
4
+ module Hawkular
5
+ class Logger
6
+ def initialize(file = STDOUT)
7
+ @logger = ::Logger.new(file)
8
+ end
9
+
10
+ def log(message, priority = :info)
11
+ @logger.send(priority, message) if EnvConfig.log_response?
12
+ end
13
+ end
14
+ end
@@ -12,6 +12,25 @@ module Hawkular::Metrics
12
12
  array
13
13
  end
14
14
 
15
+ def tags_param(tags)
16
+ tags.map { |k, v| "#{k}:#{v}" }.join(',')
17
+ end
18
+
19
+ # Retrieve all types of metrics datapoints by tags
20
+ # @param tags [Hash]
21
+ # @param buckets [Integer] optional number of buckets
22
+ # @param bucketDuration [String] optional interval (default no aggregation)
23
+ # @param starts [Integer] optional timestamp (default now - 8h)
24
+ # @param ends [Integer] optional timestamp (default now)
25
+ # @return [Array[Hash]] datapoints
26
+ def data_by_tags(tags, buckets: nil, bucketDuration:nil, start:nil, ends: nil)
27
+ data = {
28
+ tags: tags_param(tags), buckets: buckets, bucketDuration: bucketDuration, start: start, end: ends
29
+ }
30
+
31
+ http_post('metrics/stats/query', data)
32
+ end
33
+
15
34
  # Return version and status information for the used version of Hawkular-Metrics
16
35
  # @return [Hash{String=>String}]
17
36
  # ('Implementation-Version', 'Built-From-Git-SHA1', 'Status')
@@ -112,7 +131,7 @@ module Hawkular::Metrics
112
131
  # @param tags [Hash]
113
132
  # @return [Array[MetricDefinition]]
114
133
  def query(tags = nil)
115
- tags_filter = tags.nil? ? '' : "&tags=#{tags_param(tags)}"
134
+ tags_filter = tags.nil? ? '' : "&tags=#{@client.tags_param(tags)}"
116
135
  @client.http_get("/metrics/?type=#{@type}#{tags_filter}").map do |g|
117
136
  Hawkular::Metrics::MetricDefinition.new(g)
118
137
  end
@@ -189,21 +208,18 @@ module Hawkular::Metrics
189
208
  # @param starts [Integer] optional timestamp (default now - 8h)
190
209
  # @param ends [Integer] optional timestamp (default now)
191
210
  # @param bucketDuration [String] optional interval (default no aggregation)
211
+ # @param buckets [Integer] optional number of buckets
192
212
  # @return [Array[Hash]] datapoints
193
213
  # @see #push_data #push_data for datapoint detail
194
- def get_data_by_tags(tags, starts: nil, ends: nil, bucketDuration: nil)
195
- params = { tags: tags_param(tags), start: starts,
196
- end: ends, bucketDuration: bucketDuration }
214
+ def get_data_by_tags(tags, starts: nil, ends: nil, bucketDuration: nil, buckets:nil)
215
+ params = { tags: @client.tags_param(tags), start: starts,
216
+ end: ends, bucketDuration: bucketDuration, buckets: buckets }
197
217
  path = "/#{@resource}/"
198
218
  @legacy_api ? path << 'data/?' : path << 'stats/?'
199
219
  resp = @client.http_get(path + encode_params(params))
200
220
  resp.is_a?(Array) ? resp : [] # API returns no content (empty Hash) instead of empty array
201
221
  end
202
222
 
203
- def tags_param(tags)
204
- tags.map { |k, v| "#{k}:#{v}" }.join(',')
205
- end
206
-
207
223
  def encode_params(params)
208
224
  URI.encode_www_form(params.select { |_k, v| !v.nil? })
209
225
  end
@@ -13,6 +13,7 @@ class Proc
13
13
  method_name = callable.to_sym
14
14
  define_method(method_name) { |&block| block.nil? ? true : block.call(result) }
15
15
  define_method("#{method_name}?") { true }
16
+
16
17
  # method_missing is here because we are not forcing the client to provide both success and error callbacks
17
18
  # rubocop:disable Lint/NestedMethodDefinition
18
19
  # https://github.com/bbatsov/rubocop/issues/2704
@@ -27,19 +28,17 @@ end
27
28
  # Operations module allows invoking operation on the WildFly agent.
28
29
  module Hawkular::Operations
29
30
  # Client class to interact with the agent via websockets
30
- class OperationsClient < Hawkular::BaseClient
31
+ class Client < Hawkular::BaseClient
31
32
  include WebSocket::Client
32
33
 
33
- attr_accessor :ws, :session_id
34
+ attr_accessor :ws, :session_id, :logger
34
35
 
35
36
  # helper for parsing the "OperationName=json_payload" messages
36
37
  class WebSocket::Frame::Data
37
38
  def to_msg_hash
38
39
  chunks = split('=', 2)
39
- {
40
- operationName: chunks[0],
41
- data: JSON.parse(chunks[1])
42
- }
40
+
41
+ { operationName: chunks[0], data: JSON.parse(chunks[1]) }
43
42
  rescue
44
43
  {}
45
44
  end
@@ -62,39 +61,52 @@ module Hawkular::Operations
62
61
  # @example
63
62
  # Hawkular::Operations::OperationsClient.new(credentials: {username: 'jdoe', password: 'password'})
64
63
  def initialize(args)
65
- args[:use_secure_connection] ||= false
66
- ep = args[:entrypoint]
67
-
68
- unless ep.nil?
69
- uri = URI.parse ep.to_s
64
+ args = {
65
+ credentials: {},
66
+ options: {},
67
+ wait_time: 0.5,
68
+ use_secure_connection: false,
69
+ entrypoint: nil
70
+ }.merge(args)
71
+
72
+ if args[:entrypoint]
73
+ uri = URI.parse(args[:entrypoint].to_s)
70
74
  args[:host] = "#{uri.host}:#{uri.port}"
71
75
  args[:use_secure_connection] = %w(https wss).include?(uri.scheme) ? true : false
72
76
  end
73
77
 
74
78
  fail 'no parameter ":host" or ":entrypoint" given' if args[:host].nil?
75
- args[:credentials] ||= {}
76
- args[:options] ||= {}
77
- args[:wait_time] ||= 0.5
79
+
78
80
  super(args[:host], args[:credentials], args[:options])
81
+
79
82
  url = "ws#{args[:use_secure_connection] ? 's' : ''}://#{args[:host]}/hawkular/command-gateway/ui/ws"
80
- ws_options = {}
83
+
81
84
  creds = args[:credentials]
82
85
  base64_creds = ["#{creds[:username]}:#{creds[:password]}"].pack('m').delete("\r\n")
83
- ws_options[:headers] = { 'Authorization' => 'Basic ' + base64_creds,
84
- 'Hawkular-Tenant' => args[:options][:tenant],
85
- 'Accept' => 'application/json'
86
+
87
+ ws_options = {
88
+ headers: {
89
+ 'Authorization' => 'Basic ' + base64_creds,
90
+ 'Hawkular-Tenant' => args[:options][:tenant],
91
+ 'Accept' => 'application/json'
92
+ }
86
93
  }
87
94
 
95
+ @logger = Hawkular::Logger.new
96
+
88
97
  @ws = Simple.connect url, ws_options do |client|
89
98
  client.on(:message, once: true) do |msg|
90
99
  parsed_message = msg.data.to_msg_hash
91
- puts parsed_message if ENV['HAWKULARCLIENT_LOG_RESPONSE']
100
+
101
+ logger.log("Sent WebSocket message: #{parsed_message}")
102
+
92
103
  case parsed_message[:operationName]
93
104
  when 'WelcomeResponse'
94
105
  @session_id = parsed_message[:data]['sessionId']
95
106
  end
96
107
  end
97
108
  end
109
+
98
110
  sleep args[:wait_time]
99
111
  end
100
112
 
@@ -135,6 +147,7 @@ module Hawkular::Operations
135
147
  #
136
148
  # @param [Hash] hash Arguments for deployment
137
149
  # @option hash [String] :resource_path canonical path of the WildFly server into which we deploy
150
+ # or of the domain controller if we deploy into a server group (in case of domain mode)
138
151
  # @option hash [String] :destination_file_name resulting file name
139
152
  # @option hash [String] :binary_content binary content representing the war file
140
153
  # @option hash [String] :enabled whether the deployment should be enabled immediately, or not (default = true)
@@ -295,6 +308,22 @@ module Hawkular::Operations
295
308
  invoke_specific_operation({ resourcePath: resource_path }, 'ExportJdr', &callback)
296
309
  end
297
310
 
311
+ # Updates the collection intervals.
312
+ #
313
+ # @param [Hash] hash Arguments for update collection intervals
314
+ # @option hash {resourcePath} a resource managed by the target agent
315
+ # @option hash {metricTypes} A map with key=MetricTypeId, value=interval (seconds).
316
+ # MetricTypeId must be of form MetricTypeSet~MetricTypeName
317
+ # @option hash {availTypes} A map with key=AvailTypeId, value=interval (seconds).
318
+ # AvailTypeId must be of form AvailTypeSet~AvailTypeName
319
+ #
320
+ # @param callback [Block] callback that is run after the operation is done
321
+ def update_collection_intervals(hash, &callback)
322
+ required = [:resourcePath, :metricTypes, :availTypes]
323
+ check_pre_conditions hash, required, &callback
324
+ invoke_specific_operation(hash, 'UpdateCollectionIntervals', &callback)
325
+ end
326
+
298
327
  private
299
328
 
300
329
  def invoke_operation_helper(operation_payload, operation_name = nil, binary_content = nil, &callback)
@@ -333,12 +362,16 @@ module Hawkular::Operations
333
362
  # register a callback handler
334
363
  @ws.on :message do |msg|
335
364
  parsed = msg.data.to_msg_hash
336
- OperationsClient.log_message(parsed)
365
+
366
+ logger = Hawkular::Logger.new
367
+ logger.log("Received WebSocket msg: #{parsed}")
368
+
337
369
  case parsed[:operationName]
338
370
  when "#{operation_name}Response"
339
371
  same_path = parsed[:data]['resourcePath'] == operation_payload[:resourcePath]
340
372
  # failed operations don't return the operation name from some strange reason
341
- same_name = parsed[:data]['operationName'] == operation_payload[:operationName]
373
+ same_name = operation_payload[:operationName].nil? ||
374
+ parsed[:data]['operationName'] == operation_payload[:operationName].to_s
342
375
  if same_path # using the resource path as a correlation id
343
376
  success = same_name && parsed[:data]['status'] == 'OK'
344
377
  success ? callback.perform(:success, parsed[:data]) : callback.perform(:failure, parsed[:data]['message'])
@@ -355,10 +388,6 @@ module Hawkular::Operations
355
388
  callback.perform(:failure, parsed_message == {} ? 'error' : parsed_message[:data]['errorMessage'])
356
389
  end
357
390
 
358
- def self.log_message(message)
359
- puts "\nreceived WebSocket msg: #{message}\n" if ENV['HAWKULARCLIENT_LOG_RESPONSE']
360
- end
361
-
362
391
  def prepare_payload_hash(ignored_params, hash)
363
392
  # it filters out ignored params and convert keys from snake_case to camelCase
364
393
  Hash[hash.select { |k, _| !ignored_params.include? k }.map { |k, v| [to_camel_case(k.to_s).to_sym, v] }]
@@ -369,4 +398,7 @@ module Hawkular::Operations
369
398
  ret[0, 1].downcase + ret[1..-1]
370
399
  end
371
400
  end
401
+
402
+ OperationsClient = Client
403
+ deprecate_constant :OperationsClient if self.respond_to? :deprecate_constant
372
404
  end
@@ -3,7 +3,7 @@ require 'hawkular/base_client'
3
3
  # Token module provides access to the Secret Store REST API.
4
4
  module Hawkular::Token
5
5
  # Client class to interact with the Secret Store
6
- class TokenClient < Hawkular::BaseClient
6
+ class Client < Hawkular::BaseClient
7
7
  # Create a new Secret Store client
8
8
  # @param entrypoint [String] base url of Hawkular - e.g http://localhost:8080
9
9
  # @param credentials [Hash{String=>String}] Hash of username, password
@@ -31,4 +31,7 @@ module Hawkular::Token
31
31
  http_post('/secret-store/v1/tokens/create', token_attributes, auth_header)
32
32
  end
33
33
  end
34
+
35
+ TokenClient = Client
36
+ deprecate_constant :TokenClient if self.respond_to? :deprecate_constant
34
37
  end
@@ -4,5 +4,5 @@
4
4
  # @see https://github.com/hawkular
5
5
  module Hawkular
6
6
  # Version of the Hawkular Ruby Gem
7
- VERSION = '2.8.0'.freeze
7
+ VERSION = '2.9.0'.freeze
8
8
  end
@@ -0,0 +1,8 @@
1
+ require 'hawkular/version'
2
+ require 'hawkular/inventory/inventory_api'
3
+ require 'hawkular/metrics/metrics_client'
4
+ require 'hawkular/alerts/alerts_api'
5
+ require 'hawkular/tokens/tokens_api'
6
+ require 'hawkular/operations/operations_api'
7
+ require 'hawkular/base_client'
8
+ require 'hawkular/hawkular_client'
@@ -1,5 +1,5 @@
1
- require "#{File.dirname(__FILE__)}/../vcr/vcr_setup"
2
- require "#{File.dirname(__FILE__)}/../spec_helper"
1
+ require_relative '../vcr/vcr_setup'
2
+ require_relative '../spec_helper'
3
3
 
4
4
  module Hawkular::Alerts::RSpec
5
5
  ALERTS_BASE = 'http://localhost:8080/hawkular/alerts'
@@ -10,7 +10,7 @@ module Hawkular::Alerts::RSpec
10
10
  before(:all) do
11
11
  # Setup for testing
12
12
  record('Alert/Triggers', credentials, 'setup') do
13
- @client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, credentials, options)
13
+ @client = Hawkular::Alerts::Client.new(ALERTS_BASE, credentials, options)
14
14
  json = IO.read('spec/integration/alert-resources/triggers-test-data.json')
15
15
  trigger_hash = JSON.parse(json)
16
16
  @client.bulk_import_triggers trigger_hash
@@ -20,7 +20,7 @@ module Hawkular::Alerts::RSpec
20
20
  after(:all) do
21
21
  # cleanup test values
22
22
  record('Alert/Triggers', credentials, 'setup_cleanup') do
23
- @client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, credentials, options)
23
+ @client = Hawkular::Alerts::Client.new(ALERTS_BASE, credentials, options)
24
24
  json = IO.read('spec/integration/alert-resources/triggers-test-data.json')
25
25
  trigger_hash = JSON.parse(json)
26
26
  trigger_hash['triggers'].each do |trigger|
@@ -39,7 +39,7 @@ module Hawkular::Alerts::RSpec
39
39
  end
40
40
 
41
41
  before(:each) do
42
- @client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, creds, options)
42
+ @client = Hawkular::Alerts::Client.new(ALERTS_BASE, creds, options)
43
43
  end
44
44
 
45
45
  it 'Should List Triggers' do
@@ -192,7 +192,7 @@ module Hawkular::Alerts::RSpec
192
192
 
193
193
  ret = @client.get_action_definition 'email'
194
194
  expect(ret.size).to be(1)
195
- expect(ret['email'].size).to be(7)
195
+ expect(ret['email'].size).to be(8)
196
196
 
197
197
  expect { @client.get_action_definition '-does-not-exist-' }
198
198
  .to raise_error(Hawkular::BaseClient::HawkularException)
@@ -229,7 +229,7 @@ module Hawkular::Alerts::RSpec
229
229
  end
230
230
 
231
231
  before(:each) do
232
- @client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, creds, options)
232
+ @client = Hawkular::Alerts::Client.new(ALERTS_BASE, creds, options)
233
233
  end
234
234
 
235
235
  it 'Should operate a complex group trigger' do
@@ -414,7 +414,7 @@ module Hawkular::Alerts::RSpec
414
414
  before(:all) do
415
415
  # Setup for testing
416
416
  record('Alert/Alerts', credentials, 'setup') do
417
- @client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, credentials, options)
417
+ @client = Hawkular::Alerts::Client.new(ALERTS_BASE, credentials, options)
418
418
  json = IO.read('spec/integration/alert-resources/alerts-test-data.json')
419
419
  trigger_hash = JSON.parse(json)
420
420
  @client.bulk_import_triggers trigger_hash
@@ -429,7 +429,7 @@ module Hawkular::Alerts::RSpec
429
429
  after(:all) do
430
430
  # cleanup test values
431
431
  record('Alert/Alerts', credentials, 'setup_cleanup') do
432
- @client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, credentials, options)
432
+ @client = Hawkular::Alerts::Client.new(ALERTS_BASE, credentials, options)
433
433
  json = IO.read('spec/integration/alert-resources/alerts-test-data.json')
434
434
  trigger_hash = JSON.parse(json)
435
435
  trigger_hash['triggers'].each do |trigger|
@@ -451,11 +451,11 @@ module Hawkular::Alerts::RSpec
451
451
  end
452
452
 
453
453
  before(:each) do
454
- @client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, creds, options)
454
+ @client = Hawkular::Alerts::Client.new(ALERTS_BASE, creds, options)
455
455
  end
456
456
 
457
457
  it 'Should list alerts' do
458
- client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, creds, options)
458
+ client = Hawkular::Alerts::Client.new(ALERTS_BASE, creds, options)
459
459
 
460
460
  alerts = client.list_alerts
461
461
 
@@ -464,7 +464,7 @@ module Hawkular::Alerts::RSpec
464
464
  end
465
465
 
466
466
  it 'Should list open alerts' do
467
- client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, creds, options)
467
+ client = Hawkular::Alerts::Client.new(ALERTS_BASE, creds, options)
468
468
 
469
469
  alerts = client.list_alerts('statuses' => 'OPEN')
470
470
 
@@ -473,7 +473,7 @@ module Hawkular::Alerts::RSpec
473
473
  end
474
474
 
475
475
  it 'Should list alerts for trigger' do
476
- client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, creds, options)
476
+ client = Hawkular::Alerts::Client.new(ALERTS_BASE, creds, options)
477
477
 
478
478
  alerts = client.get_alerts_for_trigger 'hello-world-trigger'
479
479
 
@@ -482,7 +482,7 @@ module Hawkular::Alerts::RSpec
482
482
  end
483
483
 
484
484
  it 'Should list alerts for unknown trigger' do
485
- client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, creds, options)
485
+ client = Hawkular::Alerts::Client.new(ALERTS_BASE, creds, options)
486
486
 
487
487
  alerts = client.get_alerts_for_trigger 'does-not-exist'
488
488
 
@@ -491,7 +491,7 @@ module Hawkular::Alerts::RSpec
491
491
  end
492
492
 
493
493
  it 'Should fetch single alert' do
494
- client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, creds, options)
494
+ client = Hawkular::Alerts::Client.new(ALERTS_BASE, creds, options)
495
495
 
496
496
  alert_id = client.list_alerts('statuses' => 'OPEN').first.id
497
497
 
@@ -502,7 +502,7 @@ module Hawkular::Alerts::RSpec
502
502
  end
503
503
 
504
504
  it 'Should resolve an alert' do
505
- client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, creds, options)
505
+ client = Hawkular::Alerts::Client.new(ALERTS_BASE, creds, options)
506
506
 
507
507
  alert_id = client.list_alerts('statuses' => 'OPEN').first.id
508
508
  alert = client.get_single_alert alert_id
@@ -517,7 +517,7 @@ module Hawkular::Alerts::RSpec
517
517
 
518
518
  # # TODO enable when the semantics on the server side is known
519
519
  # it 'Should resolve an alert2' do
520
- # client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE,creds)
520
+ # client = Hawkular::Alerts::Client.new(ALERTS_BASE,creds)
521
521
  #
522
522
  # alert_id = '28026b36-8fe4-4332-84c8-524e173a68bf-snert~Local_jvm_garba-1446977734134'
523
523
  # client.resolve_alert alert_id
@@ -525,7 +525,7 @@ module Hawkular::Alerts::RSpec
525
525
  # end
526
526
 
527
527
  it 'Should acknowledge an alert' do
528
- client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, creds, options)
528
+ client = Hawkular::Alerts::Client.new(ALERTS_BASE, creds, options)
529
529
 
530
530
  alert_id = client.list_alerts('statuses' => 'OPEN').first.id
531
531
  client.get_single_alert alert_id
@@ -535,6 +535,29 @@ module Hawkular::Alerts::RSpec
535
535
  alert = client.get_single_alert alert_id
536
536
  expect(alert.ackBy).to eql('Heiko')
537
537
  end
538
+
539
+ it 'Should add tags to existing alert' do
540
+ client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, creds, options)
541
+ alert_id = client.list_alerts.first.id
542
+ alert_not_found = client.list_alerts(tags: 'new-tag-name|tag_value', thin: true).first
543
+ client.add_tags([alert_id], ['new-tag-name|tag_value', 'othertag|othervalue'])
544
+ alert_found_by_new_tag_name = client.list_alerts(tags: 'new-tag-name|tag_value', thin: true).first
545
+
546
+ expect(alert_not_found).to be_nil
547
+ expect(alert_found_by_new_tag_name).to_not be_nil
548
+ end
549
+
550
+ it 'Should remove tags from existing alert' do
551
+ client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, creds, options)
552
+ alert_id = client.list_alerts.first.id
553
+ client.add_tags([alert_id], ['new-tag-name|tag_value', 'othertag|othervalue'])
554
+ alert_found_by_new_tag_name = client.list_alerts(tags: 'new-tag-name|tag_value', thin: true).first
555
+ client.remove_tags([alert_id], ['new-tag-name'])
556
+ alert_not_found = client.list_alerts(tags: 'new-tag-name|tag_value', thin: true).first
557
+
558
+ expect(alert_found_by_new_tag_name).to_not be_nil
559
+ expect(alert_not_found).to be_nil
560
+ end
538
561
  end
539
562
 
540
563
  describe 'Alert' do
@@ -548,7 +571,7 @@ module Hawkular::Alerts::RSpec
548
571
  end
549
572
 
550
573
  before(:each) do
551
- @client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, creds)
574
+ @client = Hawkular::Alerts::Client.new(ALERTS_BASE, creds)
552
575
  end
553
576
 
554
577
  it 'Should return the version' do
@@ -561,7 +584,7 @@ module Hawkular::Alerts::RSpec
561
584
  before(:all) do
562
585
  # Setup for testing
563
586
  record('Alert/Events', credentials, 'setup') do
564
- @client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, credentials, options)
587
+ @client = Hawkular::Alerts::Client.new(ALERTS_BASE, credentials, options)
565
588
  json = IO.read('spec/integration/alert-resources/events-test-data.json')
566
589
  hash = JSON.parse(json)
567
590
  hash['events'].each do |event|
@@ -573,7 +596,7 @@ module Hawkular::Alerts::RSpec
573
596
  after(:all) do
574
597
  # cleanup test values
575
598
  record('Alert/Events', credentials, 'setup_cleanup') do
576
- @client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, credentials, options)
599
+ @client = Hawkular::Alerts::Client.new(ALERTS_BASE, credentials, options)
577
600
  json = IO.read('spec/integration/alert-resources/events-test-data.json')
578
601
  hash = JSON.parse(json)
579
602
  hash['events'].each do |event|
@@ -592,7 +615,7 @@ module Hawkular::Alerts::RSpec
592
615
  end
593
616
 
594
617
  it 'Should list events' do
595
- client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, creds, options)
618
+ client = Hawkular::Alerts::Client.new(ALERTS_BASE, creds, options)
596
619
 
597
620
  events = client.list_events('thin' => true)
598
621
 
@@ -601,7 +624,7 @@ module Hawkular::Alerts::RSpec
601
624
  end
602
625
 
603
626
  it 'Should list events using criteria' do
604
- client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, creds, options)
627
+ client = Hawkular::Alerts::Client.new(ALERTS_BASE, creds, options)
605
628
 
606
629
  events = client.list_events('categories' => %w(my-category-01 my-category-02))
607
630
 
@@ -610,7 +633,7 @@ module Hawkular::Alerts::RSpec
610
633
  end
611
634
 
612
635
  it 'Should not list events using criteria' do
613
- client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, creds, options)
636
+ client = Hawkular::Alerts::Client.new(ALERTS_BASE, creds, options)
614
637
 
615
638
  events = client.list_events('startTime' => 0, 'endTime' => 1000)
616
639
 
@@ -622,7 +645,7 @@ module Hawkular::Alerts::RSpec
622
645
  the_id = "test-event@#{Time.new.to_i}"
623
646
  VCR.eject_cassette
624
647
  record('Alert/Events', credentials.merge(id: the_id), cassette_name) do
625
- client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, creds, options)
648
+ client = Hawkular::Alerts::Client.new(ALERTS_BASE, creds, options)
626
649
 
627
650
  the_event = client.create_event(the_id, 'MyCategory', 'Li la lu',
628
651
  context: { message: 'This is a test' },
@@ -639,7 +662,7 @@ module Hawkular::Alerts::RSpec
639
662
  the_id = "test-event@#{Time.new.to_i}"
640
663
  VCR.eject_cassette
641
664
  record('Alert/Events', credentials.merge(id: the_id), cassette_name) do
642
- client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, creds, options)
665
+ client = Hawkular::Alerts::Client.new(ALERTS_BASE, creds, options)
643
666
  client.create_event(the_id, 'MyCategory', 'Li la lu',
644
667
  context: { message: 'This is a test' },
645
668
  tags: { tag_name: 'tag-value' })
@@ -662,7 +685,7 @@ module Hawkular::Alerts::RSpec
662
685
  end
663
686
 
664
687
  before(:each) do
665
- @client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, creds, options)
688
+ @client = Hawkular::Alerts::Client.new(ALERTS_BASE, creds, options)
666
689
  end
667
690
 
668
691
  it 'Should create and fire a trigger' do