2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.infrastructure.scripts;
25 import static org.apache.commons.lang3.StringUtils.*;
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.AbstractServiceTaskProcessor
30 import org.onap.so.bpmn.common.scripts.CatalogDbUtils
31 import org.onap.so.bpmn.common.scripts.CatalogDbUtilsFactory
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.uri.AAIResourceUri
46 import org.onap.so.client.aai.entities.uri.AAIUriFactory
47 import org.slf4j.Logger
48 import org.slf4j.LoggerFactory
51 * This groovy class supports the <class>DoCreateServiceInstance.bpmn</class> process.
54 * @param - msoRequestId
55 * @param - globalSubscriberId
56 * @param - subscriptionServiceType
57 * @param - serviceInstanceId
58 * @param - serviceInstanceName - O
59 * @param - serviceModelInfo
60 * @param - productFamilyId
61 * @param - disableRollback
62 * @param - failExists - TODO
63 * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)
64 * @param - sdncVersion ("1610")
65 * @param - serviceDecomposition - Decomposition for R1710
66 * (if macro provides serviceDecompsition then serviceModelInfo, serviceInstanceId & serviceInstanceName will be ignored)
69 * @param - rollbackData (localRB->null)
70 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
71 * @param - WorkflowException
72 * @param - serviceInstanceName - (GET from AAI if null in input)
74 * This BB processes Macros(except TRANSPORT all sent to sdnc) and Alacartes(sdncSvcs && nonSdncSvcs)
76 public class DoCreateServiceInstance extends AbstractServiceTaskProcessor {
78 private static final Logger logger = LoggerFactory.getLogger( DoCreateServiceInstance.class);
79 String Prefix="DCRESI_"
80 ExceptionUtil exceptionUtil = new ExceptionUtil()
81 JsonUtils jsonUtil = new JsonUtils()
82 CatalogDbUtils catalogDbUtils = new CatalogDbUtilsFactory().create()
84 void preProcessRequest (DelegateExecution execution) {
85 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
87 logger.trace("preProcessRequest")
90 String requestId = execution.getVariable("msoRequestId")
91 execution.setVariable("prefix", Prefix)
93 def rollbackData = execution.getVariable("rollbackData")
94 if (rollbackData == null) {
95 rollbackData = new RollbackData()
97 execution.setVariable("rollbackData", rollbackData)
99 setBasicDBAuthHeader(execution, isDebugEnabled)
101 //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
102 String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
104 //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
105 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
107 //requestDetails.requestParameters. for SDNC assignTopology
108 String productFamilyId = execution.getVariable("productFamilyId") //AAI productFamilyId
110 if (isBlank(globalSubscriberId)) {
111 msg = "Input globalSubscriberId is null"
113 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
116 if (isBlank(subscriptionServiceType)) {
117 msg = "Input subscriptionServiceType is null"
119 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
122 if (productFamilyId == null) {
123 execution.setVariable("productFamilyId", "")
126 String sdncCallbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
127 if (isBlank(sdncCallbackUrl)) {
128 msg = "mso.workflow.sdncadapter.callback is null"
130 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
132 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
133 logger.debug("SDNC Callback URL: " + sdncCallbackUrl)
135 //requestDetails.modelInfo.for AAI PUT servieInstanceData & SDNC assignTopology
136 String modelInvariantUuid = ""
137 String modelVersion = ""
138 String modelUuid = ""
139 String modelName = ""
140 String serviceInstanceName = ""
141 //Generated in parent.for AAI PUT
142 String serviceInstanceId = ""
143 String serviceType = ""
144 String serviceRole = ""
146 ServiceDecomposition serviceDecomp = (ServiceDecomposition) execution.getVariable("serviceDecomposition")
147 if (serviceDecomp != null)
149 serviceType = serviceDecomp.getServiceType() ?: ""
150 logger.debug("serviceType:" + serviceType)
151 serviceRole = serviceDecomp.getServiceRole() ?: ""
153 ServiceInstance serviceInstance = serviceDecomp.getServiceInstance()
154 if (serviceInstance != null)
156 serviceInstanceId = serviceInstance.getInstanceId() ?: ""
157 serviceInstanceName = serviceInstance.getInstanceName() ?: ""
158 execution.setVariable("serviceInstanceId", serviceInstanceId)
159 execution.setVariable("serviceInstanceName", serviceInstanceName)
162 ModelInfo modelInfo = serviceDecomp.getModelInfo()
163 if (modelInfo != null)
165 modelInvariantUuid = modelInfo.getModelInvariantUuid() ?: ""
166 modelVersion = modelInfo.getModelVersion() ?: ""
167 modelUuid = modelInfo.getModelUuid() ?: ""
168 modelName = modelInfo.getModelName() ?: ""
172 msg = "Input serviceModelInfo is null"
174 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
179 //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData & SDNC assignToplology
180 serviceInstanceName = execution.getVariable("serviceInstanceName") ?: ""
181 serviceInstanceId = execution.getVariable("serviceInstanceId") ?: ""
183 String serviceModelInfo = execution.getVariable("serviceModelInfo")
184 if (isBlank(serviceModelInfo)) {
185 msg = "Input serviceModelInfo is null"
187 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
189 modelInvariantUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelInvariantUuid") ?: ""
190 modelVersion = jsonUtil.getJsonValue(serviceModelInfo, "modelVersion") ?: ""
191 modelUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelUuid") ?: ""
192 modelName = jsonUtil.getJsonValue(serviceModelInfo, "modelName") ?: ""
193 //modelCustomizationUuid NA for SI
197 execution.setVariable("serviceType", serviceType)
198 execution.setVariable("serviceRole", serviceRole)
199 execution.setVariable("serviceInstanceName", serviceInstanceName)
201 execution.setVariable("modelInvariantUuid", modelInvariantUuid)
202 execution.setVariable("modelVersion", modelVersion)
203 execution.setVariable("modelUuid", modelUuid)
204 execution.setVariable("modelName", modelName)
206 //alacarte SIs are NOT sent to sdnc. exceptions are listed in config variable
207 String svcTypes = UrnPropertiesReader.getVariable("sdnc.si.svc.types",execution) ?: ""
208 logger.debug("SDNC SI serviceTypes:" + svcTypes)
209 List<String> svcList = Arrays.asList(svcTypes.split("\\s*,\\s*"));
210 boolean isSdncService= false
211 for (String listEntry : svcList){
212 if (listEntry.equalsIgnoreCase(serviceType)){
218 //All Macros are sent to SDNC, TRANSPORT(Macro) is sent to SDNW
219 //Alacartes are sent to SDNC if they are listed in config variable above
220 execution.setVariable("sendToSDNC", true)
221 if(execution.getVariable("sdncVersion").equals("1610")) //alacarte
224 execution.setVariable("sendToSDNC", false)
225 //alacarte non-sdnc svcs must provide name (sdnc provides name for rest)
226 if (isBlank(execution.getVariable("serviceInstanceName" )))
228 msg = "Input serviceInstanceName must be provided for alacarte"
230 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
235 logger.debug("isSdncService: " + isSdncService)
236 logger.debug("Send To SDNC: " + execution.getVariable("sendToSDNC"))
237 logger.debug("Service Type: " + execution.getVariable("serviceType"))
239 //macro may provide name and alacarte-portm may provide name
240 execution.setVariable("checkAAI", false)
241 if (!isBlank(execution.getVariable("serviceInstanceName" )))
243 execution.setVariable("checkAAI", true)
246 if (isBlank(serviceInstanceId)){
247 msg = "Input serviceInstanceId is null"
249 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
253 StringBuilder sbParams = new StringBuilder()
254 Map<String, String> paramsMap = execution.getVariable("serviceInputParams")
255 if (paramsMap != null)
257 sbParams.append("<service-input-parameters>")
258 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
260 String paramName = entry.getKey()
261 String paramValue = entry.getValue()
264 <name>${MsoUtils.xmlEscape(paramName)}</name>
265 <value>${MsoUtils.xmlEscape(paramValue)}</value>
268 sbParams.append(paramsXml)
270 sbParams.append("</service-input-parameters>")
272 String siParamsXml = sbParams.toString()
273 if (siParamsXml == null)
275 execution.setVariable("siParamsXml", siParamsXml)
277 } catch (BpmnError e) {
279 } catch (Exception ex){
280 msg = "Exception in preProcessRequest " + ex.getMessage()
282 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
284 logger.trace("Exit preProcessRequest")
287 void getAAICustomerById (DelegateExecution execution) {
288 // https://{aaiEP}/aai/v8/business/customers/customer/{globalCustomerId}
291 String globalCustomerId = execution.getVariable("globalSubscriberId") //VID to AAI name map
292 logger.debug(" ***** getAAICustomerById ***** globalCustomerId:" + globalCustomerId)
294 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.CUSTOMER, globalCustomerId)
295 if(!getAAIClient().exists(uri)){
296 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "GlobalCustomerId:" + globalCustomerId + " not found (404) in AAI")
298 } catch (BpmnError e) {
300 } catch (Exception ex) {
301 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Exception in getAAICustomerById. " + ex.getMessage())
303 logger.trace("Exit getAAICustomerById")
307 void putServiceInstance(DelegateExecution execution) {
308 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
309 logger.trace("putServiceInstance")
311 String serviceInstanceId = execution.getVariable("serviceInstanceId")
314 String serviceType = execution.getVariable("serviceType")
316 String oStatus = execution.getVariable("initialStatus") ?: "Active"
317 if ("TRANSPORT".equalsIgnoreCase(serviceType))
322 //QUERY CATALOG DB AND GET WORKLOAD / ENVIRONMENT CONTEXT
323 String environmentContext = ""
324 String workloadContext =""
325 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
328 String json = catalogDbUtils.getServiceResourcesByServiceModelInvariantUuidString(execution,modelInvariantUuid )
330 logger.debug("JSON IS: "+json)
332 environmentContext = jsonUtil.getJsonValue(json, "serviceResources.environmentContext") ?: ""
333 workloadContext = jsonUtil.getJsonValue(json, "serviceResources.workloadContext") ?: ""
334 logger.debug("Env Context is: "+ environmentContext)
335 logger.debug("Workload Context is: "+ workloadContext)
338 } catch (Exception ex){
339 msg = "Exception in preProcessRequest " + ex.getMessage()
341 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
344 org.onap.aai.domain.yang.ServiceInstance si = new org.onap.aai.domain.yang.ServiceInstance()
345 si.setServiceInstanceName(execution.getVariable("serviceInstanceName"))
346 si.setServiceType(serviceType)
347 si.setServiceRole(execution.getVariable("serviceRole"))
348 si.setOrchestrationStatus(oStatus)
349 si.setModelInvariantId(modelInvariantUuid)
350 si.setModelVersionId(execution.getVariable("modelUuid"))
351 si.setEnvironmentContext(environmentContext)
352 si.setWorkloadContext(workloadContext)
354 AAIResourcesClient client = new AAIResourcesClient()
355 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, execution.getVariable("globalSubscriberId"), execution.getVariable("subscriptionServiceType"), serviceInstanceId)
356 client.create(uri, si)
358 } catch (BpmnError e) {
360 } catch (Exception ex) {
361 //start rollback set up
362 def rollbackData = execution.getVariable("rollbackData")
363 if (rollbackData == null) {
364 rollbackData = new RollbackData()
366 def disableRollback = execution.getVariable("disableRollback")
367 rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
368 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
369 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)
370 rollbackData.put("SERVICEINSTANCE", "subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
371 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
372 execution.setVariable("rollbackData", rollbackData)
374 msg = "Exception in DoCreateServiceInstance.putServiceInstance. " + ex.getMessage()
376 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
378 logger.trace("Exit putServiceInstance")
381 void preProcessSDNCAssignRequest(DelegateExecution execution) {
382 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
384 logger.trace("preProcessSDNCAssignRequest")
387 def serviceInstanceId = execution.getVariable("serviceInstanceId")
388 def serviceInstanceName = execution.getVariable("serviceInstanceName")
389 def callbackURL = execution.getVariable("sdncCallbackUrl")
390 def requestId = execution.getVariable("msoRequestId")
391 def serviceId = execution.getVariable("productFamilyId")
392 def subscriptionServiceType = execution.getVariable("subscriptionServiceType")
393 def globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
396 def modelInvariantUuid = execution.getVariable("modelInvariantUuid")
397 def modelVersion = execution.getVariable("modelVersion")
398 def modelUuid = execution.getVariable("modelUuid")
399 def modelName = execution.getVariable("modelName")
401 def sdncRequestId = UUID.randomUUID().toString()
403 def siParamsXml = execution.getVariable("siParamsXml")
405 // special URL for SDNW, msoAction helps set diff url in SDNCA
406 if("TRANSPORT".equalsIgnoreCase(execution.getVariable("serviceType")))
408 msoAction = "TRANSPORT"
411 String sdncAssignRequest =
412 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
413 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
414 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
415 <sdncadapter:RequestHeader>
416 <sdncadapter:RequestId>${MsoUtils.xmlEscape(sdncRequestId)}</sdncadapter:RequestId>
417 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
418 <sdncadapter:SvcAction>assign</sdncadapter:SvcAction>
419 <sdncadapter:SvcOperation>service-topology-operation</sdncadapter:SvcOperation>
420 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
421 <sdncadapter:MsoAction>${MsoUtils.xmlEscape(msoAction)}</sdncadapter:MsoAction>
422 </sdncadapter:RequestHeader>
423 <sdncadapterworkflow:SDNCRequestData>
424 <request-information>
425 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
430 <request-action>CreateServiceInstance</request-action>
431 </request-information>
432 <service-information>
433 <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
434 <subscription-service-type>${MsoUtils.xmlEscape(subscriptionServiceType)}</subscription-service-type>
435 <onap-model-information>
436 <model-invariant-uuid>${MsoUtils.xmlEscape(modelInvariantUuid)}</model-invariant-uuid>
437 <model-uuid>${MsoUtils.xmlEscape(modelUuid)}</model-uuid>
438 <model-version>${MsoUtils.xmlEscape(modelVersion)}</model-version>
439 <model-name>${MsoUtils.xmlEscape(modelName)}</model-name>
440 </onap-model-information>
441 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
443 <global-customer-id>${MsoUtils.xmlEscape(globalSubscriberId)}</global-customer-id>
444 </service-information>
445 <service-request-input>
446 <service-instance-name>${MsoUtils.xmlEscape(serviceInstanceName)}</service-instance-name>
448 </service-request-input>
449 </sdncadapterworkflow:SDNCRequestData>
450 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
452 logger.debug("sdncAssignRequest:\n" + sdncAssignRequest)
453 sdncAssignRequest = utils.formatXml(sdncAssignRequest)
454 execution.setVariable("sdncAssignRequest", sdncAssignRequest)
455 logger.debug("sdncAssignRequest: " + sdncAssignRequest)
457 def sdncRequestId2 = UUID.randomUUID().toString()
458 String sdncDelete = sdncAssignRequest.replace(">assign<", ">delete<").replace(">CreateServiceInstance<", ">DeleteServiceInstance<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
459 def sdncRequestId3 = UUID.randomUUID().toString()
460 String sdncDeactivate = sdncDelete.replace(">delete<", ">deactivate<").replace(">${sdncRequestId2}<", ">${sdncRequestId3}<")
461 def rollbackData = execution.getVariable("rollbackData")
462 if (rollbackData != null) {
463 rollbackData.put("SERVICEINSTANCE", "sdncDeactivate", sdncDeactivate)
464 rollbackData.put("SERVICEINSTANCE", "sdncDelete", sdncDelete)
465 execution.setVariable("rollbackData", rollbackData)
467 logger.debug("rollbackData:\n" + rollbackData.toString())
470 } catch (BpmnError e) {
472 } catch(Exception ex) {
473 msg = "Exception in preProcessSDNCAssignRequest. " + ex.getMessage()
475 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
477 logger.trace("Exit preProcessSDNCAssignRequest")
480 void postProcessSDNCAssign (DelegateExecution execution) {
481 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
482 logger.trace("postProcessSDNCAssign")
484 WorkflowException workflowException = execution.getVariable("WorkflowException")
485 logger.debug("workflowException: " + workflowException)
487 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
489 String response = execution.getVariable("sdncAdapterResponse")
490 logger.debug("SDNCResponse: " + response)
492 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
493 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
495 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
496 logger.debug("Good response from SDNC Adapter for service-instance topology assign: \n" + response)
498 def rollbackData = execution.getVariable("rollbackData")
499 if (rollbackData != null) {
500 rollbackData.put("SERVICEINSTANCE", "rollbackSDNC", "true")
501 execution.setVariable("rollbackData", rollbackData)
505 logger.debug("Bad Response from SDNC Adapter for service-instance assign")
506 throw new BpmnError("MSOWorkflowException")
509 } catch (BpmnError e) {
511 } catch(Exception ex) {
512 msg = "Exception in postProcessSDNCAssign. " + ex.getMessage()
514 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
516 logger.trace("Exit postProcessSDNCAssign")
519 void postProcessAAIGET2(DelegateExecution execution) {
520 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
521 logger.trace("postProcessAAIGET2")
525 String serviceInstanceName = execution.getVariable("serviceInstanceName")
526 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
528 logger.debug("Error getting Service-instance from AAI in postProcessAAIGET2", + serviceInstanceName)
529 WorkflowException workflowException = execution.getVariable("WorkflowException")
530 logger.debug("workflowException: " + workflowException)
531 if(workflowException != null){
532 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
536 msg = "Failure in postProcessAAIGET2 GENGS_SuccessIndicator:" + succInAAI
538 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
543 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
545 String aaiService = execution.getVariable("GENGS_service")
546 if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "service-instance-name"))) {
547 execution.setVariable("serviceInstanceName", utils.getNodeText(aaiService, "service-instance-name"))
548 logger.debug("Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"))
552 } catch (BpmnError e) {
554 } catch (Exception ex) {
555 msg = "Exception in DoCreateServiceInstance.postProcessAAIGET2 " + ex.getMessage()
557 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
559 logger.trace("Exit postProcessAAIGET2")
562 void preProcessRollback (DelegateExecution execution) {
563 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
564 logger.trace("preProcessRollback")
567 Object workflowException = execution.getVariable("WorkflowException");
569 if (workflowException instanceof WorkflowException) {
570 logger.debug("Prev workflowException: " + workflowException.getErrorMessage())
571 execution.setVariable("prevWorkflowException", workflowException);
572 //execution.setVariable("WorkflowException", null);
574 } catch (BpmnError e) {
575 logger.debug("BPMN Error during preProcessRollback")
576 } catch(Exception ex) {
577 String msg = "Exception in preProcessRollback. " + ex.getMessage()
580 logger.trace("Exit preProcessRollback")
583 void postProcessRollback (DelegateExecution execution) {
584 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
585 logger.trace("postProcessRollback")
588 Object workflowException = execution.getVariable("prevWorkflowException");
589 if (workflowException instanceof WorkflowException) {
590 logger.debug("Setting prevException to WorkflowException: ")
591 execution.setVariable("WorkflowException", workflowException);
593 execution.setVariable("rollbackData", null)
594 } catch (BpmnError b) {
595 logger.debug("BPMN Error during postProcessRollback")
597 } catch(Exception ex) {
598 msg = "Exception in postProcessRollback. " + ex.getMessage()
601 logger.trace("Exit postProcessRollback")
604 void createProject(DelegateExecution execution) {
605 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
606 logger.trace("createProject")
608 String bpmnRequest = execution.getVariable("requestJson")
609 String projectName = jsonUtil.getJsonValue(bpmnRequest, "requestDetails.project.projectName")
610 String serviceInstance = execution.getVariable("serviceInstanceId")
612 logger.debug("BPMN REQUEST IS: "+ bpmnRequest)
613 logger.debug("PROJECT NAME: " + projectName)
614 logger.debug("Service Instance: " + serviceInstance)
616 if(projectName == null||projectName.equals("")){
617 logger.debug("Project Name was not found in input. Skipping task...")
620 AAICreateResources aaiCR = new AAICreateResources()
621 aaiCR.createAAIProject(projectName, serviceInstance)
622 }catch(Exception ex){
623 String msg = "Exception in createProject. " + ex.getMessage();
626 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
629 logger.trace("Exit createProject")
632 void createOwningEntity(DelegateExecution execution) {
633 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
634 logger.trace("createOwningEntity")
636 String bpmnRequest = execution.getVariable("requestJson")
637 String owningEntityId = jsonUtil.getJsonValue(bpmnRequest, "requestDetails.owningEntity.owningEntityId")
638 String owningEntityName = jsonUtil.getJsonValue(bpmnRequest,"requestDetails.owningEntity.owningEntityName");
639 String serviceInstance = execution.getVariable("serviceInstanceId")
641 logger.debug("owningEntity: " + owningEntityId)
642 logger.debug("OwningEntityName: "+ owningEntityName)
643 logger.debug("Service Instance: " + serviceInstance)
646 AAICreateResources aaiCR = new AAICreateResources()
647 if(owningEntityId==null||owningEntityId.equals("")){
648 msg = "Exception in createOwningEntity. OwningEntityId is null in input.";
649 throw new IllegalStateException();
651 if(aaiCR.existsOwningEntity(owningEntityId)){
652 aaiCR.connectOwningEntityandServiceInstance(owningEntityId,serviceInstance)
654 if(owningEntityName==null||owningEntityName.equals("")){
655 msg = "Exception in createOwningEntity. Can't create an owningEntity without an owningEntityName in input.";
656 throw new IllegalStateException();
658 Optional<OwningEntity> owningEntity = aaiCR.getOwningEntityNames(owningEntityName);
659 if(owningEntity.isPresent()){
660 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).";
661 throw new IllegalStateException();
663 aaiCR.createAAIOwningEntity(owningEntityId, owningEntityName, serviceInstance)
668 }catch(Exception ex){
671 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
673 logger.trace("Exit createOwningEntity")
676 // *******************************
677 // Build Error Section
678 // *******************************
680 void processJavaException(DelegateExecution execution){
681 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
684 logger.debug("Caught a Java Exception in DoCreateServiceInstance")
685 logger.debug("Started processJavaException Method")
686 logger.debug("Variables List: " + execution.getVariables())
687 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception in DoCreateServiceInstance") // Adding this line temporarily until this flows error handling gets updated
688 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception in DoCreateServiceInstance")
691 logger.debug("Caught Exception during processJavaException Method: " + e)
692 execution.setVariable("UnexpectedError", "Exception in processJavaException") // Adding this line temporarily until this flows error handling gets updated
693 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method")
695 logger.trace("Completed processJavaException Method in DoCreateServiceInstance")