From 3b740ff7a6ab7127ec5e4935782c33245687c429 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 11 Feb 2008 13:59:25 -0800 Subject: Converting the Compile class to use a Node::Catalog instance as its resource container, instead of having its own behaviour around resource uniqueness. --- lib/puppet/node/catalog.rb | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'lib/puppet/node') diff --git a/lib/puppet/node/catalog.rb b/lib/puppet/node/catalog.rb index 9601309d8..03187cc94 100644 --- a/lib/puppet/node/catalog.rb +++ b/lib/puppet/node/catalog.rb @@ -64,7 +64,7 @@ class Puppet::Node::Catalog < Puppet::PGraph else @resource_table[ref] = resource end - resource.catalog = self unless is_relationship_graph + resource.catalog = self if resource.respond_to?(:catalog=) and ! is_relationship_graph add_vertex!(resource) end end @@ -491,4 +491,28 @@ class Puppet::Node::Catalog < Puppet::PGraph return result end + + # Verify that the given resource isn't defined elsewhere. + def verify_resource_uniqueness(resource) + # Short-curcuit the common case, + unless existing_resource = @resource_table[resource.ref] + return true + end + + # Either it's a defined type, which are never + # isomorphic, or it's a non-isomorphic type, so + # we should throw an exception. + msg = "Duplicate definition: %s is already defined" % resource.ref + + if existing_resource.file and existing_resource.line + msg << " in file %s at line %s" % + [existing_resource.file, existing_resource.line] + end + + if resource.line or resource.file + msg << "; cannot redefine" + end + + raise Puppet::ParseError.new(msg) + end end -- cgit From 6a4cf6c978e8c8aebba4ed0f16d3de7bb31a0ce0 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 11 Feb 2008 17:24:02 -0600 Subject: Fixed #1030 - class and definition evaluation has been significantly refactored, fixing this problem and making the whole interplay between the classes, definitions, and nodes, and the Compile class much cleaner. --- lib/puppet/node/catalog.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/puppet/node') diff --git a/lib/puppet/node/catalog.rb b/lib/puppet/node/catalog.rb index 03187cc94..f93d2786d 100644 --- a/lib/puppet/node/catalog.rb +++ b/lib/puppet/node/catalog.rb @@ -395,6 +395,11 @@ class Puppet::Node::Catalog < Puppet::PGraph nil end + # Does our tag list include this tag? + def tagged?(tag) + @tags.include?(tag) + end + # Return the list of tags. def tags @tags.dup -- cgit From d21416b534eaa5717eca850cfe848716a9b1dc09 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 11 Feb 2008 18:08:15 -0600 Subject: Switching the Node Catalog to using a separate method for validating that a given resource is unique within the catalog. This no longer allows any duplication, even with Execs. --- lib/puppet/node/catalog.rb | 56 ++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 29 deletions(-) (limited to 'lib/puppet/node') diff --git a/lib/puppet/node/catalog.rb b/lib/puppet/node/catalog.rb index f93d2786d..2b9291680 100644 --- a/lib/puppet/node/catalog.rb +++ b/lib/puppet/node/catalog.rb @@ -58,12 +58,12 @@ class Puppet::Node::Catalog < Puppet::PGraph raise ArgumentError, "Can only add objects that respond to :ref" end + fail_unless_unique(resource) + ref = resource.ref - if @resource_table.include?(ref) - raise ArgumentError, "Resource %s is already defined" % ref - else - @resource_table[ref] = resource - end + + @resource_table[ref] = resource + resource.catalog = self if resource.respond_to?(:catalog=) and ! is_relationship_graph add_vertex!(resource) end @@ -452,6 +452,28 @@ class Puppet::Node::Catalog < Puppet::PGraph end end + # Verify that the given resource isn't defined elsewhere. + def fail_unless_unique(resource) + # Short-curcuit the common case, + return unless existing_resource = @resource_table[resource.ref] + + # Either it's a defined type, which are never + # isomorphic, or it's a non-isomorphic type, so + # we should throw an exception. + msg = "Duplicate definition: %s is already defined" % resource.ref + + if existing_resource.file and existing_resource.line + msg << " in file %s at line %s" % + [existing_resource.file, existing_resource.line] + end + + if resource.line or resource.file + msg << "; cannot redefine" + end + + raise ArgumentError.new(msg) + end + # An abstracted method for converting one catalog into another type of catalog. # This pretty much just converts all of the resources from one class to another, using # a conversion method. @@ -496,28 +518,4 @@ class Puppet::Node::Catalog < Puppet::PGraph return result end - - # Verify that the given resource isn't defined elsewhere. - def verify_resource_uniqueness(resource) - # Short-curcuit the common case, - unless existing_resource = @resource_table[resource.ref] - return true - end - - # Either it's a defined type, which are never - # isomorphic, or it's a non-isomorphic type, so - # we should throw an exception. - msg = "Duplicate definition: %s is already defined" % resource.ref - - if existing_resource.file and existing_resource.line - msg << " in file %s at line %s" % - [existing_resource.file, existing_resource.line] - end - - if resource.line or resource.file - msg << "; cannot redefine" - end - - raise Puppet::ParseError.new(msg) - end end -- cgit From cf21ade9abf4541920b535b0e2643b30e44b067b Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 11 Feb 2008 18:15:27 -0600 Subject: Switching the Node catalog to use the Tagging module instead of its own tag methods. --- lib/puppet/node/catalog.rb | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) (limited to 'lib/puppet/node') diff --git a/lib/puppet/node/catalog.rb b/lib/puppet/node/catalog.rb index 2b9291680..96f60b179 100644 --- a/lib/puppet/node/catalog.rb +++ b/lib/puppet/node/catalog.rb @@ -1,5 +1,7 @@ require 'puppet/indirector' +require 'puppet/util/tagging' + # This class models a node catalog. It is the thing # meant to be passed from server to client, and it contains all # of the information in the catalog, including the resources @@ -8,6 +10,8 @@ class Puppet::Node::Catalog < Puppet::PGraph extend Puppet::Indirector indirects :catalog, :terminus_class => :compiler + include Puppet::Util::Tagging + # The host name this is a catalog for. attr_accessor :name @@ -268,7 +272,6 @@ class Puppet::Node::Catalog < Puppet::PGraph super() @name = name if name @extraction_format ||= :transportable - @tags = [] @classes = [] @resource_table = {} @transient_resources = [] @@ -381,30 +384,6 @@ class Puppet::Node::Catalog < Puppet::PGraph @resource_table.keys end - # Add a tag. - def tag(*names) - names.each do |name| - name = name.to_s - @tags << name unless @tags.include?(name) - if name.include?("::") - name.split("::").each do |sub| - @tags << sub unless @tags.include?(sub) - end - end - end - nil - end - - # Does our tag list include this tag? - def tagged?(tag) - @tags.include?(tag) - end - - # Return the list of tags. - def tags - @tags.dup - end - # Convert our catalog into a RAL catalog. def to_ral to_catalog :to_type -- cgit From 8b2fae019b31513becd002eb474e1b4803abde24 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 11 Feb 2008 18:27:49 -0600 Subject: Removing the last remaining vestiges of GRATR -- removing the bangs from 'add_vertex!' and 'add_edge!'. --- lib/puppet/node/catalog.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/puppet/node') diff --git a/lib/puppet/node/catalog.rb b/lib/puppet/node/catalog.rb index 96f60b179..b74947107 100644 --- a/lib/puppet/node/catalog.rb +++ b/lib/puppet/node/catalog.rb @@ -69,7 +69,7 @@ class Puppet::Node::Catalog < Puppet::PGraph @resource_table[ref] = resource resource.catalog = self if resource.respond_to?(:catalog=) and ! is_relationship_graph - add_vertex!(resource) + add_vertex(resource) end end @@ -316,9 +316,9 @@ class Puppet::Node::Catalog < Puppet::PGraph # First create the dependency graph self.vertices.each do |vertex| - @relationship_graph.add_vertex! vertex + @relationship_graph.add_vertex vertex vertex.builddepends.each do |edge| - @relationship_graph.add_edge!(edge) + @relationship_graph.add_edge(edge) end end @@ -328,7 +328,7 @@ class Puppet::Node::Catalog < Puppet::PGraph unless @relationship_graph.edge?(edge.source, edge.target) # don't let automatic relationships conflict with manual ones. unless @relationship_graph.edge?(edge.target, edge.source) vertex.debug "Autorequiring %s" % [edge.source] - @relationship_graph.add_edge!(edge) + @relationship_graph.add_edge(edge) else vertex.debug "Skipping automatic relationship with %s" % (edge.source == vertex ? edge.target : edge.source) end @@ -487,7 +487,7 @@ class Puppet::Node::Catalog < Puppet::PGraph raise Puppet::DevError, "Could not find resource %s when converting %s resources" % [edge.target.ref, message] end - result.add_edge!(source, target, edge.label) + result.add_edge(source, target, edge.label) end map.clear -- cgit From e830f286ee1e657c775871d18340499badc6ef1f Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 18 Feb 2008 17:36:30 -0600 Subject: Fixed #1018 -- resources now have their namevars added as aliases in the resource catalog, just like they were added in the resource classes. --- lib/puppet/node/catalog.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'lib/puppet/node') diff --git a/lib/puppet/node/catalog.rb b/lib/puppet/node/catalog.rb index b74947107..ee4cedd4b 100644 --- a/lib/puppet/node/catalog.rb +++ b/lib/puppet/node/catalog.rb @@ -68,7 +68,11 @@ class Puppet::Node::Catalog < Puppet::PGraph @resource_table[ref] = resource + # If the name and title differ, set up an alias + self.alias(resource, resource.name) if resource.respond_to?(:name) and resource.respond_to?(:title) and resource.name != resource.title + resource.catalog = self if resource.respond_to?(:catalog=) and ! is_relationship_graph + add_vertex(resource) end end @@ -78,7 +82,10 @@ class Puppet::Node::Catalog < Puppet::PGraph resource.ref =~ /^(.+)\[/ newref = "%s[%s]" % [$1 || resource.class.name, name] - raise(ArgumentError, "Cannot alias %s to %s; resource %s already exists" % [resource.ref, name, newref]) if @resource_table[newref] + if existing = @resource_table[newref] + return if existing == resource + raise(ArgumentError, "Cannot alias %s to %s; resource %s already exists" % [resource.ref, name, newref]) + end @resource_table[newref] = resource @aliases[resource.ref] << newref end -- cgit From ff9705914570158d1bad3073728a2e94ca4a0060 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Sat, 23 Feb 2008 19:06:29 -0500 Subject: Somewhat refactored fileserving so that it no longer caches any objects, nor does it use Puppet's RAL resources. In the process, I fixed #894 (you can now copy links) and refactored other classes as necessary. Mostly it was fixing tests. This is a squashed commit of a temporary branch, fwiw, and it also includes any fixes to the tests that were necessary to get all tests passing again. --- lib/puppet/node/catalog.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib/puppet/node') diff --git a/lib/puppet/node/catalog.rb b/lib/puppet/node/catalog.rb index ee4cedd4b..d680de9a0 100644 --- a/lib/puppet/node/catalog.rb +++ b/lib/puppet/node/catalog.rb @@ -1,4 +1,6 @@ require 'puppet/indirector' +require 'puppet/pgraph' +require 'puppet/transaction' require 'puppet/util/tagging' @@ -69,7 +71,10 @@ class Puppet::Node::Catalog < Puppet::PGraph @resource_table[ref] = resource # If the name and title differ, set up an alias - self.alias(resource, resource.name) if resource.respond_to?(:name) and resource.respond_to?(:title) and resource.name != resource.title + #self.alias(resource, resource.name) if resource.respond_to?(:name) and resource.respond_to?(:title) and resource.name != resource.title + if resource.respond_to?(:name) and resource.respond_to?(:title) and resource.name != resource.title + self.alias(resource, resource.name) if resource.class.isomorphic? + end resource.catalog = self if resource.respond_to?(:catalog=) and ! is_relationship_graph @@ -499,7 +504,7 @@ class Puppet::Node::Catalog < Puppet::PGraph map.clear - result.add_class *self.classes + result.add_class(*self.classes) result.tag(*self.tags) return result -- cgit From 125851278d745e443c0598fbb0577b010f824365 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 25 Feb 2008 19:40:44 -0500 Subject: Fixing #1084 -- the node catalog asks the individual resources whether they're isomorphic, and they in turn ask the resource types (or default to true for defined resource types). --- lib/puppet/node/catalog.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet/node') diff --git a/lib/puppet/node/catalog.rb b/lib/puppet/node/catalog.rb index d680de9a0..f885a41ee 100644 --- a/lib/puppet/node/catalog.rb +++ b/lib/puppet/node/catalog.rb @@ -73,7 +73,7 @@ class Puppet::Node::Catalog < Puppet::PGraph # If the name and title differ, set up an alias #self.alias(resource, resource.name) if resource.respond_to?(:name) and resource.respond_to?(:title) and resource.name != resource.title if resource.respond_to?(:name) and resource.respond_to?(:title) and resource.name != resource.title - self.alias(resource, resource.name) if resource.class.isomorphic? + self.alias(resource, resource.name) if resource.isomorphic? end resource.catalog = self if resource.respond_to?(:catalog=) and ! is_relationship_graph -- cgit From 4c0f6c8502a0759519877f3e933e44ba980f7da2 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 6 Mar 2008 13:20:30 -0700 Subject: Fix for 1094 Replace the catalog with the newly created one when converting to ral types. The aliases were being lost because the resources had references to the old catalog being converted --- lib/puppet/node/catalog.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/puppet/node') diff --git a/lib/puppet/node/catalog.rb b/lib/puppet/node/catalog.rb index f885a41ee..ecda472be 100644 --- a/lib/puppet/node/catalog.rb +++ b/lib/puppet/node/catalog.rb @@ -84,6 +84,7 @@ class Puppet::Node::Catalog < Puppet::PGraph # Create an alias for a resource. def alias(resource, name) + #set $1 resource.ref =~ /^(.+)\[/ newref = "%s[%s]" % [$1 || resource.class.name, name] @@ -475,6 +476,15 @@ class Puppet::Node::Catalog < Puppet::PGraph vertices.each do |resource| next if resource.respond_to?(:virtual?) and resource.virtual? + #This is hackity hack for 1094 + #Aliases aren't working in the ral catalog because the current instance of the resource + #has a reference to the catalog being converted. . . So, give it a reference to the new one + #problem solved. . . + if resource.is_a?(Puppet::TransObject) + resource = resource.dup + resource.catalog = result + end + newres = resource.send(convert) # We can't guarantee that resources don't munge their names -- cgit From 18320b8e3271f7d1d1702907be1ff420acfc8d2b Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Fri, 21 Mar 2008 00:39:26 -0500 Subject: Found all instances of methods where split() is used without any local variables and added a local variable -- see http://snurl.com/21zf8. My own testing showed that this caused memory growth to level off at a reasonable level. Note that the link above says the problem is only with class methods, but my own testing showed that it's any method that meets these criteria. This is not a functional change, but should hopefully be the last nail in the coffin of #1131. --- lib/puppet/node/environment.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/puppet/node') diff --git a/lib/puppet/node/environment.rb b/lib/puppet/node/environment.rb index 2a314803f..343720a62 100644 --- a/lib/puppet/node/environment.rb +++ b/lib/puppet/node/environment.rb @@ -4,7 +4,8 @@ class Puppet::Node::Environment # Return the list of valid environments. Just looks them up in # the settings. def self.valid - Puppet.settings.value(:environments).split(",").collect { |e| e.to_sym } + # LAK:NOTE See http://snurl.com/21zf8 [groups_google_com] + x = Puppet.settings.value(:environments).split(",").collect { |e| e.to_sym } end # Is the provided environment valid? -- cgit