From 387abe2360938a5cd977edd23ebdb021385b2b2d Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Wed, 8 Jul 2020 20:36:12 -0400 Subject: [PATCH] Instead of array of queue names delegate to parent_manager --- app/models/ems_refresh.rb | 2 +- app/models/ext_management_system.rb | 4 ++++ .../providers/base_manager/refresh_worker.rb | 11 ----------- app/models/manageiq/providers/network_manager.rb | 2 ++ app/models/manageiq/providers/storage_manager.rb | 2 ++ app/models/miq_queue.rb | 2 +- app/models/miq_worker.rb | 12 ------------ app/models/mixins/per_ems_worker_mixin.rb | 2 +- 8 files changed, 11 insertions(+), 26 deletions(-) diff --git a/app/models/ems_refresh.rb b/app/models/ems_refresh.rb index 5450e8fa5a6..55f17acc6fe 100644 --- a/app/models/ems_refresh.rb +++ b/app/models/ems_refresh.rb @@ -115,7 +115,7 @@ def self.get_target_objects(target, single_id = nil) def self.queue_merge(targets, ems, create_task = false) queue_options = { - :queue_name => ems.queue_name, + :queue_name => ems.queue_name_for_ems_refresh, :class_name => name, :method_name => 'refresh', :role => "ems_inventory", diff --git a/app/models/ext_management_system.rb b/app/models/ext_management_system.rb index 9474fb2dc34..46457888cc2 100644 --- a/app/models/ext_management_system.rb +++ b/app/models/ext_management_system.rb @@ -693,6 +693,10 @@ def queue_name_for_ems_operations 'generic' end + def queue_name_for_ems_refresh + queue_name + end + def enforce_policy(target, event) inputs = {:ext_management_system => self} inputs[:vm] = target if target.kind_of?(Vm) diff --git a/app/models/manageiq/providers/base_manager/refresh_worker.rb b/app/models/manageiq/providers/base_manager/refresh_worker.rb index e8f340d9581..5752be408c5 100644 --- a/app/models/manageiq/providers/base_manager/refresh_worker.rb +++ b/app/models/manageiq/providers/base_manager/refresh_worker.rb @@ -7,17 +7,6 @@ class ManageIQ::Providers::BaseManager::RefreshWorker < MiqQueueWorkerBase self.include_stopping_workers_on_synchronize = true self.required_roles = %w[ems_inventory] - def self.queue_name_for_ems(ems) - return ems unless ems.kind_of?(ExtManagementSystem) - return ems.queue_name unless ems.child_managers.any? - combined_managers(ems).map(&:queue_name).sort - end - - def self.combined_managers(ems) - [ems].concat(ems.child_managers) - end - private_class_method :combined_managers - def friendly_name @friendly_name ||= begin ems = ext_management_system diff --git a/app/models/manageiq/providers/network_manager.rb b/app/models/manageiq/providers/network_manager.rb index 7bbafb0693b..dd7699ef877 100644 --- a/app/models/manageiq/providers/network_manager.rb +++ b/app/models/manageiq/providers/network_manager.rb @@ -39,6 +39,8 @@ class << model_name :class_name => "ManageIQ::Providers::BaseManager", :autosave => true + delegate :queue_name_for_ems_refresh, :to => :parent_manager + has_many :availability_zones, -> { where.not(:ems_id => nil) }, :primary_key => :parent_ems_id, :foreign_key => :ems_id has_many :flavors, -> { where.not(:ems_id => nil) }, :primary_key => :parent_ems_id, :foreign_key => :ems_id has_many :cloud_tenants, -> { where.not(:ems_id => nil) }, :primary_key => :parent_ems_id, :foreign_key => :ems_id diff --git a/app/models/manageiq/providers/storage_manager.rb b/app/models/manageiq/providers/storage_manager.rb index cb146650844..614e4dfb637 100644 --- a/app/models/manageiq/providers/storage_manager.rb +++ b/app/models/manageiq/providers/storage_manager.rb @@ -16,6 +16,8 @@ class StorageManager < ManageIQ::Providers::BaseManager :class_name => "ManageIQ::Providers::BaseManager", :autosave => true + delegate :queue_name_for_ems_refresh, :to => :parent_manager + def self.display_name(number = 1) n_('Storage Manager', 'Storage Managers', number) end diff --git a/app/models/miq_queue.rb b/app/models/miq_queue.rb index 5bd87986b14..f84ae96ef9e 100644 --- a/app/models/miq_queue.rb +++ b/app/models/miq_queue.rb @@ -208,7 +208,7 @@ def self.submit_job(options) # options[:queue_name] = "generic" options[:role] = service when "ems_inventory" - options[:queue_name] = MiqEmsRefreshWorker.queue_name_for_ems(resource) + options[:queue_name] = resource.queue_name_for_ems_refresh options[:role] = service options[:zone] = resource.my_zone when "ems_operations" diff --git a/app/models/miq_worker.rb b/app/models/miq_worker.rb index 2056e015850..ec8f1b52080 100644 --- a/app/models/miq_worker.rb +++ b/app/models/miq_worker.rb @@ -274,18 +274,6 @@ def self.log_status_all(level = :info) MiqWorker.log_status(level) end - # Overriding queue_name as now some queue names can be - # arrays of names for some workers not just a singular name. - # We use JSON.parse as the array of names is stored as a string. - # This converts it back to a Ruby Array safely. - def queue_name - begin - JSON.parse(self[:queue_name]).sort - rescue JSON::ParserError, TypeError - self[:queue_name] - end - end - def self.containerized_worker? MiqEnvironment::Command.is_podified? end diff --git a/app/models/mixins/per_ems_worker_mixin.rb b/app/models/mixins/per_ems_worker_mixin.rb index 3573ffe444c..c254b9c32aa 100644 --- a/app/models/mixins/per_ems_worker_mixin.rb +++ b/app/models/mixins/per_ems_worker_mixin.rb @@ -115,7 +115,7 @@ def parse_ems_id(queue_name) end def ems_id_from_queue_name(queue_name) - queue_name.kind_of?(Array) ? queue_name.collect { |q| parse_ems_id(q) }.flatten : parse_ems_id(queue_name) + parse_ems_id(queue_name) end def ems_from_queue_name(queue_name)