hawkular-client 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -0
- data/.gitignore +2 -1
- data/.rubocop.yml +19 -6
- data/CHANGES.rdoc +13 -3
- data/README.rdoc +9 -3
- data/hawkularclient.gemspec +8 -4
- data/lib/alerts/alerts_api.rb +202 -32
- data/lib/hawkular.rb +35 -67
- data/lib/hawkular_all.rb +2 -0
- data/lib/inventory/inventory_api.rb +459 -130
- data/lib/metrics/metric_api.rb +14 -9
- data/lib/operations/operations_api.rb +247 -0
- data/lib/tokens/tokens_api.rb +33 -0
- data/lib/version.rb +1 -1
- data/spec/integration/alerts_spec.rb +272 -20
- data/spec/integration/hello-world-definitions.json +46 -0
- data/spec/integration/inventory_spec.rb +253 -89
- data/spec/integration/metric_spec.rb +36 -0
- data/spec/integration/operations_spec.rb +420 -0
- data/spec/integration/tokens_spec.rb +45 -0
- data/spec/resources/driver.jar +0 -0
- data/spec/resources/sample.war +0 -0
- data/spec/spec_helper.rb +30 -6
- data/spec/unit/base_spec.rb +22 -1
- data/spec/unit/canonical_path_spec.rb +92 -0
- data/spec/vcr/vcr_setup.rb +3 -4
- data/spec/vcr_cassettes/Alert/EndToEnd/Should_create_and_fire_a_trigger.yml +1187 -0
- data/spec/vcr_cassettes/Alert/Events/Should_list_events.yml +101 -0
- data/spec/vcr_cassettes/Alert/Events/Should_list_events_using_criteria.yml +79 -0
- data/spec/vcr_cassettes/Alert/Events/Should_not_list_events_using_criteria.yml +49 -0
- data/spec/vcr_cassettes/Alert/Triggers/Should_bulk_load_triggers.yml +225 -0
- data/spec/vcr_cassettes/Alert/Triggers/Should_create_a_basic_trigger_with_action.yml +355 -0
- data/spec/vcr_cassettes/Alert/Triggers/Should_create_an_action.yml +134 -0
- data/spec/vcr_cassettes/Alert/Triggers/Should_create_an_action_for_webhooks.yml +220 -0
- data/spec/vcr_cassettes/Alert/Triggers/Should_get_the_action_definitions.yml +218 -0
- data/spec/vcr_cassettes/Alert/Triggers/Should_not_create_an_action_for_unknown_plugin.yml +46 -0
- data/spec/vcr_cassettes/Alert/Triggers/Should_not_create_an_action_for_unknown_properties.yml +134 -0
- data/spec/vcr_cassettes/Counter_metrics/Should_get_metrics_with_limit_and_order.yml +270 -0
- data/spec/vcr_cassettes/Inventory/Client_should_listen_on_various_inventory_events.json +47 -0
- data/spec/vcr_cassettes/Inventory/Client_should_listen_on_various_inventory_events.yml +191 -0
- data/spec/vcr_cassettes/Inventory/Helpers/generate_some_events_for_websocket.yml +507 -0
- data/spec/vcr_cassettes/Inventory/Should_List_datasources_with_no_props.yml +74 -69
- data/spec/vcr_cassettes/Inventory/{Should_list_types_without_feed.yml → Should_create_a_feed.yml} +29 -32
- data/spec/vcr_cassettes/Inventory/Should_create_a_feed_again.yml +211 -0
- data/spec/vcr_cassettes/Inventory/Should_create_a_resource_.yml +355 -0
- data/spec/vcr_cassettes/Inventory/Should_create_a_resource_with_metric.yml +786 -0
- data/spec/vcr_cassettes/Inventory/Should_create_a_resourcetype.yml +205 -0
- data/spec/vcr_cassettes/Inventory/Should_create_and_delete_feed.yml +201 -0
- data/spec/vcr_cassettes/Inventory/Should_create_and_get_a_resource.yml +419 -0
- data/spec/vcr_cassettes/Inventory/Should_list_URLs.yml +39 -27
- data/spec/vcr_cassettes/Inventory/Should_list_WildFlys.yml +37 -29
- data/spec/vcr_cassettes/Inventory/Should_list_WildFlys_with_props.yml +53 -45
- data/spec/vcr_cassettes/Inventory/Should_list_all_the_resource_types.yml +177 -0
- data/spec/vcr_cassettes/Inventory/Should_list_children_of_WildFly.yml +230 -56
- data/spec/vcr_cassettes/Inventory/Should_list_feeds.yml +27 -24
- data/spec/vcr_cassettes/Inventory/Should_list_heap_metrics_for_WildFlys.yml +586 -119
- data/spec/vcr_cassettes/Inventory/Should_list_metrics_for_WildFlys.yml +220 -59
- data/spec/vcr_cassettes/Inventory/Should_list_metrics_of_given_metric_type.yml +613 -0
- data/spec/vcr_cassettes/Inventory/Should_list_metrics_of_given_resource_type.yml +333 -0
- data/spec/vcr_cassettes/Inventory/Should_list_recursive_children_of_WildFly.yml +2064 -0
- data/spec/vcr_cassettes/Inventory/Should_list_relationships_of_WildFly.yml +460 -0
- data/spec/vcr_cassettes/Inventory/Should_list_types_with_bad_feed.yml +26 -25
- data/spec/vcr_cassettes/Inventory/Should_list_types_with_feed.yml +102 -36
- data/spec/vcr_cassettes/Inventory/Should_not_find_an_unknown_resource.yml +54 -0
- data/spec/vcr_cassettes/Inventory/Tenants/Should_Get_Tenant_For_Explicit_Credentials.yml +50 -0
- data/spec/vcr_cassettes/Inventory/Tenants/Should_Get_Tenant_For_Implicit_Credentials.yml +50 -0
- data/spec/vcr_cassettes/Operation/Helpers/get_tenant.yml +50 -0
- data/spec/vcr_cassettes/Operation/Operation/Add_JDBC_driver_should_add_the_driver.json +26 -0
- data/spec/vcr_cassettes/Operation/Operation/Add_datasource_should_be_doable.json +26 -0
- data/spec/vcr_cassettes/Operation/Operation/Add_deployment_should_be_doable.json +26 -0
- data/spec/vcr_cassettes/Operation/Operation/Redeploy_can_be_run_multiple_times_in_parallel.json +40 -0
- data/spec/vcr_cassettes/Operation/Operation/Redeploy_should_be_performed_and_eventually_respond_with_success.json +26 -0
- data/spec/vcr_cassettes/Operation/Operation/Redeploy_should_not_be_performed_if_resource_path_is_wrong.json +26 -0
- data/spec/vcr_cassettes/Operation/Operation/Remove_JDBC_driver_should_be_performed_and_eventually_respond_with_success.json +26 -0
- data/spec/vcr_cassettes/Operation/Operation/Remove_datasource_should_be_performed_and_eventually_respond_with_success.json +26 -0
- data/spec/vcr_cassettes/Operation/Operation/Remove_deployment_should_be_performed_and_eventually_respond_with_success.json +26 -0
- data/spec/vcr_cassettes/Operation/Operation/Undeploy_should_be_performed_and_eventually_respond_with_success.json +26 -0
- data/spec/vcr_cassettes/Operation/Operation/should_not_be_possible_to_perform_on_closed_client.json +12 -0
- data/spec/vcr_cassettes/Operation/Websocket_connection/should_be_established.json +9 -0
- data/spec/vcr_cassettes/Tokens/Should_be_able_to_create_a_new_token_for_an_actual_user.yml +57 -0
- data/spec/vcr_cassettes/Tokens/Should_be_able_to_list_the_available_tokens.yml +49 -0
- data/spec/vcr_cassettes/Tokens/Should_get_a_401_when_attempting_to_create_a_token_with_a_wrong_password.yml +56 -0
- data/spec/vcr_cassettes/Tokens/Should_get_a_401_when_attempting_to_create_a_token_without_a_password.yml +55 -0
- metadata +175 -11
- data/lib/metrics/version.rb +0 -7
@@ -0,0 +1,46 @@
|
|
1
|
+
{
|
2
|
+
"triggers":[
|
3
|
+
{
|
4
|
+
"trigger":{
|
5
|
+
"id": "hello-world-trigger",
|
6
|
+
"name": "Hello World Trigger",
|
7
|
+
"description": "A mandatory Hello World Trigger",
|
8
|
+
"severity": "HIGH",
|
9
|
+
"enabled": true,
|
10
|
+
"actions":[
|
11
|
+
{
|
12
|
+
"actionPlugin": "email",
|
13
|
+
"actionId": "notify-to-admins"
|
14
|
+
}
|
15
|
+
]
|
16
|
+
},
|
17
|
+
"conditions":[
|
18
|
+
{
|
19
|
+
"triggerMode": "FIRING",
|
20
|
+
"type": "threshold",
|
21
|
+
"dataId": "data-x",
|
22
|
+
"operator": "LT",
|
23
|
+
"threshold": 5
|
24
|
+
},
|
25
|
+
{
|
26
|
+
"triggerMode": "FIRING",
|
27
|
+
"type": "threshold",
|
28
|
+
"dataId": "data-y",
|
29
|
+
"operator": "GT",
|
30
|
+
"threshold": 5
|
31
|
+
}
|
32
|
+
]
|
33
|
+
}
|
34
|
+
],
|
35
|
+
"actions":[
|
36
|
+
{
|
37
|
+
"actionPlugin": "email",
|
38
|
+
"actionId": "notify-to-admins",
|
39
|
+
"properties": {
|
40
|
+
"to": "admins@hawkular.org",
|
41
|
+
"cc": "developers@hawkular.org",
|
42
|
+
"description": "Notify by email to Admins with cc to Developers"
|
43
|
+
}
|
44
|
+
}
|
45
|
+
]
|
46
|
+
}
|
@@ -1,87 +1,71 @@
|
|
1
1
|
require "#{File.dirname(__FILE__)}/../vcr/vcr_setup"
|
2
2
|
require "#{File.dirname(__FILE__)}/../spec_helper"
|
3
|
+
require 'securerandom'
|
3
4
|
|
4
5
|
module Hawkular::Inventory::RSpec
|
5
|
-
|
6
|
-
describe 'Tenants', :vcr do
|
6
|
+
describe 'Inventory/Tenants', :vcr do
|
7
7
|
it 'Should Get Tenant For Explicit Credentials' do
|
8
|
+
# get the client for given endpoint for given credentials
|
8
9
|
creds = { username: 'jdoe', password: 'password' }
|
9
|
-
|
10
|
-
|
10
|
+
client = Hawkular::Inventory::InventoryClient.create(entrypoint: 'http://localhost:8080/hawkular/inventory',
|
11
|
+
credentials: creds)
|
11
12
|
|
12
13
|
tenant = client.get_tenant(creds)
|
13
14
|
|
14
|
-
expect
|
15
|
-
expect tenant.eql?('28026b36-8fe4-4332-84c8-524e173a68bf')
|
15
|
+
expect(tenant).to eq('28026b36-8fe4-4332-84c8-524e173a68bf')
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'Should Get Tenant For Implicit Credentials' do
|
19
19
|
creds = { username: 'jdoe', password: 'password' }
|
20
|
-
|
21
|
-
client = Hawkular::Inventory::InventoryClient.new(INVENTORY_BASE, creds)
|
20
|
+
client = Hawkular::Inventory::InventoryClient.create(credentials: creds)
|
22
21
|
|
23
22
|
tenant = client.get_tenant
|
24
23
|
|
25
|
-
expect
|
26
|
-
|
27
|
-
expect tenant.eql?('28026b36-8fe4-4332-84c8-524e173a68bf')
|
24
|
+
expect(tenant).to eq('28026b36-8fe4-4332-84c8-524e173a68bf')
|
28
25
|
end
|
29
26
|
end
|
30
27
|
|
31
|
-
describe 'Inventory', :
|
32
|
-
|
33
|
-
creds = {
|
34
|
-
|
35
|
-
|
36
|
-
|
28
|
+
describe 'Inventory', vcr: { decode_compressed_response: true } do
|
29
|
+
before(:all) do
|
30
|
+
@creds = {
|
31
|
+
username: 'jdoe',
|
32
|
+
password: 'password'
|
33
|
+
}
|
34
|
+
@client = Hawkular::Inventory::InventoryClient.create(credentials: @creds)
|
35
|
+
@state = {
|
36
|
+
hostname: 'localhost.localdomain',
|
37
|
+
feed: nil
|
38
|
+
}
|
39
|
+
end
|
37
40
|
|
38
|
-
|
41
|
+
it 'Should list feeds' do
|
42
|
+
feeds = @client.list_feeds
|
39
43
|
|
40
44
|
expect(feeds.size).to be(1)
|
45
|
+
@state[:feed] = feeds[0] unless feeds[0].nil?
|
41
46
|
end
|
42
47
|
|
43
|
-
it 'Should list
|
44
|
-
|
45
|
-
|
46
|
-
client = Hawkular::Inventory::InventoryClient.new(INVENTORY_BASE, creds)
|
47
|
-
client.impersonate
|
48
|
-
|
49
|
-
types = client.list_resource_types
|
50
|
-
|
51
|
-
expect(types.size).to be(17)
|
48
|
+
it 'Should list all the resource types' do
|
49
|
+
types = @client.list_resource_types
|
50
|
+
expect(types.size).to be(19)
|
52
51
|
end
|
53
52
|
|
54
53
|
it 'Should list types with feed' do
|
55
|
-
|
56
|
-
|
57
|
-
client = Hawkular::Inventory::InventoryClient.new(INVENTORY_BASE, creds)
|
58
|
-
client.impersonate
|
54
|
+
types = @client.list_resource_types(@state[:feed])
|
59
55
|
|
60
|
-
types
|
61
|
-
|
62
|
-
expect(types.size).to be(16)
|
56
|
+
expect(types.size).to be(18)
|
63
57
|
end
|
64
58
|
|
65
59
|
it 'Should list types with bad feed' do
|
66
|
-
creds = { username: 'jdoe', password: 'password' }
|
67
|
-
|
68
|
-
client = Hawkular::Inventory::InventoryClient.new(INVENTORY_BASE, creds)
|
69
|
-
client.impersonate
|
70
|
-
|
71
60
|
type = 'does not exist'
|
72
|
-
types = client.list_resource_types(type)
|
61
|
+
types = @client.list_resource_types(type)
|
73
62
|
expect(type).to eq('does not exist')
|
74
63
|
|
75
64
|
expect(types.size).to be(0)
|
76
65
|
end
|
77
66
|
|
78
67
|
it 'Should list WildFlys' do
|
79
|
-
|
80
|
-
|
81
|
-
client = Hawkular::Inventory::InventoryClient.new(INVENTORY_BASE, creds)
|
82
|
-
client.impersonate
|
83
|
-
|
84
|
-
resources = client.list_resources_for_type('snert', 'WildFly Server')
|
68
|
+
resources = @client.list_resources_for_type(@state[:feed], 'WildFly Server')
|
85
69
|
|
86
70
|
expect(resources.size).to be(1)
|
87
71
|
wf = resources.first
|
@@ -89,25 +73,15 @@ module Hawkular::Inventory::RSpec
|
|
89
73
|
end
|
90
74
|
|
91
75
|
it 'Should list WildFlys with props' do
|
92
|
-
|
93
|
-
|
94
|
-
client = Hawkular::Inventory::InventoryClient.new(INVENTORY_BASE, creds)
|
95
|
-
client.impersonate
|
96
|
-
|
97
|
-
resources = client.list_resources_for_type('snert', 'WildFly Server', true)
|
76
|
+
resources = @client.list_resources_for_type(@state[:feed], 'WildFly Server', true)
|
98
77
|
|
99
78
|
expect(resources.size).to be(1)
|
100
79
|
wf = resources.first
|
101
|
-
expect(wf.properties['Hostname']).to eq(
|
80
|
+
expect(wf.properties['Hostname']).to eq(@state[:hostname])
|
102
81
|
end
|
103
82
|
|
104
83
|
it 'Should List datasources with no props' do
|
105
|
-
|
106
|
-
|
107
|
-
client = Hawkular::Inventory::InventoryClient.new(INVENTORY_BASE, creds)
|
108
|
-
client.impersonate
|
109
|
-
|
110
|
-
resources = client.list_resources_for_type('snert', 'Datasource', true)
|
84
|
+
resources = @client.list_resources_for_type(@state[:feed], 'Datasource', true)
|
111
85
|
|
112
86
|
expect(resources.size).to be(2)
|
113
87
|
wf = resources.first
|
@@ -115,71 +89,261 @@ module Hawkular::Inventory::RSpec
|
|
115
89
|
end
|
116
90
|
|
117
91
|
it 'Should list URLs' do
|
118
|
-
|
119
|
-
|
120
|
-
client = Hawkular::Inventory::InventoryClient.new(INVENTORY_BASE, creds)
|
121
|
-
client.impersonate
|
122
|
-
|
123
|
-
resources = client.list_resources_for_type(nil, 'URL')
|
92
|
+
resources = @client.list_resources_for_type(nil, 'URL')
|
124
93
|
|
125
94
|
expect(resources.size).to be(1)
|
126
95
|
resource = resources[0]
|
127
96
|
expect(resource.instance_of? Hawkular::Inventory::Resource).to be_truthy
|
128
|
-
expect(resource.properties.size).to be(
|
97
|
+
expect(resource.properties.size).to be(6)
|
129
98
|
expect(resource.properties['url']).to eq('http://bsd.de')
|
130
99
|
end
|
131
100
|
|
132
101
|
it 'Should list metrics for WildFlys' do
|
133
|
-
|
134
|
-
|
135
|
-
client = Hawkular::Inventory::InventoryClient.new(INVENTORY_BASE, creds)
|
136
|
-
client.impersonate
|
137
|
-
|
138
|
-
resources = client.list_resources_for_type('snert', 'WildFly Server')
|
102
|
+
resources = @client.list_resources_for_type(@state[:feed], 'WildFly Server')
|
139
103
|
expect(resources.size).to be(1)
|
140
104
|
|
141
105
|
wild_fly = resources[0]
|
142
106
|
|
143
|
-
metrics = client.list_metrics_for_resource(wild_fly)
|
107
|
+
metrics = @client.list_metrics_for_resource(wild_fly)
|
144
108
|
|
145
109
|
expect(metrics.size).to be(14)
|
146
110
|
end
|
147
111
|
|
148
112
|
it 'Should list children of WildFly' do
|
149
|
-
|
113
|
+
resources = @client.list_resources_for_type(@state[:feed], 'WildFly Server')
|
114
|
+
expect(resources.size).to be(1)
|
115
|
+
|
116
|
+
wild_fly = resources[0]
|
150
117
|
|
151
|
-
|
152
|
-
client.impersonate
|
118
|
+
children = @client.list_child_resources(wild_fly)
|
153
119
|
|
154
|
-
|
155
|
-
|
120
|
+
expect(children.size).to be(21)
|
121
|
+
end
|
156
122
|
|
123
|
+
it 'Should list recursive children of WildFly' do
|
124
|
+
resources = @client.list_resources_for_type(@state[:feed], 'WildFly Server')
|
157
125
|
wild_fly = resources[0]
|
158
126
|
|
159
|
-
|
127
|
+
children = @client.list_child_resources(wild_fly, recursive: true)
|
160
128
|
|
161
|
-
expect(
|
129
|
+
expect(children.size).to be(211)
|
162
130
|
end
|
163
131
|
|
164
|
-
it 'Should list
|
165
|
-
|
132
|
+
it 'Should list relationships of WildFly' do
|
133
|
+
resources = @client.list_resources_for_type(@state[:feed], 'WildFly Server')
|
134
|
+
wild_fly = resources[0]
|
166
135
|
|
167
|
-
|
168
|
-
|
136
|
+
rels = @client.list_relationships(wild_fly)
|
137
|
+
|
138
|
+
expect(rels.size).to be(59)
|
139
|
+
end
|
169
140
|
|
170
|
-
|
141
|
+
it 'Should list heap metrics for WildFlys' do
|
142
|
+
resources = @client.list_resources_for_type(@state[:feed], 'WildFly Server')
|
171
143
|
expect(resources.size).to be(1)
|
172
144
|
|
173
145
|
wild_fly = resources[0]
|
174
146
|
|
175
|
-
metrics = client.list_metrics_for_resource(wild_fly, type: 'GAUGE', match: 'Metrics~Heap')
|
147
|
+
metrics = @client.list_metrics_for_resource(wild_fly, type: 'GAUGE', match: 'Metrics~Heap')
|
176
148
|
expect(metrics.size).to be(3)
|
177
149
|
|
178
|
-
metrics = client.list_metrics_for_resource(wild_fly, match: 'Metrics~Heap')
|
150
|
+
metrics = @client.list_metrics_for_resource(wild_fly, match: 'Metrics~Heap')
|
179
151
|
expect(metrics.size).to be(3)
|
180
152
|
|
181
|
-
metrics = client.list_metrics_for_resource(wild_fly, type: 'GAUGE')
|
182
|
-
expect(metrics.size).to be(
|
153
|
+
metrics = @client.list_metrics_for_resource(wild_fly, type: 'GAUGE')
|
154
|
+
expect(metrics.size).to be(8)
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'Should list metrics of given metric type' do
|
158
|
+
metrics = @client.list_metrics_for_metric_type(@state[:feed], 'Total Space')
|
159
|
+
|
160
|
+
expect(metrics.size).to be(7)
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'Should list metrics of given resource type' do
|
164
|
+
metrics = @client.list_metrics_for_resource_type(@state[:feed], 'WildFly Server')
|
165
|
+
|
166
|
+
expect(metrics.size).to be(14)
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'Should create a feed' do
|
170
|
+
feed_id = 'feed_1123sdncisud6237ui23hjbdscuzsad'
|
171
|
+
ret = @client.create_feed feed_id
|
172
|
+
expect(ret).to_not be_nil
|
173
|
+
expect(ret['id']).to eq(feed_id)
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'Should create and delete feed' do
|
177
|
+
feed_id = 'feed_1123sdn'
|
178
|
+
ret = @client.create_feed feed_id
|
179
|
+
expect(ret).to_not be_nil
|
180
|
+
expect(ret['id']).to eq(feed_id)
|
181
|
+
|
182
|
+
@client.delete_feed feed_id
|
183
|
+
|
184
|
+
feed_list = @client.list_feeds
|
185
|
+
expect(feed_list).not_to include(feed_id)
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'Should create a feed again' do
|
189
|
+
feed_id = 'feed_1123sdncisud6237ui2378789vvgX'
|
190
|
+
@client.create_feed feed_id
|
191
|
+
@client.create_feed feed_id
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'Should create a resourcetype' do
|
195
|
+
feed_id = 'feed_may_exist'
|
196
|
+
@client.create_feed feed_id
|
197
|
+
|
198
|
+
ret = @client.create_resource_type feed_id, 'rt-123', 'ResourceType'
|
199
|
+
expect(ret.id).to eq('rt-123')
|
200
|
+
expect(ret.name).to eq('ResourceType')
|
201
|
+
expect(ret.path).to include('/rt;rt-123')
|
202
|
+
expect(ret.path).to include('/f;feed_may_exist')
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'Should create a resource ' do
|
206
|
+
feed_id = 'feed_may_exist'
|
207
|
+
@client.create_feed feed_id
|
208
|
+
ret = @client.create_resource_type feed_id, 'rt-123', 'ResourceType'
|
209
|
+
type_path = ret.path
|
210
|
+
|
211
|
+
@client.create_resource feed_id, type_path, 'r123', 'My Resource', 'version' => 1.0
|
212
|
+
|
213
|
+
r = @client.get_resource(feed_id, 'r123', false)
|
214
|
+
expect(r.id).to eq('r123')
|
215
|
+
expect(r.properties).not_to be_empty
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'Should create a resource with metric' do
|
219
|
+
feed_id = 'feed_may_exist'
|
220
|
+
@client.create_feed feed_id
|
221
|
+
ret = @client.create_resource_type feed_id, 'rt-123', 'ResourceType'
|
222
|
+
type_path = ret.path
|
223
|
+
|
224
|
+
@client.create_resource feed_id, type_path, 'r124', 'My Resource', 'version' => 1.0
|
225
|
+
|
226
|
+
r = @client.get_resource(feed_id, 'r124', false)
|
227
|
+
expect(r.id).to eq('r124')
|
228
|
+
expect(r.properties).not_to be_empty
|
229
|
+
|
230
|
+
r = @client.create_metric_type feed_id, 'mt-124'
|
231
|
+
expect(r).not_to be_nil
|
232
|
+
expect(r.id).to eq('mt-124')
|
233
|
+
|
234
|
+
m = @client.create_metric_for_resource feed_id, 'm-124', r.path, 'r124'
|
235
|
+
expect(m).not_to be_nil
|
236
|
+
expect(m.id).to eq('m-124')
|
237
|
+
expect(m.name).to eq('m-124')
|
238
|
+
|
239
|
+
m = @client.create_metric_for_resource feed_id, 'm-124-1', r.path, 'r124', 'Metric1'
|
240
|
+
expect(m).not_to be_nil
|
241
|
+
expect(m.id).to eq('m-124-1')
|
242
|
+
expect(m.name).to eq('Metric1')
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'Should create and get a resource' do
|
246
|
+
feed_id = 'feed_may_exist'
|
247
|
+
@client.create_feed feed_id
|
248
|
+
ret = @client.create_resource_type feed_id, 'rt-123', 'ResourceType'
|
249
|
+
type_path = ret.path
|
250
|
+
|
251
|
+
@client.create_resource feed_id, type_path, 'r125', 'My Resource', 'version' => 1.0
|
252
|
+
|
253
|
+
r = @client.get_resource(feed_id, 'r125', true)
|
254
|
+
expect(r.id).to eq('r125')
|
255
|
+
expect(r.properties).not_to be_empty
|
256
|
+
end
|
257
|
+
|
258
|
+
it 'Should not find an unknown resource' do
|
259
|
+
feed_id = 'feed_may_exist'
|
260
|
+
|
261
|
+
expect { @client.get_resource(feed_id, '*bla does not exist*') }
|
262
|
+
.to raise_error(Hawkular::BaseClient::HawkularException, /No Resource found/)
|
263
|
+
end
|
264
|
+
|
265
|
+
it 'Should reject unknown metric type' do
|
266
|
+
feed_id = 'feed_may_exist'
|
267
|
+
|
268
|
+
expect { @client.create_metric_type feed_id, 'abc', 'FOOBaR' }.to raise_error(RuntimeError, /Unknown type FOOBAR/)
|
269
|
+
end
|
270
|
+
|
271
|
+
let(:example) do |e|
|
272
|
+
e
|
273
|
+
end
|
274
|
+
|
275
|
+
it 'Client should listen on various inventory events', :websocket do
|
276
|
+
VCR::WebSocket.configure do |c|
|
277
|
+
c.hook_uris = ['localhost:8080']
|
278
|
+
end
|
279
|
+
|
280
|
+
VCR::WebSocket.record(example, self) do
|
281
|
+
# TODO: erb
|
282
|
+
# prefix = SecureRandom.uuid
|
283
|
+
prefix = 'random'
|
284
|
+
|
285
|
+
id_1 = prefix + '-r126'
|
286
|
+
id_2 = prefix + '-r127'
|
287
|
+
id_3 = prefix + '-r128'
|
288
|
+
|
289
|
+
new_resource_events = {}
|
290
|
+
resources_closable = @client.events do |resource|
|
291
|
+
new_resource_events[resource.id] = resource
|
292
|
+
end
|
293
|
+
|
294
|
+
deleted_feed_events = {}
|
295
|
+
feed_deleted_closable = @client.events('feed', 'deleted') do |feed|
|
296
|
+
deleted_feed_events[feed.id] = feed
|
297
|
+
end
|
298
|
+
|
299
|
+
new_resource_types_events = {}
|
300
|
+
resource_type_closable = @client.events('resourcetype') do |resource_type|
|
301
|
+
new_resource_types_events[resource_type.id] = resource_type
|
302
|
+
end
|
303
|
+
|
304
|
+
registered_feed_events = {}
|
305
|
+
feeds_closable = @client.events('feed', 'created') do |feed|
|
306
|
+
registered_feed_events[feed.id] = feed
|
307
|
+
end
|
308
|
+
|
309
|
+
feed_id = prefix + '-feed'
|
310
|
+
resource_type_id = prefix + '-rt-123'
|
311
|
+
resource_type_name = 'ResourceType'
|
312
|
+
|
313
|
+
VCR.use_cassette('Inventory/Helpers/generate_some_events_for_websocket') do
|
314
|
+
@client.create_feed feed_id
|
315
|
+
ret = @client.create_resource_type feed_id, resource_type_id, resource_type_name
|
316
|
+
type_path = ret.path
|
317
|
+
|
318
|
+
# create 3 resources
|
319
|
+
@client.create_resource feed_id, type_path, id_1, 'My Resource 1', 'version' => 1.0
|
320
|
+
@client.create_resource feed_id, type_path, id_2, 'My Resource 2', 'version' => 1.1
|
321
|
+
resources_closable.close
|
322
|
+
@client.create_resource feed_id, type_path, id_3, 'My Resource 3', 'version' => 1.2
|
323
|
+
|
324
|
+
@client.delete_feed feed_id
|
325
|
+
end
|
326
|
+
|
327
|
+
# wait for the data
|
328
|
+
sleep 2 if !VCR::WebSocket.cassette || VCR::WebSocket.cassette.recording?
|
329
|
+
[feed_deleted_closable, resource_type_closable, feeds_closable].each(&:close)
|
330
|
+
expect(new_resource_events[id_1]).not_to be_nil
|
331
|
+
expect(new_resource_events[id_1].properties['version']).to eq(1.0)
|
332
|
+
expect(new_resource_events[id_2]).not_to be_nil
|
333
|
+
expect(new_resource_events[id_2].properties['version']).to eq(1.1)
|
334
|
+
# resource with id_3 should not be among events, because we stopped listening before creating the 3rd one
|
335
|
+
expect(new_resource_events[id_3]).to be_nil
|
336
|
+
|
337
|
+
expect(registered_feed_events[feed_id]).not_to be_nil
|
338
|
+
expect(registered_feed_events[feed_id].id).to eq(feed_id)
|
339
|
+
|
340
|
+
expect(deleted_feed_events[feed_id]).not_to be_nil
|
341
|
+
expect(deleted_feed_events[feed_id].id).to eq(feed_id)
|
342
|
+
|
343
|
+
expect(new_resource_types_events[resource_type_id]).not_to be_nil
|
344
|
+
expect(new_resource_types_events[resource_type_id].id).to eq(resource_type_id)
|
345
|
+
expect(new_resource_types_events[resource_type_id].name).to eq(resource_type_name)
|
346
|
+
end
|
183
347
|
end
|
184
348
|
|
185
349
|
# TODO: enable when inventory supports it
|