Skip to content

Commit

Permalink
Merge pull request #314 from Ladas/refresher_refactorings
Browse files Browse the repository at this point in the history
Cleanup refreshers using base class refresher for ManagerRefresh
  • Loading branch information
agrare committed Oct 13, 2017
2 parents 6505d84 + 22c9d96 commit 4637d98
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 167 deletions.
75 changes: 9 additions & 66 deletions app/models/manageiq/providers/amazon/cloud_manager/refresher.rb
Original file line number Diff line number Diff line change
@@ -1,75 +1,18 @@
class ManageIQ::Providers::Amazon::CloudManager::Refresher < ManageIQ::Providers::BaseManager::Refresher
include ::EmsRefresh::Refreshers::EmsRefresherMixin

def collect_inventory_for_targets(ems, targets)
targets_with_data = targets.collect do |target|
target_name = target.try(:name) || target.try(:event_type)

_log.info "Filtering inventory for #{target.class} [#{target_name}] id: [#{target.id}]..."

if refresher_options.try(:[], :inventory_object_refresh)
inventory = ManageIQ::Providers::Amazon::Builder.build_inventory(ems, target)
end

_log.info "Filtering inventory...Complete"
[target, inventory]
end

targets_with_data
end

def parse_targeted_inventory(ems, _target, inventory)
log_header = format_ems_for_logging(ems)
_log.debug "#{log_header} Parsing inventory..."
hashes, = Benchmark.realtime_block(:parse_inventory) do
if refresher_options.try(:[], :inventory_object_refresh)
inventory.inventory_collections
else
ManageIQ::Providers::Amazon::CloudManager::RefreshParser.ems_inv_to_hashes(ems, refresher_options)
end
end
_log.debug "#{log_header} Parsing inventory...Complete"

hashes
end

def preprocess_targets
@targets_by_ems_id.each do |ems_id, targets|
if targets.any? { |t| t.kind_of?(ExtManagementSystem) }
ems = @ems_by_ems_id[ems_id]
targets_for_log = targets.map { |t| "#{t.class} [#{t.name}] id [#{t.id}] " }
_log.info "Defaulting to full refresh for EMS: [#{ems.name}], id: [#{ems.id}], from targets: #{targets_for_log}" if targets.length > 1
end

# We want all targets of class EmsEvent to be merged into one target, so they can be refreshed together, otherwise
# we could be missing some crosslinks in the refreshed data
all_targets, sub_ems_targets = targets.partition { |x| x.kind_of?(ExtManagementSystem) }

unless sub_ems_targets.blank?
if refresher_options.try(:[], :allow_targeted_refresh)
# We can disable targeted refresh with a setting, then we will just do full ems refresh on any event
ems_event_collection = ManagerRefresh::TargetCollection.new(:targets => sub_ems_targets,
:manager_id => ems_id)
all_targets << ems_event_collection
else
all_targets << @ems_by_ems_id[ems_id]
end
end

@targets_by_ems_id[ems_id] = all_targets
end

class ManageIQ::Providers::Amazon::CloudManager::Refresher < ManageIQ::Providers::BaseManager::ManagerRefresher
# Saves the inventory to the DB
#
# @param ems [ManageIQ::Providers::BaseManager] Manager owning the refresh
# @param target [ManageIQ::Providers::BaseManager or ManagerRefresh::Target or ManagerRefresh::TargetCollection]
# Target we are refreshing
# @param _hashes_or_persister [Array<Hash> or ManagerRefresh::Inventory::Persister] Used in superclass
def save_inventory(ems, target, _hashes_or_persister)
super
end

# TODO(lsmola) NetworkManager, remove this once we have a full representation of the NetworkManager.
# NetworkManager should refresh base on its own conditions
def save_inventory(ems, target, inventory_collections)
super
EmsRefresh.queue_refresh(ems.network_manager) if target.kind_of?(ManageIQ::Providers::BaseManager)
EmsRefresh.queue_refresh(ems.ebs_storage_manager) if target.kind_of?(ManageIQ::Providers::BaseManager)
end

# List classes that will have post process method invoked
def post_process_refresh_classes
[::Vm]
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,5 @@
module ManageIQ::Providers
class Amazon::NetworkManager::Refresher < ManageIQ::Providers::BaseManager::Refresher
include ::EmsRefresh::Refreshers::EmsRefresherMixin

def collect_inventory_for_targets(ems, targets)
targets_with_data = targets.collect do |target|
target_name = target.try(:name) || target.try(:event_type)

_log.info "Filtering inventory for #{target.class} [#{target_name}] id: [#{target.id}]..."

if refresher_options.try(:[], :inventory_object_refresh)
inventory = ManageIQ::Providers::Amazon::Builder.build_inventory(ems, target)
end

_log.info "Filtering inventory...Complete"
[target, inventory]
end

targets_with_data
end

def parse_targeted_inventory(ems, _target, inventory)
log_header = format_ems_for_logging(ems)
_log.debug "#{log_header} Parsing inventory..."
hashes, = Benchmark.realtime_block(:parse_inventory) do
if refresher_options.try(:[], :inventory_object_refresh)
inventory.inventory_collections
else
ManageIQ::Providers::Amazon::NetworkManager::RefreshParser.ems_inv_to_hashes(ems, refresher_options)
end
end
_log.debug "#{log_header} Parsing inventory...Complete"

hashes
end

class Amazon::NetworkManager::Refresher < ManageIQ::Providers::BaseManager::ManagerRefresher
def post_process_refresh_classes
[]
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,7 @@
module ManageIQ::Providers
class Amazon::StorageManager::Ebs::Refresher < ManageIQ::Providers::BaseManager::Refresher
include ::EmsRefresh::Refreshers::EmsRefresherMixin

def collect_inventory_for_targets(ems, targets)
targets_with_data = targets.collect do |target|
target_name = target.try(:name) || target.try(:event_type)

_log.info "Filtering inventory for #{target.class} [#{target_name}] id: [#{target.id}]..."

if refresher_options.try(:[], :inventory_object_refresh)
inventory = ManageIQ::Providers::Amazon::Builder.build_inventory(ems, target)
end

_log.info "Filtering inventory...Complete"
[target, inventory]
end

targets_with_data
end

def parse_targeted_inventory(ems, _target, inventory)
log_header = format_ems_for_logging(ems)
_log.debug "#{log_header} Parsing inventory..."
hashes, = Benchmark.realtime_block(:parse_inventory) do
if refresher_options.try(:[], :inventory_object_refresh)
inventory.inventory_collections
else
ManageIQ::Providers::Amazon::StorageManager::Ebs::RefreshParser.ems_inv_to_hashes(ems, refresher_options)
end
end
_log.debug "#{log_header} Parsing inventory...Complete"

hashes
class Amazon::StorageManager::Ebs::Refresher < ManageIQ::Providers::BaseManager::ManagerRefresher
def parse_legacy_inventory(ems)
::ManageIQ::Providers::Amazon::StorageManager::Ebs::RefreshParser.ems_inv_to_hashes(ems)
end

def post_process_refresh_classes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,10 @@
module ManageIQ::Providers
class Amazon::StorageManager::S3::Refresher < ManageIQ::Providers::BaseManager::Refresher
include ::EmsRefresh::Refreshers::EmsRefresherMixin

def collect_inventory_for_targets(ems, targets)
targets_with_data = targets.collect do |target|
target_name = target.try(:name) || target.try(:event_type)

_log.info "Filtering inventory for #{target.class} [#{target_name}] id: [#{target.id}]..."

if refresher_options.try(:[], :inventory_object_refresh)
inventory = ManageIQ::Providers::Amazon::Builder.build_inventory(ems, target)
end

_log.info "Filtering inventory...Complete"
[target, inventory]
end

targets_with_data
end

def parse_targeted_inventory(ems, _target, inventory)
log_header = format_ems_for_logging(ems)
_log.debug "#{log_header} Parsing inventory..."
hashes, = Benchmark.realtime_block(:parse_inventory) do
if refresher_options.try(:[], :inventory_object_refresh)
inventory.inventory_collections
else
ManageIQ::Providers::Amazon::StorageManager::S3::RefreshParser.ems_inv_to_hashes(ems, refresher_options)
end
end
_log.debug "#{log_header} Parsing inventory...Complete"

hashes
class Amazon::StorageManager::S3::Refresher < ManageIQ::Providers::BaseManager::ManagerRefresher
# Legacy parse
#
# @param ems [ManageIQ::Providers::BaseManager]
def parse_legacy_inventory(ems)
::ManageIQ::Providers::Amazon::StorageManager::S3::RefreshParser.ems_inv_to_hashes(ems)
end

def post_process_refresh_classes
Expand Down

0 comments on commit 4637d98

Please sign in to comment.