summaryrefslogtreecommitdiffstats
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-10-07 14:12:44 +0100
committerAndrewLamb <andrew.a.lamb@est.tech>2020-10-13 16:38:58 +0100
commit1d12326d47c541934fd0ee3376844a159941a9ef (patch)
tree7fa730f6e793229ead98068f65993d7e1ccf586d /so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service
parent33fb2c6e36d763fd9d24f55debc55c458dab6780 (diff)
SO-ETSI-NFVO Get NS Operation Status Backend Service
Issue-ID: SO-2871 Change-Id: I1b17bbc5750abb38bf017df4088c4b40db3552ab 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/lifecycle/NsLcmOperationOccurrenceManager.java122
-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/NsLcmOperationOccurrencesController.java24
-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/NsLcmOperationOccurrencesControllerTest.java72
-rw-r--r--so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/resources/application.yaml6
4 files changed, 213 insertions, 11 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/lifecycle/NsLcmOperationOccurrenceManager.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/NsLcmOperationOccurrenceManager.java
new file mode 100644
index 0000000000..8a5cee6d75
--- /dev/null
+++ 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/NsLcmOperationOccurrenceManager.java
@@ -0,0 +1,122 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 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.etsi.nfvo.ns.lcm.lifecycle;
+
+import static org.slf4j.LoggerFactory.getLogger;
+import org.onap.so.etsi.nfvo.ns.lcm.EtsiSoNsLcmManagerUrlProvider;
+import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NsLcmOpOcc;
+import org.onap.so.etsi.nfvo.ns.lcm.database.service.DatabaseServiceProvider;
+import org.onap.so.etsi.nfvo.ns.lcm.model.NsInstancesNsInstanceLinksSelf;
+import org.onap.so.etsi.nfvo.ns.lcm.model.NsLcmOpOccsNsLcmOpOcc;
+import org.onap.so.etsi.nfvo.ns.lcm.model.NsLcmOpOccsNsLcmOpOccLinks;
+import org.slf4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import java.util.Optional;
+
+/**
+ * @author Waqas Ikram (waqas.ikram@est.tech)
+ * @author Andrew Lamb (andrew.a.lamb@est.tech)
+ *
+ */
+@Service
+public class NsLcmOperationOccurrenceManager {
+
+ private static final Logger logger = getLogger(NsLcmOperationOccurrenceManager.class);
+
+ private final DatabaseServiceProvider databaseServiceProvider;
+ private final EtsiSoNsLcmManagerUrlProvider etsiSoNsLcmManagerUrlProvider;
+
+ @Autowired
+ public NsLcmOperationOccurrenceManager(final DatabaseServiceProvider databaseServiceProvider,
+ final EtsiSoNsLcmManagerUrlProvider etsiSoNsLcmManagerUrlProvider) {
+ this.databaseServiceProvider = databaseServiceProvider;
+ this.etsiSoNsLcmManagerUrlProvider = etsiSoNsLcmManagerUrlProvider;
+ }
+
+ public Optional<NsLcmOpOccsNsLcmOpOcc> getNsLcmOperationOccurrence(final String nsLcmOpOccId) {
+ logger.info("Getting NS LCM Operation Occurrence Operation for id: {}", nsLcmOpOccId);
+ final Optional<NsLcmOpOcc> optionalNsLcmOpOcc = databaseServiceProvider.getNsLcmOpOcc(nsLcmOpOccId);
+
+ if (optionalNsLcmOpOcc.isEmpty()) {
+ logger.info("No NS LCM Operation Occurrence found for id: {}", nsLcmOpOccId);
+ return Optional.empty();
+ }
+
+ logger.info("Found NS LCM Operation Occurrence for id: {}", nsLcmOpOccId);
+ final NsLcmOpOcc nsLcmOpOcc = optionalNsLcmOpOcc.get();
+ final NsLcmOpOccsNsLcmOpOcc nsLcmOpOccsNsLcmOpOcc = convertToNsLcmOpOccsNsLcmOpOcc(nsLcmOpOcc);
+ return Optional.of(nsLcmOpOccsNsLcmOpOcc);
+ }
+
+ private NsLcmOpOccsNsLcmOpOcc convertToNsLcmOpOccsNsLcmOpOcc(final NsLcmOpOcc nsLcmOpOcc) {
+ logger.info("Converting Database NsLcmOpOcc to API NsLcmOpOcc... ");
+ final NsLcmOpOccsNsLcmOpOcc nsLcmOpOccsNsLcmOpOcc =
+ new NsLcmOpOccsNsLcmOpOcc().id(nsLcmOpOcc.getId()).statusEnteredTime(nsLcmOpOcc.getStateEnteredTime())
+ .startTime(nsLcmOpOcc.getStartTime()).isAutomaticInvocation(nsLcmOpOcc.getIsAutoInvocation())
+ .isCancelPending(nsLcmOpOcc.getIsCancelPending());
+
+ if (nsLcmOpOcc.getNfvoNsInst() != null) {
+ nsLcmOpOccsNsLcmOpOcc.setNsInstanceId(nsLcmOpOcc.getNfvoNsInst().getNsInstId());
+ }
+
+ if (nsLcmOpOcc.getOperationState() != null) {
+ nsLcmOpOccsNsLcmOpOcc.setOperationState(
+ NsLcmOpOccsNsLcmOpOcc.OperationStateEnum.fromValue(nsLcmOpOcc.getOperationState().toString()));
+ }
+
+ if (nsLcmOpOcc.getOperation() != null) {
+ nsLcmOpOccsNsLcmOpOcc.setLcmOperationType(
+ NsLcmOpOccsNsLcmOpOcc.LcmOperationTypeEnum.fromValue(nsLcmOpOcc.getOperation().toString()));
+ }
+
+ if (nsLcmOpOcc.getOperationParams() != null) {
+ nsLcmOpOccsNsLcmOpOcc.setOperationParams(nsLcmOpOcc.getOperationParams());
+ }
+
+ if (nsLcmOpOcc.getCancelMode() != null) {
+ nsLcmOpOccsNsLcmOpOcc.setCancelMode(
+ NsLcmOpOccsNsLcmOpOcc.CancelModeEnum.fromValue(nsLcmOpOcc.getCancelMode().toString()));
+ }
+
+ nsLcmOpOccsNsLcmOpOcc.setLinks(generateLinks(nsLcmOpOcc));
+
+ logger.info("Database NsLcmOpOcc converted to API NsLcmOpOcc successfully... {}", nsLcmOpOccsNsLcmOpOcc);
+ return nsLcmOpOccsNsLcmOpOcc;
+ }
+
+ private NsLcmOpOccsNsLcmOpOccLinks generateLinks(final NsLcmOpOcc nsLcmOpOcc) {
+ logger.info("Generating links...");
+ final String nsLcmOpOccId = nsLcmOpOcc.getId();
+ final NsInstancesNsInstanceLinksSelf linksSelfNsLcmOpOcc = new NsInstancesNsInstanceLinksSelf()
+ .href(etsiSoNsLcmManagerUrlProvider.getNsLcmOpOccUri(nsLcmOpOccId).toString());
+ final NsLcmOpOccsNsLcmOpOccLinks links = new NsLcmOpOccsNsLcmOpOccLinks().self(linksSelfNsLcmOpOcc);
+
+ if (nsLcmOpOcc.getNfvoNsInst() != null) {
+ final String nsInstId = nsLcmOpOcc.getNfvoNsInst().getNsInstId();
+ final NsInstancesNsInstanceLinksSelf linksSelfNsInst = new NsInstancesNsInstanceLinksSelf()
+ .href(etsiSoNsLcmManagerUrlProvider.getCreatedNsResourceUri(nsInstId).toString());
+ links.setNsInstance(linksSelfNsInst);
+ }
+
+ return links;
+ }
+
+}
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/NsLcmOperationOccurrencesController.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/NsLcmOperationOccurrencesController.java
index ec79ce6329..207f0ff387 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/NsLcmOperationOccurrencesController.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/NsLcmOperationOccurrencesController.java
@@ -22,20 +22,25 @@ package org.onap.so.etsi.nfvo.ns.lcm.rest;
import static org.onap.so.etsi.nfvo.ns.lcm.Constants.NS_LIFE_CYCLE_MANAGEMENT_BASE_URL;
import static org.slf4j.LoggerFactory.getLogger;
import javax.ws.rs.core.MediaType;
+import org.onap.so.etsi.nfvo.ns.lcm.lifecycle.NsLcmOperationOccurrenceManager;
+import org.onap.so.etsi.nfvo.ns.lcm.model.InlineResponse400;
import org.onap.so.etsi.nfvo.ns.lcm.model.NsLcmOpOccsNsLcmOpOcc;
import org.slf4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
+import java.util.Optional;
/**
* Controller for handling NS lifecycle management operation occurrence requests see clause 6.4.9 and 6.4.10 in
* https://www.etsi.org/deliver/etsi_gs/NFV-SOL/001_099/005/02.07.01_60/gs_NFV-SOL005v020701p.pdf
*
* @author Waqas Ikram (waqas.ikram@est.tech)
+ * @author Andrew Lamb (andrew.a.lamb@est.tech)
*
*/
@Controller
@@ -43,6 +48,12 @@ import org.springframework.web.bind.annotation.RequestMapping;
public class NsLcmOperationOccurrencesController {
private static final Logger logger = getLogger(NsLcmOperationOccurrencesController.class);
+ private final NsLcmOperationOccurrenceManager nsLcmOperationOccurrenceManager;
+
+ @Autowired
+ public NsLcmOperationOccurrencesController(final NsLcmOperationOccurrenceManager nsLcmOperationOccurrenceManager) {
+ this.nsLcmOperationOccurrenceManager = nsLcmOperationOccurrenceManager;
+ }
/**
* The GET method to retrieve status information about a NS lifecycle management operation occurrence by reading an
@@ -57,7 +68,18 @@ public class NsLcmOperationOccurrencesController {
produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public ResponseEntity<?> getOperationStatus(@PathVariable("nsLcmOpOccId") final String nsLcmOpOccId) {
logger.info("Received request to retrieve operation status for nsLcmOpOccId: {}", nsLcmOpOccId);
- return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).body("Operation is not supported yet");
+ final Optional<NsLcmOpOccsNsLcmOpOcc> optionalNsLcmOpOccs =
+ nsLcmOperationOccurrenceManager.getNsLcmOperationOccurrence(nsLcmOpOccId);
+
+ if (optionalNsLcmOpOccs.isPresent()) {
+ final NsLcmOpOccsNsLcmOpOcc nsLcmOpOcc = optionalNsLcmOpOccs.get();
+ logger.info("Sending back NsLcmOpOcc: {}", nsLcmOpOcc);
+ return ResponseEntity.ok().body(nsLcmOpOcc);
+ }
+
+ final String errorMessage = "Unable to retrieve operation occurrence status for nsLcmOpOccId: " + nsLcmOpOccId;
+ logger.error(errorMessage);
+ return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new InlineResponse400().detail(errorMessage));
}
}
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/NsLcmOperationOccurrencesControllerTest.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/NsLcmOperationOccurrencesControllerTest.java
index 9eace927d6..c5862569f2 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/NsLcmOperationOccurrencesControllerTest.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/NsLcmOperationOccurrencesControllerTest.java
@@ -20,13 +20,26 @@
package org.onap.so.etsi.nfvo.ns.lcm.rest;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import java.time.LocalDateTime;
+import java.util.Optional;
import java.util.UUID;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.so.etsi.nfvo.ns.lcm.Constants;
-import org.onap.so.etsi.nfvo.ns.lcm.JSON;
import org.onap.so.etsi.nfvo.ns.lcm.TestApplication;
+import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.GsonProvider;
+import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst;
+import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NsLcmOpOcc;
+import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NsLcmOpType;
+import org.onap.so.etsi.nfvo.ns.lcm.database.beans.OperationStateEnum;
+import org.onap.so.etsi.nfvo.ns.lcm.database.beans.State;
+import org.onap.so.etsi.nfvo.ns.lcm.database.service.DatabaseServiceProvider;
+import org.onap.so.etsi.nfvo.ns.lcm.model.InlineResponse400;
+import org.onap.so.etsi.nfvo.ns.lcm.model.NsLcmOpOccsNsLcmOpOcc;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.client.RestTemplateBuilder;
@@ -42,32 +55,75 @@ import org.springframework.test.context.junit4.SpringRunner;
import com.google.gson.Gson;
/**
- *
* @author Waqas Ikram (waqas.ikram@est.tech)
+ * @author Andrew Lamb (andrew.a.lamb@est.tech)
+ *
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")
public class NsLcmOperationOccurrencesControllerTest {
+
+ private static final String NS_LCM_OP_OCCS = "/ns_lcm_op_occs/";
+
@LocalServerPort
private int port;
+
+ @Autowired
+ private DatabaseServiceProvider databaseServiceProvider;
+
+ @Autowired
+ private GsonProvider gsonProvider;
+
private TestRestTemplate testRestTemplate;
@Before
public void setUp() {
- final Gson gson = JSON.createGson().create();
+ final Gson gson = gsonProvider.getGson();
testRestTemplate = new TestRestTemplate(
new RestTemplateBuilder().additionalMessageConverters(new GsonHttpMessageConverter(gson)));
}
@Test
- public void testGetOperationStatusS_ValidNsLcmOpOccId() {
- final String baseUrl = getNsLcmBaseUrl() + "/ns_lcm_op_occs/" + UUID.randomUUID().toString();
+ public void testGetOperationStatus_validNsLcmOpOccId_returnsNsLcmOpOcc() {
+ final String nsLcmOpOccId = addDummyNsLcmOpOccToDatabase();
+ final String baseUrl = getNsLcmBaseUrl() + NS_LCM_OP_OCCS + nsLcmOpOccId;
final HttpEntity<?> request = new HttpEntity<>(new HttpHeaders());
- final ResponseEntity<Void> responseEntity =
- testRestTemplate.exchange(baseUrl, HttpMethod.GET, request, Void.class);
- assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode());
+ final ResponseEntity<NsLcmOpOccsNsLcmOpOcc> responseEntity =
+ testRestTemplate.exchange(baseUrl, HttpMethod.GET, request, NsLcmOpOccsNsLcmOpOcc.class);
+ assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
+ assertTrue(responseEntity.hasBody());
+ assertNotNull(responseEntity.getBody());
+ }
+
+ @Test
+ public void testGetOperationStatus_nsLcmOpOccIdNotFound_returnsInlineResponse400() {
+ final String nsLcmOpOccId = UUID.randomUUID().toString();
+ final Optional<NsLcmOpOcc> optionalNsLcmOpOcc = databaseServiceProvider.getNsLcmOpOcc(nsLcmOpOccId);
+ assertTrue(optionalNsLcmOpOcc.isEmpty());
+ final String baseUrl = getNsLcmBaseUrl() + NS_LCM_OP_OCCS + nsLcmOpOccId;
+ final HttpEntity<?> request = new HttpEntity<>(new HttpHeaders());
+ final ResponseEntity<InlineResponse400> responseEntity =
+ testRestTemplate.exchange(baseUrl, HttpMethod.GET, request, InlineResponse400.class);
+ assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
+ assertTrue(responseEntity.hasBody());
+ assertNotNull(responseEntity.getBody());
+ }
+
+ private String addDummyNsLcmOpOccToDatabase() {
+ final LocalDateTime currentDateTime = LocalDateTime.now();
+
+ final NfvoNsInst nsInst = new NfvoNsInst().name("name").nsdId("id").status(State.NOT_INSTANTIATED)
+ .nsdInvariantId("id").statusUpdatedTime(currentDateTime);
+ databaseServiceProvider.saveNfvoNsInst(nsInst);
+
+ final NsLcmOpOcc nsLcmOpOcc = new NsLcmOpOcc().nfvoNsInst(nsInst).operationState(OperationStateEnum.PROCESSING)
+ .isCancelPending(false).isAutoInvocation(false).operation(NsLcmOpType.INSTANTIATE)
+ .startTime(currentDateTime).stateEnteredTime(currentDateTime).operationParams("");
+ databaseServiceProvider.addNSLcmOpOcc(nsLcmOpOcc);
+
+ return nsLcmOpOcc.getId();
}
private String getNsLcmBaseUrl() {
diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/resources/application.yaml b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/resources/application.yaml
index 44acda20a4..6f2b4d26c5 100644
--- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/resources/application.yaml
+++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/resources/application.yaml
@@ -29,11 +29,13 @@ spring:
pool-name: ns-lcm-nfvo-pool
registerMbeans: true
jpa:
+ generate-ddl: true
hibernate:
- ddl-auto: none
+ ddl-auto: create
logging:
level:
org.reflections.Reflections: ERROR
+
etsi-catalog-manager:
base:
- endpoint: http://modeling-etsicatalog.onap:8806/api \ No newline at end of file
+ endpoint: http://modeling-etsicatalog.onap:8806/api