2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.bpmn.infrastructure.scripts;
23 import groovy.json.JsonSlurper
24 import groovy.json.JsonOutput
26 import org.camunda.bpm.engine.delegate.BpmnError
27 import org.camunda.bpm.engine.runtime.Execution
28 import org.apache.commons.lang3.*
29 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor;
30 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil;
31 import org.openecomp.mso.bpmn.common.scripts.NetworkUtils;
32 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils;
33 import org.openecomp.mso.bpmn.common.scripts.VidUtils;
34 import org.openecomp.mso.bpmn.core.RollbackData
35 import org.openecomp.mso.bpmn.core.WorkflowException
36 import org.openecomp.mso.bpmn.core.json.JsonUtils
38 public class CreateVfModuleInfra extends AbstractServiceTaskProcessor {
40 ExceptionUtil exceptionUtil = new ExceptionUtil()
41 JsonUtils jsonUtil = new JsonUtils()
44 * Validates the request message and sets up the workflow.
45 * @param execution the execution
47 public void preProcessRequest(Execution execution) {
48 def method = getClass().getSimpleName() + '.preProcessRequest(' +
49 'execution=' + execution.getId() +
51 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
52 logDebug('Entered ' + method, isDebugLogEnabled)
55 logDebug('Entered 1' + method, isDebugLogEnabled)
56 execution.setVariable('prefix', prefix)
57 logDebug('Entered 2' + method, isDebugLogEnabled)
58 execution.setVariable("isVidRequest", "false")
60 logDebug("Set variables", isDebugLogEnabled)
62 def rollbackData = execution.getVariable("RollbackData")
63 if (rollbackData == null) {
64 rollbackData = new RollbackData()
66 execution.setVariable("RollbackData", rollbackData)
68 logDebug("Set rollback data", isDebugLogEnabled)
69 def incomingRequest = execution.getVariable('bpmnRequest')
71 utils.log("DEBUG", "Incoming Infra Request: " + incomingRequest, isDebugLogEnabled)
72 utils.logAudit("CreateVfModule Infra incoming Request: " + incomingRequest)
74 // check if request is xml or json
76 def jsonSlurper = new JsonSlurper()
77 def jsonOutput = new JsonOutput()
78 Map reqMap = jsonSlurper.parseText(incomingRequest)
79 utils.log("DEBUG", " Request is in JSON format.", isDebugLogEnabled)
81 def serviceInstanceId = execution.getVariable('serviceInstanceId')
82 def vnfId = execution.getVariable('vnfId')
84 execution.setVariable(prefix + 'serviceInstanceId', serviceInstanceId)
85 execution.setVariable(prefix+'vnfId', vnfId)
86 execution.setVariable("isVidRequest", "true")
89 def asdcServiceModelVersion = ''
90 def serviceModelInfo = null
91 def vnfModelInfo = null
93 def relatedInstanceList = reqMap.requestDetails?.relatedInstanceList
95 if (relatedInstanceList != null) {
96 relatedInstanceList.each {
97 if (it.relatedInstance.modelInfo?.modelType == 'service') {
98 asdcServiceModelVersion = it.relatedInstance.modelInfo?.modelVersion
99 serviceModelInfo = jsonOutput.toJson(it.relatedInstance.modelInfo)
102 if (it.relatedInstance.modelInfo.modelType == 'vnf') {
103 vnfName = it.relatedInstance.instanceName ?: ''
104 vnfModelInfo = jsonOutput.toJson(it.relatedInstance.modelInfo)
109 execution.setVariable(prefix + 'vnfName', vnfName)
110 execution.setVariable(prefix + 'asdcServiceModelVersion', asdcServiceModelVersion)
111 execution.setVariable(prefix + 'serviceModelInfo', serviceModelInfo)
112 execution.setVariable(prefix + 'vnfModelInfo', vnfModelInfo)
115 def vnfType = execution.getVariable('vnfType')
116 execution.setVariable(prefix + 'vnfType', vnfType)
117 def vfModuleId = execution.getVariable('vfModuleId')
118 execution.setVariable(prefix + 'vfModuleId', vfModuleId)
119 def volumeGroupId = execution.getVariable('volumeGroupId')
120 execution.setVariable(prefix + 'volumeGroupId', volumeGroupId)
121 def userParams = reqMap.requestDetails?.requestParameters?.userParams
123 Map<String, String> userParamsMap = [:]
124 if (userParams != null) {
125 userParams.each { userParam ->
126 userParamsMap.put(userParam.name, userParam.value)
130 utils.log("DEBUG", 'Processed user params: ' + userParamsMap, isDebugLogEnabled)
132 execution.setVariable(prefix + 'vfModuleInputParams', userParamsMap)
134 def isBaseVfModule = "false"
135 if (execution.getVariable('isBaseVfModule') == true) {
136 isBaseVfModule = "true"
139 execution.setVariable(prefix + 'isBaseVfModule', isBaseVfModule)
141 def requestId = execution.getVariable("mso-request-id")
142 execution.setVariable(prefix + 'requestId', requestId)
144 def vfModuleModelInfo = jsonOutput.toJson(reqMap.requestDetails?.modelInfo)
145 execution.setVariable(prefix + 'vfModuleModelInfo', vfModuleModelInfo)
147 def suppressRollback = reqMap.requestDetails?.requestInfo?.suppressRollback
150 def backoutOnFailure = ""
151 if(suppressRollback != null){
152 if ( suppressRollback == true) {
153 backoutOnFailure = "false"
154 } else if ( suppressRollback == false) {
155 backoutOnFailure = "true"
159 execution.setVariable(prefix + 'disableRollback', suppressRollback)
161 def vfModuleName = reqMap.requestDetails?.requestInfo?.instanceName ?: null
162 execution.setVariable(prefix + 'vfModuleName', vfModuleName)
164 def serviceId = reqMap.requestDetails?.requestParameters?.serviceId ?: ''
165 execution.setVariable(prefix + 'serviceId', serviceId)
167 def usePreload = reqMap.requestDetails?.requestParameters?.usePreload
168 execution.setVariable(prefix + 'usePreload', usePreload)
170 def cloudConfiguration = reqMap.requestDetails?.cloudConfiguration
171 def lcpCloudRegionId = cloudConfiguration.lcpCloudRegionId
172 execution.setVariable(prefix + 'lcpCloudRegionId', lcpCloudRegionId)
173 def tenantId = cloudConfiguration.tenantId
174 execution.setVariable(prefix + 'tenantId', tenantId)
176 def globalSubscriberId = reqMap.requestDetails?.subscriberInfo?.globalSubscriberId ?: ''
177 execution.setVariable(prefix + 'globalSubscriberId', globalSubscriberId)
179 execution.setVariable(prefix + 'sdncVersion', '1702')
181 execution.setVariable("CreateVfModuleInfraSuccessIndicator", false)
182 execution.setVariable("RollbackCompleted", false)
184 execution.setVariable("isDebugLogEnabled", isDebugLogEnabled)
187 def source = reqMap.requestDetails?.requestInfo?.source
188 execution.setVariable("CVFMI_source", source)
190 //For Completion Handler & Fallout Handler
192 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
193 <request-id>${requestId}</request-id>
194 <action>CREATE</action>
195 <source>${source}</source>
198 execution.setVariable("CVFMI_requestInfo", requestInfo)
202 //NetworkUtils networkUtils = new NetworkUtils()
203 //execution.setVariable("CVFMI_rollbackEnabled", networkUtils.isRollbackEnabled(execution,request))
204 execution.setVariable("CVFMI_originalWorkflowException", null)
207 def newVfModuleId = UUID.randomUUID().toString()
208 execution.setVariable("newVfModuleId", newVfModuleId)
209 execution.setVariable(prefix + 'vfModuleId', newVfModuleId)
211 logDebug('RequestInfo: ' + execution.getVariable("CVFMI_requestInfo"), isDebugLogEnabled)
213 logDebug('rollbackEnabled: ' + execution.getVariable("CVFMI_rollbackEnabled"), isDebugLogEnabled)
215 logDebug('Exited ' + method, isDebugLogEnabled)
216 } catch (BpmnError bpmnError) {
219 catch(groovy.json.JsonException je) {
220 utils.log("DEBUG", " Request is not in JSON format.", isDebugLogEnabled)
221 exceptionUtil.buildAndThrowWorkflowException(execution, 400, "Internal Error - During PreProcessRequest")
224 String restFaultMessage = e.getMessage()
225 //execution.setVariable("CVFMODVOL2_RESTFault", restFaultMessage)
226 //execution.setVariable("CVFMODVOL2_isDataOk", false)
227 utils.log("ERROR", " Exception Encountered - " + "\n" + restFaultMessage, isDebugLogEnabled)
228 exceptionUtil.buildAndThrowWorkflowException(execution, 400, "Internal Error - During PreProcessRequest")
234 * Validates a workflow response.
235 * @param execution the execution
236 * @param responseVar the execution variable in which the response is stored
237 * @param responseCodeVar the execution variable in which the response code is stored
238 * @param errorResponseVar the execution variable in which the error response is stored
240 public void validateWorkflowResponse(Execution execution, String responseVar,
241 String responseCodeVar, String errorResponseVar) {
242 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
243 sdncAdapterUtils.validateSDNCResponse(execution, responseVar, responseCodeVar, errorResponseVar)
248 * Sends the empty, synchronous response back to the API Handler.
249 * @param execution the execution
251 public void sendResponse(Execution execution) {
252 def method = getClass().getSimpleName() + '.sendResponse(' +
253 'execution=' + execution.getId() +
255 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
256 logDebug('Entered ' + method, isDebugLogEnabled)
259 def requestInfo = execution.getVariable('CVFMI_requestInfo')
260 def requestId = execution.getVariable('CVFMI_requestId')
261 def source = execution.getVariable('CVFMI_source')
263 // RESTResponse (for API Handler (APIH) Reply Task)
264 def newVfModuleId = execution.getVariable("newVfModuleId")
265 String synchResponse = """{"requestReferences":{"instanceId":"${newVfModuleId}","requestId":"${requestId}"}}""".trim()
267 sendWorkflowResponse(execution, 200, synchResponse)
269 utils.logAudit("CreateVfModule Infra Response: " + synchResponse)
270 logDebug('Exited ' + method, isDebugLogEnabled)
271 } catch (BpmnError e) {
273 } catch (Exception e) {
274 logError('Caught exception in ' + method, e)
275 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in sendResponse(): ' + e.getMessage())
281 * @param execution the execution
283 public void postProcessResponse(Execution execution){
284 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
286 utils.log("DEBUG", " ======== STARTED PostProcessResponse Process ======== ", isDebugEnabled)
288 def requestInfo = execution.getVariable("CVFMI_requestInfo")
289 def action = utils.getNodeText1(requestInfo, "action")
291 utils.log("DEBUG", "requestInfo is: " + requestInfo, isDebugEnabled)
292 utils.log("DEBUG", "action is: " + action, isDebugEnabled)
295 String basicAuthValueDB = execution.getVariable("URN_mso_adapters_db_auth")
\r
296 utils.log("DEBUG", " Obtained BasicAuth userid password for Catalog DB adapter: " + basicAuthValueDB, isDebugEnabled)
\r
298 def encodedString = utils.getBasicAuth(basicAuthValueDB, execution.getVariable("URN_mso_msoKey"))
\r
299 execution.setVariable("BasicAuthHeaderValueDB",encodedString)
\r
300 } catch (IOException ex) {
\r
301 String dataErrorMessage = " Unable to encode Catalog DB user/password string - " + ex.getMessage()
\r
302 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
\r
303 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
\r
307 """ <aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
308 xmlns:ns="http://org.openecomp/mso/request/types/v1"
309 xmlns:ns8="http://org.openecomp/mso/workflow/schema/v1">
310 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
313 <ns8:status-message>Vf Module has been created successfully.</ns8:status-message>
314 <ns8:mso-bpel-name>BPMN</ns8:mso-bpel-name>
315 </aetgt:MsoCompletionRequest>"""
317 payload = utils.formatXml(payload)
318 execution.setVariable("CVFMI_SuccessFlag", true)
319 execution.setVariable("CVFMI_msoCompletionRequest", payload)
320 utils.logAudit("CreateVfModuleInfra completion request: " + payload)
321 utils.log("DEBUG", "Outgoing MsoCompletionRequest: \n" + payload, isDebugEnabled)
324 utils.log("ERROR", "Exception Occured Processing PostProcessResponse. Exception is:\n" + e, isDebugEnabled)
325 execution.setVariable("CVFMI_ErrorResponse", "Error Occured during PostProcessResponse Method:\n" + e.getMessage())
327 utils.log("DEBUG", "======== COMPLETED PostProcessResponse Process ======== ", isDebugEnabled)
335 * Validates the request, request id and service instance id. If a problem is found,
336 * a WorkflowException is generated and an MSOWorkflowException event is thrown. This
337 * method also sets up the log context for the workflow.
338 * @param execution the execution
339 * @return the validated request
341 public String validateInfraRequest(Execution execution) {
342 def method = getClass().getSimpleName() + '.validateInfraRequest(' +
343 'execution=' + execution.getId() +
345 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
346 logDebug('Entered ' + method, isDebugLogEnabled)
348 String processKey = getProcessKey(execution);
349 def prefix = execution.getVariable("prefix")
351 if (prefix == null) {
352 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " prefix is null")
356 def request = execution.getVariable(prefix + 'Request')
358 if (request == null) {
359 request = execution.getVariable(processKey + 'Request')
361 if (request == null) {
362 request = execution.getVariable('bpmnRequest')
365 setVariable(execution, processKey + 'Request', null);
366 setVariable(execution, 'bpmnRequest', null);
367 setVariable(execution, prefix + 'Request', request);
370 if (request == null) {
371 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " request is null")
376 def requestId = execution.getVariable("mso-request-id")
378 if (requestId == null) {
379 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " request has no mso-request-id")
382 setVariable(execution, prefix + 'requestId', requestId)
384 def serviceInstanceId = execution.getVariable("mso-service-instance-id")
386 if (serviceInstanceId == null) {
387 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " request message has no mso-service-instance-id")
390 utils.logContext(requestId, serviceInstanceId)
392 utils.logAudit("CreateVfModule incoming request: " + request)
393 logDebug('Incoming message: ' + System.lineSeparator() + request, isDebugLogEnabled)
394 logDebug('Exited ' + method, isDebugLogEnabled)
396 } catch (BpmnError e) {
398 } catch (Exception e) {
399 logError('Caught exception in ' + method, e)
400 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Invalid Message")
404 public void prepareUpdateInfraRequest(Execution execution){
405 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
407 utils.log("DEBUG", " ======== STARTED prepareUpdateInfraRequest Process ======== ", isDebugEnabled)
411 String requestInfo = execution.getVariable("CVFMI_requestInfo")
412 def aicCloudRegion = execution.getVariable("CVFMI_lcpCloudRegionId")
413 def tenantId = execution.getVariable("CVFMI_tenantId")
414 def requestId = utils.getNodeText1(requestInfo, "request-id")
415 def vnfId = execution.getVariable("CVFMI_vnfId")
416 def vfModuleId = execution.getVariable("CVFMI_vfModuleId")
417 // vfModuleName may be generated by DoCreateVfModule subprocess if it is not specified on the input
418 def vfModuleName = execution.getVariable("CVFMI_vfModuleName")
420 def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_db_endpoint")
421 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
422 utils.log("DEBUG", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)
425 String basicAuthValueDB = execution.getVariable("URN_mso_adapters_db_auth")
\r
426 utils.log("DEBUG", " Obtained BasicAuth userid password for Catalog DB adapter: " + basicAuthValueDB, isDebugEnabled)
\r
428 def encodedString = utils.getBasicAuth(basicAuthValueDB, execution.getVariable("URN_mso_msoKey"))
\r
429 execution.setVariable("BasicAuthHeaderValueDB",encodedString)
\r
430 } catch (IOException ex) {
\r
431 String dataErrorMessage = " Unable to encode Catalog DB user/password string - " + ex.getMessage()
\r
432 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
\r
433 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
\r
437 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
438 xmlns:ns="http://org.openecomp.mso/requestsdb">
441 <ns:updateInfraRequest xmlns:ns="http://org.openecomp.mso/requestsdb">
442 <requestId>${requestId}</requestId>
443 <lastModifiedBy>BPMN</lastModifiedBy>
444 <statusMessage>VF Module successfully created</statusMessage>
445 <responseBody></responseBody>
446 <requestStatus>COMPLETE</requestStatus>
447 <progress>100</progress>
448 <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>
449 <vfModuleId>${vfModuleId}</vfModuleId>
450 <vfModuleName>${vfModuleName}</vfModuleName>
451 </ns:updateInfraRequest>
453 </soapenv:Envelope>"""
455 payload = utils.formatXml(payload)
456 execution.setVariable("CVFMI_updateInfraRequest", payload)
457 utils.log("DEBUG", "Outgoing UpdateInfraRequest: \n" + payload, isDebugEnabled)
458 utils.logAudit("CreateVfModuleInfra Outgoing UpdateInfra Request: " + payload)
461 utils.log("ERROR", "Exception Occured Processing prepareUpdateInfraRequest. Exception is:\n" + e, isDebugEnabled)
462 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during prepareUpdateInfraRequest Method:\n" + e.getMessage())
464 utils.log("DEBUG", "======== COMPLETED prepareUpdateInfraRequest Process ======== ", isDebugEnabled)
468 * Builds a "FalloutHandler" request and stores it in the specified execution variable.
470 * @param execution the execution
471 * @param resultVar the execution variable in which the result will be stored
473 public void falloutHandlerPrep(Execution execution, String resultVar) {
474 def method = getClass().getSimpleName() + '.falloutHandlerPrep(' +
475 'execution=' + execution.getId() +
476 ', resultVar=' + resultVar +
478 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
479 logDebug('Entered ' + method, isDebugLogEnabled)
483 def WorkflowException workflowException = execution.getVariable("WorkflowException")
484 def requestInformation = execution.getVariable("CVFMI_requestInfo")
485 def errorResponseCode = workflowException.getErrorCode()
486 def errorResponseMsg = workflowException.getErrorMessage()
487 def encErrorResponseMsg = ""
488 if (errorResponseMsg != null) {
489 encErrorResponseMsg = errorResponseMsg.replace("&", "&").replace("<", "<").replace(">", ">")
493 <aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
494 xmlns:reqtype="http://org.openecomp/mso/request/types/v1"
495 xmlns:msoservtypes="http://org.openecomp/mso/request/types/v1"
496 xmlns:structuredtypes="http://org.openecomp/mso/structured/types/v1">
497 ${requestInformation}
498 <aetgt:WorkflowException>
499 <aetgt:ErrorMessage>${encErrorResponseMsg}</aetgt:ErrorMessage>
500 <aetgt:ErrorCode>${errorResponseCode}</aetgt:ErrorCode>
501 </aetgt:WorkflowException>
502 </aetgt:FalloutHandlerRequest>
505 logDebug("CONTENT before translation: " + content, isDebugLogEnabled)
506 content = utils.formatXml(content)
507 logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)
508 utils.logAudit("CreateVfModuleInfra FallOutHander Request: " + content)
509 execution.setVariable(resultVar, content)
511 logDebug('Exited ' + method, isDebugLogEnabled)
512 } catch (BpmnError e) {
514 } catch (Exception e) {
515 logError('Caught exception in ' + method, e)
516 exceptionUtil.buildWorkflowException(execution, 2000, 'Internal Error')
520 public void logAndSaveOriginalException(Execution execution) {
521 def method = getClass().getSimpleName() + '.validateRollbackResponse(' +
522 'execution=' + execution.getId() +
524 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
525 logDebug('Entered ' + method, isDebugLogEnabled)
527 logWorkflowException(execution, 'CreateVfModuleInfra caught an event')
528 saveWorkflowException(execution, 'CVFMI_originalWorkflowException')
531 public void validateRollbackResponse(Execution execution) {
532 def method = getClass().getSimpleName() + '.validateRollbackResponse(' +
533 'execution=' + execution.getId() +
535 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
536 logDebug('Entered ' + method, isDebugLogEnabled)
538 def originalException = execution.getVariable("CVFMI_originalWorkflowException")
539 execution.setVariable("WorkflowException", originalException)
541 execution.setVariable("RollbackCompleted", true)