Create empty implementation of delete VNF request 75/83175/1
authorMichaelMorris <michael.morris@est.tech>
Mon, 25 Mar 2019 10:51:21 +0000 (10:51 +0000)
committerMichaelMorris <michael.morris@est.tech>
Mon, 25 Mar 2019 10:51:21 +0000 (10:51 +0000)
The implementation provides no functionality (just logs the call and returns 202 with a job id) but enables invocation of the adapter from a flow

Issue-ID: SO-1632
Change-Id: Ie71699e917173c77b217e8a9f5eb9e5b794155a7
Signed-off-by: MichaelMorris <michael.morris@est.tech>
adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterController.java
adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java

index 77a3f21..b14ead0 100644 (file)
@@ -27,12 +27,14 @@ 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;
@@ -58,15 +60,15 @@ public class VnfmAdapterController {
                     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 = true) @RequestHeader(value = ONAPLogConstants.Headers.REQUEST_ID,
+                    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 = true) @RequestHeader(value = ONAPLogConstants.Headers.PARTNER_NAME,
+                    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 = true) @RequestHeader(value = ONAPLogConstants.Headers.INVOCATION_ID,
+                    required = false) @RequestHeader(value = ONAPLogConstants.Headers.INVOCATION_ID,
                             required = false) final String invocationId) {
 
         setLoggingMDCs(requestId, partnerName, invocationId);
@@ -79,6 +81,33 @@ public class VnfmAdapterController {
         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);
index 842b3b5..071a330 100644 (file)
@@ -28,6 +28,7 @@ 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;
@@ -75,4 +76,15 @@ public class VnfmAdapterControllerTest {
         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());
+    }
+
 }