diff options
Diffstat (limited to 'bpmn')
4 files changed, 217 insertions, 10 deletions
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/HandleOrchestrationTask.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/HandleOrchestrationTask.groovy new file mode 100644 index 0000000000..89490ff620 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/HandleOrchestrationTask.groovy @@ -0,0 +1,127 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.scripts + +import com.fasterxml.jackson.databind.ObjectMapper +import org.onap.so.db.request.beans.OrchestrationTask + +import static org.apache.commons.lang3.StringUtils.* +import org.camunda.bpm.engine.delegate.DelegateExecution +import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor +import org.onap.so.bpmn.common.scripts.ExceptionUtil +import org.onap.so.bpmn.core.UrnPropertiesReader +import org.slf4j.Logger +import org.slf4j.LoggerFactory + +class HandleOrchestrationTask extends AbstractServiceTaskProcessor { + private static final Logger logger = LoggerFactory.getLogger(HandleOrchestrationTask.class) + + ExceptionUtil exceptionUtil = new ExceptionUtil() + def supportedMethod = ["GET", "POST", "PUT"] + def validStatus = [200, 201] + + @Override + public void preProcessRequest(DelegateExecution execution) { + logger.debug("Start preProcessRequest") + String method = execution.getVariable("method") + if (!supportedMethod.contains(method)) { + String msg = "Method: " + method + " is not supported" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + + String taskId = execution.getVariable("taskId") + if (isBlank(taskId)) { + String msg = "taskId is empty" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + + def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.requestDb.endpoint",execution) + def orchestrationTaskEndpoint = dbAdapterEndpoint + "/orchestrationTask/" + if (!"POST".equals(method)) { + orchestrationTaskEndpoint = orchestrationTaskEndpoint + taskId + } + execution.setVariable("url", orchestrationTaskEndpoint) + logger.debug("DB Adapter Endpoint is: " + orchestrationTaskEndpoint) + def dbAdapterAuth = UrnPropertiesReader.getVariable("mso.adapters.requestDb.auth") + Map<String, String> headerMap = [:] + headerMap.put("content-type", "application/json") + headerMap.put("Authorization", dbAdapterAuth) + execution.setVariable("headerMap", headerMap) + logger.debug("DB Adapter Header is: " + headerMap) + + String requestId = execution.getVariable("requestId") + if (("POST".equals(method) || "PUT".equals(method)) && isBlank(requestId)) { + String msg = "requestId is empty" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + String taskName = execution.getVariable("taskName") + if (("POST".equals(method) || "PUT".equals(method)) && isBlank(taskName)) { + String msg = "task name is empty" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + String taskStatus = execution.getVariable("taskStatus") + if (("POST".equals(method) || "PUT".equals(method)) && isBlank(taskStatus)) { + String msg = "task status is empty" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + String isManual = execution.getVariable("isManual") + if (("POST".equals(method) || "PUT".equals(method)) && isBlank(isManual)) { + String msg = "isManual is empty" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + String paramJson = execution.getVariable("paramJson") + + String payload = "" + if ("POST".equals(method) || "PUT".equals(method)) { + OrchestrationTask task = new OrchestrationTask() + task.setTaskId(taskId) + task.setRequestId(requestId) + task.setName(taskName) + task.setStatus(taskStatus) + task.setIsManual(isManual) + task.setParams(paramJson) + ObjectMapper objectMapper = new ObjectMapper() + payload = objectMapper.writeValueAsString(task) + logger.debug("Outgoing payload is \n" + payload) + } + execution.setVariable("payload", payload) + logger.debug("End preProcessRequest") + } + + public void postProcess(DelegateExecution execution) { + Integer statusCode = execution.getVariable("statusCode") + logger.debug("statusCode: " + statusCode) + String response = execution.getVariable("response") + logger.debug("response: " + response) + if (!validStatus.contains(statusCode)) { + String msg = "Error in sending orchestrationTask request. \nstatusCode: " + statusCode + "\nresponse: " + response + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + } +} + diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSliceService.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSliceService.groovy index 7cc1a559c3..c3f36ef545 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSliceService.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSliceService.groovy @@ -273,7 +273,6 @@ public class CreateSliceService extends AbstractServiceTaskProcessor { execution.setVariable("orchestrationTaskId", taskId) logger.debug("BusinessKey: " + taskId) String serviceInstanceId = execution.getVariable("serviceInstanceId") - String operationId = execution.getVariable("operationId") String serviceInstanceName = execution.getVariable("serviceInstanceName") String taskName = "SliceServiceTask" String taskStatus = "Planning" @@ -286,17 +285,11 @@ public class CreateSliceService extends AbstractServiceTaskProcessor { execution.setVariable("CSSOT_requestMethod", requestMethod) Map<String, Object> serviceProfile = execution.getVariable("serviceProfile") - Map<String, Object> sliceProfileTn = execution.getVariable("sliceProfileTn") - Map<String, Object> sliceProfileCn = execution.getVariable("sliceProfileCn") - Map<String, Object> sliceProfileAn = execution.getVariable("sliceProfileAn") SliceTaskParams sliceTaskParams = new SliceTaskParams() sliceTaskParams.setServiceId(serviceInstanceId) sliceTaskParams.setServiceName(serviceInstanceName) sliceTaskParams.setServiceProfile(serviceProfile) - sliceTaskParams.setSliceProfileTn(sliceProfileTn) - sliceTaskParams.setSliceProfileCn(sliceProfileCn) - sliceTaskParams.setSliceProfileAn(sliceProfileAn) execution.setVariable("sliceTaskParams", sliceTaskParams) String paramJson = sliceTaskParams.convertToJson() diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/CreateSliceService.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/CreateSliceService.bpmn index 3e1c1179bf..013e1b62c2 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/CreateSliceService.bpmn +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/CreateSliceService.bpmn @@ -428,10 +428,7 @@ css.sendSyncResponse(execution)</bpmn:script> <camunda:in source="nstModelUuid" target="nstModelUuid" /> <camunda:in source="nstModelInvariantUuid" target="nstModelInvariantUuid" /> <camunda:in source="serviceProfile" target="serviceProfile" /> - <camunda:in source="sliceProfileTn" target="sliceProfileTn" /> <camunda:in source="msoRequestId" target="msoRequestId" /> - <camunda:in source="sliceProfileCn" target="sliceProfileCn" /> - <camunda:in source="sliceProfileAn" target="sliceProfileAn" /> <camunda:in source="sliceTaskParams" target="sliceTaskParams" /> <camunda:in source="resourceSharingLevel" target="resourceSharingLevel" /> <camunda:out source="sliceTaskParams" target="sliceTaskParams" /> diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/HandleOrchestrationTask.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/HandleOrchestrationTask.bpmn new file mode 100644 index 0000000000..09a14be26b --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/HandleOrchestrationTask.bpmn @@ -0,0 +1,90 @@ +<?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_1gbzu9i" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.1.2"> + <bpmn:process id="HandleOrchestrationTask" name="HandleOrchestrationTask" isExecutable="true"> + <bpmn:startEvent id="StartEvent_1" name="Start"> + <bpmn:outgoing>SequenceFlow_0lbtmuu</bpmn:outgoing> + </bpmn:startEvent> + <bpmn:scriptTask id="ScriptTask_0r0a9ga" name="Preprocess Request" scriptFormat="groovy"> + <bpmn:incoming>SequenceFlow_0lbtmuu</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_0uzjpd6</bpmn:outgoing> + <bpmn:script>import org.onap.so.bpmn.infrastructure.scripts.* +def hot = new HandleOrchestrationTask() +hot.preProcessRequest(execution)</bpmn:script> + </bpmn:scriptTask> + <bpmn:serviceTask id="ServiceTask_1iat8g5" name="Send Orchestration Task Request"> + <bpmn:extensionElements> + <camunda:connector> + <camunda:inputOutput> + <camunda:inputParameter name="url">${url}</camunda:inputParameter> + <camunda:inputParameter name="headers"> + <camunda:script scriptFormat="groovy">execution.getVariable("headerMap")</camunda:script> + </camunda:inputParameter> + <camunda:inputParameter name="payload">${payload}</camunda:inputParameter> + <camunda:inputParameter name="method">${method}</camunda:inputParameter> + <camunda:outputParameter name="statusCode">${statusCode}</camunda:outputParameter> + <camunda:outputParameter name="response">${response}</camunda:outputParameter> + </camunda:inputOutput> + <camunda:connectorId>http-connector</camunda:connectorId> + </camunda:connector> + </bpmn:extensionElements> + <bpmn:incoming>SequenceFlow_0uzjpd6</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_06rrzml</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:scriptTask id="ScriptTask_119zm52" name="Post Process" scriptFormat="groovy"> + <bpmn:incoming>SequenceFlow_06rrzml</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_1qthzdo</bpmn:outgoing> + <bpmn:script>import org.onap.so.bpmn.infrastructure.scripts.* +def hot = new HandleOrchestrationTask() +hot.postProcess(execution)</bpmn:script> + </bpmn:scriptTask> + <bpmn:sequenceFlow id="SequenceFlow_0uzjpd6" sourceRef="ScriptTask_0r0a9ga" targetRef="ServiceTask_1iat8g5" /> + <bpmn:sequenceFlow id="SequenceFlow_06rrzml" sourceRef="ServiceTask_1iat8g5" targetRef="ScriptTask_119zm52" /> + <bpmn:sequenceFlow id="SequenceFlow_0lbtmuu" sourceRef="StartEvent_1" targetRef="ScriptTask_0r0a9ga" /> + <bpmn:endEvent id="EndEvent_18t5h42" name="End"> + <bpmn:incoming>SequenceFlow_1qthzdo</bpmn:incoming> + </bpmn:endEvent> + <bpmn:sequenceFlow id="SequenceFlow_1qthzdo" sourceRef="ScriptTask_119zm52" targetRef="EndEvent_18t5h42" /> + </bpmn:process> + <bpmndi:BPMNDiagram id="BPMNDiagram_1"> + <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="HandleOrchestrationTask"> + <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1"> + <dc:Bounds x="179" y="103" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="185" y="146" width="25" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="ScriptTask_0r0a9ga_di" bpmnElement="ScriptTask_0r0a9ga"> + <dc:Bounds x="284" y="81" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="ServiceTask_1iat8g5_di" bpmnElement="ServiceTask_1iat8g5"> + <dc:Bounds x="466" y="81" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="ScriptTask_119zm52_di" bpmnElement="ScriptTask_119zm52"> + <dc:Bounds x="644" y="81" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_0uzjpd6_di" bpmnElement="SequenceFlow_0uzjpd6"> + <di:waypoint x="384" y="121" /> + <di:waypoint x="466" y="121" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="SequenceFlow_06rrzml_di" bpmnElement="SequenceFlow_06rrzml"> + <di:waypoint x="566" y="121" /> + <di:waypoint x="644" y="121" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="SequenceFlow_0lbtmuu_di" bpmnElement="SequenceFlow_0lbtmuu"> + <di:waypoint x="215" y="121" /> + <di:waypoint x="284" y="121" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="EndEvent_18t5h42_di" bpmnElement="EndEvent_18t5h42"> + <dc:Bounds x="820" y="103" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="828" y="146" width="20" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_1qthzdo_di" bpmnElement="SequenceFlow_1qthzdo"> + <di:waypoint x="744" y="121" /> + <di:waypoint x="820" y="121" /> + </bpmndi:BPMNEdge> + </bpmndi:BPMNPlane> + </bpmndi:BPMNDiagram> +</bpmn:definitions> + |