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 com.att.bpm.scripts;
23 import groovy.xml.XmlUtil
26 import org.openecomp.mso.bpmn.core.json.JsonUtils
27 import org.openecomp.mso.bpmn.core.WorkflowException
28 import org.openecomp.mso.rest.APIResponse
29 import org.openecomp.mso.rest.RESTClient
30 import org.openecomp.mso.rest.RESTConfig
32 import java.util.UUID;
34 import org.camunda.bpm.engine.delegate.BpmnError
35 import org.camunda.bpm.engine.runtime.Execution
36 import org.json.JSONObject;
37 import org.apache.commons.lang3.*
38 import org.apache.commons.codec.binary.Base64;
40 import org.springframework.web.util.UriUtils;
43 * This groovy class supports the <class>CreateServiceInstance.bpmn</class> process.
46 public class CreateServiceInstanceInfra extends AbstractServiceTaskProcessor {
48 String Prefix="CRESI_"
49 ExceptionUtil exceptionUtil = new ExceptionUtil()
50 JsonUtils jsonUtil = new JsonUtils()
51 VidUtils vidUtils = new VidUtils()
54 * This method is executed during the preProcessRequest task of the <class>CreateServiceInstance.bpmn</class> process.
57 public InitializeProcessVariables(Execution execution){
58 /* Initialize all the process variables in this block */
60 execution.setVariable("CRESI_CreateServiceInstanceJasonRequest", "")
61 execution.setVariable("CRESI_globalSubscriberId", "")
62 execution.setVariable("CRESI_serviceInstanceName", "")
63 execution.setVariable("CRESI_newServiceInstanceId", "")
64 execution.setVariable("CRESI_messageId", "")
65 execution.setVariable("CRESI_requestId", "")
67 execution.setVariable("CRESI_queryAAIGlobalCustomerIdUrlRequest", "")
68 execution.setVariable("CRESI_queryAAIGlobalCustomerIdResponse", "")
69 execution.setVariable("CRESI_queryAAIGlobalCustomerIdCode", "")
71 execution.setVariable("CRESI_queryAAISINameUrlRequest", "")
72 execution.setVariable("CRESI_queryAAISINamePayloadRequest", "")
73 execution.setVariable("CRESI_queryAAISINameResponse", "")
74 execution.setVariable("CRESI_queryAAISINameCode", "")
76 execution.setVariable("CRESI_createSIinAAIUrlRequest", "")
77 execution.setVariable("CRESI_createSIinAAIPayloadRequest", "")
78 execution.setVariable("CRESI_createSIinAAIResponse", "")
79 execution.setVariable("CRESI_createSIinAAICode", "")
81 execution.setVariable("CRESI_createDBRequest", "")
82 execution.setVariable("CRESI_createDBResponse", "")
83 execution.setVariable("CRESI_createDBCode", "")
85 execution.setVariable("CRESI_createDBInfraErrorRequest", "")
86 execution.setVariable("CRESI_errorDBInfraErrorResponse", "")
87 execution.setVariable("CRESI_errorDBInfraErrorErrorCode", "")
89 execution.setVariable("CRESI_CompleteMsoProcessRequest", "")
90 execution.setVariable("CRESI_FalloutHandlerRequest", "")
91 execution.setVariable("CRESI_Success", false)
92 execution.setVariable("CRESI_unexpectedError", "")
96 // **************************************************
97 // Pre or Prepare Request Section
98 // **************************************************
100 * This method is executed during the preProcessRequest task of the <class>CreateServiceInstance.bpmn</class> process.
103 public void preProcessRequest (Execution execution) {
104 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
105 execution.setVariable("prefix",Prefix)
107 utils.log("DEBUG", " ***** Inside preProcessRequest CreateServiceInstanceInfra Request ***** ", isDebugEnabled)
110 // initialize flow variables
111 InitializeProcessVariables(execution)
113 // check for incoming json message/input
114 String createServiceInstanceIncoming = execution.getVariable("bpmnRequest")
115 utils.logAudit(createServiceInstanceIncoming)
116 execution.setVariable("CRESI_CreateServiceInstanceJasonRequest", createServiceInstanceIncoming);
117 println 'createServiceInstanceIncoming - ' + createServiceInstanceIncoming
120 String requestId = execution.getVariable("att-mso-request-id")
121 execution.setVariable("CRESI_requestId", requestId)
123 String serviceInstanceId = execution.getVariable("serviceInstanceId")
124 execution.setVariable("serviceInstanceId", serviceInstanceId)
126 String requestAction = execution.getVariable("requestAction")
127 execution.setVariable("requestAction", requestAction)
129 String source = jsonUtil.getJsonValue(createServiceInstanceIncoming, "requestDetails.requestInfo.source")
130 execution.setVariable("CRESI_source", source)
132 // extract globalSubscriberId
133 String globalSubscriberId = jsonUtil.getJsonValue(createServiceInstanceIncoming, "requestDetails.subscriberInfo.globalSubscriberId")
136 String messageId = execution.getVariable("CRESI_messageId") // for testing
137 if (messageId == null || messageId == "") {
138 messageId = UUID.randomUUID()
139 utils.log("DEBUG", " CRESI_messageId, random generated: " + messageId, isDebugEnabled)
141 utils.log("DEBUG", " CRESI_messageId, pre-assigned: " + messageId, isDebugEnabled)
143 execution.setVariable("CRESI_messageId", messageId)
145 // verify element global-customer-id is sent from JSON input, throw exception if missing
146 if ((globalSubscriberId == null) || (globalSubscriberId.isEmpty())) {
147 String dataErrorMessage = " Element 'globalSubscriberId' is missing. "
148 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
151 execution.setVariable("CRESI_globalSubscriberId", globalSubscriberId)
155 AaiUtil aaiUriUtil = new AaiUtil(this)
156 String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
157 String aaiNamespace = aaiUriUtil.getNamespaceFromUri(aai_uri)
158 logDebug('AAI namespace is: ' + aaiNamespace, isDebugEnabled)
159 execution.setVariable("CRESI_aaiNamespace","${aaiNamespace}")
161 String newServiceInstanceId = execution.getVariable("CRESI_testServiceInstanceId") // for testing variable
162 if ((newServiceInstanceId) == null || (newServiceInstanceId.isEmpty())) {
163 newServiceInstanceId = UUID.randomUUID().toString()
164 utils.log("DEBUG", " Generated new Service Instance: " + newServiceInstanceId , isDebugEnabled) // generated
166 utils.log("DEBUG", " Assigned new Service Instance: " + newServiceInstanceId , isDebugEnabled)
168 newServiceInstanceId = UriUtils.encode(newServiceInstanceId,"UTF-8")
169 execution.setVariable("CRESI_newServiceInstanceId", newServiceInstanceId)
171 } catch (BpmnError e) {
174 } catch (Exception ex){
175 String exceptionMessage = "Bpmn error encountered in CreateServiceInstanceInfra flow. Unexpected from method preProcessRequest() - " + ex.getMessage()
176 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
181 public void sendSyncResponse (Execution execution) {
182 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
183 execution.setVariable("prefix",Prefix)
185 utils.log("DEBUG", " ***** Inside sendSyncResponse of CreateServiceInstanceInfra ***** ", isDebugEnabled)
188 String newServiceInstanceId = execution.getVariable("CRESI_newServiceInstanceId")
189 String requestId = execution.getVariable("att-mso-request-id")
191 // RESTResponse (for API Handler (APIH) Reply Task)
192 String syncResponse ="""{"requestReferences":{"instanceId":"${newServiceInstanceId}","requestId":"${requestId}"}}""".trim()
194 utils.log("DEBUG", " sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse, isDebugEnabled)
195 sendWorkflowResponse(execution, 202, syncResponse)
197 } catch (Exception ex) {
198 String exceptionMessage = "Bpmn error encountered in CreateServiceInstanceInfra flow. Unexpected from method sendSyncResponse() - " + ex.getMessage()
199 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
204 public void callRESTQueryAAIGlobalSubscriberId (Execution execution) {
205 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
206 execution.setVariable("prefix",Prefix)
208 utils.log("DEBUG", " ***** Inside callRESTQueryAAICustomer of CreateServiceInstanceInfra ***** " , isDebugEnabled)
212 String messageId = execution.getVariable("CRESI_requestId")
213 String globalSubscriberId = execution.getVariable("CRESI_globalSubscriberId")
214 globalSubscriberId = UriUtils.encode(globalSubscriberId,"UTF-8")
216 // Prepare AA&I url with globalCustomerId
217 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
218 AaiUtil aaiUriUtil = new AaiUtil(this)
219 String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
220 String queryAAISubscriberIdUrlRequest = "${aai_endpoint}${aai_uri}/${globalSubscriberId}"
221 utils.logAudit(queryAAISubscriberIdUrlRequest)
222 utils.log("DEBUG", " ***** AAI Query Subscriber Id Url: " + queryAAISubscriberIdUrlRequest, isDebugEnabled)
223 execution.setVariable("CRESI_queryAAIGlobalCustomerIdUrlRequest", queryAAISubscriberIdUrlRequest)
225 String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))
227 RESTConfig config = new RESTConfig(queryAAISubscriberIdUrlRequest);
228 RESTClient client = new RESTClient(config).addHeader("X-TransactionId", messageId)
229 .addHeader("X-FromAppId", "MSO")
230 .addHeader("Content-Type", "application/xml")
231 .addHeader("Accept","application/xml");
232 if (basicAuthCred != null && !"".equals(basicAuthCred)) {
233 client.addAuthorizationHeader(basicAuthCred)
235 APIResponse response = client.get()
236 String returnCode = response.getStatusCode()
237 execution.setVariable("CRESI_queryAAIGlobalCustomerIdCode", returnCode)
238 utils.log("DEBUG", " ***** AAI Query Customer Subscriber Id Response Code : " + returnCode, isDebugEnabled)
240 String aaiResponseAsString = response.getResponseBodyAsString()
241 execution.setVariable("CRESI_queryAAIGlobalCustomerIdResponse", aaiResponseAsString)
242 utils.logAudit(aaiResponseAsString)
244 if (returnCode=='200') {
245 // Customer found by ID. FLow to proceed.
246 utils.log("DEBUG", " CRESI_queryAAIGlobalCustomerIdResponse : " + aaiResponseAsString, isDebugEnabled)
249 //we might verify that service-subscription with matching name exists
250 //and throw error if not. If not checked, we will get exception in subsequent step on Create call
251 //in 1610 we assume both customer & service subscription were pre-created
254 if (returnCode=='404') {
255 String errorMessage = " Customer Global Id not found (404) in AAI, Global Subscriber id: " + globalSubscriberId
256 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
259 if (aaiResponseAsString.contains("RESTFault")) {
260 // build WorkflowException & throw new BpmnError("MSOWorkflowException")
261 WorkflowException workflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
262 execution.setVariable("WorkflowException", workflowException)
263 throw new BpmnError("MSOWorkflowException")
267 String errorMessage = " Unexpected Error Response from AAI during callRESTQueryAAICustomerSubcriberId() - " + returnCode
268 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
274 } catch (BpmnError e) {
277 } catch (Exception ex) {
278 // try error in method block
279 String exceptionMessage = "Bpmn error encountered in CreateServiceInstanceInfra flow. Unexpected Error during method callRESTQueryAAICustomerSubcriberId() - " + ex.getMessage()
280 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
286 public void callRESTQueryAAISIName (Execution execution) {
287 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
288 execution.setVariable("prefix",Prefix)
290 utils.log("DEBUG", " ***** Inside callRESTQueryAAISIName of CreateServiceInstanceInfra ***** " , isDebugEnabled)
294 String messageId = execution.getVariable("CRESI_requestId")
295 String globalSubscriberId = execution.getVariable("CRESI_globalSubscriberId")
296 globalSubscriberId = UriUtils.encode(globalSubscriberId,"UTF-8")
298 // extract serviceType
299 String createServiceInstanceIncoming = execution.getVariable("CRESI_CreateServiceInstanceJasonRequest");
300 String serviceInstanceName = jsonUtil.getJsonValue(createServiceInstanceIncoming, "requestDetails.requestInfo.instanceName")
301 serviceInstanceName = UriUtils.encode(serviceInstanceName,'UTF-8')
302 String serviceType = jsonUtil.getJsonValue(createServiceInstanceIncoming, "requestDetails.modelInfo.modelName")
303 serviceType = UriUtils.encode(serviceType,'UTF-8')
306 //String aai_endpoint = execution.getVariable("URN_aai_endpoint")
307 AaiUtil aaiUriUtil = new AaiUtil(this)
308 String aai_uri = aaiUriUtil.getSearchNodesQueryEndpoint(execution)
310 // seach by service instance name
312 // Currently not designed, but this would search for service-instance-name within realm of customer:
313 // https://{serverURL}/aai/{version}/business/customers/customer/{globalCustID}/service-subscriptions/service-subscription/{serviceType}/service-instances?service-instance-name={serviceInstanceName}
314 //search for service-instance-name globally:
315 String queryAAISINameUrlRequest = "${aai_uri}?search-node-type=service-instance&filter=service-instance-name:EQUALS:${serviceInstanceName}"
316 utils.log("DEBUG", " ***** AAI Query Service Name Url: " + queryAAISINameUrlRequest, isDebugEnabled)
318 utils.logAudit(queryAAISINameUrlRequest)
319 execution.setVariable("CRESI_queryAAISINameUrlRequest", queryAAISINameUrlRequest)
321 String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))
323 RESTConfig config = new RESTConfig(queryAAISINameUrlRequest);
324 RESTClient client = new RESTClient(config).addHeader("X-TransactionId", messageId)
325 .addHeader("X-FromAppId", "MSO")
326 .addHeader("Content-Type", "application/xml")
327 .addHeader("Accept","application/xml");
328 if (basicAuthCred != null && !"".equals(basicAuthCred)) {
329 client.addAuthorizationHeader(basicAuthCred)
331 APIResponse response = client.get()
332 String returnCode = response.getStatusCode()
333 execution.setVariable("CRESI_queryAAISINameCode", returnCode)
334 utils.log("DEBUG", " ***** AAI Query Service Instance Name Response Code : " + returnCode, isDebugEnabled)
336 String aaiResponseAsString = response.getResponseBodyAsString()
337 utils.log("DEBUG", " ***** AAI Query Service Instance Name Response : " +'\n'+ aaiResponseAsString, isDebugEnabled)
339 if (returnCode=='200') {
340 utils.logAudit(aaiResponseAsString)
341 execution.setVariable("CRESI_queryAAISINameResponse", aaiResponseAsString)
343 if ( (aaiResponseAsString != null) && (aaiResponseAsString.contains("service-instance")) ) {
344 // SI with same name was found
345 serviceInstanceName = UriUtils.decode(serviceInstanceName,'UTF-8')
346 String errorMessage = " Stopped creating Service Instance, already exists in AAI. Service instance name: " + serviceInstanceName
347 utils.log("DEBUG", errorMessage, isDebugEnabled)
348 exceptionUtil.buildWorkflowException(execution, 2500, errorMessage)
350 utils.log("DEBUG", "AAI return code 200, but no content found matching ServiceInstance name", isDebugEnabled)
351 //Actual meaning is 404 Not Found
352 execution.setVariable("CRESI_queryAAISINameCode", '404')
356 if (returnCode=='404') {
357 utils.log("DEBUG", " AAI Query return code = '404'. Proceed with the Create Service Instance !!! ", isDebugEnabled)
360 if (aaiResponseAsString.contains("RESTFault")) {
361 // build WorkflowException
362 WorkflowException workflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
363 execution.setVariable("WorkflowException", workflowException)
367 String errorMessage = " Unexpected Error Response from AAI during callRESTQueryAAISIName() - " + returnCode
368 exceptionUtil.buildWorkflowException(execution, 2500, errorMessage)
374 } catch (BpmnError e) {
377 } catch (Exception excp) {
378 // try error for method block
379 String exceptionMessage = "Bpmn error encountered in CreateServiceInstanceInfra flow in method callRESTQueryAAISIName(). Error was - " + excp.getMessage()
380 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
386 public void callRESTCreateServiceInstanceInAAI(Execution execution) {
387 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
388 execution.setVariable("prefix", Prefix)
390 utils.log("DEBUG", " ***** Inside callRESTCreateServiceInstanceInAAI of CreateServiceInstanceInfra ***** " , isDebugEnabled)
395 String messageId = execution.getVariable("CRESI_messageId")
396 String newServiceInstanceId = execution.getVariable("CRESI_newServiceInstanceId")
398 String globalSubcriberId = execution.getVariable("CRESI_globalSubscriberId")
399 globalSubcriberId = UriUtils.encode(globalSubcriberId,"UTF-8")
401 // get variable within incoming json
402 String createServiceInstanceIncoming = execution.getVariable("CRESI_CreateServiceInstanceJasonRequest");
403 String serviceType = jsonUtil.getJsonValue(createServiceInstanceIncoming, "requestDetails.requestParameters.subscriptionServiceType")
404 if (serviceType != null || serviceType != "") {
405 serviceType = UriUtils.encode(serviceType,"UTF-8")
408 String personaModelId = jsonUtil.getJsonValue(createServiceInstanceIncoming, "requestDetails.modelInfo.modelInvariantId")
409 String personaModelVersion = jsonUtil.getJsonValue(createServiceInstanceIncoming, "requestDetails.modelInfo.modelVersion")
410 String workloadContext = jsonUtil.getJsonValue(createServiceInstanceIncoming, "requestDetails.modelInfo.workload-context")
412 String serviceInstanceName = jsonUtil.getJsonValue(createServiceInstanceIncoming, "requestDetails.requestInfo.instanceName")
415 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
416 AaiUtil aaiUriUtil = new AaiUtil(this)
417 String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
418 String createServiceInstanceAAIUrlRequest = "${aai_endpoint}${aai_uri}/${globalSubcriberId}/service-subscriptions/service-subscription/${serviceType}/service-instances/service-instance/${newServiceInstanceId}"
419 utils.log("DEBUG", " ***** AAI Create Service Instance Url: " + createServiceInstanceAAIUrlRequest, isDebugEnabled)
421 utils.logAudit(createServiceInstanceAAIUrlRequest)
422 execution.setVariable("CRESI_createSIinAAIUrlRequest", createServiceInstanceAAIUrlRequest)
424 //Prepare payload (PUT)
425 String schemaVersion = aaiUriUtil.getNamespaceFromUri(aai_uri)
427 String createServiceInstancePayload =
428 """<service-instance xmlns="${execution.getVariable("CRESI_aaiNamespace")}">
429 <service-instance-name>${serviceInstanceName}</service-instance-name>
430 <persona-model-id>${personaModelId}</persona-model-id>
431 <persona-model-version>${personaModelVersion}</persona-model-version>
435 utils.logAudit(createServiceInstancePayload)
436 execution.setVariable("CRESI_createSIinAAIPayloadRequest", createServiceInstancePayload)
437 utils.log("DEBUG", " 'payload' to create Service Instance in AAI - " + "\n" + createServiceInstancePayload, isDebugEnabled)
439 String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))
441 RESTConfig config = new RESTConfig(createServiceInstanceAAIUrlRequest);
442 RESTClient client = new RESTClient(config).addHeader("X-TransactionId", messageId)
443 .addHeader("X-FromAppId", "MSO")
444 .addHeader("Content-Type", "application/xml")
445 .addHeader("Accept","application/xml");
446 if (basicAuthCred != null && !"".equals(basicAuthCred)) {
447 client.addAuthorizationHeader(basicAuthCred)
449 APIResponse response = client.httpPut(createServiceInstancePayload)
450 String returnCode = response.getStatusCode()
451 execution.setVariable("CRESI_createSIinAAICode", returnCode)
452 utils.log("DEBUG", " ***** AAI Create Service Instance Response Code : " + returnCode, isDebugEnabled)
454 String aaiResponseAsString = response.getResponseBodyAsString()
455 utils.logAudit(aaiResponseAsString)
457 if (returnCode.toInteger() > 199 && returnCode.toInteger() < 203) {
458 //200 OK 201 CREATED 202 ACCEPTED
459 utils.log("DEBUG", " AAI Create Service Instance Success REST Response.", isDebugEnabled)
462 if (returnCode=='404') {
463 String dataErrorMessage = " AAI Create Service Instance Failed, Error 404. Proposed new Create Instance Id was: " + newServiceInstanceId
464 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
467 if (aaiResponseAsString.contains("RESTFault")) {
468 // build WorkflowException & throw new BpmnError("MSOWorkflowException")
469 WorkflowException workflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
470 execution.setVariable("WorkflowException", workflowException)
471 throw new BpmnError("MSOWorkflowException")
475 String dataErrorMessage = "Bpmn error encountered in CreateServiceInstanceInfra flow. Unexpected Error during create call in AAI - " + returnCode
476 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
481 } catch (BpmnError e) {
484 } catch (Exception excep) {
485 // try error in method block
486 String exceptionMessage = "Bpmn error encountered in CreateServiceInstanceInfra flow. Unexpected Error from method callRESTCreateServiceInstanceInAAI() - " + excep.getMessage()
487 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
493 // *******************************
494 // Build DB request Section
495 // *******************************
496 public void prepareDBRequest (Execution execution) {
497 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
498 execution.setVariable("prefix", Prefix)
501 utils.log("DEBUG", " ***** Inside prepareDBRequest of CreateServiceInstanceInfra ***** ", isDebugEnabled)
503 String requestId = execution.getVariable("CRESI_requestId")
504 String statusMessage = "Service Instance successfully created."
505 String serviceInstanceId = execution.getVariable("CRESI_newServiceInstanceId")
507 //TODO - verify the format for Service Instance Create,
509 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
512 <ns:updateInfraRequest xmlns:ns="http://com.att.mso/requestsdb">
513 <requestId>${requestId}</requestId>
514 <lastModifiedBy>BPMN</lastModifiedBy>
515 <statusMessage>${statusMessage}</statusMessage>
516 <responseBody></responseBody>
517 <requestStatus>COMPLETED</requestStatus>
518 <progress>100</progress>
520 <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
521 </ns:updateInfraRequest>
523 </soapenv:Envelope>"""
525 String buildDeleteDBRequestAsString = utils.formatXml(dbRequest)
526 execution.setVariable("CRESI_createDBRequest", buildDeleteDBRequestAsString)
527 utils.logAudit(buildDeleteDBRequestAsString)
529 } catch (Exception ex) {
530 // try error in method block
531 String exceptionMessage = "Bpmn error encountered in CreateServiceInstanceInfra flow. Unexpected Error from method prepareDBRequest() - " + ex.getMessage()
532 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
539 // *****************************************
540 // Prepare Completion request Section
541 // *****************************************
542 public void postProcessResponse (Execution execution) {
543 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
544 execution.setVariable("prefix", Prefix)
546 utils.log("DEBUG", " ***** Inside postProcessResponse of CreateNetworkInstanceInfra ***** ", isDebugEnabled)
549 // Display Success scenario for DB update Response:
550 String dbReturnCode = execution.getVariable("CRESI_createDBCode")
551 utils.log("DEBUG", " ***** Success DB Update Response Code : " + dbReturnCode, isDebugEnabled)
552 utils.log("DEBUG", " ***** Success DB Update Response String: " + '\n' + execution.getVariable("CRESI_createDBResponse"), isDebugEnabled)
554 if (dbReturnCode == "200") {
555 String source = execution.getVariable("CRESI_source")
556 String requestId = execution.getVariable("CRESI_requestId")
558 String msoCompletionRequest =
559 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://ecomp.att.com/mso/workflow/schema/v1"
560 xmlns:ns="http://ecomp.att.com/mso/request/types/v1">
561 <request-info xmlns="http://ecomp.att.com/mso/infra/vnf-request/v1">
562 <request-id>${requestId}</request-id>
563 <action>CREATE</action>
564 <source>${source}</source>
566 <aetgt:status-message>Service Instance has been created successfully.</aetgt:status-message>
567 <aetgt:mso-bpel-name>BPMN Service Instance action: CREATE</aetgt:mso-bpel-name>
568 </aetgt:MsoCompletionRequest>"""
571 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
573 utils.logAudit(xmlMsoCompletionRequest)
574 execution.setVariable("CRESI_Success", true)
575 execution.setVariable("CRESI_CompleteMsoProcessRequest", xmlMsoCompletionRequest)
576 utils.log("DEBUG", " SUCCESS flow, going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
579 String exceptionMessage = "Bpmn error encountered in CreateServiceInstanceInfra flow. Unexpected Error from DB adapter, return code: " + dbReturnCode
580 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, exceptionMessage)
584 } catch (BpmnError e) {
587 } catch (Exception ex) {
588 // try error in method block
589 String exceptionMessage = "Bpmn error encountered in CreateServiceInstance flow. Unexpected Error from method postProcessResponse() - " + ex.getMessage()
590 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
597 // *******************************
598 // Build Error Section
599 // *******************************
600 public void prepareDBRequestError (Execution execution) {
601 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
602 execution.setVariable("prefix", Prefix)
604 utils.log("DEBUG", " ***** Inside prepareDBRequestError of CreateServiceInstanceInfra ***** ", isDebugEnabled)
607 String requestId = execution.getVariable("CRESI_requestId")
608 String statusMessage = ""
609 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
610 WorkflowException wfe = execution.getVariable("WorkflowException")
611 statusMessage = wfe.getErrorMessage()
614 statusMessage = "Encountered Error during CreateServiceInstance proccessing. "
617 //TODO - verify the format for Service Instance Create,
619 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
622 <ns:updateInfraRequest xmlns:ns="http://com.att.mso/requestsdb">
623 <requestId>${requestId}</requestId>
624 <lastModifiedBy>BPMN</lastModifiedBy>
625 <statusMessage>${statusMessage}</statusMessage>
626 <responseBody></responseBody>
627 <requestStatus>FAILED</requestStatus>
629 </ns:updateInfraRequest>
631 </soapenv:Envelope>"""
633 String buildDBRequestAsString = utils.formatXml(dbRequest)
634 execution.setVariable("CRESI_createDBInfraErrorRequest", buildDBRequestAsString)
635 utils.logAudit(buildDBRequestAsString)
637 } catch (Exception ex) {
638 // try error in method block
639 String exceptionMessage = "Bpmn error encountered in CreateServiceInstanceInfra flow. Unexpected Error from method prepareDBRequestError() - " + ex.getMessage()
640 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
646 // Prepare for FalloutHandler
647 public void buildErrorResponse (Execution execution) {
648 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
649 execution.setVariable("prefix", Prefix)
651 utils.log("ERROR", " ***** Prepare for FalloutHandler. FAILURE - prepare request for sub-process FalloutHandler. *****", isDebugEnabled)
653 String falloutHandlerRequest = ""
655 // Display Success scenario for DB update Response:
656 String dbReturnCode = execution.getVariable("CRESI_errorDBInfraErrorErrorCode")
657 utils.log("DEBUG", " ***** Error DB Update Response Code : " + dbReturnCode, isDebugEnabled)
658 utils.log("DEBUG", " ***** Error DB Update Response String: " + '\n' + execution.getVariable("CRESI_errorDBInfraErrorResponse"), isDebugEnabled)
660 String requestId = execution.getVariable("CRESI_requestId")
661 String source = execution.getVariable("CRESI_source")
663 execution.setVariable("CRESI_Success", false)
664 String errorMessage = ""
665 String errorCode = ""
667 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
668 WorkflowException wfe = execution.getVariable("WorkflowException")
669 errorMessage = wfe.getErrorMessage()
670 errorCode = wfe.getErrorCode().toString()
673 errorMessage = "Bpmn error encountered in CreateServiceInstance flow."
678 falloutHandlerRequest =
679 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://ecomp.att.com/mso/workflow/schema/v1"
680 xmlns:ns="http://ecomp.att.com/mso/request/types/v1"
681 xmlns:wfsch="http://ecomp.att.com/mso/workflow/schema/v1">
682 <request-info xmlns="http://ecomp.att.com/mso/infra/vnf-request/v1">
683 <request-id>${requestId}</request-id>
684 <action>CREATE</action>
685 <source>${source}</source>
687 <aetgt:WorkflowException xmlns:aetgt="http://ecomp.att.com/mso/workflow/schema/v1">
688 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
689 <aetgt:ErrorCode>${errorCode}</aetgt:ErrorCode>
690 </aetgt:WorkflowException>
691 </aetgt:FalloutHandlerRequest>"""
693 utils.logAudit(falloutHandlerRequest)
694 execution.setVariable("CRESI_FalloutHandlerRequest", falloutHandlerRequest)
695 utils.log("ERROR", " Overall Error Response going to FalloutHandler: " + "\n" + falloutHandlerRequest, isDebugEnabled)
697 } catch (Exception ex) {
698 // rebuild workflow exception
699 String requestId = execution.getVariable("CRESI_requestId")
700 String source = execution.getVariable("CRESI_source")
701 String errorException = " Build Error Response exception encountered during method buildErrorResponse(), preparing request for FalloutHandler: - " + ex.getMessage()
702 utils.log("DEBUG", errorException, isDebugEnabled)
703 falloutHandlerRequest =
704 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://ecomp.att.com/mso/workflow/schema/v1"
705 xmlns:ns="http://ecomp.att.com/mso/request/types/v1"
706 xmlns:wfsch="http://ecomp.att.com/mso/workflow/schema/v1">
707 <request-info xmlns="http://ecomp.att.com/mso/infra/vnf-request/v1">
708 <request-id>${requestId}</request-id>
709 <action>CREATE</action>
710 <source>${source}</source>
712 <aetgt:WorkflowException xmlns:aetgt="http://ecomp.att.com/mso/workflow/schema/v1">
713 <aetgt:ErrorMessage>${errorException}</aetgt:ErrorMessage>
714 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
715 </aetgt:WorkflowException>
716 </aetgt:FalloutHandlerRequest>"""
717 execution.setVariable("CRESI_FalloutHandlerRequest", falloutHandlerRequest)
718 utils.log("ERROR", " Overall Error Response going to FalloutHandler: " + "\n" + falloutHandlerRequest, isDebugEnabled)
724 public void sendSyncError (Execution execution) {
725 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
726 execution.setVariable("prefix", Prefix)
728 utils.log("DEBUG", " ***** Inside sendSyncError() of CreateServiceInstanceInfra ***** ", isDebugEnabled)
731 String errorMessage = ""
732 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
733 WorkflowException wfe = execution.getVariable("WorkflowException")
734 errorMessage = wfe.getErrorMessage()
736 errorMessage = "Sending Sync Error."
739 String buildworkflowException =
740 """<aetgt:WorkflowException xmlns:aetgt="http://ecomp.att.com/mso/workflow/schema/v1">
741 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
742 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
743 </aetgt:WorkflowException>"""
745 utils.logAudit(buildworkflowException)
746 sendWorkflowResponse(execution, 500, buildworkflowException)
749 } catch (Exception ex) {
750 utils.log("DEBUG", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
755 public void processJavaException(Execution execution){
756 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
757 execution.setVariable("prefix",Prefix)
759 utils.log("DEBUG", "Caught a Java Exception", isDebugEnabled)
760 utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
761 utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
762 execution.setVariable("CRESI_unexpectedError", "Caught a Java Lang Exception") // Adding this line temporarily until this flows error handling gets updated
763 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Caught a Java Lang Exception")
765 utils.log("ERROR", "Rethrowing MSOWorkflowException", isDebugEnabled)
768 utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
769 execution.setVariable("CRESI_unexpectedError", "Exception in processJavaException method") // Adding this line temporarily until this flows error handling gets updated
770 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Exception in processJavaException method")
772 utils.log("DEBUG", "Completed processJavaException Method", isDebugEnabled)