From 813af668993959747486d0da3b5cda33f3f4ef34 Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Thu, 21 Jun 2018 13:50:59 +0200 Subject: [PATCH 01/12] IC Builder improvements Renaming builder_params => default_values (partially) Merged common definitions from provider specific --- .../inventory_collection/builder.rb | 39 ++-- .../builder/cloud_manager.rb | 191 +++++++++++------- .../builder/network_manager.rb | 5 - .../inventory_collection/builder_spec.rb | 14 +- 4 files changed, 146 insertions(+), 103 deletions(-) diff --git a/app/models/manager_refresh/inventory_collection/builder.rb b/app/models/manager_refresh/inventory_collection/builder.rb index f5cc34909d6..0213696898a 100644 --- a/app/models/manager_refresh/inventory_collection/builder.rb +++ b/app/models/manager_refresh/inventory_collection/builder.rb @@ -49,7 +49,7 @@ def initialize(name, persister_class, options = self.class.default_options) @properties = {} @inventory_object_attributes = [] - @builder_params = {} + @default_values = {} @dependency_attributes = {} @options = options @@ -128,14 +128,16 @@ def clear_inventory_attributes! @inventory_object_attributes = [] end - # Adds key/values to builder params (part of @properties) - def add_builder_params(params = {}, mode = :overwrite) - @builder_params = merge_hashes(@builder_params, params, mode) + # Adds key/values to default values (InventoryCollection.builder_params) (part of @properties) + def add_default_values(params = {}, mode = :overwrite) + @default_values = merge_hashes(@default_values, params, mode) end + alias :add_builder_params :add_default_values # Evaluates lambda blocks def evaluate_lambdas!(persister) - evaluate_builder_params_lambdas!(persister) + @default_values = evaluate_lambdas_on(@default_values, persister) + @dependency_attributes = evaluate_lambdas_on(@dependency_attributes, persister) end # Adds key/values to dependency_attributes (part of @properties) @@ -143,11 +145,17 @@ def add_dependency_attributes(attrs = {}, mode = :overwrite) @dependency_attributes = merge_hashes(@dependency_attributes, attrs, mode) end + # Deletes key from dependency_attributes + def remove_dependency_attributes(key) + @dependency_attributes.delete(key) + end + # Returns whole InventoryCollection properties + # TODO: default values converted to builder_params, change InventoryCollection and usages in next PR def to_hash @properties.merge( :inventory_object_attributes => @inventory_object_attributes, - :builder_params => @builder_params, + :builder_params => @default_values, :dependency_attributes => @dependency_attributes ) end @@ -222,10 +230,12 @@ def auto_inventory_attributes end end - # Evaluates lambda blocks in @builder_params - def evaluate_builder_params_lambdas!(persister) - if @builder_params - @builder_params = @builder_params.transform_values do |value| + # Evaluates lambda blocks in @default_values and @dependency_attributes + # @param values[Hash] + # @param persister [ManagerRefresh::Inventory::Persister] + def evaluate_lambdas_on(values, persister) + if values + values.transform_values do |value| if value.respond_to?(:call) value.call(persister) else @@ -234,15 +244,6 @@ def evaluate_builder_params_lambdas!(persister) end end end - - def network_manager_collections? - self.class.network_manager_collections? - end - - # InventoryCollection definitions for NetworkManager? - def self.network_manager_collections? - false - end end end end diff --git a/app/models/manager_refresh/inventory_collection/builder/cloud_manager.rb b/app/models/manager_refresh/inventory_collection/builder/cloud_manager.rb index fe024acbe97..ad13bb3d386 100644 --- a/app/models/manager_refresh/inventory_collection/builder/cloud_manager.rb +++ b/app/models/manager_refresh/inventory_collection/builder/cloud_manager.rb @@ -28,11 +28,37 @@ def vm_and_template_labels :manager_ref => %i(resource name), :parent_inventory_collections => %i(vms miq_templates) ) + + add_targeted_arel( + lambda do |inventory_collection| + manager_uuids = inventory_collection.parent_inventory_collections.collect(&:manager_uuids).map(&:to_a).flatten + inventory_collection.parent.vm_and_template_labels.where( + 'vms' => {:ems_ref => manager_uuids} + ) + end + ) + end + + def vm_and_template_taggings + add_properties( + :model_class => Tagging, + :manager_ref => %i(taggable tag), + :parent_inventory_collections => %i(vms miq_templates) + ) + + add_targeted_arel( + lambda do |inventory_collection| + manager_uuids = inventory_collection.parent_inventory_collections.collect(&:manager_uuids).map(&:to_a).flatten + ems = inventory_collection.parent + ems.vm_and_template_taggings.where( + 'taggable_id' => ems.vms_and_templates.where(:ems_ref => manager_uuids) + ) + end + ) end def orchestration_stacks add_properties( - :model_class => ::ManageIQ::Providers::CloudManager::OrchestrationStack, :attributes_blacklist => %i(parent), ) @@ -77,88 +103,31 @@ def orchestration_templates end def orchestration_stack_ancestry - orchestration_stack_ancestry_save_block = lambda do |_ems, inventory_collection| - stacks_inventory_collection = inventory_collection.dependency_attributes[:orchestration_stacks].try(:first) - - return if stacks_inventory_collection.blank? - - stacks_parents = stacks_inventory_collection.data.each_with_object({}) do |x, obj| - parent_id = x.data[:parent].try(:load).try(:id) - obj[x.id] = parent_id if parent_id - end - - model_class = stacks_inventory_collection.model_class - - stacks_parents_indexed = model_class - .select(%i(id ancestry)) - .where(:id => stacks_parents.values).find_each.index_by(&:id) - - ActiveRecord::Base.transaction do - model_class.select(%i(id ancestry)) - .where(:id => stacks_parents.keys).find_each do |stack| - parent = stacks_parents_indexed[stacks_parents[stack.id]] - stack.update_attribute(:parent, parent) - end - end - end + @options[:auto_inventory_attributes] = false + @options[:without_model_class] = true add_properties( :custom_save_block => orchestration_stack_ancestry_save_block ) + + add_dependency_attributes( + :orchestration_stacks => ->(persister) { [persister.collections[:orchestration_stacks]] }, + :orchestration_stacks_resources => ->(persister) { [persister.collections[:orchestration_stacks_resources]] } + ) end def vm_and_miq_template_ancestry - vm_and_miq_template_ancestry_save_block = lambda do |_ems, inventory_collection| - vms_inventory_collection = inventory_collection.dependency_attributes[:vms].try(:first) - miq_templates_inventory_collection = inventory_collection.dependency_attributes[:miq_templates].try(:first) - - return if vms_inventory_collection.blank? || miq_templates_inventory_collection.blank? - - # Fetch IDs of all vms and genealogy_parents, only if genealogy_parent is present - vms_genealogy_parents = vms_inventory_collection.data.each_with_object({}) do |x, obj| - unless x.data[:genealogy_parent].nil? - genealogy_parent_id = x.data[:genealogy_parent].load.try(:id) - obj[x.id] = genealogy_parent_id if genealogy_parent_id - end - end - - miq_template_genealogy_parents = miq_templates_inventory_collection.data.each_with_object({}) do |x, obj| - unless x.data[:genealogy_parent].nil? - genealogy_parent_id = x.data[:genealogy_parent].load.try(:id) - obj[x.id] = genealogy_parent_id if genealogy_parent_id - end - end - - ActiveRecord::Base.transaction do - # associate parent templates to child instances - parent_miq_templates = miq_templates_inventory_collection.model_class - .select([:id]) - .where(:id => vms_genealogy_parents.values).find_each.index_by(&:id) - vms_inventory_collection.model_class - .select([:id]) - .where(:id => vms_genealogy_parents.keys).find_each do |vm| - parent = parent_miq_templates[vms_genealogy_parents[vm.id]] - vm.with_relationship_type('genealogy') { vm.parent = parent } - end - end - - ActiveRecord::Base.transaction do - # associate parent instances to child templates - parent_vms = vms_inventory_collection.model_class - .select([:id]) - .where(:id => miq_template_genealogy_parents.values).find_each.index_by(&:id) - miq_templates_inventory_collection.model_class - .select([:id]) - .where(:id => miq_template_genealogy_parents.keys).find_each do |miq_template| - parent = parent_vms[miq_template_genealogy_parents[miq_template.id]] - miq_template.with_relationship_type('genealogy') { miq_template.parent = parent } - end - end - end + @options[:auto_inventory_attributes] = false + @options[:without_model_class] = true add_properties( :custom_save_block => vm_and_miq_template_ancestry_save_block ) + + add_dependency_attributes( + :vms => ->(persister) { [persister.collections[:vms]] }, + :miq_templates => ->(persister) { [persister.collections[:miq_templates]] } + ) end end @@ -171,6 +140,84 @@ def shared_builder_params def default_ems_id ->(persister) { persister.manager.id } end + + def orchestration_stack_ancestry_save_block + lambda do |_ems, inventory_collection| + + stacks_inventory_collection = inventory_collection.dependency_attributes[:orchestration_stacks].try(:first) + + return if stacks_inventory_collection.blank? + + stacks_parents = stacks_inventory_collection.data.each_with_object({}) do |x, obj| + parent_id = x.data[:parent].try(:load).try(:id) + obj[x.id] = parent_id if parent_id + end + + model_class = stacks_inventory_collection.model_class + + stacks_parents_indexed = model_class + .select(%i(id ancestry)) + .where(:id => stacks_parents.values).find_each.index_by(&:id) + + ActiveRecord::Base.transaction do + model_class.select(%i(id ancestry)) + .where(:id => stacks_parents.keys).find_each do |stack| + parent = stacks_parents_indexed[stacks_parents[stack.id]] + stack.update_attribute(:parent, parent) + end + end + end + end + + def vm_and_miq_template_ancestry_save_block + lambda do |_ems, inventory_collection| + vms_inventory_collection = inventory_collection.dependency_attributes[:vms].try(:first) + miq_templates_inventory_collection = inventory_collection.dependency_attributes[:miq_templates].try(:first) + + return if vms_inventory_collection.blank? || miq_templates_inventory_collection.blank? + + # Fetch IDs of all vms and genealogy_parents, only if genealogy_parent is present + vms_genealogy_parents = vms_inventory_collection.data.each_with_object({}) do |x, obj| + unless x.data[:genealogy_parent].nil? + genealogy_parent_id = x.data[:genealogy_parent].load.try(:id) + obj[x.id] = genealogy_parent_id if genealogy_parent_id + end + end + + miq_template_genealogy_parents = miq_templates_inventory_collection.data.each_with_object({}) do |x, obj| + unless x.data[:genealogy_parent].nil? + genealogy_parent_id = x.data[:genealogy_parent].load.try(:id) + obj[x.id] = genealogy_parent_id if genealogy_parent_id + end + end + + ActiveRecord::Base.transaction do + # associate parent templates to child instances + parent_miq_templates = miq_templates_inventory_collection.model_class + .select([:id]) + .where(:id => vms_genealogy_parents.values).find_each.index_by(&:id) + vms_inventory_collection.model_class + .select([:id]) + .where(:id => vms_genealogy_parents.keys).find_each do |vm| + parent = parent_miq_templates[vms_genealogy_parents[vm.id]] + vm.with_relationship_type('genealogy') { vm.parent = parent } + end + end + + ActiveRecord::Base.transaction do + # associate parent instances to child templates + parent_vms = vms_inventory_collection.model_class + .select([:id]) + .where(:id => miq_template_genealogy_parents.values).find_each.index_by(&:id) + miq_templates_inventory_collection.model_class + .select([:id]) + .where(:id => miq_template_genealogy_parents.keys).find_each do |miq_template| + parent = parent_vms[miq_template_genealogy_parents[miq_template.id]] + miq_template.with_relationship_type('genealogy') { miq_template.parent = parent } + end + end + end + end end end end diff --git a/app/models/manager_refresh/inventory_collection/builder/network_manager.rb b/app/models/manager_refresh/inventory_collection/builder/network_manager.rb index 2a14baccb5c..622e68dff83 100644 --- a/app/models/manager_refresh/inventory_collection/builder/network_manager.rb +++ b/app/models/manager_refresh/inventory_collection/builder/network_manager.rb @@ -206,11 +206,6 @@ def shared_builder_params def default_ems_id ->(persister) { persister.manager.try(:network_manager).try(:id) || persister.manager.id } end - - # InventoryCollection definitions for NetworkManager? - def self.network_manager_collections? - true - end end end end diff --git a/spec/models/manager_refresh/inventory_collection/builder_spec.rb b/spec/models/manager_refresh/inventory_collection/builder_spec.rb index 96f3802e9bc..5e090855108 100644 --- a/spec/models/manager_refresh/inventory_collection/builder_spec.rb +++ b/spec/models/manager_refresh/inventory_collection/builder_spec.rb @@ -135,22 +135,22 @@ def create_persister expect(data[:some_tmp_param]).to eq :some_value end - # --- builder params --- + # --- default values --- - it 'adds builder_params repeatedly' do + it 'adds default_values repeatedly' do data = cloud.prepare_data(:tmp, persister_class) do |builder| - builder.add_builder_params(:ems_id => 10) - builder.add_builder_params(:ems_id => 20) - builder.add_builder_params(:tmp_id => 30) + builder.add_default_values(:ems_id => 10) + builder.add_default_values(:ems_id => 20) + builder.add_default_values(:tmp_id => 30) end.to_hash expect(data[:builder_params][:ems_id]).to eq 20 expect(data[:builder_params][:tmp_id]).to eq 30 end - it 'transforms lambdas in builder_params' do + it 'transforms lambdas in default_values' do bldr = cloud.prepare_data(:tmp, persister_class) do |builder| - builder.add_builder_params(:ems_id => ->(persister) { persister.manager.id }) + builder.add_default_values(:ems_id => ->(persister) { persister.manager.id }) end bldr.evaluate_lambdas!(@persister) From 8d4487ba92b59b5bc930db5e3984353991fbf4da Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Thu, 21 Jun 2018 15:53:43 +0200 Subject: [PATCH 02/12] Next builder_params => default_values renames --- .../inventory_collection/builder.rb | 2 +- .../builder/automation_manager.rb | 18 +++++----- .../builder/cloud_manager.rb | 36 +++++++++---------- .../builder/infra_manager.rb | 14 ++++---- .../builder/network_manager.rb | 30 ++++++++-------- .../inventory_collection/builder/shared.rb | 4 +-- 6 files changed, 51 insertions(+), 53 deletions(-) diff --git a/app/models/manager_refresh/inventory_collection/builder.rb b/app/models/manager_refresh/inventory_collection/builder.rb index 0213696898a..4b853302c6b 100644 --- a/app/models/manager_refresh/inventory_collection/builder.rb +++ b/app/models/manager_refresh/inventory_collection/builder.rb @@ -132,7 +132,7 @@ def clear_inventory_attributes! def add_default_values(params = {}, mode = :overwrite) @default_values = merge_hashes(@default_values, params, mode) end - alias :add_builder_params :add_default_values + alias add_builder_params add_default_values # Evaluates lambda blocks def evaluate_lambdas!(persister) diff --git a/app/models/manager_refresh/inventory_collection/builder/automation_manager.rb b/app/models/manager_refresh/inventory_collection/builder/automation_manager.rb index 7051dc0ac66..afea37551bf 100644 --- a/app/models/manager_refresh/inventory_collection/builder/automation_manager.rb +++ b/app/models/manager_refresh/inventory_collection/builder/automation_manager.rb @@ -6,40 +6,40 @@ class Builder class AutomationManager < ::ManagerRefresh::InventoryCollection::Builder def configuration_scripts default_manager_ref - default_builder_params + add_common_default_values end def configuration_script_payloads add_properties( :manager_ref => %i(configuration_script_source manager_ref) ) - default_builder_params + add_common_default_values end def configuration_script_sources default_manager_ref - default_builder_params + add_common_default_values end def configuration_workflows default_manager_ref - default_builder_params + add_common_default_values end def configured_systems default_manager_ref - default_builder_params + add_common_default_values end def credentials default_manager_ref - add_builder_params( + add_default_values( :resource => ->(persister) { persister.manager } ) end def inventory_root_groups - default_builder_params + add_common_default_values end def vms @@ -52,8 +52,8 @@ def default_manager_ref add_properties(:manager_ref => %i(manager_ref)) end - def default_builder_params - add_builder_params( + def add_common_default_values + add_default_values( :manager => ->(persister) { persister.manager } ) end diff --git a/app/models/manager_refresh/inventory_collection/builder/cloud_manager.rb b/app/models/manager_refresh/inventory_collection/builder/cloud_manager.rb index ad13bb3d386..317755f518e 100644 --- a/app/models/manager_refresh/inventory_collection/builder/cloud_manager.rb +++ b/app/models/manager_refresh/inventory_collection/builder/cloud_manager.rb @@ -3,11 +3,11 @@ class InventoryCollection class Builder class CloudManager < ::ManagerRefresh::InventoryCollection::Builder def availability_zones - shared_builder_params + add_common_default_values end def flavors - shared_builder_params + add_common_default_values end def key_pairs @@ -15,7 +15,7 @@ def key_pairs :model_class => ::ManageIQ::Providers::CloudManager::AuthKeyPair, :manager_ref => %i(name) ) - add_builder_params( + add_default_values( :resource_id => ->(persister) { persister.manager.id }, :resource_type => ->(persister) { persister.manager.class.base_class } ) @@ -62,7 +62,7 @@ def orchestration_stacks :attributes_blacklist => %i(parent), ) - shared_builder_params + add_common_default_values end def orchestration_stacks_resources @@ -133,8 +133,8 @@ def vm_and_miq_template_ancestry private - def shared_builder_params - add_builder_params(:ems_id => default_ems_id) + def add_common_default_values + add_default_values(:ems_id => default_ems_id) end def default_ems_id @@ -143,7 +143,6 @@ def default_ems_id def orchestration_stack_ancestry_save_block lambda do |_ems, inventory_collection| - stacks_inventory_collection = inventory_collection.dependency_attributes[:orchestration_stacks].try(:first) return if stacks_inventory_collection.blank? @@ -155,13 +154,12 @@ def orchestration_stack_ancestry_save_block model_class = stacks_inventory_collection.model_class - stacks_parents_indexed = model_class - .select(%i(id ancestry)) - .where(:id => stacks_parents.values).find_each.index_by(&:id) + stacks_parents_indexed = model_class.select(%i(id ancestry)) + .where(:id => stacks_parents.values).find_each.index_by(&:id) ActiveRecord::Base.transaction do model_class.select(%i(id ancestry)) - .where(:id => stacks_parents.keys).find_each do |stack| + .where(:id => stacks_parents.keys).find_each do |stack| parent = stacks_parents_indexed[stacks_parents[stack.id]] stack.update_attribute(:parent, parent) end @@ -194,11 +192,11 @@ def vm_and_miq_template_ancestry_save_block ActiveRecord::Base.transaction do # associate parent templates to child instances parent_miq_templates = miq_templates_inventory_collection.model_class - .select([:id]) - .where(:id => vms_genealogy_parents.values).find_each.index_by(&:id) + .select([:id]) + .where(:id => vms_genealogy_parents.values).find_each.index_by(&:id) vms_inventory_collection.model_class - .select([:id]) - .where(:id => vms_genealogy_parents.keys).find_each do |vm| + .select([:id]) + .where(:id => vms_genealogy_parents.keys).find_each do |vm| parent = parent_miq_templates[vms_genealogy_parents[vm.id]] vm.with_relationship_type('genealogy') { vm.parent = parent } end @@ -207,11 +205,11 @@ def vm_and_miq_template_ancestry_save_block ActiveRecord::Base.transaction do # associate parent instances to child templates parent_vms = vms_inventory_collection.model_class - .select([:id]) - .where(:id => miq_template_genealogy_parents.values).find_each.index_by(&:id) + .select([:id]) + .where(:id => miq_template_genealogy_parents.values).find_each.index_by(&:id) miq_templates_inventory_collection.model_class - .select([:id]) - .where(:id => miq_template_genealogy_parents.keys).find_each do |miq_template| + .select([:id]) + .where(:id => miq_template_genealogy_parents.keys).find_each do |miq_template| parent = parent_vms[miq_template_genealogy_parents[miq_template.id]] miq_template.with_relationship_type('genealogy') { miq_template.parent = parent } end diff --git a/app/models/manager_refresh/inventory_collection/builder/infra_manager.rb b/app/models/manager_refresh/inventory_collection/builder/infra_manager.rb index 7728c8091c0..beaec746e8d 100644 --- a/app/models/manager_refresh/inventory_collection/builder/infra_manager.rb +++ b/app/models/manager_refresh/inventory_collection/builder/infra_manager.rb @@ -61,11 +61,11 @@ def ems_folders :manager_ref => %i(uid_ems), :attributes_blacklist => %i(ems_children), ) - shared_builder_params + add_common_default_values end def datacenters - shared_builder_params + add_common_default_values end def resource_pools @@ -73,7 +73,7 @@ def resource_pools :manager_ref => %i(uid_ems), :attributes_blacklist => %i(ems_children), ) - shared_builder_params + add_common_default_values end def ems_clusters @@ -82,7 +82,7 @@ def ems_clusters ) add_inventory_attributes(%i(datacenter_id)) - shared_builder_params + add_common_default_values end def storages @@ -94,7 +94,7 @@ def storages end def hosts - shared_builder_params + add_common_default_values add_custom_reconnect_block( lambda do |inventory_collection, inventory_objects_index, attributes_index| @@ -203,8 +203,8 @@ def snapshot_parent private - def shared_builder_params - add_builder_params(:ems_id => default_ems_id) + def add_common_default_values + add_default_values(:ems_id => default_ems_id) end def default_ems_id diff --git a/app/models/manager_refresh/inventory_collection/builder/network_manager.rb b/app/models/manager_refresh/inventory_collection/builder/network_manager.rb index 622e68dff83..084b0917385 100644 --- a/app/models/manager_refresh/inventory_collection/builder/network_manager.rb +++ b/app/models/manager_refresh/inventory_collection/builder/network_manager.rb @@ -26,35 +26,35 @@ def network_ports :saver_strategy => :default ) - shared_builder_params + add_common_default_values end def network_groups - shared_builder_params + add_common_default_values end def network_routers - shared_builder_params + add_common_default_values end def floating_ips - shared_builder_params + add_common_default_values end def cloud_tenants - shared_builder_params + add_common_default_values end def cloud_subnets - shared_builder_params + add_common_default_values end def cloud_networks - shared_builder_params + add_common_default_values end def security_groups - shared_builder_params + add_common_default_values end def firewall_rules @@ -65,7 +65,7 @@ def firewall_rules end def load_balancers - shared_builder_params + add_common_default_values end def load_balancer_pools @@ -83,7 +83,7 @@ def load_balancer_pools end ) - shared_builder_params + add_common_default_values end def load_balancer_pool_members @@ -106,7 +106,7 @@ def load_balancer_pool_members end ) - shared_builder_params + add_common_default_values end def load_balancer_pool_member_pools @@ -142,7 +142,7 @@ def load_balancer_listeners end ) - shared_builder_params + add_common_default_values end def load_balancer_listener_pools @@ -177,7 +177,7 @@ def load_balancer_health_checks end ) - shared_builder_params + add_common_default_values end def load_balancer_health_check_members @@ -199,8 +199,8 @@ def load_balancer_health_check_members protected - def shared_builder_params - add_builder_params(:ems_id => default_ems_id) + def add_common_default_values + add_default_values(:ems_id => default_ems_id) end def default_ems_id diff --git a/app/models/manager_refresh/inventory_collection/builder/shared.rb b/app/models/manager_refresh/inventory_collection/builder/shared.rb index b0377deb066..a48456a1936 100644 --- a/app/models/manager_refresh/inventory_collection/builder/shared.rb +++ b/app/models/manager_refresh/inventory_collection/builder/shared.rb @@ -43,7 +43,7 @@ def vms def miq_templates vm_template_shared - add_builder_params( + add_default_values( :template => true ) end @@ -58,7 +58,7 @@ def vm_template_shared :custom_reconnect_block => INVENTORY_RECONNECT_BLOCK ) - add_builder_params( + add_default_values( :ems_id => ->(persister) { persister.manager.id } ) end From cc92de016754f0c0c12ffc8b1d4c0059b9e7afd4 Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Thu, 21 Jun 2018 16:02:18 +0200 Subject: [PATCH 03/12] Fixes IC automatic inventory_object attributes Derives attributes correctly if you specify model_class as param of add_collection() --- app/models/manager_refresh/inventory_collection/builder.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/manager_refresh/inventory_collection/builder.rb b/app/models/manager_refresh/inventory_collection/builder.rb index 4b853302c6b..379c7b5ae4b 100644 --- a/app/models/manager_refresh/inventory_collection/builder.rb +++ b/app/models/manager_refresh/inventory_collection/builder.rb @@ -72,7 +72,6 @@ def construct_data send(@name.to_sym) if respond_to?(@name.to_sym) - add_inventory_attributes(auto_inventory_attributes) if @options[:auto_inventory_attributes] end # Creates InventoryCollection @@ -125,6 +124,7 @@ def remove_inventory_attributes(array) # Clears all inventory object attributes def clear_inventory_attributes! + @options[:auto_inventory_attributes] = false @inventory_object_attributes = [] end @@ -153,6 +153,8 @@ def remove_dependency_attributes(key) # Returns whole InventoryCollection properties # TODO: default values converted to builder_params, change InventoryCollection and usages in next PR def to_hash + add_inventory_attributes(auto_inventory_attributes) if @options[:auto_inventory_attributes] + @properties.merge( :inventory_object_attributes => @inventory_object_attributes, :builder_params => @default_values, From 3f698f573d4b37d89bb828766d7e00c4f2b16794 Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Fri, 22 Jun 2018 10:58:41 +0200 Subject: [PATCH 04/12] IC Builder for Redfish Added support for PhysicalInfra - Redfish --- .../inventory_collection/builder.rb | 16 +++---- .../builder/persister_helper.rb | 5 ++ .../builder/physical_infra_manager.rb | 47 +++++++++++++++++++ 3 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 app/models/manager_refresh/inventory_collection/builder/physical_infra_manager.rb diff --git a/app/models/manager_refresh/inventory_collection/builder.rb b/app/models/manager_refresh/inventory_collection/builder.rb index 379c7b5ae4b..f0040a3dde2 100644 --- a/app/models/manager_refresh/inventory_collection/builder.rb +++ b/app/models/manager_refresh/inventory_collection/builder.rb @@ -4,10 +4,11 @@ class InventoryCollection class Builder class MissingModelClassError < StandardError; end + require_nested :AutomationManager require_nested :CloudManager require_nested :InfraManager - require_nested :AutomationManager require_nested :NetworkManager + require_nested :PhysicalInfraManager require_nested :StorageManager require_nested :PersisterHelper @@ -71,7 +72,6 @@ def construct_data add_properties(@shared_properties, :if_missing) send(@name.to_sym) if respond_to?(@name.to_sym) - end # Creates InventoryCollection @@ -236,13 +236,11 @@ def auto_inventory_attributes # @param values[Hash] # @param persister [ManagerRefresh::Inventory::Persister] def evaluate_lambdas_on(values, persister) - if values - values.transform_values do |value| - if value.respond_to?(:call) - value.call(persister) - else - value - end + values&.transform_values do |value| + if value.respond_to?(:call) + value.call(persister) + else + value end end end diff --git a/app/models/manager_refresh/inventory_collection/builder/persister_helper.rb b/app/models/manager_refresh/inventory_collection/builder/persister_helper.rb index 0cc6eed4f18..d1de0177626 100644 --- a/app/models/manager_refresh/inventory_collection/builder/persister_helper.rb +++ b/app/models/manager_refresh/inventory_collection/builder/persister_helper.rb @@ -61,6 +61,11 @@ def automation ::ManagerRefresh::InventoryCollection::Builder::AutomationManager end + # builder class for add_collection() + def physical_infra + ::ManagerRefresh::InventoryCollection::Builder::PhysicalInfraManager + end + # @param extra_settings [Hash] # :auto_inventory_attributes # - auto creates inventory_object_attributes from target model_class setters diff --git a/app/models/manager_refresh/inventory_collection/builder/physical_infra_manager.rb b/app/models/manager_refresh/inventory_collection/builder/physical_infra_manager.rb new file mode 100644 index 00000000000..a601f4d3424 --- /dev/null +++ b/app/models/manager_refresh/inventory_collection/builder/physical_infra_manager.rb @@ -0,0 +1,47 @@ +module ManagerRefresh + class InventoryCollection + class Builder + class PhysicalInfraManager < ::ManagerRefresh::InventoryCollection::Builder + def physical_servers + add_common_default_values + end + + def physical_server_details + add_properties( + :model_class => ::AssetDetail, + :manager_ref => %i(resource), + :parent_inventory_collections => %i(physical_servers) + ) + end + + def computer_systems + add_properties( + :manager_ref => %i(managed_entity), + :parent_inventory_collections => %i(physical_servers) + ) + end + + def hardwares + add_properties( + :manager_ref => %i(computer_system), + :parent_inventory_collections => %i(physical_servers) + ) + end + + def physical_racks + add_common_default_values + end + + def physical_chassis + add_common_default_values + end + + private + + def add_common_default_values + add_default_values(:ems_id => ->(persister) { persister.manager.id }) + end + end + end + end +end \ No newline at end of file From f73fb105df7f7e967b5a753579ef413dc9c4a6ec Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Fri, 22 Jun 2018 12:53:37 +0200 Subject: [PATCH 05/12] Link to documentation of add_collections() ` --- .../inventory_collection/builder/persister_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/manager_refresh/inventory_collection/builder/persister_helper.rb b/app/models/manager_refresh/inventory_collection/builder/persister_helper.rb index d1de0177626..9e8208416c7 100644 --- a/app/models/manager_refresh/inventory_collection/builder/persister_helper.rb +++ b/app/models/manager_refresh/inventory_collection/builder/persister_helper.rb @@ -19,7 +19,7 @@ module ManagerRefresh::InventoryCollection::Builder::PersisterHelper # ) # ) # - # @see ManagerRefresh::InventoryCollection::Builder + # @see documentation https://github.com/ManageIQ/guides/tree/master/providers/persister/inventory_collections.md # def add_collection(builder_class, collection_name, extra_properties = {}, settings = {}, &block) builder = builder_class.prepare_data(collection_name, From a459dcfce05b109acff50f10439e4f94e05b832c Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Mon, 25 Jun 2018 13:48:22 +0200 Subject: [PATCH 06/12] Support for Kubevirt's persister#add_collection() --- .../inventory_collection/builder/persister_helper.rb | 6 +++--- .../inventory_collection/builder/physical_infra_manager.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/manager_refresh/inventory_collection/builder/persister_helper.rb b/app/models/manager_refresh/inventory_collection/builder/persister_helper.rb index 9e8208416c7..6d07fbb008f 100644 --- a/app/models/manager_refresh/inventory_collection/builder/persister_helper.rb +++ b/app/models/manager_refresh/inventory_collection/builder/persister_helper.rb @@ -77,7 +77,7 @@ def physical_infra def make_builder_settings(extra_settings = {}) opts = ::ManagerRefresh::InventoryCollection::Builder.default_options - opts[:adv_settings] = options[:inventory_collections].try(:to_hash) || {} + opts[:adv_settings] = options.try(:[], :inventory_collections).try(:to_hash) || {} opts[:shared_properties] = shared_options opts[:auto_inventory_attributes] = true opts[:without_model_class] = false @@ -103,12 +103,12 @@ def shared_options # Returns list of target's ems_refs # @return [Array] def references(collection) - target.manager_refs_by_association.try(:[], collection).try(:[], :ems_ref).try(:to_a) || [] + target.try(:manager_refs_by_association).try(:[], collection).try(:[], :ems_ref).try(:to_a) || [] end # Returns list of target's name # @return [Array] def name_references(collection) - target.manager_refs_by_association.try(:[], collection).try(:[], :name).try(:to_a) || [] + target.try(:manager_refs_by_association).try(:[], collection).try(:[], :name).try(:to_a) || [] end end diff --git a/app/models/manager_refresh/inventory_collection/builder/physical_infra_manager.rb b/app/models/manager_refresh/inventory_collection/builder/physical_infra_manager.rb index a601f4d3424..3b02fa18544 100644 --- a/app/models/manager_refresh/inventory_collection/builder/physical_infra_manager.rb +++ b/app/models/manager_refresh/inventory_collection/builder/physical_infra_manager.rb @@ -44,4 +44,4 @@ def add_common_default_values end end end -end \ No newline at end of file +end From ca4076d7525d26ba9ad6289e84a3ef0c332dca08 Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Mon, 25 Jun 2018 15:40:18 +0200 Subject: [PATCH 07/12] Added IC definition from Ovirt --- .../inventory_collection/builder/infra_manager.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/models/manager_refresh/inventory_collection/builder/infra_manager.rb b/app/models/manager_refresh/inventory_collection/builder/infra_manager.rb index beaec746e8d..562ca11b0c3 100644 --- a/app/models/manager_refresh/inventory_collection/builder/infra_manager.rb +++ b/app/models/manager_refresh/inventory_collection/builder/infra_manager.rb @@ -56,6 +56,17 @@ def custom_attributes ) end + def vm_and_template_ems_custom_fields + @options[:auto_inventory_attributes] = false + + add_properties( + :model_class => ::CustomAttribute, + :manager_ref => %i(name) + ) + + add_inventory_attributes(%i(section name value source resource)) + end + def ems_folders add_properties( :manager_ref => %i(uid_ems), From cefcc34116d4b0e25f16da0846cf9247ea940a39 Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Mon, 2 Jul 2018 09:58:13 +0200 Subject: [PATCH 08/12] Added support for Container persisters --- .../builder/automation_manager.rb | 6 - .../builder/cloud_manager.rb | 8 - .../builder/container_manager.rb | 227 ++++++++++++++++++ .../builder/infra_manager.rb | 10 - .../builder/persister_helper.rb | 4 + .../builder/physical_infra_manager.rb | 6 - .../inventory_collection/builder/shared.rb | 7 + 7 files changed, 238 insertions(+), 30 deletions(-) create mode 100644 app/models/manager_refresh/inventory_collection/builder/container_manager.rb diff --git a/app/models/manager_refresh/inventory_collection/builder/automation_manager.rb b/app/models/manager_refresh/inventory_collection/builder/automation_manager.rb index afea37551bf..2be5c32d17b 100644 --- a/app/models/manager_refresh/inventory_collection/builder/automation_manager.rb +++ b/app/models/manager_refresh/inventory_collection/builder/automation_manager.rb @@ -51,12 +51,6 @@ def vms def default_manager_ref add_properties(:manager_ref => %i(manager_ref)) end - - def add_common_default_values - add_default_values( - :manager => ->(persister) { persister.manager } - ) - end end end end diff --git a/app/models/manager_refresh/inventory_collection/builder/cloud_manager.rb b/app/models/manager_refresh/inventory_collection/builder/cloud_manager.rb index 317755f518e..b7bca25350f 100644 --- a/app/models/manager_refresh/inventory_collection/builder/cloud_manager.rb +++ b/app/models/manager_refresh/inventory_collection/builder/cloud_manager.rb @@ -133,14 +133,6 @@ def vm_and_miq_template_ancestry private - def add_common_default_values - add_default_values(:ems_id => default_ems_id) - end - - def default_ems_id - ->(persister) { persister.manager.id } - end - def orchestration_stack_ancestry_save_block lambda do |_ems, inventory_collection| stacks_inventory_collection = inventory_collection.dependency_attributes[:orchestration_stacks].try(:first) diff --git a/app/models/manager_refresh/inventory_collection/builder/container_manager.rb b/app/models/manager_refresh/inventory_collection/builder/container_manager.rb new file mode 100644 index 00000000000..a7a889cdeb9 --- /dev/null +++ b/app/models/manager_refresh/inventory_collection/builder/container_manager.rb @@ -0,0 +1,227 @@ +module ManagerRefresh + class InventoryCollection + class Builder + class ContainerManager < ::ManagerRefresh::InventoryCollection::Builder + def container_projects + add_properties( + :secondary_refs => {:by_name => %i(name)}, + :delete_method => :disconnect_inv + ) + add_common_default_values + end + + def container_quotas + add_properties( + :attributes_blacklist => %i(namespace), + :delete_method => :disconnect_inv + ) + add_common_default_values + end + + def container_quota_scopes + add_properties( + :manager_ref => %i(container_quota scope) + ) + end + + def container_quota_items + add_properties( + :manager_ref => %i(container_quota resource quota_desired quota_enforced quota_observed), + :delete_method => :disconnect_inv + ) + end + + def container_limits + add_properties( + :attributes_blacklist => %i(namespace) + ) + add_common_default_values + end + + def container_limit_items + add_properties( + :manager_ref => %i(container_limit resource item_type) + ) + end + + def container_nodes + add_properties( + :model_class => ::ContainerNode, + :secondary_refs => {:by_name => %i(name)}, + :delete_method => :disconnect_inv + ) + add_common_default_values + end + + def computer_systems + add_properties(:manager_ref => %i(managed_entity)) + end + + def computer_system_hardwares + add_properties( + :model_class => ::Hardware, + :manager_ref => %i(computer_system) + ) + end + + def computer_system_operating_systems + add_properties( + :model_class => ::OperatingSystem, + :manager_ref => %i(computer_system) + ) + end + + # images have custom_attributes but that's done conditionally in openshift parser + def container_images + add_properties( + # TODO: (bpaskinc) old save matches on [:image_ref, :container_image_registry_id] + # TODO: (bpaskinc) should match on digest when available + :manager_ref => %i(image_ref), + :delete_method => :disconnect_inv, + :custom_reconnect_block => custom_reconnect_block + ) + add_common_default_values + end + + def container_image_registries + add_properties(:manager_ref => %i(host port)) + add_common_default_values + end + + def container_groups + add_properties( + :secondary_refs => {:by_container_project_and_name => %i(container_project name)}, + :attributes_blacklist => %i(namespace), + :delete_method => :disconnect_inv, + :custom_reconnect_block => custom_reconnect_block + ) + add_common_default_values + end + + def container_volumes + add_properties(:manager_ref => %i(parent name)) + end + + def containers + add_properties( + :delete_method => :disconnect_inv, + :custom_reconnect_block => custom_reconnect_block + ) + add_common_default_values + end + + def container_port_configs + # parser sets :ems_ref => "#{pod_id}_#{container_name}_#{port_config.containerPort}_#{port_config.hostPort}_#{port_config.protocol}" + end + + def container_env_vars + add_properties( + # TODO: (agrare) old save matches on all :name, :value, :field_path - does this matter? + :manager_ref => %i(container name) + ) + end + + def security_contexts + add_properties(:manager_ref => %i(resource)) + end + + def container_replicators + add_properties( + :secondary_refs => {:by_container_project_and_name => %i(container_project name)}, + :attributes_blacklist => %i(namespace) + ) + add_common_default_values + end + + def container_services + add_properties( + :secondary_refs => {:by_container_project_and_name => [:container_project, :name]}, + :attributes_blacklist => [:namespace], + :saver_strategy => "default" # TODO: (fryguy) (perf) Can't use batch strategy because of usage of M:N container_groups relation + ) + add_common_default_values + end + + def container_service_port_configs + add_properties(:manager_ref => %i(ems_ref protocol)) # TODO(lsmola) make protocol part of the ems_ref?) + end + + def container_routes + add_properties(:attributes_blacklist => %i(namespace)) + add_common_default_values + end + + def container_templates + add_properties(:attributes_blacklist => %i(namespace)) + add_common_default_values + end + + def container_template_parameters + add_properties(:manager_ref => %i(container_template name)) + end + + def container_builds + add_properties( + :secondary_refs => {:by_namespace_and_name => %i(namespace name)} + ) + add_common_default_values + end + + def container_build_pods + add_properties( + # TODO: (bpaskinc) convert namespace column -> container_project_id? + :manager_ref => %i(namespace name), + :secondary_refs => {:by_namespace_and_name => %i(namespace name)}, + ) + add_common_default_values + end + + def persistent_volumes + add_default_values(:parent => ->(persister) { persister.manager}) + end + + def persistent_volume_claims + add_properties( + :secondary_refs => {:by_container_project_and_name => %i(container_project name)}, + :attributes_blacklist => %i(namespace) + ) + add_common_default_values + end + protected + + def custom_reconnect_block + # TODO(lsmola) once we have DB unique indexes, we can stop using manual reconnect, since it adds processing time + lambda do |inventory_collection, inventory_objects_index, attributes_index| + relation = inventory_collection.model_class.where(:ems_id => inventory_collection.parent.id).archived + + # Skip reconnect if there are no archived entities + return if relation.archived.count <= 0 + raise "Allowed only manager_ref size of 1, got #{inventory_collection.manager_ref}" if inventory_collection.manager_ref.count > 1 + + inventory_objects_index.each_slice(1000) do |batch| + relation.where(inventory_collection.manager_ref.first => batch.map(&:first)).each do |record| + index = inventory_collection.object_index_with_keys(inventory_collection.manager_ref_to_cols, record) + + # We need to delete the record from the inventory_objects_index and attributes_index, otherwise it + # would be sent for create. + inventory_object = inventory_objects_index.delete(index) + hash = attributes_index.delete(index) + + # Make the entity active again, otherwise we would be duplicating nested entities + hash[:deleted_on] = nil + + record.assign_attributes(hash.except(:id, :type)) + if !inventory_collection.check_changed? || record.changed? + record.save! + inventory_collection.store_updated_records(record) + end + + inventory_object.id = record.id + end + end + end + end + end + end + end +end diff --git a/app/models/manager_refresh/inventory_collection/builder/infra_manager.rb b/app/models/manager_refresh/inventory_collection/builder/infra_manager.rb index 562ca11b0c3..9e85aa85c99 100644 --- a/app/models/manager_refresh/inventory_collection/builder/infra_manager.rb +++ b/app/models/manager_refresh/inventory_collection/builder/infra_manager.rb @@ -211,16 +211,6 @@ def snapshot_parent :custom_save_block => snapshot_parent_save_block ) end - - private - - def add_common_default_values - add_default_values(:ems_id => default_ems_id) - end - - def default_ems_id - ->(persister) { persister.manager.id } - end end end end diff --git a/app/models/manager_refresh/inventory_collection/builder/persister_helper.rb b/app/models/manager_refresh/inventory_collection/builder/persister_helper.rb index 6d07fbb008f..0dd9acf7f9e 100644 --- a/app/models/manager_refresh/inventory_collection/builder/persister_helper.rb +++ b/app/models/manager_refresh/inventory_collection/builder/persister_helper.rb @@ -66,6 +66,10 @@ def physical_infra ::ManagerRefresh::InventoryCollection::Builder::PhysicalInfraManager end + def container + ::ManagerRefresh::InventoryCollection::Builder::ContainerManager + end + # @param extra_settings [Hash] # :auto_inventory_attributes # - auto creates inventory_object_attributes from target model_class setters diff --git a/app/models/manager_refresh/inventory_collection/builder/physical_infra_manager.rb b/app/models/manager_refresh/inventory_collection/builder/physical_infra_manager.rb index 3b02fa18544..a7d655c828b 100644 --- a/app/models/manager_refresh/inventory_collection/builder/physical_infra_manager.rb +++ b/app/models/manager_refresh/inventory_collection/builder/physical_infra_manager.rb @@ -35,12 +35,6 @@ def physical_racks def physical_chassis add_common_default_values end - - private - - def add_common_default_values - add_default_values(:ems_id => ->(persister) { persister.manager.id }) - end end end end diff --git a/app/models/manager_refresh/inventory_collection/builder/shared.rb b/app/models/manager_refresh/inventory_collection/builder/shared.rb index a48456a1936..f5a74ec2a03 100644 --- a/app/models/manager_refresh/inventory_collection/builder/shared.rb +++ b/app/models/manager_refresh/inventory_collection/builder/shared.rb @@ -91,5 +91,12 @@ def disks :parent_inventory_collections => %i(vms) ) end + + protected + + def add_common_default_values + add_default_values(:ems_id => ->(persister) { persister.manager.id }) + end + end end From 5e180277c8ad538fdfd8ce00ec9609d27677464d Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Mon, 2 Jul 2018 14:51:08 +0200 Subject: [PATCH 09/12] Allowed IC association name as Array Kubernetes support --- .../manager_refresh/inventory_collection/builder.rb | 9 ++++++--- .../inventory_collection/builder/container_manager.rb | 9 +++++---- .../inventory_collection/builder/persister_helper.rb | 2 +- .../inventory_collection/builder/shared.rb | 1 - 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/models/manager_refresh/inventory_collection/builder.rb b/app/models/manager_refresh/inventory_collection/builder.rb index f0040a3dde2..8b0a0fff01a 100644 --- a/app/models/manager_refresh/inventory_collection/builder.rb +++ b/app/models/manager_refresh/inventory_collection/builder.rb @@ -29,7 +29,7 @@ def self.default_options # Entry point # Creates builder and builds data for inventory collection - # @param name [Symbol] InventoryCollection.association value + # @param name [Symbol || Array] InventoryCollection.association value. method not called when Array # (optional) method with this name also used for concrete inventory collection specific properties # @param persister_class [Class] used for "guessing" model_class # @param options [Hash] @@ -66,12 +66,15 @@ def initialize(name, persister_class, options = self.class.default_options) # Yields for overwriting provider-specific properties def construct_data add_properties(:association => @name) - add_properties(:model_class => auto_model_class) unless @options[:without_model_class] add_properties(@adv_settings, :if_missing) add_properties(@shared_properties, :if_missing) - send(@name.to_sym) if respond_to?(@name.to_sym) + send(@name.to_sym) if @name.respond_to?(:to_sym) && respond_to?(@name.to_sym) + + if @properties[:model_class].nil? + add_properties(:model_class => auto_model_class) unless @options[:without_model_class] + end end # Creates InventoryCollection diff --git a/app/models/manager_refresh/inventory_collection/builder/container_manager.rb b/app/models/manager_refresh/inventory_collection/builder/container_manager.rb index a7a889cdeb9..05a2441d892 100644 --- a/app/models/manager_refresh/inventory_collection/builder/container_manager.rb +++ b/app/models/manager_refresh/inventory_collection/builder/container_manager.rb @@ -26,7 +26,7 @@ def container_quota_scopes def container_quota_items add_properties( - :manager_ref => %i(container_quota resource quota_desired quota_enforced quota_observed), + :manager_ref => %i(container_quota resource quota_desired quota_enforced quota_observed), :delete_method => :disconnect_inv ) end @@ -135,7 +135,7 @@ def container_replicators def container_services add_properties( - :secondary_refs => {:by_container_project_and_name => [:container_project, :name]}, + :secondary_refs => {:by_container_project_and_name => %i(container_project name)}, :attributes_blacklist => [:namespace], :saver_strategy => "default" # TODO: (fryguy) (perf) Can't use batch strategy because of usage of M:N container_groups relation ) @@ -170,14 +170,14 @@ def container_builds def container_build_pods add_properties( # TODO: (bpaskinc) convert namespace column -> container_project_id? - :manager_ref => %i(namespace name), + :manager_ref => %i(namespace name), :secondary_refs => {:by_namespace_and_name => %i(namespace name)}, ) add_common_default_values end def persistent_volumes - add_default_values(:parent => ->(persister) { persister.manager}) + add_default_values(:parent => ->(persister) { persister.manager }) end def persistent_volume_claims @@ -187,6 +187,7 @@ def persistent_volume_claims ) add_common_default_values end + protected def custom_reconnect_block diff --git a/app/models/manager_refresh/inventory_collection/builder/persister_helper.rb b/app/models/manager_refresh/inventory_collection/builder/persister_helper.rb index 0dd9acf7f9e..d1c05b2e0a8 100644 --- a/app/models/manager_refresh/inventory_collection/builder/persister_helper.rb +++ b/app/models/manager_refresh/inventory_collection/builder/persister_helper.rb @@ -4,7 +4,7 @@ module ManagerRefresh::InventoryCollection::Builder::PersisterHelper # Interface for creating InventoryCollection under @collections # # @param builder_class [ManagerRefresh::InventoryCollection::Builder] or subclasses - # @param collection_name [Symbol] used as InventoryCollection:association + # @param collection_name [Symbol || Array] used as InventoryCollection:association # @param extra_properties [Hash] props from InventoryCollection.initialize list # - adds/overwrites properties added by builder # diff --git a/app/models/manager_refresh/inventory_collection/builder/shared.rb b/app/models/manager_refresh/inventory_collection/builder/shared.rb index f5a74ec2a03..59ce2f26719 100644 --- a/app/models/manager_refresh/inventory_collection/builder/shared.rb +++ b/app/models/manager_refresh/inventory_collection/builder/shared.rb @@ -97,6 +97,5 @@ def disks def add_common_default_values add_default_values(:ems_id => ->(persister) { persister.manager.id }) end - end end From 86d29e8dbe757313937d54d6fad0a86576496166 Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Tue, 3 Jul 2018 17:16:24 +0200 Subject: [PATCH 10/12] OpenShift IC definition fixes --- .../builder/container_manager.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/models/manager_refresh/inventory_collection/builder/container_manager.rb b/app/models/manager_refresh/inventory_collection/builder/container_manager.rb index 05a2441d892..40d9613378f 100644 --- a/app/models/manager_refresh/inventory_collection/builder/container_manager.rb +++ b/app/models/manager_refresh/inventory_collection/builder/container_manager.rb @@ -2,6 +2,7 @@ module ManagerRefresh class InventoryCollection class Builder class ContainerManager < ::ManagerRefresh::InventoryCollection::Builder + # TODO: (agrare) Targeted refreshes will require adjusting the associations / arels. (duh) def container_projects add_properties( :secondary_refs => {:by_name => %i(name)}, @@ -76,6 +77,8 @@ def container_images add_properties( # TODO: (bpaskinc) old save matches on [:image_ref, :container_image_registry_id] # TODO: (bpaskinc) should match on digest when available + # TODO: (mslemr) provider-specific class exists (openshift), but specs fail with them (?) + :model_class => ::ContainerImage, :manager_ref => %i(image_ref), :delete_method => :disconnect_inv, :custom_reconnect_block => custom_reconnect_block @@ -90,6 +93,7 @@ def container_image_registries def container_groups add_properties( + :model_class => ContainerGroup, :secondary_refs => {:by_container_project_and_name => %i(container_project name)}, :attributes_blacklist => %i(namespace), :delete_method => :disconnect_inv, @@ -104,6 +108,8 @@ def container_volumes def containers add_properties( + :model_class => Container, + # parser sets :ems_ref => "#{pod_id}_#{container.name}_#{container.image}" :delete_method => :disconnect_inv, :custom_reconnect_block => custom_reconnect_block ) @@ -136,14 +142,14 @@ def container_replicators def container_services add_properties( :secondary_refs => {:by_container_project_and_name => %i(container_project name)}, - :attributes_blacklist => [:namespace], + :attributes_blacklist => %i(namespace), :saver_strategy => "default" # TODO: (fryguy) (perf) Can't use batch strategy because of usage of M:N container_groups relation ) add_common_default_values end def container_service_port_configs - add_properties(:manager_ref => %i(ems_ref protocol)) # TODO(lsmola) make protocol part of the ems_ref?) + add_properties(:manager_ref => %i(ems_ref protocol)) # TODO: (lsmola) make protocol part of the ems_ref?) end def container_routes @@ -152,7 +158,10 @@ def container_routes end def container_templates - add_properties(:attributes_blacklist => %i(namespace)) + add_properties( + :model_class => ::ContainerTemplate, + :attributes_blacklist => %i(namespace) + ) add_common_default_values end From d9ed8487eb297c95229f73db6f0e8171e6405575 Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Wed, 4 Jul 2018 14:11:55 +0200 Subject: [PATCH 11/12] Yard fixes --- app/models/manager_refresh/inventory_collection/builder.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/manager_refresh/inventory_collection/builder.rb b/app/models/manager_refresh/inventory_collection/builder.rb index 8b0a0fff01a..ef05842bbbd 100644 --- a/app/models/manager_refresh/inventory_collection/builder.rb +++ b/app/models/manager_refresh/inventory_collection/builder.rb @@ -29,7 +29,7 @@ def self.default_options # Entry point # Creates builder and builds data for inventory collection - # @param name [Symbol || Array] InventoryCollection.association value. method not called when Array + # @param name [Symbol, Array] InventoryCollection.association value. method not called when Array # (optional) method with this name also used for concrete inventory collection specific properties # @param persister_class [Class] used for "guessing" model_class # @param options [Hash] @@ -236,7 +236,7 @@ def auto_inventory_attributes end # Evaluates lambda blocks in @default_values and @dependency_attributes - # @param values[Hash] + # @param values [Hash] # @param persister [ManagerRefresh::Inventory::Persister] def evaluate_lambdas_on(values, persister) values&.transform_values do |value| From f46fb659ea1df59445f4b53e5fbd226698650d37 Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Wed, 4 Jul 2018 14:36:52 +0200 Subject: [PATCH 12/12] IC Builder options skip methods For auto_inventory_attributes and without_model_class --- .../manager_refresh/inventory_collection/builder.rb | 12 ++++++++++++ .../inventory_collection/builder/cloud_manager.rb | 8 ++++---- .../inventory_collection/builder/infra_manager.rb | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/models/manager_refresh/inventory_collection/builder.rb b/app/models/manager_refresh/inventory_collection/builder.rb index ef05842bbbd..a2b7c4779c4 100644 --- a/app/models/manager_refresh/inventory_collection/builder.rb +++ b/app/models/manager_refresh/inventory_collection/builder.rb @@ -223,6 +223,12 @@ def auto_model_class end end + # Enables/disables auto_model_class and exception check + # @param skip [Boolean] + def skip_model_class(skip = true) + @options[:without_model_class] = skip + end + # Inventory object attributes are derived from setters # # Can be disabled by options :auto_inventory_attributes => false @@ -235,6 +241,12 @@ def auto_inventory_attributes end end + # Enables/disables auto_inventory_attributes + # @param skip [Boolean] + def skip_auto_inventory_attributes(skip = true) + @options[:auto_inventory_attributes] = !skip + end + # Evaluates lambda blocks in @default_values and @dependency_attributes # @param values [Hash] # @param persister [ManagerRefresh::Inventory::Persister] diff --git a/app/models/manager_refresh/inventory_collection/builder/cloud_manager.rb b/app/models/manager_refresh/inventory_collection/builder/cloud_manager.rb index b7bca25350f..d18ed77147e 100644 --- a/app/models/manager_refresh/inventory_collection/builder/cloud_manager.rb +++ b/app/models/manager_refresh/inventory_collection/builder/cloud_manager.rb @@ -103,8 +103,8 @@ def orchestration_templates end def orchestration_stack_ancestry - @options[:auto_inventory_attributes] = false - @options[:without_model_class] = true + skip_auto_inventory_attributes + skip_model_class add_properties( :custom_save_block => orchestration_stack_ancestry_save_block @@ -117,8 +117,8 @@ def orchestration_stack_ancestry end def vm_and_miq_template_ancestry - @options[:auto_inventory_attributes] = false - @options[:without_model_class] = true + skip_auto_inventory_attributes + skip_model_class add_properties( :custom_save_block => vm_and_miq_template_ancestry_save_block diff --git a/app/models/manager_refresh/inventory_collection/builder/infra_manager.rb b/app/models/manager_refresh/inventory_collection/builder/infra_manager.rb index 9e85aa85c99..8493ce52403 100644 --- a/app/models/manager_refresh/inventory_collection/builder/infra_manager.rb +++ b/app/models/manager_refresh/inventory_collection/builder/infra_manager.rb @@ -57,7 +57,7 @@ def custom_attributes end def vm_and_template_ems_custom_fields - @options[:auto_inventory_attributes] = false + skip_auto_inventory_attributes add_properties( :model_class => ::CustomAttribute,