-/*-
- * ============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.openecomp.mso.bpmn.infrastructure.scripts;
-
-import groovy.json.JsonSlurper
-import groovy.json.JsonOutput
-
-import org.camunda.bpm.engine.delegate.BpmnError
-import org.camunda.bpm.engine.delegate.DelegateExecution
-import org.apache.commons.lang3.*
-import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor;
-import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil;
-import org.openecomp.mso.bpmn.common.scripts.NetworkUtils;
-import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils;
-import org.openecomp.mso.bpmn.common.scripts.VidUtils;
-import org.openecomp.mso.bpmn.core.RollbackData
-import org.openecomp.mso.bpmn.core.WorkflowException
-import org.openecomp.mso.bpmn.core.json.JsonUtils
-
-public class CreateVfModuleInfra extends AbstractServiceTaskProcessor {
-
- ExceptionUtil exceptionUtil = new ExceptionUtil()
- JsonUtils jsonUtil = new JsonUtils()
-
- /**
- * Validates the request message and sets up the workflow.
- * @param execution the execution
- */
- public void preProcessRequest(DelegateExecution execution) {
- def method = getClass().getSimpleName() + '.preProcessRequest(' +
- 'execution=' + execution.getId() +
- ')'
- def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
- logDebug('Entered ' + method, isDebugLogEnabled)
-
- execution.setVariable("CVFMI_sentSyncResponse", false)
-
- def prefix = 'CVFMI_'
- logDebug('Entered 1' + method, isDebugLogEnabled)
- execution.setVariable('prefix', prefix)
- logDebug('Entered 2' + method, isDebugLogEnabled)
- execution.setVariable("isVidRequest", "false")
-
- logDebug("Set variables", isDebugLogEnabled)
-
- def rollbackData = execution.getVariable("RollbackData")
- if (rollbackData == null) {
- rollbackData = new RollbackData()
- }
- execution.setVariable("RollbackData", rollbackData)
-
- logDebug("Set rollback data", isDebugLogEnabled)
- def incomingRequest = execution.getVariable('bpmnRequest')
-
- utils.log("DEBUG", "Incoming Infra Request: " + incomingRequest, isDebugLogEnabled)
- utils.logAudit("CreateVfModule Infra incoming Request: " + incomingRequest)
-
- setBasicDBAuthHeader(execution, isDebugLogEnabled)
-
- // check if request is xml or json
- try {
- def jsonSlurper = new JsonSlurper()
- def jsonOutput = new JsonOutput()
- Map reqMap = jsonSlurper.parseText(incomingRequest)
- utils.log("DEBUG", " Request is in JSON format.", isDebugLogEnabled)
-
- def serviceInstanceId = execution.getVariable('serviceInstanceId')
- def vnfId = execution.getVariable('vnfId')
-
- execution.setVariable(prefix + 'serviceInstanceId', serviceInstanceId)
- execution.setVariable(prefix+'vnfId', vnfId)
- execution.setVariable("isVidRequest", "true")
-
- def vnfName = ''
- def asdcServiceModelVersion = ''
- def serviceModelInfo = null
- def vnfModelInfo = null
-
- def relatedInstanceList = reqMap.requestDetails?.relatedInstanceList
-
- if (relatedInstanceList != null) {
- relatedInstanceList.each {
- if (it.relatedInstance.modelInfo?.modelType == 'service') {
- asdcServiceModelVersion = it.relatedInstance.modelInfo?.modelVersion
- serviceModelInfo = jsonOutput.toJson(it.relatedInstance.modelInfo)
-
- }
- if (it.relatedInstance.modelInfo.modelType == 'vnf') {
- vnfName = it.relatedInstance.instanceName ?: ''
- vnfModelInfo = jsonOutput.toJson(it.relatedInstance.modelInfo)
- }
- }
- }
-
- execution.setVariable(prefix + 'vnfName', vnfName)
- execution.setVariable(prefix + 'asdcServiceModelVersion', asdcServiceModelVersion)
- execution.setVariable(prefix + 'serviceModelInfo', serviceModelInfo)
- execution.setVariable(prefix + 'vnfModelInfo', vnfModelInfo)
-
-
- def vnfType = execution.getVariable('vnfType')
- execution.setVariable(prefix + 'vnfType', vnfType)
- def vfModuleId = execution.getVariable('vfModuleId')
- execution.setVariable(prefix + 'vfModuleId', vfModuleId)
- def volumeGroupId = execution.getVariable('volumeGroupId')
- execution.setVariable(prefix + 'volumeGroupId', volumeGroupId)
- def userParams = reqMap.requestDetails?.requestParameters?.userParams
-
- Map<String, String> userParamsMap = [:]
- if (userParams != null) {
- userParams.each { userParam ->
- userParamsMap.put(userParam.name, jsonOutput.toJson(userParam.value).toString())
- }
- }
-
- utils.log("DEBUG", 'Processed user params: ' + userParamsMap, isDebugLogEnabled)
-
- execution.setVariable(prefix + 'vfModuleInputParams', userParamsMap)
-
- def isBaseVfModule = "false"
- if (execution.getVariable('isBaseVfModule') == true) {
- isBaseVfModule = "true"
- }
-
- execution.setVariable(prefix + 'isBaseVfModule', isBaseVfModule)
-
- def requestId = execution.getVariable("mso-request-id")
- execution.setVariable(prefix + 'requestId', requestId)
-
- def vfModuleModelInfo = jsonOutput.toJson(reqMap.requestDetails?.modelInfo)
- execution.setVariable(prefix + 'vfModuleModelInfo', vfModuleModelInfo)
-
- def suppressRollback = reqMap.requestDetails?.requestInfo?.suppressRollback
-
-
- def backoutOnFailure = ""
- if(suppressRollback != null){
- if ( suppressRollback == true) {
- backoutOnFailure = "false"
- } else if ( suppressRollback == false) {
- backoutOnFailure = "true"
- }
- }
-
- execution.setVariable('disableRollback', suppressRollback)
-
- def vfModuleName = reqMap.requestDetails?.requestInfo?.instanceName ?: null
- execution.setVariable(prefix + 'vfModuleName', vfModuleName)
-
- def serviceId = reqMap.requestDetails?.requestParameters?.serviceId ?: ''
- execution.setVariable(prefix + 'serviceId', serviceId)
-
- def usePreload = reqMap.requestDetails?.requestParameters?.usePreload
- execution.setVariable(prefix + 'usePreload', usePreload)
-
- // This is aLaCarte flow, so aLaCarte flag is always on
- execution.setVariable(prefix + 'aLaCarte', true)
-
- def cloudConfiguration = reqMap.requestDetails?.cloudConfiguration
- def lcpCloudRegionId = cloudConfiguration.lcpCloudRegionId
- execution.setVariable(prefix + 'lcpCloudRegionId', lcpCloudRegionId)
- def tenantId = cloudConfiguration.tenantId
- execution.setVariable(prefix + 'tenantId', tenantId)
-
- def globalSubscriberId = reqMap.requestDetails?.subscriberInfo?.globalSubscriberId ?: ''
- execution.setVariable(prefix + 'globalSubscriberId', globalSubscriberId)
-
- execution.setVariable(prefix + 'sdncVersion', '1702')
-
- execution.setVariable("CreateVfModuleInfraSuccessIndicator", false)
- execution.setVariable("RollbackCompleted", false)
-
- execution.setVariable("isDebugLogEnabled", isDebugLogEnabled)
-
-
- def source = reqMap.requestDetails?.requestInfo?.source
- execution.setVariable("CVFMI_source", source)
-
- //For Completion Handler & Fallout Handler
- String requestInfo =
- """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
- <request-id>${requestId}</request-id>
- <action>CREATE</action>
- <source>${source}</source>
- </request-info>"""
-
- execution.setVariable("CVFMI_requestInfo", requestInfo)
-
- //backoutOnFailure
-
- execution.setVariable("CVFMI_originalWorkflowException", null)
-
-
- def newVfModuleId = UUID.randomUUID().toString()
- execution.setVariable("newVfModuleId", newVfModuleId)
- execution.setVariable(prefix + 'vfModuleId', newVfModuleId)
-
- logDebug('RequestInfo: ' + execution.getVariable("CVFMI_requestInfo"), isDebugLogEnabled)
-
- logDebug('rollbackEnabled: ' + execution.getVariable("CVFMI_rollbackEnabled"), isDebugLogEnabled)
-
- logDebug('Exited ' + method, isDebugLogEnabled)
- } catch (BpmnError bpmnError) {
- throw bpmnError
- }
- catch(groovy.json.JsonException je) {
- utils.log("DEBUG", " Request is not in JSON format.", isDebugLogEnabled)
- exceptionUtil.buildAndThrowWorkflowException(execution, 400, "Internal Error - During PreProcessRequest")
- }
- catch(Exception e) {
- String restFaultMessage = e.getMessage()
- //execution.setVariable("CVFMODVOL2_RESTFault", restFaultMessage)
- //execution.setVariable("CVFMODVOL2_isDataOk", false)
- utils.log("ERROR", " Exception Encountered - " + "\n" + restFaultMessage, isDebugLogEnabled)
- exceptionUtil.buildAndThrowWorkflowException(execution, 400, "Internal Error - During PreProcessRequest")
- }
-
- }
-
- /**
- * Validates a workflow response.
- * @param execution the execution
- * @param responseVar the execution variable in which the response is stored
- * @param responseCodeVar the execution variable in which the response code is stored
- * @param errorResponseVar the execution variable in which the error response is stored
- */
- public void validateWorkflowResponse(DelegateExecution execution, String responseVar,
- String responseCodeVar, String errorResponseVar) {
- SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
- sdncAdapterUtils.validateSDNCResponse(execution, responseVar, responseCodeVar, errorResponseVar)
- }
-
-
- /**
- * Sends the empty, synchronous response back to the API Handler.
- * @param execution the execution
- */
- public void sendResponse(DelegateExecution execution) {
- def method = getClass().getSimpleName() + '.sendResponse(' +
- 'execution=' + execution.getId() +
- ')'
- def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
- logDebug('Entered ' + method, isDebugLogEnabled)
-
- try {
- def requestInfo = execution.getVariable('CVFMI_requestInfo')
- def requestId = execution.getVariable('CVFMI_requestId')
- def source = execution.getVariable('CVFMI_source')
-
- // RESTResponse (for API Handler (APIH) Reply Task)
- def newVfModuleId = execution.getVariable("newVfModuleId")
- String synchResponse = """{"requestReferences":{"instanceId":"${newVfModuleId}","requestId":"${requestId}"}}""".trim()
-
- sendWorkflowResponse(execution, 200, synchResponse)
-
- execution.setVariable("CVFMI_sentSyncResponse", true)
- utils.logAudit("CreateVfModule Infra Response: " + synchResponse)
- logDebug('Exited ' + method, isDebugLogEnabled)
- } catch (BpmnError e) {
- throw e;
- } catch (Exception e) {
- logError('Caught exception in ' + method, e)
- exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in sendResponse(): ' + e.getMessage())
- }
- }
-
- /**
- *
- * @param execution the execution
- */
- public void postProcessResponse(DelegateExecution execution){
- def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
-
- utils.log("DEBUG", " ======== STARTED PostProcessResponse Process ======== ", isDebugEnabled)
- try{
- def requestInfo = execution.getVariable("CVFMI_requestInfo")
- def action = utils.getNodeText1(requestInfo, "action")
-
- utils.log("DEBUG", "requestInfo is: " + requestInfo, isDebugEnabled)
- utils.log("DEBUG", "action is: " + action, isDebugEnabled)
-
- String payload =
- """ <aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
- xmlns:ns="http://org.openecomp/mso/request/types/v1"
- xmlns:ns8="http://org.openecomp/mso/workflow/schema/v1">
- <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
- ${requestInfo}
- </request-info>
- <ns8:status-message>Vf Module has been created successfully.</ns8:status-message>
- <ns8:mso-bpel-name>BPMN</ns8:mso-bpel-name>
- </aetgt:MsoCompletionRequest>"""
-
- payload = utils.formatXml(payload)
- execution.setVariable("CVFMI_SuccessFlag", true)
- execution.setVariable("CVFMI_msoCompletionRequest", payload)
- utils.logAudit("CreateVfModuleInfra completion request: " + payload)
- utils.log("DEBUG", "Outgoing MsoCompletionRequest: \n" + payload, isDebugEnabled)
-
- }catch(Exception e){
- utils.log("ERROR", "Exception Occured Processing PostProcessResponse. Exception is:\n" + e, isDebugEnabled)
- execution.setVariable("CVFMI_ErrorResponse", "Error Occured during PostProcessResponse Method:\n" + e.getMessage())
- }
- utils.log("DEBUG", "======== COMPLETED PostProcessResponse Process ======== ", isDebugEnabled)
- }
-
-
-
-
-
- /**
- * Validates the request, request id and service instance id. If a problem is found,
- * a WorkflowException is generated and an MSOWorkflowException event is thrown. This
- * method also sets up the log context for the workflow.
- * @param execution the execution
- * @return the validated request
- */
- public String validateInfraRequest(DelegateExecution execution) {
- def method = getClass().getSimpleName() + '.validateInfraRequest(' +
- 'execution=' + execution.getId() +
- ')'
- def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
- logDebug('Entered ' + method, isDebugLogEnabled)
-
- String processKey = getProcessKey(execution);
- def prefix = execution.getVariable("prefix")
-
- if (prefix == null) {
- exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " prefix is null")
- }
-
- try {
- def request = execution.getVariable(prefix + 'Request')
-
- if (request == null) {
- request = execution.getVariable(processKey + 'Request')
-
- if (request == null) {
- request = execution.getVariable('bpmnRequest')
- }
-
- setVariable(execution, processKey + 'Request', null);
- setVariable(execution, 'bpmnRequest', null);
- setVariable(execution, prefix + 'Request', request);
- }
-
- if (request == null) {
- exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " request is null")
- }
-
- /*
-
- def requestId = execution.getVariable("mso-request-id")
-
- if (requestId == null) {
- exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " request has no mso-request-id")
- }
-
- setVariable(execution, prefix + 'requestId', requestId)
-
- def serviceInstanceId = execution.getVariable("mso-service-instance-id")
-
- if (serviceInstanceId == null) {
- exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " request message has no mso-service-instance-id")
- }
-
- utils.logContext(requestId, serviceInstanceId)
- */
- utils.logAudit("CreateVfModule incoming request: " + request)
- logDebug('Incoming message: ' + System.lineSeparator() + request, isDebugLogEnabled)
- logDebug('Exited ' + method, isDebugLogEnabled)
- return request
- } catch (BpmnError e) {
- throw e;
- } catch (Exception e) {
- logError('Caught exception in ' + method, e)
- exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Invalid Message")
- }
- }
-
- public void prepareUpdateInfraRequest(DelegateExecution execution){
- def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
-
- utils.log("DEBUG", " ======== STARTED prepareUpdateInfraRequest Process ======== ", isDebugEnabled)
- try{
-
-
- String requestInfo = execution.getVariable("CVFMI_requestInfo")
- def aicCloudRegion = execution.getVariable("CVFMI_lcpCloudRegionId")
- def tenantId = execution.getVariable("CVFMI_tenantId")
- def requestId = utils.getNodeText1(requestInfo, "request-id")
- def vnfId = execution.getVariable("CVFMI_vnfId")
- def vfModuleId = execution.getVariable("CVFMI_vfModuleId")
- // vfModuleName may be generated by DoCreateVfModule subprocess if it is not specified on the input
- def vfModuleName = execution.getVariable("CVFMI_vfModuleName")
-
- def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")
- execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
- utils.log("DEBUG", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)
-
- String payload =
- """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
- xmlns:ns="http://org.openecomp.mso/requestsdb">
- <soapenv:Header/>
- <soapenv:Body>
- <ns:updateInfraRequest xmlns:ns="http://org.openecomp.mso/requestsdb">
- <requestId>${requestId}</requestId>
- <lastModifiedBy>BPMN</lastModifiedBy>
- <statusMessage>VF Module successfully created</statusMessage>
- <responseBody></responseBody>
- <requestStatus>COMPLETE</requestStatus>
- <progress>100</progress>
- <vnfOutputs><vnf-outputs xmlns="http://org.openecomp/mso/infra/vnf-request/v1" xmlns:aetgt="http://org.openecomp/mso/infra/vnf-request/v1" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd"><vnf-id>${vnfId}</vnf-id><vf-module-id>${vfModuleId}</vf-module-id></vnf-outputs></vnfOutputs>
- <vfModuleId>${vfModuleId}</vfModuleId>
- <vfModuleName>${vfModuleName}</vfModuleName>
- </ns:updateInfraRequest>
- </soapenv:Body>
- </soapenv:Envelope>"""
-
- payload = utils.formatXml(payload)
- execution.setVariable("CVFMI_updateInfraRequest", payload)
- utils.log("DEBUG", "Outgoing UpdateInfraRequest: \n" + payload, isDebugEnabled)
- utils.logAudit("CreateVfModuleInfra Outgoing UpdateInfra Request: " + payload)
-
- }catch(Exception e){
- utils.log("ERROR", "Exception Occured Processing prepareUpdateInfraRequest. Exception is:\n" + e, isDebugEnabled)
- execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during prepareUpdateInfraRequest Method:\n" + e.getMessage())
- }
- utils.log("DEBUG", "======== COMPLETED prepareUpdateInfraRequest Process ======== ", isDebugEnabled)
- }
-
- /**
- * Builds a "FalloutHandler" request and stores it in the specified execution variable.
- *
- * @param execution the execution
- * @param resultVar the execution variable in which the result will be stored
- */
- public void falloutHandlerPrep(DelegateExecution execution, String resultVar) {
- def method = getClass().getSimpleName() + '.falloutHandlerPrep(' +
- 'execution=' + execution.getId() +
- ', resultVar=' + resultVar +
- ')'
- def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
- logDebug('Entered ' + method, isDebugLogEnabled)
-
-
- try {
- def WorkflowException workflowException = execution.getVariable("WorkflowException")
- def requestInformation = execution.getVariable("CVFMI_requestInfo")
- def errorResponseCode = workflowException.getErrorCode()
- def errorResponseMsg = workflowException.getErrorMessage()
- def encErrorResponseMsg = ""
- if (errorResponseMsg != null) {
- encErrorResponseMsg = errorResponseMsg.replace("&", "&").replace("<", "<").replace(">", ">")
- }
-
- String content = """
- <aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
- xmlns:reqtype="http://org.openecomp/mso/request/types/v1"
- xmlns:msoservtypes="http://org.openecomp/mso/request/types/v1"
- xmlns:structuredtypes="http://org.openecomp/mso/structured/types/v1">
- ${requestInformation}
- <aetgt:WorkflowException>
- <aetgt:ErrorMessage>${encErrorResponseMsg}</aetgt:ErrorMessage>
- <aetgt:ErrorCode>${errorResponseCode}</aetgt:ErrorCode>
- </aetgt:WorkflowException>
- </aetgt:FalloutHandlerRequest>
- """
-
- logDebug("CONTENT before translation: " + content, isDebugLogEnabled)
- content = utils.formatXml(content)
- logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)
- utils.logAudit("CreateVfModuleInfra FallOutHander Request: " + content)
- execution.setVariable(resultVar, content)
-
- logDebug('Exited ' + method, isDebugLogEnabled)
- } catch (BpmnError e) {
- throw e;
- } catch (Exception e) {
- logError('Caught exception in ' + method, e)
- exceptionUtil.buildWorkflowException(execution, 2000, 'Internal Error')
- }
- }
-
- public void logAndSaveOriginalException(DelegateExecution execution) {
- def method = getClass().getSimpleName() + '.validateRollbackResponse(' +
- 'execution=' + execution.getId() +
- ')'
- def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
- logDebug('Entered ' + method, isDebugLogEnabled)
-
- logWorkflowException(execution, 'CreateVfModuleInfra caught an event')
- saveWorkflowException(execution, 'CVFMI_originalWorkflowException')
- }
-
- public void validateRollbackResponse(DelegateExecution execution) {
- def method = getClass().getSimpleName() + '.validateRollbackResponse(' +
- 'execution=' + execution.getId() +
- ')'
- def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
- logDebug('Entered ' + method, isDebugLogEnabled)
-
- def originalException = execution.getVariable("CVFMI_originalWorkflowException")
- execution.setVariable("WorkflowException", originalException)
-
- execution.setVariable("RollbackCompleted", true)
-
- }
-
- public void sendErrorResponse(DelegateExecution execution){
- def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
-
- utils.log("DEBUG", " *** STARTED CreateVfModulenfra sendErrorResponse Process *** ", isDebugEnabled)
- try {
- def sentSyncResponse = execution.getVariable("CVFMI_sentSyncResponse")
- if(sentSyncResponse == false){
- WorkflowException wfex = execution.getVariable("WorkflowException")
- String response = exceptionUtil.buildErrorResponseXml(wfex)
-
- utils.logAudit(response)
- sendWorkflowResponse(execution, 500, response)
- }else{
- utils.log("DEBUG", "Not Sending Error Response. Sync Response Already Sent", isDebugEnabled)
- }
-
- } catch (Exception ex) {
- utils.log("DEBUG", "Error Occured in CreateVfModuleInfra sendErrorResponse Process " + ex.getMessage(), isDebugEnabled)
- exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVfModuleInfra sendErrorResponse Process")
-
- }
- utils.log("DEBUG", "*** COMPLETED CreateVfModuleInfra sendErrorResponse Process ***", isDebugEnabled)
- }
-
-
-}
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP - SO\r
+ * ================================================================================\r
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.openecomp.mso.bpmn.infrastructure.scripts;\r
+\r
+import groovy.json.JsonSlurper\r
+import groovy.json.JsonOutput\r
+\r
+import javax.xml.parsers.DocumentBuilder\r
+import javax.xml.parsers.DocumentBuilderFactory\r
+\r
+import org.w3c.dom.Document\r
+import org.w3c.dom.Element\r
+import org.w3c.dom.Node\r
+import org.w3c.dom.NodeList\r
+import org.xml.sax.InputSource\r
+\r
+import org.camunda.bpm.engine.delegate.BpmnError\r
+import org.camunda.bpm.engine.delegate.DelegateExecution\r
+import org.onap.appc.client.lcm.model.Action\r
+import org.apache.commons.lang3.*\r
+import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor;\r
+import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil;\r
+import org.openecomp.mso.bpmn.common.scripts.NetworkUtils;\r
+import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils;\r
+import org.openecomp.mso.bpmn.common.scripts.VidUtils;\r
+import org.openecomp.mso.bpmn.core.RollbackData\r
+import org.openecomp.mso.bpmn.core.WorkflowException\r
+import org.openecomp.mso.bpmn.core.json.JsonUtils\r
+import org.openecomp.mso.bpmn.infrastructure.aai.AAICreateResources;\r
+import org.onap.aai.domain.yang.v12.GenericVnf;\r
+\r
+public class CreateVfModuleInfra extends AbstractServiceTaskProcessor {\r
+\r
+ ExceptionUtil exceptionUtil = new ExceptionUtil()\r
+ JsonUtils jsonUtil = new JsonUtils()\r
+ \r
+ private AbstractServiceTaskProcessor taskProcessor\r
+ \r
+ public SDNCAdapterUtils(AbstractServiceTaskProcessor taskProcessor) {\r
+ this.taskProcessor = taskProcessor\r
+ } \r
+\r
+ /**\r
+ * Validates the request message and sets up the workflow.\r
+ * @param execution the execution\r
+ */\r
+ public void preProcessRequest(DelegateExecution execution) {\r
+ def method = getClass().getSimpleName() + '.preProcessRequest(' +\r
+ 'execution=' + execution.getId() +\r
+ ')'\r
+ def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
+ logDebug('Entered ' + method, isDebugLogEnabled)\r
+\r
+ execution.setVariable("CVFMI_sentSyncResponse", false)\r
+ \r
+ def prefix = 'CVFMI_'\r
+ logDebug('Entered 1' + method, isDebugLogEnabled)\r
+ execution.setVariable('prefix', prefix)\r
+ logDebug('Entered 2' + method, isDebugLogEnabled)\r
+ execution.setVariable("isVidRequest", "false")\r
+\r
+ logDebug("Set variables", isDebugLogEnabled)\r
+\r
+ def rollbackData = execution.getVariable("RollbackData")\r
+ if (rollbackData == null) {\r
+ rollbackData = new RollbackData()\r
+ }\r
+ execution.setVariable("RollbackData", rollbackData)\r
+\r
+ logDebug("Set rollback data", isDebugLogEnabled)\r
+ def incomingRequest = execution.getVariable('bpmnRequest')\r
+\r
+ utils.log("DEBUG", "Incoming Infra Request: " + incomingRequest, isDebugLogEnabled)\r
+ utils.logAudit("CreateVfModule Infra incoming Request: " + incomingRequest)\r
+\r
+ setBasicDBAuthHeader(execution, isDebugLogEnabled)\r
+ \r
+ // check if request is xml or json\r
+ try {\r
+ def jsonSlurper = new JsonSlurper()\r
+ def jsonOutput = new JsonOutput()\r
+ Map reqMap = jsonSlurper.parseText(incomingRequest)\r
+ utils.log("DEBUG", " Request is in JSON format.", isDebugLogEnabled)\r
+\r
+ def serviceInstanceId = execution.getVariable('serviceInstanceId')\r
+ def vnfId = execution.getVariable('vnfId')\r
+ \r
+ execution.setVariable(prefix + 'serviceInstanceId', serviceInstanceId)\r
+ execution.setVariable(prefix+'vnfId', vnfId)\r
+ execution.setVariable("isVidRequest", "true")\r
+ \r
+ def vnfName = ''\r
+ def asdcServiceModelVersion = ''\r
+ def serviceModelInfo = null\r
+ def vnfModelInfo = null\r
+ \r
+ def relatedInstanceList = reqMap.requestDetails?.relatedInstanceList\r
+ \r
+ if (relatedInstanceList != null) {\r
+ relatedInstanceList.each {\r
+ if (it.relatedInstance.modelInfo?.modelType == 'service') {\r
+ asdcServiceModelVersion = it.relatedInstance.modelInfo?.modelVersion\r
+ serviceModelInfo = jsonOutput.toJson(it.relatedInstance.modelInfo)\r
+ \r
+ }\r
+ if (it.relatedInstance.modelInfo.modelType == 'vnf') {\r
+ vnfName = it.relatedInstance.instanceName ?: ''\r
+ vnfModelInfo = jsonOutput.toJson(it.relatedInstance.modelInfo)\r
+ }\r
+ }\r
+ }\r
+ \r
+ execution.setVariable(prefix + 'vnfName', vnfName)\r
+ execution.setVariable(prefix + 'asdcServiceModelVersion', asdcServiceModelVersion)\r
+ execution.setVariable(prefix + 'serviceModelInfo', serviceModelInfo)\r
+ execution.setVariable(prefix + 'vnfModelInfo', vnfModelInfo)\r
+ \r
+ \r
+ def vnfType = execution.getVariable('vnfType')\r
+ execution.setVariable(prefix + 'vnfType', vnfType) \r
+ def vfModuleId = execution.getVariable('vfModuleId')\r
+ execution.setVariable(prefix + 'vfModuleId', vfModuleId)\r
+ def volumeGroupId = execution.getVariable('volumeGroupId')\r
+ execution.setVariable(prefix + 'volumeGroupId', volumeGroupId)\r
+ def userParams = reqMap.requestDetails?.requestParameters?.userParams \r
+ \r
+ Map<String, String> userParamsMap = [:]\r
+ if (userParams != null) {\r
+ userParams.each { userParam ->\r
+ userParamsMap.put(userParam.name, jsonOutput.toJson(userParam.value).toString())\r
+ } \r
+ } \r
+ \r
+ utils.log("DEBUG", 'Processed user params: ' + userParamsMap, isDebugLogEnabled) \r
+ \r
+ execution.setVariable(prefix + 'vfModuleInputParams', userParamsMap)\r
+ \r
+ def isBaseVfModule = "false"\r
+ if (execution.getVariable('isBaseVfModule') == true) {\r
+ isBaseVfModule = "true"\r
+ } \r
+ \r
+ execution.setVariable(prefix + 'isBaseVfModule', isBaseVfModule)\r
+ \r
+ def requestId = execution.getVariable("mso-request-id")\r
+ execution.setVariable(prefix + 'requestId', requestId)\r
+ \r
+ def vfModuleModelInfo = jsonOutput.toJson(reqMap.requestDetails?.modelInfo)\r
+ execution.setVariable(prefix + 'vfModuleModelInfo', vfModuleModelInfo)\r
+ \r
+ def suppressRollback = reqMap.requestDetails?.requestInfo?.suppressRollback\r
+ \r
+ \r
+ def backoutOnFailure = ""\r
+ if(suppressRollback != null){\r
+ if ( suppressRollback == true) {\r
+ backoutOnFailure = "false"\r
+ } else if ( suppressRollback == false) {\r
+ backoutOnFailure = "true"\r
+ }\r
+ }\r
+ \r
+ execution.setVariable('disableRollback', suppressRollback)\r
+ \r
+ def vfModuleName = reqMap.requestDetails?.requestInfo?.instanceName ?: null\r
+ execution.setVariable(prefix + 'vfModuleName', vfModuleName)\r
+ \r
+ def serviceId = reqMap.requestDetails?.requestParameters?.serviceId ?: ''\r
+ execution.setVariable(prefix + 'serviceId', serviceId)\r
+ \r
+ def usePreload = reqMap.requestDetails?.requestParameters?.usePreload\r
+ execution.setVariable(prefix + 'usePreload', usePreload)\r
+ \r
+ // This is aLaCarte flow, so aLaCarte flag is always on \r
+ execution.setVariable(prefix + 'aLaCarte', true)\r
+ \r
+ def cloudConfiguration = reqMap.requestDetails?.cloudConfiguration\r
+ def lcpCloudRegionId = cloudConfiguration.lcpCloudRegionId\r
+ execution.setVariable(prefix + 'lcpCloudRegionId', lcpCloudRegionId)\r
+ def tenantId = cloudConfiguration.tenantId\r
+ execution.setVariable(prefix + 'tenantId', tenantId)\r
+ \r
+ def globalSubscriberId = reqMap.requestDetails?.subscriberInfo?.globalSubscriberId ?: ''\r
+ execution.setVariable(prefix + 'globalSubscriberId', globalSubscriberId)\r
+ \r
+ execution.setVariable(prefix + 'sdncVersion', '1702')\r
+\r
+ execution.setVariable("CreateVfModuleInfraSuccessIndicator", false)\r
+ execution.setVariable("RollbackCompleted", false)\r
+ \r
+ execution.setVariable("isDebugLogEnabled", isDebugLogEnabled)\r
+ \r
+ \r
+ def source = reqMap.requestDetails?.requestInfo?.source\r
+ execution.setVariable("CVFMI_source", source)\r
+ \r
+ //For Completion Handler & Fallout Handler\r
+ String requestInfo =\r
+ """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">\r
+ <request-id>${requestId}</request-id>\r
+ <action>CREATE</action>\r
+ <source>${source}</source>\r
+ </request-info>"""\r
+ \r
+ execution.setVariable("CVFMI_requestInfo", requestInfo)\r
+ \r
+ //backoutOnFailure\r
+ \r
+ execution.setVariable("CVFMI_originalWorkflowException", null)\r
+ \r
+\r
+ def newVfModuleId = UUID.randomUUID().toString()\r
+ execution.setVariable("newVfModuleId", newVfModuleId)\r
+ execution.setVariable(prefix + 'vfModuleId', newVfModuleId)\r
+ execution.setVariable('actionHealthCheck', Action.HealthCheck)\r
+ execution.setVariable('actionConfigScaleOut', Action.ConfigScaleOut)\r
+ execution.setVariable('controllerType', "APPC")\r
+ def controllerType = execution.getVariable('controllerType')\r
+ execution.setVariable(prefix + 'controllerType', controllerType)\r
+ execution.setVariable('healthCheckIndex0', 0)\r
+\r
+ logDebug('RequestInfo: ' + execution.getVariable("CVFMI_requestInfo"), isDebugLogEnabled) \r
+ \r
+ logDebug('rollbackEnabled: ' + execution.getVariable("CVFMI_rollbackEnabled"), isDebugLogEnabled)\r
+\r
+ logDebug('Exited ' + method, isDebugLogEnabled)\r
+ } catch (BpmnError bpmnError) {\r
+ throw bpmnError\r
+ }\r
+ catch(groovy.json.JsonException je) {\r
+ utils.log("DEBUG", " Request is not in JSON format.", isDebugLogEnabled)\r
+ exceptionUtil.buildAndThrowWorkflowException(execution, 400, "Internal Error - During PreProcessRequest")\r
+ }\r
+ catch(Exception e) {\r
+ String restFaultMessage = e.getMessage()\r
+ //execution.setVariable("CVFMODVOL2_RESTFault", restFaultMessage)\r
+ //execution.setVariable("CVFMODVOL2_isDataOk", false)\r
+ utils.log("ERROR", " Exception Encountered - " + "\n" + restFaultMessage, isDebugLogEnabled)\r
+ exceptionUtil.buildAndThrowWorkflowException(execution, 400, "Internal Error - During PreProcessRequest")\r
+ }\r
+\r
+ }\r
+\r
+ /**\r
+ * Validates a workflow response.\r
+ * @param execution the execution\r
+ * @param responseVar the execution variable in which the response is stored\r
+ * @param responseCodeVar the execution variable in which the response code is stored\r
+ * @param errorResponseVar the execution variable in which the error response is stored\r
+ */\r
+ public void validateWorkflowResponse(DelegateExecution execution, String responseVar,\r
+ String responseCodeVar, String errorResponseVar) {\r
+ SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)\r
+ sdncAdapterUtils.validateSDNCResponse(execution, responseVar, responseCodeVar, errorResponseVar)\r
+ }\r
+\r
+\r
+ /**\r
+ * Sends the empty, synchronous response back to the API Handler.\r
+ * @param execution the execution\r
+ */\r
+ public void sendResponse(DelegateExecution execution) {\r
+ def method = getClass().getSimpleName() + '.sendResponse(' +\r
+ 'execution=' + execution.getId() +\r
+ ')'\r
+ def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
+ logDebug('Entered ' + method, isDebugLogEnabled)\r
+\r
+ try {\r
+ def requestInfo = execution.getVariable('CVFMI_requestInfo')\r
+ def requestId = execution.getVariable('CVFMI_requestId')\r
+ def source = execution.getVariable('CVFMI_source') \r
+ \r
+ // RESTResponse (for API Handler (APIH) Reply Task)\r
+ def newVfModuleId = execution.getVariable("newVfModuleId")\r
+ String synchResponse = """{"requestReferences":{"instanceId":"${newVfModuleId}","requestId":"${requestId}"}}""".trim()\r
+\r
+ sendWorkflowResponse(execution, 200, synchResponse)\r
+\r
+ execution.setVariable("CVFMI_sentSyncResponse", true)\r
+ utils.logAudit("CreateVfModule Infra Response: " + synchResponse)\r
+ logDebug('Exited ' + method, isDebugLogEnabled)\r
+ } catch (BpmnError e) {\r
+ throw e;\r
+ } catch (Exception e) {\r
+ logError('Caught exception in ' + method, e)\r
+ exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in sendResponse(): ' + e.getMessage())\r
+ }\r
+ }\r
+ \r
+ /**\r
+ * Query AAI for vnf orchestration status to determine if health check and config scaling should be run\r
+ */\r
+ public void queryAAIForVnfOrchestrationStatus(DelegateExecution execution) {\r
+ def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
+ def vnfId = execution.getVariable("CVFMI_vnfId")\r
+ execution.setVariable("runHealthCheck", false);\r
+ execution.setVariable("runConfigScaleOut", false);\r
+ AAICreateResources aaiCreateResources = new AAICreateResources();\r
+ Optional<GenericVnf> vnf = aaiCreateResources.getVnfInstance(vnfId);\r
+ if(vnf.isPresent()){\r
+ def vnfOrchestrationStatus = vnf.get().getOrchestrationStatus();\r
+ if("active".equalsIgnoreCase(vnfOrchestrationStatus)){\r
+ execution.setVariable("runHealthCheck", false);\r
+ execution.setVariable("runConfigScaleOut", true);\r
+ }\r
+ }\r
+ }\r
+ \r
+ /**\r
+ * Retrieve data for ConfigScaleOut from SDNC topology\r
+ */\r
+ \r
+ public void retreiveConfigScaleOutData(DelegateExecution execution){\r
+ def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
+ def vfModuleId = execution.getVariable("CVFMI_vfModuleId")\r
+ String ipAddress = "";\r
+ String oamIpAddress = "";\r
+ String vnfHostIpAddress = "";\r
+\r
+ String vnfGetSDNC = execution.getVariable("DCVFM_getSDNCAdapterResponse");\r
+\r
+ String data = utils.getNodeXml(vnfGetSDNC, "response-data")\r
+ data = data.replaceAll("<", "<")\r
+ data = data.replaceAll(">", ">")\r
+\r
+ InputSource source = new InputSource(new StringReader(data));\r
+ DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();\r
+ docFactory.setNamespaceAware(true)\r
+ DocumentBuilder docBuilder = docFactory.newDocumentBuilder()\r
+ Document responseXml = docBuilder.parse(source)\r
+\r
+ NodeList paramsList = responseXml.getElementsByTagNameNS("*", "vnf-parameters")\r
+ for (int z = 0; z < paramsList.getLength(); z++) {\r
+ Node node = paramsList.item(z)\r
+ Element eElement = (Element) node\r
+ String vnfParameterName = utils.getElementText(eElement, "vnf-parameter-name")\r
+ String vnfParameterValue = utils.getElementText(eElement, "vnf-parameter-value")\r
+ if (vnfParameterName.equals("vlb_private_ip_1")) {\r
+ vnfHostIpAddress = vnfParameterValue\r
+ }\r
+ else if (vnfParameterName.equals("vdns_private_ip_0")) {\r
+ ipAddress = vnfParameterValue\r
+ }\r
+ else if (vnfParameterName.equals("vdns_private_ip_1")) { \r
+ oamIpAddress = vnfParameterValue\r
+ }\r
+ }\r
+\r
+ String payload = "{\"request-parameters\":{\"vnf-host-ip-address\":\"" + vnfHostIpAddress + "\",\"vf-module-id\":\"" + vfModuleId + "\"},\"configuration-parameters\":{\"ip-addr\":\"" + ipAddress +"\", \"oam-ip-addr\":\""+ oamIpAddress +"\",\"enabled\":\"true\"}}"\r
+ execution.setVariable("payload", payload);\r
+ }\r
+\r
+ /**\r
+ *\r
+ * @param execution the execution\r
+ */\r
+ public void postProcessResponse(DelegateExecution execution){\r
+ def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
+\r
+ utils.log("DEBUG", " ======== STARTED PostProcessResponse Process ======== ", isDebugEnabled)\r
+ try{ \r
+ def requestInfo = execution.getVariable("CVFMI_requestInfo")\r
+ def action = utils.getNodeText1(requestInfo, "action")\r
+\r
+ utils.log("DEBUG", "requestInfo is: " + requestInfo, isDebugEnabled)\r
+ utils.log("DEBUG", "action is: " + action, isDebugEnabled)\r
+\r
+ String payload =\r
+ """ <aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"\r
+ xmlns:ns="http://org.openecomp/mso/request/types/v1"\r
+ xmlns:ns8="http://org.openecomp/mso/workflow/schema/v1">\r
+ <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">\r
+ ${requestInfo}\r
+ </request-info>\r
+ <ns8:status-message>Vf Module has been created successfully.</ns8:status-message>\r
+ <ns8:mso-bpel-name>BPMN</ns8:mso-bpel-name>\r
+ </aetgt:MsoCompletionRequest>"""\r
+\r
+ payload = utils.formatXml(payload)\r
+ execution.setVariable("CVFMI_SuccessFlag", true)\r
+ execution.setVariable("CVFMI_msoCompletionRequest", payload)\r
+ utils.logAudit("CreateVfModuleInfra completion request: " + payload)\r
+ utils.log("DEBUG", "Outgoing MsoCompletionRequest: \n" + payload, isDebugEnabled)\r
+\r
+ }catch(Exception e){\r
+ utils.log("ERROR", "Exception Occured Processing PostProcessResponse. Exception is:\n" + e, isDebugEnabled)\r
+ execution.setVariable("CVFMI_ErrorResponse", "Error Occured during PostProcessResponse Method:\n" + e.getMessage())\r
+ }\r
+ utils.log("DEBUG", "======== COMPLETED PostProcessResponse Process ======== ", isDebugEnabled)\r
+ }\r
+\r
+\r
+\r
+\r
+\r
+ /**\r
+ * Validates the request, request id and service instance id. If a problem is found,\r
+ * a WorkflowException is generated and an MSOWorkflowException event is thrown. This\r
+ * method also sets up the log context for the workflow.\r
+ * @param execution the execution\r
+ * @return the validated request\r
+ */\r
+ public String validateInfraRequest(DelegateExecution execution) {\r
+ def method = getClass().getSimpleName() + '.validateInfraRequest(' +\r
+ 'execution=' + execution.getId() +\r
+ ')'\r
+ def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
+ logDebug('Entered ' + method, isDebugLogEnabled)\r
+\r
+ String processKey = getProcessKey(execution);\r
+ def prefix = execution.getVariable("prefix")\r
+\r
+ if (prefix == null) {\r
+ exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " prefix is null")\r
+ }\r
+\r
+ try {\r
+ def request = execution.getVariable(prefix + 'Request')\r
+\r
+ if (request == null) {\r
+ request = execution.getVariable(processKey + 'Request')\r
+\r
+ if (request == null) {\r
+ request = execution.getVariable('bpmnRequest')\r
+ }\r
+\r
+ setVariable(execution, processKey + 'Request', null);\r
+ setVariable(execution, 'bpmnRequest', null);\r
+ setVariable(execution, prefix + 'Request', request);\r
+ }\r
+\r
+ if (request == null) {\r
+ exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " request is null")\r
+ }\r
+\r
+ /*\r
+\r
+ def requestId = execution.getVariable("mso-request-id")\r
+\r
+ if (requestId == null) {\r
+ exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " request has no mso-request-id")\r
+ }\r
+\r
+ setVariable(execution, prefix + 'requestId', requestId)\r
+\r
+ def serviceInstanceId = execution.getVariable("mso-service-instance-id")\r
+\r
+ if (serviceInstanceId == null) {\r
+ exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " request message has no mso-service-instance-id")\r
+ }\r
+\r
+ utils.logContext(requestId, serviceInstanceId)\r
+ */\r
+ utils.logAudit("CreateVfModule incoming request: " + request)\r
+ logDebug('Incoming message: ' + System.lineSeparator() + request, isDebugLogEnabled)\r
+ logDebug('Exited ' + method, isDebugLogEnabled)\r
+ return request\r
+ } catch (BpmnError e) {\r
+ throw e;\r
+ } catch (Exception e) {\r
+ logError('Caught exception in ' + method, e)\r
+ exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Invalid Message")\r
+ }\r
+ }\r
+\r
+ public void prepareUpdateInfraRequest(DelegateExecution execution){\r
+ def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
+\r
+ utils.log("DEBUG", " ======== STARTED prepareUpdateInfraRequest Process ======== ", isDebugEnabled)\r
+ try{\r
+ \r
+ \r
+ String requestInfo = execution.getVariable("CVFMI_requestInfo") \r
+ def aicCloudRegion = execution.getVariable("CVFMI_lcpCloudRegionId")\r
+ def tenantId = execution.getVariable("CVFMI_tenantId")\r
+ def requestId = utils.getNodeText1(requestInfo, "request-id")\r
+ def vnfId = execution.getVariable("CVFMI_vnfId")\r
+ def vfModuleId = execution.getVariable("CVFMI_vfModuleId")\r
+ // vfModuleName may be generated by DoCreateVfModule subprocess if it is not specified on the input\r
+ def vfModuleName = execution.getVariable("CVFMI_vfModuleName")\r
+\r
+ def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")\r
+ execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)\r
+ utils.log("DEBUG", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)\r
+\r
+ String payload =\r
+ """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"\r
+ xmlns:ns="http://org.openecomp.mso/requestsdb">\r
+ <soapenv:Header/>\r
+ <soapenv:Body>\r
+ <ns:updateInfraRequest xmlns:ns="http://org.openecomp.mso/requestsdb">\r
+ <requestId>${requestId}</requestId>\r
+ <lastModifiedBy>BPMN</lastModifiedBy>\r
+ <statusMessage>VF Module successfully created</statusMessage>\r
+ <responseBody></responseBody>\r
+ <requestStatus>COMPLETE</requestStatus>\r
+ <progress>100</progress>\r
+ <vnfOutputs><vnf-outputs xmlns="http://org.openecomp/mso/infra/vnf-request/v1" xmlns:aetgt="http://org.openecomp/mso/infra/vnf-request/v1" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd"><vnf-id>${vnfId}</vnf-id><vf-module-id>${vfModuleId}</vf-module-id></vnf-outputs></vnfOutputs>\r
+ <vfModuleId>${vfModuleId}</vfModuleId>\r
+ <vfModuleName>${vfModuleName}</vfModuleName>\r
+ </ns:updateInfraRequest>\r
+ </soapenv:Body>\r
+ </soapenv:Envelope>"""\r
+\r
+ payload = utils.formatXml(payload)\r
+ execution.setVariable("CVFMI_updateInfraRequest", payload)\r
+ utils.log("DEBUG", "Outgoing UpdateInfraRequest: \n" + payload, isDebugEnabled)\r
+ utils.logAudit("CreateVfModuleInfra Outgoing UpdateInfra Request: " + payload)\r
+\r
+ }catch(Exception e){\r
+ utils.log("ERROR", "Exception Occured Processing prepareUpdateInfraRequest. Exception is:\n" + e, isDebugEnabled)\r
+ execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during prepareUpdateInfraRequest Method:\n" + e.getMessage())\r
+ }\r
+ utils.log("DEBUG", "======== COMPLETED prepareUpdateInfraRequest Process ======== ", isDebugEnabled)\r
+ }\r
+\r
+ /**\r
+ * Builds a "FalloutHandler" request and stores it in the specified execution variable.\r
+ *\r
+ * @param execution the execution\r
+ * @param resultVar the execution variable in which the result will be stored\r
+ */\r
+ public void falloutHandlerPrep(DelegateExecution execution, String resultVar) {\r
+ def method = getClass().getSimpleName() + '.falloutHandlerPrep(' +\r
+ 'execution=' + execution.getId() +\r
+ ', resultVar=' + resultVar +\r
+ ')'\r
+ def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
+ logDebug('Entered ' + method, isDebugLogEnabled)\r
+\r
+\r
+ try {\r
+ def WorkflowException workflowException = execution.getVariable("WorkflowException") \r
+ def requestInformation = execution.getVariable("CVFMI_requestInfo")\r
+ def errorResponseCode = workflowException.getErrorCode()\r
+ def errorResponseMsg = workflowException.getErrorMessage()\r
+ def encErrorResponseMsg = ""\r
+ if (errorResponseMsg != null) {\r
+ encErrorResponseMsg = errorResponseMsg.replace("&", "&").replace("<", "<").replace(">", ">")\r
+ }\r
+\r
+ String content = """\r
+ <aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"\r
+ xmlns:reqtype="http://org.openecomp/mso/request/types/v1"\r
+ xmlns:msoservtypes="http://org.openecomp/mso/request/types/v1"\r
+ xmlns:structuredtypes="http://org.openecomp/mso/structured/types/v1">\r
+ ${requestInformation}\r
+ <aetgt:WorkflowException>\r
+ <aetgt:ErrorMessage>${encErrorResponseMsg}</aetgt:ErrorMessage>\r
+ <aetgt:ErrorCode>${errorResponseCode}</aetgt:ErrorCode>\r
+ </aetgt:WorkflowException>\r
+ </aetgt:FalloutHandlerRequest>\r
+ """\r
+\r
+ logDebug("CONTENT before translation: " + content, isDebugLogEnabled)\r
+ content = utils.formatXml(content)\r
+ logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)\r
+ utils.logAudit("CreateVfModuleInfra FallOutHander Request: " + content)\r
+ execution.setVariable(resultVar, content)\r
+\r
+ logDebug('Exited ' + method, isDebugLogEnabled)\r
+ } catch (BpmnError e) {\r
+ throw e;\r
+ } catch (Exception e) {\r
+ logError('Caught exception in ' + method, e)\r
+ exceptionUtil.buildWorkflowException(execution, 2000, 'Internal Error')\r
+ }\r
+ }\r
+\r
+ public void logAndSaveOriginalException(DelegateExecution execution) {\r
+ def method = getClass().getSimpleName() + '.validateRollbackResponse(' +\r
+ 'execution=' + execution.getId() +\r
+ ')'\r
+ def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
+ logDebug('Entered ' + method, isDebugLogEnabled)\r
+\r
+ logWorkflowException(execution, 'CreateVfModuleInfra caught an event')\r
+ saveWorkflowException(execution, 'CVFMI_originalWorkflowException')\r
+ }\r
+\r
+ public void validateRollbackResponse(DelegateExecution execution) {\r
+ def method = getClass().getSimpleName() + '.validateRollbackResponse(' +\r
+ 'execution=' + execution.getId() +\r
+ ')'\r
+ def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
+ logDebug('Entered ' + method, isDebugLogEnabled)\r
+\r
+ def originalException = execution.getVariable("CVFMI_originalWorkflowException")\r
+ execution.setVariable("WorkflowException", originalException)\r
+\r
+ execution.setVariable("RollbackCompleted", true)\r
+\r
+ }\r
+ \r
+ public void sendErrorResponse(DelegateExecution execution){\r
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+\r
+ utils.log("DEBUG", " *** STARTED CreateVfModulenfra sendErrorResponse Process *** ", isDebugEnabled)\r
+ try {\r
+ def sentSyncResponse = execution.getVariable("CVFMI_sentSyncResponse")\r
+ if(sentSyncResponse == false){\r
+ WorkflowException wfex = execution.getVariable("WorkflowException")\r
+ String response = exceptionUtil.buildErrorResponseXml(wfex)\r
+\r
+ utils.logAudit(response)\r
+ sendWorkflowResponse(execution, 500, response)\r
+ }else{\r
+ utils.log("DEBUG", "Not Sending Error Response. Sync Response Already Sent", isDebugEnabled)\r
+ }\r
+\r
+ } catch (Exception ex) {\r
+ utils.log("DEBUG", "Error Occured in CreateVfModuleInfra sendErrorResponse Process " + ex.getMessage(), isDebugEnabled)\r
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVfModuleInfra sendErrorResponse Process")\r
+\r
+ }\r
+ utils.log("DEBUG", "*** COMPLETED CreateVfModuleInfra sendErrorResponse Process ***", isDebugEnabled)\r
+ }\r
+\r
+\r
+}\r