Class: Puppet::Transaction::Event Private

Inherits:
Object
  • Object
show all
Includes:
Network::FormatSupport, Util::Logging, Util::Tagging
Defined in:
lib/puppet/transaction/event.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 simple struct for storing what happens on the system.

Constant Summary collapse

ATTRIBUTES =

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.

[:name, :resource, :property, :previous_value, :desired_value, :historical_value, :status, :message, :file, :line, :source_description, :audited, :invalidate_refreshes, :redacted, :corrective_change]
EVENT_STATUSES =

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.

%w{noop success failure audit}

Constants included from Util::Tagging

Util::Tagging::ValidTagRegex

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Network::FormatSupport

included, #mime, #render, #support_format?, #to_json, #to_msgpack, #to_pson

Methods included from Util::Logging

#clear_deprecation_warnings, #debug, #deprecation_warning, #format_backtrace, #format_exception, #get_deprecation_offender, #log_and_raise, #log_deprecations_to_file, #log_exception, #puppet_deprecation_warning, setup_facter_logging!, #warn_once

Methods included from Util::Tagging

#merge_into, #merge_tags_from, #raw_tagged?, #set_tags, #tag, #tag_if_valid, #tagged?, #tags, #tags=, #valid_tag?

Constructor Details

#initialize(audited: false, corrective_change: false, desired_value: nil, file: nil, historical_value: nil, invalidate_refreshes: nil, line: nil, message: nil, name: nil, previous_value: nil, property: nil, redacted: false, resource: nil, source_description: nil, status: nil, tags: nil) ⇒ Event

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



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/puppet/transaction/event.rb', line 25

def initialize(audited: false,
               corrective_change: false,
               desired_value: nil,
               file: nil,
               historical_value: nil,
               invalidate_refreshes: nil,
               line: nil,
               message: nil,
               name: nil,
               previous_value: nil,
               property: nil,
               redacted: false,
               resource: nil,
               source_description: nil,
               status: nil,
               tags: nil)

  @audited = audited
  @corrective_change = corrective_change
  @desired_value = desired_value
  @file = file
  @historical_value = historical_value
  @invalidate_refreshes = invalidate_refreshes
  @line = line
  @message = message
  @name = name
  @previous_value = previous_value
  @redacted = redacted
  @source_description = source_description
  @tags = tags

  self.property = property if property
  self.resource = resource if resource
  self.status = status if status

  @time = Time.now
end

Instance Attribute Details

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



15
16
17
# File 'lib/puppet/transaction/event.rb', line 15

def default_log_level
  @default_log_level
end

#timeObject

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.



14
15
16
# File 'lib/puppet/transaction/event.rb', line 14

def time
  @time
end

Class Method Details

.from_data_hash(data) ⇒ 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.



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

def self.from_data_hash(data)
  obj = self.allocate
  obj.initialize_from_hash(data)
  obj
end

Instance Method Details

#calculate_corrective_change(old_system_value) ⇒ bool

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.

Calculate and set the corrective_change parameter, based on the old_system_value of the property.

Parameters:

  • old_system_value (Object)

    system_value from last transaction

Returns:

  • (bool)

    true if this is a corrective_change



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/puppet/transaction/event.rb', line 139

def calculate_corrective_change(old_system_value)
  # Only idempotent properties, and cases where we have an old system_value
  # are corrective_changes.
  if @property_instance.idempotent? &&
     !@property_instance.sensitive &&
     !old_system_value.nil?

    # If the values aren't insync, we have confirmed a corrective_change
    insync = @property_instance.insync_values?(old_system_value, previous_value)

    # Preserve the nil state, but flip true/false
    @corrective_change = insync.nil? ? nil : !insync
  else
    @corrective_change = false
  end
end

#eql?(event) ⇒ Boolean Also known as: ==

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)


63
64
65
# File 'lib/puppet/transaction/event.rb', line 63

def eql?(event)
  self.class == event.class && ATTRIBUTES.all? { |attr| send(attr).eql?(event.send(attr)) }
end

#initialize_from_hash(data) ⇒ 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.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/puppet/transaction/event.rb', line 68

def initialize_from_hash(data)
  data = Puppet::Pops::Serialization::FromDataConverter.convert(data, {
    :allow_unresolved => true,
    :loader => Puppet::Pops::Loaders.static_loader
  })
  @audited = data['audited']
  @property = data['property']
  @previous_value = data['previous_value']
  @desired_value = data['desired_value']
  @historical_value = data['historical_value']
  @message = data['message']
  @name = data['name'].intern if data['name']
  @status = data['status']
  @time = data['time']
  @time = Time.parse(@time) if @time.is_a? String
  @redacted = data.fetch('redacted', false)
  @corrective_change = data['corrective_change']
end

#inspectObject

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.



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

def inspect
  %Q(#<#{self.class.name} @name="#{@name.inspect}" @message="#{@message.inspect}">)
end

#property=(prop) ⇒ 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.



106
107
108
109
# File 'lib/puppet/transaction/event.rb', line 106

def property=(prop)
  @property_instance = prop
  @property = prop.to_s
end

#resource=(res) ⇒ 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.



111
112
113
114
115
116
117
# File 'lib/puppet/transaction/event.rb', line 111

def resource=(res)
  level = res[:loglevel] if res.respond_to?(:[])
  if level
    @default_log_level = level
  end
  @resource = res.to_s
end

#send_logObject

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.



119
120
121
# File 'lib/puppet/transaction/event.rb', line 119

def send_log
  super(log_level, message)
end

#status=(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.

Raises:

  • (ArgumentError)


123
124
125
126
# File 'lib/puppet/transaction/event.rb', line 123

def status=(value)
  raise ArgumentError, _("Event status can only be %{statuses}") % { statuses: EVENT_STATUSES.join(', ') } unless EVENT_STATUSES.include?(value)
  @status = value
end

#to_data_hashObject

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.



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/puppet/transaction/event.rb', line 87

def to_data_hash
  hash = {
    'audited' => @audited,
    'property' => @property,
    'previous_value' => @previous_value,
    'desired_value' => @desired_value,
    'historical_value' => @historical_value,
    'message' => @message,
    'name' => @name.nil? ? nil : @name.to_s,
    'status' => @status,
    'time' => @time.iso8601(9),
    'redacted' => @redacted,
    'corrective_change' => @corrective_change,
  }
  # Use the stringifying converter since rich data is not possible downstream.
  # (This will destroy some data type information, but this is expected).
  Puppet::Pops::Serialization::ToStringifiedConverter.convert(hash, :message_prefix => 'Event')
end

#to_sObject

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.



128
129
130
# File 'lib/puppet/transaction/event.rb', line 128

def to_s
  message
end