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

Graph refresh: links between entities #52

Merged
merged 1 commit into from
Jul 11, 2017
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,28 @@ def initialize_inventory_collections(ems)
:model_class => ContainerProject,
:parent => ems,
:builder_params => {:ems_id => ems.id},
:association => :container_projects
:association => :container_projects,
:secondary_refs => {:by_name => [:name]},
)
@inv_collections[:container_quotas] = ::ManagerRefresh::InventoryCollection.new(
:model_class => ContainerQuota,
:parent => ems,
:builder_params => {:ems_id => ems.id},
:association => :container_quotas,
#:arel => ContainerQuota.joins(:container_project).where(:container_projects => {:ems_id => ems.id}),
:model_class => ContainerQuota,
:parent => ems,
:builder_params => {:ems_id => ems.id},
:association => :container_quotas,
:attributes_blacklist => [:namespace],
)
@inv_collections[:container_quota_items] = ::ManagerRefresh::InventoryCollection.new(
:model_class => ContainerQuotaItem,
:parent => ems,
:association => :container_quota_items,
#:arel => ContainerQuotaItem.joins(:container_quota => :container_project).where(:container_projects => {:ems_id => ems.id}),
:manager_ref => [:container_quota, :resource],
)
@inv_collections[:container_limits] = ::ManagerRefresh::InventoryCollection.new(
:model_class => ContainerLimit,
:parent => ems,
:builder_params => {:ems_id => ems.id},
:association => :container_limits,
:model_class => ContainerLimit,
:parent => ems,
:builder_params => {:ems_id => ems.id},
:association => :container_limits,
:attributes_blacklist => [:namespace],
)
@inv_collections[:container_limit_items] = ::ManagerRefresh::InventoryCollection.new(
:model_class => ContainerLimitItem,
Expand All @@ -39,7 +40,10 @@ def initialize_inventory_collections(ems)
:parent => ems,
:builder_params => {:ems_id => ems.id},
:association => :container_nodes,
:secondary_refs => {:by_name => [:name]},
)
initialize_container_conditions_collection(ems.container_nodes)
initialize_custom_attributes_collections(ems.container_nodes, %w(labels additional_attributes))

# polymorphic child of ContainerNode & ContainerImage,
# but refresh only sets it on nodes.
Expand Down Expand Up @@ -79,16 +83,22 @@ def initialize_inventory_collections(ems)
:parent => ems,
:builder_params => {:ems_id => ems.id},
:association => :container_images,
:manager_ref => [:image_ref, :container_image_registry],
# TODO: old save matches on [:image_ref, :container_image_registry_id]
# TODO: should match on digest when available
:manager_ref => [:image_ref],
)

@inv_collections[:container_groups] =
::ManagerRefresh::InventoryCollection.new(
:model_class => ContainerGroup,
:parent => ems,
:builder_params => {:ems_id => ems.id},
:association => :container_groups,
:model_class => ContainerGroup,
:parent => ems,
:builder_params => {:ems_id => ems.id},
:association => :container_groups,
:secondary_refs => {:by_namespace_and_name => [:namespace, :name]},
:attributes_blacklist => [:namespace],
)
initialize_container_conditions_collection(ems.container_groups)
initialize_custom_attributes_collections(ems.container_groups, %w(labels node_selectors))
@inv_collections[:container_definitions] =
::ManagerRefresh::InventoryCollection.new(
:model_class => ContainerDefinition,
Expand Down Expand Up @@ -137,18 +147,25 @@ def initialize_inventory_collections(ems)

@inv_collections[:container_replicators] =
::ManagerRefresh::InventoryCollection.new(
:model_class => ContainerReplicator,
:parent => ems,
:builder_params => {:ems_id => ems.id},
:association => :container_replicators,
:model_class => ContainerReplicator,
:parent => ems,
:builder_params => {:ems_id => ems.id},
:association => :container_replicators,
:secondary_refs => {:by_namespace_and_name => [:namespace, :name]},
:attributes_blacklist => [:namespace],
)
initialize_custom_attributes_collections(ems.container_replicators, %w(labels selectors))

@inv_collections[:container_services] =
::ManagerRefresh::InventoryCollection.new(
:model_class => ContainerService,
:parent => ems,
:builder_params => {:ems_id => ems.id},
:association => :container_services,
:model_class => ContainerService,
:parent => ems,
:builder_params => {:ems_id => ems.id},
:association => :container_services,
:secondary_refs => {:by_namespace_and_name => [:namespace, :name]},
:attributes_blacklist => [:namespace],
)
initialize_custom_attributes_collections(ems.container_services, %w(labels selectors))
@inv_collections[:container_service_port_configs] =
::ManagerRefresh::InventoryCollection.new(
:model_class => ContainerServicePortConfig,
Expand All @@ -172,10 +189,11 @@ def initialize_inventory_collections(ems)
)
@inv_collections[:container_templates] =
::ManagerRefresh::InventoryCollection.new(
:model_class => ContainerTemplate,
:parent => ems,
:builder_params => {:ems_id => ems.id},
:association => :container_templates,
:model_class => ContainerTemplate,
:parent => ems,
:builder_params => {:ems_id => ems.id},
:association => :container_templates,
:attributes_blacklist => [:namespace],
)
@inv_collections[:container_template_parameters] =
::ManagerRefresh::InventoryCollection.new(
Expand All @@ -199,7 +217,7 @@ def initialize_inventory_collections(ems)
:association => :container_build_pods,
# TODO: is this unique? build pods do have uid that becomes ems_ref,
# but we need lazy_find by name for lookup from container_group
# TODO rename namespace -> container_project column?
# TODO: rename namespace -> container_project column?
:manager_ref => [:namespace, :name],
)
@inv_collections[:persistent_volumes] =
Expand All @@ -217,4 +235,32 @@ def initialize_inventory_collections(ems)
:association => :persistent_volume_claims,
)
end

# ContainerCondition is polymorphic child of ContainerNode & ContainerGroup.
def initialize_container_conditions_collection(relation)
query = ContainerCondition.where(
:container_entity_type => relation.model.name,
:container_entity_id => relation, # nested SELECT. TODO: compare to a JOIN.
)
@inv_collections[[:container_conditions_for, relation.model.name]] =
::ManagerRefresh::InventoryCollection.new(
:model_class => ContainerCondition,
:arel => query,
:manager_ref => [:container_entity, :name],
)
end

# CustomAttribute is polymorphic child of many models
def initialize_custom_attributes_collections(relation, sections)
sections.each do |section|
query = CustomAttribute.where(:resource_type => relation.model.name,
:resource_id => relation,
:section => section.to_s)
@inv_collections[[:custom_attributes_for, relation.model.name, section]] = ::ManagerRefresh::InventoryCollection.new(
:model_class => CustomAttribute,
:arel => query,
:manager_ref => [:resource, :section, :name],
)
end
end
end
Loading