hawkular-client 2.0.0 → 2.1.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: 0deaaa015739eac52e9e7dee6baa5af63676ead7
4
- data.tar.gz: 86167936dc2869bc8ae120649edf36d0078fba52
3
+ metadata.gz: a881d3c60a017681d81648d65397217c78f5c30f
4
+ data.tar.gz: 4ab68c65b422bcc0eaa5075c4ce8ac873af54d03
5
5
  SHA512:
6
- metadata.gz: c568daeb2e618ea436afc6af14ba5b98d6531e24ca6d7478b123ea868318e82700c1b4556eab69b4f9814aae57a4dc5dec029c9a6ef43c5b8828c410ff41de9e
7
- data.tar.gz: 1e3595bf9e178c835d84bc17f5c0104a630e0c14e506f9e119807f39b2625c1e30f1428125b4df6d6a14ad141d085cb9c5c2d074a76e83c3af03893ad46fd144
6
+ metadata.gz: 2b463dbb1267dd39f7701e09491f85f5341baa29f72b492a5df090461b12a4ac8e2a934f13dcc18fa65cedae37f0f7de3d5c8b022fc13bda9c6b54adf0734996
7
+ data.tar.gz: 780f5436eebc3149df30ed2329b4a7ee7d1245163e10fd8078e112b266be8f43758a3f3e1cd0d636525f1f197160c201bffd187fdd2a77000bbd3a3818268a17
data/CHANGES.rdoc CHANGED
@@ -3,6 +3,11 @@
3
3
  This document describes the relevant changes between releases of the
4
4
  _hawkular-client_ project.
5
5
 
6
+ === V 2.1.0
7
+ * Fix an issue where the operations endpoint constructor expected a host to be passed, which was not.
8
+ * Add authentication to the websocket setup in Operations sub-client.
9
+ * Add a status endpoint call for the Alerts sub-client
10
+
6
11
  === V 2.0.0
7
12
  * This version is compatible with hawkular-services[https://github.com/hawkular/hawkular-services]
8
13
  * By default no Tenant-Header is send in the requests, which is compatible with the old versions of Hawkular. However,
@@ -20,6 +20,13 @@ module Hawkular::Alerts
20
20
  super(entrypoint, credentials, options)
21
21
  end
22
22
 
23
+ # Return version and status information for the used version of Hawkular-Alerting
24
+ # @return [Hash{String=>String}]
25
+ # ('Implementation-Version', 'Built-From-Git-SHA1', 'status')
26
+ def fetch_version_and_status
27
+ http_get('/status')
28
+ end
29
+
23
30
  # Lists defined triggers in the system
24
31
  # @param [Array] ids List of trigger ids. If provided, limits to the given triggers
25
32
  # @param [Array] tags List of tags. If provided, limits to the given tags. Individual
@@ -43,9 +43,12 @@ module Hawkular::Operations
43
43
 
44
44
  # Initialize new OperationsClient
45
45
  #
46
- # @param [Hash] args Arguments for client
46
+ # @param [Hash] args Arguments for client.
47
+ # There are two ways of passing in the target host/port: via :host and via :entrypoint. If
48
+ # both are given, then :entrypoint will be used.
47
49
  #
48
- # @option args [String] :host base url of Hawkular - e.g http://localhost:8080
50
+ # @option args [String] :entrypoint Base URL of the hawkular server e.g. http://localhost:8080.
51
+ # @option args [String] :host base host:port pair of Hawkular - e.g localhost:8080
49
52
  # @option args [Hash{String=>String}] :credentials Hash of (username password) or token
50
53
  # @option args [Hash{String=>String}] :options Additional rest client options
51
54
  # @option args [Fixnum] :wait_time Time in seconds describing how long the constructor should block - handshake
@@ -53,14 +56,29 @@ module Hawkular::Operations
53
56
  # @example
54
57
  # Hawkular::Operations::OperationsClient.new(credentials: {username: 'jdoe', password: 'password'})
55
58
  def initialize(args)
56
- args[:host] ||= 'localhost:8080'
59
+ ep = args[:entrypoint]
60
+
61
+ unless ep.nil?
62
+ uri = URI.parse ep
63
+ args[:host] ||= "#{uri.host}:#{uri.port}"
64
+ end
65
+
66
+ fail 'no parameter ":host" or ":entrypoint" given' if args[:host].nil?
57
67
  args[:credentials] ||= {}
58
68
  args[:options] ||= {}
59
69
  args[:wait_time] ||= 0.5
60
70
  super(args[:host], args[:credentials], args[:options])
61
71
  # note: if we start using the secured WS, change the protocol to wss://
62
- url = "ws://#{entrypoint}/hawkular/command-gateway/ui/ws"
63
- @ws = Simple.connect url do |client|
72
+ url = "ws://#{args[:host]}/hawkular/command-gateway/ui/ws"
73
+ ws_options = {}
74
+ creds = args[:credentials]
75
+ base64_creds = ["#{creds[:username]}:#{creds[:password]}"].pack('m').delete("\r\n")
76
+ ws_options[:headers] = { 'Authorization' => 'Basic ' + base64_creds,
77
+ 'Hawkular-Tenant' => args[:options][:tenant],
78
+ 'Accept' => 'application/json'
79
+ }
80
+
81
+ @ws = Simple.connect url, ws_options do |client|
64
82
  client.on(:message, once: true) do |msg|
65
83
  parsed_message = msg.data.to_msg_hash
66
84
  puts parsed_message if ENV['HAWKULARCLIENT_LOG_RESPONSE']
@@ -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.0.0'
7
+ VERSION = '2.1.0'
8
8
  end
@@ -424,13 +424,16 @@ module Hawkular::Alerts::RSpec
424
424
  end
425
425
  end
426
426
 
427
- # TODO: enable when alerts supports it
428
- # describe 'Alerts' do
429
- # it 'Should return the version' do
430
- # data = @client.get_version_and_status
431
- # expect(data).not_to be_nil
432
- # end
433
- # end
427
+ describe 'Alerts', vcr: { decode_compressed_response: true } do
428
+ before(:each) do
429
+ @client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, creds)
430
+ end
431
+
432
+ it 'Should return the version' do
433
+ data = @client.fetch_version_and_status
434
+ expect(data).not_to be_nil
435
+ end
436
+ end
434
437
 
435
438
  describe 'Alert/Events', :vcr do
436
439
  VCR.configure do |c|
@@ -188,7 +188,7 @@ module Hawkular::Client::RSpec
188
188
  }
189
189
 
190
190
  actual_data = {}
191
- client = Hawkular::Operations::OperationsClient.new(credentials: @creds)
191
+ client = Hawkular::Operations::OperationsClient.new(entrypoint: 'http://localhost:8080', credentials: @creds)
192
192
  client.invoke_generic_operation(redeploy) do |on|
193
193
  on.success do |data|
194
194
  actual_data[:data] = data
@@ -20,16 +20,95 @@ module Hawkular::Operations::RSpec
20
20
 
21
21
  WebSocketVCR.record(example, self) do
22
22
  client = OperationsClient.new(host: HOST,
23
+ wait_time: WebSocketVCR.live? ? 1.5 : 2,
24
+ credentials: {
25
+ username: 'jdoe',
26
+ password: 'password'
27
+ },
28
+ options: {
29
+ tenant: 'hawkular'
30
+ })
31
+ ws = client.ws
32
+ expect(ws).not_to be nil
33
+ expect(ws.open?).to be true
34
+ end
35
+ end
36
+
37
+ it 'should be established via entrypoint' do
38
+ WebSocketVCR.configure do |c|
39
+ c.hook_uris = ['127.0.0.1:8080']
40
+ end
41
+
42
+ WebSocketVCR.record(example, self) do
43
+ ep = URI::HTTP.build(host: '127.0.0.1', port: 8080).to_s
44
+
45
+ client = OperationsClient.new(entrypoint: ep,
23
46
  wait_time: WebSocketVCR.live? ? 1.5 : 0,
24
47
  credentials: {
25
48
  username: 'jdoe',
26
49
  password: 'password'
50
+ },
51
+ options: {
52
+ tenant: 'hawkular'
27
53
  })
28
54
  ws = client.ws
29
55
  expect(ws).not_to be nil
30
56
  expect(ws.open?).to be true
31
57
  end
32
58
  end
59
+
60
+ it 'should run into error callback' do
61
+ WebSocketVCR.configure do |c|
62
+ c.hook_uris = [HOST]
63
+ end
64
+
65
+ WebSocketVCR.record(example, self) do
66
+ client = OperationsClient.new(host: HOST,
67
+ wait_time: WebSocketVCR.live? ? 1.5 : 2,
68
+ credentials: {
69
+ username: 'jdoe',
70
+ password: 'password'
71
+ },
72
+ options: {
73
+ tenant: 'hawkular'
74
+ })
75
+
76
+ noop = { operationName: 'noop', resourcePath: '/bla' }
77
+
78
+ client.invoke_generic_operation(noop) do |on|
79
+ on.success do |_data|
80
+ fail 'This should have failed'
81
+ end
82
+ on.failure do |error|
83
+ puts 'error callback was correctly called, reason: ' + error.to_s
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ it 'should bail with no host' do
90
+ WebSocketVCR.configure do |c|
91
+ c.hook_uris = [HOST]
92
+ end
93
+
94
+ WebSocketVCR.record(example, self) do
95
+ begin
96
+ OperationsClient.new(
97
+ wait_time: WebSocketVCR.live? ? 1.5 : 2,
98
+ credentials: {
99
+ username: 'jdoe',
100
+ password: 'password'
101
+ },
102
+ options: {
103
+ tenant: 'hawkular'
104
+ })
105
+ rescue
106
+ puts 'We got an exception and this is good'
107
+ else
108
+ fail 'Should have failed as no host was given'
109
+ end
110
+ end
111
+ end
33
112
  end
34
113
 
35
114
  describe 'Operation/Operation', :websocket, vcr: { decode_compressed_response: true } do
@@ -51,7 +130,8 @@ module Hawkular::Operations::RSpec
51
130
 
52
131
  before(:each) do |ex|
53
132
  unless ex.metadata[:skip_open]
54
- @client = OperationsClient.new(credentials: @creds,
133
+ @client = OperationsClient.new(entrypoint: 'http://localhost:8080',
134
+ credentials: @creds,
55
135
  wait_time: WebSocketVCR.live? ? 1.5 : 0)
56
136
  @ws = @client.ws
57
137
  end
@@ -235,7 +315,7 @@ module Hawkular::Operations::RSpec
235
315
  @client.close_connection! unless @client.nil?
236
316
 
237
317
  # open the connection
238
- operations_client = OperationsClient.new(credentials: @creds)
318
+ operations_client = OperationsClient.new(entrypoint: 'http://localhost:8080', credentials: @creds)
239
319
 
240
320
  redeploy = {
241
321
  operationName: 'Redeploy',
data/spec/spec_helper.rb CHANGED
@@ -165,7 +165,7 @@ RSpec.configure do |config|
165
165
  if ENV['VCR_OFF'] == '1'
166
166
  VCR.eject_cassette
167
167
  VCR.turn_off!(ignore_cassettes: true)
168
- WebSocketVCR.turn_off!
168
+ WebSocketVCR.turn_off! # TODO: this does not work as the impl is empty
169
169
  WebMock.allow_net_connect!
170
170
  puts 'VCR is turned off!'
171
171
  end
@@ -0,0 +1,40 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://jdoe:password@localhost:8080/hawkular/alerts/status
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Content-Type:
15
+ - application/json
16
+ User-Agent:
17
+ - Ruby
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Connection:
24
+ - keep-alive
25
+ X-Powered-By:
26
+ - Undertow/1
27
+ Server:
28
+ - WildFly/10
29
+ Content-Type:
30
+ - application/json
31
+ Content-Length:
32
+ - '124'
33
+ Date:
34
+ - Tue, 21 Jun 2016 07:58:51 GMT
35
+ body:
36
+ encoding: UTF-8
37
+ string: '{"Implementation-Version":"1.1.1.Final","Built-From-Git-SHA1":"d5381ab686932023c5a2e136dc25a4848bd7ba43","status":"STARTED"}'
38
+ http_version:
39
+ recorded_at: Tue, 21 Jun 2016 07:58:51 GMT
40
+ recorded_with: VCR 3.0.1
@@ -0,0 +1,9 @@
1
+ [
2
+ [
3
+ {
4
+ "operation": "read",
5
+ "type": "text",
6
+ "data": "WelcomeResponse={\"sessionId\":\"4y1VEeMV520Ok-c-0busP6CL8auBUS6jNEMCVPyV\"}"
7
+ }
8
+ ]
9
+ ]
@@ -0,0 +1,13 @@
1
+ [
2
+ [
3
+ {
4
+ "operation": "read",
5
+ "type": "text",
6
+ "data": "WelcomeResponse={\"sessionId\":\"r4OAdkbOPYTA5HRnjgKW2vsq1TCGjZNT-Y3_qpco\"}"
7
+ },
8
+ {
9
+ "operation": "write",
10
+ "data": "ExecuteOperationRequest={\"operationName\":\"noop\",\"resourcePath\":\"/bla\",\"authentication\":{\"username\":\"jdoe\",\"password\":\"password\"}}"
11
+ }
12
+ ]
13
+ ]
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: 2.0.0
4
+ version: 2.1.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: 2016-06-20 00:00:00.000000000 Z
14
+ date: 2016-06-27 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rest-client
@@ -181,8 +181,7 @@ dependencies:
181
181
  - - ">="
182
182
  - !ruby/object:Gem::Version
183
183
  version: '0'
184
- description: |2
185
- A Ruby client for Hawkular
184
+ description: " A Ruby client for Hawkular\n"
186
185
  email:
187
186
  - lzoubek@redhat.com
188
187
  - hrupp@redhat.com
@@ -258,6 +257,7 @@ files:
258
257
  - spec/vcr_cassettes/Alert/Triggers/Should_get_the_action_definitions.yml
259
258
  - spec/vcr_cassettes/Alert/Triggers/Should_not_create_an_action_for_unknown_plugin.yml
260
259
  - spec/vcr_cassettes/Alert/Triggers/Should_not_create_an_action_for_unknown_properties.yml
260
+ - spec/vcr_cassettes/Alerts/Should_return_the_version.yml
261
261
  - spec/vcr_cassettes/Availability_metrics/Should_create_Availability_definition_using_MetricDefinition_parameter.yml
262
262
  - spec/vcr_cassettes/Availability_metrics/Should_create_and_return_Availability_using_Hash_parameter.yml
263
263
  - spec/vcr_cassettes/Availability_metrics/Should_push_metric_data_to_non-existing_Availability.yml
@@ -344,7 +344,10 @@ files:
344
344
  - spec/vcr_cassettes/Operation/Operation/Remove_deployment_should_be_performed_and_eventually_respond_with_success.json
345
345
  - spec/vcr_cassettes/Operation/Operation/Undeploy_should_be_performed_and_eventually_respond_with_success.json
346
346
  - spec/vcr_cassettes/Operation/Operation/should_not_be_possible_to_perform_on_closed_client.json
347
+ - spec/vcr_cassettes/Operation/Websocket_connection/should_bail_with_no_host.json
347
348
  - spec/vcr_cassettes/Operation/Websocket_connection/should_be_established.json
349
+ - spec/vcr_cassettes/Operation/Websocket_connection/should_be_established_via_entrypoint.json
350
+ - spec/vcr_cassettes/Operation/Websocket_connection/should_run_into_error_callback.json
348
351
  - spec/vcr_cassettes/Simple/Should_be_Cool.yml
349
352
  - spec/vcr_cassettes/Tenants/Should_Get_Tenant_For_Explicit_Credentials.yml
350
353
  - spec/vcr_cassettes/Tenants/Should_Get_Tenant_For_Implicit_Credentials.yml
@@ -425,6 +428,7 @@ test_files:
425
428
  - spec/vcr_cassettes/Alert/Triggers/Should_get_the_action_definitions.yml
426
429
  - spec/vcr_cassettes/Alert/Triggers/Should_not_create_an_action_for_unknown_plugin.yml
427
430
  - spec/vcr_cassettes/Alert/Triggers/Should_not_create_an_action_for_unknown_properties.yml
431
+ - spec/vcr_cassettes/Alerts/Should_return_the_version.yml
428
432
  - spec/vcr_cassettes/Availability_metrics/Should_create_Availability_definition_using_MetricDefinition_parameter.yml
429
433
  - spec/vcr_cassettes/Availability_metrics/Should_create_and_return_Availability_using_Hash_parameter.yml
430
434
  - spec/vcr_cassettes/Availability_metrics/Should_push_metric_data_to_non-existing_Availability.yml
@@ -511,7 +515,10 @@ test_files:
511
515
  - spec/vcr_cassettes/Operation/Operation/Remove_deployment_should_be_performed_and_eventually_respond_with_success.json
512
516
  - spec/vcr_cassettes/Operation/Operation/Undeploy_should_be_performed_and_eventually_respond_with_success.json
513
517
  - spec/vcr_cassettes/Operation/Operation/should_not_be_possible_to_perform_on_closed_client.json
518
+ - spec/vcr_cassettes/Operation/Websocket_connection/should_bail_with_no_host.json
514
519
  - spec/vcr_cassettes/Operation/Websocket_connection/should_be_established.json
520
+ - spec/vcr_cassettes/Operation/Websocket_connection/should_be_established_via_entrypoint.json
521
+ - spec/vcr_cassettes/Operation/Websocket_connection/should_run_into_error_callback.json
515
522
  - spec/vcr_cassettes/Simple/Should_be_Cool.yml
516
523
  - spec/vcr_cassettes/Tenants/Should_Get_Tenant_For_Explicit_Credentials.yml
517
524
  - spec/vcr_cassettes/Tenants/Should_Get_Tenant_For_Implicit_Credentials.yml