-
Notifications
You must be signed in to change notification settings - Fork 898
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
Moving Inventory::Builder's functions to Inventory class #17907
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,26 +6,13 @@ class Inventory | |
|
||
attr_accessor :collector, :parsers, :persister | ||
|
||
# Based on the given provider/manager class, this returns correct parser class | ||
# | ||
# @param klass class of the Provider/Manager | ||
# @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 | ||
end | ||
|
||
# Based on the given provider/manager class, this returns correct persister class | ||
# | ||
# @param klass class of the Provider/Manager | ||
# @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 | ||
# Entry point for building inventory | ||
def self.build(ems, target) | ||
new( | ||
class_for(ems, target, 'Persister').new(ems, target), | ||
class_for(ems, target, 'Collector').new(ems, target), | ||
parser_classes_for(ems, target).map(&:new) | ||
) | ||
end | ||
|
||
# @param persister [ManageIQ::Providers::Inventory::Persister] A Persister object | ||
|
@@ -57,5 +44,73 @@ def parse | |
def inventory_collections | ||
parse.inventory_collections | ||
end | ||
|
||
# Based on the given provider/manager class, this returns correct persister class | ||
# | ||
# @param klass class of the Provider/Manager | ||
# @return [Class] Correct class name of the persister | ||
def self.persister_class_for(klass) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @agrare I only changed order of these methods in file, no change there There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm good with this for now, I think these should all be private and then all of the yardoc comments are unnecessary There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually where is persister_class_for used? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah okay 👍 |
||
provider_module = ManageIQ::Providers::Inflector.provider_module(klass) | ||
"#{provider_module}::Inventory::Persister::#{klass.name.demodulize}".safe_constantize | ||
rescue ManageIQ::Providers::Inflector::ObjectNotNamespacedError => _err | ||
nil | ||
end | ||
|
||
# Based on the given provider/manager class, this returns correct parser class | ||
# | ||
# @param klass class of the Provider/Manager | ||
# @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 | ||
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) | ||
|
||
manager_name = parsed_manager_name(target) if manager_name.nil? | ||
|
||
klass = "#{provider_module}::Inventory::#{type}::#{manager_name}".safe_constantize | ||
# if class for given target doesn't exist, try to use class for default_manager (if defined) | ||
if klass.nil? && default_manager_name.present? && manager_name != default_manager_name | ||
klass = class_for(ems, target, type, default_manager_name) | ||
end | ||
klass | ||
rescue ManageIQ::Providers::Inflector::ObjectNotNamespacedError => _err | ||
nil | ||
end | ||
|
||
# Fallback manager name when persister/parser/collector not determined from refreshes' target | ||
# @return [String, nil] i.e. 'CloudManager' | ||
def self.default_manager_name | ||
nil | ||
end | ||
|
||
# Last part of persister/parser/collector class name | ||
# For example 'CloudManager' or 'StorageManager::Ebs' | ||
def self.parsed_manager_name(target) | ||
case target | ||
when ManagerRefresh::TargetCollection | ||
'TargetCollection' | ||
else | ||
klass = target.class == Class ? target : target.class | ||
suffix_arr = klass.name.split('::') - ManageIQ::Providers::Inflector.provider_module(klass).name.split("::") | ||
suffix_arr.join('::') | ||
end | ||
rescue ManageIQ::Providers::Inflector::ObjectNotNamespacedError => _err | ||
nil | ||
end | ||
|
||
# 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')] | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of the general
class_for
here how about we callcollector_class_for
andpersister_class_for
here to give providers a change to override them?