Class: Hawkular::Inventory::Client
- Inherits:
-
BaseClient
- Object
- BaseClient
- Hawkular::Inventory::Client
- Defined in:
- lib/hawkular/inventory/inventory_api.rb
Overview
Client class to interact with Hawkular Inventory
Constant Summary
Constants inherited from BaseClient
BaseClient::HawkularConnectionException, BaseClient::HawkularException
Instance Attribute Summary collapse
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Attributes inherited from BaseClient
Class Method Summary collapse
Instance Method Summary collapse
-
#children_resources(parent_id) ⇒ Object
Get childrens of a resource.
-
#fetch_version_and_status ⇒ Hash{String=>String}
Return version and status information for the used version of Hawkular-Inventory.
-
#initialize(entrypoint = nil, credentials = {}, options = {}, page_size = nil) ⇒ Client
constructor
Create a new Inventory Client.
-
#parent(id) ⇒ Object
Get parent of a resource.
-
#resource(id) ⇒ Object
Get single resource by id.
-
#resource_tree(id) ⇒ Object
Get resource by id with its complete subtree.
-
#resources(filter = {}) ⇒ Enumeration<Resource>
List resources.
-
#resources_for_type(type) ⇒ Enumeration<Resource>
List resources for type.
-
#root_resources ⇒ Enumeration<Resource>
List root resources.
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, #url_with_websocket_scheme
Methods included from ClientUtils
Constructor Details
#initialize(entrypoint = nil, credentials = {}, options = {}, page_size = nil) ⇒ Client
Create a new Inventory Client
16 17 18 19 20 21 22 23 |
# File 'lib/hawkular/inventory/inventory_api.rb', line 16 def initialize(entrypoint = nil, credentials = {}, = {}, page_size = nil) entrypoint = normalize_entrypoint_url entrypoint, 'hawkular/inventory' @entrypoint = entrypoint super(entrypoint, credentials, ) version = fetch_version_and_status['Implementation-Version'] @version = version.scan(/\d+/).map(&:to_i) @page_size = page_size || 100 end |
Instance Attribute Details
#version ⇒ Object (readonly)
Returns the value of attribute version.
9 10 11 |
# File 'lib/hawkular/inventory/inventory_api.rb', line 9 def version @version end |
Class Method Details
.create(hash) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/hawkular/inventory/inventory_api.rb', line 29 def self.create(hash) fail Hawkular::ArgumentError, 'no parameter ":entrypoint" given' unless hash[:entrypoint] hash[:credentials] ||= {} hash[:options] ||= {} Client.new(hash[:entrypoint], hash[:credentials], hash[:options], hash[:page_size]) end |
Instance Method Details
#children_resources(parent_id) ⇒ Object
Get childrens of a resource
56 57 58 |
# File 'lib/hawkular/inventory/inventory_api.rb', line 56 def children_resources(parent_id) http_get(url('/resources/%s/children', parent_id))['results'].map { |r| Resource.new(r) } end |
#fetch_version_and_status ⇒ Hash{String=>String}
Return version and status information for the used version of Hawkular-Inventory
100 101 102 |
# File 'lib/hawkular/inventory/inventory_api.rb', line 100 def fetch_version_and_status http_get('/status') end |
#parent(id) ⇒ Object
Get parent of a resource
62 63 64 65 |
# File 'lib/hawkular/inventory/inventory_api.rb', line 62 def parent(id) hash = http_get(url('/resources/%s/parent', id)) Resource.new(hash) if hash end |
#resource(id) ⇒ Object
Get single resource by id
39 40 41 42 43 44 45 |
# File 'lib/hawkular/inventory/inventory_api.rb', line 39 def resource(id) hash = http_get(url('/resources/%s', id)) Resource.new(hash) rescue ::Hawkular::Exception => e return if e.cause.is_a?(::RestClient::NotFound) raise end |
#resource_tree(id) ⇒ Object
Get resource by id with its complete subtree
49 50 51 52 |
# File 'lib/hawkular/inventory/inventory_api.rb', line 49 def resource_tree(id) hash = http_get(url('/resources/%s/tree', id)) Resource.new(hash) end |
#resources(filter = {}) ⇒ Enumeration<Resource>
List resources
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/hawkular/inventory/inventory_api.rb', line 79 def resources(filter = {}) filter[:root] = !filter[:root].nil? if filter.key? :root filter[:maxResults] = @page_size fetch_func = lambda do |offset| filter[:startOffSet] = offset filter_query = '?' + filter.keys.join('=%s&') + '=%s' unless filter.empty? http_get(url("/resources#{filter_query}", *filter.values)) end ResultFetcher.new(fetch_func).map { |r| Resource.new(r) } end |
#resources_for_type(type) ⇒ Enumeration<Resource>
List resources for type
93 94 95 |
# File 'lib/hawkular/inventory/inventory_api.rb', line 93 def resources_for_type(type) resources typeId: type end |
#root_resources ⇒ Enumeration<Resource>
List root resources
69 70 71 |
# File 'lib/hawkular/inventory/inventory_api.rb', line 69 def root_resources resources root: 'true' end |