Skip to content

Commit

Permalink
init_extra_fields should depend only on consumption object
Browse files Browse the repository at this point in the history
  • Loading branch information
isimluk committed Dec 16, 2016
1 parent de51196 commit 77d8788
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 30 deletions.
2 changes: 1 addition & 1 deletion app/models/chargeback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def initialize(options, consumption)
classification = self.class.classification_for_perf(metric_rollup_record)
self.tag_name = classification.present? ? classification.description : _('<Empty>')
else
init_extra_fields(metric_rollup_record)
init_extra_fields(consumption)
end
self.start_date, self.end_date, self.display_range = options.report_step_range(consumption.timestamp)
self.interval_name = options.interval
Expand Down
2 changes: 1 addition & 1 deletion app/models/chargeback/consumption.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Chargeback
class Consumption
delegate :timestamp, :resource, :to => :first_metric_rollup_record
delegate :timestamp, :resource, :resource_id, :resource_name, :parent_ems, :to => :first_metric_rollup_record

def initialize(metric_rollup_records, start_time, end_time)
@rollups = metric_rollup_records
Expand Down
25 changes: 13 additions & 12 deletions app/models/chargeback_container_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ def self.default_key(metric_rollup_record, ts_key)
@options[:groupby] == 'project' ? "#{project.id}_#{ts_key}" : "#{project.id}_#{image.id}_#{ts_key}"
end

def self.image(perf)
@data_index.fetch_path(:container_image, :by_container_id, perf.resource_id)
def self.image(consumption)
@data_index.fetch_path(:container_image, :by_container_id, consumption.resource_id)
end

def self.project(perf)
@data_index.fetch_path(:container_project, :by_container_id, perf.resource_id)
def self.project(consumption)
@data_index.fetch_path(:container_project, :by_container_id, consumption.resource_id)
end

def self.where_clause(records, _options)
Expand Down Expand Up @@ -87,13 +87,14 @@ def self.report_col_options

private

def init_extra_fields(perf)
self.project_name = self.class.project(perf).name
self.image_name = self.class.image(perf).try(:full_name) || _('Deleted') # until image archiving is implemented
self.project_uid = self.class.project(perf).ems_ref
self.provider_name = perf.parent_ems.try(:name)
self.provider_uid = perf.parent_ems.try(:guid)
self.archived = self.class.project(perf).archived? ? _('Yes') : _('No')
self.entity = self.class.image(perf)
def init_extra_fields(consumption)
self.project_name = self.class.project(consumption).name
# until image archiving is implemented
self.image_name = self.class.image(consumption).try(:full_name) || _('Deleted')
self.project_uid = self.class.project(consumption).ems_ref
self.provider_name = consumption.parent_ems.try(:name)
self.provider_uid = consumption.parent_ems.try(:guid)
self.archived = self.class.project(consumption).archived? ? _('Yes') : _('No')
self.entity = self.class.image(consumption)
end
end # class ChargebackContainerImage
12 changes: 6 additions & 6 deletions app/models/chargeback_container_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ def self.report_col_options

private

def init_extra_fields(perf)
self.project_name = perf.resource_name
self.project_uid = perf.resource.ems_ref
self.provider_name = perf.parent_ems.try(:name)
self.provider_uid = perf.parent_ems.try(:guid)
self.archived = perf.resource.archived? ? _('Yes') : _('No')
def init_extra_fields(consumption)
self.project_name = consumption.resource_name
self.project_uid = consumption.resource.ems_ref
self.provider_name = consumption.parent_ems.try(:name)
self.provider_uid = consumption.parent_ems.try(:guid)
self.archived = consumption.resource.archived? ? _('Yes') : _('No')
end
end # class Chargeback
20 changes: 10 additions & 10 deletions app/models/chargeback_vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ def self.report_col_options
}
end

def self.vm_owner(perf)
def self.vm_owner(consumption)
@vm_owners ||= vms.each_with_object({}) { |vm, res| res[vm.id] = vm.evm_owner_name }
@vm_owners[perf.resource_id] ||= perf.resource.evm_owner_name
@vm_owners[consumption.resource_id] ||= consumption.resource.evm_owner_name
end

def self.vms
Expand Down Expand Up @@ -134,13 +134,13 @@ def self.vms

private

def init_extra_fields(perf)
self.vm_id = perf.resource_id
self.vm_name = perf.resource_name
self.vm_uid = perf.resource.ems_ref
self.vm_guid = perf.resource.try(:guid)
self.owner_name = self.class.vm_owner(perf)
self.provider_name = perf.parent_ems.try(:name)
self.provider_uid = perf.parent_ems.try(:guid)
def init_extra_fields(consumption)
self.vm_id = consumption.resource_id
self.vm_name = consumption.resource_name
self.vm_uid = consumption.resource.ems_ref
self.vm_guid = consumption.resource.try(:guid)
self.owner_name = self.class.vm_owner(consumption)
self.provider_name = consumption.parent_ems.try(:name)
self.provider_uid = consumption.parent_ems.try(:guid)
end
end # class Chargeback

0 comments on commit 77d8788

Please sign in to comment.