Skip to content

Commit

Permalink
create a cache to persiste the bigger ems_ref
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlleDaniel committed Jun 5, 2018
1 parent 9e9a560 commit cd1c7bf
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 43 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class ManageIQ::Providers::Lenovo::PhysicalInfraManager::EventCatcher::Stream
def initialize(ems)
@ems = ems
@collect_events = true
@last_event_ems_ref = last_event_ems_ref(@ems.id)
end

# Stop capturing events
Expand All @@ -27,17 +28,23 @@ def filter_fields
{ :operation => 'NOT', :field => 'eventClass', :value => '200' },
{ :operation => 'NOT', :field => 'eventClass', :value => '800' }
]
last_cn_event = get_last_ems_ref(@ems.id)
cn_operation = { :operation => 'GT', :field => 'cn', :value => last_cn_event.to_s }
fields.push(cn_operation) unless last_cn_event.nil?

unless @last_event_ems_ref.nil?
cn_operation = { :operation => 'GT', :field => 'cn', :value => @last_event_ems_ref.to_s }
fields.push(cn_operation)
end
fields
end

def parse_events(events)
events.collect do |data|
event = ManageIQ::Providers::Lenovo::PhysicalInfraManager::EventCatcher::Event.new(data).to_hash
ManageIQ::Providers::Lenovo::PhysicalInfraManager::EventParser.event_to_hash(event, @ems.id)
if events.any?
events = events.sort { |x, y| Integer(x.cn) <=> Integer(y.cn) }.collect do |event|
ManageIQ::Providers::Lenovo::PhysicalInfraManager::EventParser.event_to_hash(event, @ems.id)
end
# Update the @last_event_ems_ref with the new last ems_ref if to exist new events
@last_event_ems_ref = events.last[:ems_ref]
end
events
end

def events
Expand All @@ -61,7 +68,7 @@ def create_event_connection(ems)
:port => ems.endpoints.first.port)
end

def get_last_ems_ref(ems_id)
EventStream.where(:ems_id => ems_id).maximum('CAST(ems_ref AS int)') || 1
def last_event_ems_ref(ems_id)
EventStream.where(:ems_id => ems_id).maximum('CAST(ems_ref AS int)')
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module ManageIQ::Providers::Lenovo::PhysicalInfraManager::EventParser
def self.event_to_hash(event, ems_id)
def self.event_to_hash(data, ems_id)
event = filter_data(data)
event_hash = {
:event_type => event[:event_type],
:ems_ref => event[:ems_ref],
Expand All @@ -10,10 +11,27 @@ def self.event_to_hash(event, ems_id)
:full_data => event,
:ems_id => ems_id
}

event_hash
end

def self.filter_data(data)
{
:component_id => data.componentID,
:component_type => data.typeText,
:event_type => data.msgID,
:ems_ref => data.cn,
:message => data.msg,
:parent_uuid => data.senderUUID,
:parent_name => data.systemName,
:parent_model => data.systemTypeModelText,
:parent_type => data.systemTypeText,
:severity_id => data.severity,
:severity => data.severityText,
:source => 'LenovoXclarity',
:timestamp => data.timeStamp,
}
end

def self.get_physical_server_id(ems_ref)
PhysicalServer.find_by(:ems_ref => ems_ref).try(:id)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@
it "yields a valid event" do
VCR.use_cassette(described_class.name.underscore.to_s) do
result = []
pool = 2
stream.each_batch do |events|
result = events
stream.stop
expect($log).to receive(:info).with(/Stopping collect of LXCA events .../)
result.push(*events)
pool -= 1
if pool < 1
stream.stop
expect(events.count).to be == 1
expect($log).to receive(:info).with(/Stopping collect of LXCA events .../)
else
expect(events.count).to be == 20
end
end
expect(result.count).to be == 20
expect(result.all? { |item| item[:full_data][:severity] == 200 }).to be true
expect(result.count).to be == 21
expect(result.all? { |item| item[:full_data][:severity_id] == 200 }).to be true
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
}
end

let(:event1) do
data = XClarityClient::Event.new(event_attrs1)
ManageIQ::Providers::Lenovo::PhysicalInfraManager::EventCatcher::Event.new(data).to_hash
end
let(:event1) { XClarityClient::Event.new(event_attrs1) }

it 'will parse events' do
event_hash = described_class.event_to_hash(event1, 3)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cd1c7bf

Please sign in to comment.