From d41a6330bb96cf3faaa399166d2989025f9ceeee Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Wed, 5 Sep 2018 10:29:13 +0200 Subject: [PATCH] Moving Inventory Builder functionality to Inventory --- .../manageiq/providers/redhat/builder.rb | 53 ------------------- .../redhat/infra_manager/refresh/refresher.rb | 2 +- .../manageiq/providers/redhat/inventory.rb | 6 +++ .../providers/redhat/inventory/persister.rb | 5 +- .../redhat/network_manager/refresher.rb | 2 +- 5 files changed, 9 insertions(+), 59 deletions(-) delete mode 100644 app/models/manageiq/providers/redhat/builder.rb diff --git a/app/models/manageiq/providers/redhat/builder.rb b/app/models/manageiq/providers/redhat/builder.rb deleted file mode 100644 index 3958da9e9..000000000 --- a/app/models/manageiq/providers/redhat/builder.rb +++ /dev/null @@ -1,53 +0,0 @@ -class ManageIQ::Providers::Redhat::Builder - class << self - def build_inventory(ems, target) - if target.kind_of?(ManagerRefresh::TargetCollection) - inventory( - ems, - target, - ManageIQ::Providers::Redhat::Inventory::Collector::TargetCollection, - ManageIQ::Providers::Redhat::Inventory::Persister::TargetCollection, - [parser] - ) - elsif target.kind_of?(ManageIQ::Providers::Redhat::NetworkManager) - inventory( - ems, - target, - ManageIQ::Providers::Redhat::Inventory::Collector::NetworkManager, - ManageIQ::Providers::Redhat::Inventory::Persister::NetworkManager, - [ManageIQ::Providers::Redhat::Inventory::Parser::NetworkManager] - ) - else - # Fallback to ems refresh or full refresh - infra_manager_inventory(ems, target) - end - end - - private - - def parser - ManageIQ::Providers::Redhat::Inventory::Parser::InfraManager - end - - def infra_manager_inventory(ems, target) - inventory( - ems, - target, - ManageIQ::Providers::Redhat::Inventory::Collector::InfraManager, - ManageIQ::Providers::Redhat::Inventory::Persister::InfraManager, - [parser] - ) - end - - def inventory(manager, raw_target, collector_class, persister_class, parsers_classes) - collector = collector_class.new(manager, raw_target) - persister = persister_class.new(manager, raw_target, collector) - - ::ManageIQ::Providers::Redhat::Inventory.new( - persister, - collector, - parsers_classes.map(&:new) - ) - end - end -end diff --git a/app/models/manageiq/providers/redhat/infra_manager/refresh/refresher.rb b/app/models/manageiq/providers/redhat/infra_manager/refresh/refresher.rb index 28584b1a4..24be918d2 100644 --- a/app/models/manageiq/providers/redhat/infra_manager/refresh/refresher.rb +++ b/app/models/manageiq/providers/redhat/infra_manager/refresh/refresher.rb @@ -11,7 +11,7 @@ def collect_inventory_for_targets(ems, targets) _log.info "Filtering inventory for #{target.class} [#{target.name}] id: [#{target.id}]..." if ems.use_graph_refresh? - data = ManageIQ::Providers::Redhat::Builder.build_inventory(ems, target) + data = ManageIQ::Providers::Redhat::Inventory.build(ems, target) # TODO: remove when graph refresh supports ems updates ems.api_version = inventory.service.version_string diff --git a/app/models/manageiq/providers/redhat/inventory.rb b/app/models/manageiq/providers/redhat/inventory.rb index c7b735e40..249f1c091 100644 --- a/app/models/manageiq/providers/redhat/inventory.rb +++ b/app/models/manageiq/providers/redhat/inventory.rb @@ -2,4 +2,10 @@ class ManageIQ::Providers::Redhat::Inventory < ManageIQ::Providers::Inventory require_nested :Collector require_nested :Parser require_nested :Persister + + # Default manager for building collector/parser/persister classes + # when failed to get class name from refresh target automatically + def self.default_manager_name + "InfraManager" + end end diff --git a/app/models/manageiq/providers/redhat/inventory/persister.rb b/app/models/manageiq/providers/redhat/inventory/persister.rb index 020fea5e5..06d20a658 100644 --- a/app/models/manageiq/providers/redhat/inventory/persister.rb +++ b/app/models/manageiq/providers/redhat/inventory/persister.rb @@ -2,12 +2,9 @@ class ManageIQ::Providers::Redhat::Inventory::Persister < ManageIQ::Providers::I require_nested :InfraManager require_nested :TargetCollection - attr_reader :collector - - def initialize(manager, target, collector) + def initialize(manager, target) @manager = manager @target = target - @collector = collector @collections = {} @collection_group = nil diff --git a/app/models/manageiq/providers/redhat/network_manager/refresher.rb b/app/models/manageiq/providers/redhat/network_manager/refresher.rb index accebf876..176644d2f 100644 --- a/app/models/manageiq/providers/redhat/network_manager/refresher.rb +++ b/app/models/manageiq/providers/redhat/network_manager/refresher.rb @@ -7,7 +7,7 @@ def collect_inventory_for_targets(ems, targets) _log.info("Filtering inventory for #{target.class} [#{target_name}] id: [#{target.id}]...") if ::Settings.ems_refresh.redhat_network.try(:inventory_object_refresh) - inventory = ManageIQ::Providers::Redhat::Builder.build_inventory(ems, target) + inventory = ManageIQ::Providers::Redhat::Inventory.build(ems, target) end _log.info("Filtering inventory...Complete")