Class: Puppet::Graph::RelationshipGraph Private
- Inherits:
-
SimpleGraph
- Object
- SimpleGraph
- Puppet::Graph::RelationshipGraph
- Defined in:
- lib/puppet/graph/relationship_graph.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
The relationship graph is the final form of a puppet catalog in which all dependency edges are explicitly in the graph. This form of the catalog is used to traverse the graph in the order in which resources are managed.
Instance Attribute Summary collapse
- #blockers ⇒ Object readonly private
Instance Method Summary collapse
- #add_relationship(f, t, label = nil) ⇒ Object private
- #add_vertex(vertex, priority = nil) ⇒ Object private
- #clear_blockers ⇒ Object private
- #enqueue(*resources) ⇒ Object private
-
#enqueue_roots ⇒ Object
private
Enqueue the initial set of resources, those with no dependencies.
- #finish(resource) ⇒ Object private
-
#initialize(prioritizer) ⇒ RelationshipGraph
constructor
private
A new instance of RelationshipGraph.
- #next_resource ⇒ Object private
- #populate_from(catalog) ⇒ Object private
- #remove_vertex!(vertex) ⇒ Object private
- #resource_priority(resource) ⇒ Object private
- #traverse(options = {}, &block) ⇒ Object private
-
#unblock(resource) ⇒ Object
private
Decrement the blocker count for the resource by 1.
Methods inherited from SimpleGraph
#add_edge, #adjacent, #clear, #dependencies, #dependents, #direct_dependencies_of, #direct_dependents_of, #directed?, #downstream_from_vertex, #each_edge, #edge?, #edges, #edges_between, #find_cycles_in_graph, #initialize_from_hash, #leaves, #matching_edges, #path_between, #paths_in_cycle, #remove_edge!, #report_cycles_in_graph, #reversal, #size, #stringify, #tarjan, #to_a, #to_data_hash, #to_dot, #to_dot_graph, #tree_from_vertex, #upstream_from_vertex, #vertex?, #vertices, #walk, #write_cycles_to_graph, #write_graph
Methods included from Util::PsychSupport
Constructor Details
#initialize(prioritizer) ⇒ RelationshipGraph
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of RelationshipGraph.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/puppet/graph/relationship_graph.rb', line 10 def initialize(prioritizer) super() @prioritizer = prioritizer @ready = Puppet::Graph::RbTreeMap.new @generated = {} @done = {} @blockers = {} @providerless_types = [] end |
Instance Attribute Details
#blockers ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
8 9 10 |
# File 'lib/puppet/graph/relationship_graph.rb', line 8 def blockers @blockers end |
Instance Method Details
#add_relationship(f, t, label = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
44 45 46 47 |
# File 'lib/puppet/graph/relationship_graph.rb', line 44 def add_relationship(f, t, label=nil) super(f, t, label) @ready.delete(@prioritizer.priority_of(t)) end |
#add_vertex(vertex, priority = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
34 35 36 37 38 39 40 41 42 |
# File 'lib/puppet/graph/relationship_graph.rb', line 34 def add_vertex(vertex, priority = nil) super(vertex) if priority @prioritizer.record_priority_for(vertex, priority) else @prioritizer.generate_priority_for(vertex) end end |
#clear_blockers ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
78 79 80 |
# File 'lib/puppet/graph/relationship_graph.rb', line 78 def clear_blockers @blockers.clear end |
#enqueue(*resources) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
82 83 84 85 86 |
# File 'lib/puppet/graph/relationship_graph.rb', line 82 def enqueue(*resources) resources.each do |resource| @ready[@prioritizer.priority_of(resource)] = resource end end |
#enqueue_roots ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Enqueue the initial set of resources, those with no dependencies.
59 60 61 62 63 64 |
# File 'lib/puppet/graph/relationship_graph.rb', line 59 def enqueue_roots vertices.each do |v| @blockers[v] = direct_dependencies_of(v).length enqueue(v) if @blockers[v] == 0 end end |
#finish(resource) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
88 89 90 91 92 93 |
# File 'lib/puppet/graph/relationship_graph.rb', line 88 def finish(resource) direct_dependents_of(resource).each do |v| enqueue(v) if unblock(v) end @done[resource] = true end |
#next_resource ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
95 96 97 |
# File 'lib/puppet/graph/relationship_graph.rb', line 95 def next_resource @ready.delete_min end |
#populate_from(catalog) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/puppet/graph/relationship_graph.rb', line 22 def populate_from(catalog) add_all_resources_as_vertices(catalog) build_manual_dependencies build_autorelation_dependencies(catalog) write_graph(:relationships) if catalog.host_config? replace_containers_with_anchors(catalog) write_graph(:expanded_relationships) if catalog.host_config? end |
#remove_vertex!(vertex) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
49 50 51 52 |
# File 'lib/puppet/graph/relationship_graph.rb', line 49 def remove_vertex!(vertex) super @prioritizer.forget(vertex) end |
#resource_priority(resource) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
54 55 56 |
# File 'lib/puppet/graph/relationship_graph.rb', line 54 def resource_priority(resource) @prioritizer.priority_of(resource) end |
#traverse(options = {}, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/puppet/graph/relationship_graph.rb', line 99 def traverse( = {}, &block) continue_while = [:while] || lambda { true } pre_process = [:pre_process] || lambda { |resource| } overly_deferred_resource_handler = [:overly_deferred_resource_handler] || lambda { |resource| } canceled_resource_handler = [:canceled_resource_handler] || lambda { |resource| } teardown = [:teardown] || lambda {} graph_cycle_handler = [:graph_cycle_handler] || lambda { [] } if cycles = report_cycles_in_graph graph_cycle_handler.call(cycles) end enqueue_roots deferred_resources = [] while continue_while.call() && (resource = next_resource) if resource.suitable? made_progress = true pre_process.call(resource) yield resource finish(resource) else deferred_resources << resource end if @ready.empty? and deferred_resources.any? if made_progress enqueue(*deferred_resources) else deferred_resources.each do |res| overly_deferred_resource_handler.call(res) finish(res) end end made_progress = false deferred_resources = [] end end if !continue_while.call() while (resource = next_resource) canceled_resource_handler.call(resource) finish(resource) end end teardown.call() end |
#unblock(resource) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Decrement the blocker count for the resource by 1. If the number of blockers is unknown, count them and THEN decrement by 1.
68 69 70 71 72 73 74 75 76 |
# File 'lib/puppet/graph/relationship_graph.rb', line 68 def unblock(resource) @blockers[resource] ||= direct_dependencies_of(resource).select { |r2| !@done[r2] }.length if @blockers[resource] > 0 @blockers[resource] -= 1 else resource.warning _("appears to have a negative number of dependencies") end @blockers[resource] <= 0 end |