summaryrefslogtreecommitdiffstats
path: root/so-etsi-nfvo
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
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')
-rw-r--r--so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/service/JobExecutorService.java4
-rw-r--r--so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/CancelModeType.java28
-rw-r--r--so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NsLcmOpOcc.java44
-rw-r--r--so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/resources/db/migration/V1_1__create_nfvo_tables.sql3
-rw-r--r--so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/DatabaseServiceProviderTest.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/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
9 files changed, 277 insertions, 28 deletions
diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/service/JobExecutorService.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/service/JobExecutorService.java
index 5e5e51cee0..49118494cf 100644
--- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/service/JobExecutorService.java
+++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/service/JobExecutorService.java
@@ -164,7 +164,7 @@ public class JobExecutorService {
final LocalDateTime currentDateTime = LocalDateTime.now();
final NsLcmOpOcc newNsLcmOpOcc = new NsLcmOpOcc().id(nsInstanceId).operation(NsLcmOpType.INSTANTIATE)
.operationState(OperationStateEnum.PROCESSING).stateEnteredTime(currentDateTime)
- .startTime(currentDateTime).nfvoNsInst(getNfvoNsInst(nsInstanceId)).isAutoInnovation(false)
+ .startTime(currentDateTime).nfvoNsInst(getNfvoNsInst(nsInstanceId)).isAutoInvocation(false)
.isCancelPending(false).operationParams(gson.toJson(instantiateNsRequest));
databaseServiceProvider.addNSLcmOpOcc(newNsLcmOpOcc);
logger.info("New NSLcmOpOcc created in database :\n{}", newNsLcmOpOcc);
@@ -209,7 +209,7 @@ public class JobExecutorService {
final LocalDateTime currentDateTime = LocalDateTime.now();
final NsLcmOpOcc nsLcmOpOcc = new NsLcmOpOcc().id(nsInstanceId).operation(NsLcmOpType.TERMINATE)
.operationState(OperationStateEnum.PROCESSING).stateEnteredTime(currentDateTime)
- .startTime(currentDateTime).nfvoNsInst(getNfvoNsInst(nsInstanceId)).isAutoInnovation(false)
+ .startTime(currentDateTime).nfvoNsInst(getNfvoNsInst(nsInstanceId)).isAutoInvocation(false)
.isCancelPending(false).operationParams(gson.toJson(terminateNsRequest));
databaseServiceProvider.addNSLcmOpOcc(nsLcmOpOcc);
logger.info("New NSLcmOpOcc created in database :\n{}", nsLcmOpOcc);
diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/CancelModeType.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/CancelModeType.java
new file mode 100644
index 0000000000..627250535e
--- /dev/null
+++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/CancelModeType.java
@@ -0,0 +1,28 @@
+/*-
+ * ============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.database.beans;
+
+/**
+ * @author Andrew Lamb (andrew.a.lamb@est.tech)
+ *
+ */
+public enum CancelModeType {
+ GRACEFUL, FORCEFUL;
+}
diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NsLcmOpOcc.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NsLcmOpOcc.java
index 19fe969366..4846e5a361 100644
--- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NsLcmOpOcc.java
+++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NsLcmOpOcc.java
@@ -62,8 +62,8 @@ public class NsLcmOpOcc {
@Column(name = "OPERATION", nullable = false)
private NsLcmOpType operation;
- @Column(name = "IS_AUTO_INNOVATION", nullable = false)
- private boolean isAutoInnovation;
+ @Column(name = "IS_AUTO_INVOCATION", nullable = false)
+ private boolean isAutoInvocation;
@Column(name = "OPERATION_PARAMS", columnDefinition = "LONGTEXT", nullable = false)
private String operationParams;
@@ -71,6 +71,10 @@ public class NsLcmOpOcc {
@Column(name = "IS_CANCEL_PENDING", nullable = false)
private boolean isCancelPending;
+ @Enumerated(EnumType.STRING)
+ @Column(name = "CANCEL_MODE")
+ private CancelModeType cancelMode;
+
public NsLcmOpOcc() {
this.id = UUID.randomUUID().toString();
}
@@ -153,16 +157,29 @@ public class NsLcmOpOcc {
return this;
}
- public boolean getIsAutoInnovation() {
- return isAutoInnovation;
+ public boolean getIsAutoInvocation() {
+ return isAutoInvocation;
+ }
+
+ public void setIsAutoInvocation(final boolean isAutoInvocation) {
+ this.isAutoInvocation = isAutoInvocation;
+ }
+
+ public NsLcmOpOcc isAutoInvocation(final boolean isAutoInvocation) {
+ this.isAutoInvocation = isAutoInvocation;
+ return this;
+ }
+
+ public CancelModeType getCancelMode() {
+ return cancelMode;
}
- public void setIsAutoInnovation(final boolean isAutoInnovation) {
- this.isAutoInnovation = isAutoInnovation;
+ public void setCancelMode(final CancelModeType cancelMode) {
+ this.cancelMode = cancelMode;
}
- public NsLcmOpOcc isAutoInnovation(final boolean isAutoInnovation) {
- this.isAutoInnovation = isAutoInnovation;
+ public NsLcmOpOcc cancelMode(final CancelModeType cancelMode) {
+ this.cancelMode = cancelMode;
return this;
}
@@ -203,16 +220,16 @@ public class NsLcmOpOcc {
&& Objects.equals(stateEnteredTime, that.stateEnteredTime) && Objects.equals(startTime, that.startTime)
&& (nfvoNsInst == null ? that.nfvoNsInst == null
: that.nfvoNsInst != null && Objects.equals(nfvoNsInst, that.nfvoNsInst))
- && Objects.equals(operation, that.operation) && Objects.equals(isAutoInnovation, that.isAutoInnovation)
+ && Objects.equals(operation, that.operation) && Objects.equals(isAutoInvocation, that.isAutoInvocation)
&& Objects.equals(operationParams, that.operationParams)
- && Objects.equals(isCancelPending, that.isCancelPending);
+ && Objects.equals(isCancelPending, that.isCancelPending) && Objects.equals(cancelMode, that.cancelMode);
}
@Override
public int hashCode() {
return Objects.hash(id, operationState, stateEnteredTime, startTime,
- nfvoNsInst != null ? nfvoNsInst.getNsInstId() : 0, operation, isAutoInnovation, operationParams,
- isCancelPending);
+ nfvoNsInst != null ? nfvoNsInst.getNsInstId() : 0, operation, isAutoInvocation, operationParams,
+ isCancelPending, cancelMode);
}
@Override
@@ -226,9 +243,10 @@ public class NsLcmOpOcc {
sb.append(" nfvoNsInst: ").append(nfvoNsInst != null ? toIndentedString(nfvoNsInst.getNsInstId()) : null)
.append("\n");
sb.append(" operation: ").append(toIndentedString(operation)).append("\n");
- sb.append(" isAutoInnovation: ").append(toIndentedString(isAutoInnovation)).append("\n");
+ sb.append(" isAutoInvocation: ").append(toIndentedString(isAutoInvocation)).append("\n");
sb.append(" operationParams: ").append(toIndentedString(operationParams)).append("\n");
sb.append(" isCancelPending: ").append(toIndentedString(isCancelPending)).append("\n");
+ sb.append(" cancelMode: ").append(toIndentedString(cancelMode)).append("\n");
sb.append("}");
return sb.toString();
}
diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/resources/db/migration/V1_1__create_nfvo_tables.sql b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/resources/db/migration/V1_1__create_nfvo_tables.sql
index f41a8206e0..85a732b83e 100644
--- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/resources/db/migration/V1_1__create_nfvo_tables.sql
+++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/resources/db/migration/V1_1__create_nfvo_tables.sql
@@ -64,9 +64,10 @@ CREATE TABLE IF NOT EXISTS `NS_LCM_OP_OCCS` (
`START_TIME` DATETIME DEFAULT NULL,
`NS_INST_ID` varchar(255) NOT NULL,
`OPERATION` varchar(255) NOT NULL,
- `IS_AUTO_INNOVATION` varchar(255) NOT NULL,
+ `IS_AUTO_INVOCATION` varchar(255) NOT NULL,
`OPERATION_PARAMS` longtext NOT NULL,
`IS_CANCEL_PENDING` varchar(255) NOT NULL,
+ `CANCEL_MODE` varchar(255) DEFAULT NULL,
PRIMARY KEY (`ID`),
FOREIGN KEY (NS_INST_ID)
REFERENCES NS_INST(NS_INST_ID)
diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/DatabaseServiceProviderTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/DatabaseServiceProviderTest.java
index 8070036791..fcf7f9c373 100644
--- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/DatabaseServiceProviderTest.java
+++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/DatabaseServiceProviderTest.java
@@ -164,7 +164,7 @@ public class DatabaseServiceProviderTest {
databaseServiceProvider.saveNfvoNsInst(nsInst);
final NsLcmOpOcc nsLcmOpOcc = new NsLcmOpOcc().nfvoNsInst(nsInst).operationState(OperationStateEnum.PROCESSING)
- .isCancelPending(false).isAutoInnovation(false).operation(NsLcmOpType.INSTANTIATE)
+ .isCancelPending(false).isAutoInvocation(false).operation(NsLcmOpType.INSTANTIATE)
.startTime(CURRENT_DATE_TIME).stateEnteredTime(CURRENT_DATE_TIME).operationParams("");
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