diff --git a/app/models/manageiq/providers/kubernetes/inventory/persister/definitions/container_collections.rb b/app/models/manageiq/providers/kubernetes/inventory/persister/definitions/container_collections.rb index dbd8e159ee..d897439ee2 100644 --- a/app/models/manageiq/providers/kubernetes/inventory/persister/definitions/container_collections.rb +++ b/app/models/manageiq/providers/kubernetes/inventory/persister/definitions/container_collections.rb @@ -91,23 +91,38 @@ def initialize_taggings # @param manager [ExtManagementSystem] # @param association [Symbol] def add_container_conditions(manager, association) + parent_collection = @collections[association] + relation = manager.public_send(association) query = ContainerCondition.where( :container_entity_type => relation.model.base_class.name, - :container_entity_id => relation, # nested SELECT. TODO: compare to a JOIN. + :container_entity_id => relation, # TODO(lsmola): JOIN will be much better, should be defined as relation ) + targeted_arel = lambda do |inventory_collection| + # TODO(lsmola): if we use :association ^ instead of :arel, this can be autogenerated + p_collection = inventory_collection.parent_inventory_collections.first + rel = p_collection.db_collection_for_comparison_for(p_collection.targeted_scope.primary_references) + + ContainerCondition.where( + :container_entity_type => rel.model.base_class.name, + :container_entity_id => rel, + ) + end + add_collection(container, [:container_conditions_for, relation.model.base_class.name], {}, {:auto_inventory_attributes => false}) do |builder| builder.add_properties( - :model_class => ContainerCondition, - :association => nil, - :name => "container_conditions_for_#{association}".to_sym, - :arel => query, - :manager_ref => %i(container_entity name), + :model_class => ContainerCondition, + :association => nil, + :name => "container_conditions_for_#{association}".to_sym, + :arel => query, + :targeted_arel => targeted_arel, + :manager_ref => %i(container_entity name), + :parent_inventory_collections => [parent_collection.name], ) end end @@ -124,16 +139,29 @@ def add_custom_attributes(parent, sections) sections.each do |section| query = ::CustomAttribute.where( :resource_type => type, - :resource_id => relation, + :resource_id => relation, # TODO(lsmola): JOIN will be much better, should be defined as relation :section => section.to_s ) + targeted_arel = lambda do |inventory_collection| + # TODO(lsmola): if we use :association ^ instead of :arel, this can be autogenerated + p_collection = inventory_collection.parent_inventory_collections.first + rel = p_collection.db_collection_for_comparison_for(p_collection.targeted_scope.primary_references) + + CustomAttribute.where( + :resource_type => rel.model.base_class.name, + :resource_id => rel, + :section => section.to_s + ) + end + add_collection(container, [:custom_attributes_for, type, section.to_s], {}, { :auto_inventory_attributes => false }) do |builder| builder.add_properties( :model_class => ::CustomAttribute, :association => nil, :name => "custom_attributes_for_#{parent_collection.name}_#{section}".to_sym, :arel => query, + :targeted_arel => targeted_arel, :manager_ref => %i(resource section name), :parent_inventory_collections => [parent_collection.name], ) @@ -149,15 +177,27 @@ def add_taggings(parent_name) query = Tagging.where( :taggable_type => type, - :taggable_id => relation, + :taggable_id => relation, # TODO(lsmola): JOIN will be much better, should be defined as relation ).joins(:tag).merge(Tag.controlled_by_mapping) + targeted_arel = lambda do |inventory_collection| + # TODO(lsmola): if we use :association ^ instead of :arel, this can be autogenerated + p_collection = inventory_collection.parent_inventory_collections.first + rel = p_collection.db_collection_for_comparison_for(p_collection.targeted_scope.primary_references) + + Tagging.where( + :taggable_type => type, + :taggable_id => rel, + ).joins(:tag).merge(Tag.controlled_by_mapping) + end + add_collection(container, [:taggings_for, type], {}, {:auto_inventory_attributes => false}) do |builder| builder.add_properties( :model_class => ::Tagging, :association => nil, :name => "taggings_for_#{parent_collection.name}".to_sym, :arel => query, + :targeted_arel => targeted_arel, :manager_ref => %i(taggable tag), :parent_inventory_collections => [parent_collection.name], ) diff --git a/app/models/manageiq/providers/kubernetes/inventory/persister/target_collection.rb b/app/models/manageiq/providers/kubernetes/inventory/persister/target_collection.rb index 9c9e6b1c3a..e9cfc14e26 100644 --- a/app/models/manageiq/providers/kubernetes/inventory/persister/target_collection.rb +++ b/app/models/manageiq/providers/kubernetes/inventory/persister/target_collection.rb @@ -1,15 +1,9 @@ class ManageIQ::Providers::Kubernetes::Inventory::Persister::TargetCollection < ManageIQ::Providers::Kubernetes::Inventory::Persister::ContainerManager def targeted? - false # TODO(lsmola) get ready for true, which means a proper targeted refresh. That will require more effort. + true end - def shared_options - { - :targeted => targeted?, - :complete => false, # For now, we want to a only create and update elements using watches data, delete events could - # probably set finished_at and deleted_on dates, as an update based disconnect_inv. - :strategy => :local_db_find_missing_references, # By default no IC will be saved - :parent => manager.presence - } + def strategy + :local_db_find_missing_references end end