MMCT TEAM
Server IP : 111.118.215.189  /  Your IP : 18.221.192.226
Web Server : Apache
System : Linux md-in-83.webhostbox.net 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64
User : a1673wkz ( 2475)
PHP Version : 8.2.25
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /usr/share/ruby/vendor_ruby/puppet/pops/evaluator/collectors/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : //usr/share/ruby/vendor_ruby/puppet/pops/evaluator/collectors/exported_collector.rb
class Puppet::Pops::Evaluator::Collectors::ExportedCollector < Puppet::Pops::Evaluator::Collectors::AbstractCollector

  # Creates an ExportedCollector using the AbstractCollector's
  # constructor to set the scope and overrides
  #
  # param [Symbol] 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)
  def initialize(scope, type, equery, cquery, overrides = nil)
    super(scope, overrides)

    @equery = equery
    @cquery = cquery

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

  # Ensures that storeconfigs is present before calling AbstractCollector's
  # evaluate method
  def evaluate
    if Puppet[:storeconfigs] != true
      Puppet.warning "Not collecting exported resources without storeconfigs"
      return false
    end

    super
  end

  # Collect exported resources as defined by an exported
  # collection. Used with PuppetDB
  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.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 #{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
end

MMCT - 2023