Added communication with DMaaP 47/101247/4
authorPiotr Borelowski <p.borelowski@partner.samsung.com>
Fri, 31 Jan 2020 13:03:35 +0000 (14:03 +0100)
committerPiotr Borelowski <p.borelowski@partner.samsung.com>
Fri, 7 Feb 2020 13:38:20 +0000 (13:38 +0000)
Ve-Vnfm (SOL002) Adapter project

Issue-ID: SO-2574
Signed-off-by: Piotr Borelowski <p.borelowski@partner.samsung.com>
Change-Id: Ia6674f594bbf2112cbdaab47c203cb78f1ebbff0

adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/controller/NotificationController.java
adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapService.java [new file with mode: 0644]
adapters/mso-ve-vnfm-adapter/src/main/resources/application.yaml
adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/controller/NotificationControllerTest.java

index 2e5a00a..1882b4e 100644 (file)
 
 package org.onap.so.adapters.vevnfm.controller;
 
+import org.onap.so.adapters.vevnfm.service.DmaapService;
 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperationOccurrenceNotification;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -33,9 +35,13 @@ public class NotificationController {
 
     private static final Logger logger = LoggerFactory.getLogger(NotificationController.class);
 
+    @Autowired
+    private DmaapService dmaapService;
+
     @PostMapping("${notification.url}")
     public ResponseEntity receiveNotification(@RequestBody final VnfLcmOperationOccurrenceNotification notification) {
         logger.info("Notification received {}", notification);
+        dmaapService.send(notification);
         return ResponseEntity.ok().build();
     }
 }
diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapService.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapService.java
new file mode 100644 (file)
index 0000000..59397ce
--- /dev/null
@@ -0,0 +1,39 @@
+package org.onap.so.adapters.vevnfm.service;
+
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperationOccurrenceNotification;
+import org.onap.so.rest.service.HttpRestServiceProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+
+@Service
+public class DmaapService {
+
+    private static final Logger logger = LoggerFactory.getLogger(DmaapService.class);
+
+    @Value("${dmaap.endpoint}")
+    private String endpoint;
+
+    @Value("${dmaap.topic}")
+    private String topic;
+
+    @Autowired
+    private HttpRestServiceProvider restProvider;
+
+    public void send(final VnfLcmOperationOccurrenceNotification notification) {
+        final ResponseEntity<String> response = restProvider.postHttpRequest(notification, getUrl(), String.class);
+
+        final HttpStatus statusCode = response.getStatusCode();
+        final String body = response.getBody();
+
+        logger.info("The DMaaP replied with the code {} and the body {}", statusCode, body);
+    }
+
+    private String getUrl() {
+        return endpoint + topic;
+    }
+}
index f3ad961..35871c5 100644 (file)
@@ -33,6 +33,10 @@ aai:
 vnfm:
   subscription: /vnflcm/v1/subscriptions
 
+dmaap:
+  endpoint: http://message-router:30227
+  topic: /events/unauthenticated.DCAE_CL_OUTPUT
+
 spring:
   security:
     usercredentials:
index 418c2e2..57638a1 100644 (file)
@@ -21,6 +21,9 @@
 package org.onap.so.adapters.vevnfm.controller;
 
 import static org.junit.Assert.assertEquals;
+import static org.springframework.test.web.client.ExpectedCount.once;
+import static org.springframework.test.web.client.match.MockRestRequestMatchers.anything;
+import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -33,11 +36,13 @@ import org.springframework.http.MediaType;
 import org.springframework.mock.web.MockHttpServletResponse;
 import org.springframework.test.context.ActiveProfiles;
 import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.web.client.MockRestServiceServer;
 import org.springframework.test.web.servlet.MockMvc;
 import org.springframework.test.web.servlet.MvcResult;
 import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
 import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
 import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+import org.springframework.web.client.RestTemplate;
 import org.springframework.web.context.WebApplicationContext;
 
 @SpringBootTest
@@ -54,11 +59,16 @@ public class NotificationControllerTest {
     @Autowired
     private WebApplicationContext webApplicationContext;
 
+    @Autowired
+    private RestTemplate restTemplate;
+
     private MockMvc mvc;
+    private MockRestServiceServer mockRestServer;
 
     @Before
     public void init() {
         mvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
+        mockRestServer = MockRestServiceServer.bindTo(restTemplate).build();
     }
 
     @Test
@@ -67,6 +77,8 @@ public class NotificationControllerTest {
         final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(notificationUrl)
                 .contentType(MediaType.APPLICATION_JSON).content(MINIMAL_JSON_CONTENT);
 
+        mockRestServer.expect(once(), anything()).andRespond(withSuccess());
+
         // when
         final MvcResult mvcResult = mvc.perform(request).andReturn();
 
@@ -74,5 +86,6 @@ public class NotificationControllerTest {
         final MockHttpServletResponse response = mvcResult.getResponse();
         assertEquals(HttpStatus.OK.value(), response.getStatus());
         assertEquals(ZERO, response.getContentLength());
+        mockRestServer.verify();
     }
 }