Class: Roadworker::Batch::Operation
- Inherits:
-
Object
- Object
- Roadworker::Batch::Operation
- Includes:
- Log
- Defined in:
- lib/roadworker/batch.rb
Instance Attribute Summary collapse
-
#dry_run ⇒ Object
readonly
Returns the value of attribute dry_run.
-
#health_checks ⇒ Object
readonly
Returns the value of attribute health_checks.
-
#hosted_zone ⇒ Object
readonly
Returns the value of attribute hosted_zone.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#rrset ⇒ Object
readonly
Returns the value of attribute rrset.
Instance Method Summary collapse
- #changes ⇒ Array<Hash>
-
#cname_first? ⇒ Boolean
CNAME should always be created/updated later, as CNAME doesn’t permit other records See also Roadworker::Batch::Delete#cname_first?.
- #desired_rrset ⇒ Hash
- #diff!(dry_run: false) ⇒ Object
-
#initialize(hosted_zone, rrset, health_checks:, dry_run:, logger:) ⇒ Operation
constructor
A new instance of Operation.
- #inspect ⇒ Object
- #present_rrset ⇒ Roadworker::Route53Wrapper::ResourceRecordSetWrapper
- #sort_key ⇒ Object
- #to_s ⇒ Object
-
#value_size ⇒ Integer
Count total length of RR “Value” included in changes See also: Batch#slice_operations.
Methods included from Log
Constructor Details
#initialize(hosted_zone, rrset, health_checks:, dry_run:, logger:) ⇒ Operation
Returns a new instance of Operation.
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_run ⇒ Object (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_checks ⇒ Object (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_zone ⇒ Object (readonly)
Returns the value of attribute hosted_zone.
126 127 128 |
# File 'lib/roadworker/batch.rb', line 126 def hosted_zone @hosted_zone end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
128 129 130 |
# File 'lib/roadworker/batch.rb', line 128 def logger @logger end |
#rrset ⇒ Object (readonly)
Returns the value of attribute rrset.
126 127 128 |
# File 'lib/roadworker/batch.rb', line 126 def rrset @rrset end |
Instance Method Details
#changes ⇒ Array<Hash>
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?
148 149 150 |
# File 'lib/roadworker/batch.rb', line 148 def cname_first? false end |
#desired_rrset ⇒ Hash
172 173 174 |
# File 'lib/roadworker/batch.rb', line 172 def desired_rrset raise NotImplementedError end |
#diff!(dry_run: false) ⇒ Object
181 182 183 |
# File 'lib/roadworker/batch.rb', line 181 def diff!(dry_run: false) raise NotImplementedError end |
#inspect ⇒ Object
185 186 187 |
# File 'lib/roadworker/batch.rb', line 185 def inspect "#<#{self.class.name} @changes=#{changes.inspect}>" end |
#present_rrset ⇒ Roadworker::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_key ⇒ Object
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_s ⇒ Object
189 190 191 |
# File 'lib/roadworker/batch.rb', line 189 def to_s inspect end |
#value_size ⇒ Integer
Count total length of RR “Value” included in changes See also: Batch#slice_operations
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 |