Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix of inventory building and refactoring #17942

Merged
merged 2 commits into from
Sep 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/models/manageiq/providers/base_manager/refresher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ def parse_targeted_inventory(ems, target, collector)
log_header = format_ems_for_logging(ems)
_log.debug("#{log_header} Parsing inventory...")
persister, = Benchmark.realtime_block(:parse_inventory) do
persister = ManageIQ::Providers::Inventory.persister_class_for(target.class).new(ems, target)
parser = ManageIQ::Providers::Inventory.parser_class_for(target.class).new
persister = ManageIQ::Providers::Inventory.persister_class_for(ems, target, target.class.name.demodulize).new(ems, target)
parser = ManageIQ::Providers::Inventory.parser_class_for(ems, target, target.class.name.demodulize).new
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding target.class.name.demodulize makes the same behaviour as old parser_class_for method.
I choose this solution rather than some old_parser_class_for method
Problem is that Amazon's Storage manager's parser and AnsibleTower::AutomationManager::ConfigurationScriptSource's parser doesn't have compatible "suffix"


i = ManageIQ::Providers::Inventory.new(persister, collector, parser)
i.parse
Expand Down
43 changes: 27 additions & 16 deletions app/models/manageiq/providers/inventory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ class Inventory

# Entry point for building inventory
def self.build(ems, target)
collector = collector_class_for(ems, target).new(ems, target)
persister = persister_class_for(ems, target).new(ems, target)
new(
class_for(ems, target, 'Persister').new(ems, target),
class_for(ems, target, 'Collector').new(ems, target),
persister,
collector,
parser_classes_for(ems, target).map(&:new)
)
end
Expand Down Expand Up @@ -45,34 +47,43 @@ def inventory_collections
parse.inventory_collections
end

# Based on the given provider/manager class, this returns correct collector class
#
# @param ems class of the Provider/Manager
# @param target class of refresh's target
# @return [Class] Correct class name of the collector
def self.collector_class_for(ems, target = nil, manager_name = nil)
target = ems if target.nil?
class_for(ems, target, 'Collector', manager_name)
end

# Based on the given provider/manager class, this returns correct persister class
#
# @param klass class of the Provider/Manager
# @param ems class of the Provider/Manager
# @param target class of refresh's target
# @return [Class] Correct class name of the persister
def self.persister_class_for(klass)
provider_module = ManageIQ::Providers::Inflector.provider_module(klass)
"#{provider_module}::Inventory::Persister::#{klass.name.demodulize}".safe_constantize
rescue ManageIQ::Providers::Inflector::ObjectNotNamespacedError => _err
nil
def self.persister_class_for(ems, target = nil, manager_name = nil)
target = ems if target.nil?
class_for(ems, target, 'Persister', manager_name)
end

# Based on the given provider/manager class, this returns correct parser class
#
# @param klass class of the Provider/Manager
# @param ems class of the Provider/Manager
# @param target class of refresh's target
# @return [Class] Correct class name of the Parser
def self.parser_class_for(klass)
provider_module = ManageIQ::Providers::Inflector.provider_module(klass)
"#{provider_module}::Inventory::Parser::#{klass.name.demodulize}".safe_constantize
rescue ManageIQ::Providers::Inflector::ObjectNotNamespacedError => _err
nil
def self.parser_class_for(ems, target = nil, manager_name = nil)
target = ems if target.nil?
class_for(ems, target, 'Parser', manager_name)
end

# @param ems [ExtManagementSystem]
# @param target [ExtManagementSystem, ManagerRefresh::TargetCollection]
# @param type [String] 'Persister' | 'Collector' | 'Parser'
# @param manager_name [String, nil] @see default_manager_name
def self.class_for(ems, target, type, manager_name = nil)
provider_module = ManageIQ::Providers::Inflector.provider_module(ems.class)
ems_class = ems.class == Class ? ems : ems.class
provider_module = ManageIQ::Providers::Inflector.provider_module(ems_class)

manager_name = parsed_manager_name(target) if manager_name.nil?

Expand Down Expand Up @@ -110,7 +121,7 @@ def self.parsed_manager_name(target)
# Multiple parser classes
# Can be implemented in subclass when custom set needed (mainly for TargetCollection)
def self.parser_classes_for(ems, target)
[class_for(ems, target, 'Parser')]
[parser_class_for(ems, target)]
end
end
end