Class: Arborist::Node::Resource
- Inherits:
-
Arborist::Node
- Object
- Arborist::Node
- Arborist::Node::Resource
- Defined in:
- lib/arborist/node/resource.rb
Overview
A node type for Arborist trees that represent arbitrary resources of a host.
Constant Summary
Constants inherited from Arborist::Node
LOADED_INSTANCE_KEY, OPERATIONAL_ATTRIBUTES, UNREACHABLE_STATES, VALID_IDENTIFIER
Instance Attribute Summary
Attributes inherited from Arborist::Node
#ack, #children, #dependencies, #errors, #identifier, #last_contacted, #pending_change_events, #previous_ack, #properties, #quieted_reasons, #source, #status_changed, #status_history, #status_last_changed, #subscriptions, #update_delta, #warnings
Instance Method Summary collapse
-
#addresses ⇒ Object
Delegate the resources’s address to its host.
-
#category(new_category = nil) ⇒ Object
Get/set the resource category.
-
#family ⇒ Object
Return the node family, so observers can know ancestry after serialization for custom node types that inherit from this class.
-
#hostname ⇒ Object
Delegate the resource’s hostname to it’s parent host.
-
#initialize(identifier, host, attributes = {}, &block) ⇒ Resource
constructor
Create a new Resource node.
-
#match_criteria?(key, val) ⇒ Boolean
Returns
true
if the node matches the specifiedkey
andval
criteria. -
#modify(attributes) ⇒ Object
Set service
attributes
. -
#operational_values ⇒ Object
Return a Hash of the operational values that are included with the node’s monitor state.
-
#parent(new_parent = nil) ⇒ Object
Overridden to disallow modification of a Resource parent, as it needs a reference to the Host node for delegation.
-
#to_h ⇒ Object
Serialize the resource node.
Methods inherited from Arborist::Node
#<<, #==, #acked_description, #acknowledge, #add_child, add_loaded_instance, add_subnode_factory_method, #add_subscription, #all_of, #any_of, #broadcast_events, #clear_transition_temp_vars, #config, curried_create, #dependencies_down?, #dependencies_up?, #depends_on, #description, #each, each_in, #fetch_values, #find_matching_subscriptions, #flap_threshold, #flapping, from_hash, #handle_event, #handle_node_disabled_event, #handle_node_down_event, #handle_node_quieted_event, #handle_node_up_event, #has_children?, #has_dependencies?, #has_quieted_reason?, inherited, #inspect, load, #make_delta_event, #make_update_event, #marshal_dump, #marshal_load, #matches?, #merge_and_record_delta, #merge_new_properties, new, #node_description, #node_subscribers, #operational?, parent_types, #publish_events, #reachable?, #register_secondary_dependencies, #remove_child, #remove_subscription, #reparent, #restore, #state_has_changed?, #status, #status_description, #status_history_size, subnode_type?, #tags, #type, #unacknowledge, #unreachable?, #update, #update_errors, #update_properties, #update_warnings
Methods included from MethodUtilities
#attr_predicate, #attr_predicate_accessor, #dsl_accessor, #singleton_attr_accessor, #singleton_attr_reader, #singleton_attr_writer, #singleton_method_alias, #singleton_predicate_accessor, #singleton_predicate_reader
Methods included from HashUtilities
compact_hash, hash_matches, merge_recursively, stringify_keys, symbolify_keys
Constructor Details
#initialize(identifier, host, attributes = {}, &block) ⇒ Resource
Create a new Resource node.
16 17 18 19 20 21 22 23 24 |
# File 'lib/arborist/node/resource.rb', line 16 def initialize( identifier, host, attributes={}, &block ) raise Arborist::NodeError, "no host given" unless host.is_a?( Arborist::Node::Host ) qualified_identifier = "%s-%s" % [ host.identifier, identifier ] @host = host attributes[ :category ] ||= identifier super( qualified_identifier, host, attributes, &block ) end |
Instance Method Details
#addresses ⇒ Object
Delegate the resources’s address to its host.
61 62 63 |
# File 'lib/arborist/node/resource.rb', line 61 def addresses return @host.addresses end |
#category(new_category = nil) ⇒ Object
Get/set the resource category.
54 55 56 57 |
# File 'lib/arborist/node/resource.rb', line 54 def category( new_category=nil ) return @category unless new_category @category = new_category end |
#family ⇒ Object
Return the node family, so observers can know ancestry after serialization for custom node types that inherit from this class.
29 30 31 |
# File 'lib/arborist/node/resource.rb', line 29 def family return :resource end |
#hostname ⇒ Object
Delegate the resource’s hostname to it’s parent host.
67 68 69 |
# File 'lib/arborist/node/resource.rb', line 67 def hostname return @host.hostname end |
#match_criteria?(key, val) ⇒ Boolean
Returns true
if the node matches the specified key
and val
criteria.
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/arborist/node/resource.rb', line 90 def match_criteria?( key, val ) self.log.debug "Matching %p: %p against %p" % [ key, val, self ] return case key when 'address' search_addr = IPAddr.new( val ) self.addresses.any? {|a| search_addr.include?(a) } when 'category' Array( val ).include?( self.category ) else super end end |
#modify(attributes) ⇒ Object
Set service attributes
.
35 36 37 38 39 |
# File 'lib/arborist/node/resource.rb', line 35 def modify( attributes ) attributes = stringify_keys( attributes ) super self.category( attributes['category'] ) end |
#operational_values ⇒ Object
Return a Hash of the operational values that are included with the node’s monitor state.
44 45 46 47 48 49 50 |
# File 'lib/arborist/node/resource.rb', line 44 def operational_values return super.merge( addresses: self.addresses.map( &:to_s ), hostname: self.hostname, category: self.category ) end |
#parent(new_parent = nil) ⇒ Object
Overridden to disallow modification of a Resource parent, as it needs a reference to the Host node for delegation.
74 75 76 77 |
# File 'lib/arborist/node/resource.rb', line 74 def parent( new_parent=nil ) return super unless new_parent raise "Can't reparent a resource; replace the node instead" end |
#to_h ⇒ Object
Serialize the resource node. Return a Hash of the host node’s state.
81 82 83 84 85 86 |
# File 'lib/arborist/node/resource.rb', line 81 def to_h( * ) return super.merge( addresses: self.addresses.map( &:to_s ), category: self.category ) end |