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.logger.MessageEnum
44 import org.onap.so.logger.MsoLogger
45 import org.onap.so.rest.APIResponse
46 import org.springframework.web.util.UriUtils
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 MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateServiceInstance.class);
79 String Prefix="DCRESI_"
80 ExceptionUtil exceptionUtil = new ExceptionUtil()
81 JsonUtils jsonUtil = new JsonUtils()
82 CatalogDbUtils cutils = new CatalogDbUtils()
84 public void preProcessRequest (DelegateExecution execution) {
85 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
87 msoLogger.trace("preProcessRequest")
90 String requestId = execution.getVariable("msoRequestId")
91 execution.setVariable("prefix", Prefix)
93 setBasicDBAuthHeader(execution, isDebugEnabled)
95 //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
96 String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
98 //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
99 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
101 //requestDetails.requestParameters. for SDNC assignTopology
102 String productFamilyId = execution.getVariable("productFamilyId") //AAI productFamilyId
104 if (isBlank(globalSubscriberId)) {
105 msg = "Input globalSubscriberId is null"
107 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
110 if (isBlank(subscriptionServiceType)) {
111 msg = "Input subscriptionServiceType is null"
113 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
116 if (productFamilyId == null) {
117 execution.setVariable("productFamilyId", "")
120 String sdncCallbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
121 if (isBlank(sdncCallbackUrl)) {
122 msg = "mso.workflow.sdncadapter.callback is null"
124 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
126 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
127 msoLogger.debug("SDNC Callback URL: " + sdncCallbackUrl)
129 //requestDetails.modelInfo.for AAI PUT servieInstanceData & SDNC assignTopology
130 String modelInvariantUuid = ""
131 String modelVersion = ""
132 String modelUuid = ""
133 String modelName = ""
134 String serviceInstanceName = ""
135 //Generated in parent.for AAI PUT
136 String serviceInstanceId = ""
137 String serviceType = ""
138 String serviceRole = ""
140 ServiceDecomposition serviceDecomp = (ServiceDecomposition) execution.getVariable("serviceDecomposition")
141 if (serviceDecomp != null)
143 serviceType = serviceDecomp.getServiceType() ?: ""
144 msoLogger.debug("serviceType:" + serviceType)
145 serviceRole = serviceDecomp.getServiceRole() ?: ""
147 ServiceInstance serviceInstance = serviceDecomp.getServiceInstance()
148 if (serviceInstance != null)
150 serviceInstanceId = serviceInstance.getInstanceId() ?: ""
151 serviceInstanceName = serviceInstance.getInstanceName() ?: ""
152 execution.setVariable("serviceInstanceId", serviceInstanceId)
153 execution.setVariable("serviceInstanceName", serviceInstanceName)
156 ModelInfo modelInfo = serviceDecomp.getModelInfo()
157 if (modelInfo != null)
159 modelInvariantUuid = modelInfo.getModelInvariantUuid() ?: ""
160 modelVersion = modelInfo.getModelVersion() ?: ""
161 modelUuid = modelInfo.getModelUuid() ?: ""
162 modelName = modelInfo.getModelName() ?: ""
166 msg = "Input serviceModelInfo is null"
168 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
173 //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData & SDNC assignToplology
174 serviceInstanceName = execution.getVariable("serviceInstanceName") ?: ""
175 serviceInstanceId = execution.getVariable("serviceInstanceId") ?: ""
177 String serviceModelInfo = execution.getVariable("serviceModelInfo")
178 if (isBlank(serviceModelInfo)) {
179 msg = "Input serviceModelInfo is null"
181 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
183 modelInvariantUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelInvariantUuid") ?: ""
184 modelVersion = jsonUtil.getJsonValue(serviceModelInfo, "modelVersion") ?: ""
185 modelUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelUuid") ?: ""
186 modelName = jsonUtil.getJsonValue(serviceModelInfo, "modelName") ?: ""
187 //modelCustomizationUuid NA for SI
191 execution.setVariable("serviceType", serviceType)
192 execution.setVariable("serviceRole", serviceRole)
193 execution.setVariable("serviceInstanceName", serviceInstanceName)
195 execution.setVariable("modelInvariantUuid", modelInvariantUuid)
196 execution.setVariable("modelVersion", modelVersion)
197 execution.setVariable("modelUuid", modelUuid)
198 execution.setVariable("modelName", modelName)
200 //alacarte SIs are NOT sent to sdnc. exceptions are listed in config variable
201 String svcTypes = UrnPropertiesReader.getVariable("sdnc.si.svc.types",execution) ?: ""
202 msoLogger.debug("SDNC SI serviceTypes:" + svcTypes)
203 List<String> svcList = Arrays.asList(svcTypes.split("\\s*,\\s*"));
204 boolean isSdncService= false
205 for (String listEntry : svcList){
206 if (listEntry.equalsIgnoreCase(serviceType)){
212 //All Macros are sent to SDNC, TRANSPORT(Macro) is sent to SDNW
213 //Alacartes are sent to SDNC if they are listed in config variable above
214 execution.setVariable("sendToSDNC", true)
215 if(execution.getVariable("sdncVersion").equals("1610")) //alacarte
218 execution.setVariable("sendToSDNC", false)
219 //alacarte non-sdnc svcs must provide name (sdnc provides name for rest)
220 if (isBlank(execution.getVariable("serviceInstanceName" )))
222 msg = "Input serviceInstanceName must be provided for alacarte"
224 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
229 msoLogger.debug("isSdncService: " + isSdncService)
230 msoLogger.debug("Send To SDNC: " + execution.getVariable("sendToSDNC"))
231 msoLogger.debug("Service Type: " + execution.getVariable("serviceType"))
233 //macro may provide name and alacarte-portm may provide name
234 execution.setVariable("checkAAI", false)
235 if (!isBlank(execution.getVariable("serviceInstanceName" )))
237 execution.setVariable("checkAAI", true)
240 if (isBlank(serviceInstanceId)){
241 msg = "Input serviceInstanceId is null"
243 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
247 StringBuilder sbParams = new StringBuilder()
248 Map<String, String> paramsMap = execution.getVariable("serviceInputParams")
249 if (paramsMap != null)
251 sbParams.append("<service-input-parameters>")
252 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
254 String paramName = entry.getKey()
255 String paramValue = entry.getValue()
258 <name>${MsoUtils.xmlEscape(paramName)}</name>
259 <value>${MsoUtils.xmlEscape(paramValue)}</value>
262 sbParams.append(paramsXml)
264 sbParams.append("</service-input-parameters>")
266 String siParamsXml = sbParams.toString()
267 if (siParamsXml == null)
269 execution.setVariable("siParamsXml", siParamsXml)
272 String oStatus = execution.getVariable("initialStatus") ?: "Active"
273 if ("TRANSPORT".equalsIgnoreCase(serviceType))
278 String statusLine = isBlank(oStatus) ? "" : "<orchestration-status>${MsoUtils.xmlEscape(oStatus)}</orchestration-status>"
279 String serviceTypeLine = isBlank(serviceType) ? "" : "<service-type>${MsoUtils.xmlEscape(serviceType)}</service-type>"
280 String serviceRoleLine = isBlank(serviceRole) ? "" : "<service-role>${MsoUtils.xmlEscape(serviceRole)}</service-role>"
282 //QUERY CATALOG DB AND GET WORKLOAD / ENVIRONMENT CONTEXT
283 String environmentContext = ""
284 String workloadContext =""
287 String json = cutils.getServiceResourcesByServiceModelInvariantUuidString(execution,modelInvariantUuid )
289 msoLogger.debug("JSON IS: "+json)
291 environmentContext = jsonUtil.getJsonValue(json, "serviceResources.environmentContext") ?: ""
292 workloadContext = jsonUtil.getJsonValue(json, "serviceResources.workloadContext") ?: ""
293 msoLogger.debug("Env Context is: "+ environmentContext)
294 msoLogger.debug("Workload Context is: "+ workloadContext)
297 } catch (Exception ex){
298 msg = "Exception in preProcessRequest " + ex.getMessage()
300 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
304 AaiUtil aaiUriUtil = new AaiUtil(this)
305 String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
306 String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)
307 String serviceInstanceData =
308 """<service-instance xmlns=\"${namespace}\">
309 <service-instance-name>${MsoUtils.xmlEscape(serviceInstanceName)}</service-instance-name>
313 <model-invariant-id>${MsoUtils.xmlEscape(modelInvariantUuid)}</model-invariant-id>
314 <model-version-id>${MsoUtils.xmlEscape(modelUuid)}</model-version-id>
315 <environment-context>${MsoUtils.xmlEscape(environmentContext)}</environment-context>
316 <workload-context>${MsoUtils.xmlEscape(workloadContext)}</workload-context>
317 </service-instance>""".trim()
319 execution.setVariable("serviceInstanceData", serviceInstanceData)
320 msoLogger.debug(" 'payload' to create Service Instance in AAI - " + "\n" + serviceInstanceData)
322 } catch (BpmnError e) {
324 } catch (Exception ex){
325 msg = "Exception in preProcessRequest " + ex.getMessage()
327 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
329 msoLogger.trace("Exit preProcessRequest")
332 //TODO: Will be able to replace with call to GenericGetService
333 public void getAAICustomerById (DelegateExecution execution) {
334 // https://{aaiEP}/aai/v8/business/customers/customer/{globalCustomerId}
335 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
339 String globalCustomerId = execution.getVariable("globalSubscriberId") //VID to AAI name map
340 msoLogger.debug(" ***** getAAICustomerById ***** globalCustomerId:" + globalCustomerId)
342 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
343 AaiUtil aaiUriUtil = new AaiUtil(this)
344 String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
345 if (isBlank(aai_endpoint) || isBlank(aai_uri))
347 msg = "AAI URL is invalid. Endpoint:" + aai_endpoint + aai_uri
349 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
351 String getAAICustomerUrl = "${aai_endpoint}${aai_uri}/" + UriUtils.encode(globalCustomerId,"UTF-8")
353 msoLogger.debug("getAAICustomerById Url:" + getAAICustomerUrl)
354 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, getAAICustomerUrl)
355 String returnCode = response.getStatusCode()
356 String aaiResponseAsString = response.getResponseBodyAsString()
358 msg = "getAAICustomerById ResponseCode:" + returnCode + " ResponseString:" + aaiResponseAsString
361 if (returnCode=='200') {
362 // Customer found by ID. FLow to proceed.
366 //we might verify that service-subscription with matching name exists
367 //and throw error if not. If not checked, we will get exception in subsequent step on Create call
368 //in 1610 we assume both customer & service subscription were pre-created
371 if (returnCode=='404') {
372 msg = "GlobalCustomerId:" + globalCustomerId + " not found (404) in AAI"
374 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
377 if (aaiResponseAsString.contains("RESTFault")) {
378 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, aaiResponseAsString, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
379 WorkflowException workflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
380 execution.setVariable("WorkflowException", workflowException)
381 throw new BpmnError("MSOWorkflowException")
385 msg = "Error in getAAICustomerById ResponseCode:" + returnCode
387 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
392 } catch (BpmnError e) {
394 } catch (Exception ex) {
395 msg = "Exception in getAAICustomerById. " + ex.getMessage()
397 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
399 msoLogger.trace("Exit getAAICustomerById")
403 public void postProcessAAIGET(DelegateExecution execution) {
404 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
405 msoLogger.trace("postProcessAAIGET")
409 String serviceInstanceName = execution.getVariable("serviceInstanceName")
410 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
412 msoLogger.debug("Error getting Service-instance from AAI", + serviceInstanceName)
413 WorkflowException workflowException = execution.getVariable("WorkflowException")
414 if(workflowException != null){
415 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
419 msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
421 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
426 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
428 msoLogger.debug("Found Service-instance in AAI")
429 msg = "ServiceInstance already exists in AAI:" + serviceInstanceName
431 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
434 } catch (BpmnError e) {
436 } catch (Exception ex) {
437 msg = "Exception in DoCreateServiceInstance.postProcessAAIGET. " + ex.getMessage()
439 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
441 msoLogger.trace("Exit postProcessAAIGET")
444 public void postProcessAAIPUT(DelegateExecution execution) {
445 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
446 msoLogger.trace("postProcessAAIPUT")
449 String serviceInstanceId = execution.getVariable("serviceInstanceId")
450 boolean succInAAI = execution.getVariable("GENPS_SuccessIndicator")
452 msoLogger.debug("Error putting Service-instance in AAI", + serviceInstanceId)
453 WorkflowException workflowException = execution.getVariable("WorkflowException")
454 msoLogger.debug("workflowException: " + workflowException)
455 if(workflowException != null){
456 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
461 //start rollback set up
462 RollbackData rollbackData = new RollbackData()
463 def disableRollback = execution.getVariable("disableRollback")
464 rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
465 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
466 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)
467 rollbackData.put("SERVICEINSTANCE", "subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
468 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
469 execution.setVariable("rollbackData", rollbackData)
472 } catch (BpmnError e) {
474 } catch (Exception ex) {
475 msg = "Exception in DoCreateServiceInstance.postProcessAAIDEL. " + ex.getMessage()
477 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
479 msoLogger.trace("Exit postProcessAAIPUT")
482 public void preProcessSDNCAssignRequest(DelegateExecution execution) {
483 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
485 msoLogger.trace("preProcessSDNCAssignRequest")
488 def serviceInstanceId = execution.getVariable("serviceInstanceId")
489 def serviceInstanceName = execution.getVariable("serviceInstanceName")
490 def callbackURL = execution.getVariable("sdncCallbackUrl")
491 def requestId = execution.getVariable("msoRequestId")
492 def serviceId = execution.getVariable("productFamilyId")
493 def subscriptionServiceType = execution.getVariable("subscriptionServiceType")
494 def globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
497 def modelInvariantUuid = execution.getVariable("modelInvariantUuid")
498 def modelVersion = execution.getVariable("modelVersion")
499 def modelUuid = execution.getVariable("modelUuid")
500 def modelName = execution.getVariable("modelName")
502 def sdncRequestId = UUID.randomUUID().toString()
504 def siParamsXml = execution.getVariable("siParamsXml")
506 // special URL for SDNW, msoAction helps set diff url in SDNCA
507 if("TRANSPORT".equalsIgnoreCase(execution.getVariable("serviceType")))
509 msoAction = "TRANSPORT"
512 String sdncAssignRequest =
513 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
514 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
515 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
516 <sdncadapter:RequestHeader>
517 <sdncadapter:RequestId>${MsoUtils.xmlEscape(sdncRequestId)}</sdncadapter:RequestId>
518 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
519 <sdncadapter:SvcAction>assign</sdncadapter:SvcAction>
520 <sdncadapter:SvcOperation>service-topology-operation</sdncadapter:SvcOperation>
521 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
522 <sdncadapter:MsoAction>${MsoUtils.xmlEscape(msoAction)}</sdncadapter:MsoAction>
523 </sdncadapter:RequestHeader>
524 <sdncadapterworkflow:SDNCRequestData>
525 <request-information>
526 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
531 <request-action>CreateServiceInstance</request-action>
532 </request-information>
533 <service-information>
534 <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
535 <subscription-service-type>${MsoUtils.xmlEscape(subscriptionServiceType)}</subscription-service-type>
536 <onap-model-information>
537 <model-invariant-uuid>${MsoUtils.xmlEscape(modelInvariantUuid)}</model-invariant-uuid>
538 <model-uuid>${MsoUtils.xmlEscape(modelUuid)}</model-uuid>
539 <model-version>${MsoUtils.xmlEscape(modelVersion)}</model-version>
540 <model-name>${MsoUtils.xmlEscape(modelName)}</model-name>
541 </onap-model-information>
542 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
544 <global-customer-id>${MsoUtils.xmlEscape(globalSubscriberId)}</global-customer-id>
545 </service-information>
546 <service-request-input>
547 <service-instance-name>${MsoUtils.xmlEscape(serviceInstanceName)}</service-instance-name>
549 </service-request-input>
550 </sdncadapterworkflow:SDNCRequestData>
551 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
553 msoLogger.debug("sdncAssignRequest:\n" + sdncAssignRequest)
554 sdncAssignRequest = utils.formatXml(sdncAssignRequest)
555 execution.setVariable("sdncAssignRequest", sdncAssignRequest)
556 msoLogger.debug("sdncAssignRequest: " + sdncAssignRequest)
558 def sdncRequestId2 = UUID.randomUUID().toString()
559 String sdncDelete = sdncAssignRequest.replace(">assign<", ">delete<").replace(">CreateServiceInstance<", ">DeleteServiceInstance<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
560 def sdncRequestId3 = UUID.randomUUID().toString()
561 String sdncDeactivate = sdncDelete.replace(">delete<", ">deactivate<").replace(">${sdncRequestId2}<", ">${sdncRequestId3}<")
562 def rollbackData = execution.getVariable("rollbackData")
563 rollbackData.put("SERVICEINSTANCE", "sdncDeactivate", sdncDeactivate)
564 rollbackData.put("SERVICEINSTANCE", "sdncDelete", sdncDelete)
565 execution.setVariable("rollbackData", rollbackData)
567 msoLogger.debug("rollbackData:\n" + rollbackData.toString())
569 } catch (BpmnError e) {
571 } catch(Exception ex) {
572 msg = "Exception in preProcessSDNCAssignRequest. " + ex.getMessage()
574 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
576 msoLogger.trace("Exit preProcessSDNCAssignRequest")
579 public void postProcessSDNCAssign (DelegateExecution execution) {
580 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
581 msoLogger.trace("postProcessSDNCAssign")
583 WorkflowException workflowException = execution.getVariable("WorkflowException")
584 msoLogger.debug("workflowException: " + workflowException)
586 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
588 String response = execution.getVariable("sdncAdapterResponse")
589 msoLogger.debug("SDNCResponse: " + response)
591 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
592 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
594 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
595 msoLogger.debug("Good response from SDNC Adapter for service-instance topology assign: \n" + response)
597 def rollbackData = execution.getVariable("rollbackData")
598 rollbackData.put("SERVICEINSTANCE", "rollbackSDNC", "true")
599 execution.setVariable("rollbackData", rollbackData)
602 msoLogger.debug("Bad Response from SDNC Adapter for service-instance assign")
603 throw new BpmnError("MSOWorkflowException")
606 } catch (BpmnError e) {
608 } catch(Exception ex) {
609 msg = "Exception in postProcessSDNCAssign. " + ex.getMessage()
611 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
613 msoLogger.trace("Exit postProcessSDNCAssign")
616 public void postProcessAAIGET2(DelegateExecution execution) {
617 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
618 msoLogger.trace("postProcessAAIGET2")
622 String serviceInstanceName = execution.getVariable("serviceInstanceName")
623 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
625 msoLogger.debug("Error getting Service-instance from AAI in postProcessAAIGET2", + serviceInstanceName)
626 WorkflowException workflowException = execution.getVariable("WorkflowException")
627 msoLogger.debug("workflowException: " + workflowException)
628 if(workflowException != null){
629 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
633 msg = "Failure in postProcessAAIGET2 GENGS_SuccessIndicator:" + succInAAI
635 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
640 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
642 String aaiService = execution.getVariable("GENGS_service")
643 if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "service-instance-name"))) {
644 execution.setVariable("serviceInstanceName", utils.getNodeText(aaiService, "service-instance-name"))
645 msoLogger.debug("Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"))
649 } catch (BpmnError e) {
651 } catch (Exception ex) {
652 msg = "Exception in DoCreateServiceInstance.postProcessAAIGET2 " + ex.getMessage()
654 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
656 msoLogger.trace("Exit postProcessAAIGET2")
659 public void preProcessRollback (DelegateExecution execution) {
660 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
661 msoLogger.trace("preProcessRollback")
664 Object workflowException = execution.getVariable("WorkflowException");
666 if (workflowException instanceof WorkflowException) {
667 msoLogger.debug("Prev workflowException: " + workflowException.getErrorMessage())
668 execution.setVariable("prevWorkflowException", workflowException);
669 //execution.setVariable("WorkflowException", null);
671 } catch (BpmnError e) {
672 msoLogger.debug("BPMN Error during preProcessRollback")
673 } catch(Exception ex) {
674 String msg = "Exception in preProcessRollback. " + ex.getMessage()
677 msoLogger.trace("Exit preProcessRollback")
680 public void postProcessRollback (DelegateExecution execution) {
681 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
682 msoLogger.trace("postProcessRollback")
685 Object workflowException = execution.getVariable("prevWorkflowException");
686 if (workflowException instanceof WorkflowException) {
687 msoLogger.debug("Setting prevException to WorkflowException: ")
688 execution.setVariable("WorkflowException", workflowException);
690 execution.setVariable("rollbackData", null)
691 } catch (BpmnError b) {
692 msoLogger.debug("BPMN Error during postProcessRollback")
694 } catch(Exception ex) {
695 msg = "Exception in postProcessRollback. " + ex.getMessage()
698 msoLogger.trace("Exit postProcessRollback")
701 public void createProject(DelegateExecution execution) {
702 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
703 msoLogger.trace("createProject")
705 String bpmnRequest = execution.getVariable("requestJson")
706 String projectName = jsonUtil.getJsonValue(bpmnRequest, "requestDetails.project.projectName")
707 String serviceInstance = execution.getVariable("serviceInstanceId")
709 msoLogger.debug("BPMN REQUEST IS: "+ bpmnRequest)
710 msoLogger.debug("PROJECT NAME: " + projectName)
711 msoLogger.debug("Service Instance: " + serviceInstance)
713 if(projectName == null||projectName.equals("")){
714 msoLogger.debug("Project Name was not found in input. Skipping task...")
717 AAICreateResources aaiCR = new AAICreateResources()
718 aaiCR.createAAIProject(projectName, serviceInstance)
719 }catch(Exception ex){
720 String msg = "Exception in createProject. " + ex.getMessage();
723 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
726 msoLogger.trace("Exit createProject")
729 public void createOwningEntity(DelegateExecution execution) {
730 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
731 msoLogger.trace("createOwningEntity")
733 String bpmnRequest = execution.getVariable("requestJson")
734 String owningEntityId = jsonUtil.getJsonValue(bpmnRequest, "requestDetails.owningEntity.owningEntityId")
735 String owningEntityName = jsonUtil.getJsonValue(bpmnRequest,"requestDetails.owningEntity.owningEntityName");
736 String serviceInstance = execution.getVariable("serviceInstanceId")
738 msoLogger.debug("owningEntity: " + owningEntityId)
739 msoLogger.debug("OwningEntityName: "+ owningEntityName)
740 msoLogger.debug("Service Instance: " + serviceInstance)
743 AAICreateResources aaiCR = new AAICreateResources()
744 if(owningEntityId==null||owningEntityId.equals("")){
745 msg = "Exception in createOwningEntity. OwningEntityId is null in input.";
746 throw new IllegalStateException();
748 if(aaiCR.existsOwningEntity(owningEntityId)){
749 aaiCR.connectOwningEntityandServiceInstance(owningEntityId,serviceInstance)
751 if(owningEntityName==null||owningEntityName.equals("")){
752 msg = "Exception in createOwningEntity. Can't create an owningEntity without an owningEntityName in input.";
753 throw new IllegalStateException();
755 Optional<OwningEntity> owningEntity = aaiCR.getOwningEntityNames(owningEntityName);
756 if(owningEntity.isPresent()){
757 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).";
758 throw new IllegalStateException();
760 aaiCR.createAAIOwningEntity(owningEntityId, owningEntityName, serviceInstance)
765 }catch(Exception ex){
768 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
770 msoLogger.trace("Exit createOwningEntity")
773 // *******************************
774 // Build Error Section
775 // *******************************
777 public void processJavaException(DelegateExecution execution){
778 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
781 msoLogger.debug("Caught a Java Exception in DoCreateServiceInstance")
782 msoLogger.debug("Started processJavaException Method")
783 msoLogger.debug("Variables List: " + execution.getVariables())
784 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception in DoCreateServiceInstance") // Adding this line temporarily until this flows error handling gets updated
785 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception in DoCreateServiceInstance")
788 msoLogger.debug("Caught Exception during processJavaException Method: " + e)
789 execution.setVariable("UnexpectedError", "Exception in processJavaException") // Adding this line temporarily until this flows error handling gets updated
790 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method")
792 msoLogger.trace("Completed processJavaException Method in DoCreateServiceInstance")