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

Add MiqWorkerType model #19536

Merged
merged 6 commits into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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: 4 additions & 0 deletions app/models/manageiq/providers/base_manager/event_catcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ def friendly_name
end
end
end

def self.kill_priority
MiqWorkerType::KILL_PRIORITY_EVENT_CATCHERS
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ def self.supports_container?
def self.normalized_type
@normalized_type ||= "ems_metrics_collector_worker"
end

def self.kill_priority
MiqWorkerType::KILL_PRIORITY_METRICS_COLLECTOR_WORKERS
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class ManageIQ::Providers::BaseManager::OperationsWorker < MiqQueueWorkerBase

include PerEmsWorkerMixin

self.required_roles = "ems_operations"
self.required_roles = %w[ems_operations]

def friendly_name
@friendly_name ||= begin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ManageIQ::Providers::BaseManager::RefreshWorker < MiqQueueWorkerBase

# Don't allow multiple refresh workers to run at once
self.include_stopping_workers_on_synchronize = true
self.required_roles = "ems_inventory"
self.required_roles = %w[ems_inventory]

def friendly_name
@friendly_name ||= begin
Expand All @@ -21,4 +21,8 @@ def friendly_name
def self.normalized_type
@normalized_type ||= "ems_refresh_worker"
end

def self.kill_priority
MiqWorkerType::KILL_PRIORITY_REFRESH_WORKERS
end
end
4 changes: 4 additions & 0 deletions app/models/miq_cockpit_ws_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def friendly_name
@friendly_name ||= "Cockpit Worker"
end

def self.kill_priority
MiqWorkerType::KILL_PRIORITY_COCKPIT_WS_WORKERS
end

def self.can_start_cockpit_ws?
@supports_cockpit_ws ||= MiqCockpit::WS.can_start_cockpit_ws?
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/miq_ems_metrics_processor_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ def friendly_name
def self.supports_container?
true
end

def self.kill_priority
MiqWorkerType::KILL_PRIORITY_METRICS_PROCESSOR_WORKERS
end
end
4 changes: 4 additions & 0 deletions app/models/miq_event_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ class MiqEventHandler < MiqQueueWorkerBase
def self.supports_container?
true
end

def self.kill_priority
MiqWorkerType::KILL_PRIORITY_EVENT_HANDLERS
end
end
4 changes: 4 additions & 0 deletions app/models/miq_generic_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ class MiqGenericWorker < MiqQueueWorkerBase
def self.supports_container?
true
end

def self.kill_priority
MiqWorkerType::KILL_PRIORITY_GENERIC_WORKERS
end
end
4 changes: 4 additions & 0 deletions app/models/miq_priority_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ def self.queue_priority
def self.supports_container?
true
end

def self.kill_priority
MiqWorkerType::KILL_PRIORITY_PRIORITY_WORKERS
end
end
4 changes: 4 additions & 0 deletions app/models/miq_remote_console_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ def friendly_name
def self.supports_container?
true
end

def self.kill_priority
MiqWorkerType::KILL_PRIORITY_REMOTE_CONSOLE_WORKERS
end
end
4 changes: 4 additions & 0 deletions app/models/miq_reporting_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ class MiqReportingWorker < MiqQueueWorkerBase
def self.supports_container?
true
end

def self.kill_priority
MiqWorkerType::KILL_PRIORITY_REPORTING_WORKERS
end
end
4 changes: 4 additions & 0 deletions app/models/miq_schedule_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ class MiqScheduleWorker < MiqWorker
def self.supports_container?
true
end

def self.kill_priority
MiqWorkerType::KILL_PRIORITY_SCHEDULE_WORKERS
end
end
7 changes: 3 additions & 4 deletions app/models/miq_server/worker_management/monitor.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module MiqServer::WorkerManagement::Monitor
extend ActiveSupport::Concern

include_concern 'ClassNames'
include_concern 'Kill'
include_concern 'Quiesce'
include_concern 'Reason'
Expand All @@ -25,7 +24,7 @@ def monitor_workers

processed_worker_ids = []

self.class.monitor_class_names.each do |class_name|
MiqWorkerType.worker_class_names.each do |class_name|
processed_worker_ids += check_not_responding(class_name)
processed_worker_ids += check_pending_stop(class_name)
processed_worker_ids += clean_worker_records(class_name)
Expand All @@ -47,7 +46,7 @@ def worker_not_responding(w)

def sync_workers
result = {}
self.class.monitor_class_names.each do |class_name|
MiqWorkerType.worker_class_names.each do |class_name|
begin
c = class_name.constantize
raise NameError, "Constant problem: expected: #{class_name}, constantized: #{c.name}" unless c.name == class_name
Expand Down Expand Up @@ -115,7 +114,7 @@ def monitor_reason_not_responding?(w)
end

def do_system_limit_exceeded
self.class.monitor_class_names_in_kill_order.each do |class_name|
MiqWorkerType.worker_class_names_in_kill_order.each do |class_name|
workers = class_name.constantize.find_current.to_a
next if workers.empty?

Expand Down
20 changes: 0 additions & 20 deletions app/models/miq_server/worker_management/monitor/class_names.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def workers_quiesced?
# do a subset of the monitor_workers loop to allow for graceful exit
heartbeat

self.class.monitor_class_names.each do |class_name|
MiqWorkerType.worker_class_names.each do |class_name|
check_not_responding(class_name)
check_pending_stop(class_name)
clean_worker_records(class_name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module MiqServer::WorkerManagement::Monitor::Settings

def sync_child_worker_settings
@child_worker_settings = {}
self.class.monitor_class_names.each do |class_name|
MiqWorkerType.worker_class_names.each do |class_name|
c = class_name.constantize
@child_worker_settings[c.settings_name] = c.worker_settings
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/miq_server/worker_management/monitor/start.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def wait_for_started_workers
entered_wait_for_started_loop = Time.now.utc
wait_for_started_timeout = @worker_monitor_settings[:wait_for_started_timeout] || 10.minutes
loop do
starting = MiqWorker.find_starting.find_all { |w| self.class.monitor_class_names.include?(w.class.name) }
starting = MiqWorker.find_starting.find_all { |w| MiqWorkerType.worker_class_names.include?(w.class.name) }
if starting.empty?
_log.info("All workers have been started")
break
Expand Down
4 changes: 4 additions & 0 deletions app/models/miq_smart_proxy_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ class MiqSmartProxyWorker < MiqQueueWorkerBase

self.required_roles = ["smartproxy"]
self.default_queue_name = "smartproxy"

def self.kill_priority
MiqWorkerType::KILL_PRIORITY_SMART_PROXY_WORKERS
end
end
8 changes: 8 additions & 0 deletions app/models/miq_ui_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ def self.supports_container?
true
end

def self.bundler_groups
%w[manageiq_default ui_dependencies graphql_api]
end

def self.kill_priority
MiqWorkerType::KILL_PRIORITY_UI_WORKERS
end

def container_port
3001
end
Expand Down
8 changes: 8 additions & 0 deletions app/models/miq_web_service_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,12 @@ def friendly_name
def self.supports_container?
true
end

def self.bundler_groups
%w[manageiq_default graphql_api]
end

def self.kill_priority
MiqWorkerType::KILL_PRIORITY_WEB_SERVICE_WORKERS
end
end
8 changes: 8 additions & 0 deletions app/models/miq_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ class << self
attr_writer :workers
end

def self.bundler_groups
%w[manageiq_default]
end

def self.kill_priority
raise NotImplementedError, ".kill_priority must be implemented in a subclass"
end

def self.workers
return (self.has_minimal_env_option? ? 1 : 0) if MiqServer.minimal_env? && check_for_minimal_role
return 0 unless has_required_role?
Expand Down
54 changes: 54 additions & 0 deletions app/models/miq_worker_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
class MiqWorkerType < ApplicationRecord
EXCLUDED_CLASS_NAMES = %w[ManageIQ::Providers::BaseManager::OperationsWorker].freeze

KILL_PRIORITY_METRICS_PROCESSOR_WORKERS = 10
KILL_PRIORITY_METRICS_COLLECTOR_WORKERS = 20
KILL_PRIORITY_REPORTING_WORKERS = 30
KILL_PRIORITY_SMART_PROXY_WORKERS = 40
KILL_PRIORITY_GENERIC_WORKERS = 50
KILL_PRIORITY_EVENT_HANDLERS = 60
KILL_PRIORITY_REFRESH_WORKERS = 70
KILL_PRIORITY_SCHEDULE_WORKERS = 80
KILL_PRIORITY_PRIORITY_WORKERS = 90
KILL_PRIORITY_WEB_SERVICE_WORKERS = 100
KILL_PRIORITY_REFRESH_CORE_WORKERS = 110
KILL_PRIORITY_VIM_BROKER_WORKERS = 120
KILL_PRIORITY_EVENT_CATCHERS = 130
KILL_PRIORITY_UI_WORKERS = 140
KILL_PRIORITY_REMOTE_CONSOLE_WORKERS = 150
KILL_PRIORITY_COCKPIT_WS_WORKERS = 160

scope :in_kill_order, -> { order(:kill_priority => :asc) }

def self.seed
transaction do
clean_worker_types
classes_for_seed.each { |klass| seed_worker(klass) }
carbonin marked this conversation as resolved.
Show resolved Hide resolved
end
end

def self.worker_class_names
pluck(:worker_type)
end

def self.worker_class_names_in_kill_order
in_kill_order.pluck(:worker_type)
end

private_class_method def self.classes_for_seed
@classes_for_seed ||= MiqWorker.descendants.select { |w| w.subclasses.empty? } - EXCLUDED_CLASS_NAMES.map(&:constantize)
Copy link
Member

@jrafanie jrafanie Nov 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forget, will this autoload all workers in subclasses in external repos such as provider workers?

I wonder what will happen here when/if we dissect bundler groups into small components and therefore won't have all the worker classes. But that's for another day.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it will autoload all the provider subclasses.

If we split out the bundler groups for providers I would imagine the server would need all of the groups to be able to deal with provider constants, right? I don't think any of the workers with pared down bundler groups would be calling this method.

end

private_class_method def self.seed_worker(klass)
instance = find_or_initialize_by(:worker_type => klass.name)

instance.update!(
:bundler_groups => klass.bundler_groups,
:kill_priority => klass.kill_priority
)
end

private_class_method def self.clean_worker_types
where.not(:worker_type => classes_for_seed.map(&:to_s)).destroy_all
end
end
1 change: 1 addition & 0 deletions config/replication_exclude_tables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
- miq_user_roles
- miq_widgets
- miq_widget_contents
- miq_worker_types
- miq_workers
- notifications
- notification_recipients
Expand Down
1 change: 1 addition & 0 deletions lib/evm_database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class EvmDatabase
Zone
MiqServer
ServerRole
MiqWorkerType
Tenant
MiqProductFeature
MiqUserRole
Expand Down
6 changes: 0 additions & 6 deletions lib/generators/manageiq/provider/provider_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ def create_dummy
template "app/models/%plugin_path%/inventory/persister/cloud_manager.rb"
template "app/models/%plugin_path%/inventory/persister.rb"
template "app/models/%plugin_path%/cloud_manager.rb"

inject_into_file Rails.root.join('lib/workers/miq_worker_types.rb'), <<~RB.indent(2), :after => "MIQ_WORKER_TYPES = {\n"
"#{class_name}::CloudManager::EventCatcher" => %i(manageiq_default),
"#{class_name}::CloudManager::MetricsCollectorWorker" => %i(manageiq_default),
"#{class_name}::CloudManager::RefreshWorker" => %i(manageiq_default),
RB
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1000 ❤️ s!!

end

def create_vcr
Expand Down
12 changes: 6 additions & 6 deletions lib/workers/bin/run_single_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,27 @@ def all_role_names
opt_parser.parse!
worker_class = ARGV[0]

require File.expand_path("../miq_worker_types", __dir__)
require File.expand_path("../../../config/environment", __dir__)

if options[:list]
puts ::MIQ_WORKER_TYPES.keys
puts MiqWorkerType.pluck(:worker_type)
exit
end
opt_parser.abort(opt_parser.help) unless worker_class

unless ::MIQ_WORKER_TYPES.keys.include?(worker_class)
worker_type = MiqWorkerType.find_by(:worker_type => worker_class)

unless worker_type
STDERR.puts "ERR: `#{worker_class}` WORKER CLASS NOT FOUND! Please run with `-l` to see possible worker class names."
exit 1
end

# Skip heartbeating with single worker
ENV["DISABLE_MIQ_WORKER_HEARTBEAT"] ||= options[:heartbeat] ? nil : '1'
ENV["BUNDLER_GROUPS"] = MIQ_WORKER_TYPES[worker_class].join(',')
ENV["BUNDLER_GROUPS"] = worker_type.bundler_groups.join(',')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commenting regarding discussion we had in person... because line 63 loads environment which will have already read and used the BUNDLER_GROUPS env var from application.rb here, this manipulation will be too late.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this I moved the bundler groups envvar to the caller of run_single_worker.rb.

The logic was that we would either take the caller's env var if it was set and have some default in this script, but since that exact logic is already taken care of in application.rb, I didn't think it made sense to duplicate it here.

The only thing we lose with this approach is getting the correct bundler groups when someone runs run_single_worker.rb from the command line, but I would argue that if that person wants bundler groups, they will know to set the environment variable.


options[:ems_id] ||= ENV["EMS_ID"]

require File.expand_path("../../../config/environment", __dir__)

if options[:roles].present?
MiqServer.my_server.server_role_names += options[:roles]
MiqServer.my_server.activate_roles(MiqServer.my_server.server_role_names)
Expand Down
Loading