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

#raw_tagged?, #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)


161
162
163
# File 'lib/puppet/transaction.rb', line 161

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)


166
167
168
# File 'lib/puppet/transaction.rb', line 166

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.



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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/puppet/transaction.rb', line 80

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

  perform_pre_run_checks

  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.
    return if missing_tags?(resource)
    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

#perform_pre_run_checksvoid

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 returns an undefined value.

Invoke the pre_run_check hook in every resource in the catalog. This should (only) be called by Transaction#evaluate before applying the catalog.

Raises:

See Also:



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/puppet/transaction.rb', line 58

def perform_pre_run_checks
  prerun_errors = {}

  @catalog.vertices.each do |res|
    begin
      res.pre_run_check
    rescue Puppet::Error => detail
      prerun_errors[res] = detail
    end
  end

  unless prerun_errors.empty?
    prerun_errors.each do |res, detail|
      res.log_exception(detail)
    end
    raise Puppet::Error, "Some pre-run checks failed"
  end
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.



185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/puppet/transaction.rb', line 185

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.



170
171
172
# File 'lib/puppet/transaction.rb', line 170

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.



174
175
176
# File 'lib/puppet/transaction.rb', line 174

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)


156
157
158
# File 'lib/puppet/transaction.rb', line 156

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.



179
180
181
182
183
# File 'lib/puppet/transaction.rb', line 179

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

  super
end