Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple Chargeback from ManageIQ/manageiq-consumption since it's not… #19550

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,6 @@ group :smartstate, :manageiq_default do
gem "manageiq-smartstate", "~>0.3.1", :require => false
end

group :consumption, :manageiq_default do
manageiq_plugin "manageiq-consumption"
end

group :ui_dependencies do # Added to Bundler.require in config/application.rb
manageiq_plugin "manageiq-decorators"
manageiq_plugin "manageiq-ui-classic"
Expand Down
50 changes: 1 addition & 49 deletions app/models/chargeback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,7 @@ def self.build_results_for_report_chargeback(options)
chargeback_rates = data[key]["chargeback_rates"].split(', ') + rates_to_apply.collect(&:description)
data[key]["chargeback_rates"] = chargeback_rates.uniq.join(', ')

# we are getting hash with metrics and costs for metrics defined for chargeback
if Settings[:new_chargeback]
data[key].new_chargeback_calculate_costs(consumption, rates_to_apply)
else
data[key].calculate_costs(consumption, rates_to_apply)
end
data[key].calculate_costs(consumption, rates_to_apply)
end
end

Expand Down Expand Up @@ -136,49 +131,6 @@ def showback_category
end
end

def new_chargeback_calculate_costs(consumption, rates)
self.fixed_compute_metric = consumption.chargeback_fields_present if consumption.chargeback_fields_present

rates.each do |rate|
plan = ManageIQ::Showback::PricePlan.find_or_create_by(:description => rate.description,
:name => rate.description,
:resource => MiqEnterprise.first)

data = {}
rate.rate_details_relevant_to(relevant_fields, self.class.attribute_names).each do |r|
r.populate_showback_rate(plan, r, showback_category)
measure = r.chargeable_field.showback_measure
dimension, _, _ = r.chargeable_field.showback_dimension
value = r.chargeable_field.measure(consumption, @options)
data[measure] ||= {}
data[measure][dimension] = [value, r.showback_unit(ChargeableField::UNITS[r.chargeable_field.metric])]
end

# TODO: duration_of_report_step is 30.days for price plans but for consumption history,
# it's used for date ranges and needs to be 1.month with rails 5.1
duration = @options.interval == "monthly" ? 30.days : @options.duration_of_report_step
results = plan.calculate_list_of_costs_input(resource_type: showback_category,
data: data,
start_time: consumption.instance_variable_get("@start_time"),
end_time: consumption.instance_variable_get("@end_time"),
cycle_duration: duration)

results.each do |cost_value, sb_rate|
r = ChargebackRateDetail.find(sb_rate.concept)
metric = r.chargeable_field.metric
metric_index = ChargeableField::VIRTUAL_COL_USES.invert[metric] || metric
metric_value = data[r.chargeable_field.group][metric_index]
metric_field = [r.chargeable_field.group, r.chargeable_field.source, "metric"].join("_")
cost_field = [r.chargeable_field.group, r.chargeable_field.source, "cost"].join("_")
_, total_metric_field, total_field = r.chargeable_field.cost_keys
self[total_field] = (self[total_field].to_f || 0) + cost_value.to_f
self[total_metric_field] = (self[total_metric_field].to_f || 0) + cost_value.to_f
self[cost_field] = cost_value.to_f
self[metric_field] = metric_value.first.to_f
end
end
end

def calculate_fixed_compute_metric(consumption)
return unless consumption.chargeback_fields_present

Expand Down
24 changes: 0 additions & 24 deletions app/models/chargeback_rate_detail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,6 @@ def showback_unit(p_per_unit = nil)
'gbps' => 'Tbps'}[p_per_unit || per_unit]
end

def populate_showback_rate(plan, rate_detail, entity)
group = rate_detail.chargeable_field.showback_measure
field, _, calculation = rate_detail.chargeable_field.showback_dimension
unit = rate_detail.showback_unit

showback_rate = ManageIQ::Showback::Rate.find_or_create_by(:entity => entity,
:group => group,
:field => field,
:price_plan => plan,
:calculation => calculation,
:concept => rate_detail.id)
showback_rate.tiers.destroy_all
rate_detail.chargeback_tiers.each do |tier|
showback_rate.tiers.build(:tier_start_value => tier.start,
:tier_end_value => tier.finish,
:variable_rate_per_time => rate_detail.per_time,
:variable_rate_per_unit => unit,
:fixed_rate_per_time => rate_detail.per_time,
:fixed_rate => Money.new(tier.fixed_rate * Money.default_currency.subunit_to_unit),
:variable_rate => Money.new(tier.variable_rate * Money.default_currency.subunit_to_unit))
end
showback_rate.save
end

def sub_metrics
if metric == 'derived_vm_allocated_disk_storage'
volume_types = CloudVolume.volume_types
Expand Down
1 change: 0 additions & 1 deletion spec/models/chargeback_container_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
ChargebackRateDetailMeasure.seed
ChargeableField.seed
MiqEnterprise.seed
ManageIQ::Showback::InputMeasure.seed

EvmSpecHelper.create_guid_miq_server_zone
@project = FactoryBot.create(:container_project, :name => "my project", :ext_management_system => ems,
Expand Down
1 change: 0 additions & 1 deletion spec/models/chargeback_vm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ def pluck_rollup(metric_rollup_records)
MiqRegion.seed
ChargebackRateDetailMeasure.seed
ChargeableField.seed
ManageIQ::Showback::InputMeasure.seed
MiqEnterprise.seed

EvmSpecHelper.create_guid_miq_server_zone
Expand Down