2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package org.openecomp.mso.bpmn.infrastructure.scripts;
\r
23 import groovy.xml.XmlUtil
25 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
\r
26 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
\r
27 import org.openecomp.mso.bpmn.core.WorkflowException
\r
28 import org.openecomp.mso.bpmn.core.json.JsonUtils
\r
29 import org.openecomp.mso.rest.APIResponse
\r
31 import java.util.UUID;
33 import org.camunda.bpm.engine.delegate.BpmnError
34 import org.camunda.bpm.engine.runtime.Execution
35 import org.apache.commons.lang3.*
36 import org.apache.commons.codec.binary.Base64;
37 import org.springframework.web.util.UriUtils
40 * This groovy class supports the <class>CreateNetworkInstance.bpmn</class> process.
43 public class CreateNetworkInstance extends AbstractServiceTaskProcessor {
44 String Prefix="CRENI_"
45 ExceptionUtil exceptionUtil = new ExceptionUtil()
46 JsonUtils jsonUtil = new JsonUtils()
48 public InitializeProcessVariables(Execution execution){
50 execution.setVariable(Prefix + "source", "")
51 execution.setVariable(Prefix + "Success", false)
53 execution.setVariable(Prefix + "CompleteMsoProcessRequest", "")
54 execution.setVariable(Prefix + "FalloutHandlerRequest", "")
55 execution.setVariable(Prefix + "isSilentSuccess", false)
61 * This method is executed during the preProcessRequest task of the <class>CreateNetworkInstance.bpmn</class> process.
65 // **************************************************
66 // Pre or Prepare Request Section
67 // **************************************************
69 * This method is executed during the preProcessRequest task of the <class>CreateNetworkInstance.bpmn</class> process.
72 public void preProcessRequest (Execution execution) {
73 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
74 execution.setVariable("prefix",Prefix)
76 utils.log("DEBUG", " ***** Inside preProcessRequest() of CreateNetworkInstance Request ***** ", isDebugEnabled)
79 // initialize flow variables
80 InitializeProcessVariables(execution)
82 String sdncVersion = execution.getVariable("sdncVersion")
83 if (sdncVersion == null || sdncVersion == '1610') {
84 // 'a-la-cart' default, sdncVersion = '1610'
85 execution.setVariable("sdncVersion", "1610")
86 String bpmnRequest = execution.getVariable("bpmnRequest")
87 // set 'disableRollback'
88 if (bpmnRequest != null) {
89 String disableRollback = jsonUtil.getJsonValue(bpmnRequest, "requestDetails.requestInfo.suppressRollback")
90 if (disableRollback != null) {
91 execution.setVariable("disableRollback", disableRollback)
92 utils.log("DEBUG", "Received 'suppressRollback': " + disableRollback , isDebugEnabled)
94 execution.setVariable("disableRollback", false)
96 utils.log("DEBUG", " Set 'disableRollback' : " + execution.getVariable("disableRollback") , isDebugEnabled)
98 String dataErrorMessage = " Invalid 'bpmnRequest' request."
99 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
100 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
104 // 'macro' TEST ONLY, sdncVersion = '1702'
105 utils.log("DEBUG", " 'disableRollback' : " + execution.getVariable("disableRollback") , isDebugEnabled)
108 // get/set 'msoRequestId' and 'mso-request-id'
\r
109 String requestId = execution.getVariable("msoRequestId")
110 if (requestId != null) {
111 execution.setVariable("mso-request-id", requestId)
\r
113 requestId = execution.getVariable("mso-request-id")
\r
115 execution.setVariable(Prefix + "requestId", requestId)
117 // get/set 'requestId'
118 if (execution.getVariable("requestId") == null) {
119 execution.setVariable("requestId", requestId)
122 //Place holder for additional code.
125 // userParams??? 1) pre-loads indicator, 2) 'auto-activation'
126 // Tag/Value parameters
128 // Map: 'networkInputParams': 'auto-activation''
130 // "requestParameters": {
133 // "name": "someUserParam1",
134 // "value": "someValue1"
139 // String userParams = //use json util to extract "userParams"//
140 // execution.setVariable("networkInputParams", userParams)
141 // else: execution.setVariable("networkInputParams", null)
144 } catch (BpmnError e) {
147 } catch (Exception ex){
148 sendSyncError(execution)
150 String exceptionMessage = "Exception Encountered in CreateNetworkInstance, PreProcessRequest() - " + ex.getMessage()
151 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
152 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
157 public void sendSyncResponse (Execution execution) {
158 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
159 execution.setVariable("prefix",Prefix)
161 utils.log("DEBUG", " ***** Inside sendSyncResponse() of CreateNetworkInstance ***** ", isDebugEnabled)
164 String requestId = execution.getVariable("mso-request-id")
\r
166 // RESTResponse (for API Handler (APIH) Reply Task)
167 String createNetworkRestRequest = """{"requestReferences":{"instanceId":"","requestId":"${requestId}"}}""".trim()
169 utils.log("DEBUG", " sendSyncResponse to APIH - " + "\n" + createNetworkRestRequest, isDebugEnabled)
170 sendWorkflowResponse(execution, 202, createNetworkRestRequest)
172 } catch (Exception ex) {
173 String exceptionMessage = "Bpmn error encountered in CreateNetworkInstance flow. sendSyncResponse() - " + ex.getMessage()
174 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
175 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
181 public void getNetworkModelInfo (Execution execution) {
182 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
183 execution.setVariable("prefix", Prefix)
185 utils.log("DEBUG", " ***** Inside getNetworkModelInfo() of CreateNetworkInstance ***** ", isDebugEnabled)
189 // "networkModelInfo" is expected to be sent
190 String networkModelInfo = execution.getVariable("networkModelInfo")
191 utils.log("DEBUG", " networkModelInfo - " + networkModelInfo, isDebugEnabled)
193 // "serviceModelInfo" is expected to be sent
194 String serviceModelInfo = execution.getVariable("serviceModelInfo")
195 utils.log("DEBUG", " serviceModelInfo - " + serviceModelInfo, isDebugEnabled)
198 } catch (Exception ex) {
199 sendSyncError(execution)
200 String exceptionMessage = "Bpmn error encountered in CreateNetworkInstance flow. getNetworkModelInfo() - " + ex.getMessage()
201 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
202 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
209 public void sendSyncError (Execution execution) {
210 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
211 execution.setVariable("prefix", Prefix)
213 utils.log("DEBUG", " ***** Inside sendSyncError() of CreateNetworkInstance ***** ", isDebugEnabled)
217 String requestId = execution.getVariable("mso-request-id")
\r
219 // REST Error (for API Handler (APIH) Reply Task)
220 String syncError = """{"requestReferences":{"instanceId":"","requestId":"${requestId}"}}""".trim()
222 sendWorkflowResponse(execution, 500, syncError)
224 } catch (Exception ex) {
225 utils.log("DEBUG", " Bpmn error encountered in CreateNetworkInstance flow. sendSyncError() - " + ex.getMessage(), isDebugEnabled)
230 public void prepareDBRequestError (Execution execution) {
231 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
232 execution.setVariable("prefix",Prefix)
235 utils.log("DEBUG", " ***** Inside prepareDBRequestError() of CreateNetworkInstance ***** ", isDebugEnabled)
237 String statusMessage = ""
238 WorkflowException wfe = null
239 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
240 wfe = execution.getVariable("WorkflowException")
241 statusMessage = wfe.getErrorMessage()
244 String requestId = execution.getVariable(Prefix + "requestId")
245 String networkName = execution.getVariable("networkName") !=null ? execution.getVariable("networkName") : ""
246 String networkId = execution.getVariable("networkId") !=null ? execution.getVariable("networkId") : ""
248 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
251 <ns:updateInfraRequest xmlns:ns="http://org.openecomp.mso/requestsdb">
\r
252 <requestId>${requestId}</requestId>
253 <lastModifiedBy>BPMN</lastModifiedBy>
254 <statusMessage>${statusMessage}</statusMessage>
255 <responseBody></responseBody>
256 <requestStatus>FAILED</requestStatus>
257 <vnfOutputs><network-id>${networkId}</network-id><network-name>${networkName}</network-names></vnfOutputs>
258 </ns:updateInfraRequest>
260 </soapenv:Envelope>"""
262 execution.setVariable(Prefix + "createDBRequest", dbRequest)
263 utils.log("DEBUG", " DB Adapter Request - " + "\n" + dbRequest, isDebugEnabled)
264 utils.logAudit(dbRequest)
266 } catch (Exception ex) {
267 String exceptionMessage = " Bpmn error encountered in CreateNetworkInstance flow. prepareDBRequestError() - " + ex.getMessage()
268 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
269 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
275 public void prepareCompletion (Execution execution) {
276 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
277 execution.setVariable("prefix",Prefix)
279 utils.log("DEBUG", " ***** Inside prepareCompletion() of CreateNetworkInstance ***** ", isDebugEnabled)
283 String requestId = execution.getVariable("mso-request-id")
\r
284 String source = execution.getVariable(Prefix + "source")
286 String msoCompletionRequest =
287 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
288 xmlns:ns="http://org.openecomp/mso/request/types/v1">
\r
289 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
290 <request-id>${requestId}</request-id>
291 <action>CREATE</action>
294 <aetgt:status-message>Network has been created successfully.</aetgt:status-message>
295 <aetgt:mso-bpel-name>BPMN Network action: CREATE</aetgt:mso-bpel-name>
296 </aetgt:MsoCompletionRequest>"""
299 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
302 execution.setVariable(Prefix + "Success", true)
303 execution.setVariable(Prefix + "CompleteMsoProcessRequest", xmlMsoCompletionRequest)
304 utils.log("DEBUG", " Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
306 } catch (Exception ex) {
307 String exceptionMessage = " Bpmn error encountered in CreateNetworkInstance flow. prepareCompletion() - " + ex.getMessage()
308 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
309 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
319 // **************************************************
320 // Post or Validate Response Section
321 // **************************************************
323 public void postProcessResponse (Execution execution) {
324 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
325 execution.setVariable("prefix", Prefix)
327 utils.log("DEBUG", " ***** Inside postProcessResponse() of CreateNetworkInstance ***** ", isDebugEnabled)
331 if (execution.getVariable("CMSO_ResponseCode") == "200") {
332 execution.setVariable(Prefix + "Success", true)
333 utils.log("DEBUG", " ***** CreateNetworkInstance Success ***** ", isDebugEnabled)
334 // Place holder for additional code.
337 execution.setVariable(Prefix + "Success", false)
338 utils.log("DEBUG", " ***** CreateNetworkInstance Failed in CompletionMsoProces flow!. ***** ", isDebugEnabled)
343 } catch (Exception ex) {
344 String exceptionMessage = " Bpmn error encountered in CreateNetworkInstance flow. postProcessResponse() - " + ex.getMessage()
345 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
346 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
353 // *******************************
354 // Build Error Section
355 // *******************************
357 public void processRollbackData (Execution execution) {
358 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
359 execution.setVariable("prefix", Prefix)
361 utils.log("DEBUG", " ***** Inside processRollbackData() of CreateNetworkInstance ***** ", isDebugEnabled)
364 //execution.getVariable("orchestrationStatus")
365 //execution.getVariable("networkId")
366 //execution.getVariable("networkName")
367 //networkOutputParams
371 } catch (Exception ex) {
372 utils.log("DEBUG", " Bpmn error encountered in CreateNetworkInstance flow. callDBCatalog() - " + ex.getMessage(), isDebugEnabled)
377 // Prepare for FalloutHandler
378 public void buildErrorResponse (Execution execution) {
379 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
380 execution.setVariable("prefix", Prefix)
382 utils.log("DEBUG", " ***** Prepare for FalloutHandler. FAILURE - prepare request for sub-process FalloutHandler. *****", isDebugEnabled)
384 String falloutHandlerRequest = ""
385 String requestId = execution.getVariable("mso-request-id")
\r
388 WorkflowException wfe = execution.getVariable("WorkflowException")
389 String errorCode = String.valueOf(wfe.getErrorCode())
390 String errorMessage = wfe.getErrorMessage()
391 falloutHandlerRequest =
392 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
393 xmlns:ns="http://org.openecomp/mso/request/types/v1"
\r
394 xmlns:wfsch="http://org.openecomp/mso/workflow/schema/v1">
\r
395 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
396 <request-id>${requestId}</request-id>
397 <action>CREATE</action>
400 <aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
401 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
402 <aetgt:ErrorCode>${errorCode}</aetgt:ErrorCode>
403 </aetgt:WorkflowException>
404 </aetgt:FalloutHandlerRequest>"""
406 utils.logAudit(falloutHandlerRequest)
407 execution.setVariable(Prefix + "FalloutHandlerRequest", falloutHandlerRequest)
408 utils.log("DEBUG", " Overall Error Response going to FalloutHandler: " + "\n" + falloutHandlerRequest, isDebugEnabled)
410 } catch (Exception ex) {
411 String errorException = " Bpmn error encountered in CreateNetworkInstance flow. FalloutHandlerRequest, buildErrorResponse() - " + ex.getMessage()
412 utils.log("DEBUG", errorException, isDebugEnabled)
413 falloutHandlerRequest =
414 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
415 xmlns:ns="http://org.openecomp/mso/request/types/v1"
\r
416 xmlns:wfsch="http://org.openecomp/mso/workflow/schema/v1">
\r
417 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
418 <request-id>${requestId}</request-id>
419 <action>CREATE</action>
422 <aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
423 <aetgt:ErrorMessage>${errorException}</aetgt:ErrorMessage>
424 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
425 </aetgt:WorkflowException>
426 </aetgt:FalloutHandlerRequest>"""
428 execution.setVariable(Prefix + "FalloutHandlerRequest", falloutHandlerRequest)
429 utils.log("DEBUG", " Overall Error Response going to FalloutHandler: " + "\n" + falloutHandlerRequest, isDebugEnabled)
435 public void processJavaException(Execution execution){
436 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
437 execution.setVariable("prefix",Prefix)
439 utils.log("DEBUG", "Caught a Java Exception in " + Prefix, isDebugEnabled)
440 utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
441 utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
442 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
443 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
446 utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
447 execution.setVariable("UnexpectedError", "Exception in processJavaException method - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
448 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method" + Prefix)
450 utils.log("DEBUG", "Completed processJavaException Method in " + Prefix, isDebugEnabled)