Skip to content

Commit

Permalink
Merge pull request #272 from Ladas/allow_proper_targeted_refresh
Browse files Browse the repository at this point in the history
Allow proper targeted refresh
  • Loading branch information
cben authored Aug 14, 2018
2 parents 0968969 + 995524e commit 815c2fa
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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],
)
Expand All @@ -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],
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 815c2fa

Please sign in to comment.