class Hawkular::Inventory::Client

Client class to interact with Hawkular Inventory

Attributes

version[R]

Public Class Methods

create(hash) click to toggle source

Creates a new Inventory Client @param hash [Hash{String=>Object}] a hash containing base url of Hawkular-inventory - e.g

entrypoint: http://localhost:8080/hawkular/inventory

and another sub-hash containing the hash with username, password, token(optional)

   # File lib/hawkular/inventory/inventory_api.rb
29 def self.create(hash)
30   fail Hawkular::ArgumentError, 'no parameter ":entrypoint" given' unless hash[:entrypoint]
31 
32   hash[:credentials] ||= {}
33   hash[:options] ||= {}
34   Client.new(hash[:entrypoint], hash[:credentials], hash[:options], hash[:page_size])
35 end
new(entrypoint = nil, credentials = {}, options = {}, page_size = nil) click to toggle source

Create a new Inventory Client @param entrypoint [String] base url of Hawkular-inventory - e.g

http://localhost:8080/hawkular/inventory

@param credentials [Hash{String=>String}] Hash of username, password, token(optional) @param options [Hash{String=>String}] Additional rest client options

Calls superclass method Hawkular::BaseClient::new
   # File lib/hawkular/inventory/inventory_api.rb
16 def initialize(entrypoint = nil, credentials = {}, options = {}, page_size = nil)
17   entrypoint = normalize_entrypoint_url entrypoint, 'hawkular/inventory'
18   @entrypoint = entrypoint
19   super(entrypoint, credentials, options)
20   version = fetch_version_and_status['Implementation-Version']
21   @version = version.scan(/\d+/).map(&:to_i)
22   @page_size = page_size || 100
23 end

Public Instance Methods

children_resources(parent_id) click to toggle source

Get childrens of a resource @return Children of a resource

   # File lib/hawkular/inventory/inventory_api.rb
56 def children_resources(parent_id)
57   http_get(url('/resources/%s/children', parent_id))['results'].map { |r| Resource.new(r) }
58 end
fetch_version_and_status() click to toggle source

Return version and status information for the used version of Hawkular-Inventory @return [Hash{String=>String}]

('Implementation-Version', 'Built-From-Git-SHA1', 'Status')
    # File lib/hawkular/inventory/inventory_api.rb
100 def fetch_version_and_status
101   http_get('/status')
102 end
parent(id) click to toggle source

Get parent of a resource @return Resource the parent resource, or nil if the provided ID referred to a root resource

   # File lib/hawkular/inventory/inventory_api.rb
62 def parent(id)
63   hash = http_get(url('/resources/%s/parent', id))
64   Resource.new(hash) if hash
65 end
resource(id) click to toggle source

Get single resource by id @return Resource the resource

   # File lib/hawkular/inventory/inventory_api.rb
39 def resource(id)
40   hash = http_get(url('/resources/%s', id))
41   Resource.new(hash)
42 rescue ::Hawkular::Exception => e
43   return if e.cause.is_a?(::RestClient::NotFound)
44   raise
45 end
resource_tree(id) click to toggle source

Get resource by id with its complete subtree @return Resource the resource

   # File lib/hawkular/inventory/inventory_api.rb
49 def resource_tree(id)
50   hash = http_get(url('/resources/%s/tree', id))
51   Resource.new(hash)
52 end
resources(filter = {}) click to toggle source

List resources @param [Hash] filter options to filter the resource list @option filter :root If truthy, only get root resources @option filter :feedId Filter by feed id @option filter :typeId Filter by type id @return [Enumeration<Resource>] Lazy-loaded Enumeration of resources

   # File lib/hawkular/inventory/inventory_api.rb
79 def resources(filter = {})
80   filter[:root] = !filter[:root].nil? if filter.key? :root
81   filter[:maxResults] = @page_size
82 
83   fetch_func = lambda do |offset|
84     filter[:startOffSet] = offset
85     filter_query = '?' + filter.keys.join('=%s&') + '=%s' unless filter.empty?
86     http_get(url("/resources#{filter_query}", *filter.values))
87   end
88   ResultFetcher.new(fetch_func).map { |r| Resource.new(r) }
89 end
resources_for_type(type) click to toggle source

List resources for type @return [Enumeration<Resource>] Lazy-loaded Enumeration of resources

   # File lib/hawkular/inventory/inventory_api.rb
93 def resources_for_type(type)
94   resources typeId: type
95 end
root_resources() click to toggle source

List root resources @return [Enumeration<Resource>] Lazy-loaded Enumeration of resources

   # File lib/hawkular/inventory/inventory_api.rb
69 def root_resources
70   resources root: 'true'
71 end