Skip to content

Commit

Permalink
Instead of array of queue names delegate to parent_manager
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Sep 23, 2020
1 parent 28447d3 commit 387abe2
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 26 deletions.
2 changes: 1 addition & 1 deletion app/models/ems_refresh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions app/models/ext_management_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 0 additions & 11 deletions app/models/manageiq/providers/base_manager/refresh_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/models/manageiq/providers/network_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/models/manageiq/providers/storage_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/miq_queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 0 additions & 12 deletions app/models/miq_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/mixins/per_ems_worker_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 387abe2

Please sign in to comment.