summaryrefslogtreecommitdiffstats
path: root/adapters/mso-vnfm-adapter
diff options
context:
space:
mode:
Diffstat (limited to 'adapters/mso-vnfm-adapter')
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-adapter-api/pom.xml1
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/pom.xml5
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterController.java89
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java90
4 files changed, 184 insertions, 1 deletions
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-adapter-api/pom.xml b/adapters/mso-vnfm-adapter/mso-vnfm-adapter-api/pom.xml
index 56d425745f..7e866f9008 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-adapter-api/pom.xml
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-adapter-api/pom.xml
@@ -44,6 +44,7 @@
<sourceFolder>src/gen/java/main</sourceFolder>
<withXml>true</withXml>
<useRxJava2>true</useRxJava2>
+ <serializableModel>true</serializableModel>
</configOptions>
</configuration>
</execution>
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/pom.xml b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/pom.xml
index 4554835b33..2e1fc97336 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/pom.xml
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/pom.xml
@@ -76,5 +76,10 @@
<artifactId>mso-adapters-rest-interface</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.onap.so.adapters</groupId>
+ <artifactId>mso-vnfm-adapter-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
</project>
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterController.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterController.java
index 4dabec3e9b..b14ead0c4f 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterController.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterController.java
@@ -21,14 +21,101 @@
package org.onap.so.adapters.vnfmadapter.rest;
import static org.onap.so.adapters.vnfmadapter.Constants.BASE_URL;
+import java.util.UUID;
+import javax.validation.Valid;
+import javax.ws.rs.core.MediaType;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.onap.vnfmadapter.v1.model.CreateVnfRequest;
+import org.onap.vnfmadapter.v1.model.CreateVnfResponse;
+import org.onap.vnfmadapter.v1.model.DeleteVnfResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
+import io.swagger.annotations.ApiParam;
/**
* Controller for handling requests to the VNFM (Virtual Network Function Manager) adapter REST API.
*/
@Controller
-@RequestMapping(value = BASE_URL)
+@RequestMapping(value = BASE_URL, produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
+ consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public class VnfmAdapterController {
+ private static final Logger logger = LoggerFactory.getLogger(VnfmAdapterController.class);
+
+ @PostMapping(value = "/vnfs/{vnfId}")
+ public ResponseEntity<CreateVnfResponse> vnfCreate(
+ @ApiParam(value = "The identifier of the VNF. This must be the vnf-id of an existing generic-vnf in AAI.",
+ required = true) @PathVariable("vnfId") final String vnfId,
+ @ApiParam(value = "VNF creation parameters",
+ required = true) @Valid @RequestBody final CreateVnfRequest createVnfRequest,
+ @ApiParam(
+ value = "Used to track REST requests for logging purposes. Identifies a single top level invocation of ONAP",
+ required = false) @RequestHeader(value = ONAPLogConstants.Headers.REQUEST_ID,
+ required = false) final String requestId,
+ @ApiParam(
+ value = "Used to track REST requests for logging purposes. Identifies the client application user agent or user invoking the API",
+ required = false) @RequestHeader(value = ONAPLogConstants.Headers.PARTNER_NAME,
+ required = false) final String partnerName,
+ @ApiParam(
+ value = "Used to track REST requests for logging purposes. Identifies a single invocation of a single component",
+ required = false) @RequestHeader(value = ONAPLogConstants.Headers.INVOCATION_ID,
+ required = false) final String invocationId) {
+
+ setLoggingMDCs(requestId, partnerName, invocationId);
+
+ logger.info("REST request vnfCreate with body: {}", createVnfRequest);
+
+ final CreateVnfResponse response = new CreateVnfResponse();
+ response.setJobId(UUID.randomUUID().toString());
+ clearLoggingMDCs();
+ return new ResponseEntity<>(response, HttpStatus.ACCEPTED);
+ }
+
+ @DeleteMapping(value = "/vnfs/{vnfId}")
+ public ResponseEntity<DeleteVnfResponse> vnfDelete(
+ @ApiParam(value = "The identifier of the VNF. This must be the vnf-id of an existing generic-vnf in AAI.",
+ required = true) @PathVariable("vnfId") final String vnfId,
+ @ApiParam(
+ value = "Used to track REST requests for logging purposes. Identifies a single top level invocation of ONAP",
+ required = false) @RequestHeader(value = ONAPLogConstants.Headers.REQUEST_ID,
+ required = false) final String requestId,
+ @ApiParam(
+ value = "Used to track REST requests for logging purposes. Identifies the client application user agent or user invoking the API",
+ required = false) @RequestHeader(value = ONAPLogConstants.Headers.PARTNER_NAME,
+ required = false) final String partnerName,
+ @ApiParam(
+ value = "Used to track REST requests for logging purposes. Identifies a single invocation of a single component",
+ required = false) @RequestHeader(value = ONAPLogConstants.Headers.INVOCATION_ID,
+ required = false) final String invocationId) {
+
+ setLoggingMDCs(requestId, partnerName, invocationId);
+
+ logger.info("REST request vnfDelete for VNF: {}", vnfId);
+
+ final DeleteVnfResponse response = new DeleteVnfResponse();
+ response.setJobId(UUID.randomUUID().toString());
+ clearLoggingMDCs();
+ return new ResponseEntity<>(response, HttpStatus.ACCEPTED);
+ }
+
+ private void setLoggingMDCs(final String requestId, final String partnerName, final String invocationId) {
+ MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, requestId);
+ MDC.put(ONAPLogConstants.MDCs.PARTNER_NAME, partnerName);
+ MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invocationId);
+ }
+
+ private void clearLoggingMDCs() {
+ MDC.clear();
+ }
+
}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java
new file mode 100644
index 0000000000..071a330e8b
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java
@@ -0,0 +1,90 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vnfmadapter.rest;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import java.net.URI;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.so.adapters.vnfmadapter.VnfmAdapterApplication;
+import org.onap.vnfmadapter.v1.model.CreateVnfRequest;
+import org.onap.vnfmadapter.v1.model.CreateVnfResponse;
+import org.onap.vnfmadapter.v1.model.DeleteVnfResponse;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
+import org.springframework.boot.test.web.client.TestRestTemplate;
+import org.springframework.boot.web.server.LocalServerPort;
+import org.springframework.http.MediaType;
+import org.springframework.http.RequestEntity;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = VnfmAdapterApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
+@ActiveProfiles("test")
+public class VnfmAdapterControllerTest {
+
+ @LocalServerPort
+ private int port;
+
+ private final TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
+
+ @Test
+ public void createVnf_ValidRequest_Returns202AndJobId() throws Exception {
+ final CreateVnfRequest createVnfRequest = new CreateVnfRequest();
+ final RequestEntity<CreateVnfRequest> request =
+ RequestEntity.post(new URI("http://localhost:" + port + "/so/vnfm-adapter/v1/vnfs/myVnfId"))
+ .accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON)
+ .header("X-ONAP-RequestId", "myRequestId").header("X-ONAP-InvocationID", "myInvocationId")
+ .body(createVnfRequest);
+ final ResponseEntity<CreateVnfResponse> response = restTemplate.exchange(request, CreateVnfResponse.class);
+ assertEquals(202, response.getStatusCode().value());
+ assertNotNull(response.getBody().getJobId());
+ }
+
+ @Test
+ public void createVnf_UnauthorizedUser_Returns401() throws Exception {
+ final TestRestTemplate restTemplateWrongPassword = new TestRestTemplate("test", "wrongPassword");
+ final CreateVnfRequest createVnfRequest = new CreateVnfRequest();
+ final RequestEntity<CreateVnfRequest> request =
+ RequestEntity.post(new URI("http://localhost:" + port + "/so/vnfm-adapter/v1/vnfs/myVnfId"))
+ .accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON)
+ .header("X-ONAP-RequestId", "myRequestId").header("X-ONAP-InvocationID", "myInvocationId")
+ .body(createVnfRequest);
+ final ResponseEntity<CreateVnfResponse> response =
+ restTemplateWrongPassword.exchange(request, CreateVnfResponse.class);
+ assertEquals(401, response.getStatusCode().value());
+ }
+
+ @Test
+ public void deleteVnf_ValidRequest_Returns202AndJobId() throws Exception {
+ final RequestEntity<Void> request = RequestEntity
+ .delete(new URI("http://localhost:" + port + "/so/vnfm-adapter/v1/vnfs/myVnfId"))
+ .accept(MediaType.APPLICATION_JSON).header("X-ONAP-RequestId", "myRequestId")
+ .header("X-ONAP-InvocationID", "myInvocationId").header("Content-Type", "application/json").build();
+ final ResponseEntity<DeleteVnfResponse> response = restTemplate.exchange(request, DeleteVnfResponse.class);
+ assertEquals(202, response.getStatusCode().value());
+ assertNotNull(response.getBody().getJobId());
+ }
+
+}