-
Notifications
You must be signed in to change notification settings - Fork 63
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
Allow proper targeted refresh #272
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
||
query = Tagging.where( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the |
||
: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], | ||
) | ||
|
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this deleted? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's defined in the base persister |
||
{ | ||
: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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this distinct from
parent_collection
defined above?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be the same, but it's safer to load it from the inventory_collection context