diff options
Diffstat (limited to 'bpmn/so-bpmn-infrastructure-common')
2 files changed, 127 insertions, 7 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() |