summaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-infrastructure-common
diff options
context:
space:
mode:
authorLukasz Muszkieta <lukasz.muszkieta@nokia.com>2021-01-07 08:57:46 +0000
committerGerrit Code Review <gerrit@onap.org>2021-01-07 08:57:46 +0000
commit67160220ddd1463696f3d56fde035dc4f3949f73 (patch)
treef95a4bd07492077ee3a7df46bc3f02a8d01bd2be /bpmn/so-bpmn-infrastructure-common
parenta7822286a4a1631d446c30c8ccd7ede3d3f2ff4f (diff)
parent0a43a2a9fdbf7a524122384fdfea698d8eb9f523 (diff)
Merge "Fix for globalSubscriberId and requestId"
Diffstat (limited to 'bpmn/so-bpmn-infrastructure-common')
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ServiceLevelUpgrade.groovy126
1 files changed, 126 insertions, 0 deletions
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ServiceLevelUpgrade.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ServiceLevelUpgrade.groovy
new file mode 100644
index 0000000000..15f44ce03c
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ServiceLevelUpgrade.groovy
@@ -0,0 +1,126 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 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 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.common.scripts.MsoUtils
+import org.onap.so.bpmn.common.workflow.context.WorkflowContext
+import org.onap.so.bpmn.common.workflow.context.WorkflowContextHolder
+import org.onap.so.bpmn.core.WorkflowException
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_CORRELATION_ID
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.REQUEST_ID
+
+class ServiceLevelUpgrade extends AbstractServiceTaskProcessor {
+ private static final Logger logger = LoggerFactory.getLogger(ServiceLevelUpgrade.class)
+
+ ExceptionUtil exceptionUtil = new ExceptionUtil()
+ String prefix = "ServiceLevelUpgrade_"
+
+ @Override
+ void preProcessRequest(DelegateExecution execution) {
+ }
+
+ void sendResponse(DelegateExecution execution) {
+ def requestId = execution.getVariable(REQUEST_ID)
+ def instanceId = execution.getVariable(PNF_CORRELATION_ID)
+ logger.debug("Send response for requestId: {}, instanceId: {}", requestId, instanceId)
+
+ String response = """{"requestReferences":{"requestId":"${requestId}", "instanceId":"${instanceId}"}}""".trim()
+ sendWorkflowResponse(execution, 200, response)
+ }
+
+ static WorkflowContext getWorkflowContext(DelegateExecution execution) {
+ String requestId = execution.getVariable(REQUEST_ID)
+ return WorkflowContextHolder.getInstance().getWorkflowContext(requestId)
+ }
+
+ void prepareCompletion(DelegateExecution execution) {
+ try {
+ String requestId = execution.getVariable(REQUEST_ID)
+ logger.debug("Prepare Completion of Service Level Upgrade for requestId: {}", requestId)
+
+ String msoCompletionRequest =
+ """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
+ xmlns:ns="http://org.onap/so/request/types/v1">
+ <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
+ <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
+ <action>UPDATE</action>
+ <source>VID</source>
+ </request-info>
+ <aetgt:status-message>Service Level Upgrade successful.</aetgt:status-message>
+ <aetgt:mso-bpel-name>SERVICE_LEVEL_UPGRADE</aetgt:mso-bpel-name>
+ </aetgt:MsoCompletionRequest>"""
+ String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
+
+ execution.setVariable(prefix + "CompleteMsoProcessRequest", xmlMsoCompletionRequest)
+
+ logger.debug("CompleteMsoProcessRequest of Service Level Upgrade - " + "\n" + xmlMsoCompletionRequest)
+ } catch (Exception e) {
+ String msg = "Prepare Completion error for Service Level Upgrade - " + e.getMessage()
+ logger.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+ }
+ }
+
+ void prepareFalloutHandler(DelegateExecution execution) {
+ WorkflowContext workflowContext = getWorkflowContext(execution)
+ if (workflowContext == null) {
+ logger.debug("Error occurred before sending response to API handler, and send it now")
+ sendResponse(execution)
+ }
+
+ try {
+ String requestId = execution.getVariable(REQUEST_ID)
+ logger.debug("Prepare FalloutHandler of Service Level Upgrade for requestId: {}", requestId)
+
+ WorkflowException workflowException = (WorkflowException)execution.getVariable("WorkflowException")
+ String errorCode = String.valueOf(workflowException.getErrorCode())
+ String errorMessage = workflowException.getErrorMessage()
+ String falloutHandlerRequest =
+ """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
+ xmlns:ns="http://org.onap/so/request/types/v1">
+ <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
+ <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
+ <action>UPDATE</action>
+ <source>VID</source>
+ </request-info>
+ <aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
+ <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorMessage)}</aetgt:ErrorMessage>
+ <aetgt:ErrorCode>${MsoUtils.xmlEscape(errorCode)}</aetgt:ErrorCode>
+ </aetgt:WorkflowException>
+ </aetgt:FalloutHandlerRequest>"""
+ String xmlFalloutHandlerRequest = utils.formatXml(falloutHandlerRequest)
+
+ execution.setVariable(prefix + "FalloutHandlerRequest", xmlFalloutHandlerRequest)
+
+ logger.debug("FalloutHandlerRequest of Service Level Upgrade - " + "\n" + xmlFalloutHandlerRequest)
+ } catch (Exception e) {
+ String msg = "Prepare FalloutHandler error for Service Level upgrade - " + e.getMessage()
+ logger.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+ }
+ }
+}