Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Dec 7, 2022
1 parent b9a1ac5 commit 1ed4d61
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 21 deletions.
59 changes: 43 additions & 16 deletions app/models/ext_management_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ def edit_with_params(params, endpoints, authentications)
endpoints_changed = false
authentications_changed = false

endpoint_changes = {}
authentication_changes = {}

transaction do
# Remove endpoints/attributes that are not arriving in the arguments above
endpoints_to_delete = ems.endpoints.where.not(:role => nil).where.not(:role => endpoints.map { |ep| ep['role'] })
Expand All @@ -190,15 +193,23 @@ def edit_with_params(params, endpoints, authentications)
ems.endpoints = endpoints.map(&method(:assign_nested_endpoint))
ems.authentications = authentications.map(&method(:assign_nested_authentication))

endpoints_changed ||= ems.endpoints.any?(&:changed?)
authentications_changed ||= ems.authentications.any?(&:changed?)
endpoint_changes = ems.endpoints.select(&:changed?).to_h do |ep|
[ep.role.to_sym, ep.changes]
end

authentication_changes = ems.authentications.select(&:changed?).to_h do |auth|
[auth.authtype.to_sym, auth.changes]
end

endpoints_changed ||= endpoint_changes.present?
authentications_changed ||= authentication_changes.present?

ems.provider.save! if ems.provider.present? && ems.provider.changed?
ems.save!
end

after_update_endpoints if endpoints_changed
after_update_authentication if authentications_changed
after_update_endpoints(endpoint_changes) if endpoints_changed
after_update_authentication(authentication_changes) if authentications_changed
end
end

Expand Down Expand Up @@ -875,12 +886,12 @@ def perf_capture_enabled?
# Some workers hold open a connection to the provider and thus do not
# automatically pick up authentication changes. These workers have to be
# restarted manually for the new credentials to be used.
def after_update_authentication
stop_event_monitor_queue_on_credential_change
def after_update_authentication(changes)
stop_event_monitor_queue_on_credential_change(changes)
end

def after_update_endpoints
stop_event_monitor_queue_on_change
def after_update_endpoints(changes)
stop_event_monitor_queue_on_change(changes)
end

###################################
Expand All @@ -892,6 +903,14 @@ def self.event_monitor_class
end
delegate :event_monitor_class, :to => :class

def endpoint_role_for_events
:default
end

def authtype_for_events
default_authentication_type
end

def event_monitor
return if event_monitor_class.nil?
event_monitor_class.find_by_ems(self).first
Expand Down Expand Up @@ -919,15 +938,15 @@ def stop_event_monitor_queue
)
end

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

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

def endpoint_role_for_refresh
:default
end

def authtype_for_refresh
default_authentication_type
end

def refresh_worker
return if refresh_worker_class.nil?

Expand Down Expand Up @@ -983,15 +1010,15 @@ def stop_refresh_worker_queue
)
end

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

def stop_refresh_worker_queue_on_credential_change
if refresh_worker_class && !new_record? && default_authentication&.changed?
def stop_refresh_worker_queue_on_credential_change(changes)
if refresh_worker_class && !new_record? && changes[authtype_for_refresh].present?
_log.info("EMS: [#{name}], Credentials have changed, stopping Refresh Worker. It will be restarted by the WorkerMonitor.")
stop_refresh_worker_queue
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/manageiq/providers/cloud_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def open_browser
MiqSystem.open_browser(browser_url)
end

def stop_event_monitor_queue_on_credential_change
if event_monitor_class && !new_record? && default_endpoint.changed.include_any?("hostname", "ipaddress")
def stop_event_monitor_queue_on_credential_change(changes)
if event_monitor_class && !new_record? && changes["default"]&.keys&.include_any?("hostname", "ipaddress")
_log.info("EMS: [#{name}], Credentials have changed, stopping Event Monitor. It will be restarted by the WorkerMonitor.")
stop_event_monitor_queue
network_manager.stop_event_monitor_queue if respond_to?(:network_manager) && network_manager
Expand Down
6 changes: 3 additions & 3 deletions app/models/mixins/authentication_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,17 @@ def update_authentication(data, options = {})
cred.auth_key = value[:auth_key]
cred.service_account = value[:service_account].presence

changes = {type => cred.changes} if cred.changed?
changes = [type.to_sym, cred.changes] if cred.changed?

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

changes
end.compact
end.compact.to_h

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

# Invoke callback
after_update_authentication if respond_to?(:after_update_authentication)
after_update_authentication(authentication_changes) if respond_to?(:after_update_authentication)
end

def authentication_type(type)
Expand Down

0 comments on commit 1ed4d61

Please sign in to comment.