Class: Puppet::Transaction::EventManager Private

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/transaction/event_manager.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.

This class stores, routes, and responds to events generated while evaluating a transaction.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transaction) ⇒ EventManager

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 EventManager


20
21
22
23
24
# File 'lib/puppet/transaction/event_manager.rb', line 20

def initialize(transaction)
  @transaction = transaction
  @event_queues = {}
  @events = []
end

Instance Attribute Details

#eventsObject (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.


18
19
20
# File 'lib/puppet/transaction/event_manager.rb', line 18

def events
  @events
end

#transactionObject (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.


11
12
13
# File 'lib/puppet/transaction/event_manager.rb', line 11

def transaction
  @transaction
end

Instance Method Details

#dequeue_all_events_for_resource(target) ⇒ 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.


85
86
87
88
89
90
91
# File 'lib/puppet/transaction/event_manager.rb', line 85

def dequeue_all_events_for_resource(target)
  callbacks = @event_queues[target]
  if callbacks && !callbacks.empty?
    target.info _("Unscheduling all events on %{target}") % { target: target }
    @event_queues[target] = {}
  end
end

#dequeue_events_for_resource(target, callback) ⇒ 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.


93
94
95
96
# File 'lib/puppet/transaction/event_manager.rb', line 93

def dequeue_events_for_resource(target, callback)
  target.info _("Unscheduling %{callback} on %{target}") % { callback: callback, target: target }
  @event_queues[target][callback] = [] if @event_queues[target]
end

#process_events(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.

Respond to any queued events for this resource.


31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/puppet/transaction/event_manager.rb', line 31

def process_events(resource)
  restarted = false
  queued_events(resource) do |callback, events|
    r = process_callback(resource, callback, events)
    restarted ||= r
  end

  if restarted
    queue_events(resource, [resource.event(:name => :restarted, :status => "success")])

    transaction.resource_status(resource).restarted = true
  end
end

#queue_events(resource, events) ⇒ void

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.

This method returns an undefined value.

Queues events for other resources to respond to. All of these events have to be from the same resource.


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/puppet/transaction/event_manager.rb', line 51

def queue_events(resource, events)
  #@events += events

  # Do some basic normalization so we're not doing so many
  # graph queries for large sets of events.
  events.inject({}) do |collection, event|
    collection[event.name] ||= []
    collection[event.name] << event
    collection
  end.collect do |name, list|
    # It doesn't matter which event we use - they all have the same source
    # and name here.
    event = list[0]

    # Collect the targets of any subscriptions to those events.  We pass
    # the parent resource in so it will override the source in the events,
    # since eval_generated children can't have direct relationships.
    received = (event.name != :restarted)
    relationship_graph.matching_edges(event, resource).each do |edge|
      received ||= true unless edge.target.is_a?(Puppet::Type.type(:whit))
      method = edge.callback
      next unless method
      next unless edge.target.respond_to?(method)

      queue_events_for_resource(resource, edge.target, method, list)
    end
    @events << event if received

    queue_events_for_resource(resource, resource, :refresh, [event]) if resource.self_refresh? and ! resource.deleting?
  end

  dequeue_events_for_resource(resource, :refresh) if events.detect { |e| e.invalidate_refreshes }
end

#queue_events_for_resource(source, target, callback, events) ⇒ 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.


98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/puppet/transaction/event_manager.rb', line 98

def queue_events_for_resource(source, target, callback, events)
  whit = Puppet::Type.type(:whit)

  # The message that a resource is refreshing the completed-whit for its own class
  # is extremely counter-intuitive. Basically everything else is easy to understand,
  # if you suppress the whit-lookingness of the whit resources
  refreshing_c_whit = target.is_a?(whit) && target.name =~ /^completed_/

  if refreshing_c_whit
    source.debug "The container #{target} will propagate my #{callback} event"
  else
    source.info _("Scheduling %{callback} of %{target}") % { callback: callback, target: target }
  end

  @event_queues[target] ||= {}
  @event_queues[target][callback] ||= []
  @event_queues[target][callback].concat(events)
end

#queued_events(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.


117
118
119
120
121
122
123
# File 'lib/puppet/transaction/event_manager.rb', line 117

def queued_events(resource)
  callbacks = @event_queues[resource]
  return unless callbacks
  callbacks.each do |callback, events|
    yield callback, events unless events.empty?
  end
end

#relationship_graphObject

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.


26
27
28
# File 'lib/puppet/transaction/event_manager.rb', line 26

def relationship_graph
  transaction.relationship_graph
end