Class: Hawkular::Inventory::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/hawkular/inventory/entities.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Resource

Returns a new instance of Resource.



90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/hawkular/inventory/entities.rb', line 90

def initialize(hash)
  @id = hash['id']
  @name = hash['name']
  @feed = hash['feedId']
  @type = ResourceType.new(hash['type'])
  @parent_id = hash['parentId']
  @properties = hash['properties'] || {}
  @config = hash['config'] || {}
  @metrics = (hash['metrics'] || []).map { |m| Metric.new(m) }
  @children = hash['children'].map { |r| Resource.new(r) } if hash.key? 'children'
  @_hash = hash.dup
end

Instance Attribute Details

#configHash<String,String> (readonly)

Returns Config map of this resource.

Returns:

  • (Hash<String,String>)

    Config map of this resource



88
89
90
# File 'lib/hawkular/inventory/entities.rb', line 88

def config
  @config
end

#feedString (readonly)

Returns Feed this entity belongs to.

Returns:

  • (String)

    Feed this entity belongs to



80
81
82
# File 'lib/hawkular/inventory/entities.rb', line 80

def feed
  @feed
end

#idString (readonly)

Returns Id of the entity.

Returns:

  • (String)

    Id of the entity



76
77
78
# File 'lib/hawkular/inventory/entities.rb', line 76

def id
  @id
end

#nameString (readonly)

Returns Name of the entity.

Returns:

  • (String)

    Name of the entity



78
79
80
# File 'lib/hawkular/inventory/entities.rb', line 78

def name
  @name
end

#parent_idString (readonly)

Returns Parent ID of this entity (nil if it’s a root resource).

Returns:

  • (String)

    Parent ID of this entity (nil if it’s a root resource)



84
85
86
# File 'lib/hawkular/inventory/entities.rb', line 84

def parent_id
  @parent_id
end

#propertiesHash<String,String> (readonly)

Returns Properties of this resource.

Returns:

  • (Hash<String,String>)

    Properties of this resource



86
87
88
# File 'lib/hawkular/inventory/entities.rb', line 86

def properties
  @properties
end

#typeResourceType (readonly)

Returns Type of this resource.

Returns:



82
83
84
# File 'lib/hawkular/inventory/entities.rb', line 82

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



124
125
126
# File 'lib/hawkular/inventory/entities.rb', line 124

def ==(other)
  equal?(other) || other.class == self.class && other.id == @id
end

#children(recursive = false) ⇒ Object



103
104
105
106
107
108
109
# File 'lib/hawkular/inventory/entities.rb', line 103

def children(recursive = false)
  return @children unless recursive == true
  fail Hawkular::ArgumentError 'Resource tree not loaded, load it by calling resource_tree' if @children.nil?
  @children.flat_map do |child|
    [child, *child.children(recursive)]
  end
end

#children_by_type(type, recursive = false) ⇒ Object



111
112
113
# File 'lib/hawkular/inventory/entities.rb', line 111

def children_by_type(type, recursive = false)
  children(recursive).select { |c| c.type.id == type }
end

#metrics(recursive = false) ⇒ Object



115
116
117
118
# File 'lib/hawkular/inventory/entities.rb', line 115

def metrics(recursive = false)
  return @metrics unless recursive == true
  children(recursive).collect(&:metrics).flat_map(&:itself).concat(@metrics)
end

#metrics_by_family(family) ⇒ Object



120
121
122
# File 'lib/hawkular/inventory/entities.rb', line 120

def metrics_by_family(family)
  @metrics.select { |m| m.family == family }
end

#to_hHash<String,Object>

Returns a hash representation of the resource

Returns:

  • (Hash<String,Object>)

    hash of the resource



130
131
132
# File 'lib/hawkular/inventory/entities.rb', line 130

def to_h
  @_hash.dup
end