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.onap.so.bpmn.infrastructure.scripts;
23 import org.apache.commons.lang3.*
24 import org.camunda.bpm.engine.delegate.BpmnError
25 import org.camunda.bpm.engine.delegate.DelegateExecution
26 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
27 import org.onap.so.bpmn.common.scripts.ExceptionUtil
28 import org.onap.so.bpmn.common.scripts.MsoUtils
29 import org.onap.so.bpmn.core.WorkflowException
30 import org.onap.so.bpmn.core.json.JsonUtils
31 import org.onap.so.logger.MsoLogger
36 * This groovy class supports the <class>CreateNetworkInstance.bpmn</class> process.
39 public class CreateNetworkInstance extends AbstractServiceTaskProcessor {
40 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, CreateNetworkInstance.class);
42 String Prefix="CRENI_"
43 ExceptionUtil exceptionUtil = new ExceptionUtil()
44 JsonUtils jsonUtil = new JsonUtils()
46 public InitializeProcessVariables(DelegateExecution execution){
48 execution.setVariable(Prefix + "source", "")
49 execution.setVariable(Prefix + "Success", false)
51 execution.setVariable(Prefix + "CompleteMsoProcessRequest", "")
52 execution.setVariable(Prefix + "FalloutHandlerRequest", "")
53 execution.setVariable(Prefix + "isSilentSuccess", false)
59 * This method is executed during the preProcessRequest task of the <class>CreateNetworkInstance.bpmn</class> process.
63 // **************************************************
64 // Pre or Prepare Request Section
65 // **************************************************
67 * This method is executed during the preProcessRequest task of the <class>CreateNetworkInstance.bpmn</class> process.
70 public void preProcessRequest (DelegateExecution execution) {
71 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
72 execution.setVariable("prefix",Prefix)
74 msoLogger.trace("Start preProcessRequest")
77 // initialize flow variables
78 InitializeProcessVariables(execution)
80 String sdncVersion = execution.getVariable("sdncVersion")
81 if (sdncVersion == null || sdncVersion == '1610') {
82 // 'a-la-cart' default, sdncVersion = '1610'
83 execution.setVariable("sdncVersion", "1610")
84 String bpmnRequest = execution.getVariable("bpmnRequest")
85 // set 'disableRollback'
86 if (bpmnRequest != null) {
87 String disableRollback = jsonUtil.getJsonValue(bpmnRequest, "requestDetails.requestInfo.suppressRollback")
88 if (disableRollback != null) {
89 execution.setVariable("disableRollback", disableRollback)
90 msoLogger.debug("Received 'suppressRollback': " + disableRollback )
92 execution.setVariable("disableRollback", false)
94 msoLogger.debug(" Set 'disableRollback' : " + execution.getVariable("disableRollback") )
96 String dataErrorMessage = " Invalid 'bpmnRequest' request."
97 msoLogger.debug(dataErrorMessage)
98 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
102 // 'macro' TEST ONLY, sdncVersion = '1702'
103 msoLogger.debug(" 'disableRollback' : " + execution.getVariable("disableRollback") )
106 // get/set 'msoRequestId' and 'mso-request-id'
107 String requestId = execution.getVariable("msoRequestId")
108 if (requestId != null) {
109 execution.setVariable("mso-request-id", requestId)
111 requestId = execution.getVariable("mso-request-id")
113 execution.setVariable(Prefix + "requestId", requestId)
115 // get/set 'requestId'
116 if (execution.getVariable("requestId") == null) {
117 execution.setVariable("requestId", requestId)
120 //Place holder for additional code.
123 // userParams??? 1) pre-loads indicator, 2) 'auto-activation'
124 // Tag/Value parameters
126 // Map: 'networkInputParams': 'auto-activation''
128 // "requestParameters": {
131 // "name": "someUserParam1",
132 // "value": "someValue1"
137 // String userParams = //use json util to extract "userParams"//
138 // execution.setVariable("networkInputParams", userParams)
139 // else: execution.setVariable("networkInputParams", null)
142 } catch (BpmnError e) {
145 } catch (Exception ex){
146 sendSyncError(execution)
148 String exceptionMessage = "Exception Encountered in CreateNetworkInstance, PreProcessRequest() - " + ex.getMessage()
149 msoLogger.debug(exceptionMessage)
150 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
155 public void sendSyncResponse (DelegateExecution execution) {
156 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
157 execution.setVariable("prefix",Prefix)
159 msoLogger.trace("Start sendSyncResponse")
162 String requestId = execution.getVariable("mso-request-id")
164 // RESTResponse (for API Handler (APIH) Reply Task)
165 String createNetworkRestRequest = """{"requestReferences":{"instanceId":"","requestId":"${requestId}"}}""".trim()
167 msoLogger.debug(" sendSyncResponse to APIH - " + "\n" + createNetworkRestRequest)
168 sendWorkflowResponse(execution, 202, createNetworkRestRequest)
170 } catch (Exception ex) {
171 String exceptionMessage = "Bpmn error encountered in CreateNetworkInstance flow. sendSyncResponse() - " + ex.getMessage()
172 msoLogger.debug(exceptionMessage)
173 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
179 public void getNetworkModelInfo (DelegateExecution execution) {
180 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
181 execution.setVariable("prefix", Prefix)
183 msoLogger.trace("Start getNetworkModelInfo")
187 // For Ala-Carte (sdnc = 1610):
188 // 1. the Network ModelInfo is expected to be sent
189 // via requestDetails.modelInfo (modelType = network).
190 // 2. the Service ModelInfo is expected to be sent but will be IGNORE
191 // via requestDetails.relatedInstanceList.relatedInstance.modelInfo (modelType = service)
193 } catch (Exception ex) {
194 sendSyncError(execution)
195 String exceptionMessage = "Bpmn error encountered in CreateNetworkInstance flow. getNetworkModelInfo() - " + ex.getMessage()
196 msoLogger.debug(exceptionMessage)
197 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
204 public void sendSyncError (DelegateExecution execution) {
205 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
206 execution.setVariable("prefix", Prefix)
208 msoLogger.trace("Start sendSyncError")
212 String requestId = execution.getVariable("mso-request-id")
214 // REST Error (for API Handler (APIH) Reply Task)
215 String syncError = """{"requestReferences":{"instanceId":"","requestId":"${requestId}"}}""".trim()
217 sendWorkflowResponse(execution, 500, syncError)
219 } catch (Exception ex) {
220 msoLogger.debug(" Bpmn error encountered in CreateNetworkInstance flow. sendSyncError() - " + ex.getMessage())
225 public void prepareDBRequestError (DelegateExecution execution) {
226 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
227 execution.setVariable("prefix",Prefix)
230 msoLogger.trace("Start prepareDBRequestError")
232 // set DB Header Authorization
233 setBasicDBAuthHeader(execution, isDebugEnabled)
235 String statusMessage = ""
236 WorkflowException wfe = null
237 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
238 wfe = execution.getVariable("WorkflowException")
239 statusMessage = wfe.getErrorMessage()
242 String requestId = execution.getVariable(Prefix + "requestId")
243 String networkName = execution.getVariable("networkName") !=null ? execution.getVariable("networkName") : ""
244 String networkId = execution.getVariable("networkId") !=null ? execution.getVariable("networkId") : ""
246 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
249 <ns:updateInfraRequest xmlns:ns="http://org.onap.so/requestsdb">
250 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
251 <lastModifiedBy>BPMN</lastModifiedBy>
252 <statusMessage>${MsoUtils.xmlEscape(statusMessage)}</statusMessage>
253 <responseBody></responseBody>
254 <requestStatus>FAILED</requestStatus>
255 <vnfOutputs><network-id>${MsoUtils.xmlEscape(networkId)}</network-id><network-name>${MsoUtils.xmlEscape(networkName)}</network-names></vnfOutputs>
256 </ns:updateInfraRequest>
258 </soapenv:Envelope>"""
260 execution.setVariable(Prefix + "createDBRequest", dbRequest)
261 msoLogger.debug(" DB Adapter Request - " + "\n" + dbRequest)
262 msoLogger.debug(dbRequest)
264 } catch (Exception ex) {
265 String exceptionMessage = " Bpmn error encountered in CreateNetworkInstance flow. prepareDBRequestError() - " + ex.getMessage()
266 msoLogger.debug(exceptionMessage)
267 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
273 public void prepareCompletion (DelegateExecution execution) {
274 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
275 execution.setVariable("prefix",Prefix)
277 msoLogger.trace("Start prepareCompletion")
281 String requestId = execution.getVariable("mso-request-id")
282 String source = execution.getVariable(Prefix + "source")
284 String msoCompletionRequest =
285 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
286 xmlns:ns="http://org.onap/so/request/types/v1">
287 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
288 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
289 <action>CREATE</action>
292 <aetgt:status-message>Network has been created successfully.</aetgt:status-message>
293 <aetgt:mso-bpel-name>BPMN Network action: CREATE</aetgt:mso-bpel-name>
294 </aetgt:MsoCompletionRequest>"""
297 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
300 execution.setVariable(Prefix + "Success", true)
301 execution.setVariable(Prefix + "CompleteMsoProcessRequest", xmlMsoCompletionRequest)
302 msoLogger.debug(" Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest)
304 } catch (Exception ex) {
305 String exceptionMessage = " Bpmn error encountered in CreateNetworkInstance flow. prepareCompletion() - " + ex.getMessage()
306 msoLogger.debug(exceptionMessage)
307 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
317 // **************************************************
318 // Post or Validate Response Section
319 // **************************************************
321 public void postProcessResponse (DelegateExecution execution) {
322 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
323 execution.setVariable("prefix", Prefix)
325 msoLogger.trace("Start postProcessResponse")
329 if (execution.getVariable("CMSO_ResponseCode") == "200") {
330 execution.setVariable(Prefix + "Success", true)
331 msoLogger.trace("CreateNetworkInstance Success ****")
332 // Place holder for additional code.
335 execution.setVariable(Prefix + "Success", false)
336 msoLogger.trace("CreateNetworkInstance Failed in CompletionMsoProces flow!. ****")
341 } catch (Exception ex) {
342 String exceptionMessage = " Bpmn error encountered in CreateNetworkInstance flow. postProcessResponse() - " + ex.getMessage()
343 msoLogger.debug(exceptionMessage)
344 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
351 // *******************************
352 // Build Error Section
353 // *******************************
355 public void processRollbackData (DelegateExecution execution) {
356 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
357 execution.setVariable("prefix", Prefix)
359 msoLogger.trace("Start processRollbackData")
362 //execution.getVariable("orchestrationStatus")
363 //execution.getVariable("networkId")
364 //execution.getVariable("networkName")
365 //networkOutputParams
369 } catch (Exception ex) {
370 msoLogger.debug(" Bpmn error encountered in CreateNetworkInstance flow. callDBCatalog() - " + ex.getMessage())
375 // Prepare for FalloutHandler
376 public void buildErrorResponse (DelegateExecution execution) {
377 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
378 execution.setVariable("prefix", Prefix)
380 msoLogger.debug("DB updateInfraRequest ResponseCode: " + execution.getVariable(Prefix + "dbReturnCode"))
381 msoLogger.debug("DB updateInfraRequest Response: " + execution.getVariable(Prefix + "createDBResponse"))
383 msoLogger.trace("Prepare for FalloutHandler. FAILURE - prepare request for sub-process FalloutHandler.")
385 String falloutHandlerRequest = ""
386 String requestId = execution.getVariable("mso-request-id")
390 WorkflowException wfe = execution.getVariable("WorkflowException")
391 String errorCode = String.valueOf(wfe.getErrorCode())
392 String errorMessage = wfe.getErrorMessage()
393 falloutHandlerRequest =
394 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
395 xmlns:ns="http://org.onap/so/request/types/v1"
396 xmlns:wfsch="http://org.onap/so/workflow/schema/v1">
397 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
398 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
399 <action>CREATE</action>
402 <aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
403 <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorMessage)}</aetgt:ErrorMessage>
404 <aetgt:ErrorCode>${MsoUtils.xmlEscape(errorCode)}</aetgt:ErrorCode>
405 </aetgt:WorkflowException>
406 </aetgt:FalloutHandlerRequest>"""
408 msoLogger.debug(falloutHandlerRequest)
409 execution.setVariable(Prefix + "FalloutHandlerRequest", falloutHandlerRequest)
410 msoLogger.debug(" Overall Error Response going to FalloutHandler: " + "\n" + falloutHandlerRequest)
412 } catch (Exception ex) {
413 String errorException = " Bpmn error encountered in CreateNetworkInstance flow. FalloutHandlerRequest, buildErrorResponse()"
414 msoLogger.debug("Exception error in CreateNetworkInstance flow, buildErrorResponse(): " + ex.getMessage())
415 falloutHandlerRequest =
416 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
417 xmlns:ns="http://org.onap/so/request/types/v1"
418 xmlns:wfsch="http://org.onap/so/workflow/schema/v1">
419 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
420 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
421 <action>CREATE</action>
424 <aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
425 <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorException)}</aetgt:ErrorMessage>
426 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
427 </aetgt:WorkflowException>
428 </aetgt:FalloutHandlerRequest>"""
430 execution.setVariable(Prefix + "FalloutHandlerRequest", falloutHandlerRequest)
431 msoLogger.debug(" Overall Error Response going to FalloutHandler: " + "\n" + falloutHandlerRequest)
437 public void processJavaException(DelegateExecution execution){
438 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
439 execution.setVariable("prefix",Prefix)
441 msoLogger.debug("Caught a Java Exception in " + Prefix)
442 msoLogger.debug("Started processJavaException Method")
443 msoLogger.debug("Variables List: " + execution.getVariables())
444 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
445 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
448 msoLogger.debug("Caught Exception during processJavaException Method: " + e)
449 execution.setVariable("UnexpectedError", "Exception in processJavaException method - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
450 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method" + Prefix)
452 msoLogger.debug("Completed processJavaException Method in " + Prefix)