diff options
Diffstat (limited to 'bpmn')
13 files changed, 723 insertions, 0 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CNFAdapterAsync.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CNFAdapterAsync.groovy new file mode 100755 index 0000000000..9de40b4e69 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CNFAdapterAsync.groovy @@ -0,0 +1,80 @@ +package org.onap.so.bpmn.common.scripts + +import javax.ws.rs.core.Response + +import org.camunda.bpm.engine.delegate.DelegateExecution +import org.slf4j.Logger +import org.slf4j.LoggerFactory + +import com.fasterxml.jackson.databind.ObjectMapper + +import org.onap.so.bpmn.core.UrnPropertiesReader +import org.onap.logging.filter.base.ONAPComponents +import org.onap.so.client.HttpClient +import org.onap.so.client.HttpClientFactory + +import static org.onap.so.bpmn.common.scripts.GenericUtils.isBlank + +public class CNFAdapterAsync extends AbstractServiceTaskProcessor { + private static final Logger logger = LoggerFactory.getLogger(CNFAdapterAsync.class) + + ExceptionUtil exceptionUtil = new ExceptionUtil() + ObjectMapper mapper = new ObjectMapper(); + + @Override + public void preProcessRequest(DelegateExecution execution) { + logger.debug("Start preProcessRequest"); + + String apiPath = execution.getVariable("apiPath") + if (isBlank(apiPath)) { + String msg = "Cannot process CNF adapter call : API PATH is null" + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + + //Object cnfRequestPayloadFromExecutionVariable = execution.getVariable("cnfRequestPayload") + + String cnfRequestPayload = execution.getVariable("cnfRequestPayload") + if (isBlank(cnfRequestPayload)) { + String msg = "Cannot process CNF adapter call : cnfRequestPayload is null" + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + + String correlator = execution.getVariable("correlator") + if (isBlank(correlator)) { + String msg = "Cannot process CNF adapter call : correlator is null" + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + + String messageType = execution.getVariable("messageType") + if (isBlank(messageType)) { + String msg = "Cannot process CNF adapter call : messageType is null" + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + + String timeout = UrnPropertiesReader.getVariable("mso.adapters.cnf.timeout", execution); + if (isBlank(timeout)) { + logger.debug("Setting CNF Adapter timeout to default : PT30M") + timeout = "PT30M" + } + + execution.setVariable("timeout",timeout) + + logger.debug("Enter preProcessRequest: {}",execution.getVariable("messageType")); + } + + void callCnfAdapter(DelegateExecution execution) { + logger.debug("Start callCnfAdapter") + String cnfAdapterEndpoint = execution.getVariable("apiPath") + URL requestUrl = new URL(cnfAdapterEndpoint) + String cnfRequest = execution.getVariable("cnfRequestPayload") + logger.debug("cnfRequest : " + cnfRequest) + HttpClient httpClient = new HttpClientFactory().newJsonClient(requestUrl, ONAPComponents.EXTERNAL) + Response httpResponse = httpClient.post(cnfRequest) + int responseCode = httpResponse.getStatus() + logger.debug("CNF sync response code is: " + responseCode) + if(responseCode < 200 || responseCode >= 300){ + exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Sync Response from CNF.") + } + logger.debug("End callCnfAdapter") + } +} diff --git a/bpmn/MSOCommonBPMN/src/main/resources/subprocess/CNFAdapterAsyncCall.bpmn b/bpmn/MSOCommonBPMN/src/main/resources/subprocess/CNFAdapterAsyncCall.bpmn new file mode 100755 index 0000000000..39846f2d39 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/resources/subprocess/CNFAdapterAsyncCall.bpmn @@ -0,0 +1,106 @@ +<?xml version="1.0" encoding="UTF-8"?> +<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_0xinghn" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.0.0"> + <bpmn:process id="CNFAdapterAsyncCall" name="CNFAdapterAsyncCall" isExecutable="true"> + <bpmn:startEvent id="StartEvent_1" name="CNFAdapterAsyncCall_start"> + <bpmn:outgoing>Flow_0q7kp9w</bpmn:outgoing> + </bpmn:startEvent> + <bpmn:endEvent id="Event_15f5cnf" name="CNFAdapterAsyncCall_end"> + <bpmn:incoming>Flow_0cy88g6</bpmn:incoming> + </bpmn:endEvent> + <bpmn:callActivity id="Activity_0fhymrt" name="Receive Async Callback" camunda:modelerTemplate="receiveWorkflowMessage" calledElement="ReceiveWorkflowMessage"> + <bpmn:extensionElements> + <camunda:in source="true" target="isDebugLogEnabled" /> + <camunda:out source="WorkflowException" target="WorkflowException" /> + <camunda:in source="messageType" target="RCVWFMSG_messageType" /> + <camunda:in source="correlator" target="RCVWFMSG_correlator" /> + <camunda:in source="timeout" target="RCVWFMSG_timeout" /> + <camunda:out source="WorkflowResponse" target="asyncCallbackResponse" /> + </bpmn:extensionElements> + <bpmn:incoming>Flow_0njjlbm</bpmn:incoming> + <bpmn:outgoing>Flow_0cy88g6</bpmn:outgoing> + </bpmn:callActivity> + <bpmn:sequenceFlow id="Flow_0njjlbm" sourceRef="Activity_1ttieoz" targetRef="Activity_0fhymrt" /> + <bpmn:sequenceFlow id="Flow_0q7kp9w" sourceRef="StartEvent_1" targetRef="Activity_0lttdg6" /> + <bpmn:sequenceFlow id="Flow_0cy88g6" sourceRef="Activity_0fhymrt" targetRef="Event_15f5cnf" /> + <bpmn:sequenceFlow id="Flow_04o97wl" sourceRef="Activity_0lttdg6" targetRef="Activity_1ttieoz" /> + <bpmn:scriptTask id="Activity_0lttdg6" name="Preprocess request" scriptFormat="groovy"> + <bpmn:incoming>Flow_0q7kp9w</bpmn:incoming> + <bpmn:outgoing>Flow_04o97wl</bpmn:outgoing> + <bpmn:script>import org.onap.so.bpmn.common.scripts.* +def cnf= new CNFAdapterAsync() +cnf.preProcessRequest(execution)</bpmn:script> + </bpmn:scriptTask> + <bpmn:scriptTask id="Activity_1ttieoz" name="Call CnfAdapter" scriptFormat="groovy"> + <bpmn:incoming>Flow_04o97wl</bpmn:incoming> + <bpmn:outgoing>Flow_0njjlbm</bpmn:outgoing> + <bpmn:script>import org.onap.so.bpmn.common.scripts.* +def cnf= new CNFAdapterAsync() +cnf.callCnfAdapter(execution)</bpmn:script> + </bpmn:scriptTask> + <bpmn:subProcess id="Activity_06t66qc" name="Error Handling " triggeredByEvent="true"> + <bpmn:startEvent id="Event_0ny1qj3"> + <bpmn:outgoing>Flow_0xo7st8</bpmn:outgoing> + <bpmn:errorEventDefinition id="ErrorEventDefinition_0ta0yq5" /> + </bpmn:startEvent> + <bpmn:endEvent id="Event_1t6t0h6"> + <bpmn:incoming>Flow_0xo7st8</bpmn:incoming> + <bpmn:terminateEventDefinition id="TerminateEventDefinition_1i0gtkr" /> + </bpmn:endEvent> + <bpmn:sequenceFlow id="Flow_0xo7st8" sourceRef="Event_0ny1qj3" targetRef="Event_1t6t0h6" /> + </bpmn:subProcess> + </bpmn:process> + <bpmndi:BPMNDiagram id="BPMNDiagram_1"> + <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="CNFAdapterAsyncCall"> + <bpmndi:BPMNEdge id="Flow_04o97wl_di" bpmnElement="Flow_04o97wl"> + <di:waypoint x="330" y="120" /> + <di:waypoint x="370" y="120" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_0cy88g6_di" bpmnElement="Flow_0cy88g6"> + <di:waypoint x="610" y="120" /> + <di:waypoint x="682" y="120" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_0q7kp9w_di" bpmnElement="Flow_0q7kp9w"> + <di:waypoint x="188" y="120" /> + <di:waypoint x="230" y="120" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_0njjlbm_di" bpmnElement="Flow_0njjlbm"> + <di:waypoint x="470" y="120" /> + <di:waypoint x="510" y="120" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1"> + <dc:Bounds x="152" y="102" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="128" y="145" width="85" height="27" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Event_15f5cnf_di" bpmnElement="Event_15f5cnf"> + <dc:Bounds x="682" y="102" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="658" y="145" width="85" height="27" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_0fhymrt_di" bpmnElement="Activity_0fhymrt"> + <dc:Bounds x="510" y="80" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_0j7hue7_di" bpmnElement="Activity_0lttdg6"> + <dc:Bounds x="230" y="80" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_0o6kxz9_di" bpmnElement="Activity_1ttieoz"> + <dc:Bounds x="370" y="80" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_06t66qc_di" bpmnElement="Activity_06t66qc" isExpanded="true"> + <dc:Bounds x="210" y="220" width="460" height="135" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="Flow_0xo7st8_di" bpmnElement="Flow_0xo7st8"> + <di:waypoint x="328" y="294" /> + <di:waypoint x="562" y="294" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="Event_0ny1qj3_di" bpmnElement="Event_0ny1qj3"> + <dc:Bounds x="292" y="276" width="36" height="36" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Event_1t6t0h6_di" bpmnElement="Event_1t6t0h6"> + <dc:Bounds x="562" y="276" width="36" height="36" /> + </bpmndi:BPMNShape> + </bpmndi:BPMNPlane> + </bpmndi:BPMNDiagram> +</bpmn:definitions> diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/HealthCheckBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/HealthCheckBB.bpmn new file mode 100755 index 0000000000..8272bd3750 --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/HealthCheckBB.bpmn @@ -0,0 +1,102 @@ +<?xml version="1.0" encoding="UTF-8"?> +<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1bvx7yi" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.0.0"> + <bpmn:process id="HealthCheckBB" name="HealthCheckBB" isExecutable="true"> + <bpmn:startEvent id="StartEvent_1" name="HealthCheckBB_start"> + <bpmn:outgoing>Flow_0gd6hy6</bpmn:outgoing> + </bpmn:startEvent> + <bpmn:endEvent id="Event_1dklvvk" name="HealthCheckBB_end"> + <bpmn:incoming>Flow_0xiyno7</bpmn:incoming> + </bpmn:endEvent> + <bpmn:sequenceFlow id="Flow_0gd6hy6" sourceRef="StartEvent_1" targetRef="Activity_11hkwkn" /> + <bpmn:subProcess id="Activity_1pto2qh" name="Error Handling " triggeredByEvent="true"> + <bpmn:startEvent id="Event_0929aqj"> + <bpmn:outgoing>Flow_05rbrsm</bpmn:outgoing> + <bpmn:errorEventDefinition id="ErrorEventDefinition_0k0ly65" /> + </bpmn:startEvent> + <bpmn:endEvent id="Event_1s698ql"> + <bpmn:incoming>Flow_05rbrsm</bpmn:incoming> + <bpmn:terminateEventDefinition id="TerminateEventDefinition_0mn6xgi" /> + </bpmn:endEvent> + <bpmn:sequenceFlow id="Flow_05rbrsm" sourceRef="Event_0929aqj" targetRef="Event_1s698ql" /> + </bpmn:subProcess> + <bpmn:serviceTask id="Activity_11hkwkn" name="Prepare Cnf Adapter request" camunda:expression="${CnfHealthCheckTasks.prepareCnfAdaperRequest(InjectExecution.execute(execution, execution.getVariable("gBuildingBlockExecution")))}"> + <bpmn:incoming>Flow_0gd6hy6</bpmn:incoming> + <bpmn:outgoing>Flow_1aqdd5k</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="Flow_1aqdd5k" sourceRef="Activity_11hkwkn" targetRef="Activity_08mgs1k" /> + <bpmn:callActivity id="Activity_08mgs1k" name="Call CNFAdapterAsyncCall" calledElement="CNFAdapterAsyncCall"> + <bpmn:extensionElements> + <camunda:in source="apiPath" target="apiPath" /> + <camunda:in source="cnfRequestPayload" target="cnfRequestPayload" /> + <camunda:in source="mso-request-id" target="correlator" /> + <camunda:in source="timeout" target="timeout" /> + <camunda:out source="WorkflowException" target="WorkflowException" /> + <camunda:out source="asyncCallbackResponse" target="asyncCallbackResponse" /> + <camunda:in source="messageType" target="messageType" /> + <camunda:in source="true" target="isDebugLogEnabled" /> + </bpmn:extensionElements> + <bpmn:incoming>Flow_1aqdd5k</bpmn:incoming> + <bpmn:outgoing>Flow_1jeui7e</bpmn:outgoing> + </bpmn:callActivity> + <bpmn:serviceTask id="Activity_0w4hy3d" name="Process Response" camunda:expression="${CnfHealthCheckTasks.processAsyncResponse(InjectExecution.execute(execution, execution.getVariable("gBuildingBlockExecution")))}"> + <bpmn:incoming>Flow_1jeui7e</bpmn:incoming> + <bpmn:outgoing>Flow_0xiyno7</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="Flow_0xiyno7" sourceRef="Activity_0w4hy3d" targetRef="Event_1dklvvk" /> + <bpmn:sequenceFlow id="Flow_1jeui7e" sourceRef="Activity_08mgs1k" targetRef="Activity_0w4hy3d" /> + </bpmn:process> + <bpmndi:BPMNDiagram id="BPMNDiagram_1"> + <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="HealthCheckBB"> + <bpmndi:BPMNEdge id="Flow_1jeui7e_di" bpmnElement="Flow_1jeui7e"> + <di:waypoint x="600" y="120" /> + <di:waypoint x="680" y="120" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_0xiyno7_di" bpmnElement="Flow_0xiyno7"> + <di:waypoint x="780" y="120" /> + <di:waypoint x="842" y="120" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_1aqdd5k_di" bpmnElement="Flow_1aqdd5k"> + <di:waypoint x="400" y="120" /> + <di:waypoint x="500" y="120" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_0gd6hy6_di" bpmnElement="Flow_0gd6hy6"> + <di:waypoint x="218" y="120" /> + <di:waypoint x="300" y="120" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="Event_1dklvvk_di" bpmnElement="Event_1dklvvk"> + <dc:Bounds x="842" y="102" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="820" y="145" width="85" height="27" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1"> + <dc:Bounds x="182" y="102" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="156" y="145" width="90" height="27" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_11hkwkn_di" bpmnElement="Activity_11hkwkn"> + <dc:Bounds x="300" y="80" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_0f7poou_di" bpmnElement="Activity_08mgs1k"> + <dc:Bounds x="500" y="80" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_0w4hy3d_di" bpmnElement="Activity_0w4hy3d"> + <dc:Bounds x="680" y="80" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_1pto2qh_di" bpmnElement="Activity_1pto2qh" isExpanded="true"> + <dc:Bounds x="280" y="250" width="460" height="135" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="Flow_05rbrsm_di" bpmnElement="Flow_05rbrsm"> + <di:waypoint x="398" y="324" /> + <di:waypoint x="632" y="324" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="Event_0929aqj_di" bpmnElement="Event_0929aqj"> + <dc:Bounds x="362" y="306" width="36" height="36" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Event_1s698ql_di" bpmnElement="Event_1s698ql"> + <dc:Bounds x="632" y="306" width="36" height="36" /> + </bpmndi:BPMNShape> + </bpmndi:BPMNPlane> + </bpmndi:BPMNDiagram> +</bpmn:definitions> diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfHealthCheckTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfHealthCheckTasks.java new file mode 100755 index 0000000000..e6545cb800 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfHealthCheckTasks.java @@ -0,0 +1,185 @@ +package org.onap.so.bpmn.infrastructure.adapter.cnf.tasks; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; +import org.onap.logging.filter.base.ONAPComponents; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; +import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; +import org.onap.so.client.adapter.cnf.entities.HealthcheckInstance; +import org.onap.so.client.adapter.cnf.entities.HealthcheckInstanceRequest; +import org.onap.so.client.adapter.cnf.entities.HealthcheckInstanceResponse; +import org.onap.so.client.adapter.cnf.entities.HealthcheckResponse; +import org.onap.so.client.adapter.cnf.entities.StatusCheckInstanceResponse; +import org.onap.so.client.adapter.cnf.entities.StatusCheckResponse; +import org.onap.so.client.exception.ExceptionBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Component +public class CnfHealthCheckTasks { + private static final Logger LOGGER = LoggerFactory.getLogger(CnfHealthCheckTasks.class); + private static final String BUILDING_BLOCK = "buildingBlock"; + private static final String HEALTH_CHECK_SCOPE = "health-check"; + private static final String STATUS_CHECK_SCOPE = "status-check"; + private static final String CNF_ADAPTER_MESSAGE_TYPE = "CNFCallback"; + + @Autowired + private ExceptionBuilder exceptionUtil; + + private ObjectMapper mapper = new ObjectMapper(); + + public void prepareCnfAdaperRequest(BuildingBlockExecution execution) { + GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock(); + ServiceInstance serviceInstance = gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0); + GenericVnf genericVnf = serviceInstance.getVnfs().get(0); + List<VfModule> listOfVfModules = genericVnf.getVfModules(); + List<String> listOfHeatStackIds = + listOfVfModules.stream().map(x -> x.getHeatStackId()).collect(Collectors.toList()); + LOGGER.debug("listOfHeatStackIds from prepareCnfAdaperRequest: {}", listOfHeatStackIds); + + // Prepare values to pass in execution variable for CNF Adapter async Handling + String requestId = execution.getVariable("mso-request-id"); + execution.setVariable("messageType", CNF_ADAPTER_MESSAGE_TYPE); + execution.setVariable("correlator", requestId); + execution.setVariable("timeout", "PT30M"); + // Replace with environment values + String callBackUrl = + "http://so-bpmn-infra.onap:8081/mso/WorkflowMessage/" + CNF_ADAPTER_MESSAGE_TYPE + "/" + requestId; + HealthcheckInstanceRequest request = new HealthcheckInstanceRequest(); + try { + request = createStatusCheckRequest(listOfHeatStackIds, callBackUrl); + } catch (JsonProcessingException e) { + exceptionUtil.buildAndThrowWorkflowException(execution, 6822, e); + } + LOGGER.debug("request: {}", request); + + String requestPayload = ""; + try { + requestPayload = mapper.writeValueAsString(request); + } catch (JsonProcessingException e) { + LOGGER.error("Error in JSON"); + } + execution.setVariable("cnfRequestPayload", requestPayload); + + ExecuteBuildingBlock executeBuildingBlock = execution.getVariable(BUILDING_BLOCK); + BuildingBlock buildingBlock = executeBuildingBlock.getBuildingBlock(); + String action = Optional.ofNullable(buildingBlock.getBpmnAction()).orElseThrow( + () -> new NullPointerException("BPMN Action is NULL in the orchestration_flow_reference table ")); + + // Replace values with environment values + String uri = "http://so-cnf-adapter:8090"; + String apiPath = ""; + + if (STATUS_CHECK_SCOPE.equals(action)) { + apiPath = uri + "/api/cnf-adapter/v1/statuscheck/"; + } else if (HEALTH_CHECK_SCOPE.equals(action)) { + apiPath = uri + "/api/cnf-adapter/v1/healthcheck/"; + } + + LOGGER.debug("apiPath: {}", apiPath); + + execution.setVariable("apiPath", apiPath); + } + + public void processAsyncResponse(BuildingBlockExecution execution) { + // Value from CNF Async Handler activity + String asyncResponse = execution.getVariable("asyncCallbackResponse"); + + ExecuteBuildingBlock executeBuildingBlock = execution.getVariable(BUILDING_BLOCK); + BuildingBlock buildingBlock = executeBuildingBlock.getBuildingBlock(); + String action = Optional.ofNullable(buildingBlock.getBpmnAction()).orElseThrow( + () -> new NullPointerException("BPMN Action is NULL in the orchestration_flow_reference table ")); + + LOGGER.debug("action: {}", action); + + if (asyncResponse.contains("error")) { + exceptionUtil.buildAndThrowWorkflowException(execution, 500, asyncResponse, ONAPComponents.SO); + } + + if (STATUS_CHECK_SCOPE.equals(action)) { + StatusCheckResponse statusCheckResponse = new StatusCheckResponse(); + + try { + statusCheckResponse = mapper.readValue(asyncResponse, StatusCheckResponse.class); + } catch (JsonProcessingException e) { + LOGGER.error("Error in parsing JSON response"); + } + + LOGGER.debug("statusCheckResponse: {}", statusCheckResponse); + + List<StatusCheckInstanceResponse> listOfStatusInstanceResponse = statusCheckResponse.getInstanceResponse(); + + for (StatusCheckInstanceResponse statusCheckInstanceResponse : listOfStatusInstanceResponse) { + if (!statusCheckInstanceResponse.isStatus()) { + exceptionUtil.buildAndThrowWorkflowException(execution, 500, asyncResponse, ONAPComponents.SO); + } + } + + String statusCheckResponseJson = ""; + try { + statusCheckResponseJson = mapper.writeValueAsString(statusCheckResponse); + } catch (JsonProcessingException e) { + LOGGER.error("Error in PARSING statusCheckResponse"); + } + + execution.setVariable("StatusMessage", statusCheckResponseJson); + + } else if (HEALTH_CHECK_SCOPE.equals(action)) { + HealthcheckResponse healthCheckResponse = new HealthcheckResponse(); + try { + healthCheckResponse = mapper.readValue(asyncResponse, HealthcheckResponse.class); + } catch (JsonProcessingException e) { + LOGGER.error("Error in parsing JSON"); + } + + List<HealthcheckInstanceResponse> listOfHealthcheckInstanceResponses = + healthCheckResponse.getInstanceResponse(); + + for (HealthcheckInstanceResponse healthcheckInstanceResponse : listOfHealthcheckInstanceResponses) { + if ("Failed".equalsIgnoreCase(healthcheckInstanceResponse.getStatus()) + || "Unknown".equalsIgnoreCase(healthcheckInstanceResponse.getStatus())) { + exceptionUtil.buildAndThrowWorkflowException(execution, 500, asyncResponse, ONAPComponents.SO); + } + } + + String healthCheckResponseJson = ""; + try { + healthCheckResponseJson = mapper.writeValueAsString(healthCheckResponse); + } catch (JsonProcessingException e) { + LOGGER.error("Error in PARSING statusCheckResponse"); + } + + execution.setVariable("StatusMessage", healthCheckResponseJson); + + LOGGER.debug("healthCheckResponse: {}", healthCheckResponse); + } + + } + + protected HealthcheckInstanceRequest createStatusCheckRequest(List<String> listOfHeatStackIds, String callBackUrl) + throws JsonProcessingException { + HealthcheckInstanceRequest healthcheckInstanceRequest = new HealthcheckInstanceRequest(); + List<HealthcheckInstance> listOfHealthcheckInstance = new ArrayList<>(); + + listOfHeatStackIds.stream().forEach(x -> listOfHealthcheckInstance.add(new HealthcheckInstance(x))); + LOGGER.debug("listOfHealthcheckInstance: {}", listOfHealthcheckInstance); + + healthcheckInstanceRequest.setInstances(listOfHealthcheckInstance); + healthcheckInstanceRequest.setCallbackUrl(callBackUrl); + LOGGER.debug("healthcheckInstanceRequest: {}", healthcheckInstanceRequest); + + return healthcheckInstanceRequest; + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ExecuteBuildingBlockBuilder.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ExecuteBuildingBlockBuilder.java index 2bd0f2c786..920369784e 100644..100755 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ExecuteBuildingBlockBuilder.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ExecuteBuildingBlockBuilder.java @@ -54,6 +54,7 @@ public class ExecuteBuildingBlockBuilder { private static final String PNF = "Pnf"; private static final String VFMODULE = "VfModule"; private static final String NETWORK = "Network"; + private static final String HEALTH_CHECK = "HealthCheckBB"; protected List<ExecuteBuildingBlock> buildExecuteBuildingBlockList(List<OrchestrationFlow> orchFlows, List<Resource> originalResourceList, String requestId, String apiVersion, String resourceId, @@ -119,6 +120,10 @@ public class ExecuteBuildingBlockBuilder { || (orchFlow.getFlowName().contains(CONTROLLER) && (VNF).equalsIgnoreCase(orchFlow.getBpmnScope()))) { addBuildingBlockToExecuteBBList(flowsToExecute, resource, WorkflowType.VNF, orchFlow, requestId, apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, false, false); + } else if ((orchFlow.getFlowName().equalsIgnoreCase(HEALTH_CHECK)) + && (VNF).equalsIgnoreCase(orchFlow.getBpmnScope())) { + addBuildingBlockToExecuteBBList(flowsToExecute, resource, WorkflowType.VNF, orchFlow, requestId, apiVersion, + resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, false, false); } else if (orchFlow.getFlowName().contains(PNF) || (orchFlow.getFlowName().contains(CONTROLLER) && (PNF).equalsIgnoreCase(orchFlow.getBpmnScope()))) { addBuildingBlockToExecuteBBList(flowsToExecute, resource, WorkflowType.PNF, orchFlow, requestId, apiVersion, diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java index 02508b8867..f36c5a2915 100644..100755 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java @@ -38,6 +38,7 @@ import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConst import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.REPLACEINSTANCERETAINASSIGNMENTS; import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.SERVICE; import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.UPDATE_INSTANCE; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.HEALTH_CHECK; import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.WORKFLOW_ACTION_ERROR_MESSAGE; import java.io.IOException; import java.util.ArrayList; @@ -298,6 +299,9 @@ public class WorkflowAction { } else if (resourceType == WorkflowType.VNF && UPDATE_INSTANCE.equalsIgnoreCase(requestAction)) { vnfEBBLoader.customTraverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(), workflowResourceIds.getVnfId(), aaiResourceIds); + } else if (resourceType == WorkflowType.VNF && HEALTH_CHECK.equalsIgnoreCase(requestAction)) { + vnfEBBLoader.customTraverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(), + workflowResourceIds.getVnfId(), aaiResourceIds); } else { buildAndThrowException(execution, "Current Macro Request is not supported"); } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java index 8c6fb2b38b..a41613982d 100644..100755 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java @@ -50,6 +50,7 @@ public final class WorkflowActionConstants { public static final String UPDATE_INSTANCE = "updateInstance"; public static final String USER_PARAM_SERVICE = "service"; public static final String VOLUMEGROUP = "VolumeGroup"; + public static final String HEALTH_CHECK = "healthCheck"; public static final String WORKFLOW_ACTION_ERROR_MESSAGE = "WorkflowActionErrorMessage"; } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/HealthcheckInstance.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/HealthcheckInstance.java new file mode 100755 index 0000000000..e3fc8b80df --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/HealthcheckInstance.java @@ -0,0 +1,32 @@ +package org.onap.so.client.adapter.cnf.entities; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(value = "true") +public class HealthcheckInstance { + + public HealthcheckInstance() {} + + public HealthcheckInstance(String instanceId) { + this.instanceId = instanceId; + } + + @JsonProperty("instanceId") + private String instanceId; + + public String getInstanceId() { + return instanceId; + } + + public void setInstanceId(String instanceId) { + this.instanceId = instanceId; + } + + @Override + public String toString() { + return "InstanceRequest{" + "instanceId='" + instanceId + '\'' + '}'; + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/HealthcheckInstanceRequest.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/HealthcheckInstanceRequest.java new file mode 100755 index 0000000000..a89d18bb3d --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/HealthcheckInstanceRequest.java @@ -0,0 +1,38 @@ +package org.onap.so.client.adapter.cnf.entities; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(value = "true") +public class HealthcheckInstanceRequest { + + @JsonProperty("requestedInstances") + private List<HealthcheckInstance> instances; + + @JsonProperty("callbackUrl") + private String callbackUrl; + + public List<HealthcheckInstance> getInstances() { + return instances; + } + + public void setInstances(List<HealthcheckInstance> instances) { + this.instances = instances; + } + + public String getCallbackUrl() { + return callbackUrl; + } + + public void setCallbackUrl(String callbackUrl) { + this.callbackUrl = callbackUrl; + } + + @Override + public String toString() { + return "CheckInstanceRequest{" + "instances=" + instances + ", callbackUrl='" + callbackUrl + '\'' + '}'; + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/HealthcheckInstanceResponse.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/HealthcheckInstanceResponse.java new file mode 100755 index 0000000000..ca8a1caad5 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/HealthcheckInstanceResponse.java @@ -0,0 +1,57 @@ +package org.onap.so.client.adapter.cnf.entities; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(value = "true") +public class HealthcheckInstanceResponse { + + @JsonProperty("instanceId") + private String instanceId; + + @JsonProperty("reason") + private String reason; + + @JsonProperty("status") + private String status; + + public HealthcheckInstanceResponse() {} + + public HealthcheckInstanceResponse(String instanceId, String reason, String status) { + this.instanceId = instanceId; + this.reason = reason; + this.status = status; + } + + public String getInstanceId() { + return instanceId; + } + + public void setInstanceId(String instanceId) { + this.instanceId = instanceId; + } + + public String getReason() { + return reason; + } + + public void setReason(String reason) { + this.reason = reason; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + @Override + public String toString() { + return "HealthcheckInstanceResponse{" + "instanceId='" + instanceId + '\'' + ", reason='" + reason + '\'' + + ", status=" + status + '}'; + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/HealthcheckResponse.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/HealthcheckResponse.java new file mode 100755 index 0000000000..175cb3a224 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/HealthcheckResponse.java @@ -0,0 +1,28 @@ +package org.onap.so.client.adapter.cnf.entities; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(value = "true") +public class HealthcheckResponse { + + @JsonProperty("result") + private List<HealthcheckInstanceResponse> instanceResponse; + + public List<HealthcheckInstanceResponse> getInstanceResponse() { + return instanceResponse; + } + + public void setInstanceResponse(List<HealthcheckInstanceResponse> instanceResponse) { + this.instanceResponse = instanceResponse; + } + + @Override + public String toString() { + return "HealthcheckResponse{" + "instanceResponse=" + instanceResponse + '}'; + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/StatusCheckInstanceResponse.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/StatusCheckInstanceResponse.java new file mode 100755 index 0000000000..cac589f90a --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/StatusCheckInstanceResponse.java @@ -0,0 +1,57 @@ +package org.onap.so.client.adapter.cnf.entities; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(value = "true") +public class StatusCheckInstanceResponse { + + @JsonProperty("instanceId") + private String instanceId; + + @JsonProperty("reason") + private String reason; + + @JsonProperty("status") + private boolean status; + + public StatusCheckInstanceResponse() {} + + public StatusCheckInstanceResponse(String instanceId, String reason, boolean status) { + this.instanceId = instanceId; + this.reason = reason; + this.status = status; + } + + public String getInstanceId() { + return instanceId; + } + + public void setInstanceId(String instanceId) { + this.instanceId = instanceId; + } + + public String getReason() { + return reason; + } + + public void setReason(String reason) { + this.reason = reason; + } + + public boolean isStatus() { + return status; + } + + public void setStatus(boolean status) { + this.status = status; + } + + @Override + public String toString() { + return "StatusCheckInstanceResponse{" + "instanceId='" + instanceId + '\'' + ", reason='" + reason + '\'' + + ", status=" + status + '}'; + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/StatusCheckResponse.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/StatusCheckResponse.java new file mode 100755 index 0000000000..aec2892e22 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/StatusCheckResponse.java @@ -0,0 +1,28 @@ +package org.onap.so.client.adapter.cnf.entities; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(value = "true") +public class StatusCheckResponse { + + @JsonProperty("result") + private List<StatusCheckInstanceResponse> instanceResponse; + + public List<StatusCheckInstanceResponse> getInstanceResponse() { + return instanceResponse; + } + + public void setInstanceResponse(List<StatusCheckInstanceResponse> instanceResponse) { + this.instanceResponse = instanceResponse; + } + + @Override + public String toString() { + return "StatusCheckResponse{" + "instanceResponse=" + instanceResponse + '}'; + } + +} |