Skip to content

Commit

Permalink
Raise a more useful exception if target.ems is nil
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Apr 10, 2017
1 parent 48c8a95 commit be1cf3d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
23 changes: 12 additions & 11 deletions app/models/metric/ci_mixin/capture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ def perf_capture_object

delegate :perf_collect_metrics, :to => :perf_capture_object

def queue_name_for_metrics_collection
ems = if self.kind_of?(ExtManagementSystem)
self
elsif respond_to?(:ext_management_system) && ext_management_system.present?
ext_management_system
elsif respond_to?(:old_ext_management_system) && old_ext_management_system.present?
old_ext_management_system
end
raise _("Unsupported type %{name} (id: %{number})") % {:name => self.class.name, :number => id} if ems.nil?
ems.metrics_collector_queue_name
def ems_for_capture_target
if self.kind_of?(ExtManagementSystem)
self
elsif respond_to?(:ext_management_system) && ext_management_system.present?
ext_management_system
elsif respond_to?(:old_ext_management_system) && old_ext_management_system.present?
old_ext_management_system
end
end

def split_capture_intervals(interval_name, start_time, end_time, threshold = 1.day)
Expand All @@ -38,8 +36,11 @@ def perf_capture_queue(interval_name, options = {})
task_id = options[:task_id]
zone = options[:zone] || my_zone
zone = zone.name if zone.respond_to?(:name)
ems = ems_for_capture_target

raise ArgumentError, "invalid interval_name '#{interval_name}'" unless Metric::Capture::VALID_CAPTURE_INTERVALS.include?(interval_name)
raise ArgumentError, "end_time cannot be specified if start_time is nil" if start_time.nil? && !end_time.nil?
raise ArgumentError, "target does not have an ExtManagementSystem" if ems.nil?

start_time = start_time.utc unless start_time.nil?
end_time = end_time.utc unless end_time.nil?
Expand All @@ -65,7 +66,7 @@ def perf_capture_queue(interval_name, options = {})
:class_name => self.class.name,
:instance_id => id,
:role => 'ems_metrics_collector',
:queue_name => queue_name_for_metrics_collection,
:queue_name => ems.metrics_collector_queue_name,
:zone => zone,
:state => ['ready', 'dequeue'],
}
Expand Down
6 changes: 3 additions & 3 deletions spec/models/metric/ci_mixin/capture_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ def parse_datetime(datetime)
group.disconnect_inv
project.disconnect_inv

expect(container.queue_name_for_metrics_collection).to eq ems.metrics_collector_queue_name
expect(group.queue_name_for_metrics_collection).to eq ems.metrics_collector_queue_name
expect(project.queue_name_for_metrics_collection).to eq ems.metrics_collector_queue_name
expect(container.ems_for_capture_target).to eq ems
expect(group.ems_for_capture_target).to eq ems
expect(project.ems_for_capture_target).to eq ems

expect(container.my_zone).to eq ems.my_zone
expect(group.my_zone).to eq ems.my_zone
Expand Down

0 comments on commit be1cf3d

Please sign in to comment.