Skip to content

Commit 0394dd3

Browse files
committed
WIP
1 parent 3de1309 commit 0394dd3

File tree

3 files changed

+48
-21
lines changed

3 files changed

+48
-21
lines changed

app/models/ext_management_system.rb

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ def edit_with_params(params, endpoints, authentications)
178178
endpoints_changed = false
179179
authentications_changed = false
180180

181+
endpoint_changes = {}
182+
authentication_changes = {}
183+
181184
transaction do
182185
# Remove endpoints/attributes that are not arriving in the arguments above
183186
endpoints_to_delete = ems.endpoints.where.not(:role => nil).where.not(:role => endpoints.map { |ep| ep['role'] })
@@ -190,15 +193,23 @@ def edit_with_params(params, endpoints, authentications)
190193
ems.endpoints = endpoints.map(&method(:assign_nested_endpoint))
191194
ems.authentications = authentications.map(&method(:assign_nested_authentication))
192195

193-
endpoints_changed ||= ems.endpoints.any?(&:changed?)
194-
authentications_changed ||= ems.authentications.any?(&:changed?)
196+
endpoint_changes = ems.endpoints.select(&:changed?).to_h do |ep|
197+
[ep.role.to_sym, ep.changes]
198+
end
199+
200+
authentication_changes = ems.authentications.select(&:changed?).to_h do |auth|
201+
[auth.authtype.to_sym, auth.changes]
202+
end
203+
204+
endpoints_changed ||= endpoint_changes.present?
205+
authentications_changed ||= authentication_changes.present?
195206

196207
ems.provider.save! if ems.provider.present? && ems.provider.changed?
197208
ems.save!
198209
end
199210

200-
after_update_endpoints if endpoints_changed
201-
after_update_authentication if authentications_changed
211+
after_update_endpoints(endpoint_changes) if endpoints_changed
212+
after_update_authentication(authentication_changes) if authentications_changed
202213
end
203214
end
204215

@@ -875,12 +886,12 @@ def perf_capture_enabled?
875886
# Some workers hold open a connection to the provider and thus do not
876887
# automatically pick up authentication changes. These workers have to be
877888
# restarted manually for the new credentials to be used.
878-
def after_update_authentication
879-
stop_event_monitor_queue_on_credential_change
889+
def after_update_authentication(changes)
890+
stop_event_monitor_queue_on_credential_change(changes)
880891
end
881892

882-
def after_update_endpoints
883-
stop_event_monitor_queue_on_change
893+
def after_update_endpoints(changes)
894+
stop_event_monitor_queue_on_change(changes)
884895
end
885896

886897
###################################
@@ -892,6 +903,14 @@ def self.event_monitor_class
892903
end
893904
delegate :event_monitor_class, :to => :class
894905

906+
def endpoint_role_for_events
907+
:default
908+
end
909+
910+
def authtype_for_events
911+
default_authentication_type
912+
end
913+
895914
def event_monitor
896915
return if event_monitor_class.nil?
897916
event_monitor_class.find_by_ems(self).first
@@ -919,15 +938,15 @@ def stop_event_monitor_queue
919938
)
920939
end
921940

922-
def stop_event_monitor_queue_on_change
923-
if event_monitor_class && !new_record?
941+
def stop_event_monitor_queue_on_change(changes)
942+
if event_monitor_class && !new_record? && changes[endpoint_role_for_events]&.keys&.include_any?("hostname", "ipaddress")
924943
_log.info("EMS: [#{name}], Hostname or IP address has changed, stopping Event Monitor. It will be restarted by the WorkerMonitor.")
925944
stop_event_monitor_queue
926945
end
927946
end
928947

929-
def stop_event_monitor_queue_on_credential_change
930-
if event_monitor_class && !new_record?
948+
def stop_event_monitor_queue_on_credential_change(changes)
949+
if event_monitor_class && !new_record? && changes[authtype_for_events].present?
931950
_log.info("EMS: [#{name}], Credentials have changed, stopping Event Monitor. It will be restarted by the WorkerMonitor.")
932951
stop_event_monitor_queue
933952
end
@@ -953,6 +972,14 @@ def self.refresh_worker_class
953972
end
954973
delegate :refresh_worker_class, :to => :class
955974

975+
def endpoint_role_for_refresh
976+
:default
977+
end
978+
979+
def authtype_for_refresh
980+
default_authentication_type
981+
end
982+
956983
def refresh_worker
957984
return if refresh_worker_class.nil?
958985

@@ -983,15 +1010,15 @@ def stop_refresh_worker_queue
9831010
)
9841011
end
9851012

986-
def stop_refresh_worker_queue_on_change
987-
if refresh_worker_class && !new_record? && default_endpoint.changed.include_any?("hostname", "ipaddress")
1013+
def stop_refresh_worker_queue_on_change(changes)
1014+
if refresh_worker_class && !new_record? && changes["default"]&.keys&.include_any?("hostname", "ipaddress")
9881015
_log.info("EMS: [#{name}], Hostname or IP address has changed, stopping Refresh Worker. It will be restarted by the WorkerMonitor.")
9891016
stop_refresh_worker_queue
9901017
end
9911018
end
9921019

993-
def stop_refresh_worker_queue_on_credential_change
994-
if refresh_worker_class && !new_record? && default_authentication&.changed?
1020+
def stop_refresh_worker_queue_on_credential_change(changes)
1021+
if refresh_worker_class && !new_record? && changes[authtype_for_refresh].present?
9951022
_log.info("EMS: [#{name}], Credentials have changed, stopping Refresh Worker. It will be restarted by the WorkerMonitor.")
9961023
stop_refresh_worker_queue
9971024
end

app/models/manageiq/providers/cloud_manager.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ def open_browser
7676
MiqSystem.open_browser(browser_url)
7777
end
7878

79-
def stop_event_monitor_queue_on_credential_change
80-
if event_monitor_class && !new_record? && default_endpoint.changed.include_any?("hostname", "ipaddress")
79+
def stop_event_monitor_queue_on_credential_change(changes)
80+
if event_monitor_class && !new_record? && changes["default"]&.keys&.include_any?("hostname", "ipaddress")
8181
_log.info("EMS: [#{name}], Credentials have changed, stopping Event Monitor. It will be restarted by the WorkerMonitor.")
8282
stop_event_monitor_queue
8383
network_manager.stop_event_monitor_queue if respond_to?(:network_manager) && network_manager

app/models/mixins/authentication_mixin.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,17 +243,17 @@ def update_authentication(data, options = {})
243243
cred.auth_key = value[:auth_key]
244244
cred.service_account = value[:service_account].presence
245245

246-
changes = {type => cred.changes} if cred.changed?
246+
changes = [type.to_sym, cred.changes] if cred.changed?
247247

248248
cred.save if options[:save] && id
249249

250250
changes
251-
end.compact
251+
end.compact.to_h
252252

253253
return if authentication_changes.blank? || !options[:save]
254254

255255
# Invoke callback
256-
after_update_authentication if respond_to?(:after_update_authentication)
256+
after_update_authentication(authentication_changes) if respond_to?(:after_update_authentication)
257257
end
258258

259259
def authentication_type(type)

0 commit comments

Comments
 (0)