Class: Puppet::Pops::Evaluator::Collectors::ExportedCollector

Inherits:
AbstractCollector show all
Defined in:
lib/puppet/pops/evaluator/collectors/exported_collector.rb

Constant Summary

Constants inherited from AbstractCollector

AbstractCollector::EMPTY_RESOURCES

Instance Attribute Summary

Attributes inherited from AbstractCollector

#collected, #overrides, #scope

Instance Method Summary collapse

Methods inherited from AbstractCollector

#unresolved_resources

Constructor Details

#initialize(scope, type, equery, cquery, overrides = nil) ⇒ ExportedCollector

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)



9
10
11
12
13
14
15
16
# File 'lib/puppet/pops/evaluator/collectors/exported_collector.rb', line 9

def initialize(scope, type, equery, cquery, overrides = nil)
  super(scope, overrides)

  @equery = equery
  @cquery = cquery

  @type = Puppet::Resource.new(type, 'whatever').type
end

Instance Method Details

#collectObject

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



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/puppet/pops/evaluator/collectors/exported_collector.rb', line 30

def collect
  resources = []

  time = Puppet::Util.thinmark do
    t = @type
    q = @cquery

    resources = scope.compiler.resources.find_all do |resource|
      resource.type == t && resource.exported? && (q.nil? || q.call(resource))
    end

    found = Puppet::Resource.indirection.
      search(@type, :host => @scope.compiler.node.name, :filter => @equery, :scope => @scope)

    found_resources = found.map {|x| x.is_a?(Puppet::Parser::Resource) ? x : x.to_resource(@scope)}

    found_resources.each do |item|
      if existing = @scope.findresource(item.resource_type, item.title)
        unless existing.collector_id == item.collector_id
          raise Puppet::ParseError,
            _("A duplicate resource was found while collecting exported resources, with the type and title %{title}") % { title: item.ref }
        end
      else
        item.exported = false
        @scope.compiler.add_resource(@scope, item)
        resources << item
      end
    end
  end

  scope.debug("Collected %s %s resource%s in %.2f seconds" %
              [resources.length, @type, resources.length == 1 ? "" : "s", time])

  resources
end

#evaluateObject

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



20
21
22
23
24
25
26
# File 'lib/puppet/pops/evaluator/collectors/exported_collector.rb', line 20

def evaluate
  if Puppet[:storeconfigs] != true
    return false
  end

  super
end

#to_sObject



66
67
68
# File 'lib/puppet/pops/evaluator/collectors/exported_collector.rb', line 66

def to_s
  "Exported-Collector[#{@type.to_s}]"
end