Class: Hawkular::Inventory::Client

Inherits:
BaseClient show all
Defined in:
lib/hawkular/inventory/inventory_api.rb

Overview

Client class to interact with Hawkular Inventory

Instance Attribute Summary collapse

Attributes inherited from BaseClient

#tenants

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseClient

#admin_header, #base_64_credentials, #generate_query_params, #http_delete, #http_get, #http_post, #http_put, #normalize_entrypoint_url, #now, #url_with_websocket_scheme

Methods included from ClientUtils

#hawk_escape, #hawk_escape_id

Constructor Details

#initialize(entrypoint = nil, credentials = {}, options = {}) ⇒ Client

Create a new Inventory Client

Parameters:

  • entrypoint (String) (defaults to: nil)

    base url of Hawkular-inventory - e.g localhost:8080/hawkular/inventory

  • credentials (Hash{String=>String}) (defaults to: {})

    Hash of username, password, token(optional)

  • options (Hash{String=>String}) (defaults to: {})

    Additional rest client options



22
23
24
25
26
27
28
# File 'lib/hawkular/inventory/inventory_api.rb', line 22

def initialize(entrypoint = nil, credentials = {}, options = {})
  entrypoint = normalize_entrypoint_url entrypoint, 'hawkular/inventory'
  @entrypoint = entrypoint
  super(entrypoint, credentials, options)
  version = fetch_version_and_status['Implementation-Version']
  @version = version.scan(/\d+/).map(&:to_i)
end

Instance Attribute Details

#versionObject (readonly)

Returns the value of attribute version



15
16
17
# File 'lib/hawkular/inventory/inventory_api.rb', line 15

def version
  @version
end

Class Method Details

.create(hash) ⇒ Object

Creates a new Inventory Client and another sub-hash containing the hash with username, password, token(optional)

Parameters:



34
35
36
37
38
39
# File 'lib/hawkular/inventory/inventory_api.rb', line 34

def self.create(hash)
  fail 'no parameter ":entrypoint" given' if hash[:entrypoint].nil?
  hash[:credentials] ||= {}
  hash[:options] ||= {}
  Client.new(hash[:entrypoint], hash[:credentials], hash[:options])
end

Instance Method Details

#create_feed(feed_id, feed_name = nil) ⇒ Object

Create a new feed

Parameters:

  • feed_id (String)

    Id of a feed - required

  • feed_name (String) (defaults to: nil)

    A display name for the feed

Returns:

  • (Object)


271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/hawkular/inventory/inventory_api.rb', line 271

def create_feed(feed_id, feed_name = nil)
  feed = create_blueprint
  feed[:id] = feed_id
  feed[:name] = feed_name

  begin
    return http_post('/entity/feed', feed)
  rescue HawkularException  => error
    # 409 We already exist -> that is ok
    if error.status_code == 409
      the_feed = hawk_escape_id feed_id
      http_get("/entity/f;#{the_feed}")
    else
      raise
    end
  end
end

#create_metric_for_resource(metric_type_path, resource_path, metric_id, metric_name = nil) ⇒ Metric

Create a Metric and associate it with a resource.

Parameters:

  • metric_type_path (String)

    Canonical path of the metric type of the new metric.

  • resource_path (String)

    Canonical path of the resource to which we want to associate the metric.

  • metric_id (String)

    Id of the metric

  • metric_name (String) (defaults to: nil)

    a (display) name for the metric. If nil, #metric_id is used.

Returns:

  • (Metric)

    The metric created or if it already existed the version from the server



448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
# File 'lib/hawkular/inventory/inventory_api.rb', line 448

def create_metric_for_resource(metric_type_path, resource_path, metric_id, metric_name = nil)
  type_path = metric_type_path.is_a?(CanonicalPath) ? metric_type_path : CanonicalPath.parse(metric_type_path)
  feed_id = type_path.feed_id
  res_path = resource_path.is_a?(CanonicalPath) ? resource_path : CanonicalPath.parse(resource_path)
  res_path_str = 'r;' + res_path.resource_ids.join('/r;')

  m = {}
  m['id'] = metric_id
  m['name'] = metric_name || metric_id
  m['metricTypePath'] = type_path.to_s

  begin
    http_post("/entity/f;#{feed_id}/metric", m)
  rescue HawkularException => error
    # 409 We already exist -> that is ok
    raise unless error.status_code == 409
  end

  ret = http_get("/entity/f;#{feed_id}/m;#{metric_id}")
  the_metric = Metric.new(ret)

  begin
    rl = {}
    rl['otherEnd'] = the_metric.path.to_s
    rl['name'] = 'incorporates'
    http_post("/entity/f;#{feed_id}/#{res_path_str}/relationship", [rl])
  rescue HawkularException => error
    # 409 We already exist -> that is ok
    raise unless error.status_code == 409
  end
  the_metric
end

#create_metric_type(feed_id, metric_type_id, type = 'GAUGE', unit = 'NONE', collection_interval = 60) ⇒ MetricType

Create a new metric type for a feed

Parameters:

  • feed_id (String)

    Id of the feed

  • metric_type_id (String)

    Id of the metric type to create

  • type (String) (defaults to: 'GAUGE')

    Type of the Metric. Allowed are GAUGE,COUNTER, AVAILABILITY

  • unit (String) (defaults to: 'NONE')

    Unit of the metric

  • collection_interval (Numeric) (defaults to: 60)

Returns:

  • (MetricType)

    Type just created or the one from the server if it already existed.



395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
# File 'lib/hawkular/inventory/inventory_api.rb', line 395

def create_metric_type(feed_id, metric_type_id, type = 'GAUGE', unit = 'NONE', collection_interval = 60)
  the_feed = hawk_escape_id feed_id

  metric_kind = type.nil? ? 'GAUGE' : type.upcase
  fail "Unknown type #{metric_kind}" unless %w(GAUGE COUNTER AVAILABILITY').include?(metric_kind)

  mt = build_metric_type_hash(collection_interval, metric_kind, metric_type_id, unit)

  begin
    http_post("/entity/f;#{the_feed}/metricType", mt)
  rescue HawkularException => error
    # 409 We already exist -> that is ok
    raise unless error.status_code == 409
  end

  new_mt = http_get("/entity/f;#{the_feed}/mt;#{metric_type_id}")

  MetricType.new(new_mt)
end

#create_resource(resource_type_path, resource_id, resource_name = nil, properties = {}) ⇒ Object

Create a resource of a given type. To retrieve that resource you need to call #get_resource

Parameters:

  • resource_type_path (String)

    Canonical path of the new resource's type.

  • resource_id (String)

    Id of the new resource

  • resource_name (String) (defaults to: nil)

    Name of the new resource

  • properties (Hash<String,Object>) (defaults to: {})

    Additional properties. Those are not the config-properties



326
327
328
# File 'lib/hawkular/inventory/inventory_api.rb', line 326

def create_resource(resource_type_path, resource_id, resource_name = nil, properties = {})
  create_resource_under_resource(resource_type_path, nil, resource_id, resource_name, properties)
end

#create_resource_type(feed_id, type_id, type_name) ⇒ ResourceType

Create a new resource type

Parameters:

  • feed_id (String)

    Id of the feed to add the type to

  • type_id (String)

    Id of the new type

  • type_name (String)

    Name of the type

Returns:



301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/hawkular/inventory/inventory_api.rb', line 301

def create_resource_type(feed_id, type_id, type_name)
  the_feed = hawk_escape_id feed_id

  type = create_blueprint
  type[:id] = type_id
  type[:name] = type_name

  begin
    http_post("/entity/f;#{the_feed}/resourceType", type)
  rescue HawkularException => error
    # 409 We already exist -> that is ok
    raise unless error.status_code == 409
  ensure
    the_type = hawk_escape_id type_id
    res = http_get("/entity/f;#{the_feed}/rt;#{the_type}")
  end
  ResourceType.new(res)
end

#create_resource_under_resource(res_type_path, parent_res_path, resource_id, resource_name = nil, properties = {}) ⇒ Object

Create a resource of a given type under a given resource. To retrieve that resource you need to call #get_resource

Parameters:

  • res_type_path (String)

    Canonical path of the new resource's type.

  • parent_res_path (String)

    Canonical path of the resource under which we create this resource. If nil, the top-lvl resource will be created.

  • resource_id (String)

    Id of the resource

  • resource_name (String) (defaults to: nil)

    Name of the resource

  • properties (Hash<String,Object>) (defaults to: {})

    Additional properties. Those are not the config-properties



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
# File 'lib/hawkular/inventory/inventory_api.rb', line 338

def create_resource_under_resource(res_type_path, parent_res_path, resource_id, resource_name = nil,
                                   properties = {})
  type_path = res_type_path.is_a?(CanonicalPath) ? res_type_path : CanonicalPath.parse(res_type_path)
  feed_id = type_path.feed_id

  res = create_blueprint
  res[:properties] = properties
  res[:id] = resource_id
  res[:name] = resource_name
  res[:resourceTypePath] = type_path.to_s

  begin
    if parent_res_path.nil?
      res = http_post("/entity/f;#{feed_id}/resource", res)
    else
      path = parent_res_path.is_a?(CanonicalPath) ? parent_res_path : CanonicalPath.parse(parent_res_path)
      resource_path = 'r;' + path.resource_ids.join('/r;')
      res = http_post("/entity/f;#{feed_id}/#{resource_path}/resource", res)
    end
  rescue HawkularException => error
    # 409 We already exist -> that is ok
    raise unless error.status_code == 409
    # Ensure we have a consistent behaviour if resource already exists Issue#180
    if parent_res_path.nil?
      hash = type_path.to_h
      hash.delete(:metric_type_id)
      path = CanonicalPath.new(hash)
    end
    res = get_resource(path.to_resource(resource_id)).to_h
  end
  Resource.new(res)
end

#delete_feed(feed_id) ⇒ Object

Delete the feed with the passed feed id.

Parameters:

  • feed_id

    Id of the feed to be deleted.



291
292
293
294
# File 'lib/hawkular/inventory/inventory_api.rb', line 291

def delete_feed(feed_id)
  the_feed = hawk_escape_id feed_id
  http_delete("/entity/f;#{the_feed}")
end

#events(type = 'resource', action = 'created') ⇒ Object

Listen on inventory changes Allowed values: resource, metric, resourcetype, metrictype, feed, environment, operationtype, metadatapack Allowed values: created, updated, deleted, copied, registered

Parameters:

  • type (String) (defaults to: 'resource')

    Type of entity for which we want the events.

  • action (String) (defaults to: 'created')

    What types of events are we interested in.



486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
# File 'lib/hawkular/inventory/inventory_api.rb', line 486

def events(type = 'resource', action = 'created')
  tenant_id = get_tenant

  base64_creds = ["#{@credentials[:username]}:#{@credentials[:password]}"].pack('m').delete("\r\n")
  ws_options = {
    headers: {
      Authorization: 'Basic ' + base64_creds,
      Accept: 'application/json'
    }
  }
  ws_options[:headers][:Hawkular-Tenant'] = tenant_id

  url = normalize_entrypoint_url(@entrypoint, "ws/events?tenantId=#{tenant_id}&type=#{type}&action=#{action}")
  url = url_with_websocket_scheme(url)
  @ws = WebSocket::Client::Simple.connect url, ws_options do |client|
    client.on :message do |msg|
      parsed_message = JSON.parse(msg.data)
      entity = case type
               when 'resource'
                 Resource.new(parsed_message)
               when 'resourcetype'
                 ResourceType.new(parsed_message)
               when 'metric'
                 Metric.new(parsed_message)
               when 'metrictype'
                 MetricType.new(parsed_message)
               else
                 BaseEntity.new(parsed_message)
               end
      yield entity
    end
  end
end

#fetch_version_and_statusHash{String=>String}

Return version and status information for the used version of Hawkular-Inventory

Returns:

  • (Hash{String=>String})

    ('Implementation-Version', 'Built-From-Git-SHA1', 'Status')



529
530
531
# File 'lib/hawkular/inventory/inventory_api.rb', line 529

def fetch_version_and_status
  http_get('/status')
end

#get_config_data_for_resource(resource_path) ⇒ Hash<String,Object] Hash with additional data

Retrieve runtime properties for the passed resource

Parameters:

  • resource_path (String)

    Canonical path of the resource to read properties from.

Returns:

  • (Hash<String,Object] Hash with additional data)

    Hash<String,Object] Hash with additional data



122
123
124
125
126
127
128
129
# File 'lib/hawkular/inventory/inventory_api.rb', line 122

def get_config_data_for_resource(resource_path)
  path = resource_path.is_a?(CanonicalPath) ? resource_path : CanonicalPath.parse(resource_path)
  resource_path = 'r;' + path.resource_ids.join('/r;')
  feed_id = path.feed_id
  http_get("/entity/f;#{feed_id}/#{resource_path}/d;configuration")
rescue
  {}
end

#get_entity(path) ⇒ Object

Retrieve a single entity from inventory by its canonical path

Parameters:

  • path (String)

    canonical path of the entity

Returns:

  • inventory entity



195
196
197
198
# File 'lib/hawkular/inventory/inventory_api.rb', line 195

def get_entity(path)
  c_path = path.is_a?(CanonicalPath) ? path : CanonicalPath.parse(path)
  http_get("/entity#{c_path}")
end

#get_resource(resource_path, fetch_resource_config = true) ⇒ Object

Return the resource object for the passed path

Parameters:

  • resource_path (String)

    Canonical path of the resource to fetch.

  • fetch_resource_config (Boolean) (defaults to: true)

    Should the resource config data be fetched?



374
375
376
377
378
379
380
381
382
383
384
385
386
# File 'lib/hawkular/inventory/inventory_api.rb', line 374

def get_resource(resource_path, fetch_resource_config = true)
  path = resource_path.is_a?(CanonicalPath) ? resource_path : CanonicalPath.parse(resource_path)
  feed_id = path.feed_id
  res_path = 'r;' + path.resource_ids.join('/r;')

  res = http_get("/entity/f;#{feed_id}/#{res_path}")
  if fetch_resource_config
    p = get_config_data_for_resource(resource_path)
    res['properties'] ||= {}
    res['properties'].merge! p['value'] unless p['value'].nil?
  end
  Resource.new(res)
end

#get_tenant(credentials = {}) ⇒ String

Deprecated.

this doesn't provide any value, because it merely returns the tenant ID which is known before the

Retrieve the tenant id for the passed credentials. If no credentials are passed, the ones from the constructor are used call anyway.

Parameters:

  • credentials (Hash{String=>String}) (defaults to: {})

    Hash of username, password, token(optional)

Returns:

  • (String)

    tenant id



47
48
49
50
51
52
53
54
# File 'lib/hawkular/inventory/inventory_api.rb', line 47

def get_tenant(credentials = {})
  creds = credentials.empty? ? @credentials : credentials
  auth_header = { Authorization: base_64_credentials(creds) }

  ret = http_get('/tenant', auth_header)

  ret['id']
end

#list_child_resources(parent_res_path, recursive = false) ⇒ Array<Resource>

Obtain the child resources of the passed resource. In case of a WildFly server, those would be Datasources, Deployments and so on.

Parameters:

  • parent_res_path (String)

    Canonical path of the resource to obtain children from.

  • recursive (Boolean) (defaults to: false)

    Whether to fetch also all the children of children of …

Returns:

  • (Array<Resource>)

    List of resources that are children of the given parent resource. Can be empty



137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/hawkular/inventory/inventory_api.rb', line 137

def list_child_resources(parent_res_path, recursive = false)
  path = parent_res_path.is_a?(CanonicalPath) ? parent_res_path : CanonicalPath.parse(parent_res_path)
  parent_resource_path = 'r;' + path.resource_ids.join('/r;')
  feed_id = path.feed_id

  if recursive
    ret = http_get("/traversal/f;#{feed_id}/#{parent_resource_path}/recursive;over=isParentOf;type=r")
  else
    ret = http_get("/traversal/f;#{feed_id}/#{parent_resource_path}/type=r")
  end
  ret.map { |r| Resource.new(r) }
end

#list_feedsArray<String>

List feeds in the system

Returns:

  • (Array<String>)

    List of feed ids



58
59
60
61
# File 'lib/hawkular/inventory/inventory_api.rb', line 58

def list_feeds
  ret = http_get('/traversal/type=f')
  ret.map { |f| f['id'] }
end

#list_metrics_for_metric_type(metric_type_path) ⇒ Array<Metric>

List the metrics for the passed metric type. If feed is not passed in the path, all the metrics across all the feeds of a given type will be retrieved This method may perform multiple REST calls.

Parameters:

  • metric_type_path (String)

    Canonical path of the resource type to look for. Can be obtained from MetricType.path. Must not be nil. The tenant_id in the canonical path doesn't have to be there.

Returns:

  • (Array<Metric>)

    List of metrics. Can be empty



206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/hawkular/inventory/inventory_api.rb', line 206

def list_metrics_for_metric_type(metric_type_path)
  path = metric_type_path.is_a?(CanonicalPath) ? metric_type_path : CanonicalPath.parse(metric_type_path)
  metric_type_id = path.metric_type_id
  feed_id = path.feed_id
  if feed_id.nil?
    ret = http_get("/traversal/mt;#{metric_type_id}/rl;defines/type=m")
  else
    ret = http_get("/traversal/f;#{feed_id}/mt;#{metric_type_id}/rl;defines/type=m")
  end

  ret.map { |m| Metric.new(m) }
rescue
  []
end

#list_metrics_for_resource(resource_path, filter = {}) ⇒ Array<Metric>

List metric (definitions) for the passed resource. It is possible to filter down the

result by a filter to only return a subset. The

Examples:

# Filter by type and match on metrics id
client.list_metrics_for_resource(wild_fly, type: 'GAUGE', match: 'Metrics~Heap')
# Filter by type only
client.list_metrics_for_resource(wild_fly, type: 'COUNTER')
# Don't filter, return all metric definitions
client.list_metrics_for_resource(wild_fly)

Parameters:

  • resource_path (String)

    Canonical path of the resource.

  • filter (Hash{Symbol=>String}) (defaults to: {})

    for 'type' and 'match' Metric type can be one of 'GAUGE', 'COUNTER', 'AVAILABILITY'. If a key is missing it will not be used for filtering

Returns:

  • (Array<Metric>)

    List of metrics that can be empty.



256
257
258
259
260
261
262
263
264
265
# File 'lib/hawkular/inventory/inventory_api.rb', line 256

def list_metrics_for_resource(resource_path, filter = {})
  path = resource_path.is_a?(CanonicalPath) ? resource_path : CanonicalPath.parse(resource_path)
  feed_id = path.feed_id
  resource_path_escaped = 'r;' + path.resource_ids.join('/r;')

  query = generate_query_params sort: 'id'
  ret = http_get("/traversal/f;#{feed_id}/#{resource_path_escaped}/rl;incorporates/type=m#{query}")
  to_filter = ret.map { |m| Metric.new(m) }
  filter_entities(to_filter, filter)
end

#list_metrics_for_resource_type(resource_type_path) ⇒ Array<Metric>

List the metrics for all the resources of a given resource type. If feed is not passed in the resource type canonical path, all the metrics across all the feeds of a resource type will be retrieved. This method may perform multiple REST calls.

Parameters:

  • resource_type_path (String)

    Canonical path of the resource type to look for. Can be obtained from ResourceType.path. Must not be nil. The tenant_id in the canonical path doesn't have to be there.

Returns:

  • (Array<Metric>)

    List of metrics. Can be empty



227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/hawkular/inventory/inventory_api.rb', line 227

def list_metrics_for_resource_type(resource_type_path)
  path = resource_type_path.is_a?(CanonicalPath) ? resource_type_path : CanonicalPath.parse(resource_type_path)
  resource_type_id = path.resource_type_id
  feed_id = path.feed_id

  query = generate_query_params sort: 'id'
  if feed_id.nil?
    ret = http_get("/traversal/rt;#{resource_type_id}/rl;defines/type=r/rl;incorporates/type=m#{query}")
  else
    ret = http_get(
      "/traversal/f;#{feed_id}/rt;#{resource_type_id}/rl;defines/type=r/rl;incorporates/type=m#{query}")
  end
  ret.map { |m| Metric.new(m) }
end

#list_operation_definitions(resource_type_path) ⇒ Array<String>

List operation definitions (types) for a given resource type

Parameters:

  • resource_type_path (String)

    canonical path of the resource type entity

Returns:

  • (Array<String>)

    List of operation type ids



418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# File 'lib/hawkular/inventory/inventory_api.rb', line 418

def list_operation_definitions(resource_type_path)
  parsed_path = CanonicalPath.parse(resource_type_path.to_s)
  feed_id = parsed_path.feed_id
  resource_type_id = parsed_path.resource_type_id
  ots = http_get("/traversal/f;#{feed_id}/rt;#{resource_type_id}/type=ot")
  res = {}
  ots.each do |ot|
    ot_name = ERB::Util.url_encode ot['name']
    pts = http_get("/traversal/f;#{feed_id}/rt;#{resource_type_id}/ot;#{ot_name}/d;parameterTypes")
    ot['parameters'] = pts[0]['value'] unless pts.empty?
    od = OperationDefinition.new ot
    res.store od.name, od
  end
  res
end

#list_operation_definitions_for_resource(resource_path) ⇒ Array<String>

List operation definitions (types) for a given resource

Parameters:

  • resource_path (String)

    canonical path of the resource entity

Returns:

  • (Array<String>)

    List of operation type ids



437
438
439
440
# File 'lib/hawkular/inventory/inventory_api.rb', line 437

def list_operation_definitions_for_resource(resource_path)
  resource = get_resource(resource_path.to_s, false)
  list_operation_definitions(resource.type_path)
end

#list_relationships(entity_path, named = nil) ⇒ Array<Relationship>

Obtain a list of relationships starting at the passed resource

Parameters:

  • entity_path (String)

    Canonical path of the entity that forms the one end of the relationship

  • named (String) (defaults to: nil)

    Name of the relationship

Returns:



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/hawkular/inventory/inventory_api.rb', line 154

def list_relationships(entity_path, named = nil)
  path = entity_path.is_a?(CanonicalPath) ? entity_path : CanonicalPath.parse(entity_path)
  query_params = {
    sort: '__targetCp'
  }

  query = generate_query_params query_params
  if named.nil?
    ret = http_get("/traversal#{path}/relationships#{query}")
  else
    ret = http_get("/traversal#{path}/relationships;name=#{named}#{query}")
  end

  ret.map { |r| Relationship.new(r) }
end

#list_relationships_for_feed(feed_id, named = nil) ⇒ Array<Relationship>

Obtain a list of relationships for the passed feed

Parameters:

  • feed_id (String)

    Id of the feed

  • named (String) (defaults to: nil)

    Name of the relationship

Returns:



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/hawkular/inventory/inventory_api.rb', line 174

def list_relationships_for_feed(feed_id, named = nil)
  the_feed = hawk_escape_id feed_id
  query_params = {
    sort: '__targetCp'
  }

  query = generate_query_params query_params
  if named.nil?
    ret = http_get("/traversal/f;#{the_feed}/relationships#{query}")
  else
    ret = http_get("/traversal;/f;#{the_feed}/relationships;named=#{named}#{query}")
  end

  ret.map { |r| Relationship.new(r) }
rescue
  []
end

#list_resource_types(feed_id = nil) ⇒ Array<ResourceType>

List resource types. If no feed_id is given all types are listed

Parameters:

  • feed_id (String) (defaults to: nil)

    The id of the feed the type lives under. Can be nil for feedless types

Returns:

  • (Array<ResourceType>)

    List of types, that can be empty



66
67
68
69
70
71
72
73
74
# File 'lib/hawkular/inventory/inventory_api.rb', line 66

def list_resource_types(feed_id = nil)
  if feed_id.nil?
    ret = http_get('/traversal/type=rt')
  else
    the_feed = hawk_escape_id feed_id
    ret = http_get("/traversal/f;#{the_feed}/type=rt")
  end
  ret.map { |rt| ResourceType.new(rt) }
end

#list_resources_for_feed(feed_id, fetch_properties = false, filter = {}) ⇒ Array<Resource>

Return all resources for a feed

Parameters:

  • feed_id (String)

    Id of the feed that hosts the resources

  • fetch_properties (Boolean) (defaults to: false)

    Should the config data be fetched too

Returns:

  • (Array<Resource>)

    List of resources, which can be empty.



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/hawkular/inventory/inventory_api.rb', line 80

def list_resources_for_feed(feed_id, fetch_properties = false, filter = {})
  fail 'Feed id must be given' unless feed_id
  the_feed = hawk_escape_id feed_id
  ret = http_get("/traversal/f;#{the_feed}/type=r")
  to_filter = ret.map do |r|
    if fetch_properties
      p = get_config_data_for_resource(r['path'])
      r['properties'] = p['value']
    end
    Resource.new(r)
  end
  filter_entities(to_filter, filter)
end

#list_resources_for_type(resource_type_path, fetch_properties = false) ⇒ Array<Resource>

List the resources for the passed resource type. The representation for resources under a feed are sparse and additional data must be retrieved separately. It is possible though to also obtain runtime properties by setting #fetch_properties to true.

Parameters:

  • resource_type_path (String)

    Canonical path of the resource type. Can be obtained from ResourceType.path. Must not be nil. The tenant_id in the canonical path doesn't have to be there.

  • fetch_properties (Boolean) (defaults to: false)

    Shall additional runtime properties be fetched?

Returns:

  • (Array<Resource>)

    List of resources. Can be empty



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/hawkular/inventory/inventory_api.rb', line 101

def list_resources_for_type(resource_type_path, fetch_properties = false)
  path = resource_type_path.is_a?(CanonicalPath) ? resource_type_path : CanonicalPath.parse(resource_type_path)
  resource_type_id = path.resource_type_id
  feed_id = path.feed_id
  if feed_id.nil?
    ret = http_get("/traversal/rt;#{resource_type_id}/rl;defines/type=r")
  else
    ret = http_get("/traversal/f;#{feed_id}/rt;#{resource_type_id}/rl;defines/type=r")
  end
  ret.map do |r|
    if fetch_properties && !feed_id.nil?
      p = get_config_data_for_resource(r['path'])
      r['properties'] = p['value']
    end
    Resource.new(r)
  end
end

#no_more_events!Object

Stop listening on inventory events. this method closes the web socket connection



522
523
524
# File 'lib/hawkular/inventory/inventory_api.rb', line 522

def no_more_events!
  @ws.close
end