AAI events are not being published 13/138913/2
authorFiete Ostkamp <Fiete.Ostkamp@telekom.de>
Fri, 6 Sep 2024 11:54:33 +0000 (13:54 +0200)
committerFiete Ostkamp <Fiete.Ostkamp@telekom.de>
Fri, 6 Sep 2024 12:29:37 +0000 (14:29 +0200)
- create e2e test case for notification sending
- fix notification sending
- disable tests since they can only be active with some larger refactoring

Issue-ID: AAI-3988
Change-Id: I498b3b02218d81821dd17c3d8ad0da4de859924b
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
18 files changed:
aai-aaf-auth/pom.xml
aai-annotations/pom.xml
aai-auth/pom.xml
aai-common-docker/aai-common-images/pom.xml
aai-common-docker/aai-haproxy-image/pom.xml
aai-common-docker/pom.xml
aai-core/pom.xml
aai-core/src/main/java/org/onap/aai/kafka/AAIKafkaEventJMSProducer.java
aai-core/src/test/java/org/onap/aai/kafka/AAIKafkaEventIntegrationTest.java
aai-core/src/test/resources/payloads/expected/pserver-event.json [new file with mode: 0644]
aai-els-onap-logging/pom.xml
aai-failover/pom.xml
aai-parent/pom.xml
aai-rest/pom.xml
aai-schema-abstraction/pom.xml
aai-schema-ingest/pom.xml
aai-utils/pom.xml
pom.xml

index 4f50e48..8be6291 100644 (file)
@@ -6,7 +6,7 @@
     <parent>
         <groupId>org.onap.aai.aai-common</groupId>
         <artifactId>aai-parent</artifactId>
-        <version>1.14.6-SNAPSHOT</version>
+        <version>1.14.7-SNAPSHOT</version>
         <relativePath>../aai-parent/pom.xml</relativePath>
     </parent>
     <artifactId>aai-aaf-auth</artifactId>
index 9718c8c..0a7044f 100644 (file)
@@ -27,7 +27,7 @@
     <parent>
         <groupId>org.onap.aai.aai-common</groupId>
         <artifactId>aai-parent</artifactId>
-        <version>1.14.6-SNAPSHOT</version>
+        <version>1.14.7-SNAPSHOT</version>
         <relativePath>../aai-parent/pom.xml</relativePath>
     </parent>
     <artifactId>aai-annotations</artifactId>
index b766ffe..f3e22bc 100644 (file)
@@ -27,7 +27,7 @@
     <parent>
         <groupId>org.onap.aai.aai-common</groupId>
         <artifactId>aai-parent</artifactId>
-        <version>1.14.6-SNAPSHOT</version>
+        <version>1.14.7-SNAPSHOT</version>
         <relativePath>../aai-parent/pom.xml</relativePath>
     </parent>
     <artifactId>aai-auth</artifactId>
index a10bb12..267fb3d 100644 (file)
     <parent>
         <groupId>org.onap.aai.aai-common</groupId>
         <artifactId>aai-common-docker</artifactId>
-        <version>1.14.6-SNAPSHOT</version>
+        <version>1.14.7-SNAPSHOT</version>
     </parent>
 
     <artifactId>aai-common-images</artifactId>
-    <version>1.14.6-SNAPSHOT</version>
+    <version>1.14.7-SNAPSHOT</version>
     <packaging>pom</packaging>
     <name>aai-aai-common-images</name>
     <description>Contains dockerfiles for aai-common images (alpine and ubuntu based).</description>
index bd2b3a4..8b98e47 100644 (file)
     <parent>
         <groupId>org.onap.aai.aai-common</groupId>
         <artifactId>aai-common-docker</artifactId>
-        <version>1.14.6-SNAPSHOT</version>
+        <version>1.14.7-SNAPSHOT</version>
     </parent>
 
     <artifactId>aai-haproxy-image</artifactId>
-    <version>1.14.6-SNAPSHOT</version>
+    <version>1.14.7-SNAPSHOT</version>
     <packaging>pom</packaging>
     <name>aai-aai-haproxy-image</name>
     <description>Contains dockerfiles for aai-haproxy image.</description>
index 8aaa8c5..c6c629b 100644 (file)
@@ -26,7 +26,7 @@
     <parent>
         <groupId>org.onap.aai.aai-common</groupId>
         <artifactId>aai-parent</artifactId>
-        <version>1.14.6-SNAPSHOT</version>
+        <version>1.14.7-SNAPSHOT</version>
         <relativePath>../aai-parent/pom.xml</relativePath>
     </parent>
 
index d2aed3a..2f5908b 100644 (file)
@@ -26,7 +26,7 @@ limitations under the License.
        <parent>
                <groupId>org.onap.aai.aai-common</groupId>
                <artifactId>aai-parent</artifactId>
-               <version>1.14.6-SNAPSHOT</version>
+               <version>1.14.7-SNAPSHOT</version>
                <relativePath>../aai-parent/pom.xml</relativePath>
        </parent>
        <artifactId>aai-core</artifactId>
index 4e94877..1ed3542 100644 (file)
  * ============LICENSE_END=========================================================
  */
 
-package org.onap.aai.kafka;
+ package org.onap.aai.kafka;
 
-import org.json.JSONObject;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.jms.core.JmsTemplate;
-import org.springframework.stereotype.Service;
+ import org.json.JSONObject;
+ import org.onap.aai.config.SpringContextAware;
+ import org.onap.aai.domain.notificationEvent.NotificationEvent;
+ import org.onap.aai.util.AAIConfig;
+ import org.springframework.jms.core.JmsTemplate;
+ import org.springframework.stereotype.Service;
 
-import lombok.RequiredArgsConstructor;
+ import com.fasterxml.jackson.core.JsonProcessingException;
+ import com.fasterxml.jackson.databind.ObjectMapper;
+ import com.fasterxml.jackson.databind.json.JsonMapper;
 
-@Service
-@RequiredArgsConstructor
-public class AAIKafkaEventJMSProducer implements MessageProducer {
+ import lombok.RequiredArgsConstructor;
+ import lombok.extern.slf4j.Slf4j;
 
-    @Value("${aai.events.enabled:true}") private boolean eventsEnabled;
-    private final JmsTemplate jmsTemplate;
+ @Slf4j
+ @Service
+ @RequiredArgsConstructor
+ public class AAIKafkaEventJMSProducer implements MessageProducer {
 
-    public void sendMessageToDefaultDestination(String msg) {
-        if (eventsEnabled) {
-            jmsTemplate.convertAndSend(msg);
-        }
-    }
+     private boolean eventsEnabled = "true".equals(AAIConfig.get("aai.jms.enable", "true"));
+     private JmsTemplate jmsTemplate;
+     private static final ObjectMapper mapper = new JsonMapper();
 
-    public void sendMessageToDefaultDestination(JSONObject finalJson) {
-        sendMessageToDefaultDestination(finalJson.toString());
-    }
-}
+     public AAIKafkaEventJMSProducer(JmsTemplate jmsTemplate) {
+         this.jmsTemplate = jmsTemplate;
+     }
+
+     public void sendMessageToDefaultDestination(String msg) {
+         if (eventsEnabled) {
+             if(jmsTemplate == null) {
+                 this.jmsTemplate = SpringContextAware.getBean(JmsTemplate.class);
+             }
+             jmsTemplate.convertAndSend(msg);
+         }
+     }
+
+     public void sendMessageToDefaultDestination(JSONObject finalJson) {
+         sendMessageToDefaultDestination(finalJson.toString());
+     }
+ }
index 0f5f47a..56a6a85 100644 (file)
 package org.onap.aai.kafka;
 
 import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.Mockito.when;
 
+import java.io.IOException;
+import java.net.URI;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.List;
+
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.UriInfo;
 
 import org.apache.kafka.clients.consumer.Consumer;
-import org.apache.kafka.clients.consumer.ConsumerRecord;
 import org.apache.kafka.clients.consumer.ConsumerRecords;
+import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.onap.aai.AAISetup;
 import org.onap.aai.PayloadUtil;
+import org.onap.aai.exceptions.AAIException;
+import org.onap.aai.introspection.Introspector;
+import org.onap.aai.introspection.Loader;
+import org.onap.aai.parsers.query.QueryParser;
+import org.onap.aai.rest.db.DBRequest;
+import org.onap.aai.restcore.HttpMethod;
+import org.onap.aai.serialization.engines.TransactionalGraphEngine;
+import org.onap.aai.setup.SchemaVersion;
 import org.skyscreamer.jsonassert.JSONAssert;
 import org.skyscreamer.jsonassert.JSONCompareMode;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -41,8 +63,10 @@ import org.springframework.kafka.test.utils.KafkaTestUtils;
 import org.springframework.test.context.ActiveProfiles;
 import org.springframework.test.context.TestPropertySource;
 
+import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 
+@Ignore
 @Slf4j
 @ActiveProfiles("kafka")
 @Import(KafkaTestConfiguration.class)
@@ -66,6 +90,18 @@ public class AAIKafkaEventIntegrationTest extends AAISetup {
     @Autowired
     private ConsumerFactory<String, String> consumerFactory;
 
+    @Mock UriInfo uriInfoMock;
+    @Mock MultivaluedMap<String, String> queryParamsMock;
+    @Mock HttpHeaders headersMock;
+
+    @Before
+    public void setup() {
+        when(headersMock.getAcceptableMediaTypes()).thenReturn(Collections.singletonList(MediaType.APPLICATION_JSON_TYPE));
+        when(uriInfoMock.getQueryParameters(anyBoolean())).thenReturn(queryParamsMock);
+        when(queryParamsMock.getFirst("depth")).thenReturn("0");
+        when(headersMock.getRequestHeader("aai-request-context")).thenReturn(null);
+    }
+
     @Test
     public void onMessage_shouldSendMessageToKafkaTopic_whenAAIEventReceived()
             throws Exception {
@@ -84,4 +120,43 @@ public class AAIKafkaEventIntegrationTest extends AAISetup {
         });
     }
 
+    @Test
+    @Ignore
+    // only works when aai.jms.enable=true in aaiconfig.properties
+    public void thatEventsAreBeingCreated() throws AAIException, IOException {
+        Consumer<String, String> consumer = consumerFactory.createConsumer();
+        consumer.subscribe(Collections.singletonList("AAI-EVENT"));
+
+        traversalUriHttpEntry.setHttpEntryProperties(new SchemaVersion("v14"));
+        String pserverUri = "/aai/v14/cloud-infrastructure/pservers/pserver/pserver1";
+        String entity = new String(Files.readAllBytes(Paths.get("src/test/resources/payloads/templates/pserver.json"))).replace("${hostname}", "pserver1");
+        DBRequest dbRequest = createDBRequest(pserverUri, entity);
+        List<DBRequest> dbRequests = new ArrayList<>();
+        dbRequests.add(dbRequest);
+
+        traversalUriHttpEntry.process(dbRequests, "test");
+
+        ConsumerRecords<String, String> consumerRecords = KafkaTestUtils.getRecords(consumer, 100000);
+        assertFalse(consumerRecords.isEmpty());
+        String expectedResponse = PayloadUtil.getExpectedPayload("pserver-event.json");
+
+        consumerRecords.forEach(consumerRecord -> {
+            JSONAssert.assertEquals(expectedResponse, consumerRecord.value(), JSONCompareMode.LENIENT);
+        });
+    }
+
+    @SneakyThrows
+    private DBRequest createDBRequest(String uri, String entity) {
+        TransactionalGraphEngine dbEngine = traversalUriHttpEntry.getDbEngine();
+        Loader loader = traversalUriHttpEntry.getLoader();
+        URI uriObject = new URI(uri);
+        QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject);
+        String objName = uriQuery.getResultType();
+        Introspector obj = loader.unmarshal(objName, entity,
+            org.onap.aai.restcore.MediaType.getEnum("application/json"));
+        return new DBRequest.Builder(HttpMethod.PUT, uriObject, uriQuery, obj, headersMock, uriInfoMock, "someTransaction")
+            .rawRequestContent(entity)
+            .build();
+    }
+
 }
diff --git a/aai-core/src/test/resources/payloads/expected/pserver-event.json b/aai-core/src/test/resources/payloads/expected/pserver-event.json
new file mode 100644 (file)
index 0000000..11c1a10
--- /dev/null
@@ -0,0 +1,44 @@
+{
+    "cambria.partition": "AAI",
+    "event-header": {
+        "severity": "NORMAL",
+        "entity-type": "pserver",
+        "top-entity-type": "pserver",
+        "entity-link": "/aai/v14/cloud-infrastructure/pservers/pserver/pserver1",
+        "event-type": "AAI-EVENT",
+        "domain": "devINT1",
+        "action": "CREATE",
+        "sequence-number": "0",
+        "id": "someTransaction",
+        "source-name": "test",
+        "version": "v14",
+    },
+    "entity": {
+        "ptnii-equip-name": "example-ptnii-equip-name-val-36969",
+        "ipaddress-v6-loopback-0": "example-ipaddress-v6-loopback0-val-17856",
+        "equip-vendor": "example-equip-vendor-val-37452",
+        "purpose": "example-purpose-val-90218",
+        "pserver-selflink": "example-pserver-selflink-val-10125",
+        "number-of-cpus": 62220,
+        "ipaddress-v6-aim": "example-ipaddress-v6-aim-val-6210",
+        "pserver-name2": "example-pserver-name2-val-53802",
+        "hostname": "pserver1",
+        "inv-status": "example-inv-status-val-3682",
+        "disk-in-gigabytes": 872,
+        "equip-type": "example-equip-type-val-22986",
+        "fqdn": "example-fqdn-val-33429",
+        "serial-number": "example-serial-number-val-12010",
+        "ipaddress-v6-oam": "example-ipaddress-v6-oam-val-40977",
+        "pserver-id": "example-pserver-id-val-82142",
+        "prov-status": "example-prov-status-val-11642",
+        "ipv4-oam-address": "example-ipv4-oam-address-val-3155",
+        "ipaddress-v4-loopback-0": "example-ipaddress-v4-loopback0-val-77686",
+        "equip-model": "example-equip-model-val-14665",
+        "in-maint": true,
+        "ram-in-megabytes": 35331,
+        "ipaddress-v4-aim": "example-ipaddress-v4-aim-val-33665",
+        "management-option": "example-management-option-val-91111",
+        "internet-topology": "example-internet-topology-val-56425",
+        "host-profile": "example-host-profile-val-36247"
+    }
+}
index 6b24e1f..1f7cec5 100644 (file)
@@ -4,7 +4,7 @@
     <parent>
         <groupId>org.onap.aai.aai-common</groupId>
         <artifactId>aai-parent</artifactId>
-        <version>1.14.6-SNAPSHOT</version>
+        <version>1.14.7-SNAPSHOT</version>
         <relativePath>../aai-parent/pom.xml</relativePath>
     </parent>
     <artifactId>aai-els-onap-logging</artifactId>
index 240fd07..14c01b3 100644 (file)
@@ -5,7 +5,7 @@
     <parent>
         <groupId>org.onap.aai.aai-common</groupId>
         <artifactId>aai-parent</artifactId>
-        <version>1.14.6-SNAPSHOT</version>
+        <version>1.14.7-SNAPSHOT</version>
         <relativePath>../aai-parent/pom.xml</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>
index 3fe7b3f..d9a8022 100644 (file)
@@ -27,7 +27,7 @@ limitations under the License.
   <parent>
     <groupId>org.onap.aai.aai-common</groupId>
     <artifactId>aai-common</artifactId>
-    <version>1.14.6-SNAPSHOT</version>
+    <version>1.14.7-SNAPSHOT</version>
   </parent>
   <artifactId>aai-parent</artifactId>
   <name>aai-parent</name>
index 9af589f..a514b11 100644 (file)
@@ -29,7 +29,7 @@
     <parent>
         <groupId>org.onap.aai.aai-common</groupId>
         <artifactId>aai-parent</artifactId>
-        <version>1.14.6-SNAPSHOT</version>
+        <version>1.14.7-SNAPSHOT</version>
         <relativePath>../aai-parent/pom.xml</relativePath>
     </parent>
     <artifactId>aai-rest</artifactId>
index c89cf6e..cbf128e 100644 (file)
@@ -28,7 +28,7 @@
   <parent>
     <groupId>org.onap.aai.aai-common</groupId>
     <artifactId>aai-parent</artifactId>
-    <version>1.14.6-SNAPSHOT</version>
+    <version>1.14.7-SNAPSHOT</version>
     <relativePath>../aai-parent/pom.xml</relativePath>
   </parent>
 
index 56305a9..700db49 100644 (file)
@@ -26,7 +26,7 @@ limitations under the License.
        <parent>
                <groupId>org.onap.aai.aai-common</groupId>
                <artifactId>aai-parent</artifactId>
-               <version>1.14.6-SNAPSHOT</version>
+               <version>1.14.7-SNAPSHOT</version>
                <relativePath>../aai-parent/pom.xml</relativePath>
        </parent>
        <artifactId>aai-schema-ingest</artifactId>
index af541a2..a9d4aeb 100644 (file)
@@ -27,7 +27,7 @@
     <parent>
         <groupId>org.onap.aai.aai-common</groupId>
         <artifactId>aai-parent</artifactId>
-        <version>1.14.6-SNAPSHOT</version>
+        <version>1.14.7-SNAPSHOT</version>
         <relativePath>../aai-parent/pom.xml</relativePath>
     </parent>
     <artifactId>aai-utils</artifactId>
diff --git a/pom.xml b/pom.xml
index ce03066..9861d14 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -30,7 +30,7 @@
 
     <groupId>org.onap.aai.aai-common</groupId>
     <artifactId>aai-common</artifactId>
-    <version>1.14.6-SNAPSHOT</version>
+    <version>1.14.7-SNAPSHOT</version>
     <packaging>pom</packaging>
     <name>aai-aai-common</name>
     <description>Contains all of the common code for resources and traversal repos</description>