aboutsummaryrefslogtreecommitdiffstats
path: root/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service
diff options
context:
space:
mode:
authorAndrewLamb <andrew.a.lamb@est.tech>2020-09-10 13:37:31 +0100
committerAndrewLamb <andrew.a.lamb@est.tech>2020-09-24 16:22:13 +0100
commitb4b7e11715b8dbeda752229012d8cdc00ed5c32f (patch)
tree9419c2c5af45de5accdced7dfac058ebda822e80 /so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service
parent8d68a316f303d0fc57eb7da4fef881a26d39d439 (diff)
Terminate NS Backend Service
Issue-ID: SO-2869 Change-Id: I9c2b268d4f9aba7179633b71c8994065acacb742 Signed-off-by: AndrewLamb <andrew.a.lamb@est.tech>
Diffstat (limited to 'so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service')
-rw-r--r--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.java2
-rw-r--r--so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/lifecycle/NsLifeCycleManager.java10
-rw-r--r--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.java10
-rw-r--r--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.java40
4 files changed, 50 insertions, 12 deletions
diff --git a/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 b/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
index da1649de57..80ec60468f 100644
--- a/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
+++ b/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
@@ -45,7 +45,7 @@ public class EtsiSoNsLcmManagerUrlProvider {
+ nsInstanceId);
}
- public URI getInstantiatedOccUri(final String nsLcmOpOccId) {
+ public URI getNsLcmOpOccUri(final String nsLcmOpOccId) {
return URI.create(etsiNsLcmManagerEndpoint + Constants.NS_LIFE_CYCLE_MANAGEMENT_BASE_URL + "/ns_lcm_op_occs/"
+ nsLcmOpOccId);
}
diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/lifecycle/NsLifeCycleManager.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/lifecycle/NsLifeCycleManager.java
index 792ffdd00a..2ebf55ff7f 100644
--- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/lifecycle/NsLifeCycleManager.java
+++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/lifecycle/NsLifeCycleManager.java
@@ -27,6 +27,7 @@ import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.service.JobExecutorService;
import org.onap.so.etsi.nfvo.ns.lcm.model.CreateNsRequest;
import org.onap.so.etsi.nfvo.ns.lcm.model.InstantiateNsRequest;
import org.onap.so.etsi.nfvo.ns.lcm.model.NsInstancesNsInstance;
+import org.onap.so.etsi.nfvo.ns.lcm.model.TerminateNsRequest;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -70,8 +71,15 @@ public class NsLifeCycleManager {
instantiateNsRequest, nsInstanceId);
final String nsLcmOpOccId = jobExecutorService.runInstantiateNsJob(nsInstanceId, instantiateNsRequest);
- return etsiSoNsLcmManagerUrlProvider.getInstantiatedOccUri(nsLcmOpOccId);
+ return etsiSoNsLcmManagerUrlProvider.getNsLcmOpOccUri(nsLcmOpOccId);
}
+ public URI terminateNs(final String nsInstanceId, final TerminateNsRequest terminateNsRequest) {
+ logger.info("Will execute Terminate Ns for TerminateNsRequest: {} and nsInstanceId: {}", terminateNsRequest,
+ nsInstanceId);
+ final String nsLcmOpOccId = jobExecutorService.runTerminateNsJob(nsInstanceId, terminateNsRequest);
+
+ return etsiSoNsLcmManagerUrlProvider.getNsLcmOpOccUri(nsLcmOpOccId);
+ }
}
diff --git a/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 b/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
index 87ec8420c6..cfda89f3f0 100644
--- a/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
+++ b/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
@@ -72,8 +72,9 @@ public class NsLifecycleManagementController {
* @param globalCustomerId The global customer ID
* @param serviceType The service type
* @param createNsRequest create network service request (see clause 6.5.2.9)
- * @return "201 Created" response containing a representation of the NS instance resource {@link NsInstance} just
- * created by the NFVO, and provides the URI of the newly-created resource in the "Location:" HTTP header
+ * @return "201 Created" response containing a representation of the NS instance resource
+ * {@link NsInstancesNsInstance} just created by the NFVO, and provides the URI of the newly-created
+ * resource in the "Location:" HTTP header
*/
@PostMapping(value = "/ns_instances", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@@ -145,7 +146,10 @@ public class NsLifecycleManagementController {
public ResponseEntity<?> terminateNs(@PathVariable("nsInstanceId") final String nsInstanceId,
@RequestBody final TerminateNsRequest terminateNsRequest) {
logger.debug("Received terminate NS request: {}\n with nsInstanceId: {}", terminateNsRequest, nsInstanceId);
- return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).body("Operation is not supported yet");
+ final URI resourceUri = nsLifeCycleManager.terminateNs(nsInstanceId, terminateNsRequest);
+ logger.info("{} Ns Terminate started successfully. Resource Operation Occurrence uri: {}", nsInstanceId,
+ resourceUri);
+ return ResponseEntity.accepted().location(resourceUri).build();
}
}
diff --git a/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 b/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
index 81c4e8fd68..4b1195244c 100644
--- a/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
+++ b/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
@@ -77,7 +77,7 @@ public class NsLifecycleManagementControllerTest {
private static final String GLOBAL_CUSTOMER_ID = UUID.randomUUID().toString();
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 =
+ private static final String EXPECTED_NS_LCM_OP_OCC_REQ_LOCATION_URL =
EXPECTED_BASE_URL + "/ns_lcm_op_occs/" + RANDOM_NS_LCM_OP_OCC_ID;
@LocalServerPort
@@ -197,7 +197,7 @@ public class NsLifecycleManagementControllerTest {
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));
+ assertEquals(EXPECTED_NS_LCM_OP_OCC_REQ_LOCATION_URL, actual.get(0));
}
@Test
@@ -218,17 +218,43 @@ public class NsLifecycleManagementControllerTest {
}
@Test
- public void testTerminateNs_ValidInstantiateNsRequest() {
- final String baseUrl = getNsLcmBaseUrl() + "/ns_instances/" + UUID.randomUUID().toString() + "/terminate";
- final HttpEntity<?> request = new HttpEntity<>(getTerminateNsRequest());
+ public void testTerminateNs_ValidTerminateNsRequest_Success() {
+ final TerminateNsRequest terminateNsRequest = getTerminateNsRequest();
+ when(mockedJobExecutorService.runTerminateNsJob(eq(RANDOM_NS_INST_ID), eq(terminateNsRequest)))
+ .thenReturn(RANDOM_NS_LCM_OP_OCC_ID);
+
+ final String baseUrl = getNsLcmBaseUrl() + "/ns_instances/" + RANDOM_NS_INST_ID + "/terminate";
+ final HttpEntity<?> request = new HttpEntity<>(terminateNsRequest);
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_NS_LCM_OP_OCC_REQ_LOCATION_URL, actual.get(0));
}
+ @Test
+ public void testTerminateNs_ValidTerminateNsRequest_nsRequestProcessingExceptionThrown_returnInlineResponse400() {
+ final String errorMessage = "ERROR MESSAGE";
+ final TerminateNsRequest terminateNsRequest = getTerminateNsRequest();
+ when(mockedJobExecutorService.runTerminateNsJob(eq(RANDOM_NS_INST_ID), eq(terminateNsRequest)))
+ .thenThrow(new NsRequestProcessingException(errorMessage));
+
+ final String baseUrl = getNsLcmBaseUrl() + "/ns_instances/" + RANDOM_NS_INST_ID + "/terminate";
+ final HttpEntity<?> request = new HttpEntity<>(terminateNsRequest);
+ 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());
+ }
private TerminateNsRequest getTerminateNsRequest() {
- return new TerminateNsRequest().terminationTime(LocalDateTime.now());
+ // Only support for the immediate Terminate request; i.e., terminateTime field is empty (not set)
+ return new TerminateNsRequest();
}
private InstantiateNsRequest getInstantiateNsRequest() {