From 57aa480c5a0e9a823c13024f71e84f7673d7ed23 Mon Sep 17 00:00:00 2001 From: AndrewLamb Date: Thu, 1 Oct 2020 10:32:00 +0100 Subject: SO-ETSI-NFVO Delete NS Backend Service Issue-ID: SO-2870 Change-Id: I476e78a7f528d460eb6dc9bd9019e7407ff167e3 Signed-off-by: AndrewLamb --- .../bpmn/flows/CamundaVariableNameConstants.java | 3 +- .../so/etsi/nfvo/ns/lcm/bpmn/flows/Constants.java | 1 + .../flows/extclients/aai/AaiServiceProvider.java | 1 + .../extclients/aai/AaiServiceProviderImpl.java | 12 +- .../lcm/bpmn/flows/service/JobExecutorService.java | 49 ++++ .../bpmn/flows/service/WorkflowQueryService.java | 6 +- .../flows/tasks/AbstractNetworkServiceTask.java | 17 +- .../nfvo/ns/lcm/bpmn/flows/tasks/CreateNsTask.java | 8 +- .../nfvo/ns/lcm/bpmn/flows/tasks/DeleteNsTask.java | 140 +++++++++++ .../ns/lcm/bpmn/flows/tasks/InstantiateNsTask.java | 7 - .../ns/lcm/bpmn/flows/tasks/TerminateNsTask.java | 8 - .../src/main/resources/CreateNs.bpmn | 4 +- .../src/main/resources/DeleteNs.bpmn | 260 +++++++++++++++++++++ .../src/main/resources/InstantiateNs.bpmn | 4 +- .../src/main/resources/TerminateNs.bpmn | 2 +- .../so/etsi/nfvo/ns/lcm/bpmn/flows/BaseTest.java | 5 + .../ns/workflow/engine/tasks/CreateNsTaskTest.java | 12 +- .../ns/workflow/engine/tasks/DeleteNsTaskTest.java | 185 +++++++++++++++ .../MonitorSol003AdapterCreateJobTaskTest.java | 2 +- .../workflow/engine/tasks/TerminateNsTaskTest.java | 13 -- 20 files changed, 681 insertions(+), 58 deletions(-) create mode 100644 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/tasks/DeleteNsTask.java create mode 100644 so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/DeleteNs.bpmn create mode 100644 so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/DeleteNsTaskTest.java (limited to 'so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src') 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/CamundaVariableNameConstants.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/CamundaVariableNameConstants.java index fd51b1a873..a7acc3ec25 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/CamundaVariableNameConstants.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/CamundaVariableNameConstants.java @@ -32,8 +32,7 @@ public class CamundaVariableNameConstants { public static final String SERVICE_TYPE_PARAM_NAME = "serviceType"; public static final String NS_PACKAGE_MODEL_PARAM_NAME = "NSPackageModel"; - public static final String CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME = - "CreateNsWorkflowProcessingException"; + public static final String NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME = "NsWorkflowProcessingException"; public static final String CREATE_NS_RESPONSE_PARAM_NAME = "createNsResponse"; public static final String INSTANTIATE_NS_REQUEST_PARAM_NAME = "instantiateNsRequest"; 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/Constants.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/Constants.java index 14a4f4340b..c6c56c9eb3 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/Constants.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/Constants.java @@ -30,6 +30,7 @@ public class Constants { public static final String CREATE_NS_WORKFLOW_NAME = "CreateNs"; public static final String INSTANTIATE_NS_WORKFLOW_NAME = "InstantiateNs"; public static final String TERMINATE_NS_WORKFLOW_NAME = "TerminateNs"; + public static final String DELETE_NS_WORKFLOW_NAME = "DeleteNs"; public static final String GET_NS_OCCURRENCE_OPERATION_STATUS_NAME = "GetNsOccurrenceOperationStatus"; 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/extclients/aai/AaiServiceProvider.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/extclients/aai/AaiServiceProvider.java index 29ed85cbd8..a54a6f41f9 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/extclients/aai/AaiServiceProvider.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/extclients/aai/AaiServiceProvider.java @@ -43,4 +43,5 @@ public interface AaiServiceProvider { void deleteGenericVnf(final String vnfId); + void deleteServiceInstance(final String globalCustomerId, final String serviceType, final String serviceInstanceId); } 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/extclients/aai/AaiServiceProviderImpl.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/extclients/aai/AaiServiceProviderImpl.java index 0da53a09c2..a3b3fa9d66 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/extclients/aai/AaiServiceProviderImpl.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/extclients/aai/AaiServiceProviderImpl.java @@ -22,7 +22,6 @@ package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.aai; import java.util.Optional; import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.ServiceInstance; -import org.onap.aaiclient.client.aai.AAIObjectType; import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; @@ -93,4 +92,15 @@ public class AaiServiceProviderImpl implements AaiServiceProvider { AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId)); aaiClientProvider.getAaiClient().delete(aaiResourceUri); } + + @Override + public void deleteServiceInstance(final String globalCustomerId, final String serviceType, + final String serviceInstanceId) { + logger.info( + "Deleting Service Instance with \nGlobal Customer Id: {}, \nService Type: {}, and \nService Instance Id: {} \nfrom AAI.", + globalCustomerId, serviceType, serviceInstanceId); + final AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business() + .customer(globalCustomerId).serviceSubscription(serviceType).serviceInstance(serviceInstanceId)); + aaiClientProvider.getAaiClient().delete(serviceInstanceUri); + } } 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 31e3011c0e..5e5e51cee0 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 @@ -28,8 +28,10 @@ import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstan import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.SERVICE_TYPE_PARAM_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.TERMINATE_NS_REQUEST_PARAM_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.Constants.CREATE_NS_WORKFLOW_NAME; +import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.Constants.DELETE_NS_WORKFLOW_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.Constants.INSTANTIATE_NS_WORKFLOW_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.Constants.TERMINATE_NS_WORKFLOW_NAME; +import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobAction.DELETE; import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobAction.INSTANTIATE; import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobAction.TERMINATE; import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum.ERROR; @@ -240,6 +242,46 @@ public class JobExecutorService { throw new NsRequestProcessingException(message); } + public void runDeleteNsJob(final String nsInstanceId) { + final NfvoJob nfvoJob = new NfvoJob().startTime(LocalDateTime.now()).jobType("NS").jobAction(DELETE) + .resourceId(nsInstanceId).status(STARTING).progress(0); + databaseServiceProvider.addJob(nfvoJob); + logger.info("New job created in database :\n{}", nfvoJob); + + workflowExecutorService.executeWorkflow(nfvoJob.getJobId(), DELETE_NS_WORKFLOW_NAME, + getVariables(nsInstanceId, nfvoJob.getJobId())); + + final ImmutablePair immutablePair = + waitForJobToFinish(nfvoJob.getJobId(), JOB_FINISHED_STATES); + + if (immutablePair.getRight() == null) { + final String message = "Failed to Delete NS with id: " + nsInstanceId; + logger.error(message); + throw new NsRequestProcessingException(message); + } + + final JobStatusEnum finalJobStatus = immutablePair.getRight(); + final String processInstanceId = immutablePair.getLeft(); + + if (FINISHED.equals(finalJobStatus)) { + logger.info("Delete Job status: {}", finalJobStatus); + return; + } + + final Optional optional = workflowQueryService.getProblemDetails(processInstanceId); + if (optional.isPresent()) { + final InlineResponse400 problemDetails = optional.get(); + final String message = "Failed to Delete NS with id: " + nsInstanceId + " due to:\n" + problemDetails; + logger.error(message); + throw new NsRequestProcessingException(message, problemDetails); + } + + final String message = + "Received unexpected Job Status: " + finalJobStatus + " Failed to Delete NS with id: " + nsInstanceId; + logger.error(message); + throw new NsRequestProcessingException(message); + } + private void doInitialTerminateChecks(final String nsInstanceId, final TerminateNsRequest terminateNsRequest) { if (isNotImmediateTerminateRequest(terminateNsRequest)) { final String message = "TerminateNsRequest received with terminateTime: " @@ -347,4 +389,11 @@ public class JobExecutorService { variables.put(TERMINATE_NS_REQUEST_PARAM_NAME, terminateNsRequest); return variables; } + + private Map getVariables(final String nsInstanceId, final String jobId) { + final Map variables = new HashMap<>(); + variables.put(NS_INSTANCE_ID_PARAM_NAME, nsInstanceId); + variables.put(JOB_ID_PARAM_NAME, jobId); + return variables; + } } 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/WorkflowQueryService.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/WorkflowQueryService.java index 297e9c34af..a6180b0e52 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/WorkflowQueryService.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/WorkflowQueryService.java @@ -20,7 +20,7 @@ package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.service; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.CREATE_NS_RESPONSE_PARAM_NAME; -import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME; +import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.Constants.TENANT_ID; import static org.slf4j.LoggerFactory.getLogger; import java.util.Optional; @@ -83,7 +83,7 @@ public class WorkflowQueryService { public Optional getProblemDetails(final String processInstanceId) { try { final HistoricVariableInstance historicVariableInstance = - getVariable(processInstanceId, CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME); + getVariable(processInstanceId, NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME); logger.info("Found HistoricVariableInstance : {}", historicVariableInstance); final Object variableValue = historicVariableInstance.getValue(); @@ -94,7 +94,7 @@ public class WorkflowQueryService { historicVariableInstance.getValue() != null ? variableValue.getClass() : null, variableValue); } catch (final ProcessEngineException processEngineException) { logger.error("Unable to find {} variable using processInstanceId: {}", - CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, processInstanceId, processEngineException); + NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, processInstanceId, processEngineException); } return Optional.empty(); } 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/tasks/AbstractNetworkServiceTask.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/tasks/AbstractNetworkServiceTask.java index e6905b86fc..d23e81201c 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/tasks/AbstractNetworkServiceTask.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/tasks/AbstractNetworkServiceTask.java @@ -19,7 +19,7 @@ */ package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.tasks; -import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME; +import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.JOB_ID_PARAM_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NS_INSTANCE_ID_PARAM_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.OCC_ID_PARAM_NAME; @@ -33,6 +33,7 @@ import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJobStatus; 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.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.slf4j.Logger; @@ -77,7 +78,7 @@ public abstract class AbstractNetworkServiceTask { final Optional optional = databaseServiceProvider.getJob(jobId); if (optional.isPresent()) { final InlineResponse400 problemDetails = - (InlineResponse400) execution.getVariable(CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME); + (InlineResponse400) execution.getVariable(NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME); final NfvoJob nfvoJob = optional.get(); nfvoJob.status(JobStatusEnum.ERROR).endTime(LocalDateTime.now()); @@ -146,7 +147,7 @@ public abstract class AbstractNetworkServiceTask { protected void abortOperation(final DelegateExecution execution, final String message, final InlineResponse400 problemDetails) { logger.error(message); - execution.setVariable(CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, problemDetails); + execution.setVariable(NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, problemDetails); throw new BpmnError("WORKFLOW_FAILED"); } @@ -156,14 +157,20 @@ public abstract class AbstractNetworkServiceTask { if (optional.isEmpty()) { final String message = "Unable to find job using job id: " + jobId; logger.error(message); - execution.setVariable(CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, - new InlineResponse400().detail(message)); + execution.setVariable(NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, new InlineResponse400().detail(message)); throw new BpmnError("WORKFLOW_FAILED"); } return optional.get(); } + protected void updateNsInstanceStatus(final DelegateExecution execution, final State nsStatus) { + final NfvoNsInst nfvoNsInst = getNfvoNsInst(execution); + logger.info("Updating NfvoNsInst Status to {} and saving to DB", nsStatus); + nfvoNsInst.setStatus(nsStatus); + databaseServiceProvider.saveNfvoNsInst(nfvoNsInst); + } + protected NfvoNsInst getNfvoNsInst(final DelegateExecution execution) { final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME); return getNfvoNsInst(execution, nsInstId); 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/tasks/CreateNsTask.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/tasks/CreateNsTask.java index fa7187b388..2cf68bee14 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/tasks/CreateNsTask.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/tasks/CreateNsTask.java @@ -21,7 +21,7 @@ package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.tasks; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.CREATE_NS_REQUEST_PARAM_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.CREATE_NS_RESPONSE_PARAM_NAME; -import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME; +import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.GLOBAL_CUSTOMER_ID_PARAM_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NS_INSTANCE_ID_PARAM_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NS_PACKAGE_MODEL_PARAM_NAME; @@ -102,7 +102,7 @@ public class CreateNsTask extends AbstractNetworkServiceTask { final String message = "Unable to find NS package using NsdId: " + createNsRequest.getNsdId(); logger.error(message); execution.setVariable(DOES_NS_PACKAGE_EXISTS_PARAM_NAME, false); - execution.setVariable(CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, + execution.setVariable(NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, new InlineResponse400().detail(message)); } @@ -113,7 +113,7 @@ public class CreateNsTask extends AbstractNetworkServiceTask { execution.setVariable(DOES_NS_PACKAGE_EXISTS_PARAM_NAME, false); - execution.setVariable(CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, + execution.setVariable(NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, new InlineResponse400().title(message).detail(message)); } @@ -135,7 +135,7 @@ public class CreateNsTask extends AbstractNetworkServiceTask { final Optional optional = databaseServiceProvider.getNfvoNsInstByName(createNsRequest.getNsName()); final NfvoNsInst nfvoNsInst = optional.get(); - execution.setVariable(CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, new InlineResponse400() + execution.setVariable(NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, new InlineResponse400() .detail("Ns Instance already exists in database : " + nfvoNsInst.toString())); } 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/tasks/DeleteNsTask.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/tasks/DeleteNsTask.java new file mode 100644 index 0000000000..cd711fb3e8 --- /dev/null +++ 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/tasks/DeleteNsTask.java @@ -0,0 +1,140 @@ +/*- + * ============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.bpmn.flows.tasks; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.aai.AaiServiceProvider; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst; +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.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import java.util.Optional; +import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NS_INSTANCE_ID_PARAM_NAME; +import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME; +import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum.FINISHED; +import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum.IN_PROGRESS; +import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum.STARTED; +import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.State.NOT_INSTANTIATED; + +/** + * @author Andrew Lamb (andrew.a.lamb@est.tech) + * + */ +@Component +public class DeleteNsTask extends AbstractNetworkServiceTask { + + private static final String NS_INSTANCE_EXISTS_PARAM_NAME = "nsInstanceExists"; + private static final String NS_INSTANCE_IS_IN_NOT_INSTANTIATED_STATE_PARAM_NAME = "isInNotInstantiatedState"; + private static final Logger logger = LoggerFactory.getLogger(DeleteNsTask.class); + private final AaiServiceProvider aaiServiceProvider; + + @Autowired + public DeleteNsTask(final DatabaseServiceProvider databaseServiceProvider, + final AaiServiceProvider aaiServiceProvider) { + super(databaseServiceProvider); + this.aaiServiceProvider = aaiServiceProvider; + } + + public void setJobStatusToStarted(final DelegateExecution execution) { + setJobStatus(execution, STARTED, "Delete NS workflow process started"); + } + + public void setJobStatusToFinished(final DelegateExecution execution) { + setJobStatus(execution, FINISHED, "Delete NS workflow process finished"); + } + + public void setJobStatusInProgress(final DelegateExecution execution, final String message) { + setJobStatus(execution, IN_PROGRESS, message); + } + + public void setJobStatusToError(final DelegateExecution execution) { + setJobStatusToError(execution, "Delete NS workflow process failed"); + } + + public void checkIfNsInstanceExistsInDb(final DelegateExecution execution) { + logger.info("Executing checkIfNsInstanceExistsInDb ..."); + setJobStatusInProgress(execution, "Checking that NS Instance Exists in DB"); + + final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME); + final Optional optionalNfvoNsInst = databaseServiceProvider.getNfvoNsInst(nsInstId); + final boolean nsInstanceExists = optionalNfvoNsInst.isPresent(); + logger.info("NS Instance entry with id: {} {} exist in database", nsInstId, + nsInstanceExists ? "does" : "doesn't"); + execution.setVariable(NS_INSTANCE_EXISTS_PARAM_NAME, nsInstanceExists); + + if (!nsInstanceExists) { + final String message = + "NS Instance with id: " + nsInstId + " does not exist in database, so will not be deleted."; + logger.info(message); + execution.setVariable(NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, new InlineResponse400().detail(message)); + } + + logger.info("Finished executing checkIfNsInstanceExistsInDb ..."); + } + + public void checkthatNsInstanceInDbIsInNotInstantiatedState(final DelegateExecution execution) { + logger.info("Executing checkthatNsInstanceInDbIsInNotInstantiatedState ..."); + setJobStatusInProgress(execution, "Checking that NS Instance is in NOT_INSTANTIATED state in Db"); + + final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME); + final NfvoNsInst nfvoNsInst = getNfvoNsInst(execution, nsInstId); + final State nfvoNsInstState = nfvoNsInst.getStatus(); + final boolean nsInstanceIsNotInstantiated = NOT_INSTANTIATED.equals(nfvoNsInstState); + logger.info("Ns Instance entry with nsInstId: {} is in state: {}", nsInstId, nfvoNsInstState); + execution.setVariable(NS_INSTANCE_IS_IN_NOT_INSTANTIATED_STATE_PARAM_NAME, nsInstanceIsNotInstantiated); + + if (!nsInstanceIsNotInstantiated) { + final String message = + "Cannot Delete NS Instance with id: " + nsInstId + " in the state: " + nfvoNsInstState; + logger.info(message); + execution.setVariable(NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, new InlineResponse400().detail(message)); + } + + logger.info("Finished executing checkthatNsInstanceInDbIsInNotInstantiatedState ..."); + } + + public void deleteNsInstanceFromAai(final DelegateExecution execution) { + logger.info("Executing deleteNsInstanceFromAAI ..."); + setJobStatusInProgress(execution, "Deleting NS Instance from AAI"); + + final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME); + final NfvoNsInst nfvoNsInst = getNfvoNsInst(execution, nsInstId); + final String globalCustomerId = nfvoNsInst.getGlobalCustomerId(); + final String serviceType = nfvoNsInst.getServiceType(); + + aaiServiceProvider.deleteServiceInstance(globalCustomerId, serviceType, nsInstId); + + logger.info("Finished executing deleteNsInstanceFromAAI ..."); + } + + public void deleteNsInstanceFromDb(final DelegateExecution execution) { + logger.info("Executing deleteNsInstanceFromDb ..."); + setJobStatusInProgress(execution, "Deleting NS Instance from Db"); + + final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME); + databaseServiceProvider.deleteNfvoNsInst(nsInstId); + + logger.info("Finished executing deleteNsInstanceFromDb ..."); + } +} 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/tasks/InstantiateNsTask.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/tasks/InstantiateNsTask.java index 2157051e8b..1d9e09e74b 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/tasks/InstantiateNsTask.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/tasks/InstantiateNsTask.java @@ -316,13 +316,6 @@ public class InstantiateNsTask extends AbstractNetworkServiceTask { } - private void updateNsInstanceStatus(final DelegateExecution execution, final State nsStatus) { - final NfvoNsInst nfvoNsInst = getNfvoNsInst(execution); - logger.info("Updating NfvoNsInst Status to {} and saving to DB", nsStatus); - nfvoNsInst.setStatus(nsStatus); - databaseServiceProvider.saveNfvoNsInst(nfvoNsInst); - } - private Optional getTenant(final Map additionalParams) { final String vimId = (String) additionalParams.get("vim_id"); if (vimId != null) { 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/tasks/TerminateNsTask.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/tasks/TerminateNsTask.java index 972e4d6de8..2baa2845a5 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/tasks/TerminateNsTask.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/tasks/TerminateNsTask.java @@ -22,7 +22,6 @@ package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.tasks; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants; import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNfInst; -import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst; import org.onap.so.etsi.nfvo.ns.lcm.database.beans.State; import org.onap.so.etsi.nfvo.ns.lcm.database.service.DatabaseServiceProvider; import org.slf4j.Logger; @@ -116,13 +115,6 @@ public class TerminateNsTask extends AbstractNetworkServiceTask { } } - private void updateNsInstanceStatus(final DelegateExecution execution, final State nsStatus) { - final NfvoNsInst nfvoNsInst = getNfvoNsInst(execution); - logger.info("Updating NfvoNsInst Status to {} and saving to DB", nsStatus); - nfvoNsInst.setStatus(nsStatus); - databaseServiceProvider.saveNfvoNsInst(nfvoNsInst); - } - private List getNfvoNfInstIds(final DelegateExecution execution) { final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME); logger.info("Getting NfvoNfInstList using nsInstId: {}", nsInstId); diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/CreateNs.bpmn b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/CreateNs.bpmn index 815b76c907..4c24f91cf9 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/CreateNs.bpmn +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/CreateNs.bpmn @@ -1,5 +1,5 @@ - + Flow_1tqn5q5 @@ -102,7 +102,7 @@ - + diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/DeleteNs.bpmn b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/DeleteNs.bpmn new file mode 100644 index 0000000000..a6bb214440 --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/DeleteNs.bpmn @@ -0,0 +1,260 @@ + + + + + Flow_1tqn5q5 + + + Flow_0t87ov3 + + + + Flow_1tqn5q5 + Flow_0fhodlp + + + Flow_1rtsvpm + Flow_0t87ov3 + + + + + Flow_0554tjv + + + + Flow_04xvpee + + + + Flow_0554tjv + Flow_04xvpee + + + + + + Flow_0j1otrx + + + + Flow_0oqv7vl + + + + Flow_0j1otrx + Flow_0oqv7vl + + + + + Flow_0fhodlp + Flow_1duwqzf + + + Flow_02g3nbb + Flow_1ihvsfs + + + Flow_04wub0a + Flow_1rtsvpm + + + + + + + Flow_1buncqe + Flow_04wub0a + + + + Flow_1duwqzf + Flow_02g3nbb + Flow_1swnlzf + + + #{nsInstanceExists} + + + Flow_1ihvsfs + Flow_1buncqe + Flow_1eozcur + + + #{isInNotInstantiatedState} + + + Flow_1swnlzf + Flow_1eozcur + + + + #{not nsInstanceExists} + + + #{not isInNotInstantiatedState} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/InstantiateNs.bpmn b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/InstantiateNs.bpmn index ba9e641d84..bc34c144c9 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/InstantiateNs.bpmn +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/InstantiateNs.bpmn @@ -133,7 +133,7 @@ - + @@ -328,4 +328,4 @@ - + \ No newline at end of file diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/TerminateNs.bpmn b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/TerminateNs.bpmn index 36c52c8ad6..e971f6acf0 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/TerminateNs.bpmn +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/TerminateNs.bpmn @@ -123,7 +123,7 @@ - + diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/BaseTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/BaseTest.java index 86f2879966..b6fd9e407a 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/BaseTest.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/BaseTest.java @@ -147,4 +147,9 @@ public abstract class BaseTest { return runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult() == null; } + protected String getAaiServiceInstanceEndPoint() { + return "/aai/v[0-9]+/business/customers/customer/" + GLOBAL_CUSTOMER_ID + + "/service-subscriptions/service-subscription/" + SERVICE_TYPE + + "/service-instances/service-instance/.*"; + } } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/CreateNsTaskTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/CreateNsTaskTest.java index 05213a344f..3686cd620d 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/CreateNsTaskTest.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/CreateNsTaskTest.java @@ -234,7 +234,7 @@ public class CreateNsTaskTest extends BaseTest { assertNull(nsResponseVariable); final HistoricVariableInstance workflowExceptionVariable = getVariable(processInstance.getProcessInstanceId(), - CamundaVariableNameConstants.CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME); + CamundaVariableNameConstants.NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME); final InlineResponse400 problemDetails = (InlineResponse400) workflowExceptionVariable.getValue(); assertNotNull(problemDetails); @@ -306,7 +306,7 @@ public class CreateNsTaskTest extends BaseTest { mockEtsiCatalogEndpoints(nsdId); - final String modelEndpoint = getAiaServiceInstancelEndPoint(createNsRequest); + final String modelEndpoint = getAaiServiceInstanceEndPoint(); wireMockServer.stubFor(put(urlMatching(modelEndpoint)).willReturn(WireMock.serverError())); wireMockServer.stubFor(get(urlMatching(modelEndpoint)).willReturn(WireMock.serverError())); @@ -339,18 +339,12 @@ public class CreateNsTaskTest extends BaseTest { } private void mockAAIEndpoints(final CreateNsRequest createNsRequest) { - final String modelEndpoint = getAiaServiceInstancelEndPoint(createNsRequest); + final String modelEndpoint = getAaiServiceInstanceEndPoint(); wireMockServer.stubFor(put(urlMatching(modelEndpoint)).willReturn(ok())); wireMockServer.stubFor(get(urlMatching(modelEndpoint)).willReturn(notFound())); } - private String getAiaServiceInstancelEndPoint(final CreateNsRequest createNsRequest) { - return "/aai/v[0-9]+/business/customers/customer/" + GLOBAL_CUSTOMER_ID - + "/service-subscriptions/service-subscription/" + SERVICE_TYPE - + "/service-instances/service-instance/.*"; - } - private void mockEtsiCatalogEndpoints(final String nsdId) { mockRestServiceServer.expect(requestTo(ETSI_CATALOG_URL + "/nsd/v1/ns_descriptors/" + nsdId)) .andExpect(method(HttpMethod.GET)) diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/DeleteNsTaskTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/DeleteNsTaskTest.java new file mode 100644 index 0000000000..adb8a9e69b --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/DeleteNsTaskTest.java @@ -0,0 +1,185 @@ +/*- + * ============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.workflow.engine.tasks; + +import com.google.gson.Gson; +import org.camunda.bpm.engine.history.HistoricProcessInstance; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.BaseTest; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.GsonProvider; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.exceptions.NsRequestProcessingException; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.service.JobExecutorService; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJob; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.State; +import org.springframework.beans.factory.annotation.Autowired; +import java.time.LocalDateTime; +import java.util.Optional; +import java.util.UUID; +import static com.github.tomakehurst.wiremock.client.WireMock.delete; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.ok; +import static com.github.tomakehurst.wiremock.client.WireMock.okJson; +import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +/** + * @author Andrew Lamb (andrew.a.lamb@est.tech) + * + */ +public class DeleteNsTaskTest extends BaseTest { + + @Autowired + private JobExecutorService objUnderTest; + + @Autowired + private GsonProvider gsonProvider; + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + private Gson gson; + + @Before + public void before() { + wireMockServer.resetAll(); + gson = gsonProvider.getGson(); + } + + @After + public void after() { + wireMockServer.resetAll(); + } + + @Test + public void testRunDeleteNsJob_nsInstanceIdNotInDatabase_throwsException() { + final String nsInstanceId = UUID.randomUUID().toString(); + assertTrue(databaseServiceProvider.getNfvoNsInst(nsInstanceId).isEmpty()); + + expectedException.expect(NsRequestProcessingException.class); + objUnderTest.runDeleteNsJob(nsInstanceId); + } + + @Test + public void testRunDeleteNsJob_nsInstanceStateInstantiated_throwsException() { + final String nsInstanceId = UUID.randomUUID().toString(); + addDummyNsToDatabase(nsInstanceId, State.INSTANTIATED); + + final Optional optionalNfvoNsInst = databaseServiceProvider.getNfvoNsInst(nsInstanceId); + assertTrue(optionalNfvoNsInst.isPresent()); + assertEquals(State.INSTANTIATED, optionalNfvoNsInst.get().getStatus()); + + expectedException.expect(NsRequestProcessingException.class); + objUnderTest.runDeleteNsJob(nsInstanceId); + } + + @Test + public void testRunDeleteNsJob_nsInstanceStateInstantiating_throwsException() { + final String nsInstanceId = UUID.randomUUID().toString(); + addDummyNsToDatabase(nsInstanceId, State.INSTANTIATING); + + final Optional optionalNfvoNsInst = databaseServiceProvider.getNfvoNsInst(nsInstanceId); + assertTrue(optionalNfvoNsInst.isPresent()); + assertEquals(State.INSTANTIATING, optionalNfvoNsInst.get().getStatus()); + + expectedException.expect(NsRequestProcessingException.class); + objUnderTest.runDeleteNsJob(nsInstanceId); + } + + @Test + public void testRunDeleteNsJob_nsInstanceStateTerminating_throwsException() { + final String nsInstanceId = UUID.randomUUID().toString(); + addDummyNsToDatabase(nsInstanceId, State.TERMINATING); + + final Optional optionalNfvoNsInst = databaseServiceProvider.getNfvoNsInst(nsInstanceId); + assertTrue(optionalNfvoNsInst.isPresent()); + assertEquals(State.TERMINATING, optionalNfvoNsInst.get().getStatus()); + + expectedException.expect(NsRequestProcessingException.class); + objUnderTest.runDeleteNsJob(nsInstanceId); + } + + @Test + public void testRunDeleteNsJob_nsInstanceStateFailed_throwsException() { + final String nsInstanceId = UUID.randomUUID().toString(); + addDummyNsToDatabase(nsInstanceId, State.FAILED); + + final Optional optionalNfvoNsInst = databaseServiceProvider.getNfvoNsInst(nsInstanceId); + assertTrue(optionalNfvoNsInst.isPresent()); + assertEquals(State.FAILED, optionalNfvoNsInst.get().getStatus()); + + expectedException.expect(NsRequestProcessingException.class); + objUnderTest.runDeleteNsJob(nsInstanceId); + } + + @Test + public void testRunDeleteNsJob_SuccessfulCase() throws InterruptedException { + final String nsInstanceId = UUID.randomUUID().toString(); + addDummyNsToDatabase(nsInstanceId, State.NOT_INSTANTIATED); + mockAaiEndpoints(); + + final Optional optionalNfvoNsInst = databaseServiceProvider.getNfvoNsInst(nsInstanceId); + assertTrue(optionalNfvoNsInst.isPresent()); + assertEquals(State.NOT_INSTANTIATED, optionalNfvoNsInst.get().getStatus()); + + objUnderTest.runDeleteNsJob(nsInstanceId); + + final Optional optional = getJobByResourceId(nsInstanceId); + assertTrue(optional.isPresent()); + final NfvoJob nfvoJob = optional.get(); + + // Confirm Process finishes in STATE_COMPLETED + assertTrue(waitForProcessInstanceToFinish(nfvoJob.getProcessInstanceId())); + final HistoricProcessInstance historicProcessInstance = + getHistoricProcessInstance(nfvoJob.getProcessInstanceId()); + assertNotNull(historicProcessInstance); + assertEquals(HistoricProcessInstance.STATE_COMPLETED, historicProcessInstance.getState()); + + // Confirm NS Instance no longer in database + final Optional optionalNfvoNsInstance = databaseServiceProvider.getNfvoNsInst(nsInstanceId); + assertTrue(optionalNfvoNsInstance.isEmpty()); + } + + private void addDummyNsToDatabase(final String nsInstanceId, final State state) { + final String nsPackageId = UUID.randomUUID().toString(); + final NfvoNsInst nfvoNsInst = new NfvoNsInst().nsInstId(nsInstanceId).name("nsName").nsPackageId(nsPackageId) + .nsdId("nsdId").nsdInvariantId("nsdId").status(state).statusUpdatedTime(LocalDateTime.now()) + .globalCustomerId(GLOBAL_CUSTOMER_ID).serviceType(SERVICE_TYPE); + databaseServiceProvider.saveNfvoNsInst(nfvoNsInst); + } + + private void mockAaiEndpoints() { + final String modelEndpoint = getAaiServiceInstanceEndPoint(); + final String resourceVersion = "12345"; + + final String body = + "{\"resource-version\": \"" + resourceVersion + "\",\n\"orchestration-status\": \"Assigned\"}"; + wireMockServer.stubFor(get(urlMatching(modelEndpoint)).willReturn(ok()).willReturn(okJson(body))); + + wireMockServer.stubFor( + delete(urlMatching(modelEndpoint + "\\?resource-version=" + resourceVersion)).willReturn(ok())); + } +} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/MonitorSol003AdapterCreateJobTaskTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/MonitorSol003AdapterCreateJobTaskTest.java index ff5c2a9105..aa8d8cf10e 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/MonitorSol003AdapterCreateJobTaskTest.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/MonitorSol003AdapterCreateJobTaskTest.java @@ -132,7 +132,7 @@ public class MonitorSol003AdapterCreateJobTaskTest extends BaseTest { assertNull(nsResponseVariable); final HistoricVariableInstance workflowExceptionVariable = getVariable(processInstance.getProcessInstanceId(), - CamundaVariableNameConstants.CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME); + CamundaVariableNameConstants.NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME); final InlineResponse400 problemDetails = (InlineResponse400) workflowExceptionVariable.getValue(); assertNotNull(problemDetails); diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/TerminateNsTaskTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/TerminateNsTaskTest.java index 14e5b1cafc..b821c85edd 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/TerminateNsTaskTest.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/TerminateNsTaskTest.java @@ -74,16 +74,10 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat */ public class TerminateNsTaskTest extends BaseTest { - @Autowired - @Qualifier(ETSI_CATALOG_REST_TEMPLATE_BEAN) - private RestTemplate etsiCatalogRestTemplate; - @Autowired @Qualifier(SOL003_ADAPTER_REST_TEMPLATE_BEAN) private RestTemplate sol003AdapterRestTemplate; - private MockRestServiceServer mockEtsiCatalogRestServiceServer; - private MockRestServiceServer mockSol003AdapterRestServiceServer; @Autowired @@ -101,21 +95,14 @@ public class TerminateNsTaskTest extends BaseTest { public void before() { wireMockServer.resetAll(); gson = gsonProvider.getGson(); - - mockEtsiCatalogRestServiceServer = - MockRestServiceServer.bindTo(etsiCatalogRestTemplate).ignoreExpectOrder(true).build(); mockSol003AdapterRestServiceServer = MockRestServiceServer.bindTo(sol003AdapterRestTemplate).ignoreExpectOrder(true).build(); - - etsiCatalogRestTemplate.getMessageConverters().add(new GsonHttpMessageConverter(gson)); sol003AdapterRestTemplate.getMessageConverters().add(new GsonHttpMessageConverter(gson)); - } @After public void after() { wireMockServer.resetAll(); - mockEtsiCatalogRestServiceServer.reset(); } @Test -- cgit 1.2.3-korg