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) ⇒ Object



17
18
19
# File 'app/models/katello/glue/candlepin/pool.rb', line 17

def candlepin_data(cp_id)
  Katello::Resources::Candlepin::Pool.find(cp_id)
end

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



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

def determine_subscription(organization:, product_id: nil, source_stack_id: nil)
  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



21
22
23
# File 'app/models/katello/glue/candlepin/pool.rb', line 21

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

#import_candlepin_record(record:, organization:) ⇒ Object



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

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



38
39
40
41
42
# File 'app/models/katello/glue/candlepin/pool.rb', line 38

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) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/katello/glue/candlepin/pool.rb', line 25

def import_pool(cp_pool_id)
  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
  end
end

#stacking_subscription(org, stacking_id) ⇒ Object



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

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