Skip to content

Commit

Permalink
Merge pull request #13960 from isimluk/extract-chargeback-field-6-sto…
Browse files Browse the repository at this point in the history
…p-seeding-it

Extract chargeable field [6/8] -- stop seeding the stuff
  • Loading branch information
gtanzillo authored Apr 3, 2017
2 parents fa30988 + 5780743 commit ca98821
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 66 deletions.
8 changes: 1 addition & 7 deletions app/models/chargeback_rate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,10 @@ def self.seed
rec = find_by(:guid => cbr[:guid])
rates = cbr.delete(:rates)

# The yml measure field is the name of the measure. It's changed to the id
rates.each do |rate_detail|
measure = ChargebackRateDetailMeasure.find_by(:name => rate_detail.delete(:measure))
currency = ChargebackRateDetailCurrency.find_by(:name => rate_detail.delete(:type_currency))
metric = rate_detail[:metric] || "#{rate_detail[:group]}_#{rate_detail[:source]}"
field = ChargeableField.find_by(:metric => metric)
field = ChargeableField.find_by(:metric => rate_detail.delete(:metric))
rate_detail[:chargeable_field_id] = field.id
unless measure.nil?
rate_detail[:chargeback_rate_detail_measure_id] = measure.id
end
if currency
rate_detail[:chargeback_rate_detail_currency_id] = currency.id
end
Expand Down
4 changes: 1 addition & 3 deletions app/models/chargeback_rate_detail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,9 @@ def self.default_rate_details_for(rate_type)

chargeback_rate[:rates].each do |detail|
detail_new = ChargebackRateDetail.new(detail.slice(*ChargebackRateDetail::FORM_ATTRIBUTES))
detail_new.detail_measure = ChargebackRateDetailMeasure.find_by(:name => detail[:measure])
detail_new.detail_currency = ChargebackRateDetailCurrency.find_by(:name => detail[:type_currency])
detail_new.metric = detail[:metric]
chargeable_metric = detail[:metric] || "#{detail[:group]}_#{detail[:source]}"
detail_new.chargeable_field = ChargeableField.find_by(:metric => chargeable_metric)
detail_new.chargeable_field = ChargeableField.find_by(:metric => detail.delete(:metric))

detail[:tiers].sort_by { |tier| tier[:start] }.each do |tier|
detail_new.chargeback_tiers << ChargebackTier.new(tier.slice(*ChargebackTier::FORM_ATTRIBUTES))
Expand Down
62 changes: 6 additions & 56 deletions db/fixtures/chargeback_rates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,16 @@
:default: true
:rates:
- :description: Used CPU
:group: cpu
:source: used
:metric: cpu_usagemhz_rate_average
:per_time: hourly
:per_unit: megahertz
:measure: Hz Units
:type_currency: Dollars
:tiers:
- :start: 0
:finish: Infinity
:fixed_rate: 0.0
:variable_rate: 0.02
- :description: Used CPU Cores
:group: cpu_cores
:source: used
:metric: v_derived_cpu_total_cores_used
:per_time: hourly
:per_unit: cpu core
Expand All @@ -30,8 +25,6 @@
:fixed_rate: 1.0
:variable_rate: 0.02
- :description: Allocated CPU Count
:group: cpu
:source: allocated
:metric: derived_vm_numvcpus
:per_time: hourly
:per_unit: cpu
Expand All @@ -42,38 +35,29 @@
:fixed_rate: 1.0
:variable_rate: 0.0
- :description: Used Memory
:group: memory
:source: used
:metric: derived_memory_used
:per_time: hourly
:per_unit: megabytes
:measure: Bytes Units
:type_currency: Dollars
:tiers:
- :start: 0
:finish: Infinity
:fixed_rate: 0.0
:variable_rate: 0.02
- :description: Allocated Memory
:group: memory
:source: allocated
:metric: derived_memory_available
:per_time: hourly
:per_unit: megabytes
:measure: Bytes Units
:type_currency: Dollars
:tiers:
- :start: 0
:finish: Infinity
:fixed_rate: 0.0
:variable_rate: 0.0
- :description: Used Network I/O
:group: net_io
:source: used
:metric: net_usage_rate_average
:per_time: hourly
:per_unit: kbps
:measure: Bytes per Second Units
:type_currency: Dollars
:tiers:
- :start: 0
Expand All @@ -85,21 +69,17 @@
:fixed_rate: 0.5
:variable_rate: 0.005
- :description: Used Disk I/O
:group: disk_io
:source: used
:metric: disk_usage_rate_average
:per_time: hourly
:per_unit: kbps
:measure: Bytes per Second Units
:type_currency: Dollars
:tiers:
- :start: 0
:finish: Infinity
:fixed_rate: 0.0
:variable_rate: 0.005
- :description: Fixed Compute Cost 1
:group: fixed
:source: compute_1
:metric: fixed_compute_1
:per_time: hourly
:type_currency: Dollars
:tiers:
Expand All @@ -108,8 +88,7 @@
:fixed_rate: 0.0
:variable_rate: 0.0
- :description: Fixed Compute Cost 2
:group: fixed
:source: compute_2
:metric: fixed_compute_2
:per_time: hourly
:type_currency: Dollars
:tiers:
Expand All @@ -123,34 +102,27 @@
:default: true
:rates:
- :description: Allocated Disk Storage
:group: storage
:source: allocated
:metric: derived_vm_allocated_disk_storage
:per_time: hourly
:per_unit: gigabytes
:measure: Bytes Units
:type_currency: Dollars
:tiers:
- :start: 0
:finish: Infinity
:fixed_rate: 1.0
:variable_rate: 0.0
- :description: Used Disk Storage
:group: storage
:source: used
:metric: derived_vm_used_disk_storage
:per_time: hourly
:per_unit: gigabytes
:measure: Bytes Units
:type_currency: Dollars
:tiers:
- :start: 0
:finish: Infinity
:fixed_rate: 0.0
:variable_rate: 2.0
- :description: Fixed Storage Cost 1
:group: fixed
:source: storage_1
:metric: fixed_storage_1
:per_time: hourly
:type_currency: Dollars
:tiers:
Expand All @@ -159,8 +131,7 @@
:fixed_rate: 0.0
:variable_rate: 0.0
- :description: Fixed Storage Cost 2
:group: fixed
:source: storage_2
:metric: fixed_storage_2
:per_time: hourly
:type_currency: Dollars
:tiers:
Expand All @@ -174,21 +145,16 @@
:default: false
:rates:
- :description: Used CPU
:group: cpu
:source: used
:metric: cpu_usagemhz_rate_average
:per_time: hourly
:per_unit: megahertz
:measure: Hz Units
:type_currency: Dollars
:tiers:
- :start: 0
:finish: Infinity
:fixed_rate: 0.0
:variable_rate: 0.02
- :description: Used CPU Cores
:group: cpu_cores
:source: used
:metric: v_derived_cpu_total_cores_used
:per_time: hourly
:per_unit: cpu core
Expand All @@ -199,8 +165,6 @@
:fixed_rate: 1.0
:variable_rate: 0.02
- :description: Allocated CPU Count
:group: cpu
:source: allocated
:metric: derived_vm_numvcpus
:per_time: hourly
:per_unit: cpu
Expand All @@ -211,38 +175,29 @@
:fixed_rate: 1.0
:variable_rate: 0.0
- :description: Used Memory
:group: memory
:source: used
:metric: derived_memory_used
:per_time: hourly
:per_unit: megabytes
:measure: Bytes Units
:type_currency: Dollars
:tiers:
- :start: 0
:finish: Infinity
:fixed_rate: 0.0
:variable_rate: 0.02
- :description: Allocated Memory
:group: memory
:source: allocated
:metric: derived_memory_available
:per_time: hourly
:per_unit: megabytes
:measure: Bytes Units
:type_currency: Dollars
:tiers:
- :start: 0
:finish: Infinity
:fixed_rate: 0.0
:variable_rate: 0.0
- :description: Used Network I/O
:group: net_io
:source: used
:metric: net_usage_rate_average
:per_time: hourly
:per_unit: kbps
:measure: Bytes per Second Units
:type_currency: Dollars
:tiers:
- :start: 0
Expand All @@ -254,21 +209,17 @@
:fixed_rate: 0.5
:variable_rate: 0.005
- :description: Used Disk I/O
:group: disk_io
:source: used
:metric: disk_usage_rate_average
:per_time: hourly
:per_unit: kbps
:measure: Bytes per Second Units
:type_currency: Dollars
:tiers:
- :start: 0
:finish: Infinity
:fixed_rate: 0.0
:variable_rate: 0.005
- :description: Fixed Compute Cost 1
:group: fixed
:source: compute_1
:metric: fixed_compute_1
:per_time: hourly
:type_currency: Dollars
:tiers:
Expand All @@ -277,8 +228,7 @@
:fixed_rate: 0.0
:variable_rate: 0.0
- :description: Fixed Compute Cost 2
:group: fixed
:source: compute_2
:metric: fixed_compute_2
:per_time: hourly
:type_currency: Dollars
:tiers:
Expand Down

0 comments on commit ca98821

Please sign in to comment.