Adding NS instantiation 55/112355/1
authorwaqas.ikram <waqas.ikram@est.tech>
Wed, 9 Sep 2020 08:41:54 +0000 (09:41 +0100)
committerwaqas.ikram <waqas.ikram@est.tech>
Wed, 9 Sep 2020 09:04:06 +0000 (10:04 +0100)
Change-Id: I06a8e1c9bfeb82f5fc61604030ec62bd17193e90
Issue-ID: SO-2868
Signed-off-by: waqas.ikram <waqas.ikram@est.tech>
so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-application/src/main/resources/application.yaml
so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/EtsiSoNsLcmManagerUrlProvider.java
so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementController.java
so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/rest/exceptions/NsLcmControllerExceptionHandler.java
so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementControllerTest.java
so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/resources/application.yaml

index 6dfe635..7f0fd93 100644 (file)
@@ -65,5 +65,5 @@ so:
 etsi-catalog-manager:
    base:
       endpoint: http://modeling-etsicatalog.onap:8806/api
-etsi-so-ns-lcm-manager:
-   endpoint: http://so-etsi-nfvo-ns-lcm:9095
\ No newline at end of file
+so-etsi-nfvo-ns-lcm:
+   endpoint: http://so-etsi-nfvo-ns-lcm.onap:9095
\ No newline at end of file
index baf1119..da1649d 100644 (file)
@@ -36,7 +36,7 @@ public class EtsiSoNsLcmManagerUrlProvider {
 
     @Autowired
     public EtsiSoNsLcmManagerUrlProvider(
-            @Value("${etsi-so-ns-lcm-manager.endpoint}") final String etsiNsLcmManagerEndpoint) {
+            @Value("${so-etsi-nfvo-ns-lcm.endpoint:http://so-etsi-nfvo-ns-lcm.onap:9095}") final String etsiNsLcmManagerEndpoint) {
         this.etsiNsLcmManagerEndpoint = etsiNsLcmManagerEndpoint;
     }
 
index fb0a250..87ec842 100644 (file)
@@ -125,7 +125,10 @@ public class NsLifecycleManagementController {
     public ResponseEntity<?> instantiateNs(@PathVariable("nsInstanceId") final String nsInstanceId,
             @RequestBody final InstantiateNsRequest instantiateNsRequest) {
         logger.debug("Received instantiate NS request: {}\n with nsInstanceId: {}", instantiateNsRequest, nsInstanceId);
-        return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).body("Operation is not supported yet");
+        final URI resourceUri = nsLifeCycleManager.instantiateNs(nsInstanceId, instantiateNsRequest);
+        logger.info("{} Ns Instantiation started successfully. Resource Operation Occurrence uri: {}", nsInstanceId,
+                resourceUri);
+        return ResponseEntity.accepted().location(resourceUri).build();
     }
 
     /**
index 8d9fdbe..3db04fc 100644 (file)
@@ -41,21 +41,18 @@ public class NsLcmControllerExceptionHandler {
                 .body(getInlineResponse400(nsRequestProcessingException));
     }
 
-    private InlineResponse400 getInlineResponse400(final NsRequestProcessingException nsRequestProcessingException) {
+    @ExceptionHandler(Exception.class)
+    public ResponseEntity<InlineResponse400> handleNsRequestProcessingException(final Exception exception) {
+        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new InlineResponse400()
+                .status(HttpStatus.INTERNAL_SERVER_ERROR.value()).detail(exception.getMessage()));
+    }
 
+    private InlineResponse400 getInlineResponse400(final NsRequestProcessingException nsRequestProcessingException) {
         if (nsRequestProcessingException.getProblemDetails() != null) {
             return nsRequestProcessingException.getProblemDetails();
         }
-
         return new InlineResponse400().status(HttpStatus.INTERNAL_SERVER_ERROR.value())
                 .detail(nsRequestProcessingException.getMessage());
-
-    }
-
-    @ExceptionHandler(Exception.class)
-    public ResponseEntity<InlineResponse400> handleNsRequestProcessingException(final Exception exception) {
-        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new InlineResponse400()
-                .status(HttpStatus.INTERNAL_SERVER_ERROR.value()).detail(exception.getMessage()));
     }
 
 }
index 4ff74ea..81c4e8f 100644 (file)
@@ -69,11 +69,16 @@ import com.google.gson.Gson;
 @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
 @ActiveProfiles("test")
 public class NsLifecycleManagementControllerTest {
+    private static final String EXPECTED_BASE_URL =
+            "http://so-etsi-nfvo-ns-lcm.onap:9095/so/so-etsi-nfvo-ns-lcm/v1/api/nslcm/v1";
+    private static final String RANDOM_NS_LCM_OP_OCC_ID = UUID.randomUUID().toString();
     private static final String RANDOM_NS_INST_ID = UUID.randomUUID().toString();
     private static final String SERVICE_TYPE = "NetworkService";
     private static final String GLOBAL_CUSTOMER_ID = UUID.randomUUID().toString();
-    private static final String EXPECTED_LOCATION_URL = "http://etsi-so-ns-lcm-manager-service:9095"
-            + "/so/so-etsi-nfvo-ns-lcm/v1/" + "api/nslcm/v1/ns_instances/" + RANDOM_NS_INST_ID;
+    private static final String EXPECTED_CREATE_REQ_LOCATION_URL =
+            EXPECTED_BASE_URL + "/ns_instances/" + RANDOM_NS_INST_ID;
+    private static final String EXPECTED_INSTANTIATE_REQ_LOCATION_URL =
+            EXPECTED_BASE_URL + "/ns_lcm_op_occs/" + RANDOM_NS_LCM_OP_OCC_ID;
 
     @LocalServerPort
     private int port;
@@ -115,7 +120,7 @@ public class NsLifecycleManagementControllerTest {
         assertTrue(httpHeaders.containsKey(HttpHeaders.LOCATION));
         final List<String> actual = httpHeaders.get(HttpHeaders.LOCATION);
         assertEquals(1, actual.size());
-        assertEquals(EXPECTED_LOCATION_URL, actual.get(0));
+        assertEquals(EXPECTED_CREATE_REQ_LOCATION_URL, actual.get(0));
     }
 
     @Test
@@ -177,11 +182,39 @@ public class NsLifecycleManagementControllerTest {
 
     @Test
     public void testInstantiateNs_ValidInstantiateNsRequest() {
-        final String baseUrl = getNsLcmBaseUrl() + "/ns_instances/" + UUID.randomUUID().toString() + "/instantiate";
-        final HttpEntity<?> request = new HttpEntity<>(getInstantiateNsRequest());
+
+        final InstantiateNsRequest instantiateNsRequest = getInstantiateNsRequest();
+        when(mockedJobExecutorService.runInstantiateNsJob(eq(RANDOM_NS_INST_ID), eq(instantiateNsRequest)))
+                .thenReturn(RANDOM_NS_LCM_OP_OCC_ID);
+
+        final String baseUrl = getNsLcmBaseUrl() + "/ns_instances/" + RANDOM_NS_INST_ID + "/instantiate";
+        final HttpEntity<?> request = new HttpEntity<>(instantiateNsRequest);
         final ResponseEntity<Void> responseEntity =
                 testRestTemplate.exchange(baseUrl, HttpMethod.POST, request, Void.class);
-        assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode());
+        assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode());
+
+        final HttpHeaders httpHeaders = responseEntity.getHeaders();
+        assertTrue(httpHeaders.containsKey(HttpHeaders.LOCATION));
+        final List<String> actual = httpHeaders.get(HttpHeaders.LOCATION);
+        assertEquals(1, actual.size());
+        assertEquals(EXPECTED_INSTANTIATE_REQ_LOCATION_URL, actual.get(0));
+    }
+
+    @Test
+    public void testInstantiateNs_instantiateNsRequest_nsRequestProcessingExceptionThrown_returnInlineResponse400() {
+        final String message = "Unable to process request";
+        final InstantiateNsRequest instantiateNsRequest = getInstantiateNsRequest();
+        when(mockedJobExecutorService.runInstantiateNsJob(eq(RANDOM_NS_INST_ID), eq(instantiateNsRequest)))
+                .thenThrow(new NsRequestProcessingException(message, new InlineResponse400().detail(message)));
+
+        final String baseUrl = getNsLcmBaseUrl() + "/ns_instances/" + RANDOM_NS_INST_ID + "/instantiate";
+        final HttpEntity<?> request = new HttpEntity<>(instantiateNsRequest);
+        final ResponseEntity<InlineResponse400> responseEntity =
+                testRestTemplate.exchange(baseUrl, HttpMethod.POST, request, InlineResponse400.class);
+
+        assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
+        assertTrue(responseEntity.hasBody());
+        assertNotNull(responseEntity.getBody());
     }
 
     @Test
index 6c8a799..44acda2 100644 (file)
@@ -26,7 +26,7 @@ spring:
          nfvo:
             jdbcUrl: jdbc:h2:mem:NFVO;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS NFVO;
             driver-class-name: org.h2.Driver
-            pool-name: ns-lcm-bpmn-pool
+            pool-name: ns-lcm-nfvo-pool
             registerMbeans: true
    jpa:
       hibernate:
@@ -36,6 +36,4 @@ logging:
       org.reflections.Reflections: ERROR
 etsi-catalog-manager:
    base:
-      endpoint: http://modeling-etsicatalog.onap:8806/api
-etsi-so-ns-lcm-manager:
-   endpoint: http://etsi-so-ns-lcm-manager-service:9095
\ No newline at end of file
+      endpoint: http://modeling-etsicatalog.onap:8806/api
\ No newline at end of file