class Puppet::Pops::Evaluator::Collectors::ExportedCollector

Public Class Methods

new(scope, type, equery, cquery, overrides = nil) click to toggle source

Creates an ExportedCollector using the AbstractCollector's constructor to set the scope and overrides

param [Puppet::CompilableResourceType] type the resource type to be collected param [Array] equery an array representation of the query (exported query) param [Proc] cquery a proc representation of the query (catalog query)

   # File lib/puppet/pops/evaluator/collectors/exported_collector.rb
10 def initialize(scope, type, equery, cquery, overrides = nil)
11   super(scope, overrides)
12 
13   @equery = equery
14   @cquery = cquery
15 
16   @type = Puppet::Resource.new(type, 'whatever').type
17 end

Public Instance Methods

collect() click to toggle source

Collect exported resources as defined by an exported collection. Used with PuppetDB

   # File lib/puppet/pops/evaluator/collectors/exported_collector.rb
31 def collect
32   resources = []
33 
34   time = Puppet::Util.thinmark do
35     t = @type
36     q = @cquery
37 
38     resources = scope.compiler.resources.find_all do |resource|
39       resource.type == t && resource.exported? && (q.nil? || q.call(resource))
40     end
41 
42     found = Puppet::Resource.indirection.
43       search(@type, :host => @scope.compiler.node.name, :filter => @equery, :scope => @scope)
44 
45     found_resources = found.map {|x| x.is_a?(Puppet::Parser::Resource) ? x : x.to_resource(@scope)}
46 
47     found_resources.each do |item|
48       existing = @scope.findresource(item.resource_type, item.title)
49       if existing
50         unless existing.collector_id == item.collector_id
51           raise Puppet::ParseError,
52             _("A duplicate resource was found while collecting exported resources, with the type and title %{title}") % { title: item.ref }
53         end
54       else
55         item.exported = false
56         @scope.compiler.add_resource(@scope, item)
57         resources << item
58       end
59     end
60   end
61 
62   scope.debug("Collected %s %s resource%s in %.2f seconds" %
63               [resources.length, @type, resources.length == 1 ? "" : "s", time])
64 
65   resources
66 end
evaluate() click to toggle source

Ensures that storeconfigs is present before calling AbstractCollector's evaluate method

   # File lib/puppet/pops/evaluator/collectors/exported_collector.rb
21 def evaluate
22   if Puppet[:storeconfigs] != true
23     return false
24   end
25 
26   super
27 end
to_s() click to toggle source
   # File lib/puppet/pops/evaluator/collectors/exported_collector.rb
68 def to_s
69   "Exported-Collector[#{@type}]"
70 end