From 57cceb2b3d680363719bda3204c24d93fd93f64f Mon Sep 17 00:00:00 2001 From: ToineSiebelink Date: Wed, 21 Jun 2023 16:45:47 +0100 Subject: Improve handling of legacy events Legacy (non-cloud) events would cause a NPE in the event filter Although the event woudl still be ignored it would lead to uncessary error logging This fix addressed this issue using a trace level message instead (also some improvements in the associated test) Issue-ID: CPS-1724 Signed-off-by: ToineSiebelink Change-Id: Ibf71b13e4a47aaf705e32df5fe50cf41de5f558f --- .../ncmp/api/impl/async/DataOperationRecordFilterStrategy.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'cps-ncmp-service/src/main/java/org/onap') diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/async/DataOperationRecordFilterStrategy.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/async/DataOperationRecordFilterStrategy.java index ce666b109..76cc0c4b7 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/async/DataOperationRecordFilterStrategy.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/async/DataOperationRecordFilterStrategy.java @@ -22,6 +22,7 @@ package org.onap.cps.ncmp.api.impl.async; import io.cloudevents.CloudEvent; import io.cloudevents.kafka.impl.KafkaHeaders; +import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.kafka.listener.adapter.RecordFilterStrategy; @@ -31,6 +32,7 @@ import org.springframework.kafka.listener.adapter.RecordFilterStrategy; * */ @Configuration +@Slf4j public class DataOperationRecordFilterStrategy { /** @@ -42,8 +44,11 @@ public class DataOperationRecordFilterStrategy { @Bean public RecordFilterStrategy includeDataOperationEventsOnly() { return consumedRecord -> { - final String eventTypeHeaderValue = KafkaHeaders.getParsedKafkaHeader( - consumedRecord.headers(), "ce_type"); + final String eventTypeHeaderValue = KafkaHeaders.getParsedKafkaHeader(consumedRecord.headers(), "ce_type"); + if (eventTypeHeaderValue == null) { + log.trace("No ce_type header found, possibly a legacy event (ignored)"); + return true; + } return !(eventTypeHeaderValue.contains("DataOperationEvent")); }; } -- cgit 1.2.3-korg