Module: Glue::Candlepin::Pool::ClassMethods

Defined in:
app/models/katello/glue/candlepin/pool.rb

Instance Method Summary collapse

Instance Method Details

#candlepin_data(cp_id, rescue_gone = false) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/katello/glue/candlepin/pool.rb', line 30

def candlepin_data(cp_id, rescue_gone = false)
  Katello::Resources::Candlepin::Pool.find(cp_id)
rescue Katello::Errors::CandlepinPoolGone => e
  raise e unless rescue_gone

  if (pool_id = ::Katello::Pool.find_by_cp_id(cp_id)&.id)
    Katello::EventQueue.push_event(::Katello::Events::DeletePool::EVENT_TYPE, pool_id)
    Rails.logger.warn("Sending pool delete event for missing candlepin pool cp_id=#{cp_id}")
  end
  {}
end

#determine_subscription(product_id: nil, source_stack_id: nil, organization:) ⇒ Object



77
78
79
80
81
82
83
84
# File 'app/models/katello/glue/candlepin/pool.rb', line 77

def determine_subscription(product_id: nil, source_stack_id: nil, organization:)
  if source_stack_id
    self.stacking_subscription(organization, source_stack_id)
    # isn't it an error if we have a sourceStackID but no stacking subscription?
  else
    ::Katello::Subscription.find_by(:cp_id => product_id, organization: organization)
  end
end

#get_for_owner(organization) ⇒ Object



42
43
44
# File 'app/models/katello/glue/candlepin/pool.rb', line 42

def get_for_owner(organization)
  Katello::Resources::Candlepin::Pool.get_for_owner(organization, true)
end

#import_candlepin_record(record:, organization:) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
# File 'app/models/katello/glue/candlepin/pool.rb', line 65

def import_candlepin_record(record:, organization:)
  subscription = determine_subscription(
    product_id: record['productId'],
    source_stack_id: record['sourceStackId'],
    organization: organization
  )

  super do |attrs|
    attrs[:subscription] = subscription
  end
end

#import_candlepin_records(pools, org) ⇒ Object



59
60
61
62
63
# File 'app/models/katello/glue/candlepin/pool.rb', line 59

def import_candlepin_records(pools, org)
  # Skip import of pools that were associated with an orphaned custom product
  pools = pools.reject { |cp_pool| ::Katello::Glue::Provider.orphaned_custom_product?(cp_pool['productId'], org) }
  super(pools, org)
end

#import_pool(cp_pool_id, index_hosts = true) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/katello/glue/candlepin/pool.rb', line 46

def import_pool(cp_pool_id, index_hosts = true)
  Katello::Logging.time("import candlepin pool", data: { cp_id: cp_pool_id }) do
    json = candlepin_data(cp_pool_id)

    org = Organization.find_by(label: json['owner']['key'])
    fail("Organization with label #{json['owner']['key']} wasn't found while importing Candlepin pool") unless org

    pool = import_candlepin_record(record: json, organization: org)
    pool.backend_data = json
    pool.import_data(index_hosts)
  end
end

#stacking_subscription(org, stacking_id) ⇒ Object



86
87
88
89
90
91
92
93
# File 'app/models/katello/glue/candlepin/pool.rb', line 86

def stacking_subscription(org, stacking_id)
  subscription = ::Katello::Subscription.find_by(:organization_id => org.id, :cp_id => stacking_id)
  if subscription.nil?
    found_product = ::Katello::Resources::Candlepin::Product.find_for_stacking_id(org.label, stacking_id)
    subscription = ::Katello::Subscription.find_by(:organization_id => org.id, :cp_id => found_product['id']) if found_product
  end
  subscription
end