diff options
author | Luke Kanies <luke@reductivelabs.com> | 2010-03-22 16:31:42 -0700 |
---|---|---|
committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
commit | 68ce086e6b57f67998c52073109e0cca0aee7002 (patch) | |
tree | 80d50162710c6ce9b553b1e44183667426adf2e1 | |
parent | 9919b14f262c994a58eb202cda408f1b90d728e0 (diff) | |
download | puppet-68ce086e6b57f67998c52073109e0cca0aee7002.tar.gz puppet-68ce086e6b57f67998c52073109e0cca0aee7002.tar.xz puppet-68ce086e6b57f67998c52073109e0cca0aee7002.zip |
Changing the method profile of EventManager#queue_event
It now takes multiple events instead of just one. This will
help simplify a bunch of performance optimizations.
Signed-off-by: Luke Kanies <luke@reductivelabs.com>
-rw-r--r-- | lib/puppet/transaction.rb | 4 | ||||
-rw-r--r-- | lib/puppet/transaction/event_manager.rb | 36 | ||||
-rwxr-xr-x | spec/unit/transaction.rb | 5 | ||||
-rwxr-xr-x | spec/unit/transaction/event_manager.rb | 26 |
4 files changed, 36 insertions, 35 deletions
diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index 1b0c470e1..e7d8f63fd 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -42,9 +42,7 @@ class Puppet::Transaction def apply(resource) status = resource_harness.evaluate(resource) add_resource_status(status) - status.events.each do |event| - event_manager.queue_event(resource, event) - end + event_manager.queue_events(resource, status.events) rescue => detail resource.err "Could not evaluate: #{detail}" end diff --git a/lib/puppet/transaction/event_manager.rb b/lib/puppet/transaction/event_manager.rb index aacd17a95..f74927b3c 100644 --- a/lib/puppet/transaction/event_manager.rb +++ b/lib/puppet/transaction/event_manager.rb @@ -22,7 +22,7 @@ class Puppet::Transaction::EventManager end if restarted - queue_event(resource, resource.event(:name => :restarted, :status => "success")) + queue_events(resource, [resource.event(:name => :restarted, :status => "success")]) transaction.resource_status(resource).restarted = true end @@ -30,21 +30,23 @@ class Puppet::Transaction::EventManager # Queue events for other resources to respond to. All of these events have # to be from the same resource. - def queue_event(resource, event) - @events << event - - # 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. - relationship_graph.matching_edges(event, resource).each do |edge| - next unless method = edge.callback - next unless edge.target.respond_to?(method) - - queue_event_for_resource(resource, edge.target, method, event) - end - - if resource.self_refresh? and ! resource.deleting? - queue_event_for_resource(resource, resource, :refresh, event) + def queue_events(resource, events) + @events += events + + events.each do |event| + # 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. + relationship_graph.matching_edges(event, resource).each do |edge| + next unless method = edge.callback + next unless edge.target.respond_to?(method) + + queue_event_for_resource(resource, edge.target, method, event) + end + + if resource.self_refresh? and ! resource.deleting? + queue_event_for_resource(resource, resource, :refresh, event) + end end end @@ -83,7 +85,7 @@ class Puppet::Transaction::EventManager resource.notice "Would have triggered '#{callback}' from #{events.length} events" # And then add an event for it. - queue_event(resource, resource.event(:status => "noop", :name => :noop_restart)) + queue_events(resource, [resource.event(:status => "noop", :name => :noop_restart)]) true # so the 'and if' works end end diff --git a/spec/unit/transaction.rb b/spec/unit/transaction.rb index f0c98db8e..2c8f60589 100755 --- a/spec/unit/transaction.rb +++ b/spec/unit/transaction.rb @@ -146,7 +146,7 @@ describe Puppet::Transaction do @status = Puppet::Resource::Status.new(@resource) @transaction = Puppet::Transaction.new(Puppet::Resource::Catalog.new) - @transaction.event_manager.stubs(:queue_event) + @transaction.event_manager.stubs(:queue_events) @transaction.resource_harness.stubs(:evaluate).returns(@status) end @@ -162,8 +162,7 @@ describe Puppet::Transaction do it "should queue any events added to the resource status" do @status.expects(:events).returns %w{a b} - @transaction.event_manager.expects(:queue_event).with(@resource, "a") - @transaction.event_manager.expects(:queue_event).with(@resource, "b") + @transaction.event_manager.expects(:queue_events).with(@resource, ["a", "b"]) @transaction.apply(@resource) end diff --git a/spec/unit/transaction/event_manager.rb b/spec/unit/transaction/event_manager.rb index 12407c3cc..f808377ee 100755 --- a/spec/unit/transaction/event_manager.rb +++ b/spec/unit/transaction/event_manager.rb @@ -32,10 +32,12 @@ describe Puppet::Transaction::EventManager do @event = Puppet::Transaction::Event.new(:name => :foo, :resource => @resource) end - it "should store each event in its event list" do - @manager.queue_event(@resource, @event) + it "should store all of the events in its event list" do + @event2 = Puppet::Transaction::Event.new(:name => :bar, :resource => @resource) + @manager.queue_events(@resource, [@event, @event2]) @manager.events.should include(@event) + @manager.events.should include(@event2) end it "should queue events for the target and callback of any matching edges" do @@ -47,7 +49,7 @@ describe Puppet::Transaction::EventManager do @manager.expects(:queue_event_for_resource).with(@resource, edge1.target, edge1.callback, @event) @manager.expects(:queue_event_for_resource).with(@resource, edge2.target, edge2.callback, @event) - @manager.queue_event(@resource, @event) + @manager.queue_events(@resource, [@event]) end it "should queue events for the changed resource if the resource is self-refreshing and not being deleted" do @@ -57,7 +59,7 @@ describe Puppet::Transaction::EventManager do @resource.expects(:deleting?).returns false @manager.expects(:queue_event_for_resource).with(@resource, @resource, :refresh, @event) - @manager.queue_event(@resource, @event) + @manager.queue_events(@resource, [@event]) end it "should not queue events for the changed resource if the resource is not self-refreshing" do @@ -67,7 +69,7 @@ describe Puppet::Transaction::EventManager do @resource.stubs(:deleting?).returns false @manager.expects(:queue_event_for_resource).never - @manager.queue_event(@resource, @event) + @manager.queue_events(@resource, [@event]) end it "should not queue events for the changed resource if the resource is being deleted" do @@ -77,7 +79,7 @@ describe Puppet::Transaction::EventManager do @resource.expects(:deleting?).returns true @manager.expects(:queue_event_for_resource).never - @manager.queue_event(@resource, @event) + @manager.queue_events(@resource, [@event]) end it "should ignore edges that don't have a callback" do @@ -87,7 +89,7 @@ describe Puppet::Transaction::EventManager do @manager.expects(:queue_event_for_resource).never - @manager.queue_event(@resource, @event) + @manager.queue_events(@resource, [@event]) end it "should ignore targets that don't respond to the callback" do @@ -97,7 +99,7 @@ describe Puppet::Transaction::EventManager do @manager.expects(:queue_event_for_resource).never - @manager.queue_event(@resource, @event) + @manager.queue_events(@resource, [@event]) end end @@ -136,7 +138,7 @@ describe Puppet::Transaction::EventManager do before do @transaction = Puppet::Transaction.new(Puppet::Resource::Catalog.new) @manager = Puppet::Transaction::EventManager.new(@transaction) - @manager.stubs(:queue_event) + @manager.stubs(:queue_events) @resource = Puppet::Type.type(:file).new :path => "/my/file" @event = Puppet::Transaction::Event.new(:name => :event, :resource => @resource) @@ -167,7 +169,7 @@ describe Puppet::Transaction::EventManager do @resource.stubs(:callback1) @resource.expects(:event).with(:name => :restarted, :status => "success").returns "myevent" - @manager.expects(:queue_event).with(@resource, "myevent") + @manager.expects(:queue_events).with(@resource, ["myevent"]) @manager.process_events(@resource) end @@ -219,7 +221,7 @@ describe Puppet::Transaction::EventManager do it "should queue a new noop event generated from the resource" do event = Puppet::Transaction::Event.new @resource.expects(:event).with(:status => "noop", :name => :noop_restart).returns event - @manager.expects(:queue_event).with(@resource, event) + @manager.expects(:queue_events).with(@resource, [event]) @manager.process_events(@resource) end @@ -245,7 +247,7 @@ describe Puppet::Transaction::EventManager do end it "should not queue a 'restarted' event" do - @manager.expects(:queue_event).never + @manager.expects(:queue_events).never @manager.process_events(@resource) end |