Skip to content

Commit

Permalink
Merge pull request #20179 from agrare/add_ems_uid_and_type_to_event_p…
Browse files Browse the repository at this point in the history
…ayload

Add ems_uid and ems_type to event payload

(cherry picked from commit 5d73337)
  • Loading branch information
chessbyte authored and simaishi committed May 21, 2020
1 parent 4247cba commit 5805d5c
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 5805d5c

Please sign in to comment.