-
Notifications
You must be signed in to change notification settings - Fork 28
/
operations_spec.rb
420 lines (378 loc) · 15.3 KB
/
operations_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
require "#{File.dirname(__FILE__)}/../vcr/vcr_setup"
require "#{File.dirname(__FILE__)}/../spec_helper"
require 'securerandom'
include Hawkular::Inventory
include Hawkular::Operations
# examples for operations, it uses the websocket communication
module Hawkular::Operations::RSpec
HOST = 'localhost:8080'
describe 'Operation/Websocket connection', vcr: { decode_compressed_response: true } do
let(:example) do |e|
e
end
it 'should be established' do
VCR::WebSocket.configure do |c|
c.hook_uris = [HOST]
end
VCR::WebSocket.record(example, self) do
client = OperationsClient.new(host: HOST,
wait_time: 0,
credentials: {
username: 'jdoe',
password: 'password'
})
ws = client.ws
expect(ws).not_to be nil
expect(ws.open?).to be true
end
end
end
describe 'Operation/Operation', :websocket, vcr: { decode_compressed_response: true } do
let(:example) do |e|
e
end
before(:all) do
# TODO: erb substitution
VCR.use_cassette('Operation/Helpers/get_tenant', decode_compressed_response: true) do
@creds = { username: 'jdoe', password: 'password' }
inventory_client = InventoryClient.create(credentials: @creds)
@tenant_id = inventory_client.get_tenant
# @feed_id = inventory_client.list_feeds[0]
@feed_id = '41df9f9c-72a6-457b-a0ee-ee1740846254'
# @random_uuid = SecureRandom.uuid comment this out once the erb support is there
@random_uuid = 'random'
end
end
before(:each) do |ex|
unless ex.metadata[:skip_open]
@client = OperationsClient.new(credentials: @creds,
wait_time: 0)
@ws = @client.ws
end
end
around(:each) do |ex|
if ex.metadata[:websocket]
VCR::WebSocket.configure do |c|
c.hook_uris = [HOST]
end
VCR::WebSocket.record(ex, self) do
ex.run
end
else
ex.run
end
end
after(:each) do |ex|
unless ex.metadata[:skip_close]
@client.close_connection!
@client = nil
@ws = nil
end
end
it 'Add JDBC driver should add the driver' do
wf_server_resource_id = 'Local~~'
driver_name = 'CreatedByRubyDriver' + @random_uuid
driver_bits = IO.binread("#{File.dirname(__FILE__)}/../resources/driver.jar")
wf_path = CanonicalPath.new(tenant_id: @tenant_id,
feed_id: @feed_id,
resource_ids: [wf_server_resource_id]).to_s
actual_data = {}
@client.add_jdbc_driver(resource_path: wf_path,
driver_jar_name: 'driver.jar',
driver_name: driver_name,
module_name: 'foo.bar.' + @random_uuid, # jboss module
driver_class: 'com.mysql.jdbc.Driver',
binary_content: driver_bits) do |on|
on.success do |data|
actual_data[:data] = data
end
on.failure do |error|
actual_data[:data] = {}
puts 'error callback was called, reason: ' + error.to_s
end
end
actual_data = wait_for actual_data
expect(actual_data['status']).to eq('OK')
expect(actual_data['message']).to start_with('Added JDBC Driver')
expect(actual_data['driverName']).to eq(driver_name)
end
it 'Redeploy should be performed and eventually respond with success' do
wf_server_resource_id = 'Local~~'
alerts_war_resource_id = 'Local~%2Fdeployment%3Dhawkular-alerts-actions-email.war'
path = CanonicalPath.new(tenant_id: @tenant_id,
feed_id: @feed_id,
resource_ids: [wf_server_resource_id, alerts_war_resource_id])
redeploy = {
operationName: 'Redeploy',
resourcePath: path.to_s
}
actual_data = {}
@client.invoke_generic_operation(redeploy) do |on|
on.success do |data|
actual_data[:data] = data
end
on.failure do |error|
actual_data[:data] = {}
puts 'error callback was called, reason: ' + error.to_s
end
end
# expectations don't work from callbacks so waiting for the results via blocking helper `wait_for`
actual_data = wait_for actual_data
expect(actual_data['status']).to eq('OK')
expect(actual_data['resourcePath']).to eq(path.to_s)
expect(actual_data['message']).to start_with('Performed [Redeploy] on')
end
it 'Redeploy should not be performed if resource path is wrong' do
wf_server_resource_id = 'Local~~'
wrong_war_resource_id = 'Local~%2Fdeployment%3Dnon-existent.war'
path = CanonicalPath.new(tenant_id: @tenant_id,
feed_id: @feed_id,
resource_ids: [wf_server_resource_id, wrong_war_resource_id])
redeploy = {
operationName: 'Redeploy',
resourcePath: path.to_s
}
actual_data = {}
@client.invoke_generic_operation(redeploy) do |on|
on.success do |_|
actual_data[:data] = { error: 'the operation should have failed' }
end
on.failure do |error|
actual_data[:data] = { error: error }
end
end
actual_data = wait_for actual_data
expect(actual_data[:error]).to start_with('Could not perform [Redeploy] on')
end
it 'Undeploy should be performed and eventually respond with success' do
wf_server_resource_id = 'Local~~'
alerts_war_resource_id = 'Local~%2Fdeployment%3Dhawkular-alerts-actions-email.war'
path = CanonicalPath.new(tenant_id: @tenant_id,
feed_id: @feed_id,
resource_ids: [wf_server_resource_id, alerts_war_resource_id])
undeploy = {
operationName: 'Undeploy',
resourcePath: path.to_s
}
actual_data = {}
@client.invoke_generic_operation(undeploy) do |on|
on.success do |data|
actual_data[:data] = data
end
on.failure do |error|
actual_data[:data] = {}
puts 'error callback was called, reason: ' + error.to_s
end
end
actual_data = wait_for actual_data
expect(actual_data['status']).to eq('OK')
expect(actual_data['message']).to start_with('Performed [Undeploy] on')
end
it 'Add datasource should be doable' do
wf_server_resource_id = 'Local~~'
wf_path = CanonicalPath.new(tenant_id: @tenant_id,
feed_id: @feed_id,
resource_ids: [wf_server_resource_id]).to_s
payload = {
# compulsory fields
resourcePath: wf_path,
xaDatasource: false,
datasourceName: 'CreatedByRubyDS' + @random_uuid,
jndiName: 'java:jboss/datasources/CreatedByRubyDS' + @random_uuid,
driverName: 'h2',
# this is probably a bug (driver class should be already defined in driver)
driverClass: 'org.h2.Driver',
connectionUrl: 'dbc:h2:mem:ruby;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE',
# optional
datasourceProperties: {
someKey: 'someValue'
},
userName: 'sa',
password: 'sa',
securityDomain: 'other'
# xaDataSourceClass: 'clazz' for xa DS
}
actual_data = {}
@client.add_datasource(payload) do |on|
on.success do |data|
actual_data[:data] = data
end
on.failure do |error|
actual_data[:data] = { 'status' => 'ERROR' }
puts 'error callback was called, reason: ' + error.to_s
end
end
actual_data = wait_for actual_data
expect(actual_data['status']).to eq('OK')
expect(actual_data['message']).to start_with('Added Datasource')
expect(actual_data['xaDatasource']).to be_falsey
expect(actual_data['datasourceName']).to eq(payload[:datasourceName])
expect(actual_data['resourcePath']).to eq(payload[:resourcePath])
end
it 'should not be possible to perform on closed client', skip_open: true, skip_close: true do
@client.close_connection! unless @client.nil?
# open the connection
operations_client = OperationsClient.new(credentials: @creds)
redeploy = {
operationName: 'Redeploy',
resourcePath: '/t;t1/f;whatever/r;something'
}
# close the connection
operations_client.close_connection!
expect do
operations_client.invoke_generic_operation(redeploy)
end.to raise_error(RuntimeError, /Handshake with server has not been done./)
end
it 'Redeploy can be run multiple times in parallel' do
wf_server_resource_id = 'Local~~'
alerts_war_resource_id = 'Local~%2Fdeployment%3Dhawkular-alerts-actions-email.war'
console_war_resource_id = 'Local~%2Fdeployment%3Dhawkular-console.war'
path1 = CanonicalPath.new(tenant_id: @tenant_id,
feed_id: @feed_id,
resource_ids: [wf_server_resource_id, alerts_war_resource_id])
path2 = CanonicalPath.new(tenant_id: @tenant_id,
feed_id: @feed_id,
resource_ids: [wf_server_resource_id, console_war_resource_id])
redeploy1 = {
operationName: 'Redeploy',
resourcePath: path1.to_s
}
redeploy2 = {
operationName: 'Redeploy',
resourcePath: path2.to_s
}
# run the first operation w/o registering the callback
@client.invoke_generic_operation(redeploy1)
actual_data = {}
# run the 2nd operation with 2 callback blocks (the happy path and the less happy path)
@client.invoke_generic_operation(redeploy2) do |on|
on.success do |data|
actual_data[:data] = data
end
on.failure do |error|
actual_data[:data] = {}
puts 'error callback was called, reason: ' + error.to_s
end
end
actual_data = wait_for actual_data
expect(actual_data['status']).to eq('OK')
expect(actual_data['resourcePath']).to eq(path2.to_s)
expect(actual_data['message']).to start_with('Performed [Redeploy] on')
end
it 'Add deployment should be doable' do
wf_server_resource_id = 'Local~~'
app_name = 'sample.war'
war_file = IO.binread("#{File.dirname(__FILE__)}/../resources/#{app_name}")
wf_path = CanonicalPath.new(tenant_id: @tenant_id,
feed_id: @feed_id,
resource_ids: [wf_server_resource_id]).to_s
actual_data = {}
@client.add_deployment(resource_path: wf_path,
destination_file_name: app_name,
binary_content: war_file) do |on|
on.success do |data|
actual_data[:data] = data
end
on.failure do |error|
actual_data[:data] = {}
puts 'error callback was called, reason: ' + error.to_s
end
end
actual_data = wait_for actual_data
expect(actual_data['status']).to eq('OK')
expect(actual_data['message']).to start_with('Performed [Deploy] on')
expect(actual_data['destinationFileName']).to eq(app_name)
expect(actual_data['resourcePath']).to eq(wf_path)
end
it 'Remove deployment should be performed and eventually respond with success' do
wf_server_resource_id = 'Local~~'
sample_app_resource_id = 'Local~%2Fdeployment=sample.war'
path = CanonicalPath.new(tenant_id: @tenant_id,
feed_id: @feed_id,
resource_ids: [wf_server_resource_id, sample_app_resource_id])
remove_deployment = {
operationName: 'Remove',
resourcePath: path.to_s
}
actual_data = {}
@client.invoke_generic_operation(remove_deployment) do |on|
on.success do |data|
actual_data[:data] = data
end
on.failure do |error|
actual_data[:data] = { 'status' => 'ERROR' }
puts 'error callback was called, reason: ' + error.to_s
end
end
actual_data = wait_for actual_data
expect(actual_data['status']).to eq('OK')
expect(actual_data['message']).to start_with('Performed [Remove] on')
end
it 'Remove datasource should be performed and eventually respond with success' do
wf_server_resource_id = 'Local~~'
datasource_resource_id = 'Local~%2Fsubsystem%3Ddatasources%2Fdata-source%3DCreatedByRubyDS' + @random_uuid
path = CanonicalPath.new(tenant_id: @tenant_id,
feed_id: @feed_id,
resource_ids: [wf_server_resource_id, datasource_resource_id])
operation = {
resourcePath: path.to_s
}
actual_data = {}
@client.invoke_specific_operation(operation, 'RemoveDatasource') do |on|
on.success do |data|
actual_data[:data] = data
end
on.failure do |error|
actual_data[:data] = {}
puts 'error callback was called, reason: ' + error.to_s
end
end
actual_data = wait_for actual_data
expect(actual_data['status']).to eq('OK')
expect(actual_data['message']).to start_with('Performed [Remove] on')
expect(actual_data['serverRefreshIndicator']).to eq('RELOAD-REQUIRED')
end
it 'Remove JDBC driver should be performed and eventually respond with success' do
wf_server_resource_id = 'Local~~'
driver_resource_id = 'Local~%2Fsubsystem%3Ddatasources%2Fjdbc-driver%3DCreatedByRubyDriver' + @random_uuid
path = CanonicalPath.new(tenant_id: @tenant_id,
feed_id: @feed_id,
resource_ids: [wf_server_resource_id, driver_resource_id]).to_s
actual_data = {}
@client.invoke_specific_operation({ resourcePath: path }, 'RemoveJdbcDriver') do |on|
on.success do |data|
actual_data[:data] = data
end
on.failure do |error|
actual_data[:data] = {}
puts 'error callback was called, reason: ' + error.to_s
end
end
actual_data = wait_for actual_data
expect(actual_data['status']).to eq('OK')
expect(actual_data['resourcePath']).to eq(path)
expect(actual_data['message']).to start_with('Performed [Remove] on a [JDBC Driver]')
end
xit 'Export JDR should retrieve the zip file with the report' do
wf_server_resource_id = 'Local~~'
path = CanonicalPath.new(tenant_id: @tenant_id,
feed_id: @feed_id,
resource_ids: [wf_server_resource_id]).to_s
actual_data = {}
@client.export_jdr(path) do |on|
on.success do |data|
actual_data[:data] = data
end
on.failure do |error|
actual_data[:data] = {}
puts 'error callback was called, reason: ' + error.to_s
end
end
actual_data = wait_for actual_data
expect(actual_data['status']).to eq('OK')
expect(actual_data['resourcePath']).to eq(path)
expect(actual_data['message']).to start_with('Performed [Export JDR] on')
expect(actual_data['fileName']).to start_with('jdr_')
end
end
end