Class: Roadworker::Batch::Operation

Inherits:
Object
  • Object
show all
Includes:
Log
Defined in:
lib/roadworker/batch.rb

Direct Known Subclasses

Create, Delete, Update

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Log

#log

Constructor Details

#initialize(hosted_zone, rrset, health_checks:, dry_run:, logger:) ⇒ Operation

Returns a new instance of Operation.

Parameters:



118
119
120
121
122
123
124
# File 'lib/roadworker/batch.rb', line 118

def initialize(hosted_zone, rrset, health_checks:, dry_run:, logger:)
  @hosted_zone = hosted_zone
  @rrset = rrset
  @health_checks = health_checks
  @dry_run = dry_run
  @logger = logger
end

Instance Attribute Details

#dry_runObject (readonly)

Returns the value of attribute dry_run.



128
129
130
# File 'lib/roadworker/batch.rb', line 128

def dry_run
  @dry_run
end

#health_checksObject (readonly)

Returns the value of attribute health_checks.



127
128
129
# File 'lib/roadworker/batch.rb', line 127

def health_checks
  @health_checks
end

#hosted_zoneObject (readonly)

Returns the value of attribute hosted_zone.



126
127
128
# File 'lib/roadworker/batch.rb', line 126

def hosted_zone
  @hosted_zone
end

#loggerObject (readonly)

Returns the value of attribute logger.



128
129
130
# File 'lib/roadworker/batch.rb', line 128

def logger
  @logger
end

#rrsetObject (readonly)

Returns the value of attribute rrset.



126
127
128
# File 'lib/roadworker/batch.rb', line 126

def rrset
  @rrset
end

Instance Method Details

#changesArray<Hash>

Returns:

  • (Array<Hash>)

Raises:

  • (NotImplementedError)


167
168
169
# File 'lib/roadworker/batch.rb', line 167

def changes
  raise NotImplementedError
end

#cname_first?Boolean

CNAME should always be created/updated later, as CNAME doesn’t permit other records See also Roadworker::Batch::Delete#cname_first?

Returns:

  • (Boolean)


148
149
150
# File 'lib/roadworker/batch.rb', line 148

def cname_first?
  false
end

#desired_rrsetHash

Returns:

  • (Hash)

Raises:

  • (NotImplementedError)


172
173
174
# File 'lib/roadworker/batch.rb', line 172

def desired_rrset
  raise NotImplementedError
end

#diff!(dry_run: false) ⇒ Object

Raises:

  • (NotImplementedError)


181
182
183
# File 'lib/roadworker/batch.rb', line 181

def diff!(dry_run: false)
  raise NotImplementedError
end

#inspectObject



185
186
187
# File 'lib/roadworker/batch.rb', line 185

def inspect
  "#<#{self.class.name} @changes=#{changes.inspect}>"
end

#present_rrsetRoadworker::Route53Wrapper::ResourceRecordSetWrapper



177
178
179
# File 'lib/roadworker/batch.rb', line 177

def present_rrset
  hosted_zone.find_resource_record_set(rrset.name, rrset.type, rrset.set_identifier) or raise "record not present"
end

#sort_keyObject



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/roadworker/batch.rb', line 130

def sort_key
  # See Operation#cname_first?
  cname_precedence = if rrset.type == 'CNAME'
                       cname_first? ? 0 : 2
                     else
                       1
                     end
  # Alias target may be created in the same change batch. Let's do operations for non-alias records first.
  alias_precedence = if rrset.dns_name
                       1
                     else
                       0
                     end
  [rrset.name, cname_precedence, alias_precedence, rrset.type, rrset.set_identifier]
end

#to_sObject



189
190
191
# File 'lib/roadworker/batch.rb', line 189

def to_s
  inspect
end

#value_sizeInteger

Count total length of RR “Value” included in changes See also: Batch#slice_operations

Returns:

  • (Integer)


155
156
157
158
159
160
161
162
163
164
# File 'lib/roadworker/batch.rb', line 155

def value_size
  changes.map do |change|
    upsert_multiplier = change[:action] == 'UPSERT' ? 2 : 1
    rrset = change[:resource_record_set]
    next 0 unless rrset
    rrs = rrset[:resource_records]
    next 0 unless rrs
    (rrs.map { |_| _[:value]&.size || 0 }.sum) * upsert_multiplier
  end.sum || 0
end