-
Notifications
You must be signed in to change notification settings - Fork 897
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
app/models/manageiq/providers/ansible_tower/configuration_manager/event_catcher.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class ManageIQ::Providers::AnsibleTower::ConfigurationManager::EventCatcher < ManageIQ::Providers::BaseManager::EventCatcher | ||
require_nested :Runner | ||
end |
30 changes: 30 additions & 0 deletions
30
app/models/manageiq/providers/ansible_tower/configuration_manager/event_catcher/runner.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class ManageIQ::Providers::AnsibleTower::ConfigurationManager::EventCatcher::Runner < ManageIQ::Providers::BaseManager::EventCatcher::Runner | ||
def stop_event_monitor | ||
event_monitor_handle.stop | ||
end | ||
|
||
def monitor_events | ||
event_monitor_handle.start | ||
event_monitor_handle.poll do |event| | ||
_log.debug { "#{log_prefix} Received event #{event.id}" } | ||
event_monitor_running | ||
@queue.enq event | ||
end | ||
ensure | ||
stop_event_monitor | ||
end | ||
|
||
def queue_event(event) | ||
_log.info "#{log_prefix} Caught event [#{event.id}]" | ||
event_hash = ManageIQ::Providers::AnsibleTower::ConfigurationManager::EventParser.event_to_hash(event, @cfg[:ems_id]) | ||
EmsEvent.add_queue('add', @cfg[:ems_id], event_hash) | ||
end | ||
|
||
private | ||
|
||
def event_monitor_handle | ||
@event_monitor_handle ||= begin | ||
ManageIQ::Providers::AnsibleTower::ConfigurationManager::EventCatcher::Stream.new(@ems) | ||
end | ||
end | ||
end |
46 changes: 46 additions & 0 deletions
46
app/models/manageiq/providers/ansible_tower/configuration_manager/event_catcher/stream.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
class ManageIQ::Providers::AnsibleTower::ConfigurationManager::EventCatcher::Stream | ||
class ProviderUnreachable < ManageIQ::Providers::BaseManager::EventCatcher::Runner::TemporaryFailure | ||
end | ||
|
||
def initialize(ems) | ||
@ems = ems | ||
@last_activity = nil | ||
@stop_polling = false | ||
end | ||
|
||
def start | ||
@stop_polling = false | ||
end | ||
|
||
def stop | ||
@stop_polling = true | ||
end | ||
|
||
def poll | ||
@ems.with_provider_connection do |ansible| | ||
catch(:stop_polling) do | ||
begin | ||
loop do | ||
ansible.api.activity_stream.all(filter).each do |activity| | ||
throw :stop_polling if @stop_polling | ||
yield activity | ||
@last_activity = activity | ||
end | ||
sleep(20) | ||
end | ||
rescue => exception | ||
raise ProviderUnreachable, exception.message | ||
end | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def filter | ||
{ | ||
:order_by => 'timestamp', | ||
:timestamp__gt => @last_activity ? @last_activity.timestamp : 1.minute.ago.to_s(:db) | ||
} | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
app/models/manageiq/providers/ansible_tower/configuration_manager/event_parser.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module ManageIQ::Providers::AnsibleTower::ConfigurationManager::EventParser | ||
def self.event_to_hash(event, ems_id) | ||
{ | ||
:event_type => event.operation, | ||
:source => "ANSIBLE_TOWER", | ||
:message => event.changes.to_s, | ||
:timestamp => event.timestamp, | ||
:full_data => event.to_h, | ||
:ems_id => ems_id | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters