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 2 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
130
Fryguy marked this conversation as resolved.
Show resolved Hide resolved
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
20
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
70
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
160
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
10
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
60
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
50
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
90
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
150
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
30
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
80
end
end
11 changes: 2 additions & 9 deletions app/models/miq_server/worker_management/monitor/class_names.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
require "workers/miq_worker_types"

module MiqServer::WorkerManagement::Monitor::ClassNames
extend ActiveSupport::Concern

# This are loaded from `lib/workers/miq_worker_types.rb`, and are just a
# memory reference to them for compatability.
MONITOR_CLASS_NAMES = MIQ_WORKER_TYPES.keys
MONITOR_CLASS_NAMES_IN_KILL_ORDER = MIQ_WORKER_TYPES_IN_KILL_ORDER

module ClassMethods
def monitor_class_names
MONITOR_CLASS_NAMES
MiqWorkerType.pluck(:worker_type)
end

def monitor_class_names_in_kill_order
MONITOR_CLASS_NAMES_IN_KILL_ORDER
MiqWorkerType.in_kill_order.pluck(:worker_type)
end
end
end
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
40
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
140
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
100
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
24 changes: 24 additions & 0 deletions app/models/miq_worker_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class MiqWorkerType < ApplicationRecord
EXCLUDED_CLASS_NAMES = %w[ManageIQ::Providers::BaseManager::OperationsWorker].freeze

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

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

private_class_method def self.classes_for_seed
MiqWorker.descendants.select { |w| w.subclasses.empty? } - EXCLUDED_CLASS_NAMES.map(&:constantize)
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
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