From 16b4369694a865a1c4bfaa6b562562ecbd102ed3 Mon Sep 17 00:00:00 2001 From: tragait Date: Thu, 26 Nov 2020 13:49:12 +0000 Subject: Fix for globalSubscriberId and requestId Issue-ID: SO-3401 Signed-off-by: tragait Change-Id: I33a71dffe7c63a50c807aa206d638a6aea5f1210 --- .../scripts/ServiceLevelUpgrade.groovy | 126 +++++++++++++++++++ .../resources/process/GenericPnfHealthCheck.bpmn | 3 +- .../resources/process/GenericPnfSWUPDownload.bpmn | 3 +- .../process/GenericPnfSoftwareUpgrade.bpmn | 3 +- .../resources/process/ServiceLevelUpgrade.bpmn | 140 ++++++++++++--------- .../process/ServiceLevelUpgradeTest.java | 4 +- 6 files changed, 214 insertions(+), 65 deletions(-) create mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ServiceLevelUpgrade.groovy (limited to 'bpmn') 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 = + """ + + ${MsoUtils.xmlEscape(requestId)} + UPDATE + VID + + Service Level Upgrade successful. + SERVICE_LEVEL_UPGRADE + """ + 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 = + """ + + ${MsoUtils.xmlEscape(requestId)} + UPDATE + VID + + + ${MsoUtils.xmlEscape(errorMessage)} + ${MsoUtils.xmlEscape(errorCode)} + + """ + 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) + } + } +} diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/GenericPnfHealthCheck.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/GenericPnfHealthCheck.bpmn index 36f6221da9..d46b5856d1 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/GenericPnfHealthCheck.bpmn +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/GenericPnfHealthCheck.bpmn @@ -1,5 +1,5 @@ - + SequenceFlow_1ng4b6l @@ -42,6 +42,7 @@ taskProcessor.prepareCompletion(execution) + SequenceFlow_0ipc3nt SequenceFlow_0tle5zb diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/GenericPnfSWUPDownload.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/GenericPnfSWUPDownload.bpmn index 6a0b260a70..8c667a291b 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/GenericPnfSWUPDownload.bpmn +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/GenericPnfSWUPDownload.bpmn @@ -1,5 +1,5 @@ - + SequenceFlow_1fdclh0 @@ -131,6 +131,7 @@ pnfSwUpgrade.prepareCompletion(execution) + SequenceFlow_183s0wo SequenceFlow_0mjjdia diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/GenericPnfSoftwareUpgrade.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/GenericPnfSoftwareUpgrade.bpmn index 9b8ce4a7b7..0303d7d1d5 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/GenericPnfSoftwareUpgrade.bpmn +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/GenericPnfSoftwareUpgrade.bpmn @@ -1,5 +1,5 @@ - + SequenceFlow_1ng4b6l @@ -138,6 +138,7 @@ pnfSwUpgrade.prepareCompletion(execution) + SequenceFlow_0ipc3nt SequenceFlow_0tle5zb diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ServiceLevelUpgrade.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ServiceLevelUpgrade.bpmn index 8ff1a1efec..34b8b76901 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ServiceLevelUpgrade.bpmn +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ServiceLevelUpgrade.bpmn @@ -1,5 +1,5 @@ - + Flow_0nrz340 @@ -54,13 +54,16 @@ Flow_1ptk2a3 - Flow_0l67uzl + Flow_05aa7gj Flow_0frhsd0 import org.onap.so.bpmn.infrastructure.scripts.* -def pnfSwUpgrade = new GenericPnfSoftwareUpgrade() -pnfSwUpgrade.prepareCompletion(execution) +def serviceLevelUpgrade = new ServiceLevelUpgrade() +serviceLevelUpgrade.prepareCompletion(execution) + + + Flow_0frhsd0 Flow_10jgbxm @@ -100,7 +103,7 @@ pnfSwUpgrade.prepareFalloutHandler(execution) - + #{execution.getVariable("ControllerStatus").equals("Success")} @@ -116,6 +119,7 @@ pnfSwUpgrade.prepareFalloutHandler(execution) + Flow_0rpnl02 Flow_0zjsp5x @@ -129,6 +133,7 @@ pnfSwUpgrade.prepareFalloutHandler(execution) + Flow_0g6gkgx Flow_1y3cptr @@ -175,6 +180,14 @@ pnfSwUpgrade.prepareFalloutHandler(execution) Flow_19tmp99 Flow_0g6gkgx + + Flow_0l67uzl + Flow_05aa7gj + import org.onap.so.bpmn.infrastructure.scripts.* +def pnfSwUpgrade = new GenericPnfSoftwareUpgrade() +pnfSwUpgrade.sendResponse(execution) + + @@ -223,8 +236,8 @@ pnfSwUpgrade.prepareFalloutHandler(execution) - - + + @@ -263,11 +276,9 @@ pnfSwUpgrade.prepareFalloutHandler(execution) - - - + - + @@ -304,81 +315,69 @@ pnfSwUpgrade.prepareFalloutHandler(execution) - - + + - - + + - - + + + + + + + + - + - - - + + + - - + + - - + + - - + + - - + + - - - - - - - - - - - - - - - - - - - - - - - + + - - + + - - + + - - + + - - + + + + + @@ -413,6 +412,27 @@ pnfSwUpgrade.prepareFalloutHandler(execution) + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-infrastructure-flows/src/test/java/org/onap/so/bpmn/infrastructure/process/ServiceLevelUpgradeTest.java b/bpmn/so-bpmn-infrastructure-flows/src/test/java/org/onap/so/bpmn/infrastructure/process/ServiceLevelUpgradeTest.java index 4322ff5bdf..7da3a2c81b 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/test/java/org/onap/so/bpmn/infrastructure/process/ServiceLevelUpgradeTest.java +++ b/bpmn/so-bpmn-infrastructure-flows/src/test/java/org/onap/so/bpmn/infrastructure/process/ServiceLevelUpgradeTest.java @@ -145,7 +145,7 @@ public class ServiceLevelUpgradeTest extends BaseBPMNTest { assertThat(pi).isEnded().hasPassedInOrder("Event_02mc8tr", "Activity_18vue7u", "Activity_09bqns0", "Activity_02vp5np", "Activity_0n17xou", "Gateway_1nr51kr", "Activity_0snmatn", "Activity_0e6w886", "Activity_1q4o9fx", "Gateway_02fectw", "Activity_1hp67qz", "Gateway_18ch73t", "Activity_0ft7fa2", - "Gateway_1vq11i7", "Activity_1n4rk7m", "Activity_1lz38px", "Event_12983th"); + "Gateway_1vq11i7", "Activity_0o2rrag", "Activity_1n4rk7m", "Activity_1lz38px", "Event_12983th"); List detailedMessages = grpcNettyServer.getDetailedMessages(); assertThat(detailedMessages.size() == 5); @@ -205,7 +205,7 @@ public class ServiceLevelUpgradeTest extends BaseBPMNTest { private void mockAai() { final String sIUrl = - "/business/customers/customer/5df8b6de-2083-11e7-93ae-92361f002676/service-subscriptions/service-subscription/pNF/service-instances/service-instance/ETE_Customer_807c7a02-249c-4db8-9fa9-bee973fe08ce"; + "/business/customers/customer/ETE_Customer_807c7a02-249c-4db8-9fa9-bee973fe08ce/service-subscriptions/service-subscription/pNF/service-instances/service-instance/5df8b6de-2083-11e7-93ae-92361f002676"; final String aaiPnfDemoEntry = FileUtil.readResourceFile("response/PnfDemo_aai.json"); final String aaiPnfDemo1Entry = FileUtil.readResourceFile("response/PnfDemo1_aai.json"); final String aaiServiceInstanceEntry = FileUtil.readResourceFile("response/Service_instance_aai.json"); -- cgit 1.2.3-korg