Class: Katello::Candlepin::MessageHandler
- Inherits:
-
Object
- Object
- Katello::Candlepin::MessageHandler
- Defined in:
- app/services/katello/candlepin/message_handler.rb
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Service to handle parsing the messages we receive from candlepin.
-
#pool ⇒ Object
readonly
Service to handle parsing the messages we receive from candlepin.
-
#subscription_facet ⇒ Object
readonly
Service to handle parsing the messages we receive from candlepin.
Instance Method Summary collapse
- #consumer_uuid ⇒ Object
- #content ⇒ Object
- #create_pool_on_host ⇒ Object
- #delete_pool ⇒ Object
- #entity_id ⇒ Object
- #event_data ⇒ Object
- #handle_content_access_mode_modified ⇒ Object
- #import_pool(index_hosts = true) ⇒ Object
-
#initialize(message) ⇒ MessageHandler
constructor
A new instance of MessageHandler.
- #pool_id ⇒ Object
- #reasons ⇒ Object
- #remove_pool_from_host ⇒ Object
- #status ⇒ Object
- #subject ⇒ Object
- #system_purpose ⇒ Object
- #target_name ⇒ Object
Constructor Details
#initialize(message) ⇒ MessageHandler
7 8 9 10 11 |
# File 'app/services/katello/candlepin/message_handler.rb', line 7 def initialize() = @subscription_facet = ::Katello::Host::SubscriptionFacet.find_by_uuid(consumer_uuid) if consumer_uuid @pool = ::Katello::Pool.find_by_cp_id(pool_id) if pool_id end |
Instance Attribute Details
#message ⇒ Object (readonly)
Service to handle parsing the messages we receive from candlepin
5 6 7 |
# File 'app/services/katello/candlepin/message_handler.rb', line 5 def end |
#pool ⇒ Object (readonly)
Service to handle parsing the messages we receive from candlepin
5 6 7 |
# File 'app/services/katello/candlepin/message_handler.rb', line 5 def pool @pool end |
#subscription_facet ⇒ Object (readonly)
Service to handle parsing the messages we receive from candlepin
5 6 7 |
# File 'app/services/katello/candlepin/message_handler.rb', line 5 def subscription_facet @subscription_facet end |
Instance Method Details
#consumer_uuid ⇒ Object
41 42 43 |
# File 'app/services/katello/candlepin/message_handler.rb', line 41 def consumer_uuid content['consumerUuid'] end |
#content ⇒ Object
17 18 19 |
# File 'app/services/katello/candlepin/message_handler.rb', line 17 def content @content ||= JSON.parse(.content) end |
#create_pool_on_host ⇒ Object
60 61 62 63 64 65 66 |
# File 'app/services/katello/candlepin/message_handler.rb', line 60 def create_pool_on_host return if self.subscription_facet.nil? || pool.nil? old_host_ids = subscription_facet_host_ids ::Katello::SubscriptionFacetPool.where(subscription_facet_id: self.subscription_facet.id, pool_id: pool.id).first_or_create pool.import_audit_record(old_host_ids) end |
#delete_pool ⇒ Object
90 91 92 93 94 |
# File 'app/services/katello/candlepin/message_handler.rb', line 90 def delete_pool if Katello::Pool.where(:cp_id => pool_id).destroy_all.any? Rails.logger.info "Deleted Katello::Pool with cp_id=#{pool_id}" end end |
#entity_id ⇒ Object
25 26 27 |
# File 'app/services/katello/candlepin/message_handler.rb', line 25 def entity_id content['entityId'] end |
#event_data ⇒ Object
21 22 23 |
# File 'app/services/katello/candlepin/message_handler.rb', line 21 def event_data @event_data ||= (data = content['eventData']) ? JSON.parse(data) : {} end |
#handle_content_access_mode_modified ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'app/services/katello/candlepin/message_handler.rb', line 96 def handle_content_access_mode_modified # Ideally the target_name would be the Candlepin Owner key # Since it's the displayName, and we don't update that after org creation, there could be a mismatch # For now, find the Candlepin Owner displayName from this event, and tie it back to a Katello org based on owner key owners = Katello::Resources::Candlepin::Owner.all owner = owners.find { |o| o['displayName'] == target_name } unless owner fail("Candlepin Owner %s could not be found" % target_name) end org = ::Organization.find_by!(label: owner['key']) hosts = org.hosts if event_data['contentAccessMode'] == 'org_environment' Katello::HostStatusManager.clear_syspurpose_status(hosts) Katello::HostStatusManager.update_subscription_status_to_sca(hosts) elsif event_data['contentAccessMode'] == 'entitlement' cp_consumer_uuids = hosts.joins(:subscription_facet).pluck("#{Katello::Host::SubscriptionFacet.table_name}.uuid") cp_consumer_uuids.each do |uuid| Katello::Resources::Candlepin::Consumer.compliance(uuid) Katello::Resources::Candlepin::Consumer.purpose_compliance(uuid) rescue => e Rails.logger.error("Error encountered while fetching compliance for consumer #{uuid}: #{e.message}") end end org.simple_content_access?(cached: false) end |
#import_pool(index_hosts = true) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/services/katello/candlepin/message_handler.rb', line 76 def import_pool(index_hosts = true) if pool ::Katello::EventQueue.push_event(::Katello::Events::ImportPool::EVENT_TYPE, pool.id) else begin ::Katello::Pool.import_pool(pool_id, index_hosts) rescue ActiveRecord::RecordInvalid # if we hit this block it's likely that the pool's subscription, product are being created # as a result of manifest import/refresh or custom product creation Rails.logger.warn("Unable to import pool. It will likely be created by another process.") end end end |
#pool_id ⇒ Object
52 53 54 55 56 57 58 |
# File 'app/services/katello/candlepin/message_handler.rb', line 52 def pool_id if subject == 'pool.created' || subject == 'pool.deleted' content['entityId'] elsif subject == 'entitlement.created' || subject == 'entitlement.deleted' content['referenceId'] end end |
#reasons ⇒ Object
37 38 39 |
# File 'app/services/katello/candlepin/message_handler.rb', line 37 def reasons event_data['reasons'] end |
#remove_pool_from_host ⇒ Object
68 69 70 71 72 73 74 |
# File 'app/services/katello/candlepin/message_handler.rb', line 68 def remove_pool_from_host return if self.subscription_facet.nil? || pool.nil? old_host_ids = subscription_facet_host_ids ::Katello::SubscriptionFacetPool.where(subscription_facet_id: self.subscription_facet.id, pool_id: pool.id).destroy_all pool.import_audit_record(old_host_ids) end |
#status ⇒ Object
33 34 35 |
# File 'app/services/katello/candlepin/message_handler.rb', line 33 def status event_data['status'] end |
#subject ⇒ Object
13 14 15 |
# File 'app/services/katello/candlepin/message_handler.rb', line 13 def subject .subject end |
#system_purpose ⇒ Object
45 46 47 48 49 50 |
# File 'app/services/katello/candlepin/message_handler.rb', line 45 def system_purpose if subject == 'system_purpose_compliance.created' && @system_purpose.nil? @system_purpose = Katello::Candlepin::SystemPurpose.new(event_data) end @system_purpose end |
#target_name ⇒ Object
29 30 31 |
# File 'app/services/katello/candlepin/message_handler.rb', line 29 def target_name content['targetName'] end |