diff options
author | Luke Kanies <luke@madstop.com> | 2005-08-18 19:36:47 +0000 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2005-08-18 19:36:47 +0000 |
commit | 4741eeff6bae987c9dfa9e06e2908ae91daa4d16 (patch) | |
tree | bd7ec692c4c2f429f03176cc9e8cfb34f30453cb /lib/puppet/type/component.rb | |
parent | 63309c3b40b7e7f6f46692e0b4b2c780fc806737 (diff) | |
download | puppet-4741eeff6bae987c9dfa9e06e2908ae91daa4d16.tar.gz puppet-4741eeff6bae987c9dfa9e06e2908ae91daa4d16.tar.xz puppet-4741eeff6bae987c9dfa9e06e2908ae91daa4d16.zip |
Execution order is now based on dependency relationships, and those relationships correctly propagate up and descend into components. There is also an event test suite now, along with a (currently simple) component test suite.
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@565 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/type/component.rb')
-rw-r--r-- | lib/puppet/type/component.rb | 52 |
1 files changed, 50 insertions, 2 deletions
diff --git a/lib/puppet/type/component.rb b/lib/puppet/type/component.rb index 2274c7c10..a996bd591 100644 --- a/lib/puppet/type/component.rb +++ b/lib/puppet/type/component.rb @@ -10,6 +10,7 @@ require 'puppet/type' require 'puppet/transaction' module Puppet + class Type class Component < Puppet::Type include Enumerable @@ -19,9 +20,42 @@ module Puppet @states = [] @parameters = [:name,:type] + # topo sort functions + def self.sort(objects) + list = [] + inlist = {} + + objects.each { |obj| + self.recurse(obj, inlist, list) + } + + return list + end + + def self.recurse(obj, inlist, list) + return if list.include?(obj.object_id) + obj.eachdependency { |req| + self.recurse(req, inlist, list) + } + + list << obj + inlist[obj.object_id] = true + end + def each @children.each { |child| yield child } end + + # this returns a sorted array, not a new component, but that suits me just fine + def flatten + self.class.sort(@children.collect { |child| + if child.is_a?(self.class) + child.flatten + else + child + end + }.flatten) + end def initialize(args) @children = [] @@ -31,16 +65,29 @@ module Puppet args[:type] = "component" end super(args) - debug "Made component with name %s and type %s" % [self.name, self[:type]] + Puppet.debug "Made component with name %s and type %s" % + [self.name, self[:type]] end + # the "old" way of doing things # just turn the container into a transaction - def evaluate + def oldevaluate transaction = Puppet::Transaction.new(@children) transaction.component = self return transaction end + # flatten all children, sort them, and evaluate them in order + # this is only called on one component over the whole system + # this also won't work with scheduling, but eh + def evaluate + # but what about dependencies? + + transaction = Puppet::Transaction.new(self.flatten) + transaction.component = self + return transaction + end + def name #return self[:name] return "%s[%s]" % [self[:type],self[:name]] @@ -78,4 +125,5 @@ module Puppet return "component(%s)" % self.name end end + end end |