From 9d8d8d99489dc92951d9e587e8fdc8f048d53e26 Mon Sep 17 00:00:00 2001 From: rameshiyer27 Date: Wed, 29 Jul 2020 18:39:01 +0100 Subject: Refactor PNF names in BPMN workflows Issue-ID: SO-3105 Signed-off-by: zrrmmua Change-Id: I8cab1afa54ea8a1981fcddcf0c25f6f86bb14421 --- .../scripts/GenericPnfSoftwareUpgrade.groovy | 124 +++++++++++++++++++++ .../scripts/PNFSoftwareUpgrade.groovy | 124 --------------------- 2 files changed, 124 insertions(+), 124 deletions(-) create mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/GenericPnfSoftwareUpgrade.groovy delete mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/PNFSoftwareUpgrade.groovy (limited to 'bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap') diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/GenericPnfSoftwareUpgrade.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/GenericPnfSoftwareUpgrade.groovy new file mode 100644 index 0000000000..89902209a0 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/GenericPnfSoftwareUpgrade.groovy @@ -0,0 +1,124 @@ +/*- + * ============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.slf4j.Logger +import org.slf4j.LoggerFactory +import org.onap.so.bpmn.common.scripts.ExceptionUtil +import org.onap.so.bpmn.common.scripts.MsoUtils +import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor +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 static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.* + +class GenericPnfSoftwareUpgrade extends AbstractServiceTaskProcessor { + private static final Logger logger = LoggerFactory.getLogger(GenericPnfSoftwareUpgrade.class) + + ExceptionUtil exceptionUtil = new ExceptionUtil() + String prefix = "PnfSwUpgrade_" + + @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 PNF Software Upgrade for requestId: {}", requestId) + + String msoCompletionRequest = + """ + + ${MsoUtils.xmlEscape(requestId)} + UPDATE + VID + + PNF has been upgraded successfully. + PNF_SOFTWARE_UPGRADE + """ + String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest) + + execution.setVariable(prefix + "CompleteMsoProcessRequest", xmlMsoCompletionRequest) + + logger.debug("CompleteMsoProcessRequest of PNF Software Upgrade - " + "\n" + xmlMsoCompletionRequest) + } catch (Exception e) { + String msg = "Prepare Completion error for PNF software 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 PNF Software Upgrade for requestId: {}", requestId) + + 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 PNF Software Upgrade - " + "\n" + xmlFalloutHandlerRequest) + } catch (Exception e) { + String msg = "Prepare FalloutHandler error for PNF software upgrade - " + e.getMessage() + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg) + } + } +} diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/PNFSoftwareUpgrade.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/PNFSoftwareUpgrade.groovy deleted file mode 100644 index 8e7a4f727d..0000000000 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/PNFSoftwareUpgrade.groovy +++ /dev/null @@ -1,124 +0,0 @@ -/*- - * ============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.slf4j.Logger -import org.slf4j.LoggerFactory -import org.onap.so.bpmn.common.scripts.ExceptionUtil -import org.onap.so.bpmn.common.scripts.MsoUtils -import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor -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 static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.* - -class PNFSoftwareUpgrade extends AbstractServiceTaskProcessor { - private static final Logger logger = LoggerFactory.getLogger(PNFSoftwareUpgrade.class) - - ExceptionUtil exceptionUtil = new ExceptionUtil() - String prefix = "PnfSwUpgrade_" - - @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 PNF Software Upgrade for requestId: {}", requestId) - - String msoCompletionRequest = - """ - - ${MsoUtils.xmlEscape(requestId)} - UPDATE - VID - - PNF has been upgraded successfully. - PNF_SOFTWARE_UPGRADE - """ - String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest) - - execution.setVariable(prefix + "CompleteMsoProcessRequest", xmlMsoCompletionRequest) - - logger.debug("CompleteMsoProcessRequest of PNF Software Upgrade - " + "\n" + xmlMsoCompletionRequest) - } catch (Exception e) { - String msg = "Prepare Completion error for PNF software 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 PNF Software Upgrade for requestId: {}", requestId) - - 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 PNF Software Upgrade - " + "\n" + xmlFalloutHandlerRequest) - } catch (Exception e) { - String msg = "Prepare FalloutHandler error for PNF software upgrade - " + e.getMessage() - logger.error(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg) - } - } -} -- cgit 1.2.3-korg