Class: Puppet::Transaction Private

Inherits:
Object show all
Includes:
Util, Util::Tagging
Defined in:
lib/puppet/transaction.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.

the class that actually walks our resource/property tree, collects the changes, and performs them

Defined Under Namespace

Classes: AdditionalResourceGenerator, Event, EventManager, Report, ResourceHarness

Constant Summary

Constants included from Util::Tagging

Util::Tagging::ValidTagRegex

Constants included from Util

Util::AbsolutePathPosix, Util::AbsolutePathWindows, Util::DEFAULT_POSIX_MODE, Util::DEFAULT_WINDOWS_MODE

Constants included from Util::POSIX

Util::POSIX::LOCALE_ENV_VARS, Util::POSIX::USER_ENV_VARS

Constants included from Util::SymbolicFileMode

Util::SymbolicFileMode::SetGIDBit, Util::SymbolicFileMode::SetUIDBit, Util::SymbolicFileMode::StickyBit, Util::SymbolicFileMode::SymbolicMode, Util::SymbolicFileMode::SymbolicSpecialToBit

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::Tagging

#tag, #tagged?, #tags=

Methods included from Util

absolute_path?, activerecord_version, benchmark, binread, chuser, classproxy, deterministic_rand, execfail, execpipe, execute, exit_on_fail, logmethods, memory, path_to_uri, pretty_backtrace, proxy, replace_file, safe_posix_fork, symbolizehash, thinmark, uri_to_path, which, withenv, withumask

Methods included from Util::POSIX

#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid

Methods included from Util::SymbolicFileMode

#normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?

Constructor Details

#initialize(catalog, report, prioritizer) ⇒ Transaction

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 Transaction.



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

def initialize(catalog, report, prioritizer)
  @catalog = catalog

  @report = report || Puppet::Transaction::Report.new("apply", catalog.version, catalog.environment)

  @prioritizer = prioritizer

  @report.add_times(:config_retrieval, @catalog.retrieval_duration || 0)

  @event_manager = Puppet::Transaction::EventManager.new(self)

  @resource_harness = Puppet::Transaction::ResourceHarness.new(self)

  @prefetched_providers = Hash.new { |h,k| h[k] = {} }
end

Instance Attribute Details

#catalogObject

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.



18
19
20
# File 'lib/puppet/transaction.rb', line 18

def catalog
  @catalog
end

#event_managerObject (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.

Routes and stores any events and subscriptions.



24
25
26
# File 'lib/puppet/transaction.rb', line 24

def event_manager
  @event_manager
end

#for_network_deviceObject

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.



18
19
20
# File 'lib/puppet/transaction.rb', line 18

def for_network_device
  @for_network_device
end

#ignoreschedulesObject

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.



18
19
20
# File 'lib/puppet/transaction.rb', line 18

def ignoreschedules
  @ignoreschedules
end

#prefetched_providersObject (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.



29
30
31
# File 'lib/puppet/transaction.rb', line 29

def prefetched_providers
  @prefetched_providers
end

#reportObject (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.

The report, once generated.



21
22
23
# File 'lib/puppet/transaction.rb', line 21

def report
  @report
end

#resource_harnessObject (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.

Handles most of the actual interacting with resources



27
28
29
# File 'lib/puppet/transaction.rb', line 27

def resource_harness
  @resource_harness
end

Instance Method Details

#any_failed?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.

Are there any failed resources in this transaction?

Returns:

  • (Boolean)


131
132
133
# File 'lib/puppet/transaction.rb', line 131

def any_failed?
  report.resource_statuses.values.detect { |status| status.failed? }
end

#changed?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.

Find all of the changed resources.

Returns:

  • (Boolean)


136
137
138
# File 'lib/puppet/transaction.rb', line 136

def changed?
  report.resource_statuses.values.find_all { |status| status.changed }.collect { |status| catalog.resource(status.resource) }
end

#evaluate(&block) ⇒ 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.

This method does all the actual work of running a transaction. It collects all of the changes, executes them, and responds to any necessary events.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/puppet/transaction.rb', line 53

def evaluate(&block)
  block ||= method(:eval_resource)
  generator = AdditionalResourceGenerator.new(@catalog, relationship_graph, @prioritizer)
  @catalog.vertices.each { |resource| generator.generate_additional_resources(resource) }

  Puppet.info "Applying configuration version '#{catalog.version}'" if catalog.version

  continue_while = lambda { !stop_processing? }

  post_evalable_providers = Set.new
  pre_process = lambda do |resource|
    prov_class = resource.provider.class
    post_evalable_providers << prov_class if prov_class.respond_to?(:post_resource_eval)

    prefetch_if_necessary(resource)

    # If we generated resources, we don't know what they are now
    # blocking, so we opt to recompute it, rather than try to track every
    # change that would affect the number.
    relationship_graph.clear_blockers if generator.eval_generate(resource)
  end

  providerless_types = []
  overly_deferred_resource_handler = lambda do |resource|
    # We don't automatically assign unsuitable providers, so if there
    # is one, it must have been selected by the user.
    if resource.provider
      resource.err "Provider #{resource.provider.class.name} is not functional on this host"
    else
      providerless_types << resource.type
    end

    resource_status(resource).failed = true
  end

  canceled_resource_handler = lambda do |resource|
    resource_status(resource).skipped = true
    resource.debug "Transaction canceled, skipping"
  end

  teardown = lambda do
    # Just once per type. No need to punish the user.
    providerless_types.uniq.each do |type|
      Puppet.err "Could not find a suitable provider for #{type}"
    end

    post_evalable_providers.each do |provider|
      begin
        provider.post_resource_eval
      rescue => detail
        Puppet.log_exception(detail, "post_resource_eval failed for provider #{provider}")
      end
    end
  end

  relationship_graph.traverse(:while => continue_while,
                              :pre_process => pre_process,
                              :overly_deferred_resource_handler => overly_deferred_resource_handler,
                              :canceled_resource_handler => canceled_resource_handler,
                              :teardown => teardown) do |resource|
    if resource.is_a?(Puppet::Type::Component)
      Puppet.warning "Somehow left a component in the relationship graph"
    else
      resource.info "Starting to evaluate the resource" if Puppet[:evaltrace] and @catalog.host_config?
      seconds = thinmark { block.call(resource) }
      resource.info "Evaluated in %0.2f seconds" % seconds if Puppet[:evaltrace] and @catalog.host_config?
    end
  end

  Puppet.debug "Finishing transaction #{object_id}"
end

#prefetch_if_necessary(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.



155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/puppet/transaction.rb', line 155

def prefetch_if_necessary(resource)
  provider_class = resource.provider.class
  return unless provider_class.respond_to?(:prefetch) and !prefetched_providers[resource.type][provider_class.name]

  resources = resources_by_provider(resource.type, provider_class.name)

  if provider_class == resource.class.defaultprovider
    providerless_resources = resources_by_provider(resource.type, nil)
    providerless_resources.values.each {|res| res.provider = provider_class.name}
    resources.merge! providerless_resources
  end

  prefetch(provider_class, resources)
end

#relationship_graphObject

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.



140
141
142
# File 'lib/puppet/transaction.rb', line 140

def relationship_graph
  catalog.relationship_graph(@prioritizer)
end

#resource_status(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.



144
145
146
# File 'lib/puppet/transaction.rb', line 144

def resource_status(resource)
  report.resource_statuses[resource.to_s] || add_resource_status(Puppet::Resource::Status.new(resource))
end

#stop_processing?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.

Wraps application run state check to flag need to interrupt processing

Returns:

  • (Boolean)


126
127
128
# File 'lib/puppet/transaction.rb', line 126

def stop_processing?
  Puppet::Application.stop_requested? && catalog.host_config?
end

#tagsObject

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.

The tags we should be checking.



149
150
151
152
153
# File 'lib/puppet/transaction.rb', line 149

def tags
  self.tags = Puppet[:tags] unless defined?(@tags)

  super
end