hawkular-client 3.0.2 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ab85ad134aa538531c4b1a49bd2719fa891e571
4
- data.tar.gz: 3f6eac54b04032844df33902c440e34f6e08f674
3
+ metadata.gz: 29d98c76e5262c54b3c0949ebfd998051e3abb81
4
+ data.tar.gz: b7c63829113d7bd814d5a300f3e6d8da36b48195
5
5
  SHA512:
6
- metadata.gz: 006e318a94934bf4c982cdee7cddd0c0e0d511a5162aa79cccd19a0a6d9c956f0a4fa3dbca75f2faf32d03f1b3c5eeebe770fa37d8e68e10961308bbf391700c
7
- data.tar.gz: 1858d7ad7caac9a136f42419da8b7b9e990216f62cf4529dbdeaa45080a84d3e6f69fe55cdda8296b593f0aa6157f01718c3377ddb51547cd900e6e25ff840f2
6
+ metadata.gz: 5e3c7e6e3ccc5bdd7357dfa435046bf428f7f5a88800222d4dedddcd6e525a28a348a6af6d725096c49b71b8c724ceed0263948b2ec85b9a963b31f2761dd92a
7
+ data.tar.gz: 50aa5323c03caf2704e1d5848c7311ef7d9c640a7c73583aa911da9d8976262f75bc6139a385a8f541f58cdf1c1b5dd843e642ce4d9367523c5062370d2d214b
@@ -4,6 +4,11 @@ This document describes the relevant changes between releases of the
4
4
  _hawkular-client_ project.
5
5
 
6
6
 
7
+ === v 4.0.0
8
+ * Standardized Exceptions under the Hawkular namespace, and the old names were deprecated, here is the list:
9
+ 1. <code>Hawkular::BaseClient::HawkularException</code> -> <code>Hawkular::Exception</code>
10
+ 2. <code>Hawkular::BaseClient::HawkularConnectionException</code> -> <code>Hawkular::ConnectionException</code>
11
+
7
12
  === v 3.0.2
8
13
  * Adding <code>URI.unescape</code> in the <code>list_metrics_for_resource</code> method to fix the behavior of the method
9
14
 
@@ -6,7 +6,7 @@
6
6
 
7
7
  A Ruby Hawkular Client.
8
8
 
9
- Documentation[http://www.hawkular.org/hawkular-client-ruby/docs/]
9
+ Documentation[http://www.hawkular.org/hawkular-client-ruby/]
10
10
 
11
11
  == Changelog
12
12
 
@@ -9,6 +9,9 @@ module Hawkular
9
9
  # that inherit from it. You should not directly use it,
10
10
  # but through the more specialized clients.
11
11
  class BaseClient
12
+ HawkularException = Hawkular::Exception
13
+ HawkularConnectionException = Hawkular::ConnectionException
14
+
12
15
  include ClientUtils
13
16
 
14
17
  # @!visibility private
@@ -34,7 +37,7 @@ module Hawkular
34
37
 
35
38
  @logger = Hawkular::Logger.new
36
39
 
37
- fail 'You need to provide an entrypoint' if entrypoint.nil?
40
+ fail Hawkular::ArgumentError, 'You need to provide an entrypoint' if entrypoint.nil?
38
41
  end
39
42
 
40
43
  def http_get(suburl, headers = {})
@@ -141,7 +144,8 @@ module Hawkular
141
144
  # @param suffix_path [String] sufix path to be added if it doesn't exist
142
145
  # @return [String] URL with path attached to it at the end
143
146
  def normalize_entrypoint_url(entrypoint, suffix_path)
144
- fail ArgumentError, 'suffix_path must not be empty' if suffix_path.empty?
147
+ fail Hawkular::ArgumentError, 'suffix_path must not be empty' if suffix_path.empty?
148
+
145
149
  strip_path = suffix_path.gsub(%r{/$}, '')
146
150
  strip_path.nil? || suffix_path = strip_path
147
151
  strip_path = suffix_path.gsub(%r{^/}, '')
@@ -165,21 +169,6 @@ module Hawkular
165
169
  url.to_s.sub(/^http(s?)/, 'ws\1')
166
170
  end
167
171
 
168
- # Specialized exception to be thrown
169
- # when the interaction with Hawkular fails
170
- class HawkularException < StandardError
171
- def initialize(message, status_code = 0)
172
- @message = message
173
- @status_code = status_code
174
- super(message)
175
- end
176
-
177
- attr_reader :message, :status_code
178
- end
179
-
180
- class HawkularConnectionException < HawkularException
181
- end
182
-
183
172
  def admin_header
184
173
  headers = {}
185
174
  headers[:'Hawkular-Admin-Token'] = @admin_token unless @admin_token.nil?
@@ -201,17 +190,18 @@ module Hawkular
201
190
  # @!visibility private
202
191
  def connect_error(fault)
203
192
  if fault.is_a?(SocketError)
204
- HawkularConnectionException.new(fault.to_s)
193
+ Hawkular::ConnectionException.new(fault.to_s)
205
194
  elsif [Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EHOSTUNREACH,
206
195
  Errno::EADDRNOTAVAIL, Errno::ENETDOWN, Errno::ENETUNREACH,
207
196
  Errno::ETIMEDOUT].include?(fault.class)
208
- HawkularConnectionException.new(fault.to_s, fault.class::Errno)
197
+ Hawkular::ConnectionException.new(fault.to_s, fault.class::Errno)
209
198
  end
210
199
  end
211
200
 
212
201
  def handle_fault(f)
213
202
  http_code = (f.respond_to?(:http_code) ? f.http_code : 0)
214
- fail HawkularException.new('Unauthorized', http_code) if f.instance_of? RestClient::Unauthorized
203
+ fail Hawkular::Exception.new('Unauthorized', http_code) if f.instance_of? RestClient::Unauthorized
204
+
215
205
  if f.respond_to?(:http_body) && !f.http_body.nil?
216
206
  begin
217
207
  json_body = JSON.parse(f.http_body)
@@ -219,11 +209,12 @@ module Hawkular
219
209
  rescue JSON::ParserError
220
210
  fault_message = f.http_body
221
211
  end
222
- fail HawkularException.new(fault_message, http_code)
212
+
213
+ fail Hawkular::Exception.new(fault_message, http_code)
223
214
  elsif (connect_error_exception = connect_error(f))
224
- fail connect_error_exception
215
+ fail Hawkular::ConnectionException, connect_error_exception
225
216
  else
226
- fail f
217
+ fail Hawkular::Exception, f
227
218
  end
228
219
  end
229
220
  end
@@ -1,4 +1,22 @@
1
1
  module Hawkular
2
+ # Specialized exception to be thrown
3
+ # when the interaction with Hawkular fails
4
+ class Exception < StandardError
5
+ def initialize(message, status_code = 0)
6
+ @message = message
7
+ @status_code = status_code
8
+ super(message)
9
+ end
10
+
11
+ attr_reader :message, :status_code
12
+ end
13
+
14
+ class ConnectionException < Hawkular::Exception
15
+ end
16
+
17
+ class ArgumentError < Hawkular::Exception
18
+ end
19
+
2
20
  module ClientUtils
3
21
  # Escapes the passed url part. This is necessary,
4
22
  # as many ids inside Hawkular can contain characters
@@ -12,7 +12,9 @@ module Hawkular
12
12
  def initialize(hash)
13
13
  hash[:credentials] ||= {}
14
14
  hash[:options] ||= {}
15
- fail 'no parameter ":entrypoint" given' if hash[:entrypoint].nil?
15
+
16
+ fail Hawkular::ArgumentError, 'no parameter ":entrypoint" given' if hash[:entrypoint].nil?
17
+
16
18
  @state = hash
17
19
  end
18
20
 
@@ -24,7 +26,7 @@ module Hawkular
24
26
  when /^operations_/ then operations
25
27
  when /^tokens_/ then tokens
26
28
  else
27
- fail "unknown method prefix `#{name}`, allowed prefixes:"\
29
+ fail Hawkular::ArgumentError, "unknown method prefix `#{name}`, allowed prefixes:"\
28
30
  '`inventory_`, `metrics_`,`alerts_`,`operations_`, `tokens_`'
29
31
  end
30
32
  method = name.to_s.sub(/^[^_]+_/, '')
@@ -181,7 +181,8 @@ module Hawkular::Inventory
181
181
  end
182
182
 
183
183
  def self.parse(path)
184
- fail 'CanonicalPath must not be nil or empty' if path.to_s.strip.length == 0
184
+ fail Hawkular::ArgumentError, 'CanonicalPath must not be nil or empty' if path.to_s.strip.length == 0
185
+
185
186
  CanonicalPath.new(path_to_h path)
186
187
  end
187
188
 
@@ -257,7 +258,8 @@ module Hawkular::Inventory
257
258
  end
258
259
 
259
260
  def to_tags
260
- fail 'Missing feed_id' if @feed_id.nil?
261
+ fail Hawkular::ArgumentError, 'Missing feed_id' if @feed_id.nil?
262
+
261
263
  tags = "module:inventory,feed:#{Regexp.quote(@feed_id)}"
262
264
  tags += ",type:rt,id:#{Regexp.quote(@resource_type_id)}" if @resource_type_id
263
265
  tags += ",type:mt,id:#{Regexp.quote(@metric_type_id)}" if @metric_type_id
@@ -34,7 +34,8 @@ module Hawkular::Inventory
34
34
  # entrypoint: http://localhost:8080/hawkular/inventory
35
35
  # and another sub-hash containing the hash with username[String], password[String], token(optional)
36
36
  def self.create(hash)
37
- fail 'no parameter ":entrypoint" given' unless hash[:entrypoint]
37
+ fail Hawkular::ArgumentError, 'no parameter ":entrypoint" given' unless hash[:entrypoint]
38
+
38
39
  hash[:credentials] ||= {}
39
40
  hash[:options] ||= {}
40
41
  Client.new(hash[:entrypoint], hash[:credentials], hash[:options])
@@ -52,7 +53,8 @@ module Hawkular::Inventory
52
53
  # @param [String] feed_id The id of the feed the type lives under
53
54
  # @return [Array<ResourceType>] List of types, that can be empty
54
55
  def list_resource_types(feed_id)
55
- fail 'Feed id must be given' unless feed_id
56
+ fail Hawkular::ArgumentError, 'Feed id must be given' unless feed_id
57
+
56
58
  feed_path = feed_cp(feed_id)
57
59
  response = http_post(
58
60
  '/strings/raw/query',
@@ -70,7 +72,8 @@ module Hawkular::Inventory
70
72
  # @param [String] feed_id The id of the feed the type lives under
71
73
  # @return [Array<MetricType>] List of types, that can be empty
72
74
  def list_metric_types(feed_id)
73
- fail 'Feed id must be given' unless feed_id
75
+ fail Hawkular::ArgumentError, 'Feed id must be given' unless feed_id
76
+
74
77
  feed_path = feed_cp(feed_id)
75
78
  response = http_post(
76
79
  '/strings/raw/query',
@@ -89,7 +92,8 @@ module Hawkular::Inventory
89
92
  # @param [Boolean] fetch_properties Should the config data be fetched too
90
93
  # @return [Array<Resource>] List of resources, which can be empty.
91
94
  def list_resources_for_feed(feed_id, fetch_properties = false, filter = {})
92
- fail 'Feed id must be given' unless feed_id
95
+ fail Hawkular::ArgumentError, 'Feed id must be given' unless feed_id
96
+
93
97
  feed_path = feed_cp(feed_id)
94
98
  response = http_post(
95
99
  '/strings/raw/query',
@@ -113,8 +117,9 @@ module Hawkular::Inventory
113
117
  # @return [Array<Resource>] List of resources. Can be empty
114
118
  def list_resources_for_type(resource_type_path, fetch_properties = false)
115
119
  path = CanonicalPath.parse_if_string(resource_type_path)
116
- fail 'Feed id must be given' unless path.feed_id
117
- fail 'Resource type must be given' unless path.resource_type_id
120
+
121
+ fail Hawkular::ArgumentError, 'Feed id must be given' unless path.feed_id
122
+ fail Hawkular::ArgumentError, 'Resource type must be given' unless path.resource_type_id
118
123
 
119
124
  # Fetch metrics by tag
120
125
  feed_path = feed_cp(URI.unescape(path.feed_id))
@@ -151,7 +156,9 @@ module Hawkular::Inventory
151
156
  def list_child_resources(parent_res_path, recursive = false)
152
157
  path = CanonicalPath.parse_if_string(parent_res_path)
153
158
  feed_id = path.feed_id
154
- fail 'Feed id must be given' unless feed_id
159
+
160
+ fail Hawkular::ArgumentError, 'Feed id must be given' unless feed_id
161
+
155
162
  entity_hash = get_raw_entity_hash(path)
156
163
  extract_child_resources([], path.to_s, entity_hash, recursive) if entity_hash
157
164
  end
@@ -163,8 +170,10 @@ module Hawkular::Inventory
163
170
  # @return [Array<Metric>] List of metrics. Can be empty
164
171
  def list_metrics_for_metric_type(metric_type_path)
165
172
  path = CanonicalPath.parse_if_string(metric_type_path)
166
- fail 'Feed id must be given' unless path.feed_id
167
- fail 'Metric type id must be given' unless path.metric_type_id
173
+
174
+ fail Hawkular::ArgumentError, 'Feed id must be given' unless path.feed_id
175
+ fail Hawkular::ArgumentError, 'Metric type id must be given' unless path.metric_type_id
176
+
168
177
  feed_id = URI.unescape(path.feed_id)
169
178
  metric_type_id = URI.unescape(path.metric_type_id)
170
179
 
@@ -224,10 +233,11 @@ module Hawkular::Inventory
224
233
  def get_resource(resource_path, fetch_properties = true)
225
234
  path = CanonicalPath.parse_if_string(resource_path)
226
235
  raw_hash = get_raw_entity_hash(path)
236
+
227
237
  unless raw_hash
228
- exception = HawkularException.new("Resource not found: #{resource_path}")
229
- fail exception
238
+ fail Hawkular::Exception, "Resource not found: #{resource_path}"
230
239
  end
240
+
231
241
  entity_hash = entity_json_to_hash(-> (_) { path }, raw_hash, fetch_properties)
232
242
  Resource.new(entity_hash)
233
243
  end
@@ -237,10 +247,11 @@ module Hawkular::Inventory
237
247
  def get_resource_type(resource_type_path)
238
248
  path = CanonicalPath.parse_if_string(resource_type_path)
239
249
  raw_hash = get_raw_entity_hash(path)
250
+
240
251
  unless raw_hash
241
- exception = HawkularException.new("Resource type not found: #{resource_type_path}")
242
- fail exception
252
+ fail Hawkular::Exception, "Resource type not found: #{resource_type_path}"
243
253
  end
254
+
244
255
  entity_hash = entity_json_to_hash(-> (_) { path }, raw_hash, false)
245
256
  ResourceType.new(entity_hash)
246
257
  end
@@ -250,10 +261,11 @@ module Hawkular::Inventory
250
261
  def get_metric_type(metric_type_path)
251
262
  path = CanonicalPath.parse_if_string(metric_type_path)
252
263
  raw_hash = get_raw_entity_hash(path)
264
+
253
265
  unless raw_hash
254
- exception = HawkularException.new("Metric type not found: #{metric_type_path}")
255
- fail exception
266
+ fail Hawkular::Exception, "Metric type not found: #{metric_type_path}"
256
267
  end
268
+
257
269
  entity_hash = entity_json_to_hash(-> (_) { path }, raw_hash, false)
258
270
  MetricType.new(entity_hash)
259
271
  end
@@ -263,8 +275,10 @@ module Hawkular::Inventory
263
275
  # @return [Array<String>] List of operation type ids
264
276
  def list_operation_definitions(resource_type_path)
265
277
  path = CanonicalPath.parse_if_string(resource_type_path)
266
- fail 'Missing feed_id in resource_type_path' unless path.feed_id
267
- fail 'Missing resource_type_id in resource_type_path' unless path.resource_type_id
278
+
279
+ fail Hawkular::ArgumentError, 'Missing feed_id in resource_type_path' unless path.feed_id
280
+ fail Hawkular::ArgumentError, 'Missing resource_type_id in resource_type_path' unless path.resource_type_id
281
+
268
282
  response = http_post(
269
283
  '/strings/raw/query',
270
284
  fromEarliest: true,
@@ -445,26 +459,34 @@ module Hawkular::Inventory
445
459
  end
446
460
 
447
461
  def extract_structures_from_body(response_body_array)
448
- response_body_array.map { |element| rebuild_from_chunks(element['data']) }
462
+ response_body_array.map { |element| Client.rebuild_from_chunks(element['data']) }
449
463
  .select { |full| full } # evict nil
450
- .map { |full| decompress(full) }
464
+ .map { |full| Client.decompress(full) }
451
465
  end
452
466
 
453
- def rebuild_from_chunks(data_node)
467
+ def self.rebuild_from_chunks(data_node)
454
468
  return if data_node.empty?
455
469
  master_data = data_node[0]
456
470
  return Base64.decode64(master_data['value']) unless (master_data.key? 'tags') &&
457
471
  (master_data['tags'].key? 'chunks')
472
+ master_timestamp = master_data['timestamp']
458
473
  last_chunk = master_data['tags']['chunks'].to_i - 1
459
474
  all = Base64.decode64(master_data['value'])
460
475
  return if all.empty?
461
476
  (1..last_chunk).inject(all) do |full, chunk_id|
462
477
  slave_data = data_node[chunk_id]
478
+ # Race condition: slave_data might be nil if not all chunks have been written yet on DB
479
+ # Consider the object is not there yet
480
+ return nil unless slave_data
481
+ # The same race condition could give us an expirated slave_data; do sanity check to cover that
482
+ # Timestamps are useful here, they're in consecutive, decreasing order
483
+ slave_timestamp = slave_data['timestamp']
484
+ return nil unless slave_timestamp == master_timestamp - chunk_id
463
485
  full.concat(Base64.decode64(slave_data['value']))
464
486
  end
465
487
  end
466
488
 
467
- def decompress(raw)
489
+ def self.decompress(raw)
468
490
  gz = Zlib::GzipReader.new(StringIO.new(raw))
469
491
  JSON.parse(gz.read)
470
492
  end
@@ -35,11 +35,12 @@ module Hawkular::Metrics
35
35
 
36
36
  def check_version
37
37
  version_status_hash = fetch_version_and_status
38
+
38
39
  fail_version_msg = 'Unable to determine implementation version for metrics'
39
- fail fail_version_msg if version_status_hash['Implementation-Version'].nil?
40
+ fail Hawkular::Exception, fail_version_msg if version_status_hash['Implementation-Version'].nil?
40
41
  version = version_status_hash['Implementation-Version']
41
42
  major, minor = version.scan(/\d+/).map(&:to_i)
42
- fail fail_version_msg if major.nil? || minor.nil?
43
+ fail Hawkular::Exception, fail_version_msg if major.nil? || minor.nil?
43
44
  @legacy_api = (major == 0 && minor < 16)
44
45
  end
45
46
 
@@ -1,3 +1,6 @@
1
+ require 'timeout'
2
+ require 'monitor'
3
+
1
4
  require 'hawkular/base_client'
2
5
  require 'websocket-client-simple'
3
6
  require 'json'
@@ -13,14 +16,7 @@ class Proc
13
16
  method_name = callable.to_sym
14
17
  define_method(method_name) { |&block| block.nil? ? true : block.call(result) }
15
18
  define_method("#{method_name}?") { true }
16
-
17
- # method_missing is here because we are not forcing the client to provide both success and error callbacks
18
- # rubocop:disable Lint/NestedMethodDefinition
19
- # https://github.com/bbatsov/rubocop/issues/2704
20
- def method_missing(_method_name, *_args, &_block)
21
- PerformMethodMissing
22
- end
23
- # rubocop:enable Lint/NestedMethodDefinition
19
+ define_method(:method_missing) { |*| PerformMethodMissing }
24
20
  end.new)
25
21
  end
26
22
  end
@@ -30,6 +26,7 @@ module Hawkular::Operations
30
26
  # Client class to interact with the agent via websockets
31
27
  class Client < Hawkular::BaseClient
32
28
  include WebSocket::Client
29
+ include MonitorMixin
33
30
 
34
31
  attr_accessor :ws, :session_id, :logger
35
32
 
@@ -75,26 +72,36 @@ module Hawkular::Operations
75
72
  args[:use_secure_connection] = %w(https wss).include?(uri.scheme) ? true : false
76
73
  end
77
74
 
78
- fail 'no parameter ":host" or ":entrypoint" given' if args[:host].nil?
75
+ fail Hawkular::ArgumentError, 'no parameter ":host" or ":entrypoint" given' if args[:host].nil?
79
76
 
80
77
  super(args[:host], args[:credentials], args[:options])
81
78
 
82
- url = "ws#{args[:use_secure_connection] ? 's' : ''}://#{args[:host]}/hawkular/command-gateway/ui/ws"
79
+ @logger = Hawkular::Logger.new
80
+
81
+ @url = "ws#{args[:use_secure_connection] ? 's' : ''}://#{args[:host]}/hawkular/command-gateway/ui/ws"
82
+ @credentials = args[:credentials]
83
+ @tenant = args[:options][:tenant]
84
+ @wait_time = args[:wait_time]
85
+ end
86
+
87
+ def base64_credentials
88
+ ["#{@credentials[:username]}:#{@credentials[:password]}"].pack('m').delete("\r\n")
89
+ end
83
90
 
84
- creds = args[:credentials]
85
- base64_creds = ["#{creds[:username]}:#{creds[:password]}"].pack('m').delete("\r\n")
91
+ def connect
92
+ return if @connecting || (@ws && @ws.open?)
93
+
94
+ @connecting = true
86
95
 
87
96
  ws_options = {
88
97
  headers: {
89
- 'Authorization' => 'Basic ' + base64_creds,
90
- 'Hawkular-Tenant' => args[:options][:tenant],
98
+ 'Authorization' => 'Basic ' + base64_credentials,
99
+ 'Hawkular-Tenant' => @tenant,
91
100
  'Accept' => 'application/json'
92
101
  }
93
102
  }
94
103
 
95
- @logger = Hawkular::Logger.new
96
-
97
- @ws = Simple.connect url, ws_options do |client|
104
+ @ws = Simple.connect @url, ws_options do |client|
98
105
  client.on(:message, once: true) do |msg|
99
106
  parsed_message = msg.data.to_msg_hash
100
107
 
@@ -107,12 +114,14 @@ module Hawkular::Operations
107
114
  end
108
115
  end
109
116
 
110
- sleep args[:wait_time]
117
+ Timeout.timeout(@wait_time) { sleep 0.1 until @ws.open? }
118
+ ensure
119
+ @connecting = false
111
120
  end
112
121
 
113
122
  # Closes the WebSocket connection
114
123
  def close_connection!
115
- @ws.close
124
+ @ws && @ws.close
116
125
  end
117
126
 
118
127
  # Invokes a generic operation on the WildFly agent
@@ -136,7 +145,7 @@ module Hawkular::Operations
136
145
  # RemoveDatasource (and not RemoveDatasourceRequest)
137
146
  # @param callback [Block] callback that is run after the operation is done
138
147
  def invoke_specific_operation(operation_payload, operation_name, &callback)
139
- fail 'Operation must be specified' if operation_name.nil?
148
+ fail Hawkular::ArgumentError, 'Operation must be specified' if operation_name.nil?
140
149
  required = [:resourcePath]
141
150
  check_pre_conditions operation_payload, required, &callback
142
151
 
@@ -297,7 +306,7 @@ module Hawkular::Operations
297
306
  # @param [String] resource_path canonical path of the WildFly server
298
307
  # @param callback [Block] callback that is run after the operation is done
299
308
  def export_jdr(resource_path, &callback)
300
- fail 'resource_path must be specified' if resource_path.nil?
309
+ fail Hawkular::ArgumentError, 'resource_path must be specified' if resource_path.nil?
301
310
  check_pre_conditions(&callback)
302
311
 
303
312
  invoke_specific_operation({ resourcePath: resource_path }, 'ExportJdr', &callback)
@@ -322,6 +331,8 @@ module Hawkular::Operations
322
331
  private
323
332
 
324
333
  def invoke_operation_helper(operation_payload, operation_name = nil, binary_content = nil, &callback)
334
+ synchronize { connect }
335
+
325
336
  # fallback to generic 'ExecuteOperation' if nothing is specified
326
337
  operation_name ||= 'ExecuteOperation'
327
338
  add_credentials! operation_payload
@@ -332,19 +343,23 @@ module Hawkular::Operations
332
343
  payload = "#{operation_name}Request=#{operation_payload.to_json}"
333
344
  payload += binary_content unless binary_content.nil?
334
345
  @ws.send payload, type: binary_content.nil? ? :text : :binary
346
+ rescue => e
347
+ callback.perform(:failure, "#{e.class} - #{e.message}")
335
348
  end
336
349
 
337
350
  def check_pre_conditions(hash = {}, params = [], &callback)
338
- fail 'Handshake with server has not been done.' unless @ws.open?
339
- fail 'Hash cannot be nil.' if hash.nil?
340
- fail 'callback must have the perform method defined. include Hawkular::Operations' unless
351
+ fail Hawkular::ArgumentError, 'Hash cannot be nil.' if hash.nil?
352
+ fail Hawkular::ArgumentError, 'callback must have the perform method defined. include Hawkular::Operations' unless
341
353
  callback.nil? || callback.respond_to?('perform')
354
+
342
355
  params.each do |property|
343
356
  next unless hash[property].nil?
344
357
  err_callback = 'You need to specify error callback'
345
358
  err_message = "Hash property #{property} must be specified"
346
- fail(ArgumentError, err_callback) if callback.nil?
347
- fail(ArgumentError, err_callback) if callback.perform(:failure, err_message).equal? Proc::PerformMethodMissing
359
+
360
+ if !callback || callback.perform(:failure, err_message) == Proc::PerformMethodMissing
361
+ fail(Hawkular::ArgumentError, err_callback)
362
+ end
348
363
  end
349
364
  end
350
365
 
@@ -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 = '3.0.2'.freeze
7
+ VERSION = '4.0.0'.freeze
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hawkular-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Libor Zoubek
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-05-04 00:00:00.000000000 Z
14
+ date: 2017-06-27 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rest-client
@@ -145,14 +145,14 @@ dependencies:
145
145
  requirements:
146
146
  - - "~>"
147
147
  - !ruby/object:Gem::Version
148
- version: 1.24.0
148
+ version: '3.0'
149
149
  type: :development
150
150
  prerelease: false
151
151
  version_requirements: !ruby/object:Gem::Requirement
152
152
  requirements:
153
153
  - - "~>"
154
154
  - !ruby/object:Gem::Version
155
- version: 1.24.0
155
+ version: '3.0'
156
156
  - !ruby/object:Gem::Dependency
157
157
  name: vcr
158
158
  requirement: !ruby/object:Gem::Requirement