Class: Puppet::Transaction::ResourceHarness Private

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

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.

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.

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.



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

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.



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

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.



64
65
66
# File 'lib/puppet/transaction/resource_harness.rb', line 64

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.



59
60
61
# File 'lib/puppet/transaction/resource_harness.rb', line 59

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.



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

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.



48
49
50
51
52
53
54
55
56
# File 'lib/puppet/transaction/resource_harness.rb', line 48

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

  return nil unless name = resource[:schedule]
  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:

  • (Boolean)


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

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

  # 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