From f31c7f8bd4985c84f9126d071439c1a4de57f704 Mon Sep 17 00:00:00 2001 From: JosephKeenan Date: Tue, 24 May 2022 18:59:25 +0100 Subject: Async request response NCMP -> Client -Added consumer for DMI events and producer for forwarding to client -Added schemas for events -Updated tests -Added new module for ncmp events -Used mapstruct for event mapping Issue-ID: CPS-830 Change-Id: I096d08af9d69092cf8651e11eaa00ce441fc3605 Signed-off-by: sourabh_sourabh Signed-off-by: JosephKeenan Signed-off-by: ToineSiebelink Signed-off-by: JosephKeenan --- cps-service/pom.xml | 330 ++++++++++----------- .../org/onap/cps/api/impl/CpsDataServiceImpl.java | 31 +- .../notification/KafkaTestContainerConfig.groovy | 2 +- .../notification/NotificationServiceSpec.groovy | 25 +- cps-service/src/test/resources/application.yml | 1 + 5 files changed, 198 insertions(+), 191 deletions(-) (limited to 'cps-service') diff --git a/cps-service/pom.xml b/cps-service/pom.xml index b9d626874..1be45d1bc 100644 --- a/cps-service/pom.xml +++ b/cps-service/pom.xml @@ -1,165 +1,165 @@ - - - - - 4.0.0 - - org.onap.cps - cps-parent - 3.1.0-SNAPSHOT - ../cps-parent/pom.xml - - - cps-service - - - 0.94 - - - - - org.onap.cps - cps-events - - - org.opendaylight.yangtools - yang-model-api - - - org.opendaylight.yangtools - yang-parser-api - - - org.opendaylight.yangtools - yang-parser-impl - - - org.opendaylight.yangtools - yang-model-util - - - - org.opendaylight.yangtools - yang-data-codec-gson - - - org.projectlombok - lombok - - - org.springframework.boot - spring-boot-starter-cache - - - com.github.ben-manes.caffeine - caffeine - - - org.springframework.kafka - spring-kafka - - - org.springframework - spring-messaging - - - - org.slf4j - slf4j-api - - - - org.springframework - spring-context - - - org.springframework.boot - spring-boot-starter-validation - - - - com.google.code.gson - gson - - - org.springframework.boot - spring-boot-starter-aop - - - net.logstash.logback - logstash-logback-encoder - - - org.codehaus.janino - janino - - - - org.codehaus.groovy - groovy - test - - - org.codehaus.groovy - groovy-json - test - - - org.spockframework - spock-core - test - - - org.spockframework - spock-spring - test - - - org.springframework.boot - spring-boot-starter-test - test - - - cglib - cglib-nodep - test - - - org.testcontainers - kafka - test - - - org.springframework.kafka - spring-kafka-test - test - - - org.aspectj - aspectjrt - test - - - + + + + + 4.0.0 + + org.onap.cps + cps-parent + 3.1.0-SNAPSHOT + ../cps-parent/pom.xml + + + cps-service + + + 0.94 + + + + + org.onap.cps + cps-events + + + org.opendaylight.yangtools + yang-model-api + + + org.opendaylight.yangtools + yang-parser-api + + + org.opendaylight.yangtools + yang-parser-impl + + + org.opendaylight.yangtools + yang-model-util + + + + org.opendaylight.yangtools + yang-data-codec-gson + + + org.projectlombok + lombok + + + org.springframework.boot + spring-boot-starter-cache + + + com.github.ben-manes.caffeine + caffeine + + + org.springframework.kafka + spring-kafka + + + org.springframework + spring-messaging + + + + org.slf4j + slf4j-api + + + + org.springframework + spring-context + + + org.springframework.boot + spring-boot-starter-validation + + + + com.google.code.gson + gson + + + org.springframework.boot + spring-boot-starter-aop + + + net.logstash.logback + logstash-logback-encoder + + + org.codehaus.janino + janino + + + + org.codehaus.groovy + groovy + test + + + org.codehaus.groovy + groovy-json + test + + + org.spockframework + spock-core + test + + + org.spockframework + spock-spring + test + + + org.springframework.boot + spring-boot-starter-test + test + + + cglib + cglib-nodep + test + + + org.testcontainers + kafka + test + + + org.springframework.kafka + spring-kafka-test + test + + + org.aspectj + aspectjrt + test + + + diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java index 2f1067aaf..0772a8c9f 100755 --- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java +++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java @@ -22,6 +22,10 @@ package org.onap.cps.api.impl; +import static org.onap.cps.notification.Operation.CREATE; +import static org.onap.cps.notification.Operation.DELETE; +import static org.onap.cps.notification.Operation.UPDATE; + import java.time.OffsetDateTime; import java.util.Collection; import lombok.AllArgsConstructor; @@ -61,7 +65,7 @@ public class CpsDataServiceImpl implements CpsDataService { CpsValidator.validateNameCharacters(dataspaceName, anchorName); final DataNode dataNode = buildDataNode(dataspaceName, anchorName, ROOT_NODE_XPATH, jsonData); cpsDataPersistenceService.storeDataNode(dataspaceName, anchorName, dataNode); - processDataUpdatedEventAsync(dataspaceName, anchorName, observedTimestamp, ROOT_NODE_XPATH, Operation.CREATE); + processDataUpdatedEventAsync(dataspaceName, anchorName, observedTimestamp, ROOT_NODE_XPATH, CREATE); } @Override @@ -70,7 +74,7 @@ public class CpsDataServiceImpl implements CpsDataService { CpsValidator.validateNameCharacters(dataspaceName, anchorName); final DataNode dataNode = buildDataNode(dataspaceName, anchorName, parentNodeXpath, jsonData); cpsDataPersistenceService.addChildDataNode(dataspaceName, anchorName, parentNodeXpath, dataNode); - processDataUpdatedEventAsync(dataspaceName, anchorName, observedTimestamp, parentNodeXpath, Operation.CREATE); + processDataUpdatedEventAsync(dataspaceName, anchorName, observedTimestamp, parentNodeXpath, CREATE); } @Override @@ -81,7 +85,7 @@ public class CpsDataServiceImpl implements CpsDataService { buildDataNodes(dataspaceName, anchorName, parentNodeXpath, jsonData); cpsDataPersistenceService.addListElements(dataspaceName, anchorName, parentNodeXpath, listElementDataNodeCollection); - processDataUpdatedEventAsync(dataspaceName, anchorName, observedTimestamp, parentNodeXpath, Operation.UPDATE); + processDataUpdatedEventAsync(dataspaceName, anchorName, observedTimestamp, parentNodeXpath, UPDATE); } @Override @@ -98,7 +102,7 @@ public class CpsDataServiceImpl implements CpsDataService { final DataNode dataNode = buildDataNode(dataspaceName, anchorName, parentNodeXpath, jsonData); cpsDataPersistenceService .updateDataLeaves(dataspaceName, anchorName, dataNode.getXpath(), dataNode.getLeaves()); - processDataUpdatedEventAsync(dataspaceName, anchorName, observedTimestamp, parentNodeXpath, Operation.UPDATE); + processDataUpdatedEventAsync(dataspaceName, anchorName, observedTimestamp, parentNodeXpath, UPDATE); } @Override @@ -113,7 +117,7 @@ public class CpsDataServiceImpl implements CpsDataService { for (final DataNode dataNodeUpdate : dataNodeUpdates) { processDataNodeUpdate(dataspaceName, anchorName, dataNodeUpdate); } - processDataUpdatedEventAsync(dataspaceName, anchorName, observedTimestamp, parentNodeXpath, Operation.UPDATE); + processDataUpdatedEventAsync(dataspaceName, anchorName, observedTimestamp, parentNodeXpath, UPDATE); } @Override @@ -143,7 +147,7 @@ public class CpsDataServiceImpl implements CpsDataService { CpsValidator.validateNameCharacters(dataspaceName, anchorName); final DataNode dataNode = buildDataNode(dataspaceName, anchorName, parentNodeXpath, jsonData); cpsDataPersistenceService.replaceDataNodeTree(dataspaceName, anchorName, dataNode); - processDataUpdatedEventAsync(dataspaceName, anchorName, observedTimestamp, parentNodeXpath, Operation.UPDATE); + processDataUpdatedEventAsync(dataspaceName, anchorName, observedTimestamp, parentNodeXpath, UPDATE); } @Override @@ -160,7 +164,7 @@ public class CpsDataServiceImpl implements CpsDataService { final Collection dataNodes, final OffsetDateTime observedTimestamp) { CpsValidator.validateNameCharacters(dataspaceName, anchorName); cpsDataPersistenceService.replaceListContent(dataspaceName, anchorName, parentNodeXpath, dataNodes); - processDataUpdatedEventAsync(dataspaceName, anchorName, observedTimestamp, parentNodeXpath, Operation.UPDATE); + processDataUpdatedEventAsync(dataspaceName, anchorName, observedTimestamp, parentNodeXpath, UPDATE); } @Override @@ -168,7 +172,7 @@ public class CpsDataServiceImpl implements CpsDataService { final OffsetDateTime observedTimestamp) { CpsValidator.validateNameCharacters(dataspaceName, anchorName); cpsDataPersistenceService.deleteDataNode(dataspaceName, anchorName, dataNodeXpath); - processDataUpdatedEventAsync(dataspaceName, anchorName, observedTimestamp, dataNodeXpath, Operation.DELETE); + processDataUpdatedEventAsync(dataspaceName, anchorName, observedTimestamp, dataNodeXpath, DELETE); } @Override @@ -177,7 +181,7 @@ public class CpsDataServiceImpl implements CpsDataService { CpsValidator.validateNameCharacters(dataspaceName, anchorName); final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName); cpsDataPersistenceService.deleteDataNodes(dataspaceName, anchorName); - processDataUpdatedEventAsync(anchor, ROOT_NODE_XPATH, Operation.DELETE, observedTimestamp); + processDataUpdatedEventAsync(anchor, ROOT_NODE_XPATH, DELETE, observedTimestamp); } @Override @@ -185,7 +189,7 @@ public class CpsDataServiceImpl implements CpsDataService { final OffsetDateTime observedTimestamp) { CpsValidator.validateNameCharacters(dataspaceName, anchorName); cpsDataPersistenceService.deleteListDataNode(dataspaceName, anchorName, listNodeXpath); - processDataUpdatedEventAsync(dataspaceName, anchorName, observedTimestamp, listNodeXpath, Operation.DELETE); + processDataUpdatedEventAsync(dataspaceName, anchorName, observedTimestamp, listNodeXpath, DELETE); } private DataNode buildDataNode(final String dataspaceName, final String anchorName, @@ -233,10 +237,13 @@ public class CpsDataServiceImpl implements CpsDataService { this.processDataUpdatedEventAsync(anchor, xpath, operation, observedTimestamp); } - private void processDataUpdatedEventAsync(final Anchor anchor, final String xpath, final Operation operation, + private void processDataUpdatedEventAsync(final Anchor anchor, + final String xpath, + final Operation operation, final OffsetDateTime observedTimestamp) { try { - notificationService.processDataUpdatedEvent(anchor, observedTimestamp, xpath, operation); + notificationService.processDataUpdatedEvent(anchor, observedTimestamp, xpath, + operation); } catch (final Exception exception) { //If async message can't be queued for notification service, the initial request should not failed. log.error("Failed to send message to notification service", exception); diff --git a/cps-service/src/test/groovy/org/onap/cps/notification/KafkaTestContainerConfig.groovy b/cps-service/src/test/groovy/org/onap/cps/notification/KafkaTestContainerConfig.groovy index 5124a519a..05b9624a4 100644 --- a/cps-service/src/test/groovy/org/onap/cps/notification/KafkaTestContainerConfig.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/notification/KafkaTestContainerConfig.groovy @@ -33,7 +33,7 @@ class KafkaTestContainerConfig { // Not the best performance but it is good enough for test case private static synchronized KafkaContainer getKafkaContainer() { if (kafkaContainer == null) { - kafkaContainer = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:6.1.1")) + kafkaContainer = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:6.2.1")) .withEnv("KAFKA_AUTO_CREATE_TOPICS_ENABLE", "false") kafkaContainer.start() Runtime.getRuntime().addShutdownHook(new Thread(kafkaContainer::stop)) diff --git a/cps-service/src/test/groovy/org/onap/cps/notification/NotificationServiceSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/notification/NotificationServiceSpec.groovy index 6ef6874b3..8263c31f0 100644 --- a/cps-service/src/test/groovy/org/onap/cps/notification/NotificationServiceSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/notification/NotificationServiceSpec.groovy @@ -29,7 +29,6 @@ import org.spockframework.spring.SpringSpy import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.boot.test.context.SpringBootTest -import org.springframework.scheduling.annotation.EnableAsync import org.springframework.test.context.ContextConfiguration import spock.lang.Shared import spock.lang.Specification @@ -107,18 +106,18 @@ class NotificationServiceSpec extends Specification { 1 * mockNotificationPublisher.sendNotification(cpsDataUpdatedEvent) where: scenario | xpath | operation || expectedOperationInEvent - 'Same event is sent when root nodes' | '' | Operation.CREATE || Operation.CREATE - 'Same event is sent when root nodes' | '' | Operation.UPDATE || Operation.UPDATE - 'Same event is sent when root nodes' | '' | Operation.DELETE || Operation.DELETE - 'Same event is sent when root nodes' | '/' | Operation.CREATE || Operation.CREATE - 'Same event is sent when root nodes' | '/' | Operation.UPDATE || Operation.UPDATE - 'Same event is sent when root nodes' | '/' | Operation.DELETE || Operation.DELETE - 'Same event is sent when container nodes' | '/parent' | Operation.CREATE || Operation.CREATE - 'Same event is sent when container nodes' | '/parent' | Operation.UPDATE || Operation.UPDATE - 'Same event is sent when container nodes' | '/parent' | Operation.DELETE || Operation.DELETE - 'UPDATE event is sent when non root nodes' | '/parent/child' | Operation.CREATE || Operation.UPDATE - 'UPDATE event is sent when non root nodes' | '/parent/child' | Operation.UPDATE || Operation.UPDATE - 'UPDATE event is sent when non root nodes' | '/parent/child' | Operation.DELETE || Operation.UPDATE + 'Same event is sent when root nodes' | '' | Operation.CREATE || Operation.CREATE + 'Same event is sent when root nodes' | '' | Operation.UPDATE || Operation.UPDATE + 'Same event is sent when root nodes' | '' | Operation.DELETE || Operation.DELETE + 'Same event is sent when root nodes' | '/' | Operation.CREATE || Operation.CREATE + 'Same event is sent when root nodes' | '/' | Operation.UPDATE || Operation.UPDATE + 'Same event is sent when root nodes' | '/' | Operation.DELETE || Operation.DELETE + 'Same event is sent when container nodes' | '/parent' | Operation.CREATE || Operation.CREATE + 'Same event is sent when container nodes' | '/parent' | Operation.UPDATE || Operation.UPDATE + 'Same event is sent when container nodes' | '/parent' | Operation.DELETE || Operation.DELETE + 'UPDATE event is sent when non root nodes' | '/parent/child' | Operation.CREATE || Operation.UPDATE + 'UPDATE event is sent when non root nodes' | '/parent/child' | Operation.UPDATE || Operation.UPDATE + 'UPDATE event is sent when non root nodes' | '/parent/child' | Operation.DELETE || Operation.UPDATE } def 'Error handling in notification service.'() { diff --git a/cps-service/src/test/resources/application.yml b/cps-service/src/test/resources/application.yml index 436c3d4c3..a28b40083 100644 --- a/cps-service/src/test/resources/application.yml +++ b/cps-service/src/test/resources/application.yml @@ -1,5 +1,6 @@ # ============LICENSE_START======================================================= # Copyright (c) 2021 Bell Canada. +# Modification Copyright (C) 2022 Nordix Foundation. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. -- cgit 1.2.3-korg