Skip to content

Commit

Permalink
Correct targeted_arel joined with load_balancer
Browse files Browse the repository at this point in the history
Correct targeted_arel joined with load_balancer. For AWS,
it was ok to join to pool, which had the same ems_ref as lb.
But for Azure, the pool has different ems_ref, so we need to
correctly join every table to load_balancers table and filter there

Partially fixes
https://bugzilla.redhat.com/show_bug.cgi?id=1487602
  • Loading branch information
Ladas committed Feb 28, 2018
1 parent 431dd0e commit 55c7163
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
1 change: 1 addition & 0 deletions app/models/load_balancer_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class LoadBalancerPool < ApplicationRecord

has_many :load_balancer_listener_pools, :dependent => :destroy
has_many :load_balancer_listeners, :through => :load_balancer_listener_pools
has_many :load_balancers, :through => :load_balancer_listeners
has_many :load_balancer_pool_member_pools, :dependent => :destroy
has_many :load_balancer_pool_members, :through => :load_balancer_pool_member_pools

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ def load_balancer_pools(extra_attributes = {})

attributes[:targeted_arel] = lambda do |inventory_collection|
manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a }
inventory_collection.parent.load_balancer_pools.where(:ems_ref => manager_uuids)
inventory_collection.parent.load_balancer_pools
.joins(:load_balancers)
.where(:load_balancers => {:ems_ref => manager_uuids})
.distinct
end

attributes.merge!(extra_attributes)
Expand All @@ -135,9 +138,14 @@ def load_balancer_pool_members(extra_attributes = {})
attributes[:targeted_arel] = lambda do |inventory_collection|
manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a }
inventory_collection.parent.load_balancer_pool_members
.joins(:load_balancer_pool_member_pools => :load_balancler_pool)
.where(:load_balancer_pool_member_pools => {'load_balancer_pools' => {:ems_ref => manager_uuids}})
.distinct
.joins(:load_balancer_pool_member_pools => [:load_balancer_pool => :load_balancers])
.where(:load_balancer_pool_member_pools => {
'load_balancer_pools' => {
'load_balancers' => {
:ems_ref => manager_uuids
}
}
}).distinct
end

attributes.merge!(extra_attributes)
Expand All @@ -154,8 +162,8 @@ def load_balancer_pool_member_pools(extra_attributes = {})
attributes[:targeted_arel] = lambda do |inventory_collection|
manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a }
inventory_collection.parent.load_balancer_pool_member_pools
.references(:load_balancer_pools)
.where(:load_balancer_pools => {:ems_ref => manager_uuids})
.joins(:load_balancer_pool => :load_balancers)
.where(:load_balancer_pools => {'load_balancers' => {:ems_ref => manager_uuids}})
.distinct
end

Expand All @@ -175,9 +183,10 @@ def load_balancer_listeners(extra_attributes = {})

attributes[:targeted_arel] = lambda do |inventory_collection|
manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a }
inventory_collection.parent.load_balancer_listeners.joins(:load_balancer).where(
:load_balancers => {:ems_ref => manager_uuids}
)
inventory_collection.parent.load_balancer_listeners
.joins(:load_balancer)
.where(:load_balancers => {:ems_ref => manager_uuids})
.distinct
end

attributes.merge!(extra_attributes)
Expand All @@ -193,9 +202,10 @@ def load_balancer_listener_pools(extra_attributes = {})

attributes[:targeted_arel] = lambda do |inventory_collection|
manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a }
inventory_collection.parent.load_balancer_listener_pools.joins(:load_balancer_pool).where(
:load_balancer_pools => {:ems_ref => manager_uuids}
)
inventory_collection.parent.load_balancer_listener_pools
.joins(:load_balancer_pool => :load_balancers)
.where(:load_balancer_pools => {'load_balancers' => {:ems_ref => manager_uuids}})
.distinct
end

attributes.merge!(extra_attributes)
Expand All @@ -213,7 +223,10 @@ def load_balancer_health_checks(extra_attributes = {})

attributes[:targeted_arel] = lambda do |inventory_collection|
manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a }
inventory_collection.parent.load_balancer_health_checks.where(:ems_ref => manager_uuids)
inventory_collection.parent.load_balancer_health_checks
.joins(:load_balancer)
.where(:load_balancers => {:ems_ref => manager_uuids})
.distinct
end

attributes.merge!(extra_attributes)
Expand All @@ -229,9 +242,10 @@ def load_balancer_health_check_members(extra_attributes = {})

attributes[:targeted_arel] = lambda do |inventory_collection|
manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a }
inventory_collection.parent.load_balancer_health_check_members.references(:load_balancer_health_checks).where(
:load_balancer_health_checks => {:ems_ref => manager_uuids}
)
inventory_collection.parent.load_balancer_health_check_members
.joins(:load_balancer_health_check => :load_balancer)
.where(:load_balancer_health_checks => {'load_balancers' => {:ems_ref => manager_uuids}})
.distinct
end

attributes.merge!(extra_attributes)
Expand Down

0 comments on commit 55c7163

Please sign in to comment.