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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc8f82c57d113d57a96488d3d5537e7e20449435
4
- data.tar.gz: 365a613e0f23108b62d87fbb1bf78cc0ac7db08a
3
+ metadata.gz: f90b7acb9dd7b68be8eee6d0bb3de9dbf7741889
4
+ data.tar.gz: 6949105936e1945f288c7580ac79e12bfab21138
5
5
  SHA512:
6
- metadata.gz: e072263ba50864dc2c3e7a5bdcd3e4bb4975f2dde4157fa31ddcb2498d5889ed83473c76186ba20b47cb80730e9d4f803ec1f2374b82d9ca9c49a16feb299f7a
7
- data.tar.gz: acd1aef7ed3c8a2282a355efd8d9e1a06b4968c5a5e113e388dadd0d8bc5a5d24e309745beaf0078d4d0db121aeaf7b9dbd8ecb3ccb622c4d15da40bfd170fc2
6
+ metadata.gz: 4dda4fc49377010414493c0fd44ff4ff2fd26dfaa9bd8501abdc4a786f883cfaba563c1bfec1980238d6abd548289d33f56f071372d77619e4a665b0761cc032
7
+ data.tar.gz: 493b2e043dede0926bee0bb65ca09f51ae8913619ace6e3dbd07985fb895ec0cef661b8ba953b1ae39d17ed81b4e754df4d318004ea17a0edc618b2851b586cd
data/.travis.yml CHANGED
@@ -17,7 +17,4 @@ env:
17
17
  services:
18
18
  - docker
19
19
  before_install:
20
- - (test $RUN_ON_LIVE_SERVER = 1 && docker-compose up -d && ./.travis/wait_for_services.rb) || echo "Skipping live server"
21
- # Lets wait a bit for the agent to load everything it needs.
22
- before_script:
23
- - (test $RUN_ON_LIVE_SERVER = 1 && sleep 20s) || true
20
+ - (test $RUN_ON_LIVE_SERVER = 1 && ./.travis/start_hawkular_services.sh -d && ./.travis/wait_for_services.rb) || echo "Skipping live server"
@@ -0,0 +1,21 @@
1
+ #!/bin/bash
2
+
3
+ docker-compose up -d myCassandra
4
+
5
+ # Wait for Cassandra
6
+ CASSANDRA_STATUS="undecided"
7
+ TOTAL_WAIT=0;
8
+ while [ "$CASSANDRA_STATUS" != "running" ] && [ $TOTAL_WAIT -lt 60 ]; do
9
+ CASSANDRA_STATUS=`docker-compose exec myCassandra nodetool statusbinary | tr -dc '[[:print:]]'`
10
+ echo "Cassandra server status: $CASSANDRA_STATUS."
11
+
12
+ sleep 3
13
+
14
+ TOTAL_WAIT=$((TOTAL_WAIT+3))
15
+ echo "Waited $TOTAL_WAIT seconds for Cassandra to start."
16
+ done
17
+
18
+ # Ensure the volume exists and has correct permissions.
19
+ mkdir -p /tmp/opt/hawkular/server
20
+ chown 1000:1000 -R /tmp/opt/hawkular
21
+ docker-compose up -d hawkular
@@ -1,23 +1,39 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'net/http'
3
+ require 'json'
3
4
 
4
- uris = [
5
- 'http://localhost:8080/hawkular/status',
6
- 'http://localhost:8080/hawkular/metrics/status',
7
- 'http://localhost:8080/hawkular/alerts/status',
8
- 'http://localhost:8080/hawkular/inventory/status'
9
- ]
5
+ services = {
6
+ 'hawkular-services' => {
7
+ url: 'http://localhost:8080/hawkular/status',
8
+ is_ready: -> (response) { response.code == '200' }
9
+ },
10
+ 'metrics' => {
11
+ url: 'http://localhost:8080/hawkular/metrics/status',
12
+ is_ready: -> (response) { response.code == '200' && JSON.parse(response.body)['MetricsService'] == 'STARTED' }
13
+ },
14
+ 'alerts' => {
15
+ url: 'http://localhost:8080/hawkular/alerts/status',
16
+ is_ready: -> (response) { response.code == '200' && JSON.parse(response.body)['status'] == 'STARTED' }
17
+ },
18
+ 'inventory' => {
19
+ url: 'http://localhost:8080/hawkular/inventory/status',
20
+ is_ready: -> (response) { response.code == '200' && JSON.parse(response.body)['Initialized'] == 'true' }
21
+ }
22
+ }
10
23
 
11
- uris.each do |uri_string|
24
+ services.each do |name, service|
12
25
  loop do
13
- uri = URI(uri_string)
26
+ uri = URI(service[:url])
14
27
  begin
15
28
  response = Net::HTTP.get_response(uri)
16
- break if response.code == '200'
17
- puts "Waiting for: #{uri_string}"
29
+ break if service[:is_ready].call(response)
30
+ puts "Waiting for: #{name}"
18
31
  rescue
19
32
  puts 'Waiting for Hawkular-Services to accept connections'
20
33
  end
21
34
  sleep 5
22
35
  end
23
36
  end
37
+ puts 'Waiting 2 minutes for agent to complete it\'s first round...'
38
+ sleep 120
39
+ puts 'Hawkular-services started successfully... '
data/CHANGES.rdoc CHANGED
@@ -3,6 +3,32 @@
3
3
  This document describes the relevant changes between releases of the
4
4
  _hawkular-client_ project.
5
5
 
6
+ === V 2.9.0
7
+ * Adding a way to update collection interval on the agent
8
+ * Fixed <code>get_entity</code> method in the inventory client
9
+ * Big improvements to the testing suite. Now we run the tests against live Hawkular server that runs as a Docker container
10
+ * Fixed a bug in operations client where it was necessary to pass the operation name only as a string and it silently failed with symbol
11
+ * Alert conditions now expose also the interval field
12
+ * Added an option to query metrics based on tag only (regardless to type)
13
+ * Improved passing of options to underlying Rest client
14
+ * The API is now consistent when creating resource that already existed
15
+ * Making sure the gem can work with Alerts 1.5.1
16
+ * Now it's unable to add/remove datasources if the Hawkular Services are running in container
17
+ * All the sub-clients are now lazily initiated with the first usage
18
+ * Adds the ability to assign and remove tags to existing alerts
19
+ * Uniform client names
20
+
21
+ ==== Deprecations
22
+ * instead of <code>HawkularUtilsMixin</code> use <code>Hawkular::ClientUtils</code>
23
+ * instead of <code>Hawkular::Operations::OperationsClient</code> use <code>Hawkular::Operations::Client</code>
24
+ * instead of <code>Hawkular::Alerts::AlertsClient</code> use <code>Hawkular::Alerts::Client</code>
25
+ * instead of <code>Hawkular::Token::TokenClient</code> use <code>Hawkular::Token::Client</code>
26
+ * instead of <code>Hawkular::Inventory::InventoryClient</code> use <code>Hawkular::Inventory::Client</code>
27
+
28
+ Warning: in the next major version we may remove the deprecated API
29
+
30
+ Full list of changes can be found at https://github.com/hawkular/hawkular-client-ruby/milestone/14?closed=1
31
+
6
32
  === V 2.8.0
7
33
 
8
34
  * Allow to list tags in Hawkular-Metrics
data/README.rdoc CHANGED
@@ -61,6 +61,18 @@ You can also access each subproject's API individually, if you would like to use
61
61
  options: { tenant: 'hawkular' }
62
62
  )
63
63
 
64
+ === HTTP and HTTPS options
65
+
66
+ Will all client classes, the +:options+ hash can contain extra parameters passed through to +RestClient+ gem. It can include a +:headers+ sub-hash to add custom headers:
67
+
68
+ require 'hawkular/hawkular_client'
69
+ client = Hawkular::Client.new(
70
+ entrypoint: 'http://localhost:8080',
71
+ credentials: { username: 'jdoe', password: 'password' },
72
+ options: { tenant: 'hawkular', proxy: 'proxy.example.com', ssl_ca_file: 'ca.pem',
73
+ headers: {'Max-Forwards': 5} }
74
+ )
75
+
64
76
  === Examples
65
77
 
66
78
  Suppose you will monitor the availability of two networks to later determine which one is the best.
@@ -147,4 +159,3 @@ variables:
147
159
  Client documentation can be generated using http://yardoc.org
148
160
 
149
161
  yardoc
150
-
data/docker-compose.yml CHANGED
@@ -1,15 +1,17 @@
1
1
  hawkular:
2
- image: "pilhuhn/hawkular-services:latest"
2
+ image: "hawkular/hawkular-services:latest"
3
3
  ports:
4
4
  - "8080:8080"
5
5
  - "8443:8443"
6
6
  - "9990:9990"
7
7
  links:
8
8
  - myCassandra
9
+ volumes:
10
+ - /tmp/opt/hawkular/server:/opt/data
9
11
  environment:
10
12
  - CASSANDRA_NODES=myCassandra
11
13
  - ADMIN_TOKEN
12
14
  myCassandra:
13
- image: cassandra:3.7
15
+ image: cassandra:3.0.9
14
16
  environment:
15
17
  - CASSANDRA_START_RPC=true
@@ -26,6 +26,7 @@ Gem::Specification.new do |gem|
26
26
  gem.add_runtime_dependency('addressable')
27
27
  gem.add_development_dependency('shoulda')
28
28
  gem.add_development_dependency('rspec-rails', '~> 3.1')
29
+ gem.add_development_dependency('actionpack', '~> 4')
29
30
  gem.add_development_dependency('rake', '< 11')
30
31
  gem.add_development_dependency('simple-websocket-vcr', '= 0.0.7')
31
32
  gem.add_development_dependency('yard')
@@ -34,6 +35,7 @@ Gem::Specification.new do |gem|
34
35
  gem.add_development_dependency('rubocop', '= 0.34.2')
35
36
  gem.add_development_dependency('coveralls')
36
37
  gem.add_development_dependency('rack', '~> 1.6.4')
38
+ gem.add_development_dependency('pry-byebug')
37
39
 
38
40
  gem.rdoc_options << '--title' << gem.name <<
39
41
  '--main' << 'README.rdoc' << '--line-numbers' << '--inline-source'
@@ -13,7 +13,7 @@ module Hawkular::Alerts
13
13
  # http://localhost:8080/hawkular/alerts
14
14
  # @param credentials [Hash{String=>String}] Hash of username, password, token(optional)
15
15
  # @param options [Hash{String=>String}] Additional rest client options
16
- class AlertsClient < Hawkular::BaseClient
16
+ class Client < Hawkular::BaseClient
17
17
  def initialize(entrypoint, credentials = {}, options = {})
18
18
  entrypoint = normalize_entrypoint_url entrypoint, 'hawkular/alerts'
19
19
  @entrypoint = entrypoint
@@ -322,6 +322,22 @@ module Hawkular::Alerts
322
322
  def delete_event(id)
323
323
  http_delete "/events/#{id}"
324
324
  end
325
+
326
+ # Add tags to existing Alerts.
327
+ # @param [Array<numeric>] alert_ids List of alert IDs
328
+ # @param [Array<String>] tags List of tags. Each tag of format 'name|value'.
329
+ def add_tags(alert_ids, tags)
330
+ query = generate_query_params(alertIds: alert_ids, tags: tags)
331
+ http_put('/tags' + query, {})
332
+ end
333
+
334
+ # Remove tags from existing Alerts.
335
+ # @param [Array<numeric>] alert_ids List of alert IDs
336
+ # @param [Array<String>] tag_names List of tag names.
337
+ def remove_tags(alert_ids, tag_names)
338
+ query = generate_query_params(alertIds: alert_ids, tagNames: tag_names)
339
+ http_delete('/tags' + query)
340
+ end
325
341
  end
326
342
 
327
343
  # Representation of one Trigger
@@ -406,6 +422,7 @@ module Hawkular::Alerts
406
422
  @data2_id = cond_hash['data2Id']
407
423
  @data2_multiplier = cond_hash['data2Multiplier']
408
424
  @trigger_id = cond_hash['triggerId']
425
+ @interval = cond_hash['interval']
409
426
  end
410
427
 
411
428
  def to_h
@@ -420,6 +437,7 @@ module Hawkular::Alerts
420
437
  cond_hash['data2Id'] = @data2_id
421
438
  cond_hash['data2Multiplier'] = @data2_multiplier
422
439
  cond_hash['triggerId'] = @trigger_id
440
+ cond_hash['interval'] = @interval
423
441
  cond_hash
424
442
  end
425
443
  end
@@ -557,4 +575,7 @@ module Hawkular::Alerts
557
575
  super(event_hash)
558
576
  end
559
577
  end
578
+
579
+ AlertsClient = Client
580
+ deprecate_constant :AlertsClient if self.respond_to? :deprecate_constant
560
581
  end
@@ -1,16 +1,18 @@
1
1
  require 'base64'
2
2
  require 'addressable/uri'
3
- require 'hawkular/hawkular_client_utils'
3
+
4
+ require 'hawkular/logger'
5
+ require 'hawkular/client_utils'
4
6
 
5
7
  module Hawkular
6
8
  # This is the base functionality for all the clients,
7
9
  # that inherit from it. You should not directly use it,
8
10
  # but through the more specialized clients.
9
11
  class BaseClient
10
- include HawkularUtilsMixin
12
+ include ClientUtils
11
13
 
12
14
  # @!visibility private
13
- attr_reader :credentials, :entrypoint, :options
15
+ attr_reader :credentials, :entrypoint, :options, :logger
14
16
  # @return [Tenants] access tenants API
15
17
  attr_reader :tenants
16
18
 
@@ -24,22 +26,22 @@ module Hawkular
24
26
  token: nil
25
27
  }.merge(credentials)
26
28
  @options = {
27
- tenant: nil,
28
- admin_token: nil,
29
- ssl_ca_file: nil,
30
29
  verify_ssl: OpenSSL::SSL::VERIFY_PEER,
31
- ssl_client_cert: nil,
32
- ssl_client_key: nil,
33
- http_proxy_uri: nil,
34
30
  headers: {}
35
31
  }.merge(options)
32
+ @tenant = @options.delete(:tenant)
33
+ @admin_token = @options.delete(:admin_token)
34
+
35
+ @logger = Hawkular::Logger.new
36
36
 
37
37
  fail 'You need to provide an entrypoint' if entrypoint.nil?
38
38
  end
39
39
 
40
40
  def http_get(suburl, headers = {})
41
41
  res = rest_client(suburl).get(http_headers(headers))
42
- puts "#{res}\n" if ENV['HAWKULARCLIENT_LOG_RESPONSE']
42
+
43
+ logger.log(res)
44
+
43
45
  res.empty? ? {} : JSON.parse(res)
44
46
  rescue
45
47
  handle_fault $ERROR_INFO
@@ -48,7 +50,9 @@ module Hawkular
48
50
  def http_post(suburl, hash, headers = {})
49
51
  body = JSON.generate(hash)
50
52
  res = rest_client(suburl).post(body, http_headers(headers))
51
- puts "#{res}\n" if ENV['HAWKULARCLIENT_LOG_RESPONSE']
53
+
54
+ logger.log(res)
55
+
52
56
  res.empty? ? {} : JSON.parse(res)
53
57
  rescue
54
58
  handle_fault $ERROR_INFO
@@ -57,7 +61,9 @@ module Hawkular
57
61
  def http_put(suburl, hash, headers = {})
58
62
  body = JSON.generate(hash)
59
63
  res = rest_client(suburl).put(body, http_headers(headers))
60
- puts "#{res}\n" if ENV['HAWKULARCLIENT_LOG_RESPONSE']
64
+
65
+ logger.log(res)
66
+
61
67
  res.empty? ? {} : JSON.parse(res)
62
68
  rescue
63
69
  handle_fault $ERROR_INFO
@@ -65,7 +71,9 @@ module Hawkular
65
71
 
66
72
  def http_delete(suburl, headers = {})
67
73
  res = rest_client(suburl).delete(http_headers(headers))
68
- puts "#{res}\n" if ENV['HAWKULARCLIENT_LOG_RESPONSE']
74
+
75
+ logger.log(res)
76
+
69
77
  res.empty? ? {} : JSON.parse(res)
70
78
  rescue
71
79
  handle_fault $ERROR_INFO
@@ -73,17 +81,14 @@ module Hawkular
73
81
 
74
82
  # @!visibility private
75
83
  def rest_client(suburl)
76
- options[:timeout] = ENV['HAWKULARCLIENT_REST_TIMEOUT'] if ENV['HAWKULARCLIENT_REST_TIMEOUT']
77
- options[:ssl_ca_file] = @options[:ssl_ca_file]
78
- options[:verify_ssl] = @options[:verify_ssl]
79
- options[:ssl_client_cert] = @options[:ssl_client_cert]
80
- options[:ssl_client_key] = @options[:ssl_client_key]
81
- options[:proxy] = @options[:http_proxy_uri]
82
- options[:user] = @credentials[:username]
83
- options[:password] = @credentials[:password]
84
+ opts = @options.dup
85
+ opts[:timeout] ||= ENV['HAWKULARCLIENT_REST_TIMEOUT'] if ENV['HAWKULARCLIENT_REST_TIMEOUT']
86
+ opts[:proxy] ||= opts.delete(:http_proxy_uri)
87
+ opts[:user] = @credentials[:username]
88
+ opts[:password] = @credentials[:password]
84
89
  # strip @endpoint in case suburl is absolute
85
90
  suburl = suburl[@entrypoint.length, suburl.length] if suburl.match(/^http/)
86
- RestClient::Resource.new(@entrypoint, options)[suburl]
91
+ RestClient::Resource.new(@entrypoint, opts)[suburl]
87
92
  end
88
93
 
89
94
  # @!visibility private
@@ -177,7 +182,7 @@ module Hawkular
177
182
 
178
183
  def admin_header
179
184
  headers = {}
180
- headers[:'Hawkular-Admin-Token'] = @options[:admin_token] unless @options[:admin_token].nil?
185
+ headers[:'Hawkular-Admin-Token'] = @admin_token unless @admin_token.nil?
181
186
  headers
182
187
  end
183
188
 
@@ -189,7 +194,7 @@ module Hawkular
189
194
 
190
195
  def tenant_header
191
196
  headers = {}
192
- headers[:'Hawkular-Tenant'] = @options[:tenant] unless @options[:tenant].nil?
197
+ headers[:'Hawkular-Tenant'] = @tenant unless @tenant.nil?
193
198
  headers
194
199
  end
195
200
 
@@ -0,0 +1,42 @@
1
+ module Hawkular
2
+ module ClientUtils
3
+ # Escapes the passed url part. This is necessary,
4
+ # as many ids inside Hawkular can contain characters
5
+ # that are invalid for an url/uri.
6
+ # The passed value is duplicated
7
+ # Does not escape the = character
8
+ # @param [String] url_part Part of an url to be escaped
9
+ # @return [String] escaped url_part as new string
10
+ def hawk_escape(url_part)
11
+ return url_part.to_s if url_part.is_a?(Numeric)
12
+
13
+ url_part
14
+ .to_s
15
+ .dup
16
+ .gsub('%', '%25')
17
+ .gsub(' ', '%20')
18
+ .gsub('[', '%5b')
19
+ .gsub(']', '%5d')
20
+ .gsub('|', '%7c')
21
+ .gsub('(', '%28')
22
+ .gsub(')', '%29')
23
+ .gsub('/', '%2f')
24
+ end
25
+
26
+ # Escapes the passed url part. This is necessary,
27
+ # as many ids inside Hawkular can contain characters
28
+ # that are invalid for an url/uri.
29
+ # The passed value is duplicated
30
+ # Does escape the = character
31
+ # @param [String] url_part Part of an url to be escaped
32
+ # @return [String] escaped url_part as new string
33
+ def hawk_escape_id(url_part)
34
+ hawk_escape(url_part)
35
+ .gsub('=', '%3d')
36
+ .gsub(';', '%3b')
37
+ end
38
+ end
39
+ end
40
+
41
+ HawkularUtilsMixin = Hawkular::ClientUtils
42
+ deprecate_constant(:HawkularUtilsMixin) if self.respond_to?(:deprecate_constant)
@@ -0,0 +1,15 @@
1
+ require 'logger'
2
+
3
+ module Hawkular
4
+ module EnvConfig
5
+ module_function
6
+
7
+ def log_response?
8
+ ENV['HAWKULARCLIENT_LOG_RESPONSE']
9
+ end
10
+
11
+ def rest_timeout
12
+ ENV['HAWKULARCLIENT_REST_TIMEOUT']
13
+ end
14
+ end
15
+ end
@@ -1,5 +1,5 @@
1
1
  require 'hawkular/inventory/inventory_api'
2
- require 'hawkular/metrics/metrics_client.rb'
2
+ require 'hawkular/metrics/metrics_client'
3
3
  require 'hawkular/alerts/alerts_api'
4
4
  require 'hawkular/tokens/tokens_api'
5
5
  require 'hawkular/operations/operations_api'
@@ -14,31 +14,15 @@ module Hawkular
14
14
  hash[:options] ||= {}
15
15
  fail 'no parameter ":entrypoint" given' if hash[:entrypoint].nil?
16
16
  @state = hash
17
-
18
- @inventory = Inventory::InventoryClient.create(entrypoint: "#{hash[:entrypoint]}/hawkular/inventory",
19
- credentials: hash[:credentials],
20
- options: hash[:options])
21
-
22
- @metrics = Metrics::Client.new("#{hash[:entrypoint]}/hawkular/metrics",
23
- hash[:credentials],
24
- hash[:options])
25
-
26
- @alerts = Alerts::AlertsClient.new("#{hash[:entrypoint]}/hawkular/alerts",
27
- hash[:credentials],
28
- hash[:options])
29
-
30
- @tokens = Token::TokenClient.new(hash[:entrypoint],
31
- hash[:credentials],
32
- hash[:options])
33
17
  end
34
18
 
35
19
  def method_missing(name, *args, &block)
36
20
  delegate_client = case name
37
- when /^inventory_/ then @inventory
38
- when /^metrics_/ then @metrics
39
- when /^alerts_/ then @alerts
40
- when /^operations_/ then @operations ||= init_operations_client
41
- when /^tokens_/ then @tokens
21
+ when /^inventory_/ then inventory
22
+ when /^metrics_/ then metrics
23
+ when /^alerts_/ then alerts
24
+ when /^operations_/ then operations
25
+ when /^tokens_/ then tokens
42
26
  else
43
27
  fail "unknown method prefix `#{name}`, allowed prefixes:"\
44
28
  '`inventory_`, `metrics_`,`alerts_`,`operations_`, `tokens_`'
@@ -47,6 +31,24 @@ module Hawkular
47
31
  delegate_client.__send__(method, *args, &block)
48
32
  end
49
33
 
34
+ def inventory
35
+ @inventory ||= Inventory::Client.new("#{@state[:entrypoint]}/hawkular/inventory",
36
+ @state[:credentials],
37
+ @state[:options])
38
+ end
39
+
40
+ def metrics
41
+ @metrics ||= Metrics::Client.new("#{@state[:entrypoint]}/hawkular/metrics",
42
+ @state[:credentials],
43
+ @state[:options])
44
+ end
45
+
46
+ def alerts
47
+ @alerts ||= Alerts::Client.new("#{@state[:entrypoint]}/hawkular/alerts",
48
+ @state[:credentials],
49
+ @state[:options])
50
+ end
51
+
50
52
  # adds a way to explicitly open the new web socket connection (the default is to recycle it)
51
53
  # @param open_new [Boolean] if true, opens the new websocket connection
52
54
  def operations(open_new = false)
@@ -54,13 +56,19 @@ module Hawkular
54
56
  @operations ||= init_operations_client
55
57
  end
56
58
 
59
+ def tokens
60
+ @tokens ||= Token::Client.new(@state[:entrypoint],
61
+ @state[:credentials],
62
+ @state[:options])
63
+ end
64
+
57
65
  private
58
66
 
59
67
  # this is in a dedicated method, because constructor opens the websocket connection to make the handshake
60
68
  def init_operations_client
61
- Operations::OperationsClient.new(entrypoint: @state[:entrypoint],
62
- credentials: @state[:credentials],
63
- options: @state[:options])
69
+ Operations::Client.new(entrypoint: @state[:entrypoint],
70
+ credentials: @state[:credentials],
71
+ options: @state[:options])
64
72
  end
65
73
  end
66
74
  end