aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__MacroData.sql4
-rw-r--r--bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfDeleteBB.bpmn46
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfDeleteTask.java96
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTask.java16
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProvider.java5
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java52
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmUrlProvider.java9
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmCreateJobTask.java63
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java6
9 files changed, 209 insertions, 88 deletions
diff --git a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__MacroData.sql b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__MacroData.sql
index aea0c222b8..3a4f92a5c5 100644
--- a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__MacroData.sql
+++ b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__MacroData.sql
@@ -868,7 +868,9 @@ VALUES
('CONFIGURATION', 'PENDING', 'DEACTIVATE', 'FAIL'),
('VNF','CONFIGDEPLOYED','ACTIVATE','CONTINUE'),
('CNF','PRECREATED','ACTIVATE','CONTINUE'),
-('CNF','PRECREATED','DEACTIVATE','CONTINUE');
+('CNF','PRECREATED','DEACTIVATE','CONTINUE'),
+('CNF','CREATED','DEACTIVATE','CONTINUE');
+
INSERT INTO vnf_components_recipe (VNF_TYPE, VNF_COMPONENT_TYPE, ACTION, VERSION, ORCHESTRATION_URI, RECIPE_TIMEOUT)
diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfDeleteBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfDeleteBB.bpmn
index 45d51d78a8..da3577ed61 100644
--- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfDeleteBB.bpmn
+++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfDeleteBB.bpmn
@@ -7,31 +7,55 @@
<bpmn:endEvent id="EndEvent_001k15i">
<bpmn:incoming>Flow_1s7gtbc</bpmn:incoming>
</bpmn:endEvent>
- <bpmn:serviceTask id="invokeCnfmToDeleteAsInstnace" name="invoke CNFM to DeleteASInstance" camunda:asyncAfter="true" camunda:expression="${CnfDeleteTask.invokeCnfmToDeleteAsInstnace(InjectExecution.execute(execution, execution.getVariable(&#34;gBuildingBlockExecution&#34;)))}">
- <bpmn:incoming>SequenceFlow_016sgof</bpmn:incoming>
+ <bpmn:serviceTask id="invokeCnfmToDeleteAsInstnace" name="Invoke CNFM to DeleteASInstance" camunda:expression="${CnfDeleteTask.invokeCnfmToDeleteAsInstance(InjectExecution.execute(execution, execution.getVariable(&#34;gBuildingBlockExecution&#34;)))}">
+ <bpmn:incoming>Flow_0td4p22</bpmn:incoming>
<bpmn:outgoing>Flow_1s7gtbc</bpmn:outgoing>
</bpmn:serviceTask>
- <bpmn:sequenceFlow id="SequenceFlow_016sgof" sourceRef="StartEvent_0ru3x55" targetRef="invokeCnfmToDeleteAsInstnace" />
+ <bpmn:sequenceFlow id="SequenceFlow_016sgof" sourceRef="StartEvent_0ru3x55" targetRef="Activity_1uqgwny" />
<bpmn:sequenceFlow id="Flow_1s7gtbc" sourceRef="invokeCnfmToDeleteAsInstnace" targetRef="EndEvent_001k15i" />
+ <bpmn:serviceTask id="invokeCnfmToTerminateAsInstnace" name="Invoke CNFM to TerminateAsInstnace" camunda:expression="${CnfDeleteTask.invokeCnfmToTerminateAsInstance(InjectExecution.execute(execution, execution.getVariable(&#34;gBuildingBlockExecution&#34;)))}">
+ <bpmn:incoming>Flow_19rm5pn</bpmn:incoming>
+ <bpmn:outgoing>Flow_0td4p22</bpmn:outgoing>
+ </bpmn:serviceTask>
+ <bpmn:sequenceFlow id="Flow_19rm5pn" sourceRef="Activity_1uqgwny" targetRef="invokeCnfmToTerminateAsInstnace" />
+ <bpmn:serviceTask id="Activity_1uqgwny" name="Invoke Create TerminateAsRequest" camunda:expression="${CnfDeleteTask.createTerminateAsRequest(InjectExecution.execute(execution, execution.getVariable(&#34;gBuildingBlockExecution&#34;)))}">
+ <bpmn:incoming>SequenceFlow_016sgof</bpmn:incoming>
+ <bpmn:outgoing>Flow_19rm5pn</bpmn:outgoing>
+ </bpmn:serviceTask>
+ <bpmn:sequenceFlow id="Flow_0td4p22" sourceRef="invokeCnfmToTerminateAsInstnace" targetRef="invokeCnfmToDeleteAsInstnace" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="CnfDeleteBB">
+ <bpmndi:BPMNEdge id="Flow_19rm5pn_di" bpmnElement="Flow_19rm5pn">
+ <di:waypoint x="320" y="140" />
+ <di:waypoint x="380" y="140" />
+ </bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1s7gtbc_di" bpmnElement="Flow_1s7gtbc">
- <di:waypoint x="390" y="120" />
- <di:waypoint x="492" y="120" />
+ <di:waypoint x="810" y="140" />
+ <di:waypoint x="1022" y="140" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="SequenceFlow_016sgof_di" bpmnElement="SequenceFlow_016sgof">
- <di:waypoint x="208" y="120" />
- <di:waypoint x="290" y="120" />
+ <di:waypoint x="178" y="140" />
+ <di:waypoint x="220" y="140" />
+ </bpmndi:BPMNEdge>
+ <bpmndi:BPMNEdge id="Flow_0td4p22_di" bpmnElement="Flow_0td4p22">
+ <di:waypoint x="480" y="140" />
+ <di:waypoint x="710" y="140" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="StartEvent_0ru3x55_di" bpmnElement="StartEvent_0ru3x55">
- <dc:Bounds x="172" y="102" width="36" height="36" />
+ <dc:Bounds x="142" y="122" width="36" height="36" />
</bpmndi:BPMNShape>
- <bpmndi:BPMNShape id="EndEvent_001k15i_di" bpmnElement="EndEvent_001k15i">
- <dc:Bounds x="492" y="102" width="36" height="36" />
+ <bpmndi:BPMNShape id="Activity_0ziu33x_di" bpmnElement="Activity_1uqgwny">
+ <dc:Bounds x="220" y="100" width="100" height="80" />
+ </bpmndi:BPMNShape>
+ <bpmndi:BPMNShape id="Activity_06oby7l_di" bpmnElement="invokeCnfmToTerminateAsInstnace">
+ <dc:Bounds x="380" y="100" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="ServiceTask_11_di" bpmnElement="invokeCnfmToDeleteAsInstnace">
- <dc:Bounds x="290" y="80" width="100" height="80" />
+ <dc:Bounds x="710" y="100" width="100" height="80" />
+ </bpmndi:BPMNShape>
+ <bpmndi:BPMNShape id="EndEvent_001k15i_di" bpmnElement="EndEvent_001k15i">
+ <dc:Bounds x="1022" y="122" width="36" height="36" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfDeleteTask.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfDeleteTask.java
index 6bbb391ca9..54b87ec2fe 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfDeleteTask.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfDeleteTask.java
@@ -19,19 +19,23 @@
*/
package org.onap.so.bpmn.infrastructure.adapter.cnfm.tasks;
-import org.onap.logging.filter.base.ONAPComponents;
+import static org.onap.so.bpmn.servicedecomposition.entities.ResourceKey.GENERIC_VNF_ID;
+
+import java.net.URI;
+import java.util.HashMap;
+import java.util.NoSuchElementException;
+import java.util.Optional;
+import org.camunda.bpm.engine.delegate.BpmnError;
import org.onap.so.bpmn.common.BuildingBlockExecution;
-import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
-import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
+import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
import org.onap.so.client.exception.ExceptionBuilder;
-import org.onap.so.serviceinstancebeans.RequestDetails;
+import org.onap.so.cnfm.lcm.model.TerminateAsRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import static java.util.Objects.isNull;
-
/**
* This class performs CNF Delete
@@ -40,43 +44,79 @@ import static java.util.Objects.isNull;
*/
@Component
public class CnfDeleteTask {
-
- private static final String AS_INSTANCE_ID = "asInstanceid";
- private static final Logger LOGGER = LoggerFactory.getLogger(CnfInstantiateTask.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(CnfDeleteTask.class);
private final ExceptionBuilder exceptionUtil;
private final CnfmHttpServiceProvider cnfmHttpServiceProvider;
+ private final ExtractPojosForBB extractPojosForBB;
+ private static final String CNFM_REQUEST_STATUS_CHECK_URL = "CnfmStatusCheckUrl";
+ private static final String TERMINATE_AS_REQUEST_OBJECT = "TerminateAsRequest";
+ private static final String MONITOR_JOB_NAME = "MonitorJobName";
@Autowired
- public CnfDeleteTask(final CnfmHttpServiceProvider cnfmHttpServiceProvider, final ExceptionBuilder exceptionUtil) {
+ public CnfDeleteTask(final CnfmHttpServiceProvider cnfmHttpServiceProvider, final ExceptionBuilder exceptionUtil,
+ ExtractPojosForBB extractPojosForBB) {
this.cnfmHttpServiceProvider = cnfmHttpServiceProvider;
this.exceptionUtil = exceptionUtil;
+ this.extractPojosForBB = extractPojosForBB;
}
- public void invokeCnfmToDeleteAsInstnace(final BuildingBlockExecution execution) {
+ public void createTerminateAsRequest(final BuildingBlockExecution execution) {
try {
- LOGGER.debug("Executing DelteAsInstance task ...");
- final ExecuteBuildingBlock executeBuildingBlock =
- (ExecuteBuildingBlock) execution.getVariable("buildingBlock");
-
- final GeneralBuildingBlock generalBuildingBlock = execution.getGeneralBuildingBlock();
+ LOGGER.debug("Executing createTerminateAsRequest task ...");
- final RequestDetails requestDetails = executeBuildingBlock.getRequestDetails();
- LOGGER.debug("RequestDetails of DeleteAsInstance: {}", requestDetails);
+ final TerminateAsRequest terminateAsRequest = new TerminateAsRequest();
+ terminateAsRequest.setTerminationType(TerminateAsRequest.TerminationTypeEnum.GRACEFUL);
+ terminateAsRequest.setGracefulTerminationTimeout(0);
+ terminateAsRequest.setAdditionalParams(new HashMap<>());
- if (isNull(requestDetails) && isNull(requestDetails.getModelInfo())
- && isNull(requestDetails.getRequestInfo()) && isNull(requestDetails.getCloudConfiguration())
- && isNull(generalBuildingBlock)) {
- LOGGER.error("Missing Mandatory attribute from RequestDetails: {} or GeneralBuildingBlock: {}",
- requestDetails, generalBuildingBlock);
- exceptionUtil.buildAndThrowWorkflowException(execution, 2000,
- "Missing Mandatory attribute from RequestDetails or GeneralBuildingBlock", ONAPComponents.SO);
- }
+ LOGGER.debug("Adding TerminateAsRequest to execution {}", terminateAsRequest);
- LOGGER.debug("Finished executing DeleteAsInstance task ...");
+ execution.setVariable(TERMINATE_AS_REQUEST_OBJECT, terminateAsRequest);
+ LOGGER.debug("Finished executing terminateAsRequest task ...");
} catch (final Exception exception) {
- LOGGER.error("Unable to invoke DeleteAsInstance", exception);
+ LOGGER.error("Unable to create TerminateAsRequest", exception);
exceptionUtil.buildAndThrowWorkflowException(execution, 2001, exception);
}
}
+
+ public void invokeCnfmToTerminateAsInstance(final BuildingBlockExecution execution) {
+ try {
+ LOGGER.debug("Executing TerminateAsInstance task ...");
+
+ final TerminateAsRequest terminateAsRequest = execution.getVariable(TERMINATE_AS_REQUEST_OBJECT);
+ final GenericVnf vnf = extractPojosForBB.extractByKey(execution, GENERIC_VNF_ID);
+ final String asInstanceId = vnf.getVnfId();
+
+ Optional<URI> terminateStatusCheck =
+ cnfmHttpServiceProvider.invokeTerminateAsRequest(asInstanceId, terminateAsRequest);
+ execution.setVariable(CNFM_REQUEST_STATUS_CHECK_URL,
+ terminateStatusCheck.orElseThrow(() -> new NoSuchElementException("Status check url Not found")));
+ execution.setVariable(MONITOR_JOB_NAME, "Terminate");
+ LOGGER.debug("Successfully invoked CNFM terminate AS request: {}", asInstanceId);
+
+ } catch (final Exception exception) {
+ LOGGER.error("Unable to invoke CNFM TerminateAsRequest", exception);
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2004, exception);
+ }
+ }
+
+ public void invokeCnfmToDeleteAsInstance(final BuildingBlockExecution execution) {
+ try {
+ LOGGER.debug("Executing DelteAsInstance task ...");
+
+ final GenericVnf vnf = extractPojosForBB.extractByKey(execution, GENERIC_VNF_ID);
+ final String asInstanceId = vnf.getVnfId();
+
+ Optional<Boolean> response = cnfmHttpServiceProvider.invokeDeleteAsRequest(asInstanceId);
+ if (Boolean.TRUE.equals(response
+ .orElseThrow(() -> new BpmnError("Unable to complete DeleteAsRequest of ID: " + asInstanceId)))) {
+ LOGGER.debug("Successfully invoked CNFM delete AS request with ID: {}", asInstanceId);
+ }
+
+ } catch (final Exception exception) {
+ LOGGER.error("Unable to invoke CNFM DeleteAsRequest", exception);
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2004, exception);
+ }
+ }
}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTask.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTask.java
index 0071e36ef9..e73c3f1703 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTask.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTask.java
@@ -31,6 +31,7 @@ import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.NoSuchElementException;
import java.util.Optional;
import org.apache.groovy.util.Maps;
import org.onap.logging.filter.base.ONAPComponents;
@@ -51,8 +52,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import camundajar.impl.scala.collection.immutable.HashMap;
-
/**
* This class performs CNF Instantiation
@@ -65,6 +64,7 @@ public class CnfInstantiateTask {
private static final String CREATE_AS_REQUEST_OBJECT = "CreateAsRequestObject";
private static final String INSTANTIATE_AS_REQUEST_OBJECT = "InstantiateAsRequest";
private static final String CNFM_REQUEST_STATUS_CHECK_URL = "CnfmStatusCheckUrl";
+ private static final String MONITOR_JOB_NAME = "MonitorJobName";
private static final String AS_INSTANCE_ID = "asInstanceid";
private static final Logger LOGGER = LoggerFactory.getLogger(CnfInstantiateTask.class);
private final ExceptionBuilder exceptionUtil;
@@ -133,7 +133,8 @@ public class CnfInstantiateTask {
"Unable to invoke CNFM for CreateAsRequest", ONAPComponents.SO);
}
- final AsInstance asInstance = optional.get();
+ final AsInstance asInstance =
+ optional.orElseThrow(() -> new NoSuchElementException("AsInstance object is empty"));
execution.setVariable(AS_INSTANCE_ID, asInstance.getAsInstanceid());
LOGGER.debug("Successfully invoked CNFM response: {}", asInstance);
@@ -153,8 +154,8 @@ public class CnfInstantiateTask {
if (requestDetails != null && requestDetails.getRequestParameters() != null) {
List<Map<String, Object>> userParams = requestDetails.getRequestParameters().getUserParams();
if (userParams != null && !userParams.isEmpty()) {
- List deploymentItems = new ArrayList<Object>();
- List deploymentItemsReq = new ArrayList<AsInfoModificationRequestDeploymentItems>();
+ List<Object> deploymentItems = new ArrayList<>();
+ List<AsInfoModificationRequestDeploymentItems> deploymentItemsReq = new ArrayList<>();
for (Map<String, Object> userParam : userParams) {
if (userParam.containsKey("deploymentItems")) {
deploymentItems = (ArrayList<Object>) userParam.get("deploymentItems");
@@ -186,9 +187,10 @@ public class CnfInstantiateTask {
try {
final InstantiateAsRequest instantiateAsRequest = execution.getVariable(INSTANTIATE_AS_REQUEST_OBJECT);
final String asInstanceId = execution.getVariable(AS_INSTANCE_ID);
- Optional<URI> cnf_status_check_url =
+ Optional<URI> cnfStatusCheckURL =
cnfmHttpServiceProvider.invokeInstantiateAsRequest(instantiateAsRequest, asInstanceId);
- execution.setVariable(CNFM_REQUEST_STATUS_CHECK_URL, cnf_status_check_url.get());
+ execution.setVariable(CNFM_REQUEST_STATUS_CHECK_URL, cnfStatusCheckURL.orElseThrow());
+ execution.setVariable(MONITOR_JOB_NAME, "Instantiate");
LOGGER.debug("Successfully invoked CNFM instantiate AS request: {}", asInstanceId);
} catch (final Exception exception) {
LOGGER.error("Unable to invoke CNFM InstantiateAsRequest", exception);
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProvider.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProvider.java
index 556d1a172b..06784a0564 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProvider.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProvider.java
@@ -26,6 +26,7 @@ import org.onap.so.cnfm.lcm.model.AsInstance;
import org.onap.so.cnfm.lcm.model.AsLcmOpOcc;
import org.onap.so.cnfm.lcm.model.CreateAsRequest;
import org.onap.so.cnfm.lcm.model.InstantiateAsRequest;
+import org.onap.so.cnfm.lcm.model.TerminateAsRequest;
/**
* @author Sagar Shetty (sagar.shetty@est.tech)
@@ -39,4 +40,8 @@ public interface CnfmHttpServiceProvider {
Optional<URI> invokeInstantiateAsRequest(InstantiateAsRequest instantiateAsRequest, String asInstanceId);
Optional<AsLcmOpOcc> getInstantiateOperationJobStatus(final String url);
+
+ Optional<Boolean> invokeDeleteAsRequest(final String asInstanceId);
+
+ Optional<URI> invokeTerminateAsRequest(String asInstanceId, TerminateAsRequest terminateAsRequest);
}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java
index 709c5c5758..ed0bc3937b 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java
@@ -23,11 +23,11 @@ import static org.onap.so.bpmn.infrastructure.adapter.cnfm.tasks.CnfmHttpService
import java.net.URI;
import java.util.Optional;
-
import org.onap.so.cnfm.lcm.model.AsInstance;
import org.onap.so.cnfm.lcm.model.AsLcmOpOcc;
import org.onap.so.cnfm.lcm.model.CreateAsRequest;
import org.onap.so.cnfm.lcm.model.InstantiateAsRequest;
+import org.onap.so.cnfm.lcm.model.TerminateAsRequest;
import org.onap.so.rest.exceptions.HttpResouceNotFoundException;
import org.onap.so.rest.exceptions.InvalidRestRequestException;
import org.onap.so.rest.exceptions.RestProcessingException;
@@ -136,4 +136,54 @@ public class CnfmHttpServiceProviderImpl implements CnfmHttpServiceProvider {
}
}
+ @Override
+ public Optional<Boolean> invokeDeleteAsRequest(String asInstanceId) {
+ try {
+
+ final String url = cnfmUrlProvider.getDeleteAsRequestUrl(asInstanceId);
+ LOGGER.debug("Will send request to CNFM by uisng the url: {}", url);
+
+ ResponseEntity<Void> response = httpServiceProvider.deleteHttpRequest(url, Void.class);
+ final HttpStatus httpStatus = response.getStatusCode();
+ if (!(httpStatus.is2xxSuccessful())) {
+ LOGGER.error("Unable to invoke HTTP DELETE using URL: {}, Response Code: {}", url, httpStatus.value());
+ return Optional.empty();
+ }
+ return Optional.of(Boolean.TRUE);
+ } catch (final RestProcessingException | InvalidRestRequestException
+ | HttpResouceNotFoundException httpInvocationException) {
+ LOGGER.error("Unexpected error while processing delete request", httpInvocationException);
+ return Optional.empty();
+ }
+ }
+
+ @Override
+ public Optional<URI> invokeTerminateAsRequest(String asInstanceId, TerminateAsRequest terminateAsRequest) {
+ try {
+
+ final String url = cnfmUrlProvider.getTerminateAsRequestUrl(asInstanceId);
+ LOGGER.debug("Will send request to CNFM to terminate by uisng the url: {}", url);
+
+ ResponseEntity<Void> response = httpServiceProvider.postHttpRequest(terminateAsRequest, url, Void.class);
+ final HttpStatus httpStatus = response.getStatusCode();
+ if (httpStatus.is2xxSuccessful()) {
+ URI statusUri = response.getHeaders().getLocation();
+ if (statusUri == null) {
+ LOGGER.error("Received response without status URL while terminating of instance with ID: {}",
+ asInstanceId);
+ return Optional.empty();
+ }
+ return Optional.of(statusUri);
+ }
+ LOGGER.error("Unable to invoke HTTP DELETE while terminating by using URL: {}, Response Code: {}", url,
+ httpStatus.value());
+ return Optional.empty();
+
+ } catch (final RestProcessingException | InvalidRestRequestException
+ | HttpResouceNotFoundException httpInvocationException) {
+ LOGGER.error("Unexpected error while processing terminate request", httpInvocationException);
+ return Optional.empty();
+ }
+ }
+
}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmUrlProvider.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmUrlProvider.java
index 6cd5d1e262..a7dbf9322b 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmUrlProvider.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmUrlProvider.java
@@ -49,4 +49,13 @@ public class CnfmUrlProvider {
.pathSegment("instantiate").build().toString();
}
+ public String getDeleteAsRequestUrl(String asInstanceId) {
+ return UriComponentsBuilder.fromUri(baseUri).pathSegment("as_instances").pathSegment(asInstanceId).build()
+ .toString();
+ }
+
+ public String getTerminateAsRequestUrl(String asInstanceId) {
+ return UriComponentsBuilder.fromUri(baseUri).pathSegment("as_instances").pathSegment(asInstanceId)
+ .pathSegment("terminate").build().toString();
+ }
}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmCreateJobTask.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmCreateJobTask.java
index 323141365d..40a26cfaf9 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmCreateJobTask.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmCreateJobTask.java
@@ -23,22 +23,18 @@ import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.CREAT
import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.OPERATION_STATUS_PARAM_NAME;
import java.net.URI;
+import java.util.NoSuchElementException;
import java.util.Optional;
-
-import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.CreateVnfResponse;
-import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.QueryJobResponse;
+import java.util.Set;
import org.onap.so.bpmn.common.BuildingBlockExecution;
import org.onap.so.client.exception.ExceptionBuilder;
+import org.onap.so.cnfm.lcm.model.AsLcmOpOcc;
+import org.onap.so.cnfm.lcm.model.AsLcmOpOcc.OperationStateEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import com.google.common.collect.ImmutableSet;
-
-import org.onap.so.cnfm.lcm.model.AsLcmOpOcc;
-import org.onap.so.cnfm.lcm.model.AsLcmOpOcc.OperationStateEnum;
-
/**
* @author sagar.shetty@est.tech
@@ -48,8 +44,9 @@ import org.onap.so.cnfm.lcm.model.AsLcmOpOcc.OperationStateEnum;
public class MonitorCnfmCreateJobTask {
private static final String CNFM_REQUEST_STATUS_CHECK_URL = "CnfmStatusCheckUrl";
- public static final ImmutableSet<OperationStateEnum> OPERATION_FINISHED_STATES =
- ImmutableSet.of(OperationStateEnum.COMPLETED, OperationStateEnum.FAILED, OperationStateEnum.ROLLED_BACK);
+ private static final String MONITOR_JOB_NAME = "MonitorJobName";
+ public static final Set<OperationStateEnum> OPERATION_FINISHED_STATES =
+ Set.of(OperationStateEnum.COMPLETED, OperationStateEnum.FAILED, OperationStateEnum.ROLLED_BACK);
private static final Logger LOGGER = LoggerFactory.getLogger(MonitorCnfmCreateJobTask.class);
protected final ExceptionBuilder exceptionUtil;
private final CnfmHttpServiceProvider cnfmHttpServiceProvider;
@@ -69,10 +66,11 @@ public class MonitorCnfmCreateJobTask {
public void getCurrentOperationStatus(final BuildingBlockExecution execution) {
try {
LOGGER.debug("Executing getCurrentOperationStatus ...");
- final URI operation_status_url = execution.getVariable(CNFM_REQUEST_STATUS_CHECK_URL);
- LOGGER.debug("Executing getCurrentOperationStatus for CNF... :{}", operation_status_url.toString());
+ final Optional<URI> operationStatusURL = Optional.of(execution.getVariable(CNFM_REQUEST_STATUS_CHECK_URL));
+ LOGGER.debug("Executing getCurrentOperationStatus for CNF... :{}", operationStatusURL);
final Optional<AsLcmOpOcc> instantiateOperationJobStatus =
- cnfmHttpServiceProvider.getInstantiateOperationJobStatus(operation_status_url.toString());
+ cnfmHttpServiceProvider.getInstantiateOperationJobStatus(String.valueOf(operationStatusURL
+ .orElseThrow(() -> new NoSuchElementException("Operational Status check url Not found"))));
if (instantiateOperationJobStatus.isPresent()) {
final AsLcmOpOcc asLcmOpOccResponse = instantiateOperationJobStatus.get();
if (asLcmOpOccResponse.getOperationState() != null) {
@@ -81,17 +79,15 @@ public class MonitorCnfmCreateJobTask {
operationStatus, asLcmOpOccResponse.getOperationState());
execution.setVariable(OPERATION_STATUS_PARAM_NAME, asLcmOpOccResponse.getOperationState());
}
-
LOGGER.debug("Operation {} without operationStatus and operation retrieval status :{}",
asLcmOpOccResponse.getId(), asLcmOpOccResponse.getOperationState());
}
- execution.setVariable(CREATE_CNF_STATUS_RESPONSE_PARAM_NAME, instantiateOperationJobStatus.get());
+ execution.setVariable(CREATE_CNF_STATUS_RESPONSE_PARAM_NAME,
+ instantiateOperationJobStatus.isPresent() ? instantiateOperationJobStatus.get() : " ");
LOGGER.debug("Finished executing getCurrentOperationStatus for CNF...");
} catch (final Exception exception) {
- final String message = "Unable to invoke get current Operation status";
- LOGGER.error(message);
- exceptionUtil.buildAndThrowWorkflowException(execution, 1209, message);
-
+ LOGGER.error("Unable to invoke get current Operation status");
+ exceptionUtil.buildAndThrowWorkflowException(execution, 1209, exception);
}
}
@@ -100,10 +96,10 @@ public class MonitorCnfmCreateJobTask {
*
* @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
*/
- public void timeOutLogFailue(final BuildingBlockExecution execution) {
- final String message = "CNF Instantiation operation time out";
+ public void timeOutLogFailure(final BuildingBlockExecution execution) {
+ String message = "CNF" + execution.getVariable(MONITOR_JOB_NAME) + "operation time out";
LOGGER.error(message);
- exceptionUtil.buildAndThrowWorkflowException(execution, 1205, message);
+ exceptionUtil.buildAndThrowWorkflowException(execution, 1205, new Exception(message));
}
/**
@@ -115,22 +111,15 @@ public class MonitorCnfmCreateJobTask {
LOGGER.debug("Executing CNF checkIfOperationWasSuccessful ...");
final OperationStateEnum operationStatusOption = execution.getVariable(OPERATION_STATUS_PARAM_NAME);
final AsLcmOpOcc cnfInstantiateStautusResponse = execution.getVariable(CREATE_CNF_STATUS_RESPONSE_PARAM_NAME);
- if (operationStatusOption == null) {
- final String message = "Unable to instantiate CNF jobId: "
- + (cnfInstantiateStautusResponse != null ? cnfInstantiateStautusResponse.getId() : "null")
- + "Unable to retrieve OperationStatus";
+ if ((operationStatusOption == OperationStateEnum.FAILED)
+ || (operationStatusOption == OperationStateEnum.FAILED_TEMP)) {
+ final String message = "Unable to" + execution.getVariable(MONITOR_JOB_NAME) + "CNF jobId: "
+ + (cnfInstantiateStautusResponse != null ? cnfInstantiateStautusResponse.getId() : "null");
LOGGER.error(message);
- exceptionUtil.buildAndThrowWorkflowException(execution, 1206, message);
- } else {
- final OperationStateEnum operationStatus = operationStatusOption;
- if (operationStatus != OperationStateEnum.COMPLETED) {
- final String message = "Unable to instantiate jobId: "
- + (cnfInstantiateStautusResponse != null ? cnfInstantiateStautusResponse.getId() : "null")
- + " OperationStatus: " + operationStatus;
- LOGGER.error(message);
- exceptionUtil.buildAndThrowWorkflowException(execution, 1207, message);
- }
- LOGGER.debug("Successfully completed CNF instatiation of job status {}", cnfInstantiateStautusResponse);
+ exceptionUtil.buildAndThrowWorkflowException(execution, 1206, new Exception());
+ } else if ((operationStatusOption == OperationStateEnum.COMPLETED)) {
+ String monitorJobName = execution.getVariable(MONITOR_JOB_NAME);
+ LOGGER.debug("Successfully completed CNF {} job", monitorJobName);
}
}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java
index d11ae75c69..849b3ff8f4 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java
@@ -419,7 +419,7 @@ public class ServiceInstances extends AbstractRestHandler {
}
@DELETE
- @Path("/{version:[vV][7]}/serviceInstances/{serviceInstanceId}/cnfs/{asInstanceId}")
+ @Path("/{version:[vV][7]}/serviceInstances/{serviceInstanceId}/cnfs/{cnfInstanceId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Delete provided for CNF instance",
@@ -427,13 +427,13 @@ public class ServiceInstances extends AbstractRestHandler {
content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
@Transactional
public Response deleteCnfInstance(String request, @PathParam("version") String version,
- @PathParam("serviceInstanceId") String serviceInstanceId, @PathParam("asInstanceId") String asInstanceId,
+ @PathParam("serviceInstanceId") String serviceInstanceId, @PathParam("cnfInstanceId") String cnfInstanceId,
@Context ContainerRequestContext requestContext) throws ApiException {
logger.debug("Inside API Handler to perform delete CNF Instance");
String requestId = requestHandlerUtils.getRequestId(requestContext);
HashMap<String, String> instanceIdMap = new HashMap<>();
instanceIdMap.put("serviceInstanceId", serviceInstanceId);
- instanceIdMap.put("asInstanceId", asInstanceId);
+ instanceIdMap.put("vnfInstanceId", cnfInstanceId);
return serviceInstances(request, Action.deleteInstance, instanceIdMap, version, requestId,
requestHandlerUtils.getRequestUri(requestContext, uriPrefix));
}