From 4b23ea7fbe55fadd119a3534a578aa86e664ebd9 Mon Sep 17 00:00:00 2001 From: "Boslet, Cory" Date: Mon, 9 Dec 2019 08:49:08 -0500 Subject: refactor fallouthandler Created a new update method to allow accessibility from groovy Ignore test that do not function in groovy. Fixed typo and bug in request db client class Fixed failing junits for falloouthandler Add the request factory to the rest template so that patch works updated check payload keyword to check response Issue-ID: SO-2555 Signed-off-by: Benjamin, Max (mb388a) Change-Id: Iebfea31b659a02069bd6c59c09f025fdc6a99843 --- .../bpmn/common/scripts/CompleteMsoProcess.groovy | 375 ++++------------ .../so/bpmn/common/scripts/FalloutHandler.groovy | 472 +++++--------------- .../resources/subprocess/CompleteMsoProcess.bpmn | 376 ++-------------- .../main/resources/subprocess/FalloutHandler.bpmn | 486 ++------------------- .../common/scripts/CompleteMsoProcessTest.groovy | 214 ++++----- .../bpmn/common/scripts/FalloutHandlerTest.groovy | 333 ++++---------- 6 files changed, 436 insertions(+), 1820 deletions(-) (limited to 'bpmn/MSOCommonBPMN') diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CompleteMsoProcess.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CompleteMsoProcess.groovy index 7e1280729c..841fe9f50e 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CompleteMsoProcess.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CompleteMsoProcess.groovy @@ -9,9 +9,9 @@ * 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. @@ -25,295 +25,98 @@ package org.onap.so.bpmn.common.scripts import org.onap.so.logger.LoggingAnchor import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.delegate.DelegateExecution +import org.onap.so.db.request.beans.InfraActiveRequests +import org.onap.so.db.request.client.RequestsDbClient import org.onap.so.logger.ErrorCode import org.onap.so.logger.MessageEnum import org.slf4j.Logger import org.slf4j.LoggerFactory +import org.onap.so.bpmn.core.UrnPropertiesReader; public class CompleteMsoProcess extends AbstractServiceTaskProcessor { - private static final Logger logger = LoggerFactory.getLogger( CompleteMsoProcess.class); - - String Prefix="CMSO_" - ExceptionUtil exceptionUtil = new ExceptionUtil() - - // Complete MSO Request processing - public initializeProcessVariables(DelegateExecution execution){ - - def method = getClass().getSimpleName() + '.initializeProcessVariables(' +'execution=' + execution.getId() +')' - logger.trace('Entered ' + method) - try { - - /* Initialize all the process request variables in this block */ - execution.setVariable("prefix",Prefix) - execution.setVariable("CMSO_request_id","") - execution.setVariable("CMSO_notification-url","") - execution.setVariable("CMSO_mso-bpel-name","") - execution.setVariable("CMSO_request_action","") - execution.setVariable("CMSO_notification-url-Ok", false) - execution.setVariable("CMSO_request_id-Ok", false) - - //updateRequest Adapter process variables - execution.setVariable("CMSO_updateRequestResponse", "") - execution.setVariable("CMSO_updateRequestResponseCode", "") - execution.setVariable("CMSO_updateFinalNotifyAckStatusFailedPayload", "") - - //Set DB adapter variables here - execution.setVariable("CMSO_updateDBStatusToSuccessPayload", "") - execution.setVariable("CMSO_updateInfraRequestDBPayload", "") - execution.setVariable("CMSO_setUpdateDBstatustoSuccessPayload", "") - - //Auth variables - execution.setVariable("BasicAuthHeaderValue","") - - //Response variables - execution.setVariable("CompletionHandlerResponse","") - execution.setVariable("CMSO_ErrorResponse", null) - execution.setVariable("CMSO_ResponseCode", "") - - setSuccessIndicator(execution, false) - - } catch (BpmnError e) { - throw e; - } catch (Exception e) { - logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), 'Caught exception in' + - ' ' + method, "BPMN", ErrorCode.UnknownError.getValue(), "Exception is:\n" + e); - exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method) - } - - } - - public void preProcessRequest (DelegateExecution execution) { - - initializeProcessVariables(execution) - def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')' - // logger.trace("Started CompleteMsoProcess preProcessRequest Method "); - logger.trace('Entered ' + method) - - setBasicDBAuthHeader(execution, execution.getVariable('isDebugLogEnabled')) - - try { - def xml = execution.getVariable("CompleteMsoProcessRequest") - - logger.debug("CompleteMsoProcess Request: " + xml) - logger.debug("Incoming Request is: "+ xml) - - //mso-bpel-name from the incoming request - def msoBpelName = utils.getNodeText(xml,"mso-bpel-name") - execution.setVariable("CMSO_mso-bpel-name",msoBpelName) - - //Check the incoming request type - //Incoming request can be ACTIVE_REQUESTS (request-information node) or INFRA_ACTIVE_REQUESTS (request-info node) - if (utils.nodeExists(xml, "request-information")) { - execution.setVariable("CMSO_request_id-Ok", true) // Incoming request is for ACTIVE_REQUESTS - } - - //Check for rehome indicator - def rehomeIndicator = utils.getNodeText(xml,"rehomeDone") - execution.setVariable("rehomeDone", rehomeIndicator) - - //Check notification-url for the incoming request type - //ACTIVE_REQUESTS may have notificationurl node - //INFRA_ACTIVE_REQUESTS notificationurl node does not exist - def notificationurl = "" - if (utils.nodeExists(xml, "notification-url")) { - notificationurl = utils.getNodeText(xml,"notification-url") - if(notificationurl != null && !notificationurl.isEmpty()) { - execution.setVariable("CMSO_notification-url-Ok", true) - execution.setVariable("CMSO_notification-url",notificationurl) - } - } - - //Check request_id for the incoming request type - //For INFRA_ACTIVE_REQUESTS payload request-id IS optional (Not sure why this is option since req id is primary key ... also tried exe through SOAP UI to check if MSO code handles null like auto generated seq not it does not) - //For ACTIVE_REQUESTS payload request-id is NOT optional - def request_id = "" - if (utils.nodeExists(xml, "request-id")) { - execution.setVariable("CMSO_request_id",utils.getNodeText(xml,"request-id")) - } - - - // INFRA_ACTIVE_REQUESTS have "action" element ... mandatory - // ACTIVE_REQUEST have "request-action" ... mandatory - if (utils.nodeExists(xml, "request-action")) { - execution.setVariable("CMSO_request_action",utils.getNodeText(xml,"request-action")) - } else if (utils.nodeExists(xml, "action")) { - execution.setVariable("CMSO_request_action",utils.getNodeText(xml,"action")) - } - - //Check source for the incoming request type - //For INFRA_ACTIVE_REQUESTS payload source IS optional - //For ACTIVE_REQUESTS payload source is NOT optional - def source = "" - if (utils.nodeExists(xml, "source")) { - execution.setVariable("CMSO_source",utils.getNodeText(xml,"source")) - } - - logger.trace("--> " + execution.getVariable("")) - logger.trace("--> " + execution.getVariable("")) - - // set the DHV/Service Instantiation values if specified in the request - execution.setVariable("CMSO_is_srv_inst_req", String.valueOf("true".equals(utils.getNodeText(xml, "is-srv-inst-req")))) - logger.trace("--> " + execution.getVariable("")) - execution.setVariable("CMSO_is_json_content", String.valueOf("JSON".equals(utils.getNodeText(xml, "resp-content-type")))) - logger.trace("--> " + execution.getVariable("")) - execution.setVariable("CMSO_service_inst_id", utils.getNodeText(xml, "service-instance-id")) - logger.trace("--> " + execution.getVariable("")) - execution.setVariable("CMSO_start_time", utils.getNodeText(xml, "start-time")) - logger.trace("--> " + execution.getVariable("")) - // this variable is used by the camunda flow to set the Content-Type for the async response - if (execution.getVariable("CMSO_is_srv_inst_req").equals("true") && - execution.getVariable("CMSO_is_json_content").equals("true")) { - execution.setVariable("CMSO_content_type", "application/json") - } else { - execution.setVariable("CMSO_content_type", "text/xml") - } - - logger.trace('Exited ' + method) - } catch (BpmnError e) { - throw e; - } catch (Exception e) { - logger.debug("Exception Occured During PreProcessRequest: " + e); - exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in " + method) - } - } - - public void setUpdateDBstatustoSuccessPayload (DelegateExecution execution){ - - def method = getClass().getSimpleName() + '.setUpdateDBstatustoSuccessPayload(' +'execution=' + execution.getId() +')' - logger.trace('Entered ' + method) - - try { - - def xml = execution.getVariable("CompleteMsoProcessRequest") - - //Get statusMessage if exists - def statusMessage - if(utils.nodeExists(xml, "status-message")){ - statusMessage = utils.getNodeText(xml, "status-message") - }else{ - statusMessage = "Resource Completed Successfully" - } - - //Get instance Id if exist - String idXml = "" - if(utils.nodeExists(xml, "vnfId")){ - idXml = utils.getNodeXml(xml, "vnfId") - }else if(utils.nodeExists(xml, "networkId")){ - idXml = utils.getNodeXml(xml, "networkId") - }else if(utils.nodeExists(xml, "configurationId")){ - idXml = utils.getNodeXml(xml, "configurationId") - }else if(utils.nodeExists(xml, "serviceInstanceId")){ - idXml = utils.getNodeXml(xml, "serviceInstanceId") - }else if(utils.nodeExists(xml, "vfModuleId")){ - idXml = utils.getNodeXml(xml, "vfModuleId") - }else if(utils.nodeExists(xml, "volumeGroupId")){ - idXml = utils.getNodeXml(xml, "volumeGroupId") - }else{ - idXml = "" - } - idXml = utils.removeXmlPreamble(idXml) - idXml = utils.removeXmlNamespaces(idXml) - logger.debug("Incoming Instance Id Xml: " + idXml) - - String payload = """ - - - - - ${MsoUtils.xmlEscape(execution.getVariable("CMSO_request_id"))} - ${MsoUtils.xmlEscape(execution.getVariable("CMSO_mso-bpel-name"))} - ${MsoUtils.xmlEscape(statusMessage)} - COMPLETE - 100 - ${idXml} - - - """ - - execution.setVariable("CMSO_setUpdateDBstatustoSuccessPayload", payload) - logger.debug("Outgoing Update Mso Request Payload is: " + payload) - logger.debug("setUpdateDBstatustoSuccessPayload: " + payload) - - } catch (BpmnError e) { - throw e; - } catch (Exception e) { - logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), - 'Caught exception in ' + method, "BPMN", - ErrorCode.UnknownError.getValue(), "Exception is:\n" + e); - exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method) - } - logger.trace('Exited ' + method) - } - - public void buildDataError (DelegateExecution execution, String message) { - - def method = getClass().getSimpleName() + '.buildDataError(' +'execution=' + execution.getId() +')' - logger.trace('Entered ' + method) - try { - - String msoCompletionResponse = """ - - BPEL ${execution.getVariable("CMSO_mso-bpel-name")} FAILED - - """.trim() - - // Format Response - def xmlMsoCompletionResponse = utils.formatXml(msoCompletionResponse) - String buildMsoCompletionResponseAsString = xmlMsoCompletionResponse.drop(38).trim() - logger.debug("CompleteMsoProcess Response: " + buildMsoCompletionResponseAsString) - execution.setVariable("CompleteMsoProcessResponse", buildMsoCompletionResponseAsString) - logger.debug("@@ CompleteMsoProcess Response @@ " + "\n" + execution.getVariable("CompletionHandlerResponse")) - - exceptionUtil.buildAndThrowWorkflowException(execution, 500, message) - - } catch (BpmnError e) { - logger.debug("Rethrowing MSOWorkflowException") - throw e; - } catch (Exception e) { - logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), - 'Caught exception in ' + method, "BPMN", - ErrorCode.UnknownError.getValue(), "Exception is:\n" + e); - exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method) - } - - } - - public void postProcessResponse (DelegateExecution execution) { - - def method = getClass().getSimpleName() + '.postProcessResponse(' +'execution=' + execution.getId() +')' - logger.trace('Entered ' + method) - // logger.trace("Started CompleteMsoProcess PostProcessRequest Method "); - try { - - String msoCompletionResponse = """ - - BPEL ${execution.getVariable("CMSO_mso-bpel-name")} completed - - """.trim() - - // Format Response - def xmlMsoCompletionResponse = utils.formatXML(msoCompletionResponse) - String buildMsoCompletionResponseAsString = xmlMsoCompletionResponse.drop(38).trim() - // TODO: Should deprecate use of processKey+Response variable for the response. Will use "WorkflowResponse" instead - execution.setVariable("WorkflowResponse", buildMsoCompletionResponseAsString) - logger.debug("CompleteMsoProcess Response: " + buildMsoCompletionResponseAsString) - execution.setVariable("CompleteMsoProcessResponse", buildMsoCompletionResponseAsString) - execution.setVariable("CMSO_ResponseCode", "200") - - setSuccessIndicator(execution, true) - - logger.debug("@@ CompleteMsoProcess Response @@ " + "\n" + execution.getVariable("CompleteMsoProcessResponse")) - - logger.trace('Exited ' + method) - } catch (BpmnError e) { - throw e; - } catch (Exception e) { - logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), - 'Caught exception in ' + method, "BPMN", - ErrorCode.UnknownError.getValue(), "Exception is:\n" + e); - exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method) - } - } - + private static final Logger logger = LoggerFactory.getLogger(CompleteMsoProcess.class); + + String Prefix="CMSO_" + ExceptionUtil exceptionUtil = new ExceptionUtil() + + public void preProcessRequest (DelegateExecution execution) { + try { + def xml = execution.getVariable("CompleteMsoProcessRequest") + + logger.debug("CompleteMsoProcess Request: " + xml) + logger.debug("Incoming Request is: "+ xml) + + //mso-bpel-name from the incoming request + def msoBpelName = utils.getNodeText(xml,"mso-bpel-name") + execution.setVariable("CMSO_mso-bpel-name",msoBpelName) + + if (utils.nodeExists(xml, "request-information")) { + throw new BpmnError("500", "FalloutHandler subflow does not support this request type.") + } + + def request_id = "" + if (utils.nodeExists(xml, "request-id")) { + execution.setVariable("CMSO_request_id",utils.getNodeText(xml,"request-id")) + } + + } catch (BpmnError e) { + throw e; + } catch (Exception e) { + logger.debug("Exception Occured During PreProcessRequest: " + e); + exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in preprocess") + } + } + + public void updateInfraRequestDB (DelegateExecution execution){ + try { + + def xml = execution.getVariable("CompleteMsoProcessRequest") + + //Get statusMessage if exists + def statusMessage + if(utils.nodeExists(xml, "status-message")){ + statusMessage = utils.getNodeText(xml, "status-message") + }else{ + statusMessage = "Resource Completed Successfully" + } + + RequestsDbClient dbClient = getDbClient() + + InfraActiveRequests infraRequest = dbClient.getInfraActiveRequests(execution.getVariable("CMSO_request_id"), UrnPropertiesReader.getVariable("mso.adapters.requestDb.auth"), UrnPropertiesReader.getVariable("mso.adapters.requestDb.endpoint")) + if(infraRequest == null){ + infraRequest = new InfraActiveRequests(); + infraRequest.setRequestId(execution.getVariable("CMSO_request_id")) + } + infraRequest.setLastModifiedBy("BPMN") + infraRequest.setStatusMessage(statusMessage) + infraRequest.setRequestStatus("COMPLETED") + infraRequest.setProgress(100) + + if(utils.nodeExists(xml, "vnfId")){ + infraRequest.setVnfId(utils.getNodeText(xml, "vnfId")) + }else if(utils.nodeExists(xml, "networkId")){ + infraRequest.setNetworkId(utils.getNodeText(xml, "networkId")) + }else if(utils.nodeExists(xml, "configurationId")){ + infraRequest.setConfigurationId(utils.getNodeText(xml, "configurationId")) + }else if(utils.nodeExists(xml, "serviceInstanceId")){ + infraRequest.setServiceInstanceId(utils.getNodeText(xml, "serviceInstanceId")) + }else if(utils.nodeExists(xml, "vfModuleId")){ + infraRequest.setVfModuleId(utils.getNodeText(xml, "vfModuleId")) + }else if(utils.nodeExists(xml, "volumeGroupId")){ + infraRequest.setVolumeGroupId(utils.getNodeText(xml, "volumeGroupId")) + + } + + dbClient.updateInfraActiveRequests(infraRequest, UrnPropertiesReader.getVariable("mso.adapters.requestDb.auth"), UrnPropertiesReader.getVariable("mso.adapters.requestDb.endpoint")) + + } catch (Exception e) { + logger.error("Internal error while updating request db", e); + exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in update infra request db") + } + } + + protected RequestsDbClient getDbClient(){ + return new RequestsDbClient() + } } diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/FalloutHandler.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/FalloutHandler.groovy index ed849755b7..8306f33592 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/FalloutHandler.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/FalloutHandler.groovy @@ -9,9 +9,9 @@ * 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. @@ -24,376 +24,134 @@ package org.onap.so.bpmn.common.scripts import org.onap.so.logger.LoggingAnchor import org.onap.so.bpmn.core.UrnPropertiesReader +import org.onap.so.db.request.beans.InfraActiveRequests +import org.onap.so.db.request.client.RequestsDbClient import org.onap.so.logger.ErrorCode - +import org.onap.so.bpmn.core.UrnPropertiesReader; import java.text.SimpleDateFormat import org.apache.commons.lang3.* +import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.delegate.DelegateExecution import org.onap.so.logger.MessageEnum import org.slf4j.Logger import org.slf4j.LoggerFactory public class FalloutHandler extends AbstractServiceTaskProcessor { - private static final Logger logger = LoggerFactory.getLogger( FalloutHandler.class); - - String Prefix="FH_" - ExceptionUtil exceptionUtil = new ExceptionUtil() - - public initializeProcessVariables(DelegateExecution execution){ - def method = getClass().getSimpleName() + '.initializeProcessVariables(' +'execution=' + execution.getId() +')' - logger.trace('Entered ' + method) - - try { - execution.setVariable("prefix",Prefix) - - //These variables are form the input Message to the BPMN - execution.setVariable("FH_request_id","") - execution.setVariable("FH_request_action","") - execution.setVariable("FH_notification-url","") - execution.setVariable("FH_mso-bpel-name","") - execution.setVariable("FH_ErrorCode", "") - execution.setVariable("FH_ErrorMessage", "") - - execution.setVariable("FH_notification-url-Ok", false) - execution.setVariable("FH_request_id-Ok", false) - - //These variables are for Get Mso Aai Password Adapter - execution.setVariable("FH_deliveryStatus", true) - - //update Response Status to pending ...Adapter variables - execution.setVariable("FH_updateResponseStatusPayload", null) - execution.setVariable("FH_updateResponseStatusResponse", null) - - //update Request Gamma ...Adapter variables - execution.setVariable("FH_updateRequestGammaPayload", "") - execution.setVariable("FH_updateRequestGammaResponse", null) - execution.setVariable("FH_updateRequestGammaResponseCode", null) - - //update Request Infra ...Adapter variables - execution.setVariable("FH_updateRequestInfraPayload", "") - execution.setVariable("FH_updateRequestInfraResponse", null) - execution.setVariable("FH_updateRequestInfraResponseCode", null) - - //assign True to success variable - execution.setVariable("FH_success", true) - - //Set notify status to Failed variable - execution.setVariable("FH_NOTIFY_STATUS", "SUCCESS") - - //Set DB update variable - execution.setVariable("FH_updateRequestPayload", "") - execution.setVariable("FH_updateRequestResponse", null) - execution.setVariable("FH_updateRequestResponseCode", null) - - //Auth variables - execution.setVariable("BasicAuthHeaderValue","") - - //Parameter list - execution.setVariable("FH_parameterList", "") - - //Response variables - execution.setVariable("FalloutHandlerResponse","") - execution.setVariable("FH_ErrorResponse", null) - execution.setVariable("FH_ResponseCode", "") - - } catch (Exception e) { - logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), - 'Caught exception in ' + method, "BPMN", - ErrorCode.UnknownError.getValue(), "Exception is:\n" + e); - // exceptionUtil.buildWorkflowException(execution, 2000, "Internal Error - Occured in " + method) - } - } - - public void preProcessRequest (DelegateExecution execution) { - def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')' - logger.trace('Entered ' + method) - - // Initialize flow variables - initializeProcessVariables(execution) - setSuccessIndicator(execution, false) - - setBasicDBAuthHeader(execution, execution.getVariable('isDebugLogEnabled')) - - try { - def xml = execution.getVariable("FalloutHandlerRequest") - logger.debug(" XML --> " + xml) - logger.debug("FalloutHandler request: " + xml) - - //Check the incoming request type - //Incoming request can be ACTIVE_REQUESTS (request-information node) or INFRA_ACTIVE_REQUESTS (request-info node) - if (utils.nodeExists(xml, "request-information")) { - execution.setVariable("FH_request_id-Ok", true) // Incoming request is for ACTIVE_REQUESTS - } - - //Check notification-url for the incoming request type - //ACTIVE_REQUESTS may have notificationurl node - //INFRA_ACTIVE_REQUESTS notificationurl node does not exist - def notificationurl = "" - if (utils.nodeExists(xml, "notification-url")) { - notificationurl = utils.getNodeText(xml,"notification-url") - if(notificationurl != null && !notificationurl.isEmpty()) { - logger.debug("********** Incoming notification Url is: " + notificationurl); - execution.setVariable("FH_notification-url-Ok", true) - execution.setVariable("FH_notification-url",notificationurl) - } - } - - //Check request_id for the incoming request type - //For INFRA_ACTIVE_REQUESTS payload request-id IS optional (Not sure why this is option since req id is primary key ... also tried exe through SOAP UI to check if MSO code handles null like auto generated seq not it does not) - //For ACTIVE_REQUESTS payload request-id is NOT optional - def request_id = "" - if (utils.nodeExists(xml, "request-id")) { - execution.setVariable("FH_request_id",utils.getNodeText(xml,"request-id")) - } - logger.debug("FH_request_id: " + execution.getVariable("FH_request_id")) - - // INFRA_ACTIVE_REQUESTS have "action" element ... mandatory - // ACTIVE_REQUEST have "request-action" ... mandatory - if (utils.nodeExists(xml, "request-action")) { - execution.setVariable("FH_request_action",utils.getNodeText(xml,"request-action")) - } else if (utils.nodeExists(xml, "action")) { - execution.setVariable("FH_request_action",utils.getNodeText(xml,"action")) - } - - - //Check source for the incoming request type - //For INFRA_ACTIVE_REQUESTS payload source IS optional - //For ACTIVE_REQUESTS payload source is NOT optional - def source = "" - if (utils.nodeExists(xml, "source")) { - execution.setVariable("FH_source",utils.getNodeText(xml,"source")) - } - - //Check if ErrorCode node exists. If yes, initialize it from request xml, if no, it will stay with defaulf value already set in initializeProcessVariables() method above. - def errorCode = "" - if (utils.nodeExists(xml, "ErrorCode")) { - errorCode = utils.getNodeText(xml,"ErrorCode") - if(errorCode != null && !errorCode.isEmpty()) { - execution.setVariable("FH_ErrorCode", errorCode) - } - } - logger.debug("FH_ErrorCode: " + errorCode) - - //Check if ErrorMessage node exists. If yes, initialize it from request xml, if no, it will stay with defaulf value already set in initializeProcessVariables() method above. - def errorMessage = "" - if (utils.nodeExists(xml, "ErrorMessage")) { - errorCode = utils.getNodeText(xml,"ErrorMessage") - if(errorCode != null && !errorCode.isEmpty()) { - errorCode = errorCode - execution.setVariable("FH_ErrorMessage", errorCode) - } - } - - //Check for Parameter List - if (utils.nodeExists(xml, "parameter-list")) { - def parameterList = utils.getNodeXml(xml, "parameter-list", false) - execution.setVariable("FH_parameterList", parameterList) - } - - logger.trace("--> " + execution.getVariable("")) - logger.debug("FH_request_id-OK --> " + execution.getVariable("FH_request_id-Ok")) - - // set the DHV/Service Instantiation values if specified in the request - execution.setVariable("FH_is_srv_inst_req", String.valueOf("true".equals(utils.getNodeText(xml, "is-srv-inst-req")))) - logger.trace("--> " + execution.getVariable("")) - execution.setVariable("FH_is_json_content", String.valueOf("JSON".equals(utils.getNodeText(xml, "resp-content-type")))) - logger.trace("--> " + execution.getVariable("")) - execution.setVariable("FH_service_inst_id", utils.getNodeText(xml, "service-instance-id")) - logger.trace("--> " + execution.getVariable("")) - execution.setVariable("FH_start_time", utils.getNodeText(xml, "start-time")) - logger.trace("--> " + execution.getVariable("")) - // this variable is used by the camunda flow to set the Content-Type for the async response - if (execution.getVariable("FH_is_srv_inst_req").equals("true") && - execution.getVariable("FH_is_json_content").equals("true")) { - execution.setVariable("FH_content_type", "application/json") - } else { - execution.setVariable("FH_content_type", "text/xml") - } - } catch (Exception e) { - logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), - 'Caught exception in ' + method, "BPMN", - ErrorCode.UnknownError.getValue(), "Exception is:\n" + e); - // exceptionUtil.buildWorkflowException(execution, 2000, "Internal Error - Occured in" + method) - } - - logger.debug("OUTOF --> Initialize Variables Fallout Handler #########"); - } - - public String updateRequestPayload (DelegateExecution execution){ - def method = getClass().getSimpleName() + '.updateRequestPayload(' +'execution=' + execution.getId() +')' - logger.trace('Entered ' + method) - - try { - String payload = """ - - - - - ${MsoUtils.xmlEscape(execution.getVariable("FH_request_id"))} - BPEL - ${MsoUtils.xmlEscape(execution.getVariable("FH_ErrorMessage"))} - ${MsoUtils.xmlEscape(execution.getVariable("FH_ErrorCode"))} - FAILED - ${MsoUtils.xmlEscape(execution.getVariable("FH_NOTIFY_STATUS"))} - - - - """ - - logger.debug("updateRequestPayload: " + payload) - execution.setVariable("FH_updateRequestPayload", payload) - return execution.getVariable("FH_updateRequestPayload") - } catch (Exception e) { - logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), - 'Caught exception in ' + method, "BPMN", - ErrorCode.UnknownError.getValue(), "Exception is:\n" + e); - // exceptionUtil.buildWorkflowException(execution, 2000, "Internal Error - Occured in " + method) - } - } - - public String updateRequestInfraPayload (DelegateExecution execution){ - def method = getClass().getSimpleName() + '.updateRequestInfraPayload(' +'execution=' + execution.getId() +')' - logger.trace('Entered ' + method) - - try { - String payload = """ - - - - - ${MsoUtils.xmlEscape(execution.getVariable("FH_request_id"))} - BPEL - ${MsoUtils.xmlEscape(execution.getVariable("FH_ErrorMessage"))} - FAILED - 100 - - - - """ - - execution.setVariable("FH_updateRequestInfraPayload", payload) - logger.debug("updateRequestInfraPayload: " + payload) - return execution.getVariable("FH_updateRequestInfraPayload") - } catch (Exception e) { - logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), - 'Caught exception in ' + method, "BPMN", - ErrorCode.UnknownError.getValue(), "Exception is:\n" + e); - // exceptionUtil.buildWorkflowException(execution, 2000, "Internal Error - Occured in " + method) - } - } - - public String updateRequestGammaPayload (DelegateExecution execution){ - def method = getClass().getSimpleName() + '.updateRequestGammaPayload(' +'execution=' + execution.getId() +')' - logger.trace('Entered ' + method) - - try { - String payload = """ - - - - - ${MsoUtils.xmlEscape(execution.getVariable("FH_request_id"))} - BPEL - ${MsoUtils.xmlEscape(execution.getVariable("FH_ErrorMessage"))} - ${MsoUtils.xmlEscape(execution.getVariable("FH_ErrorCode"))} - FAILED - - - - """ - - execution.setVariable("FH_updateRequestGammaPayload", payload) - logger.debug("updateRequestGammaPayload: " + payload) - return execution.getVariable("FH_updateRequestGammaPayload") - } catch (Exception e) { - logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), - 'Caught exception in ' + method, "BPMN", - ErrorCode.UnknownError.getValue(), "Exception is:\n" + e); - // exceptionUtil.buildWorkflowException(execution, 2000, "Internal Error - Occured in " + method) - } - } - - public String updateResponseStatusPayload (DelegateExecution execution){ - def method = getClass().getSimpleName() + '.updateResponseStatusPayload(' +'execution=' + execution.getId() +')' - logger.trace('Entered ' + method) - - try { - String payload = """ - - - - - ${MsoUtils.xmlEscape(execution.getVariable("FH_request_id"))} - BPEL - SENDING_FINAL_NOTIFY - - - - """ - - execution.setVariable("FH_updateResponseStatusPayload", payload) - logger.debug("updateResponseStatusPayload: " + payload) - return execution.getVariable("FH_updateResponseStatusPayload") - } catch (Exception e) { - logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), - 'Caught exception in ' + method, "BPMN", - ErrorCode.UnknownError.getValue(), "Exception is:\n" + e); - // exceptionUtil.buildWorkflowException(execution, 2000, "Internal Error - Occured in " + method) - } - } - - public void buildDBWorkflowException(DelegateExecution execution, String responseCodeVariable) { - def method = getClass().getSimpleName() + '.buildDBWorkflowException(' + - 'execution=' + execution.getId() + - ', responseCodeVariable=' + responseCodeVariable + ')' - logger.trace('Entered ' + method) - - try { - def responseCode = execution.getVariable(responseCodeVariable) - // If the HTTP response code was null, it means a connection fault occurred (a java exception) - def errorMessage = responseCode == null ? "Could not connect to DB Adapter" : "DB Adapter returned ${responseCode} response" - def errorCode = responseCode == null ? 7000 : 7020 - // exceptionUtil.buildWorkflowException(execution, errorCode, errorMessage) - } catch (Exception e) { - logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), - 'Caught exception in ' + method, "BPMN", - ErrorCode.UnknownError.getValue(), "Exception is:\n" + e); - // exceptionUtil.buildWorkflowException(execution, 2000, "Internal Error - Occured in " + method) - } - } - - /** - * Used to create a workflow response in success and failure cases. - */ - public void postProcessResponse (DelegateExecution execution) { - def method = getClass().getSimpleName() + '.postProcessResponse(' +'execution=' + execution.getId() +')' - logger.trace('Entered ' + method) - - try { - Boolean success = (Boolean) execution.getVariable("FH_success") - String out = success ? "Fallout Handler Succeeded" : "Fallout Handler Failed"; - - String falloutHandlerResponse = """ + private static final Logger logger = LoggerFactory.getLogger(FalloutHandler.class); + + ExceptionUtil exceptionUtil = new ExceptionUtil() + + + public void preProcessRequest (DelegateExecution execution) { + def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')' + logger.trace('Entered ' + method) + + execution.setVariable("FH_success", true) + + try { + def xml = execution.getVariable("FalloutHandlerRequest") + logger.debug("FalloutHandler request: " + xml) + + if (utils.nodeExists(xml, "request-information")) { + throw new BpmnError("500", "FalloutHandler subflow does not support this request type.") + } + + //Check request_id for the incoming request type + //For INFRA_ACTIVE_REQUESTS payload request-id IS optional (Not sure why this is option since req id is primary key ... also tried exe through SOAP UI to check if MSO code handles null like auto generated seq not it does not) + //For ACTIVE_REQUESTS payload request-id is NOT optional + def request_id = "" + if (utils.nodeExists(xml, "request-id")) { + execution.setVariable("FH_request_id",utils.getNodeText(xml,"request-id")) + } + logger.debug("FH_request_id: " + execution.getVariable("FH_request_id")) + + //Check if ErrorCode node exists. If yes, initialize it from request xml, if no, it will stay with defaulf value already set in initializeProcessVariables() method above. + def errorCode = "500" + if (utils.nodeExists(xml, "ErrorCode")) { + if(errorCode != null && !errorCode.isEmpty()) { + errorCode = utils.getNodeText(xml,"ErrorCode") + } + } + execution.setVariable("FH_ErrorCode", errorCode) + + //Check if ErrorMessage node exists. If yes, initialize it from request xml, if no, it will stay with defaulf value already set in initializeProcessVariables() method above. + String errorMessage = "Internal Error occured in MSO, unable to determine error message" + if (utils.nodeExists(xml, "ErrorMessage")) { + if(errorCode != null && !errorCode.isEmpty()) { + errorMessage = utils.getNodeText(xml,"ErrorMessage") + } + } + execution.setVariable("FH_ErrorMessage", errorMessage) + + //Check for Parameter List + if (utils.nodeExists(xml, "parameter-list")) { + def parameterList = utils.getNodeXml(xml, "parameter-list", false) + execution.setVariable("FH_parameterList", parameterList) + } + + + } catch (Exception e) { + logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), + 'Caught exception in ' + method, "BPMN", + ErrorCode.UnknownError.getValue(), "Exception is:\n" + e); + // exceptionUtil.buildWorkflowException(execution, 2000, "Internal Error - Occured in" + method) + } + + } + + public String updateInfraRequestDB(DelegateExecution execution){ + try { + RequestsDbClient client = getDbClient() + InfraActiveRequests infraRequest = client.getInfraActiveRequests(execution.getVariable("FH_request_id"), UrnPropertiesReader.getVariable("mso.adapters.requestDb.auth"), UrnPropertiesReader.getVariable("mso.adapters.requestDb.endpoint")) + if(infraRequest == null){ + infraRequest = new InfraActiveRequests(); + infraRequest.setRequestId(execution.getVariable("CMSO_request_id")) + } + infraRequest.setLastModifiedBy("BPMN") + infraRequest.setStatusMessage(MsoUtils.xmlEscape(execution.getVariable("FH_ErrorMessage"))) + infraRequest.setRequestStatus("FAILED") + infraRequest.setProgress(100) + client.updateInfraActiveRequests(infraRequest, UrnPropertiesReader.getVariable("mso.adapters.requestDb.auth"), UrnPropertiesReader.getVariable("mso.adapters.requestDb.endpoint")) + } catch (Exception e) { + execution.setVariable("FH_success", false) + logger.error("Exception Occured while updating infra request db", e) + } + } + + /** + * Used to create a workflow response in success and failure cases. + */ + public void postProcessResponse (DelegateExecution execution) { + def method = getClass().getSimpleName() + '.postProcessResponse(' +'execution=' + execution.getId() +')' + logger.trace('Entered ' + method) + + try { + Boolean success = (Boolean) execution.getVariable("FH_success") + String out = success ? "Fallout Handler Succeeded" : "Fallout Handler Failed"; + + String falloutHandlerResponse = """ ${MsoUtils.xmlEscape(out)} """ - falloutHandlerResponse = utils.formatXml(falloutHandlerResponse) - logger.debug("FalloutHandler Response: " + falloutHandlerResponse); + falloutHandlerResponse = utils.formatXml(falloutHandlerResponse) + + execution.setVariable("FalloutHandlerResponse", falloutHandlerResponse) + execution.setVariable("WorkflowResponse", falloutHandlerResponse) + execution.setVariable("FH_ResponseCode", success ? "200" : "500") + setSuccessIndicator(execution, success) - execution.setVariable("FalloutHandlerResponse", falloutHandlerResponse) - execution.setVariable("WorkflowResponse", falloutHandlerResponse) - execution.setVariable("FH_ResponseCode", success ? "200" : "500") - setSuccessIndicator(execution, success) + logger.debug("FalloutHandlerResponse =\n" + falloutHandlerResponse) + } catch (Exception e) { + logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), + 'Caught exception in ' + method, "BPMN", + ErrorCode.UnknownError.getValue(), "Exception is:\n" + e); + } + } - logger.debug("FalloutHandlerResponse =\n" + falloutHandlerResponse) - } catch (Exception e) { - // Do NOT throw WorkflowException! - logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), - 'Caught exception in ' + method, "BPMN", - ErrorCode.UnknownError.getValue(), "Exception is:\n" + e); - } - } + protected RequestsDbClient getDbClient(){ + return new RequestsDbClient() + } } diff --git a/bpmn/MSOCommonBPMN/src/main/resources/subprocess/CompleteMsoProcess.bpmn b/bpmn/MSOCommonBPMN/src/main/resources/subprocess/CompleteMsoProcess.bpmn index 63c867f3c7..72bed98a5f 100644 --- a/bpmn/MSOCommonBPMN/src/main/resources/subprocess/CompleteMsoProcess.bpmn +++ b/bpmn/MSOCommonBPMN/src/main/resources/subprocess/CompleteMsoProcess.bpmn @@ -1,5 +1,5 @@ - + SequenceFlow_18 @@ -10,8 +10,8 @@ preProcessRequestData.preProcessRequest(execution) ]]> - - + + SequenceFlow_18 @@ -34,136 +34,18 @@ preProcessRequestData.preProcessRequest(execution) - - SequenceFlow_9 - - - - SequenceFlow_127i45q - SequenceFlow_10 + + SequenceFlow_2 + SequenceFlow_1oes9qv - - - - - - - - - - - application/soap+xml - #{BasicAuthHeaderValueDB} - #{CMSO_request_id} - - - POST - - ${statusCode} - - soap-http-connector - - - SequenceFlow_10 - SequenceFlow_6 - - - - SequenceFlow_1 - SequenceFlow_0mipf25 - SequenceFlow_9 - Build Error Message @@@@" -//println "CMSO_updateRequestResponse IS --> " + execution.getVariable("CMSO_updateRequestResponse") -import org.onap.so.bpmn.common.scripts.* -def buildDataErrorMessage = new CompleteMsoProcess() -buildDataErrorMessage.buildDataError(execution, "Complete MSO -- Update DB status to SUCCESS -- Failed")]]> +completeMsoProcess.updateInfraRequestDB(execution)]]> - - - SequenceFlow_6 - SequenceFlow_1 - SequenceFlow_03z8rch - - - - SequenceFlow_0mipf25 - - - SequenceFlow_1pzb94j + SequenceFlow_1oes9qv - - - - - - - - - - SequenceFlow_81 - SequenceFlow_13qdn1s - - - - SequenceFlow_067veaf - SequenceFlow_81 - SequenceFlow_1dptl35 - - - SequenceFlow_1dptl35 - SequenceFlow_13qdn1s - SequenceFlow_1hpvwyt - - - - - - - SequenceFlow_2 - SequenceFlow_067veaf - SequenceFlow_0xe5zck - - - SequenceFlow_12he9a1 - SequenceFlow_1hpvwyt - SequenceFlow_1g8ig3h - - - - - SequenceFlow_0xe5zck - SequenceFlow_127i45q - SequenceFlow_1ffkc0n - - - - - - - SequenceFlow_03z8rch - SequenceFlow_1ffkc0n - SequenceFlow_12he9a1 - - - - - - - - - SequenceFlow_1g8ig3h - SequenceFlow_1pzb94j - Complete MSO Process Done SUCCESSFULLY" -import org.onap.so.bpmn.common.scripts.* -def postProcessResponseData = new CompleteMsoProcess() -postProcessResponseData.postProcessResponse(execution) -println "CompleteMsoProcess Response -->" + "\n" + execution.getVariable("CompletionHandlerResponse")]]> - - + @@ -171,254 +53,64 @@ println "CompleteMsoProcess Response -->" + "\n" + execution.getVariable("Comple - + - + - + - - - + + + - + - - + + - + - - - - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - + diff --git a/bpmn/MSOCommonBPMN/src/main/resources/subprocess/FalloutHandler.bpmn b/bpmn/MSOCommonBPMN/src/main/resources/subprocess/FalloutHandler.bpmn index 6914e7575f..0c7a8ac063 100644 --- a/bpmn/MSOCommonBPMN/src/main/resources/subprocess/FalloutHandler.bpmn +++ b/bpmn/MSOCommonBPMN/src/main/resources/subprocess/FalloutHandler.bpmn @@ -1,178 +1,37 @@ - + - - SequenceFlow_12 - SequenceFlow_2 - SequenceFlow_24 - - - - - SequenceFlow_2 - SequenceFlow_3 - SequenceFlow_23 - - - - - SequenceFlow_10 - SequenceFlow_12 + SequenceFlow_1kx7ea5 - - + SequenceFlow_10 - - SequenceFlow_37 - SequenceFlow_38 - SequenceFlow_8 - - - SequenceFlow_8 + SequenceFlow_1u8shdz SequenceFlow_9 - - SequenceFlow_23 - SequenceFlow_0m7gwor - SequenceFlow_38 - - - - SequenceFlow_24 - SequenceFlow_25 - SequenceFlow_26 - - - - - - - - - - - POST - - - application/soap+xml - #{BasicAuthHeaderValueDB} - #{FH_request_id} - - - - update Request Gamma" -import org.onap.so.bpmn.common.scripts.* -def updateRequestGamma= new FalloutHandler() -return updateRequestGamma.updateRequestGammaPayload(execution)]]> - - - ${statusCode} - - soap-http-connector - - - SequenceFlow_25 - SequenceFlow_29 - - - - SequenceFlow_72 - - - - SequenceFlow_35 - SequenceFlow_36 - SequenceFlow_37 - - - + SequenceFlow_9 - - - SequenceFlow_72 - SequenceFlow_31 - SequenceFlow_79 + + SequenceFlow_1kx7ea5 + SequenceFlow_1u8shdz +falloutHandler.updateInfraRequestDB(execution)]]> - - - SequenceFlow_29 - SequenceFlow_31 - SequenceFlow_35 - - - - - - - SequenceFlow_32 - SequenceFlow_80 - SequenceFlow_73 - - - - - - - - - POST - - - application/soap+xml - #{BasicAuthHeaderValueDB} - #{FH_request_id} - - - - update Request Infra" -import org.onap.so.bpmn.common.scripts.* -def updateRequestInfra= new FalloutHandler() -return updateRequestInfra.updateRequestInfraPayload(execution)]]> - - - ${statusCode} - - soap-http-connector - - - SequenceFlow_26 - SequenceFlow_30 - - - - SequenceFlow_30 - SequenceFlow_32 - SequenceFlow_36 - - - - - - - SequenceFlow_80 - - - SequenceFlow_1ko8ggw @@ -200,345 +59,94 @@ execution.setVariable("FH_WorkflowException", wfe)]]> - - SequenceFlow_73 - - - - SequenceFlow_79 - - - - - - - - - - - SequenceFlow_3 - SequenceFlow_0m7gwor - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - + + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - + - + - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - + - - - - + - - - - - - - - - - - - - - - - + - + - - - - - - - - + + + - + - - - - - + + + + - + - - - + + + - + - - - + + + - + - - - diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CompleteMsoProcessTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CompleteMsoProcessTest.groovy index 99c351c465..119159f458 100644 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CompleteMsoProcessTest.groovy +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CompleteMsoProcessTest.groovy @@ -1,22 +1,22 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= - */ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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.common.scripts @@ -24,13 +24,17 @@ import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.delegate.DelegateExecution import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity import org.junit.Before +import org.junit.Ignore import org.junit.Test import org.junit.runner.RunWith import org.mockito.ArgumentCaptor +import org.mockito.Mock import org.mockito.MockitoAnnotations +import org.mockito.Spy import org.mockito.runners.MockitoJUnitRunner import org.onap.so.bpmn.core.WorkflowException - +import org.onap.so.db.request.beans.InfraActiveRequests +import org.onap.so.db.request.client.RequestsDbClient import static org.assertj.core.api.Assertions.assertThat import static org.assertj.core.api.Assertions.assertThatThrownBy import static org.mockito.ArgumentMatchers.eq @@ -38,27 +42,20 @@ import static org.mockito.Mockito.* @RunWith(MockitoJUnitRunner.class) class CompleteMsoProcessTest { - @Before - public void init() { - MockitoAnnotations.initMocks(this) - } - - private String completeMsoProcessRequest = """ - - - uCPE1020_STUW105_5002 - Layer3ServiceActivateRequest - COMPLETE - OMX - http://localhost:28090/CCD/StatusNotification - 10205000 - 1 - - UCPELayer3ServiceActivateV1 - - """ - - private String completeMsoNetworkProcessRequest = """ + + @Mock + RequestsDbClient requestsDbClient; + + @Spy + CompleteMsoProcess completeMsoProcess; + + + @Before + public void init() { + MockitoAnnotations.initMocks(this) + } + + private String completeMsoNetworkProcessRequest = """ @@ -71,104 +68,39 @@ class CompleteMsoProcessTest { BPMN Network action: CREATE """ - @Test - public void testPreProcessRequest() { - - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - when(mockExecution.getVariable("CompleteMsoProcessRequest")).thenReturn(completeMsoProcessRequest) - when(mockExecution.getVariable("mso.adapters.db.auth")).thenReturn("5E12ACACBD552A415E081E29F2C4772F9835792A51C766CCFDD7433DB5220B59969CB2798C"); - when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7"); - - CompleteMsoProcess completeMsoProcess = new CompleteMsoProcess() - completeMsoProcess.preProcessRequest(mockExecution) - - /* Initialize all the process request variables in this block */ - verify(mockExecution).setVariable("prefix","CMSO_") - //verify(mockExecution).setVariable("getLayer3ServiceDetailsV1Response","") - verify(mockExecution).setVariable("CMSO_request_id","") - verify(mockExecution).setVariable("CMSO_notification-url","") - verify(mockExecution).setVariable("CMSO_mso-bpel-name","") - verify(mockExecution).setVariable("CMSO_request_action","") - - verify(mockExecution).setVariable("CMSO_notification-url-Ok", false) - verify(mockExecution).setVariable("CMSO_request_id-Ok", false) - - //updateRequest Adapter process variables - verify(mockExecution).setVariable("CMSO_updateRequestResponse", "") - verify(mockExecution).setVariable("CMSO_updateRequestResponseCode", "") - verify(mockExecution).setVariable("CMSO_updateFinalNotifyAckStatusFailedPayload", "") - - //Set DB adapter variables here - verify(mockExecution).setVariable("CMSO_updateDBStatusToSuccessPayload", "") - verify(mockExecution).setVariable("CMSO_updateInfraRequestDBPayload", "") - verify(mockExecution).setVariable("CMSO_setUpdateDBstatustoSuccessPayload", "") - - //Auth variables - verify(mockExecution).setVariable("BasicAuthHeaderValue","") - - //Response variables - verify(mockExecution).setVariable("CompletionHandlerResponse","") - verify(mockExecution).setVariable("CMSO_ErrorResponse", null) - verify(mockExecution).setVariable("CMSO_ResponseCode", "") - - verify(mockExecution).setVariable("CMSO_notification-url-Ok",true) - verify(mockExecution).setVariable("CMSO_request_id-Ok",true) - verify(mockExecution).setVariable("CMSO_notification-url","http://localhost:28090/CCD/StatusNotification") - verify(mockExecution).setVariable("CMSO_request_id","uCPE1020_STUW105_5002") - verify(mockExecution).setVariable("CMSO_request_action","Layer3ServiceActivateRequest") - verify(mockExecution).setVariable("CMSO_source","OMX") - - } - - private String setUpdateDBstatustoSuccessPayload = """ - - - - - testReqId - BPEL - Resource Completed Successfully - COMPLETE - 100 - bd631913-cfc6-488b-ba22-6b98504f703d - - - """ - - @Test - public void testsetUpdateDBstatustoSuccessPayload(){ - - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - when(mockExecution.getVariable("CMSO_request_id")).thenReturn("testReqId") - when(mockExecution.getVariable("CMSO_mso-bpel-name")).thenReturn("BPEL") - when(mockExecution.getVariable("mso.adapters.db.auth")).thenReturn("757A94191D685FD2092AC1490730A4FC"); - when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7"); - when(mockExecution.getVariable("CompleteMsoProcessRequest")).thenReturn(completeMsoNetworkProcessRequest); - - CompleteMsoProcess completeMsoProcess = new CompleteMsoProcess() - completeMsoProcess.setUpdateDBstatustoSuccessPayload(mockExecution) - - verify(mockExecution).setVariable("CMSO_setUpdateDBstatustoSuccessPayload",setUpdateDBstatustoSuccessPayload) - } - - private String msoCompletionResponse = """onse xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"> - BPEL BPEL-NAME FAILED -""" - - - @Test - void postProcessResponse_successful() { - DelegateExecution mockExecution = mock(DelegateExecution.class) - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") - when(mockExecution.getVariable("CMSO_mso-bpel-name")).thenReturn("mso-bpel-test") - new CompleteMsoProcess().postProcessResponse(mockExecution) - - String expectedResponse = "\n" + - " BPEL mso-bpel-test completed\n" + - "" - - verify(mockExecution).setVariable("WorkflowResponse", expectedResponse) - verify(mockExecution).setVariable("CompleteMsoProcessResponse", expectedResponse) - verify(mockExecution).setVariable("CMSO_ResponseCode", "200") - } + @Test + public void testPreProcessRequest() { + + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getVariable("CompleteMsoProcessRequest")).thenReturn(completeMsoNetworkProcessRequest) + + completeMsoProcess.preProcessRequest(mockExecution) + + verify(mockExecution).setVariable("CMSO_request_id", "bd631913-cfc6-488b-ba22-6b98504f703d") + } + + + @Test + public void testUpdateInfraRequestDB(){ + + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getVariable("CMSO_request_id")).thenReturn("testReqId") + when(mockExecution.getVariable("CompleteMsoProcessRequest")).thenReturn(completeMsoNetworkProcessRequest); + when(completeMsoProcess.getDbClient()).thenReturn(requestsDbClient) + completeMsoProcess.updateInfraRequestDB(mockExecution) + + InfraActiveRequests request = new InfraActiveRequests() + request.setRequestId("testReqId") + + completeMsoProcess.updateInfraRequestDB(mockExecution) + + request.setRequestStatus("COMPLETED") + request.setStatusMessage("Resource Completed Successfully") + request.setProgress(100) + request.setLastModifiedBy("BPMN") + request.setNetworkId("bd631913-cfc6-488b-ba22-6b98504f703d") + + + verify(requestsDbClient, times(2)).updateInfraActiveRequests(request, null, null) + } } \ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/FalloutHandlerTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/FalloutHandlerTest.groovy index 25f62a6555..6cae293971 100644 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/FalloutHandlerTest.groovy +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/FalloutHandlerTest.groovy @@ -1,22 +1,22 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= - */ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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.common.scripts @@ -29,31 +29,41 @@ import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.ArgumentCaptor; +import org.mockito.Mock import org.mockito.MockitoAnnotations +import org.mockito.Spy import org.mockito.runners.MockitoJUnitRunner import org.onap.so.bpmn.common.scripts.MsoUtils; +import org.onap.so.db.request.beans.InfraActiveRequests +import org.onap.so.db.request.client.RequestsDbClient import org.onap.so.bpmn.common.scripts.FalloutHandler; @RunWith(MockitoJUnitRunner.class) class FalloutHandlerTest { - - public MsoUtils utils = new MsoUtils() - - @Before - public void init() { - MockitoAnnotations.initMocks(this) - } - private String falloutHandlerRequest = """ + public MsoUtils utils = new MsoUtils() + + @Spy + FalloutHandler falloutHandler = new FalloutHandler() + + @Mock + RequestsDbClient requestsDbClient; + + @Before + public void init() { + MockitoAnnotations.initMocks(this) + } + + private String falloutHandlerRequest = """ - + uCPE1020_STUW105_5002 Layer3ServiceActivateRequest CANCEL OMX 10205000 1 - + Some Error Message - Fallout Handler Some Error Code - Fallout Handler @@ -62,251 +72,64 @@ class FalloutHandlerTest { """ - private String falloutHandlerResponse = """ + private String falloutHandlerResponse = """ Fallout Handler Failed """ - @Test - public void testPreProcessRequest() { - - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - - when(mockExecution.getVariable("FalloutHandlerRequest")).thenReturn(falloutHandlerRequest) - when(mockExecution.getVariable("mso.adapters.db.auth")).thenReturn("5E12ACACBD552A415E081E29F2C4772F9835792A51C766CCFDD7433DB5220B59969CB2798C"); - when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7"); - - FalloutHandler falloutHandler = new FalloutHandler() - falloutHandler.preProcessRequest(mockExecution) - - /* Initialize all the process request variables in this block */ - verify(mockExecution).setVariable("prefix","FH_") - //verify(mockExecution).setVariable("getLayer3ServiceDetailsV1Response","") + @Test + public void testPreProcessRequest() { - //These variables are form the input Message to the BPMN - verify(mockExecution).setVariable("FH_request_id","") - verify(mockExecution).setVariable("FH_request_action","") - verify(mockExecution).setVariable("FH_notification-url","") - verify(mockExecution).setVariable("FH_mso-bpel-name","") - verify(mockExecution).setVariable("FH_ErrorCode", "") - verify(mockExecution).setVariable("FH_ErrorMessage", "") + ExecutionEntity mockExecution = mock(ExecutionEntity.class) - verify(mockExecution).setVariable("FH_notification-url-Ok", false) - verify(mockExecution).setVariable("FH_request_id-Ok", false) + when(mockExecution.getVariable("FalloutHandlerRequest")).thenReturn(falloutHandlerRequest) - //These variables are for Get Mso Aai Password Adapter - verify(mockExecution).setVariable("FH_deliveryStatus", true) + falloutHandler.preProcessRequest(mockExecution) - //update Response Status to pending ...Adapter variables - verify(mockExecution).setVariable("FH_updateResponseStatusPayload", null) - verify(mockExecution).setVariable("FH_updateResponseStatusResponse", null) + verify(mockExecution).setVariable("FH_success", true) + verify(mockExecution).setVariable("FH_request_id","uCPE1020_STUW105_5002") + verify(mockExecution).setVariable("FH_ErrorCode","Some Error Code - Fallout Handler") + verify(mockExecution).setVariable("FH_ErrorMessage","Some Error Message - Fallout Handler") + } - //update Request Gamma ...Adapter variables - verify(mockExecution).setVariable("FH_updateRequestGammaPayload", "") - verify(mockExecution).setVariable("FH_updateRequestGammaResponse", null) - verify(mockExecution).setVariable("FH_updateRequestGammaResponseCode", null) + @Test + public void testpostProcessResponse(){ - //update Request Infra ...Adapter variables - verify(mockExecution).setVariable("FH_updateRequestInfraPayload", "") - verify(mockExecution).setVariable("FH_updateRequestInfraResponse", null) - verify(mockExecution).setVariable("FH_updateRequestInfraResponseCode", null) + ExecutionEntity mockExecution = mock(ExecutionEntity.class) - //assign False to success variable - verify(mockExecution).setVariable("FH_success", true) + when(mockExecution.getVariable("FH_success")).thenReturn(false) - //Set notify status to Failed variable - verify(mockExecution).setVariable("FH_NOTIFY_STATUS", "SUCCESS") + falloutHandler.postProcessResponse(mockExecution) - //Set DB update variable - verify(mockExecution).setVariable("FH_updateRequestPayload", "") - verify(mockExecution).setVariable("FH_updateRequestResponse", null) - verify(mockExecution).setVariable("FH_updateRequestResponseCode", null) + // Capture the arguments to setVariable + ArgumentCaptor captor1 = ArgumentCaptor.forClass(String.class); + ArgumentCaptor captor2 = ArgumentCaptor.forClass(String.class); - //Auth variables - verify(mockExecution).setVariable("BasicAuthHeaderValue","") + verify(mockExecution, times(4)).setVariable(captor1.capture(), captor2.capture()) + List arg2List = captor2.getAllValues() + String payloadResponseActual = arg2List.get(1) - //Response variables - verify(mockExecution).setVariable("FalloutHandlerResponse","") - verify(mockExecution).setVariable("FH_ErrorResponse", null) - verify(mockExecution).setVariable("FH_ResponseCode", "") + assertEquals(falloutHandlerResponse.replaceAll("\\s+", ""), payloadResponseActual.replaceAll("\\s+", "")) - verify(mockExecution).setVariable("FH_request_id-Ok",true) - verify(mockExecution).setVariable("FH_request_id","uCPE1020_STUW105_5002") - verify(mockExecution).setVariable("FH_request_action","Layer3ServiceActivateRequest") - verify(mockExecution).setVariable("FH_source","OMX") - verify(mockExecution).setVariable("FH_ErrorCode","Some Error Code - Fallout Handler") - verify(mockExecution).setVariable("FH_ErrorMessage","Some Error Message - Fallout Handler") + verify(mockExecution).setVariable("FH_ResponseCode","500") + } - } - @Test - public void testpostProcessResponse(){ + @Test + public void testUpdateInfraRequestDB(){ - ExecutionEntity mockExecution = mock(ExecutionEntity.class) + ExecutionEntity mockExecution = mock(ExecutionEntity.class) + when(mockExecution.getVariable("FH_request_id")).thenReturn("testReqId") + when(mockExecution.getVariable("FH_ErrorMessage")).thenReturn("ErrorMessage") + when(falloutHandler.getDbClient()).thenReturn(requestsDbClient) - when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") - when(mockExecution.getVariable("FH_success")).thenReturn(false) - - FalloutHandler falloutHandler = new FalloutHandler() - falloutHandler.postProcessResponse(mockExecution) - - // Capture the arguments to setVariable - ArgumentCaptor captor1 = ArgumentCaptor.forClass(String.class); - ArgumentCaptor captor2 = ArgumentCaptor.forClass(String.class); - - verify(mockExecution, times(4)).setVariable(captor1.capture(), captor2.capture()) - List arg2List = captor2.getAllValues() - String payloadResponseActual = arg2List.get(1) - - assertEquals(falloutHandlerResponse.replaceAll("\\s+", ""), payloadResponseActual.replaceAll("\\s+", "")) - - verify(mockExecution).setVariable("FH_ResponseCode","500") - } - - private String updateRequestPayload = """ - - - - - testReqId - BPEL - ErrorMessage - ErrorCode - FAILED - NotifyStatus - - - - """ - - @Test - public void testupdateRequestPayload(){ - - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - when(mockExecution.getVariable("FH_request_id")).thenReturn("testReqId") - when(mockExecution.getVariable("FH_ErrorMessage")).thenReturn("ErrorMessage") - when(mockExecution.getVariable("FH_ErrorCode")).thenReturn("ErrorCode") - when(mockExecution.getVariable("FH_NOTIFY_STATUS")).thenReturn("NotifyStatus") - - FalloutHandler falloutHandler = new FalloutHandler() - falloutHandler.updateRequestPayload(mockExecution) - - // Capture the arguments to setVariable - ArgumentCaptor captor1 = ArgumentCaptor.forClass(String.class); - ArgumentCaptor captor2 = ArgumentCaptor.forClass(String.class); - - verify(mockExecution, times(1)).setVariable(captor1.capture(), captor2.capture()) - List arg2List = captor2.getAllValues() - String payloadRequestActual = arg2List.get(0) - - assertEquals(updateRequestPayload.replaceAll("\\s+", ""), payloadRequestActual.replaceAll("\\s+", "")) - } - - private String updateRequestInfraPayload = """ - - - - - testReqId - BPEL - ErrorMessage - FAILED - 100 - - - - """ - - @Test - public void testupdateRequestInfraPayload(){ - - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - when(mockExecution.getVariable("FH_request_id")).thenReturn("testReqId") - when(mockExecution.getVariable("FH_ErrorMessage")).thenReturn("ErrorMessage") - - FalloutHandler falloutHandler = new FalloutHandler() - falloutHandler.updateRequestInfraPayload(mockExecution) - - // Capture the arguments to setVariable - ArgumentCaptor captor1 = ArgumentCaptor.forClass(String.class); - ArgumentCaptor captor2 = ArgumentCaptor.forClass(String.class); - - verify(mockExecution, times(1)).setVariable(captor1.capture(), captor2.capture()) - List arg2List = captor2.getAllValues() - String payloadRequestActual = arg2List.get(0) - - assertEquals(updateRequestInfraPayload.replaceAll("\\s+", ""), payloadRequestActual.replaceAll("\\s+", "")) - } - - private String updateRequestGammaPayload = """ - - - - - testReqId - BPEL - ErrorMessage - ErrorCode - FAILED - - - - """ - - @Test - public void testupdateRequestGammaPayload(){ - - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - when(mockExecution.getVariable("FH_request_id")).thenReturn("testReqId") - when(mockExecution.getVariable("FH_ErrorMessage")).thenReturn("ErrorMessage") - when(mockExecution.getVariable("FH_ErrorCode")).thenReturn("ErrorCode") - when(mockExecution.getVariable("mso.default.adapter.namespace")).thenReturn("http://org.onap.so"); - - FalloutHandler falloutHandler = new FalloutHandler() - falloutHandler.updateRequestGammaPayload(mockExecution) - - // Capture the arguments to setVariable - ArgumentCaptor captor1 = ArgumentCaptor.forClass(String.class); - ArgumentCaptor captor2 = ArgumentCaptor.forClass(String.class); - - verify(mockExecution, times(1)).setVariable(captor1.capture(), captor2.capture()) - List arg2List = captor2.getAllValues() - String payloadRequestActual = arg2List.get(0) - - assertEquals(updateRequestGammaPayload.replaceAll("\\s+", ""), payloadRequestActual.replaceAll("\\s+", "")) - } - - - String updateResponseStatusPayload = """ - - - - - testReqId - BPEL - SENDING_FINAL_NOTIFY - - - - """ - - @Test - public void testupdateResponseStatusPayload(){ - - ExecutionEntity mockExecution = mock(ExecutionEntity.class) - when(mockExecution.getVariable("FH_request_id")).thenReturn("testReqId") + falloutHandler.updateInfraRequestDB(mockExecution) - FalloutHandler falloutHandler = new FalloutHandler() - falloutHandler.updateResponseStatusPayload(mockExecution) - - // Capture the arguments to setVariable - ArgumentCaptor captor1 = ArgumentCaptor.forClass(String.class); - ArgumentCaptor captor2 = ArgumentCaptor.forClass(String.class); - - verify(mockExecution, times(1)).setVariable(captor1.capture(), captor2.capture()) - List arg2List = captor2.getAllValues() - String payloadResponseActual = arg2List.get(0) - - assertEquals(updateResponseStatusPayload.replaceAll("\\s+", ""), payloadResponseActual.replaceAll("\\s+", "")) - } + InfraActiveRequests infraRequest = new InfraActiveRequests(); + infraRequest.setLastModifiedBy("BPMN") + infraRequest.setStatusMessage("ErrorMessage") + infraRequest.setRequestStatus("FAILED") + infraRequest.setProgress(100) + verify(requestsDbClient, times(1)).updateInfraActiveRequests(infraRequest, null, null) + } } \ No newline at end of file -- cgit 1.2.3-korg