summaryrefslogtreecommitdiffstats
path: root/adapters/mso-ve-vnfm-adapter
diff options
context:
space:
mode:
authorSteve Smokowski <ss835w@att.com>2020-02-10 17:02:50 +0000
committerGerrit Code Review <gerrit@onap.org>2020-02-10 17:02:50 +0000
commitc1dacabbcf9f9f09a00458b44f5168f1273965ec (patch)
tree2c75049bba2978dca7b24889eb14354a0b68f4f1 /adapters/mso-ve-vnfm-adapter
parentac1a59fc6731c6261712eac5bec76816b11d1096 (diff)
parent37dad48713382ce04354e2231bd2938246f45340 (diff)
Merge "Added communication with DMaaP"
Diffstat (limited to 'adapters/mso-ve-vnfm-adapter')
-rw-r--r--adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/controller/NotificationController.java6
-rw-r--r--adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapService.java39
-rw-r--r--adapters/mso-ve-vnfm-adapter/src/main/resources/application.yaml4
-rw-r--r--adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/controller/NotificationControllerTest.java13
4 files changed, 62 insertions, 0 deletions
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<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;
+ }
+}
diff --git a/adapters/mso-ve-vnfm-adapter/src/main/resources/application.yaml b/adapters/mso-ve-vnfm-adapter/src/main/resources/application.yaml
index f3ad9615ec..35871c51ac 100644
--- a/adapters/mso-ve-vnfm-adapter/src/main/resources/application.yaml
+++ b/adapters/mso-ve-vnfm-adapter/src/main/resources/application.yaml
@@ -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:
diff --git a/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/controller/NotificationControllerTest.java b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/controller/NotificationControllerTest.java
index 418c2e2201..57638a165a 100644
--- a/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/controller/NotificationControllerTest.java
+++ b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/controller/NotificationControllerTest.java
@@ -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();
}
}
://localhost:8181`. As an alternative, you can work using Hot Module Replacement (HMR): * `npm run start:hmr` And you are all set! You can now modify your components on the fly without having to reload the entire page. ## Testing #### 1. Unit Tests * single run: `npm test` * live mode (TDD style): `npm run test-watch` #### 2. End-to-End Tests (aka. e2e, integration) * single run: * in a tab, *if not already running!*: `npm start` * in a new tab: `npm run webdriver-start` * in another new tab: `npm run e2e` * interactive mode: * instead of the last command above, you can run: `npm run e2e-live` * when debugging or first writing test suites, you may find it helpful to try out Protractor commands without starting up the entire test suite. You can do this with the element explorer. * you can learn more about [Protractor Interactive Mode here](https://github.com/angular/protractor/blob/master/docs/debugging.md#testing-out-protractor-interactively) ## Production To build your application, run: * `npm run build` You can now go to `/dist` and deploy that to your server! ## Documentation You can generate api docs (using [TypeDoc](http://typedoc.org/)) for your code with the following: * `npm run docs` # FAQ #### Do I need to add script / link tags into index.html ? No, Webpack will add all the needed Javascript bundles as script tags and all the CSS files as link tags. The advantage is that you don't need to modify the index.html every time you build your solution to update the hashes. #### How to include external angular libraries ? It's simple, just install the lib via npm and import it in your code when you need it. Don't forget that you need to configure some external libs in the [bootstrap](https://github.com/preboot/angular-webpack/blob/master/src/main.ts) of your application. #### How to include external css files such as bootstrap.css ? Just install the lib and import the css files in [vendor.ts](https://github.com/preboot/angular-webpack/blob/master/src/vendor.ts). For example this is how to do it with bootstrap: ```sh npm install bootstrap@next --save ``` And in [vendor.ts](https://github.com/preboot/angular-webpack/blob/master/src/vendor.ts) add the following: ```ts import 'bootstrap/dist/css/bootstrap.css'; ``` # TypeScript > To take full advantage of TypeScript with autocomplete you would have to use an editor with the correct TypeScript plugins. ## Use a TypeScript-aware editor We have good experience using these editors: * [Visual Studio Code](https://code.visualstudio.com/) * [Webstorm 11+](https://www.jetbrains.com/webstorm/download/) * [Atom](https://atom.io/) with [TypeScript plugin](https://atom.io/packages/atom-typescript) * [Sublime Text](http://www.sublimetext.com/3) with [Typescript-Sublime-Plugin](https://github.com/Microsoft/Typescript-Sublime-plugin#installation) # License The vid-webpack-master project is provided under the Apache License, version 2.0 (Apache-2.0). It includes code from the angular-webpack template files, which were originally provided under the MIT license.