Skip to content

Commit

Permalink
SmartState and C&U suspend
Browse files Browse the repository at this point in the history
Suspend checks extracted to common mixin

https://bugzilla.redhat.com/show_bug.cgi?id=1455145
  • Loading branch information
slemrmartin committed May 29, 2018
1 parent 8b42ce2 commit 67120c5
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
8 changes: 4 additions & 4 deletions app/models/ext_management_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ def hostname_format_valid?
default_value_for :enabled, true

def self.enable(ems_id)
where(:id => ems_id).or(where(:parent_ems_id => ems_id)).update_all(enabled: true)
_log.info("Provider #{name} enabled")
where(:id => ems_id).or(where(:parent_ems_id => ems_id)).update_all(:enabled => true)
_log.info("Provider enabled: #{name}")
end

def self.disable(ems_id)
where(:id => ems_id).or(where(:parent_ems_id => ems_id)).update_all(enabled: false)
_log.info("Provider #{name} disabled")
where(:id => ems_id).or(where(:parent_ems_id => ems_id)).update_all(:enabled => false)
_log.info("Provider disabled: #{name}")
end

def self.with_ipaddress(ipaddress)
Expand Down
6 changes: 2 additions & 4 deletions app/models/host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Host < ApplicationRecord
include TenantIdentityMixin
include DeprecationMixin
include CustomActionsMixin
include ProviderSuspendMixin

VENDOR_TYPES = {
# DB Displayed
Expand Down Expand Up @@ -1295,10 +1296,7 @@ def scan(userid = "system", options = {})
end

def scan_queue(userid = 'system', _options = {})
if ext_management_system.present? && !ext_management_system.enabled
_log.debug("SmartState analysis disabled [#{log_target}] (provider #{ext_management_system.name} disabled)")
return nil
end
return nil if smartstate_analysis_suspended?(log_target)

_log.info("Queuing scan of #{log_target}")

Expand Down
4 changes: 4 additions & 0 deletions app/models/metric/ci_mixin/capture.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module Metric::CiMixin::Capture
include ProviderSuspendMixin

def perf_capture_object
self.class.parent::MetricsCapture.new(self)
end
Expand Down Expand Up @@ -128,6 +130,8 @@ def perf_capture_historical(*args)
end

def perf_capture(interval_name, start_time = nil, end_time = nil)
return nil if metrics_capture_suspended?(name)

unless Metric::Capture::VALID_CAPTURE_INTERVALS.include?(interval_name)
raise ArgumentError, _("invalid interval_name '%{name}'") % {:name => interval_name}
end
Expand Down
23 changes: 23 additions & 0 deletions app/models/mixins/provider_suspend_mixin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module ProviderSuspendMixin
extend ActiveSupport::Concern

included do
# @param name [String] name of metrics collection's target (ie. VM)
def metrics_capture_suspended?(name = '')
provider_suspended?("Metrics capture disabled [#{name}]")
end

# @param name [String] name of SmartState target (ie. Vm/Template/Host)
def smartstate_analysis_suspended?(name = '')
provider_suspended?("SmartState analysis disabled [#{name}]")
end

# Checks if ExtManagementSystem.enabled is false
# @param log_message [String | nil]
def provider_suspended?(log_message = nil)
suspended = respond_to?(:ext_management_system) && !ext_management_system.enabled
_log.debug("#{log_message} | Provider disabled: #{ext_management_system.name}") if suspended && log_message.present?
suspended
end
end
end
8 changes: 4 additions & 4 deletions app/models/vm_or_template/scanning.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module VmOrTemplate::Scanning
extend ActiveSupport::Concern

include ProviderSuspendMixin

# Call the VmScan Job and raise a "request" event
def scan(userid = "system", options = {})
# Check if there are any current scan jobs already waiting to run
Expand All @@ -16,10 +18,8 @@ def scan(userid = "system", options = {})
end

def raw_scan(userid = "system", options = {})
if ext_management_system.present? && !ext_management_system.enabled
_log.debug("SmartState analysis disabled [#{name}] (provider #{ext_management_system.name} disabled)")
return nil
end
return nil if smartstate_analysis_suspended?(name)

options = {
:target_id => id,
:target_class => self.class.base_class.name,
Expand Down

0 comments on commit 67120c5

Please sign in to comment.