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 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}
288 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
292 String globalCustomerId = execution.getVariable("globalSubscriberId") //VID to AAI name map
293 msoLogger.debug(" ***** getAAICustomerById ***** globalCustomerId:" + globalCustomerId)
295 AaiUtil aaiUriUtil = new AaiUtil(this)
297 AAIUri uri = AAIUriFactory.createResourceUri(AAIObjectType.CUSTOMER, globalCustomerId)
298 String getAAICustomerUrl = aaiUriUtil.createAaiUri(uri)
300 if (isBlank(getAAICustomerUrl))
302 msg = "AAI URL is invalid. Endpoint:" + getAAICustomerUrl
304 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
307 msoLogger.debug("getAAICustomerById Url:" + getAAICustomerUrl)
308 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, getAAICustomerUrl)
309 String returnCode = response.getStatusCode()
310 String aaiResponseAsString = response.getResponseBodyAsString()
312 msg = "getAAICustomerById ResponseCode:" + returnCode + " ResponseString:" + aaiResponseAsString
315 if (returnCode=='200') {
316 // Customer found by ID. FLow to proceed.
320 //we might verify that service-subscription with matching name exists
321 //and throw error if not. If not checked, we will get exception in subsequent step on Create call
322 //in 1610 we assume both customer & service subscription were pre-created
325 if (returnCode=='404') {
326 msg = "GlobalCustomerId:" + globalCustomerId + " not found (404) in AAI"
328 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
331 if (aaiResponseAsString.contains("RESTFault")) {
332 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, aaiResponseAsString, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
333 WorkflowException workflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
334 execution.setVariable("WorkflowException", workflowException)
335 throw new BpmnError("MSOWorkflowException")
339 msg = "Error in getAAICustomerById ResponseCode:" + returnCode
341 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
346 } catch (BpmnError e) {
348 } catch (Exception ex) {
349 msg = "Exception in getAAICustomerById. " + ex.getMessage()
351 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
353 msoLogger.trace("Exit getAAICustomerById")
357 public void putServiceInstance(DelegateExecution execution) {
358 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
359 msoLogger.trace("putServiceInstance")
361 String serviceInstanceId = execution.getVariable("serviceInstanceId")
364 String serviceType = execution.getVariable("serviceType")
366 String oStatus = execution.getVariable("initialStatus") ?: "Active"
367 if ("TRANSPORT".equalsIgnoreCase(serviceType))
372 //QUERY CATALOG DB AND GET WORKLOAD / ENVIRONMENT CONTEXT
373 String environmentContext = ""
374 String workloadContext =""
375 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
378 String json = cutils.getServiceResourcesByServiceModelInvariantUuidString(execution,modelInvariantUuid )
380 msoLogger.debug("JSON IS: "+json)
382 environmentContext = jsonUtil.getJsonValue(json, "serviceResources.environmentContext") ?: ""
383 workloadContext = jsonUtil.getJsonValue(json, "serviceResources.workloadContext") ?: ""
384 msoLogger.debug("Env Context is: "+ environmentContext)
385 msoLogger.debug("Workload Context is: "+ workloadContext)
388 } catch (Exception ex){
389 msg = "Exception in preProcessRequest " + ex.getMessage()
391 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
394 org.onap.aai.domain.yang.ServiceInstance si = new org.onap.aai.domain.yang.ServiceInstance()
395 si.setServiceInstanceName(execution.getVariable("serviceInstanceName"))
396 si.setServiceType(serviceType)
397 si.setServiceRole(execution.getVariable("serviceRole"))
398 si.setOrchestrationStatus(oStatus)
399 si.setModelInvariantId(modelInvariantUuid)
400 si.setModelVersionId(execution.getVariable("modelUuid"))
401 si.setEnvironmentContext(environmentContext)
402 si.setWorkloadContext(workloadContext)
404 AAIResourcesClient client = new AAIResourcesClient()
405 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, execution.getVariable("globalSubscriberId"), execution.getVariable("subscriptionServiceType"), serviceInstanceId)
406 client.create(uri, si)
408 } catch (BpmnError e) {
410 } catch (Exception ex) {
411 //start rollback set up
412 RollbackData rollbackData = new RollbackData()
413 def disableRollback = execution.getVariable("disableRollback")
414 rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
415 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
416 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)
417 rollbackData.put("SERVICEINSTANCE", "subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
418 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
419 execution.setVariable("rollbackData", rollbackData)
421 msg = "Exception in DoCreateServiceInstance.putServiceInstance. " + ex.getMessage()
423 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
425 msoLogger.trace("Exit putServiceInstance")
428 public void preProcessSDNCAssignRequest(DelegateExecution execution) {
429 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
431 msoLogger.trace("preProcessSDNCAssignRequest")
434 def serviceInstanceId = execution.getVariable("serviceInstanceId")
435 def serviceInstanceName = execution.getVariable("serviceInstanceName")
436 def callbackURL = execution.getVariable("sdncCallbackUrl")
437 def requestId = execution.getVariable("msoRequestId")
438 def serviceId = execution.getVariable("productFamilyId")
439 def subscriptionServiceType = execution.getVariable("subscriptionServiceType")
440 def globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
443 def modelInvariantUuid = execution.getVariable("modelInvariantUuid")
444 def modelVersion = execution.getVariable("modelVersion")
445 def modelUuid = execution.getVariable("modelUuid")
446 def modelName = execution.getVariable("modelName")
448 def sdncRequestId = UUID.randomUUID().toString()
450 def siParamsXml = execution.getVariable("siParamsXml")
452 // special URL for SDNW, msoAction helps set diff url in SDNCA
453 if("TRANSPORT".equalsIgnoreCase(execution.getVariable("serviceType")))
455 msoAction = "TRANSPORT"
458 String sdncAssignRequest =
459 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
460 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
461 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
462 <sdncadapter:RequestHeader>
463 <sdncadapter:RequestId>${MsoUtils.xmlEscape(sdncRequestId)}</sdncadapter:RequestId>
464 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
465 <sdncadapter:SvcAction>assign</sdncadapter:SvcAction>
466 <sdncadapter:SvcOperation>service-topology-operation</sdncadapter:SvcOperation>
467 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
468 <sdncadapter:MsoAction>${MsoUtils.xmlEscape(msoAction)}</sdncadapter:MsoAction>
469 </sdncadapter:RequestHeader>
470 <sdncadapterworkflow:SDNCRequestData>
471 <request-information>
472 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
477 <request-action>CreateServiceInstance</request-action>
478 </request-information>
479 <service-information>
480 <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
481 <subscription-service-type>${MsoUtils.xmlEscape(subscriptionServiceType)}</subscription-service-type>
482 <onap-model-information>
483 <model-invariant-uuid>${MsoUtils.xmlEscape(modelInvariantUuid)}</model-invariant-uuid>
484 <model-uuid>${MsoUtils.xmlEscape(modelUuid)}</model-uuid>
485 <model-version>${MsoUtils.xmlEscape(modelVersion)}</model-version>
486 <model-name>${MsoUtils.xmlEscape(modelName)}</model-name>
487 </onap-model-information>
488 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
490 <global-customer-id>${MsoUtils.xmlEscape(globalSubscriberId)}</global-customer-id>
491 </service-information>
492 <service-request-input>
493 <service-instance-name>${MsoUtils.xmlEscape(serviceInstanceName)}</service-instance-name>
495 </service-request-input>
496 </sdncadapterworkflow:SDNCRequestData>
497 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
499 msoLogger.debug("sdncAssignRequest:\n" + sdncAssignRequest)
500 sdncAssignRequest = utils.formatXml(sdncAssignRequest)
501 execution.setVariable("sdncAssignRequest", sdncAssignRequest)
502 msoLogger.debug("sdncAssignRequest: " + sdncAssignRequest)
504 def sdncRequestId2 = UUID.randomUUID().toString()
505 String sdncDelete = sdncAssignRequest.replace(">assign<", ">delete<").replace(">CreateServiceInstance<", ">DeleteServiceInstance<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
506 def sdncRequestId3 = UUID.randomUUID().toString()
507 String sdncDeactivate = sdncDelete.replace(">delete<", ">deactivate<").replace(">${sdncRequestId2}<", ">${sdncRequestId3}<")
508 def rollbackData = execution.getVariable("rollbackData")
509 rollbackData.put("SERVICEINSTANCE", "sdncDeactivate", sdncDeactivate)
510 rollbackData.put("SERVICEINSTANCE", "sdncDelete", sdncDelete)
511 execution.setVariable("rollbackData", rollbackData)
513 msoLogger.debug("rollbackData:\n" + rollbackData.toString())
515 } catch (BpmnError e) {
517 } catch(Exception ex) {
518 msg = "Exception in preProcessSDNCAssignRequest. " + ex.getMessage()
520 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
522 msoLogger.trace("Exit preProcessSDNCAssignRequest")
525 public void postProcessSDNCAssign (DelegateExecution execution) {
526 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
527 msoLogger.trace("postProcessSDNCAssign")
529 WorkflowException workflowException = execution.getVariable("WorkflowException")
530 msoLogger.debug("workflowException: " + workflowException)
532 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
534 String response = execution.getVariable("sdncAdapterResponse")
535 msoLogger.debug("SDNCResponse: " + response)
537 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
538 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
540 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
541 msoLogger.debug("Good response from SDNC Adapter for service-instance topology assign: \n" + response)
543 def rollbackData = execution.getVariable("rollbackData")
544 rollbackData.put("SERVICEINSTANCE", "rollbackSDNC", "true")
545 execution.setVariable("rollbackData", rollbackData)
548 msoLogger.debug("Bad Response from SDNC Adapter for service-instance assign")
549 throw new BpmnError("MSOWorkflowException")
552 } catch (BpmnError e) {
554 } catch(Exception ex) {
555 msg = "Exception in postProcessSDNCAssign. " + ex.getMessage()
557 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
559 msoLogger.trace("Exit postProcessSDNCAssign")
562 public void postProcessAAIGET2(DelegateExecution execution) {
563 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
564 msoLogger.trace("postProcessAAIGET2")
568 String serviceInstanceName = execution.getVariable("serviceInstanceName")
569 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
571 msoLogger.debug("Error getting Service-instance from AAI in postProcessAAIGET2", + serviceInstanceName)
572 WorkflowException workflowException = execution.getVariable("WorkflowException")
573 msoLogger.debug("workflowException: " + workflowException)
574 if(workflowException != null){
575 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
579 msg = "Failure in postProcessAAIGET2 GENGS_SuccessIndicator:" + succInAAI
581 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
586 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
588 String aaiService = execution.getVariable("GENGS_service")
589 if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "service-instance-name"))) {
590 execution.setVariable("serviceInstanceName", utils.getNodeText(aaiService, "service-instance-name"))
591 msoLogger.debug("Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"))
595 } catch (BpmnError e) {
597 } catch (Exception ex) {
598 msg = "Exception in DoCreateServiceInstance.postProcessAAIGET2 " + ex.getMessage()
600 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
602 msoLogger.trace("Exit postProcessAAIGET2")
605 public void preProcessRollback (DelegateExecution execution) {
606 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
607 msoLogger.trace("preProcessRollback")
610 Object workflowException = execution.getVariable("WorkflowException");
612 if (workflowException instanceof WorkflowException) {
613 msoLogger.debug("Prev workflowException: " + workflowException.getErrorMessage())
614 execution.setVariable("prevWorkflowException", workflowException);
615 //execution.setVariable("WorkflowException", null);
617 } catch (BpmnError e) {
618 msoLogger.debug("BPMN Error during preProcessRollback")
619 } catch(Exception ex) {
620 String msg = "Exception in preProcessRollback. " + ex.getMessage()
623 msoLogger.trace("Exit preProcessRollback")
626 public void postProcessRollback (DelegateExecution execution) {
627 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
628 msoLogger.trace("postProcessRollback")
631 Object workflowException = execution.getVariable("prevWorkflowException");
632 if (workflowException instanceof WorkflowException) {
633 msoLogger.debug("Setting prevException to WorkflowException: ")
634 execution.setVariable("WorkflowException", workflowException);
636 execution.setVariable("rollbackData", null)
637 } catch (BpmnError b) {
638 msoLogger.debug("BPMN Error during postProcessRollback")
640 } catch(Exception ex) {
641 msg = "Exception in postProcessRollback. " + ex.getMessage()
644 msoLogger.trace("Exit postProcessRollback")
647 public void createProject(DelegateExecution execution) {
648 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
649 msoLogger.trace("createProject")
651 String bpmnRequest = execution.getVariable("requestJson")
652 String projectName = jsonUtil.getJsonValue(bpmnRequest, "requestDetails.project.projectName")
653 String serviceInstance = execution.getVariable("serviceInstanceId")
655 msoLogger.debug("BPMN REQUEST IS: "+ bpmnRequest)
656 msoLogger.debug("PROJECT NAME: " + projectName)
657 msoLogger.debug("Service Instance: " + serviceInstance)
659 if(projectName == null||projectName.equals("")){
660 msoLogger.debug("Project Name was not found in input. Skipping task...")
663 AAICreateResources aaiCR = new AAICreateResources()
664 aaiCR.createAAIProject(projectName, serviceInstance)
665 }catch(Exception ex){
666 String msg = "Exception in createProject. " + ex.getMessage();
669 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
672 msoLogger.trace("Exit createProject")
675 public void createOwningEntity(DelegateExecution execution) {
676 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
677 msoLogger.trace("createOwningEntity")
679 String bpmnRequest = execution.getVariable("requestJson")
680 String owningEntityId = jsonUtil.getJsonValue(bpmnRequest, "requestDetails.owningEntity.owningEntityId")
681 String owningEntityName = jsonUtil.getJsonValue(bpmnRequest,"requestDetails.owningEntity.owningEntityName");
682 String serviceInstance = execution.getVariable("serviceInstanceId")
684 msoLogger.debug("owningEntity: " + owningEntityId)
685 msoLogger.debug("OwningEntityName: "+ owningEntityName)
686 msoLogger.debug("Service Instance: " + serviceInstance)
689 AAICreateResources aaiCR = new AAICreateResources()
690 if(owningEntityId==null||owningEntityId.equals("")){
691 msg = "Exception in createOwningEntity. OwningEntityId is null in input.";
692 throw new IllegalStateException();
694 if(aaiCR.existsOwningEntity(owningEntityId)){
695 aaiCR.connectOwningEntityandServiceInstance(owningEntityId,serviceInstance)
697 if(owningEntityName==null||owningEntityName.equals("")){
698 msg = "Exception in createOwningEntity. Can't create an owningEntity without an owningEntityName in input.";
699 throw new IllegalStateException();
701 Optional<OwningEntity> owningEntity = aaiCR.getOwningEntityNames(owningEntityName);
702 if(owningEntity.isPresent()){
703 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).";
704 throw new IllegalStateException();
706 aaiCR.createAAIOwningEntity(owningEntityId, owningEntityName, serviceInstance)
711 }catch(Exception ex){
714 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
716 msoLogger.trace("Exit createOwningEntity")
719 // *******************************
720 // Build Error Section
721 // *******************************
723 public void processJavaException(DelegateExecution execution){
724 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
727 msoLogger.debug("Caught a Java Exception in DoCreateServiceInstance")
728 msoLogger.debug("Started processJavaException Method")
729 msoLogger.debug("Variables List: " + execution.getVariables())
730 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception in DoCreateServiceInstance") // Adding this line temporarily until this flows error handling gets updated
731 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception in DoCreateServiceInstance")
734 msoLogger.debug("Caught Exception during processJavaException Method: " + e)
735 execution.setVariable("UnexpectedError", "Exception in processJavaException") // Adding this line temporarily until this flows error handling gets updated
736 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method")
738 msoLogger.trace("Completed processJavaException Method in DoCreateServiceInstance")