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.camunda.bpm.engine.delegate.BpmnError
26 import org.camunda.bpm.engine.delegate.DelegateExecution
27 import org.onap.aai.domain.yang.OwningEntity
28 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
29 import org.onap.so.bpmn.common.scripts.CatalogDbUtils
30 import org.onap.so.bpmn.common.scripts.CatalogDbUtilsFactory
31 import org.onap.so.bpmn.common.scripts.ExceptionUtil
32 import org.onap.so.bpmn.common.scripts.MsoUtils
33 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
34 import org.onap.so.bpmn.core.RollbackData
35 import org.onap.so.bpmn.core.UrnPropertiesReader
36 import org.onap.so.bpmn.core.WorkflowException
37 import org.onap.so.bpmn.core.domain.ModelInfo
38 import org.onap.so.bpmn.core.domain.ServiceDecomposition
39 import org.onap.so.bpmn.core.domain.ServiceInstance
40 import org.onap.so.bpmn.core.json.JsonUtils
41 import org.onap.so.bpmn.infrastructure.aai.groovyflows.AAICreateResources
42 import org.onap.so.client.aai.AAIObjectType
43 import org.onap.so.client.aai.AAIResourcesClient
44 import org.onap.so.client.aai.entities.uri.AAIResourceUri
45 import org.onap.so.client.aai.entities.uri.AAIUri
46 import org.onap.so.client.aai.entities.uri.AAIUriFactory
47 import org.onap.so.logger.MsoLogger
50 * This groovy class supports the <class>DoCreateServiceInstance.bpmn</class> process.
53 * @param - msoRequestId
54 * @param - globalSubscriberId
55 * @param - subscriptionServiceType
56 * @param - serviceInstanceId
57 * @param - serviceInstanceName - O
58 * @param - serviceModelInfo
59 * @param - productFamilyId
60 * @param - disableRollback
61 * @param - failExists - TODO
62 * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)
63 * @param - sdncVersion ("1610")
64 * @param - serviceDecomposition - Decomposition for R1710
65 * (if macro provides serviceDecompsition then serviceModelInfo, serviceInstanceId & serviceInstanceName will be ignored)
68 * @param - rollbackData (localRB->null)
69 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
70 * @param - WorkflowException
71 * @param - serviceInstanceName - (GET from AAI if null in input)
73 * This BB processes Macros(except TRANSPORT all sent to sdnc) and Alacartes(sdncSvcs && nonSdncSvcs)
75 public class DoCreateServiceInstance extends AbstractServiceTaskProcessor {
77 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateServiceInstance.class);
78 String Prefix="DCRESI_"
79 ExceptionUtil exceptionUtil = new ExceptionUtil()
80 JsonUtils jsonUtil = new JsonUtils()
81 CatalogDbUtils catalogDbUtils = new CatalogDbUtilsFactory().create()
83 public void preProcessRequest (DelegateExecution execution) {
84 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
86 msoLogger.trace("preProcessRequest")
89 String requestId = execution.getVariable("msoRequestId")
90 execution.setVariable("prefix", Prefix)
92 def rollbackData = execution.getVariable("rollbackData")
93 if (rollbackData == null) {
94 rollbackData = new RollbackData()
96 execution.setVariable("rollbackData", rollbackData)
98 setBasicDBAuthHeader(execution, isDebugEnabled)
100 //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
101 String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
103 //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
104 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
106 //requestDetails.requestParameters. for SDNC assignTopology
107 String productFamilyId = execution.getVariable("productFamilyId") //AAI productFamilyId
109 if (isBlank(globalSubscriberId)) {
110 msg = "Input globalSubscriberId is null"
112 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
115 if (isBlank(subscriptionServiceType)) {
116 msg = "Input subscriptionServiceType is null"
118 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
121 if (productFamilyId == null) {
122 execution.setVariable("productFamilyId", "")
125 String sdncCallbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
126 if (isBlank(sdncCallbackUrl)) {
127 msg = "mso.workflow.sdncadapter.callback is null"
129 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
131 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
132 msoLogger.debug("SDNC Callback URL: " + sdncCallbackUrl)
134 //requestDetails.modelInfo.for AAI PUT servieInstanceData & SDNC assignTopology
135 String modelInvariantUuid = ""
136 String modelVersion = ""
137 String modelUuid = ""
138 String modelName = ""
139 String serviceInstanceName = ""
140 //Generated in parent.for AAI PUT
141 String serviceInstanceId = ""
142 String serviceType = ""
143 String serviceRole = ""
145 ServiceDecomposition serviceDecomp = (ServiceDecomposition) execution.getVariable("serviceDecomposition")
146 if (serviceDecomp != null)
148 serviceType = serviceDecomp.getServiceType() ?: ""
149 msoLogger.debug("serviceType:" + serviceType)
150 serviceRole = serviceDecomp.getServiceRole() ?: ""
152 ServiceInstance serviceInstance = serviceDecomp.getServiceInstance()
153 if (serviceInstance != null)
155 serviceInstanceId = serviceInstance.getInstanceId() ?: ""
156 serviceInstanceName = serviceInstance.getInstanceName() ?: ""
157 execution.setVariable("serviceInstanceId", serviceInstanceId)
158 execution.setVariable("serviceInstanceName", serviceInstanceName)
161 ModelInfo modelInfo = serviceDecomp.getModelInfo()
162 if (modelInfo != null)
164 modelInvariantUuid = modelInfo.getModelInvariantUuid() ?: ""
165 modelVersion = modelInfo.getModelVersion() ?: ""
166 modelUuid = modelInfo.getModelUuid() ?: ""
167 modelName = modelInfo.getModelName() ?: ""
171 msg = "Input serviceModelInfo is null"
173 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
178 //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData & SDNC assignToplology
179 serviceInstanceName = execution.getVariable("serviceInstanceName") ?: ""
180 serviceInstanceId = execution.getVariable("serviceInstanceId") ?: ""
182 String serviceModelInfo = execution.getVariable("serviceModelInfo")
183 if (isBlank(serviceModelInfo)) {
184 msg = "Input serviceModelInfo is null"
186 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
188 modelInvariantUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelInvariantUuid") ?: ""
189 modelVersion = jsonUtil.getJsonValue(serviceModelInfo, "modelVersion") ?: ""
190 modelUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelUuid") ?: ""
191 modelName = jsonUtil.getJsonValue(serviceModelInfo, "modelName") ?: ""
192 //modelCustomizationUuid NA for SI
196 execution.setVariable("serviceType", serviceType)
197 execution.setVariable("serviceRole", serviceRole)
198 execution.setVariable("serviceInstanceName", serviceInstanceName)
200 execution.setVariable("modelInvariantUuid", modelInvariantUuid)
201 execution.setVariable("modelVersion", modelVersion)
202 execution.setVariable("modelUuid", modelUuid)
203 execution.setVariable("modelName", modelName)
205 //alacarte SIs are NOT sent to sdnc. exceptions are listed in config variable
206 String svcTypes = UrnPropertiesReader.getVariable("sdnc.si.svc.types",execution) ?: ""
207 msoLogger.debug("SDNC SI serviceTypes:" + svcTypes)
208 List<String> svcList = Arrays.asList(svcTypes.split("\\s*,\\s*"));
209 boolean isSdncService= false
210 for (String listEntry : svcList){
211 if (listEntry.equalsIgnoreCase(serviceType)){
217 //All Macros are sent to SDNC, TRANSPORT(Macro) is sent to SDNW
218 //Alacartes are sent to SDNC if they are listed in config variable above
219 execution.setVariable("sendToSDNC", true)
220 if(execution.getVariable("sdncVersion").equals("1610")) //alacarte
223 execution.setVariable("sendToSDNC", false)
224 //alacarte non-sdnc svcs must provide name (sdnc provides name for rest)
225 if (isBlank(execution.getVariable("serviceInstanceName" )))
227 msg = "Input serviceInstanceName must be provided for alacarte"
229 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
234 msoLogger.debug("isSdncService: " + isSdncService)
235 msoLogger.debug("Send To SDNC: " + execution.getVariable("sendToSDNC"))
236 msoLogger.debug("Service Type: " + execution.getVariable("serviceType"))
238 //macro may provide name and alacarte-portm may provide name
239 execution.setVariable("checkAAI", false)
240 if (!isBlank(execution.getVariable("serviceInstanceName" )))
242 execution.setVariable("checkAAI", true)
245 if (isBlank(serviceInstanceId)){
246 msg = "Input serviceInstanceId is null"
248 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
252 StringBuilder sbParams = new StringBuilder()
253 Map<String, String> paramsMap = execution.getVariable("serviceInputParams")
254 if (paramsMap != null)
256 sbParams.append("<service-input-parameters>")
257 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
259 String paramName = entry.getKey()
260 String paramValue = entry.getValue()
263 <name>${MsoUtils.xmlEscape(paramName)}</name>
264 <value>${MsoUtils.xmlEscape(paramValue)}</value>
267 sbParams.append(paramsXml)
269 sbParams.append("</service-input-parameters>")
271 String siParamsXml = sbParams.toString()
272 if (siParamsXml == null)
274 execution.setVariable("siParamsXml", siParamsXml)
276 } catch (BpmnError e) {
278 } catch (Exception ex){
279 msg = "Exception in preProcessRequest " + ex.getMessage()
281 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
283 msoLogger.trace("Exit preProcessRequest")
286 public void getAAICustomerById (DelegateExecution execution) {
287 // https://{aaiEP}/aai/v8/business/customers/customer/{globalCustomerId}
290 String globalCustomerId = execution.getVariable("globalSubscriberId") //VID to AAI name map
291 msoLogger.debug(" ***** getAAICustomerById ***** globalCustomerId:" + globalCustomerId)
293 AAIUri uri = AAIUriFactory.createResourceUri(AAIObjectType.CUSTOMER, globalCustomerId)
294 if(!getAAIClient().exists(uri)){
295 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "GlobalCustomerId:" + globalCustomerId + " not found (404) in AAI")
297 } catch (BpmnError e) {
299 } catch (Exception ex) {
300 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Exception in getAAICustomerById. " + ex.getMessage())
302 msoLogger.trace("Exit getAAICustomerById")
306 public void putServiceInstance(DelegateExecution execution) {
307 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
308 msoLogger.trace("putServiceInstance")
310 String serviceInstanceId = execution.getVariable("serviceInstanceId")
313 String serviceType = execution.getVariable("serviceType")
315 String oStatus = execution.getVariable("initialStatus") ?: "Active"
316 if ("TRANSPORT".equalsIgnoreCase(serviceType))
321 //QUERY CATALOG DB AND GET WORKLOAD / ENVIRONMENT CONTEXT
322 String environmentContext = ""
323 String workloadContext =""
324 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
327 String json = catalogDbUtils.getServiceResourcesByServiceModelInvariantUuidString(execution,modelInvariantUuid )
329 msoLogger.debug("JSON IS: "+json)
331 environmentContext = jsonUtil.getJsonValue(json, "serviceResources.environmentContext") ?: ""
332 workloadContext = jsonUtil.getJsonValue(json, "serviceResources.workloadContext") ?: ""
333 msoLogger.debug("Env Context is: "+ environmentContext)
334 msoLogger.debug("Workload Context is: "+ workloadContext)
337 } catch (Exception ex){
338 msg = "Exception in preProcessRequest " + ex.getMessage()
340 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
343 org.onap.aai.domain.yang.ServiceInstance si = new org.onap.aai.domain.yang.ServiceInstance()
344 si.setServiceInstanceName(execution.getVariable("serviceInstanceName"))
345 si.setServiceType(serviceType)
346 si.setServiceRole(execution.getVariable("serviceRole"))
347 si.setOrchestrationStatus(oStatus)
348 si.setModelInvariantId(modelInvariantUuid)
349 si.setModelVersionId(execution.getVariable("modelUuid"))
350 si.setEnvironmentContext(environmentContext)
351 si.setWorkloadContext(workloadContext)
353 AAIResourcesClient client = new AAIResourcesClient()
354 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, execution.getVariable("globalSubscriberId"), execution.getVariable("subscriptionServiceType"), serviceInstanceId)
355 client.create(uri, si)
357 } catch (BpmnError e) {
359 } catch (Exception ex) {
360 //start rollback set up
361 def rollbackData = execution.getVariable("rollbackData")
362 if (rollbackData == null) {
363 rollbackData = new RollbackData()
365 def disableRollback = execution.getVariable("disableRollback")
366 rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
367 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
368 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)
369 rollbackData.put("SERVICEINSTANCE", "subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
370 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
371 execution.setVariable("rollbackData", rollbackData)
373 msg = "Exception in DoCreateServiceInstance.putServiceInstance. " + ex.getMessage()
375 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
377 msoLogger.trace("Exit putServiceInstance")
380 public void preProcessSDNCAssignRequest(DelegateExecution execution) {
381 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
383 msoLogger.trace("preProcessSDNCAssignRequest")
386 def serviceInstanceId = execution.getVariable("serviceInstanceId")
387 def serviceInstanceName = execution.getVariable("serviceInstanceName")
388 def callbackURL = execution.getVariable("sdncCallbackUrl")
389 def requestId = execution.getVariable("msoRequestId")
390 def serviceId = execution.getVariable("productFamilyId")
391 def subscriptionServiceType = execution.getVariable("subscriptionServiceType")
392 def globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
395 def modelInvariantUuid = execution.getVariable("modelInvariantUuid")
396 def modelVersion = execution.getVariable("modelVersion")
397 def modelUuid = execution.getVariable("modelUuid")
398 def modelName = execution.getVariable("modelName")
400 def sdncRequestId = UUID.randomUUID().toString()
402 def siParamsXml = execution.getVariable("siParamsXml")
404 // special URL for SDNW, msoAction helps set diff url in SDNCA
405 if("TRANSPORT".equalsIgnoreCase(execution.getVariable("serviceType")))
407 msoAction = "TRANSPORT"
410 String sdncAssignRequest =
411 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
412 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
413 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
414 <sdncadapter:RequestHeader>
415 <sdncadapter:RequestId>${MsoUtils.xmlEscape(sdncRequestId)}</sdncadapter:RequestId>
416 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
417 <sdncadapter:SvcAction>assign</sdncadapter:SvcAction>
418 <sdncadapter:SvcOperation>service-topology-operation</sdncadapter:SvcOperation>
419 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
420 <sdncadapter:MsoAction>${MsoUtils.xmlEscape(msoAction)}</sdncadapter:MsoAction>
421 </sdncadapter:RequestHeader>
422 <sdncadapterworkflow:SDNCRequestData>
423 <request-information>
424 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
429 <request-action>CreateServiceInstance</request-action>
430 </request-information>
431 <service-information>
432 <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
433 <subscription-service-type>${MsoUtils.xmlEscape(subscriptionServiceType)}</subscription-service-type>
434 <onap-model-information>
435 <model-invariant-uuid>${MsoUtils.xmlEscape(modelInvariantUuid)}</model-invariant-uuid>
436 <model-uuid>${MsoUtils.xmlEscape(modelUuid)}</model-uuid>
437 <model-version>${MsoUtils.xmlEscape(modelVersion)}</model-version>
438 <model-name>${MsoUtils.xmlEscape(modelName)}</model-name>
439 </onap-model-information>
440 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
442 <global-customer-id>${MsoUtils.xmlEscape(globalSubscriberId)}</global-customer-id>
443 </service-information>
444 <service-request-input>
445 <service-instance-name>${MsoUtils.xmlEscape(serviceInstanceName)}</service-instance-name>
447 </service-request-input>
448 </sdncadapterworkflow:SDNCRequestData>
449 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
451 msoLogger.debug("sdncAssignRequest:\n" + sdncAssignRequest)
452 sdncAssignRequest = utils.formatXml(sdncAssignRequest)
453 execution.setVariable("sdncAssignRequest", sdncAssignRequest)
454 msoLogger.debug("sdncAssignRequest: " + sdncAssignRequest)
456 def sdncRequestId2 = UUID.randomUUID().toString()
457 String sdncDelete = sdncAssignRequest.replace(">assign<", ">delete<").replace(">CreateServiceInstance<", ">DeleteServiceInstance<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
458 def sdncRequestId3 = UUID.randomUUID().toString()
459 String sdncDeactivate = sdncDelete.replace(">delete<", ">deactivate<").replace(">${sdncRequestId2}<", ">${sdncRequestId3}<")
460 def rollbackData = execution.getVariable("rollbackData")
461 if (rollbackData != null) {
462 rollbackData.put("SERVICEINSTANCE", "sdncDeactivate", sdncDeactivate)
463 rollbackData.put("SERVICEINSTANCE", "sdncDelete", sdncDelete)
464 execution.setVariable("rollbackData", rollbackData)
466 msoLogger.debug("rollbackData:\n" + rollbackData.toString())
469 } catch (BpmnError e) {
471 } catch(Exception ex) {
472 msg = "Exception in preProcessSDNCAssignRequest. " + ex.getMessage()
474 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
476 msoLogger.trace("Exit preProcessSDNCAssignRequest")
479 public void postProcessSDNCAssign (DelegateExecution execution) {
480 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
481 msoLogger.trace("postProcessSDNCAssign")
483 WorkflowException workflowException = execution.getVariable("WorkflowException")
484 msoLogger.debug("workflowException: " + workflowException)
486 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
488 String response = execution.getVariable("sdncAdapterResponse")
489 msoLogger.debug("SDNCResponse: " + response)
491 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
492 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
494 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
495 msoLogger.debug("Good response from SDNC Adapter for service-instance topology assign: \n" + response)
497 def rollbackData = execution.getVariable("rollbackData")
498 if (rollbackData != null) {
499 rollbackData.put("SERVICEINSTANCE", "rollbackSDNC", "true")
500 execution.setVariable("rollbackData", rollbackData)
504 msoLogger.debug("Bad Response from SDNC Adapter for service-instance assign")
505 throw new BpmnError("MSOWorkflowException")
508 } catch (BpmnError e) {
510 } catch(Exception ex) {
511 msg = "Exception in postProcessSDNCAssign. " + ex.getMessage()
513 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
515 msoLogger.trace("Exit postProcessSDNCAssign")
518 public void postProcessAAIGET2(DelegateExecution execution) {
519 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
520 msoLogger.trace("postProcessAAIGET2")
524 String serviceInstanceName = execution.getVariable("serviceInstanceName")
525 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
527 msoLogger.debug("Error getting Service-instance from AAI in postProcessAAIGET2", + serviceInstanceName)
528 WorkflowException workflowException = execution.getVariable("WorkflowException")
529 msoLogger.debug("workflowException: " + workflowException)
530 if(workflowException != null){
531 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
535 msg = "Failure in postProcessAAIGET2 GENGS_SuccessIndicator:" + succInAAI
537 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
542 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
544 String aaiService = execution.getVariable("GENGS_service")
545 if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "service-instance-name"))) {
546 execution.setVariable("serviceInstanceName", utils.getNodeText(aaiService, "service-instance-name"))
547 msoLogger.debug("Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"))
551 } catch (BpmnError e) {
553 } catch (Exception ex) {
554 msg = "Exception in DoCreateServiceInstance.postProcessAAIGET2 " + ex.getMessage()
556 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
558 msoLogger.trace("Exit postProcessAAIGET2")
561 public void preProcessRollback (DelegateExecution execution) {
562 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
563 msoLogger.trace("preProcessRollback")
566 Object workflowException = execution.getVariable("WorkflowException");
568 if (workflowException instanceof WorkflowException) {
569 msoLogger.debug("Prev workflowException: " + workflowException.getErrorMessage())
570 execution.setVariable("prevWorkflowException", workflowException);
571 //execution.setVariable("WorkflowException", null);
573 } catch (BpmnError e) {
574 msoLogger.debug("BPMN Error during preProcessRollback")
575 } catch(Exception ex) {
576 String msg = "Exception in preProcessRollback. " + ex.getMessage()
579 msoLogger.trace("Exit preProcessRollback")
582 public void postProcessRollback (DelegateExecution execution) {
583 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
584 msoLogger.trace("postProcessRollback")
587 Object workflowException = execution.getVariable("prevWorkflowException");
588 if (workflowException instanceof WorkflowException) {
589 msoLogger.debug("Setting prevException to WorkflowException: ")
590 execution.setVariable("WorkflowException", workflowException);
592 execution.setVariable("rollbackData", null)
593 } catch (BpmnError b) {
594 msoLogger.debug("BPMN Error during postProcessRollback")
596 } catch(Exception ex) {
597 msg = "Exception in postProcessRollback. " + ex.getMessage()
600 msoLogger.trace("Exit postProcessRollback")
603 public void createProject(DelegateExecution execution) {
604 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
605 msoLogger.trace("createProject")
607 String bpmnRequest = execution.getVariable("requestJson")
608 String projectName = jsonUtil.getJsonValue(bpmnRequest, "requestDetails.project.projectName")
609 String serviceInstance = execution.getVariable("serviceInstanceId")
611 msoLogger.debug("BPMN REQUEST IS: "+ bpmnRequest)
612 msoLogger.debug("PROJECT NAME: " + projectName)
613 msoLogger.debug("Service Instance: " + serviceInstance)
615 if(projectName == null||projectName.equals("")){
616 msoLogger.debug("Project Name was not found in input. Skipping task...")
619 AAICreateResources aaiCR = new AAICreateResources()
620 aaiCR.createAAIProject(projectName, serviceInstance)
621 }catch(Exception ex){
622 String msg = "Exception in createProject. " + ex.getMessage();
625 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
628 msoLogger.trace("Exit createProject")
631 public void createOwningEntity(DelegateExecution execution) {
632 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
633 msoLogger.trace("createOwningEntity")
635 String bpmnRequest = execution.getVariable("requestJson")
636 String owningEntityId = jsonUtil.getJsonValue(bpmnRequest, "requestDetails.owningEntity.owningEntityId")
637 String owningEntityName = jsonUtil.getJsonValue(bpmnRequest,"requestDetails.owningEntity.owningEntityName");
638 String serviceInstance = execution.getVariable("serviceInstanceId")
640 msoLogger.debug("owningEntity: " + owningEntityId)
641 msoLogger.debug("OwningEntityName: "+ owningEntityName)
642 msoLogger.debug("Service Instance: " + serviceInstance)
645 AAICreateResources aaiCR = new AAICreateResources()
646 if(owningEntityId==null||owningEntityId.equals("")){
647 msg = "Exception in createOwningEntity. OwningEntityId is null in input.";
648 throw new IllegalStateException();
650 if(aaiCR.existsOwningEntity(owningEntityId)){
651 aaiCR.connectOwningEntityandServiceInstance(owningEntityId,serviceInstance)
653 if(owningEntityName==null||owningEntityName.equals("")){
654 msg = "Exception in createOwningEntity. Can't create an owningEntity without an owningEntityName in input.";
655 throw new IllegalStateException();
657 Optional<OwningEntity> owningEntity = aaiCR.getOwningEntityNames(owningEntityName);
658 if(owningEntity.isPresent()){
659 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).";
660 throw new IllegalStateException();
662 aaiCR.createAAIOwningEntity(owningEntityId, owningEntityName, serviceInstance)
667 }catch(Exception ex){
670 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
672 msoLogger.trace("Exit createOwningEntity")
675 // *******************************
676 // Build Error Section
677 // *******************************
679 public void processJavaException(DelegateExecution execution){
680 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
683 msoLogger.debug("Caught a Java Exception in DoCreateServiceInstance")
684 msoLogger.debug("Started processJavaException Method")
685 msoLogger.debug("Variables List: " + execution.getVariables())
686 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception in DoCreateServiceInstance") // Adding this line temporarily until this flows error handling gets updated
687 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception in DoCreateServiceInstance")
690 msoLogger.debug("Caught Exception during processJavaException Method: " + e)
691 execution.setVariable("UnexpectedError", "Exception in processJavaException") // Adding this line temporarily until this flows error handling gets updated
692 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method")
694 msoLogger.trace("Completed processJavaException Method in DoCreateServiceInstance")