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

Move the IC::Builder to Inventory::Persister #17901

Merged
merged 2 commits into from
Aug 24, 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
3 changes: 2 additions & 1 deletion app/models/manager_refresh/inventory/persister.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
class ManagerRefresh::Inventory::Persister
require 'json'
require 'yaml'
require_nested :Builder

attr_reader :manager, :target, :collections

include ::ManagerRefresh::InventoryCollection::Builder::PersisterHelper
include ::ManagerRefresh::Inventory::Persister::Builder::PersisterHelper

# @param manager [ManageIQ::Providers::BaseManager] A manager object
# @param target [Object] A refresh Target object
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module ManagerRefresh
class InventoryCollection
class Inventory::Persister
# @see test in /spec/models/manager_refresh/inventory_collection/builder_spec.rb
class Builder
class MissingModelClassError < StandardError; end
Expand All @@ -12,7 +12,7 @@ class MissingModelClassError < StandardError; end
require_nested :StorageManager
require_nested :PersisterHelper

include ::ManagerRefresh::InventoryCollection::Builder::Shared
include ::ManagerRefresh::Inventory::Persister::Builder::Shared

# Default options for builder
# :adv_settings
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ManagerRefresh
class InventoryCollection
class Inventory::Persister
class Builder
class AutomationManager < ::ManagerRefresh::InventoryCollection::Builder
class AutomationManager < ::ManagerRefresh::Inventory::Persister::Builder
def configuration_scripts
default_manager_ref
add_common_default_values
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ManagerRefresh
class InventoryCollection
class Inventory::Persister
class Builder
class CloudManager < ::ManagerRefresh::InventoryCollection::Builder
class CloudManager < ::ManagerRefresh::Inventory::Persister::Builder
def availability_zones
add_common_default_values
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ManagerRefresh
class InventoryCollection
class Inventory::Persister
class Builder
class ContainerManager < ::ManagerRefresh::InventoryCollection::Builder
class ContainerManager < ::ManagerRefresh::Inventory::Persister::Builder
# TODO: (agrare) Targeted refreshes will require adjusting the associations / arels. (duh)
def container_projects
add_properties(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ManagerRefresh
class InventoryCollection
class Inventory::Persister
class Builder
class InfraManager < ::ManagerRefresh::InventoryCollection::Builder
class InfraManager < ::ManagerRefresh::Inventory::Persister::Builder
def networks
add_properties(
:manager_ref => %i(hardware ipaddress ipv6address),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ManagerRefresh
class InventoryCollection
class Inventory::Persister
class Builder
class NetworkManager < ::ManagerRefresh::InventoryCollection::Builder
class NetworkManager < ::ManagerRefresh::Inventory::Persister::Builder
def cloud_subnet_network_ports
add_properties(
# :model_class => ::CloudSubnetNetworkPort,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
module ManagerRefresh::InventoryCollection::Builder::PersisterHelper
module ManagerRefresh::Inventory::Persister::Builder::PersisterHelper
extend ActiveSupport::Concern

# Interface for creating InventoryCollection under @collections
#
# @param builder_class [ManagerRefresh::InventoryCollection::Builder] or subclasses
# @param builder_class [ManagerRefresh::Inventory::Persister::Builder] or subclasses
# @param collection_name [Symbol || Array] used as InventoryCollection:association
# @param extra_properties [Hash] props from InventoryCollection.initialize list
# - adds/overwrites properties added by builder
#
# @param settings [Hash] builder settings
# - @see ManagerRefresh::InventoryCollection::Builder.default_options
# - @see ManagerRefresh::Inventory::Persister::Builder.default_options
# - @see make_builder_settings()
#
# @example
# add_collection(ManagerRefresh::InventoryCollection::Builder::CloudManager, :vms) do |builder|
# add_collection(ManagerRefresh::Inventory::Persister::Builder::CloudManager, :vms) do |builder|
# builder.add_properties(
# :strategy => :local_db_cache_all,
# )
Expand All @@ -38,36 +38,36 @@ def add_collection(builder_class, collection_name, extra_properties = {}, settin

# builder_class for add_collection()
def cloud
::ManagerRefresh::InventoryCollection::Builder::CloudManager
::ManagerRefresh::Inventory::Persister::Builder::CloudManager
end

# builder_class for add_collection()
def network
::ManagerRefresh::InventoryCollection::Builder::NetworkManager
::ManagerRefresh::Inventory::Persister::Builder::NetworkManager
end

# builder_class for add_collection()
def infra
::ManagerRefresh::InventoryCollection::Builder::InfraManager
::ManagerRefresh::Inventory::Persister::Builder::InfraManager
end

# builder_class for add_collection()
def storage
::ManagerRefresh::InventoryCollection::Builder::StorageManager
::ManagerRefresh::Inventory::Persister::Builder::StorageManager
end

# builder_class for add_collection()
def automation
::ManagerRefresh::InventoryCollection::Builder::AutomationManager
::ManagerRefresh::Inventory::Persister::Builder::AutomationManager
end

# builder class for add_collection()
def physical_infra
::ManagerRefresh::InventoryCollection::Builder::PhysicalInfraManager
::ManagerRefresh::Inventory::Persister::Builder::PhysicalInfraManager
end

def container
::ManagerRefresh::InventoryCollection::Builder::ContainerManager
::ManagerRefresh::Inventory::Persister::Builder::ContainerManager
end

# @param extra_settings [Hash]
Expand All @@ -77,9 +77,9 @@ def container
# :without_model_class
# - if false and no model_class derived or specified, throws exception
# - doesn't try to derive model class automatically
# - @see method ManagerRefresh::InventoryCollection::Builder.auto_model_class
# - @see method ManagerRefresh::Inventory::Persister::Builder.auto_model_class
def make_builder_settings(extra_settings = {})
opts = ::ManagerRefresh::InventoryCollection::Builder.default_options
opts = ::ManagerRefresh::Inventory::Persister::Builder.default_options

opts[:adv_settings] = options.try(:[], :inventory_collections).try(:to_hash) || {}
opts[:shared_properties] = shared_options
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ManagerRefresh
class InventoryCollection
class Inventory::Persister
class Builder
class PhysicalInfraManager < ::ManagerRefresh::InventoryCollection::Builder
class PhysicalInfraManager < ::ManagerRefresh::Inventory::Persister::Builder
def physical_servers
add_common_default_values
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module ManagerRefresh::InventoryCollection::Builder::Shared
module ManagerRefresh::Inventory::Persister::Builder::Shared
extend ActiveSupport::Concern

included do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module ManagerRefresh
class Inventory::Persister
class Builder
class StorageManager < ::ManagerRefresh::Inventory::Persister::Builder
# Nothing there
end
end
end
end
2 changes: 0 additions & 2 deletions app/models/manager_refresh/inventory_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ module ManagerRefresh
# puts @ems.vms.collect(&:ems_ref) # => ["vm2", "vm3"]
#
class InventoryCollection
require_nested :Builder

# @return [Boolean] A true value marks that we collected all the data of the InventoryCollection,
# meaning we also collected all the references.
attr_accessor :data_collection_finalized
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require_relative '../persister/test_persister'
require_relative 'test_persister'

describe ManagerRefresh::InventoryCollection::Builder do
describe ManagerRefresh::Inventory::Persister::Builder do
before :each do
@zone = FactoryGirl.create(:zone)
@ems = FactoryGirl.create(:ems_cloud,
Expand All @@ -15,9 +15,9 @@ def create_persister

let(:adv_settings) { {:strategy => :local_db_find_missing_references, :saver_strategy => :concurrent_safe_batch} }

let(:cloud) { ::ManagerRefresh::InventoryCollection::Builder::CloudManager }
let(:cloud) { ::ManagerRefresh::Inventory::Persister::Builder::CloudManager }

let(:network) { ::ManagerRefresh::InventoryCollection::Builder::NetworkManager }
let(:network) { ::ManagerRefresh::Inventory::Persister::Builder::NetworkManager }

let(:persister_class) { ::ManagerRefresh::Inventory::Persister }

Expand Down Expand Up @@ -58,7 +58,7 @@ def create_persister
it 'throws exception if model_class not specified' do
builder = cloud.prepare_data(:non_existing_ic, persister_class)

expect { builder.to_inventory_collection }.to raise_error(::ManagerRefresh::InventoryCollection::Builder::MissingModelClassError)
expect { builder.to_inventory_collection }.to raise_error(::ManagerRefresh::Inventory::Persister::Builder::MissingModelClassError)
end

# --- adv. settings (TODO: link to gui)---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ def container_quota_items_attrs_init_data(extra_attributes = {})
end

def cloud
ManagerRefresh::InventoryCollection::Builder::CloudManager
ManagerRefresh::Inventory::Persister::Builder::CloudManager
end

def network
ManagerRefresh::InventoryCollection::Builder::NetworkManager
ManagerRefresh::Inventory::Persister::Builder::NetworkManager
end

def persister_class
Expand Down