Class: Katello::Candlepin::PoolService

Inherits:
Object
  • Object
show all
Defined in:
app/services/katello/candlepin/pool_service.rb

Class Method Summary collapse

Class Method Details

.local_to_upstream_ids(local_pool_ids, fail_on_not_found: true) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/services/katello/candlepin/pool_service.rb', line 10

def self.local_to_upstream_ids(local_pool_ids, fail_on_not_found: true)
  pools = Katello::Pool.where(id: local_pool_ids)
  id_map = Hash.new { |hash, key| hash[key] = [] }

  pools.each do |pool|
    if fail_on_not_found && !pool.upstream_pool_id
      fail 'No upstream pool ID was found for Katello::Pool with ID: %s' % pool.id
    end
    id_map[pool.upstream_pool_id] << pool.id
  end

  id_map
end

.map_upstream_pools_to_local(pools) ⇒ Object

For mapping the upstream pools after the candlepin request has returned them



25
26
27
28
29
# File 'app/services/katello/candlepin/pool_service.rb', line 25

def self.map_upstream_pools_to_local(pools)
  upstream_pool_ids = pools.map { |x| x['id'] }
  local_pool_ids = Katello::Pool.where(upstream_pool_id: upstream_pool_ids).pluck(:id)
  return upstream_pool_id_map(local_pool_ids, fail_on_not_found: false)
end

.upstream_pool_id_map(local_pool_ids, fail_on_not_found: true) ⇒ Object



4
5
6
7
8
# File 'app/services/katello/candlepin/pool_service.rb', line 4

def self.upstream_pool_id_map(local_pool_ids, fail_on_not_found: true)
  return {} unless local_pool_ids

  local_to_upstream_ids(local_pool_ids, fail_on_not_found: fail_on_not_found)
end