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
 9 def initialize(scope, type, equery, cquery, overrides = nil)
10   super(scope, overrides)
11 
12   @equery = equery
13   @cquery = cquery
14 
15   @type = Puppet::Resource.new(type, 'whatever').type
16 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
30 def collect
31   resources = []
32 
33   time = Puppet::Util.thinmark do
34     t = @type
35     q = @cquery
36 
37     resources = scope.compiler.resources.find_all do |resource|
38       resource.type == t && resource.exported? && (q.nil? || q.call(resource))
39     end
40 
41     found = Puppet::Resource.indirection.
42       search(@type, :host => @scope.compiler.node.name, :filter => @equery, :scope => @scope)
43 
44     found_resources = found.map {|x| x.is_a?(Puppet::Parser::Resource) ? x : x.to_resource(@scope)}
45 
46     found_resources.each do |item|
47       existing = @scope.findresource(item.resource_type, item.title)
48       if existing
49         unless existing.collector_id == item.collector_id
50           raise Puppet::ParseError,
51             _("A duplicate resource was found while collecting exported resources, with the type and title %{title}") % { title: item.ref }
52         end
53       else
54         item.exported = false
55         @scope.compiler.add_resource(@scope, item)
56         resources << item
57       end
58     end
59   end
60 
61   scope.debug("Collected %s %s resource%s in %.2f seconds" %
62               [resources.length, @type, resources.length == 1 ? "" : "s", time])
63 
64   resources
65 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
20 def evaluate
21   if Puppet[:storeconfigs] != true
22     return false
23   end
24 
25   super
26 end
to_s() click to toggle source
   # File lib/puppet/pops/evaluator/collectors/exported_collector.rb
67 def to_s
68   "Exported-Collector[#{@type}]"
69 end