summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorJames Turnbull <james@lovedthanlost.net>2008-07-05 10:21:36 +1000
committerJames Turnbull <james@lovedthanlost.net>2008-07-05 10:21:36 +1000
commit81be1c5c3f85f514505e99fab5b8a2b2ae6fbec8 (patch)
tree192dd042cd69942d2ac803fce86e1b97eb0b3390 /lib/puppet
parent083f4ca7862fbde5cb6fb5562be10f13b66d9250 (diff)
parent9d69b3fd12f90ddead7b6a3392395fbe4e901d9b (diff)
downloadpuppet-81be1c5c3f85f514505e99fab5b8a2b2ae6fbec8.tar.gz
puppet-81be1c5c3f85f514505e99fab5b8a2b2ae6fbec8.tar.xz
puppet-81be1c5c3f85f514505e99fab5b8a2b2ae6fbec8.zip
Merge branch 'refactor/0.24.x/transaction_changes' of git://github.com/lak/puppet into 0.24.x
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/event.rb28
-rw-r--r--lib/puppet/metatype/evaluation.rb4
-rw-r--r--lib/puppet/pgraph.rb2
-rw-r--r--lib/puppet/property.rb1
-rw-r--r--lib/puppet/propertychange.rb141
-rw-r--r--lib/puppet/transaction.rb21
-rw-r--r--lib/puppet/transaction/change.rb94
-rw-r--r--lib/puppet/transaction/event.rb21
-rw-r--r--lib/puppet/type.rb2
-rw-r--r--lib/puppet/type/yumrepo.rb1
10 files changed, 125 insertions, 190 deletions
diff --git a/lib/puppet/event.rb b/lib/puppet/event.rb
deleted file mode 100644
index c1928a354..000000000
--- a/lib/puppet/event.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-require 'puppet'
-require 'puppet/util/methodhelper'
-require 'puppet/util/errors'
-
-module Puppet
- # events are transient packets of information; they result in one or more (or none)
- # subscriptions getting triggered, and then they get cleared
- # eventually, these will be passed on to some central event system
- class Event
- include Puppet
- include Puppet::Util::MethodHelper
- include Puppet::Util::Errors
-
- attr_accessor :event, :source, :transaction
-
- @@events = []
-
- def initialize(args)
- set_options symbolize_options(args)
- requiredopts(:event, :source)
- end
-
- def to_s
- @source.to_s + " -> " + self.event.to_s
- end
- end
-end
-
diff --git a/lib/puppet/metatype/evaluation.rb b/lib/puppet/metatype/evaluation.rb
index ff1eddb55..18bbb812f 100644
--- a/lib/puppet/metatype/evaluation.rb
+++ b/lib/puppet/metatype/evaluation.rb
@@ -139,7 +139,7 @@ class Puppet::Type
end
if ensureparam and ! ensureparam.insync?(currentvalues[ensureparam])
- changes << Puppet::PropertyChange.new(ensureparam, currentvalues[ensureparam])
+ changes << Puppet::Transaction::Change.new(ensureparam, currentvalues[ensureparam])
# Else, if the 'ensure' property is correctly absent, then do
# nothing
elsif ensureparam and currentvalues[ensureparam] == :absent
@@ -149,7 +149,7 @@ class Puppet::Type
currentvalues[property] ||= :absent
! property.insync?(currentvalues[property])
}.collect { |property|
- Puppet::PropertyChange.new(property, currentvalues[property])
+ Puppet::Transaction::Change.new(property, currentvalues[property])
}
end
diff --git a/lib/puppet/pgraph.rb b/lib/puppet/pgraph.rb
index 3bcc2ced0..55ad7d2c1 100644
--- a/lib/puppet/pgraph.rb
+++ b/lib/puppet/pgraph.rb
@@ -58,7 +58,7 @@ class Puppet::PGraph < Puppet::SimpleGraph
# to, which is the same thing as saying all edges directly below
# This vertex in the graph.
adjacent(source, :direction => :out, :type => :edges).find_all do |edge|
- edge.match?(event.event)
+ edge.match?(event.name)
end
end.compact.flatten
end
diff --git a/lib/puppet/property.rb b/lib/puppet/property.rb
index fcaa19d48..9e8bae7a4 100644
--- a/lib/puppet/property.rb
+++ b/lib/puppet/property.rb
@@ -2,7 +2,6 @@
# blocks for actually doing work on the system.
require 'puppet'
-require 'puppet/propertychange'
require 'puppet/parameter'
module Puppet
diff --git a/lib/puppet/propertychange.rb b/lib/puppet/propertychange.rb
deleted file mode 100644
index 35bbede1a..000000000
--- a/lib/puppet/propertychange.rb
+++ /dev/null
@@ -1,141 +0,0 @@
-# the class responsible for actually doing any work
-
-# enables no-op and logging/rollback
-
-module Puppet
- # Handle all of the work around performing an actual change,
- # including calling 'sync' on the properties and producing events.
- class PropertyChange
- attr_accessor :is, :should, :type, :path, :property, :transaction, :changed, :proxy
-
- # The log file generated when this object was changed.
- attr_reader :report
-
- # Switch the goals of the property, thus running the change in reverse.
- def backward
- @property.should = @is
- @is = @property.retrieve
-
- unless defined? @transaction
- raise Puppet::Error,
- "PropertyChange '%s' tried to be executed outside of transaction" %
- self
- end
- unless @property.insync?(@is)
- @property.info "Backing %s" % self
- return self.go
- else
- @property.debug "rollback is already in sync: %s vs. %s" %
- [@is, @property.should.inspect]
- return nil
- end
- end
-
- def changed?
- self.changed
- end
-
- # Create our event object.
- def event(name)
- # default to a simple event type
- unless name.is_a?(Symbol)
- @property.warning("Property '%s' returned invalid event '%s'; resetting to default" %
- [@property.class, name])
-
- event = @property.resource.class.name.id2name + "_changed"
- end
-
- Puppet::Event.new(
- :event => name,
- :transaction => @transaction,
- :source => self.source
- )
- end
-
- def initialize(property, currentvalue)
- unless property.is_a?(Puppet::Property)
- raise Puppet::DevError, "Got a %s instead of a property" %
- property.class
- end
- @property = property
- @path = [property.path,"change"].flatten
- @is = currentvalue
-
- @should = property.should
-
- @changed = false
- end
-
- # Perform the actual change. This method can go either forward or
- # backward, and produces an event.
- def go
- if skip?
- if self.noop
- return [event(:noop)]
- else
- return nil
- end
- end
-
- # The transaction catches any exceptions here.
- events = @property.sync
- if events.nil?
- return nil
- end
-
- if events.is_a?(Array)
- if events.empty?
- return nil
- end
- else
- events = [events]
- end
-
- return events.collect { |name|
- @report = @property.log(@property.change_to_s(@is, @should))
- event(name)
- }
- end
-
- def forward
- #@property.debug "moving change forward"
-
- unless defined? @transaction
- raise Puppet::Error,
- "PropertyChange '%s' tried to be executed outside of transaction" %
- self
- end
-
- return self.go
- end
-
- def noop
- return @property.noop
- end
-
- def skip?
- if @property.insync?(@is)
- @property.info "Already in sync"
- return true
- end
-
- if @property.noop
- @property.log "is %s, should be %s (noop)" %
- [property.is_to_s(@is), property.should_to_s(@should)]
- #@property.debug "%s is noop" % @property
- return true
- end
- return false
- end
-
- def source
- self.proxy || @property.resource
- end
-
- def to_s
- return "change %s.%s(%s)" %
- [@transaction.object_id, self.object_id, @property.change_to_s(@is, @should)]
- #return "change %s.%s" % [@transaction.object_id, self.object_id]
- end
- end
-end
diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb
index b191f8219..f3defb7a2 100644
--- a/lib/puppet/transaction.rb
+++ b/lib/puppet/transaction.rb
@@ -2,10 +2,12 @@
# and performs them
require 'puppet'
-require 'puppet/propertychange'
module Puppet
class Transaction
+ require 'puppet/transaction/change'
+ require 'puppet/transaction/event'
+
attr_accessor :component, :catalog, :ignoreschedules
attr_accessor :sorted_resources, :configurator
@@ -96,7 +98,7 @@ class Transaction
# Create an edge with this resource as both the source and
# target. The triggering method treats these specially for
# logging.
- events = resourceevents.collect { |e| e.event }
+ events = resourceevents.collect { |e| e.name }
set_trigger(Puppet::Relationship.new(resource, resource, :callback => :refresh, :event => events))
end
end
@@ -109,7 +111,6 @@ class Transaction
changes.collect { |change|
@changes << change
@count += 1
- change.transaction = self
events = nil
begin
# use an array, so that changes can return more than one
@@ -278,7 +279,7 @@ class Transaction
# of course, bad.
edge = orig_edge.class.new(orig_edge.source, orig_edge.target)
label = orig_edge.label.dup
- label[:event] = events.collect { |e| e.event }
+ label[:event] = events.collect { |e| e.name }
edge.label = label
set_trigger(edge)
end
@@ -680,11 +681,7 @@ class Transaction
[callback, subs.length]
# And then add an event for it.
- return [Puppet::Event.new(
- :event => :noop,
- :transaction => self,
- :source => resource
- )]
+ return [Puppet::Transaction::Event.new(:noop, resource)]
end
if subs.length == 1 and subs[0].source == resource
@@ -712,11 +709,7 @@ class Transaction
end
# And then add an event for it.
- trigged << Puppet::Event.new(
- :event => :triggered,
- :transaction => self,
- :source => resource
- )
+ trigged << Puppet::Transaction::Event.new(:triggered, resource)
triggered(resource, callback)
end
diff --git a/lib/puppet/transaction/change.rb b/lib/puppet/transaction/change.rb
new file mode 100644
index 000000000..e05c2592c
--- /dev/null
+++ b/lib/puppet/transaction/change.rb
@@ -0,0 +1,94 @@
+require 'puppet/transaction'
+require 'puppet/transaction/event'
+
+# Handle all of the work around performing an actual change,
+# including calling 'sync' on the properties and producing events.
+class Puppet::Transaction::Change
+ attr_accessor :is, :should, :path, :property, :changed, :proxy
+
+ # Switch the goals of the property, thus running the change in reverse.
+ def backward
+ @is, @should = @should, @is
+ @property.should = @should
+
+ @property.info "Reversing %s" % self
+ return self.go
+ end
+
+ def changed?
+ self.changed
+ end
+
+ # Create our event object.
+ def event(name)
+ # default to a simple event type
+ unless name.is_a?(Symbol)
+ @property.warning("Property '%s' returned invalid event '%s'; resetting to default" %
+ [@property.class, name])
+
+ name = @property.event(should)
+ end
+
+ Puppet::Transaction::Event.new(name, self.resource)
+ end
+
+ def initialize(property, currentvalue)
+ @property = property
+ @path = [property.path,"change"].flatten
+ @is = currentvalue
+
+ @should = property.should
+
+ @changed = false
+ end
+
+ # Perform the actual change. This method can go either forward or
+ # backward, and produces an event.
+ def go
+ if self.noop?
+ @property.log "is %s, should be %s (noop)" % [property.is_to_s(@is), property.should_to_s(@should)]
+ return [event(:noop)]
+ end
+
+ # The transaction catches any exceptions here.
+ events = @property.sync
+ if events.nil?
+ return nil
+ end
+
+ if events.is_a?(Array)
+ if events.empty?
+ return nil
+ end
+ else
+ events = [events]
+ end
+
+ return events.collect { |name|
+ @report = @property.log(@property.change_to_s(@is, @should))
+ event(name)
+ }
+ end
+
+ def forward
+ return self.go
+ end
+
+ # Is our property noop? This is used for generating special events.
+ def noop?
+ return @property.noop
+ end
+
+ # The resource that generated this change. This is used for handling events,
+ # and the proxy resource is used for generated resources, since we can't
+ # send an event to a resource we don't have a direct relationship. If we
+ # have a proxy resource, then the events will be considered to be from
+ # that resource, rather than us, so the graph resolution will still work.
+ def resource
+ self.proxy || @property.resource
+ end
+
+ def to_s
+ return "change %s" % @property.change_to_s(@is, @should)
+ end
+end
diff --git a/lib/puppet/transaction/event.rb b/lib/puppet/transaction/event.rb
new file mode 100644
index 000000000..f1a48b382
--- /dev/null
+++ b/lib/puppet/transaction/event.rb
@@ -0,0 +1,21 @@
+require 'puppet'
+require 'puppet/util/methodhelper'
+require 'puppet/util/errors'
+
+# events are transient packets of information; they result in one or more (or none)
+# subscriptions getting triggered, and then they get cleared
+# eventually, these will be passed on to some central event system
+class Puppet::Transaction::Event
+ include Puppet::Util::MethodHelper
+ include Puppet::Util::Errors
+
+ attr_reader :name, :source
+
+ def initialize(name, source)
+ @name, @source = name, source
+ end
+
+ def to_s
+ source.to_s + " -> " + name.to_s
+ end
+end
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index f8949ec90..45dd7f5b5 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -1,6 +1,5 @@
require 'puppet'
require 'puppet/util/log'
-require 'puppet/event'
require 'puppet/util/metric'
require 'puppet/property'
require 'puppet/parameter'
@@ -415,7 +414,6 @@ class Type
end # Puppet::Type
end
-require 'puppet/propertychange'
require 'puppet/provider'
# Always load these types.
diff --git a/lib/puppet/type/yumrepo.rb b/lib/puppet/type/yumrepo.rb
index acb3b9b83..d19b5a470 100644
--- a/lib/puppet/type/yumrepo.rb
+++ b/lib/puppet/type/yumrepo.rb
@@ -1,6 +1,5 @@
# Description of yum repositories
-require 'puppet/propertychange'
require 'puppet/util/inifile'
module Puppet