Skip to content

Commit

Permalink
Add ems_uid and ems_type to event payload
Browse files Browse the repository at this point in the history
The Event payload already containes the ems_id, we can add the ems_type
and ems_uid to assist in identifying the source provider without having
to hit the MIQ API

Fixes ManageIQ#20178
  • Loading branch information
agrare committed May 15, 2020
1 parent 2aa3b79 commit e0a5d20
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
26 changes: 18 additions & 8 deletions app/models/ems_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,7 @@ def self.bottleneck_event_groups
end

def self.add_queue(meth, ems_id, event)
unless MiqQueue.messaging_type == "miq_queue"
MiqQueue.messaging_client('event_handler')&.publish_topic(
:service => "manageiq.ems-events",
:sender => ems_id,
:event => event[:event_type],
:payload => event
)
end
publish_event(ems_id, event)

MiqQueue.submit_job(
:service => "event",
Expand Down Expand Up @@ -258,6 +251,23 @@ def self.create_completed_event(event, orig_task = nil)

private_class_method :create_completed_event

def self.publish_event(ems_id, event)
return if MiqQueue.messaging_type == "miq_queue"

ems = ExtManagementSystem.find(ems_id)
event[:ems_uid] = ems&.uid_ems
event[:ems_type] = ems&.class&.ems_type

MiqQueue.messaging_client('event_handler')&.publish_topic(
:service => "manageiq.ems-events",
:sender => ems_id,
:event => event[:event_type],
:payload => event
)
end

private_class_method :publish_event

def get_refresh_target(target_type)
m = "#{target_type}_refresh_target"
try(m)
Expand Down
10 changes: 8 additions & 2 deletions spec/models/ems_event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@
:service => "manageiq.ems-events",
:sender => ems.id,
:event => event_hash[:event_type],
:payload => event_hash,
:payload => event_hash.merge(
:ems_type => ems.class.ems_type,
:ems_uid => ems.uid_ems
)
}

expect(messaging_client).to receive(:publish_topic).with(expected_queue_payload)
Expand All @@ -150,7 +153,10 @@
:service => "manageiq.ems-events",
:sender => ems.id,
:event => event_hash[:event_type],
:payload => event_hash,
:payload => event_hash.merge(
:ems_type => ems.class.ems_type,
:ems_uid => ems.uid_ems
)
}

expect(messaging_client).to receive(:publish_topic).with(expected_queue_payload)
Expand Down

0 comments on commit e0a5d20

Please sign in to comment.