Skip to content

Commit

Permalink
Replace MIQ_WORKER_TYPES constant by using MiqWorkerType model
Browse files Browse the repository at this point in the history
  • Loading branch information
carbonin committed Nov 19, 2019
1 parent ec91eb9 commit 059b777
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 182 deletions.
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
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
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(',')

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
146 changes: 0 additions & 146 deletions lib/workers/miq_worker_types.rb

This file was deleted.

14 changes: 0 additions & 14 deletions spec/lib/workers/miq_worker_types_spec.rb

This file was deleted.

1 change: 1 addition & 0 deletions spec/models/miq_server/worker_monitor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
allow_any_instance_of(MiqServer).to receive(:get_time_threshold).and_return(120)
allow_any_instance_of(MiqServer).to receive(:get_memory_threshold).and_return(100.megabytes)

MiqWorkerType.seed
@miq_server = EvmSpecHelper.local_miq_server
end

Expand Down
3 changes: 2 additions & 1 deletion spec/models/miq_worker/container_common_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
it "no worker deployment names are over 60 characters" do
# OpenShift does not allow deployment names over 63 characters
# We also want to leave some for the ems_id so we compare against 60 to be safe
MIQ_WORKER_TYPES_IN_KILL_ORDER.each do |klass|
MiqWorkerType.seed
MiqWorkerType.pluck(:worker_type).each do |klass|
expect(klass.constantize.new.worker_deployment_name.length).to be <= 60
end
end
Expand Down

0 comments on commit 059b777

Please sign in to comment.