summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main/java/org/onap
diff options
context:
space:
mode:
authorToine Siebelink <toine.siebelink@est.tech>2023-06-29 14:26:55 +0000
committerGerrit Code Review <gerrit@onap.org>2023-06-29 14:26:55 +0000
commite79415f72acce2d9508737fae552b989db1d473f (patch)
treef2b29617277d0a32d78aed5e776fe182bdb81588 /cps-ncmp-service/src/main/java/org/onap
parent3be942a91a4baccc85fe85ceab122b5e82dd964c (diff)
parentffe0e1ee121e2ca89f82824f193ed0a0e599a2c0 (diff)
Merge "Updating the Kafka listener compliance to could events and legacy"
Diffstat (limited to 'cps-ncmp-service/src/main/java/org/onap')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/async/AsyncRestRequestResponseEventConsumer.java (renamed from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/async/NcmpAsyncRequestResponseEventConsumer.java)8
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/async/DataOperationEventConsumer.java (renamed from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/async/NcmpAsyncDataOperationEventConsumer.java)8
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/async/DataOperationRecordFilterStrategy.java55
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/async/RecordFilterStrategies.java77
4 files changed, 86 insertions, 62 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/async/NcmpAsyncRequestResponseEventConsumer.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/async/AsyncRestRequestResponseEventConsumer.java
index 0ac0fb92de..0044182ddd 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/async/NcmpAsyncRequestResponseEventConsumer.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/async/AsyncRestRequestResponseEventConsumer.java
@@ -36,7 +36,7 @@ import org.springframework.stereotype.Component;
@Slf4j
@RequiredArgsConstructor
@ConditionalOnProperty(name = "notification.enabled", havingValue = "true", matchIfMissing = true)
-public class NcmpAsyncRequestResponseEventConsumer {
+public class AsyncRestRequestResponseEventConsumer {
private final EventsPublisher<NcmpAsyncRequestResponseEvent> eventsPublisher;
private final NcmpAsyncRequestResponseEventMapper ncmpAsyncRequestResponseEventMapper;
@@ -48,13 +48,15 @@ public class NcmpAsyncRequestResponseEventConsumer {
*/
@KafkaListener(
topics = "${app.ncmp.async-m2m.topic}",
+ filter = "includeNonCloudEventsOnly",
+ groupId = "ncmp-async-rest-request-event-group",
properties = {"spring.json.value.default.type=org.onap.cps.ncmp.event.model.DmiAsyncRequestResponseEvent"})
public void consumeAndForward(final DmiAsyncRequestResponseEvent dmiAsyncRequestResponseEvent) {
log.debug("Consuming event {} ...", dmiAsyncRequestResponseEvent);
-
final NcmpAsyncRequestResponseEvent ncmpAsyncRequestResponseEvent =
ncmpAsyncRequestResponseEventMapper.toNcmpAsyncEvent(dmiAsyncRequestResponseEvent);
eventsPublisher.publishEvent(ncmpAsyncRequestResponseEvent.getEventTarget(),
- ncmpAsyncRequestResponseEvent.getEventId(), ncmpAsyncRequestResponseEvent);
+ ncmpAsyncRequestResponseEvent.getEventId(),
+ ncmpAsyncRequestResponseEvent);
}
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/async/NcmpAsyncDataOperationEventConsumer.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/async/DataOperationEventConsumer.java
index 4a0ec5c493..9649b0109d 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/async/NcmpAsyncDataOperationEventConsumer.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/async/DataOperationEventConsumer.java
@@ -37,13 +37,13 @@ import org.springframework.stereotype.Component;
@Slf4j
@RequiredArgsConstructor
@ConditionalOnProperty(name = "notification.enabled", havingValue = "true", matchIfMissing = true)
-public class NcmpAsyncDataOperationEventConsumer {
+public class DataOperationEventConsumer {
private final EventsPublisher<CloudEvent> eventsPublisher;
/**
- * Consume the DataOperationResponseEvent published by producer to topic 'async-m2m.topic'
- * and publish the same to the client specified topic.
+ * Consume the DataOperation cloud event published by producer to topic 'async-m2m.topic'
+ * and publish the same to client specified topic.
*
* @param dataOperationEventConsumerRecord consuming event as a ConsumerRecord.
*/
@@ -51,7 +51,7 @@ public class NcmpAsyncDataOperationEventConsumer {
topics = "${app.ncmp.async-m2m.topic}",
filter = "includeDataOperationEventsOnly",
groupId = "ncmp-data-operation-event-group",
- properties = {"spring.json.value.default.type=org.onap.cps.ncmp.events.async1_0_0.DataOperationEvent"})
+ containerFactory = "cloudEventConcurrentKafkaListenerContainerFactory")
public void consumeAndPublish(final ConsumerRecord<String, CloudEvent> dataOperationEventConsumerRecord) {
log.info("Consuming event payload {} ...", dataOperationEventConsumerRecord.value());
final String eventTarget = KafkaHeaders.getParsedKafkaHeader(
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
deleted file mode 100644
index 76cc0c4b7b..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/async/DataOperationRecordFilterStrategy.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2023 Nordix Foundation
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-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;
-
-/**
- * Data operation record filter strategy, which helps to filter the consumer records.
- *
- */
-@Configuration
-@Slf4j
-public class DataOperationRecordFilterStrategy {
-
- /**
- * Filtering the consumer records based on the eventType header, It
- * returns boolean, true means filter the consumer record and false
- * means not filter the consumer record.
- * @return boolean value.
- */
- @Bean
- public RecordFilterStrategy<String, CloudEvent> includeDataOperationEventsOnly() {
- return consumedRecord -> {
- 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"));
- };
- }
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/async/RecordFilterStrategies.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/async/RecordFilterStrategies.java
new file mode 100644
index 0000000000..0404790408
--- /dev/null
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/async/RecordFilterStrategies.java
@@ -0,0 +1,77 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.ncmp.api.impl.async;
+
+import io.cloudevents.CloudEvent;
+import io.cloudevents.kafka.impl.KafkaHeaders;
+import java.io.Serializable;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.kafka.common.header.Headers;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.kafka.listener.adapter.RecordFilterStrategy;
+
+/**
+ * Record filter strategies, which helps to filter the consumer records based on some conditions.
+ *
+ */
+@Configuration
+@Slf4j
+public class RecordFilterStrategies {
+
+ private static final boolean EXCLUDE_EVENT = true;
+
+ /**
+ * Include only DataOperation events based on the cloud event type header, It
+ * returns boolean, true means exclude the consumer record and false
+ * means include the consumer record.
+ * @return boolean value.
+ */
+ @Bean
+ public RecordFilterStrategy<String, CloudEvent> includeDataOperationEventsOnly() {
+ return consumerRecord ->
+ isNotCloudEventOfType(consumerRecord.headers(), "DataOperationEvent");
+ }
+
+ /**
+ * Includes the consumer records based on the cloud event type header, It returns boolean,
+ * true means exclude the consumer record and false means include the consumer record.
+ * It includes only the legacy events i.e. non-cloud events
+ * @return boolean value.
+ */
+ @Bean
+ public RecordFilterStrategy<String, Serializable> includeNonCloudEventsOnly() {
+ return consumerRecord -> isCloudEvent(consumerRecord.headers());
+ }
+
+ private boolean isCloudEvent(final Headers headers) {
+ return headers.lastHeader("ce_type") != null;
+ }
+
+ private boolean isNotCloudEventOfType(final Headers headers, final String requiredEventType) {
+ final String eventTypeHeaderValue = KafkaHeaders.getParsedKafkaHeader(headers, "ce_type");
+ if (eventTypeHeaderValue == null) {
+ log.trace("No ce_type header found, possibly a legacy event (ignored)");
+ return EXCLUDE_EVENT;
+ }
+ return !(eventTypeHeaderValue.contains(requiredEventType));
+ }
+}