From 37dad48713382ce04354e2231bd2938246f45340 Mon Sep 17 00:00:00 2001 From: Piotr Borelowski Date: Fri, 31 Jan 2020 14:03:35 +0100 Subject: Added communication with DMaaP Ve-Vnfm (SOL002) Adapter project Issue-ID: SO-2574 Signed-off-by: Piotr Borelowski Change-Id: Ia6674f594bbf2112cbdaab47c203cb78f1ebbff0 --- .../vevnfm/controller/NotificationController.java | 6 ++++ .../so/adapters/vevnfm/service/DmaapService.java | 39 ++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapService.java (limited to 'adapters/mso-ve-vnfm-adapter/src/main/java/org') diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/controller/NotificationController.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/controller/NotificationController.java index 2e5a00ad02..1882b4e183 100644 --- a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/controller/NotificationController.java +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/controller/NotificationController.java @@ -20,9 +20,11 @@ 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 index 0000000000..59397cead3 --- /dev/null +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapService.java @@ -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 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; + } +} -- cgit 1.2.3-korg