Class: Puppet::Transaction::Persistence Private

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/transaction/persistence.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.

A persistence store implementation for storing information between transaction runs for the purposes of information inference (such as calculating corrective_change).

Instance Method Summary collapse

Constructor Details

#initializePersistence

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 Persistence


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

def initialize
  @old_data = {}
  @new_data = {"resources" => {}}
end

Instance Method Details

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


43
44
45
46
47
48
49
# File 'lib/puppet/transaction/persistence.rb', line 43

def copy_skipped(resource_name)
  @old_data["resources"] ||= {}
  old_value = @old_data["resources"][resource_name]
  if !old_value.nil?
    @new_data["resources"][resource_name] = old_value
  end
end

#dataHash

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.

Obtain the full raw data from the persistence store.


16
17
18
# File 'lib/puppet/transaction/persistence.rb', line 16

def data
  @old_data
end

#enabled?(catalog) ⇒ 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.

Use the catalog and run_mode to determine if persistence should be enabled or not


96
97
98
# File 'lib/puppet/transaction/persistence.rb', line 96

def enabled?(catalog)
  catalog.host_config? && Puppet.run_mode.name == :agent
end

#get_system_value(resource_name, param_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.

Retrieve the system value using the resource and parameter name


24
25
26
27
28
29
30
31
32
33
# File 'lib/puppet/transaction/persistence.rb', line 24

def get_system_value(resource_name, param_name)
  if !@old_data["resources"].nil? &&
     !@old_data["resources"][resource_name].nil? &&
     !@old_data["resources"][resource_name]["parameters"].nil? &&
     !@old_data["resources"][resource_name]["parameters"][param_name].nil?
    @old_data["resources"][resource_name]["parameters"][param_name]["system_value"]
  else
    nil
  end
end

#loadObject

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.

Load data from the persistence store on disk.


52
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
# File 'lib/puppet/transaction/persistence.rb', line 52

def load
  filename = Puppet[:transactionstorefile]
  unless Puppet::FileSystem.exist?(filename)
    return
  end
  unless File.file?(filename)
    Puppet.warning(_("Transaction store file %{filename} is not a file, ignoring") % { filename: filename })
    return
  end

  result = nil
  Puppet::Util.benchmark(:debug, _("Loaded transaction store file in %{seconds} seconds")) do
    begin
      result = Puppet::Util::Yaml.safe_load_file(filename, [Symbol])
    rescue Puppet::Util::Yaml::YamlLoadError => detail
      Puppet.log_exception(detail, _("Transaction store file %{filename} is corrupt (%{detail}); replacing") % { filename: filename, detail: detail })

      begin
        File.rename(filename, filename + ".bad")
      rescue => detail
        Puppet.log_exception(detail, _("Unable to rename corrupt transaction store file: %{detail}") % { detail: detail })
        raise Puppet::Error, _("Could not rename corrupt transaction store file %{filename}; remove manually") % { filename: filename }, detail.backtrace
      end

      result = {}
    end
  end

  unless result.is_a?(Hash)
    Puppet.err _("Transaction store file %{filename} is valid YAML but not returning a hash. Check the file for corruption, or remove it before continuing.") % { filename: filename }
    return
  end

  @old_data = result
end

#saveObject

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.

Save data from internal class to persistence store on disk.


89
90
91
# File 'lib/puppet/transaction/persistence.rb', line 89

def save
  Puppet::Util::Yaml.dump(@new_data, Puppet[:transactionstorefile])
end

#set_system_value(resource_name, param_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.


35
36
37
38
39
40
41
# File 'lib/puppet/transaction/persistence.rb', line 35

def set_system_value(resource_name, param_name, value)
  @new_data["resources"] ||= {}
  @new_data["resources"][resource_name] ||= {}
  @new_data["resources"][resource_name]["parameters"] ||= {}
  @new_data["resources"][resource_name]["parameters"][param_name] ||= {}
  @new_data["resources"][resource_name]["parameters"][param_name]["system_value"] = value
end