diff options
author | John Keiser <john@johnkeiser.com> | 2015-06-30 21:14:28 -0600 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2015-07-06 12:04:47 -0600 |
commit | 591b5599f5412faa382e45d035d76535cd93736a (patch) | |
tree | 3494785822024b7c4acc97adc4883c7a73e2eaaf /lib/chef/resource_resolver.rb | |
parent | cfd2b1fa1b26e8b0aa92a5ba8bd294b96379b2fa (diff) | |
download | chef-591b5599f5412faa382e45d035d76535cd93736a.tar.gz |
Re-separate priority map and DSL handler map so that provides has veto power over priority
Diffstat (limited to 'lib/chef/resource_resolver.rb')
-rw-r--r-- | lib/chef/resource_resolver.rb | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/lib/chef/resource_resolver.rb b/lib/chef/resource_resolver.rb index 2f27e93a3b..47b3df18af 100644 --- a/lib/chef/resource_resolver.rb +++ b/lib/chef/resource_resolver.rb @@ -83,9 +83,9 @@ class Chef # @api private use Chef::ResourceResolver.resolve instead. def resolve # log this so we know what resources will work for the generic resource on the node (early cut) - Chef::Log.debug "Resources for generic #{resource_name} resource enabled on node include: #{enabled_handlers}" + Chef::Log.debug "Resources for generic #{resource_name} resource enabled on node include: #{prioritized_handlers}" - handler = enabled_handlers.first + handler = prioritized_handlers.first if handler Chef::Log.debug "Resource for #{resource_name} is #{handler}" @@ -98,8 +98,8 @@ class Chef # @api private def list - Chef::Log.debug "Resources for generic #{resource_name} resource enabled on node include: #{enabled_handlers}" - enabled_handlers + Chef::Log.debug "Resources for generic #{resource_name} resource enabled on node include: #{prioritized_handlers}" + prioritized_handlers end # @@ -118,7 +118,7 @@ class Chef # # @api private def self.includes_handler?(resource_name, resource_class) - priority_map.includes_handler?(resource_name, resource_class) + handler_map.list(nil, resource_name).include?(resource_class) end protected @@ -127,19 +127,38 @@ class Chef Chef.resource_priority_map end + def self.handler_map + Chef.resource_handler_map + end + def priority_map Chef.resource_priority_map end + def handler_map + Chef.resource_handler_map + end + # @api private def potential_handlers - priority_map.list_handlers(node, resource_name, canonical: canonical) + handler_map.list(node, resource_name, canonical: canonical).uniq end def enabled_handlers potential_handlers.select { |handler| !overrode_provides?(handler) || handler.provides?(node, resource_name) } end + def prioritized_handlers + @prioritized_handlers ||= begin + enabled_handlers = self.enabled_handlers + + prioritized = priority_map.list(node, resource_name, canonical: canonical).flatten(1) + prioritized &= enabled_handlers # Filter the priority map by the actual enabled handlers + prioritized |= enabled_handlers # Bring back any handlers that aren't in the priority map, at the *end* (ordered set) + prioritized + end + end + def overrode_provides?(handler) handler.method(:provides?).owner != Chef::Resource.method(:provides?).owner end @@ -151,17 +170,15 @@ class Chef end def enabled_handlers - @enabled_handlers ||= begin - handlers = super - if handlers.empty? - handlers = resources.select { |handler| overrode_provides?(handler) && handler.provides?(node, resource_name) } - handlers.each do |handler| - Chef::Log.deprecation("#{handler}.provides? returned true when asked if it provides DSL #{resource_name}, but provides #{resource_name.inspect} was never called!") - Chef::Log.deprecation("In Chef 13, this will break: you must call provides to mark the names you provide, even if you also override provides? yourself.") - end + handlers = super + if handlers.empty? + handlers = resources.select { |handler| overrode_provides?(handler) && handler.provides?(node, resource_name) } + handlers.each do |handler| + Chef::Log.deprecation("#{handler}.provides? returned true when asked if it provides DSL #{resource_name}, but provides #{resource_name.inspect} was never called!") + Chef::Log.deprecation("In Chef 13, this will break: you must call provides to mark the names you provide, even if you also override provides? yourself.") end - handlers end + handlers end end prepend Deprecated |