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 static org.apache.commons.lang3.StringUtils.*;
25 import org.apache.commons.lang3.*
26 import org.camunda.bpm.engine.delegate.BpmnError
27 import org.camunda.bpm.engine.delegate.DelegateExecution
28 import org.onap.aai.domain.yang.OwningEntity
29 import org.onap.so.bpmn.common.scripts.AaiUtil
30 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
31 import org.onap.so.bpmn.common.scripts.CatalogDbUtils
32 import org.onap.so.bpmn.common.scripts.ExceptionUtil
33 import org.onap.so.bpmn.common.scripts.MsoUtils
34 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
35 import org.onap.so.bpmn.core.RollbackData
36 import org.onap.so.bpmn.core.UrnPropertiesReader
37 import org.onap.so.bpmn.core.WorkflowException
38 import org.onap.so.bpmn.core.domain.ModelInfo
39 import org.onap.so.bpmn.core.domain.ServiceDecomposition
40 import org.onap.so.bpmn.core.domain.ServiceInstance
41 import org.onap.so.bpmn.core.json.JsonUtils
42 import org.onap.so.bpmn.infrastructure.aai.groovyflows.AAICreateResources
43 import org.onap.so.client.aai.AAIObjectType
44 import org.onap.so.client.aai.AAIResourcesClient
45 import org.onap.so.client.aai.entities.AAIResultWrapper
46 import org.onap.so.client.aai.entities.uri.AAIResourceUri
47 import org.onap.so.client.aai.entities.uri.AAIUri
48 import org.onap.so.client.aai.entities.uri.AAIUriFactory
49 import org.onap.so.logger.MessageEnum
50 import org.onap.so.logger.MsoLogger
51 import org.onap.so.rest.APIResponse
56 * This groovy class supports the <class>DoCreateServiceInstance.bpmn</class> process.
59 * @param - msoRequestId
60 * @param - globalSubscriberId
61 * @param - subscriptionServiceType
62 * @param - serviceInstanceId
63 * @param - serviceInstanceName - O
64 * @param - serviceModelInfo
65 * @param - productFamilyId
66 * @param - disableRollback
67 * @param - failExists - TODO
68 * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)
69 * @param - sdncVersion ("1610")
70 * @param - serviceDecomposition - Decomposition for R1710
71 * (if macro provides serviceDecompsition then serviceModelInfo, serviceInstanceId & serviceInstanceName will be ignored)
74 * @param - rollbackData (localRB->null)
75 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
76 * @param - WorkflowException
77 * @param - serviceInstanceName - (GET from AAI if null in input)
79 * This BB processes Macros(except TRANSPORT all sent to sdnc) and Alacartes(sdncSvcs && nonSdncSvcs)
81 public class DoCreateServiceInstance extends AbstractServiceTaskProcessor {
83 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateServiceInstance.class);
84 String Prefix="DCRESI_"
85 ExceptionUtil exceptionUtil = new ExceptionUtil()
86 JsonUtils jsonUtil = new JsonUtils()
87 CatalogDbUtils cutils = new CatalogDbUtils()
89 public void preProcessRequest (DelegateExecution execution) {
90 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
92 msoLogger.trace("preProcessRequest")
95 String requestId = execution.getVariable("msoRequestId")
96 execution.setVariable("prefix", Prefix)
98 def rollbackData = execution.getVariable("rollbackData")
99 if (rollbackData == null) {
100 rollbackData = new RollbackData()
102 execution.setVariable("rollbackData", rollbackData)
104 setBasicDBAuthHeader(execution, isDebugEnabled)
106 //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
107 String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
109 //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
110 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
112 //requestDetails.requestParameters. for SDNC assignTopology
113 String productFamilyId = execution.getVariable("productFamilyId") //AAI productFamilyId
115 if (isBlank(globalSubscriberId)) {
116 msg = "Input globalSubscriberId is null"
118 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
121 if (isBlank(subscriptionServiceType)) {
122 msg = "Input subscriptionServiceType is null"
124 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
127 if (productFamilyId == null) {
128 execution.setVariable("productFamilyId", "")
131 String sdncCallbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
132 if (isBlank(sdncCallbackUrl)) {
133 msg = "mso.workflow.sdncadapter.callback is null"
135 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
137 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
138 msoLogger.debug("SDNC Callback URL: " + sdncCallbackUrl)
140 //requestDetails.modelInfo.for AAI PUT servieInstanceData & SDNC assignTopology
141 String modelInvariantUuid = ""
142 String modelVersion = ""
143 String modelUuid = ""
144 String modelName = ""
145 String serviceInstanceName = ""
146 //Generated in parent.for AAI PUT
147 String serviceInstanceId = ""
148 String serviceType = ""
149 String serviceRole = ""
151 ServiceDecomposition serviceDecomp = (ServiceDecomposition) execution.getVariable("serviceDecomposition")
152 if (serviceDecomp != null)
154 serviceType = serviceDecomp.getServiceType() ?: ""
155 msoLogger.debug("serviceType:" + serviceType)
156 serviceRole = serviceDecomp.getServiceRole() ?: ""
158 ServiceInstance serviceInstance = serviceDecomp.getServiceInstance()
159 if (serviceInstance != null)
161 serviceInstanceId = serviceInstance.getInstanceId() ?: ""
162 serviceInstanceName = serviceInstance.getInstanceName() ?: ""
163 execution.setVariable("serviceInstanceId", serviceInstanceId)
164 execution.setVariable("serviceInstanceName", serviceInstanceName)
167 ModelInfo modelInfo = serviceDecomp.getModelInfo()
168 if (modelInfo != null)
170 modelInvariantUuid = modelInfo.getModelInvariantUuid() ?: ""
171 modelVersion = modelInfo.getModelVersion() ?: ""
172 modelUuid = modelInfo.getModelUuid() ?: ""
173 modelName = modelInfo.getModelName() ?: ""
177 msg = "Input serviceModelInfo is null"
179 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
184 //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData & SDNC assignToplology
185 serviceInstanceName = execution.getVariable("serviceInstanceName") ?: ""
186 serviceInstanceId = execution.getVariable("serviceInstanceId") ?: ""
188 String serviceModelInfo = execution.getVariable("serviceModelInfo")
189 if (isBlank(serviceModelInfo)) {
190 msg = "Input serviceModelInfo is null"
192 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
194 modelInvariantUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelInvariantUuid") ?: ""
195 modelVersion = jsonUtil.getJsonValue(serviceModelInfo, "modelVersion") ?: ""
196 modelUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelUuid") ?: ""
197 modelName = jsonUtil.getJsonValue(serviceModelInfo, "modelName") ?: ""
198 //modelCustomizationUuid NA for SI
202 execution.setVariable("serviceType", serviceType)
203 execution.setVariable("serviceRole", serviceRole)
204 execution.setVariable("serviceInstanceName", serviceInstanceName)
206 execution.setVariable("modelInvariantUuid", modelInvariantUuid)
207 execution.setVariable("modelVersion", modelVersion)
208 execution.setVariable("modelUuid", modelUuid)
209 execution.setVariable("modelName", modelName)
211 //alacarte SIs are NOT sent to sdnc. exceptions are listed in config variable
212 String svcTypes = UrnPropertiesReader.getVariable("sdnc.si.svc.types",execution) ?: ""
213 msoLogger.debug("SDNC SI serviceTypes:" + svcTypes)
214 List<String> svcList = Arrays.asList(svcTypes.split("\\s*,\\s*"));
215 boolean isSdncService= false
216 for (String listEntry : svcList){
217 if (listEntry.equalsIgnoreCase(serviceType)){
223 //All Macros are sent to SDNC, TRANSPORT(Macro) is sent to SDNW
224 //Alacartes are sent to SDNC if they are listed in config variable above
225 execution.setVariable("sendToSDNC", true)
226 if(execution.getVariable("sdncVersion").equals("1610")) //alacarte
229 execution.setVariable("sendToSDNC", false)
230 //alacarte non-sdnc svcs must provide name (sdnc provides name for rest)
231 if (isBlank(execution.getVariable("serviceInstanceName" )))
233 msg = "Input serviceInstanceName must be provided for alacarte"
235 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
240 msoLogger.debug("isSdncService: " + isSdncService)
241 msoLogger.debug("Send To SDNC: " + execution.getVariable("sendToSDNC"))
242 msoLogger.debug("Service Type: " + execution.getVariable("serviceType"))
244 //macro may provide name and alacarte-portm may provide name
245 execution.setVariable("checkAAI", false)
246 if (!isBlank(execution.getVariable("serviceInstanceName" )))
248 execution.setVariable("checkAAI", true)
251 if (isBlank(serviceInstanceId)){
252 msg = "Input serviceInstanceId is null"
254 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
258 StringBuilder sbParams = new StringBuilder()
259 Map<String, String> paramsMap = execution.getVariable("serviceInputParams")
260 if (paramsMap != null)
262 sbParams.append("<service-input-parameters>")
263 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
265 String paramName = entry.getKey()
266 String paramValue = entry.getValue()
269 <name>${MsoUtils.xmlEscape(paramName)}</name>
270 <value>${MsoUtils.xmlEscape(paramValue)}</value>
273 sbParams.append(paramsXml)
275 sbParams.append("</service-input-parameters>")
277 String siParamsXml = sbParams.toString()
278 if (siParamsXml == null)
280 execution.setVariable("siParamsXml", siParamsXml)
282 } catch (BpmnError e) {
284 } catch (Exception ex){
285 msg = "Exception in preProcessRequest " + ex.getMessage()
287 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
289 msoLogger.trace("Exit preProcessRequest")
292 public void getAAICustomerById (DelegateExecution execution) {
293 // https://{aaiEP}/aai/v8/business/customers/customer/{globalCustomerId}
296 String globalCustomerId = execution.getVariable("globalSubscriberId") //VID to AAI name map
297 msoLogger.debug(" ***** getAAICustomerById ***** globalCustomerId:" + globalCustomerId)
299 AAIUri uri = AAIUriFactory.createResourceUri(AAIObjectType.CUSTOMER, globalCustomerId)
300 if(!getAAIClient().exists(uri)){
301 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "GlobalCustomerId:" + globalCustomerId + " not found (404) in AAI")
303 } catch (BpmnError e) {
305 } catch (Exception ex) {
306 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Exception in getAAICustomerById. " + ex.getMessage())
308 msoLogger.trace("Exit getAAICustomerById")
312 public void putServiceInstance(DelegateExecution execution) {
313 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
314 msoLogger.trace("putServiceInstance")
316 String serviceInstanceId = execution.getVariable("serviceInstanceId")
319 String serviceType = execution.getVariable("serviceType")
321 String oStatus = execution.getVariable("initialStatus") ?: "Active"
322 if ("TRANSPORT".equalsIgnoreCase(serviceType))
327 //QUERY CATALOG DB AND GET WORKLOAD / ENVIRONMENT CONTEXT
328 String environmentContext = ""
329 String workloadContext =""
330 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
333 String json = cutils.getServiceResourcesByServiceModelInvariantUuidString(execution,modelInvariantUuid )
335 msoLogger.debug("JSON IS: "+json)
337 environmentContext = jsonUtil.getJsonValue(json, "serviceResources.environmentContext") ?: ""
338 workloadContext = jsonUtil.getJsonValue(json, "serviceResources.workloadContext") ?: ""
339 msoLogger.debug("Env Context is: "+ environmentContext)
340 msoLogger.debug("Workload Context is: "+ workloadContext)
343 } catch (Exception ex){
344 msg = "Exception in preProcessRequest " + ex.getMessage()
346 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
349 org.onap.aai.domain.yang.ServiceInstance si = new org.onap.aai.domain.yang.ServiceInstance()
350 si.setServiceInstanceName(execution.getVariable("serviceInstanceName"))
351 si.setServiceType(serviceType)
352 si.setServiceRole(execution.getVariable("serviceRole"))
353 si.setOrchestrationStatus(oStatus)
354 si.setModelInvariantId(modelInvariantUuid)
355 si.setModelVersionId(execution.getVariable("modelUuid"))
356 si.setEnvironmentContext(environmentContext)
357 si.setWorkloadContext(workloadContext)
359 AAIResourcesClient client = new AAIResourcesClient()
360 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, execution.getVariable("globalSubscriberId"), execution.getVariable("subscriptionServiceType"), serviceInstanceId)
361 client.create(uri, si)
363 } catch (BpmnError e) {
365 } catch (Exception ex) {
366 //start rollback set up
367 def rollbackData = execution.getVariable("rollbackData")
368 if (rollbackData == null) {
369 rollbackData = new RollbackData()
371 def disableRollback = execution.getVariable("disableRollback")
372 rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
373 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
374 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)
375 rollbackData.put("SERVICEINSTANCE", "subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
376 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
377 execution.setVariable("rollbackData", rollbackData)
379 msg = "Exception in DoCreateServiceInstance.putServiceInstance. " + ex.getMessage()
381 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
383 msoLogger.trace("Exit putServiceInstance")
386 public void preProcessSDNCAssignRequest(DelegateExecution execution) {
387 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
389 msoLogger.trace("preProcessSDNCAssignRequest")
392 def serviceInstanceId = execution.getVariable("serviceInstanceId")
393 def serviceInstanceName = execution.getVariable("serviceInstanceName")
394 def callbackURL = execution.getVariable("sdncCallbackUrl")
395 def requestId = execution.getVariable("msoRequestId")
396 def serviceId = execution.getVariable("productFamilyId")
397 def subscriptionServiceType = execution.getVariable("subscriptionServiceType")
398 def globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
401 def modelInvariantUuid = execution.getVariable("modelInvariantUuid")
402 def modelVersion = execution.getVariable("modelVersion")
403 def modelUuid = execution.getVariable("modelUuid")
404 def modelName = execution.getVariable("modelName")
406 def sdncRequestId = UUID.randomUUID().toString()
408 def siParamsXml = execution.getVariable("siParamsXml")
410 // special URL for SDNW, msoAction helps set diff url in SDNCA
411 if("TRANSPORT".equalsIgnoreCase(execution.getVariable("serviceType")))
413 msoAction = "TRANSPORT"
416 String sdncAssignRequest =
417 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
418 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
419 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
420 <sdncadapter:RequestHeader>
421 <sdncadapter:RequestId>${MsoUtils.xmlEscape(sdncRequestId)}</sdncadapter:RequestId>
422 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
423 <sdncadapter:SvcAction>assign</sdncadapter:SvcAction>
424 <sdncadapter:SvcOperation>service-topology-operation</sdncadapter:SvcOperation>
425 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
426 <sdncadapter:MsoAction>${MsoUtils.xmlEscape(msoAction)}</sdncadapter:MsoAction>
427 </sdncadapter:RequestHeader>
428 <sdncadapterworkflow:SDNCRequestData>
429 <request-information>
430 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
435 <request-action>CreateServiceInstance</request-action>
436 </request-information>
437 <service-information>
438 <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
439 <subscription-service-type>${MsoUtils.xmlEscape(subscriptionServiceType)}</subscription-service-type>
440 <onap-model-information>
441 <model-invariant-uuid>${MsoUtils.xmlEscape(modelInvariantUuid)}</model-invariant-uuid>
442 <model-uuid>${MsoUtils.xmlEscape(modelUuid)}</model-uuid>
443 <model-version>${MsoUtils.xmlEscape(modelVersion)}</model-version>
444 <model-name>${MsoUtils.xmlEscape(modelName)}</model-name>
445 </onap-model-information>
446 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
448 <global-customer-id>${MsoUtils.xmlEscape(globalSubscriberId)}</global-customer-id>
449 </service-information>
450 <service-request-input>
451 <service-instance-name>${MsoUtils.xmlEscape(serviceInstanceName)}</service-instance-name>
453 </service-request-input>
454 </sdncadapterworkflow:SDNCRequestData>
455 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
457 msoLogger.debug("sdncAssignRequest:\n" + sdncAssignRequest)
458 sdncAssignRequest = utils.formatXml(sdncAssignRequest)
459 execution.setVariable("sdncAssignRequest", sdncAssignRequest)
460 msoLogger.debug("sdncAssignRequest: " + sdncAssignRequest)
462 def sdncRequestId2 = UUID.randomUUID().toString()
463 String sdncDelete = sdncAssignRequest.replace(">assign<", ">delete<").replace(">CreateServiceInstance<", ">DeleteServiceInstance<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
464 def sdncRequestId3 = UUID.randomUUID().toString()
465 String sdncDeactivate = sdncDelete.replace(">delete<", ">deactivate<").replace(">${sdncRequestId2}<", ">${sdncRequestId3}<")
466 def rollbackData = execution.getVariable("rollbackData")
467 if (rollbackData != null) {
468 rollbackData.put("SERVICEINSTANCE", "sdncDeactivate", sdncDeactivate)
469 rollbackData.put("SERVICEINSTANCE", "sdncDelete", sdncDelete)
470 execution.setVariable("rollbackData", rollbackData)
472 msoLogger.debug("rollbackData:\n" + rollbackData.toString())
475 } catch (BpmnError e) {
477 } catch(Exception ex) {
478 msg = "Exception in preProcessSDNCAssignRequest. " + ex.getMessage()
480 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
482 msoLogger.trace("Exit preProcessSDNCAssignRequest")
485 public void postProcessSDNCAssign (DelegateExecution execution) {
486 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
487 msoLogger.trace("postProcessSDNCAssign")
489 WorkflowException workflowException = execution.getVariable("WorkflowException")
490 msoLogger.debug("workflowException: " + workflowException)
492 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
494 String response = execution.getVariable("sdncAdapterResponse")
495 msoLogger.debug("SDNCResponse: " + response)
497 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
498 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
500 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
501 msoLogger.debug("Good response from SDNC Adapter for service-instance topology assign: \n" + response)
503 def rollbackData = execution.getVariable("rollbackData")
504 if (rollbackData != null) {
505 rollbackData.put("SERVICEINSTANCE", "rollbackSDNC", "true")
506 execution.setVariable("rollbackData", rollbackData)
510 msoLogger.debug("Bad Response from SDNC Adapter for service-instance assign")
511 throw new BpmnError("MSOWorkflowException")
514 } catch (BpmnError e) {
516 } catch(Exception ex) {
517 msg = "Exception in postProcessSDNCAssign. " + ex.getMessage()
519 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
521 msoLogger.trace("Exit postProcessSDNCAssign")
524 public void postProcessAAIGET2(DelegateExecution execution) {
525 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
526 msoLogger.trace("postProcessAAIGET2")
530 String serviceInstanceName = execution.getVariable("serviceInstanceName")
531 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
533 msoLogger.debug("Error getting Service-instance from AAI in postProcessAAIGET2", + serviceInstanceName)
534 WorkflowException workflowException = execution.getVariable("WorkflowException")
535 msoLogger.debug("workflowException: " + workflowException)
536 if(workflowException != null){
537 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
541 msg = "Failure in postProcessAAIGET2 GENGS_SuccessIndicator:" + succInAAI
543 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
548 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
550 String aaiService = execution.getVariable("GENGS_service")
551 if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "service-instance-name"))) {
552 execution.setVariable("serviceInstanceName", utils.getNodeText(aaiService, "service-instance-name"))
553 msoLogger.debug("Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"))
557 } catch (BpmnError e) {
559 } catch (Exception ex) {
560 msg = "Exception in DoCreateServiceInstance.postProcessAAIGET2 " + ex.getMessage()
562 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
564 msoLogger.trace("Exit postProcessAAIGET2")
567 public void preProcessRollback (DelegateExecution execution) {
568 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
569 msoLogger.trace("preProcessRollback")
572 Object workflowException = execution.getVariable("WorkflowException");
574 if (workflowException instanceof WorkflowException) {
575 msoLogger.debug("Prev workflowException: " + workflowException.getErrorMessage())
576 execution.setVariable("prevWorkflowException", workflowException);
577 //execution.setVariable("WorkflowException", null);
579 } catch (BpmnError e) {
580 msoLogger.debug("BPMN Error during preProcessRollback")
581 } catch(Exception ex) {
582 String msg = "Exception in preProcessRollback. " + ex.getMessage()
585 msoLogger.trace("Exit preProcessRollback")
588 public void postProcessRollback (DelegateExecution execution) {
589 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
590 msoLogger.trace("postProcessRollback")
593 Object workflowException = execution.getVariable("prevWorkflowException");
594 if (workflowException instanceof WorkflowException) {
595 msoLogger.debug("Setting prevException to WorkflowException: ")
596 execution.setVariable("WorkflowException", workflowException);
598 execution.setVariable("rollbackData", null)
599 } catch (BpmnError b) {
600 msoLogger.debug("BPMN Error during postProcessRollback")
602 } catch(Exception ex) {
603 msg = "Exception in postProcessRollback. " + ex.getMessage()
606 msoLogger.trace("Exit postProcessRollback")
609 public void createProject(DelegateExecution execution) {
610 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
611 msoLogger.trace("createProject")
613 String bpmnRequest = execution.getVariable("requestJson")
614 String projectName = jsonUtil.getJsonValue(bpmnRequest, "requestDetails.project.projectName")
615 String serviceInstance = execution.getVariable("serviceInstanceId")
617 msoLogger.debug("BPMN REQUEST IS: "+ bpmnRequest)
618 msoLogger.debug("PROJECT NAME: " + projectName)
619 msoLogger.debug("Service Instance: " + serviceInstance)
621 if(projectName == null||projectName.equals("")){
622 msoLogger.debug("Project Name was not found in input. Skipping task...")
625 AAICreateResources aaiCR = new AAICreateResources()
626 aaiCR.createAAIProject(projectName, serviceInstance)
627 }catch(Exception ex){
628 String msg = "Exception in createProject. " + ex.getMessage();
631 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
634 msoLogger.trace("Exit createProject")
637 public void createOwningEntity(DelegateExecution execution) {
638 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
639 msoLogger.trace("createOwningEntity")
641 String bpmnRequest = execution.getVariable("requestJson")
642 String owningEntityId = jsonUtil.getJsonValue(bpmnRequest, "requestDetails.owningEntity.owningEntityId")
643 String owningEntityName = jsonUtil.getJsonValue(bpmnRequest,"requestDetails.owningEntity.owningEntityName");
644 String serviceInstance = execution.getVariable("serviceInstanceId")
646 msoLogger.debug("owningEntity: " + owningEntityId)
647 msoLogger.debug("OwningEntityName: "+ owningEntityName)
648 msoLogger.debug("Service Instance: " + serviceInstance)
651 AAICreateResources aaiCR = new AAICreateResources()
652 if(owningEntityId==null||owningEntityId.equals("")){
653 msg = "Exception in createOwningEntity. OwningEntityId is null in input.";
654 throw new IllegalStateException();
656 if(aaiCR.existsOwningEntity(owningEntityId)){
657 aaiCR.connectOwningEntityandServiceInstance(owningEntityId,serviceInstance)
659 if(owningEntityName==null||owningEntityName.equals("")){
660 msg = "Exception in createOwningEntity. Can't create an owningEntity without an owningEntityName in input.";
661 throw new IllegalStateException();
663 Optional<OwningEntity> owningEntity = aaiCR.getOwningEntityNames(owningEntityName);
664 if(owningEntity.isPresent()){
665 msg = "Exception in createOwningEntity. Can't create OwningEntity as name already exists in AAI associated with a different owning-entity-id (name must be unique).";
666 throw new IllegalStateException();
668 aaiCR.createAAIOwningEntity(owningEntityId, owningEntityName, serviceInstance)
673 }catch(Exception ex){
676 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
678 msoLogger.trace("Exit createOwningEntity")
681 // *******************************
682 // Build Error Section
683 // *******************************
685 public void processJavaException(DelegateExecution execution){
686 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
689 msoLogger.debug("Caught a Java Exception in DoCreateServiceInstance")
690 msoLogger.debug("Started processJavaException Method")
691 msoLogger.debug("Variables List: " + execution.getVariables())
692 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception in DoCreateServiceInstance") // Adding this line temporarily until this flows error handling gets updated
693 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception in DoCreateServiceInstance")
696 msoLogger.debug("Caught Exception during processJavaException Method: " + e)
697 execution.setVariable("UnexpectedError", "Exception in processJavaException") // Adding this line temporarily until this flows error handling gets updated
698 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method")
700 msoLogger.trace("Completed processJavaException Method in DoCreateServiceInstance")