Skip to content

Commit

Permalink
Merge pull request #15597 from gtanzillo/rearch-combine-config-and-ro…
Browse files Browse the repository at this point in the history
…les-messages

[Rearch] Combine worker messages 'sync_config' and sync_active_role' into a single 'sync_config' message.
  • Loading branch information
Fryguy authored Aug 1, 2017
2 parents eb5e8c9 + c801bdb commit 9dd6d3b
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 73 deletions.
17 changes: 1 addition & 16 deletions app/models/miq_server/worker_management/heartbeat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,10 @@ def worker_heartbeat(worker_pid, worker_class = nil, queue_name = nil)
h[:queue_name] ||= queue_name
end unless @workers_lock.nil?

# Special process the sync_ messages to send the current values of what to synchronize
messages.collect do |message, *args|
case message
when "sync_active_roles"
[message, {:roles => @active_role_names}]
else
[message, *args]
end
end
messages
end

def worker_set_message(w, message, *args)
# Special process for this compound message, by breaking it up into 2 simpler messages
if message == 'sync_active_roles_and_config'
worker_set_message(w, 'sync_active_roles')
worker_set_message(w, 'sync_config')
return
end

_log.info("#{w.format_full_log_msg} is being requested to #{message}")
@workers_lock.synchronize(:EX) do
worker_add_message(w.pid, [message, *args]) if @workers.key?(w.pid)
Expand Down
8 changes: 1 addition & 7 deletions app/models/miq_server/worker_management/monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,7 @@ def sync_needed?

if resync_needed
@last_sync = Time.now.utc
if (config_changed && roles_changed) || sync_interval_reached
sync_message = "sync_active_roles_and_config"
elsif config_changed
sync_message = "sync_config"
else
sync_message = "sync_active_roles"
end
sync_message = "sync_config"

sync_config if config_changed
sync_assigned_roles if config_changed
Expand Down
24 changes: 9 additions & 15 deletions app/models/miq_worker/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def worker_initialization
starting_worker_record
set_process_title
# Sync the config and roles early since heartbeats and logging require the configuration
sync_active_roles
sync_config

set_connection_pool_size
Expand Down Expand Up @@ -267,30 +266,30 @@ def message_restarted(*_args)
# just consume the restarted message
end

def message_sync_active_roles(*args)
_log.info("#{log_prefix} Synchronizing active roles...")
opts = args.extract_options!
sync_active_roles(opts[:roles])
_log.info("#{log_prefix} Synchronizing active roles complete...")
end

def message_sync_config(*_args)
_log.info("#{log_prefix} Synchronizing configuration...")
sync_config
_log.info("#{log_prefix} Synchronizing configuration complete...")
end

def sync_config
# Sync roles
@active_roles = MiqServer.my_active_roles(true)
after_sync_active_roles

# Sync settings
Vmdb::Settings.reload!
@my_zone ||= MiqServer.my_zone
sync_log_level
sync_worker_settings
sync_blacklisted_events
_log.info("ID [#{@worker.id}], PID [#{@worker.pid}], GUID [#{@worker.guid}], Zone [#{@my_zone}], Active Roles [#{@active_roles.join(',')}], Assigned Roles [#{MiqServer.my_role}], Configuration:")
after_sync_config

_log.info("ID [#{@worker.id}], PID [#{Process.pid}], GUID [#{@worker.guid}], Zone [#{@my_zone}], Active Roles [#{@active_roles.join(',')}], Assigned Roles [#{MiqServer.my_role}], Configuration:")
$log.log_hashes(@worker_settings)
$log.info("---")
$log.log_hashes(@cfg)
after_sync_config

@worker.release_db_connection if @worker.respond_to?(:release_db_connection)
end

Expand All @@ -305,11 +304,6 @@ def sync_worker_settings
poll_method
end

def sync_active_roles(role_names = nil)
@active_roles = role_names || MiqServer.my_active_roles(true)
after_sync_active_roles
end

#
# Work methods
#
Expand Down
1 change: 0 additions & 1 deletion spec/models/miq_ems_refresh_core_worker/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

# General stubbing for testing any worker (methods called during initialize)
@worker_record = FactoryGirl.create(:miq_ems_refresh_core_worker, :queue_name => "ems_#{@ems.id}", :miq_server => server)
allow_any_instance_of(described_class).to receive(:sync_active_roles)
allow_any_instance_of(described_class).to receive(:sync_config)
allow_any_instance_of(described_class).to receive(:set_connection_pool_size)
allow_any_instance_of(described_class).to receive(:heartbeat_using_drb?).and_return(false)
Expand Down
1 change: 0 additions & 1 deletion spec/models/miq_queue_worker_base/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
let(:server) { EvmSpecHelper.local_miq_server }
let(:worker) { FactoryGirl.create(:miq_generic_worker, :miq_server => server, :pid => 123) }
let(:runner) do
allow_any_instance_of(MiqQueueWorkerBase::Runner).to receive(:sync_active_roles)
allow_any_instance_of(MiqQueueWorkerBase::Runner).to receive(:sync_config)
allow_any_instance_of(MiqQueueWorkerBase::Runner).to receive(:set_connection_pool_size)
described_class.new(:guid => worker.guid)
Expand Down
1 change: 0 additions & 1 deletion spec/models/miq_schedule_worker/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
@worker = FactoryGirl.create(:miq_schedule_worker, :guid => worker_guid, :miq_server_id => @miq_server.id)

allow_any_instance_of(MiqScheduleWorker::Runner).to receive(:initialize_rufus)
allow_any_instance_of(MiqScheduleWorker::Runner).to receive(:sync_active_roles)
allow_any_instance_of(MiqScheduleWorker::Runner).to receive(:sync_config)
allow_any_instance_of(MiqScheduleWorker::Runner).to receive(:set_connection_pool_size)

Expand Down
31 changes: 0 additions & 31 deletions spec/models/miq_server/worker_monitor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -288,37 +288,6 @@
end
end

context "when server has a single sync_active_roles message" do
before(:each) do
@miq_server.message_for_worker(@worker1.id, "sync_active_roles")
end

it "should return proper message on heartbeat via drb" do
expect(@miq_server.worker_heartbeat(@worker1.pid)).to eq([['sync_active_roles', {:roles => nil}]])
end
end

context "#stop_worker followed by a single sync_active_roles_and_config message" do
before(:each) do
@miq_server.stop_worker(@worker1)
@miq_server.message_for_worker(@worker1.id, "sync_active_roles_and_config")
end

it "exit message followed by active_roles and config" do
expect(@miq_server.worker_heartbeat(@worker1.pid)).to eq([['exit'], ['sync_active_roles', {:roles => nil}], ['sync_config']])
end
end

context "when server has a single sync_active_roles_and_config message" do
before(:each) do
@miq_server.message_for_worker(@worker1.id, "sync_active_roles_and_config")
end

it "should return proper message on heartbeat via drb" do
expect(@miq_server.worker_heartbeat(@worker1.pid)).to eq([['sync_active_roles', {:roles => nil}], ['sync_config']])
end
end

context "when server has a single reconnect_ems message with a parameter" do
before(:each) do
@ems_id = 7
Expand Down
1 change: 0 additions & 1 deletion spec/models/miq_vim_broker_worker/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
@worker_record = FactoryGirl.create(:miq_vim_broker_worker, :guid => @worker_guid, :miq_server_id => server.id)
@drb_uri = "drb://127.0.0.1:12345"
allow(DRb).to receive(:uri).and_return(@drb_uri)
allow_any_instance_of(described_class).to receive(:sync_active_roles)
allow_any_instance_of(described_class).to receive(:sync_config)
allow_any_instance_of(described_class).to receive(:set_connection_pool_size)
allow_any_instance_of(ManageIQ::Providers::Vmware::InfraManager).to receive(:authentication_check).and_return([true, ""])
Expand Down

0 comments on commit 9dd6d3b

Please sign in to comment.