diff options
author | Luke Kanies <luke@madstop.com> | 2005-06-01 22:20:10 +0000 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2005-06-01 22:20:10 +0000 |
commit | 0dad57a29e84d510a9d530c79b12aa4fba9f334f (patch) | |
tree | ab2cb59d48209d5c00ddddadd1568730a3c31d76 /lib | |
parent | d1f2187c26358288c3a0986b752ffdf5e7b87388 (diff) | |
download | puppet-0dad57a29e84d510a9d530c79b12aa4fba9f334f.tar.gz puppet-0dad57a29e84d510a9d530c79b12aa4fba9f334f.tar.xz puppet-0dad57a29e84d510a9d530c79b12aa4fba9f334f.zip |
md5 summing now works, all the way through!
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@293 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rw-r--r-- | lib/blink/statechange.rb | 11 | ||||
-rw-r--r-- | lib/blink/transaction.rb | 19 | ||||
-rw-r--r-- | lib/blink/type.rb | 46 | ||||
-rw-r--r-- | lib/blink/type/service.rb | 8 |
4 files changed, 62 insertions, 22 deletions
diff --git a/lib/blink/statechange.rb b/lib/blink/statechange.rb index 066f4b7b9..f88108d8a 100644 --- a/lib/blink/statechange.rb +++ b/lib/blink/statechange.rb @@ -35,12 +35,12 @@ module Blink # default to a simple event type if event.nil? - event = @state.parent.name.id2name + "_changed" + event = @state.parent.class.name.id2name + "_changed" elsif ! event.is_a?(Symbol) Blink.notice "State '%s' returned invalid event '%s'; resetting to default" % [@state.class,event] - event = @state.parent.name.id2name + "_changed" + event = @state.parent.class.name.id2name + "_changed" end # i should maybe include object type, but the event type @@ -53,10 +53,15 @@ module Blink ) rescue => detail Blink.error "%s failed: %s" % [self.to_s,detail] + raise # there should be a way to ask the state what type of event # it would have generated, but... + pname = @state.parent.class.name.id2name + #if pname.is_a?(Symbol) + # pname = pname.id2name + #end return Blink::Event.new( - :event => @state.parent.name.id2name + "_failed", + :event => pname + "_failed", :object => @state.parent, :transaction => @transaction, :message => "Failed: " + self.to_s diff --git a/lib/blink/transaction.rb b/lib/blink/transaction.rb index 245c07445..87b2f950c 100644 --- a/lib/blink/transaction.rb +++ b/lib/blink/transaction.rb @@ -52,6 +52,7 @@ class Transaction #@@changed.push change.state.parent rescue => detail Blink.error("%s failed: %s" % [change,detail]) + raise # at this point, we would normally do error handling # but i haven't decided what to do for that yet # so just record that a sync failed for a given object @@ -60,19 +61,25 @@ class Transaction # but a chmod failed? how would i handle that error? dern end - # first handle the subscriptions on individual objects - events.each { |event| - change.state.parent.subscribers?(event).each { |sub| - sub.trigger(self) + if events.nil? + Blink.verbose "No events returned?" + else + # first handle the subscriptions on individual objects + events.each { |event| + change.state.parent.subscribers?(event).each { |sub| + sub.trigger(self) + } } - } + end events elsif change.is_a?(Blink::Transaction) change.evaluate else raise "Transactions cannot handle objects of type %s" % child.class end - }.flatten.each { |event| + }.flatten.reject { |event| + event.nil? + }.each { |event| # this handles subscriptions on the components, rather than # on idividual objects self.component.subscribers?(event).each { |sub| diff --git a/lib/blink/type.rb b/lib/blink/type.rb index 5fd6d6aae..da99aeb45 100644 --- a/lib/blink/type.rb +++ b/lib/blink/type.rb @@ -33,7 +33,7 @@ require 'blink/type/state' module Blink class Type < Blink::Element - attr_accessor :children, :parameters, :parent, :states + attr_accessor :children, :parameters, :parent include Enumerable @@allobjects = Array.new # an array for all objects @@ -562,8 +562,10 @@ class Type < Blink::Element #--------------------------------------------------------------- def retrieve - self.collect { |child| - child.retrieve + # it's important to use the method here, so we always get + # them back in the right order + self.states.collect { |state| + state.retrieve } end #--------------------------------------------------------------- @@ -572,6 +574,8 @@ class Type < Blink::Element def sync self.collect { |child| child.sync + }.reject { |event| + ! (event.is_a?(Symbol) or event.is_a?(String)) }.flatten end #--------------------------------------------------------------- @@ -589,7 +593,7 @@ class Type < Blink::Element #--------------------------------------------------------------- #--------------------------------------------------------------- - def eachstate + def states Blink.debug "%s has %s states" % [self,@states.length] tmpstates = [] self.class.states.each { |state| @@ -600,7 +604,13 @@ class Type < Blink::Element unless tmpstates.length == @states.length raise "Something went very wrong with tmpstates creation" end - tmpstates.each { |state| + return tmpstates + end + #--------------------------------------------------------------- + + #--------------------------------------------------------------- + def eachstate + self.states.each { |state| yield state } end @@ -660,11 +670,25 @@ class Type < Blink::Element end @evalcount += 1 - # collect changes and return them - # these changes could be from child objects or from contained states - self.collect { |child| + changes = @children.collect { |child| child.evaluate } + + # this only operates on states, not states + children + self.retrieve + unless self.insync? + changes << self.states.find_all { |state| + ! state.insync? + }.collect { |state| + Blink::StateChange.new(state) + } + end + # collect changes and return them + # these changes could be from child objects or from contained states + #self.collect { |child| + # child.evaluate + #} + return changes end #--------------------------------------------------------------- @@ -673,9 +697,9 @@ class Type < Blink::Element def insync? insync = true - self.each { |obj| - unless obj.insync? - Blink.debug("%s is not in sync" % obj) + self.states.each { |state| + unless state.insync? + Blink.debug("%s is not in sync" % state) insync = false end } diff --git a/lib/blink/type/service.rb b/lib/blink/type/service.rb index a4c822fc8..f17f17e3f 100644 --- a/lib/blink/type/service.rb +++ b/lib/blink/type/service.rb @@ -12,6 +12,7 @@ module Blink class State class ServiceRunning < State @name = :running + #@event = :file_created # this whole thing is annoying # i should probably just be using booleans, but for now, i'm not... @@ -61,11 +62,12 @@ module Blink end Blink.debug "'%s' status is '%s' and should be '%s'" % [self,status,should] + event = nil if self.should > 0 if status < 1 Blink.debug "Starting '%s'" % self if self.parent.initcmd("start") - return :service_started + event = :service_started else raise "Failed to start '%s'" % self.parent.name end @@ -79,13 +81,15 @@ module Blink elsif status > 0 Blink.debug "Stopping '%s'" % self if self.parent.initcmd("stop") - return :service_stopped + event = :service_stopped else raise "Failed to stop %s" % self.name end else Blink.debug "Not running '%s' and shouldn't be running" % self end + + return event end end end |