Class: Puppet::Transaction::ResourceHarness Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/puppet/transaction/resource_harness.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

API:

  • private

Defined Under Namespace

Classes: ResourceApplicationContext

Constant Summary collapse

NO_ACTION =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

API:

  • private

Object.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transaction) ⇒ ResourceHarness

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ResourceHarness.

API:

  • private



12
13
14
15
# File 'lib/puppet/transaction/resource_harness.rb', line 12

def initialize(transaction)
  @transaction = transaction
  @persistence = transaction.persistence
end

Instance Attribute Details

#transactionObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



10
11
12
# File 'lib/puppet/transaction/resource_harness.rb', line 10

def transaction
  @transaction
end

Instance Method Details

#cache(resource, name, value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Used mostly for scheduling and auditing at this point.

API:

  • private



67
68
69
# File 'lib/puppet/transaction/resource_harness.rb', line 67

def cache(resource, name, value)
  Puppet::Util::Storage.cache(resource)[name] = value
end

#cached(resource, name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Used mostly for scheduling and auditing at this point.

API:

  • private



62
63
64
# File 'lib/puppet/transaction/resource_harness.rb', line 62

def cached(resource, name)
  Puppet::Util::Storage.cache(resource)[name]
end

#evaluate(resource) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/puppet/transaction/resource_harness.rb', line 17

def evaluate(resource)
  status = Puppet::Resource::Status.new(resource)

  begin
    context = ResourceApplicationContext.from_resource(resource, status)
    perform_changes(resource, context)

    if status.changed? && ! resource.noop?
      cache(resource, :synced, Time.now)
      resource.flush if resource.respond_to?(:flush)
    end
  rescue => detail
    status.failed_because(detail)
  ensure
    status.evaluation_time = Time.now - status.time
  end

  status
end

#schedule(resource) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



50
51
52
53
54
55
56
57
58
59
# File 'lib/puppet/transaction/resource_harness.rb', line 50

def schedule(resource)
  unless resource.catalog
    resource.warning _("Cannot schedule without a schedule-containing catalog")
    return nil
  end

  name = resource[:schedule]
  return nil unless name
  resource.catalog.resource(:schedule, name) || resource.fail(_("Could not find schedule %{name}") % { name: name })
end

#scheduled?(resource) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

API:

  • private



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/puppet/transaction/resource_harness.rb', line 37

def scheduled?(resource)
  return true if Puppet[:ignoreschedules]
  schedule = schedule(resource)
  return true unless schedule

  # We use 'checked' here instead of 'synced' because otherwise we'll
  # end up checking most resources most times, because they will generally
  # have been synced a long time ago (e.g., a file only gets updated
  # once a month on the server and its schedule is daily; the last sync time
  # will have been a month ago, so we'd end up checking every run).
  schedule.match?(cached(resource, :checked).to_i)
end