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=========================================================
 
  20 package org.openecomp.mso.bpmn.infrastructure.scripts;
 
  22 import static org.apache.commons.lang3.StringUtils.*;
 
  23 import groovy.xml.XmlUtil
 
  26 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition
 
  27 import org.openecomp.mso.bpmn.core.domain.ServiceInstance
 
  28 import org.openecomp.mso.bpmn.core.domain.ModelInfo
 
  29 import org.openecomp.mso.bpmn.core.json.JsonUtils
 
  30 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
 
  31 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
 
  32 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
 
  33 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
 
  34 import org.openecomp.mso.bpmn.core.RollbackData
 
  35 import org.openecomp.mso.bpmn.core.WorkflowException
 
  36 import org.openecomp.mso.rest.APIResponse;
 
  37 import org.openecomp.mso.rest.RESTClient
 
  38 import org.openecomp.mso.rest.RESTConfig
 
  40 import java.util.UUID;
 
  42 import org.camunda.bpm.engine.delegate.BpmnError
 
  43 import org.camunda.bpm.engine.runtime.Execution
 
  44 import org.json.JSONObject;
 
  45 import org.apache.commons.lang3.*
 
  46 import org.apache.commons.codec.binary.Base64;
 
  47 import org.springframework.web.util.UriUtils;
 
  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)
 
  74 public class DoCreateServiceInstance extends AbstractServiceTaskProcessor {
 
  76         String Prefix="DCRESI_"
 
  77         ExceptionUtil exceptionUtil = new ExceptionUtil()
 
  78         JsonUtils jsonUtil = new JsonUtils()
 
  80         public void preProcessRequest (Execution execution) {
 
  81                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
 
  83                 utils.log("DEBUG"," ***** preProcessRequest *****",  isDebugEnabled)
 
  86                         String requestId = execution.getVariable("msoRequestId")
 
  87                         execution.setVariable("prefix", Prefix)
 
  90                         //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
 
  91                         String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
 
  93                         //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
 
  94                         String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
 
  96                         //requestDetails.requestParameters. for SDNC assignTopology
 
  97                         String productFamilyId = execution.getVariable("productFamilyId") //AAI productFamilyId
 
  99                         if (isBlank(globalSubscriberId)) {
 
 100                                 msg = "Input globalSubscriberId is null"
 
 101                                 utils.log("DEBUG", msg, isDebugEnabled)
 
 102                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
 105                         if (isBlank(subscriptionServiceType)) {
 
 106                                 msg = "Input subscriptionServiceType is null"
 
 107                                 utils.log("DEBUG", msg, isDebugEnabled)
 
 108                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
 111                         if (productFamilyId == null) {
 
 112                                 execution.setVariable("productFamilyId", "")
 
 115                         String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback')
 
 116                         if (isBlank(sdncCallbackUrl)) {
 
 117                                 msg = "URN_mso_workflow_sdncadapter_callback is null"
 
 118                                 utils.log("DEBUG", msg, isDebugEnabled)
 
 119                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
 121                         execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
 
 122                         utils.log("DEBUG","SDNC Callback URL: " + sdncCallbackUrl, isDebugEnabled)
 
 124                         //requestDetails.modelInfo.for AAI PUT servieInstanceData & SDNC assignTopology
 
 125                         String modelInvariantUuid = ""
 
 126                         String modelVersion = ""
 
 127                         String modelUuid = ""
 
 128                         String modelName = ""
 
 129                         String serviceInstanceName = "" 
 
 130                         //Generated in parent.for AAI PUT
 
 131                         String serviceInstanceId = ""
 
 132                         String serviceType = ""
 
 133                         String serviceRole = ""
 
 135                         ServiceDecomposition serviceDecomp = (ServiceDecomposition) execution.getVariable("serviceDecomposition")
 
 136                         if (serviceDecomp != null)
 
 138                                 serviceType = serviceDecomp.getServiceType()
 
 139                                 if (serviceType == null)
 
 141                                         utils.log("DEBUG", "null serviceType", isDebugEnabled)
 
 146                                         utils.log("DEBUG", "serviceType:" + serviceType, isDebugEnabled)
 
 148                                 serviceRole = serviceDecomp.getServiceRole()
 
 149                                 if (serviceRole == null)
 
 154                                 ServiceInstance serviceInstance = serviceDecomp.getServiceInstance()
 
 155                                 if (serviceInstance != null)
 
 157                                         serviceInstanceId = serviceInstance.getInstanceId()
 
 158                                         serviceInstanceName = serviceInstance.getInstanceName()
 
 159                                         execution.setVariable("serviceInstanceId", serviceInstanceId)
 
 160                                         execution.setVariable("serviceInstanceName", serviceInstanceName)
 
 163                                 ModelInfo modelInfo = serviceDecomp.getModelInfo()
 
 164                                 if (modelInfo != null)
 
 166                                         modelInvariantUuid = modelInfo.getModelInvariantUuid()
 
 167                                         modelVersion = modelInfo.getModelVersion()
 
 168                                         modelUuid = modelInfo.getModelUuid()
 
 169                                         modelName = modelInfo.getModelName()
 
 173                                         msg = "Input serviceModelInfo is null"
 
 174                                         utils.log("DEBUG", msg, isDebugEnabled)
 
 175                                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
 180                                 //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData & SDNC assignToplology
 
 181                                 serviceInstanceName = execution.getVariable("serviceInstanceName")
 
 182                                 serviceInstanceId = execution.getVariable("serviceInstanceId")
 
 184                                 String serviceModelInfo = execution.getVariable("serviceModelInfo")
 
 185                                 if (isBlank(serviceModelInfo)) {
 
 186                                         msg = "Input serviceModelInfo is null"
 
 187                                         utils.log("DEBUG", msg, isDebugEnabled)
 
 188                                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
 190                                 modelInvariantUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelInvariantUuid")
 
 191                                 modelVersion = jsonUtil.getJsonValue(serviceModelInfo, "modelVersion")
 
 192                                 modelUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelUuid")
 
 193                                 modelName = jsonUtil.getJsonValue(serviceModelInfo, "modelName")
 
 194                                 //modelCustomizationUuid NA for SI
 
 197                         execution.setVariable("serviceType", serviceType)
 
 198                         execution.setVariable("serviceRole", serviceRole)
 
 200                         if (serviceInstanceName == null) {
 
 201                                 execution.setVariable("serviceInstanceName", "")
 
 202                                 serviceInstanceName = ""
 
 204                         if (isBlank(serviceInstanceId)){
 
 205                                 msg = "Input serviceInstanceId is null"
 
 206                                 utils.log("DEBUG", msg, isDebugEnabled)
 
 207                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
 210                         if (modelInvariantUuid == null) {
 
 211                                 modelInvariantUuid = ""
 
 213                         if (modelUuid == null) {
 
 216                         if (modelVersion == null) {
 
 219                         if (modelName == null) {
 
 223                         execution.setVariable("modelInvariantUuid", modelInvariantUuid)
 
 224                         execution.setVariable("modelVersion", modelVersion)
 
 225                         execution.setVariable("modelUuid", modelUuid)
 
 226                         execution.setVariable("modelName", modelName)
 
 228                         StringBuilder sbParams = new StringBuilder()
 
 229                         Map<String, String> paramsMap = execution.getVariable("serviceInputParams")
 
 230                         if (paramsMap != null)
 
 232                                 sbParams.append("<service-input-parameters>")
 
 233                                 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
 
 235                                         String paramName = entry.getKey()
 
 236                                         String paramValue = entry.getValue()
 
 239                                                         <name>${paramName}</name>
 
 240                                                         <value>${paramValue}</value>
 
 243                                         sbParams.append(paramsXml)
 
 245                                 sbParams.append("</service-input-parameters>")
 
 247                         String siParamsXml = sbParams.toString()
 
 248                         if (siParamsXml == null)
 
 250                         execution.setVariable("siParamsXml", siParamsXml)
 
 253                         String oStatus= "Active"
 
 254                         if ("TRANSPORT".equalsIgnoreCase(serviceType))
 
 259                         AaiUtil aaiUriUtil = new AaiUtil(this)
 
 260                         String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
 
 261                         String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)
 
 262                         String serviceInstanceData =
 
 263                                         """<service-instance xmlns=\"${namespace}\">
 
 264                                         <service-instance-name>${serviceInstanceName}</service-instance-name>
 
 265                                         <service-type>${serviceType}</service-type>
 
 266                                         <service-role>${serviceRole}</service-role>
 
 267                                         <orchestration-status>${oStatus}</orchestration-status>
 
 268                                     <model-invariant-id>${modelInvariantUuid}</model-invariant-id>
 
 269                                     <model-version-id>${modelUuid}</model-version-id>
 
 270                                         </service-instance>""".trim()
 
 272                         execution.setVariable("serviceInstanceData", serviceInstanceData)
 
 273                         utils.logAudit(serviceInstanceData)
 
 274                         utils.log("DEBUG", " 'payload' to create Service Instance in AAI - " + "\n" + serviceInstanceData, isDebugEnabled)
 
 276                 } catch (BpmnError e) {
 
 278                 } catch (Exception ex){
 
 279                         msg = "Exception in preProcessRequest " + ex.getMessage()
 
 280                         utils.log("DEBUG", msg, isDebugEnabled)
 
 281                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 283                 utils.log("DEBUG"," ***** Exit preProcessRequest *****",  isDebugEnabled)
 
 286         //TODO: Will be able to replace with call to GenericGetService
 
 287         public void getAAICustomerById (Execution execution) {
 
 288                 // https://{aaiEP}/aai/v8/business/customers/customer/{globalCustomerId}
 
 289                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
 
 293                         String globalCustomerId = execution.getVariable("globalSubscriberId") //VID to AAI name map
 
 294                         utils.log("DEBUG"," ***** getAAICustomerById ***** globalCustomerId:" + globalCustomerId, isDebugEnabled)
 
 296                         String aai_endpoint = execution.getVariable("URN_aai_endpoint")
 
 297                         AaiUtil aaiUriUtil = new AaiUtil(this)
 
 298                         String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
 
 299                         if (isBlank(aai_endpoint) || isBlank(aai_uri))
 
 301                                 msg = "AAI URL is invalid. Endpoint:" + aai_endpoint + aai_uri
 
 302                                 utils.log("DEBUG", msg, isDebugEnabled)
 
 303                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
 305                         String getAAICustomerUrl = "${aai_endpoint}${aai_uri}/" + UriUtils.encode(globalCustomerId,"UTF-8")
 
 307                         utils.logAudit(getAAICustomerUrl)
 
 308                         utils.log("DEBUG", "getAAICustomerById Url:" + getAAICustomerUrl, isDebugEnabled)
 
 309                         APIResponse response = aaiUriUtil.executeAAIGetCall(execution, getAAICustomerUrl)
 
 310                         String returnCode = response.getStatusCode()
 
 311                         String aaiResponseAsString = response.getResponseBodyAsString()
 
 313                         msg = "getAAICustomerById ResponseCode:" + returnCode + " ResponseString:" + aaiResponseAsString
 
 314                         utils.log("DEBUG",msg, isDebugEnabled)
 
 317                         if (returnCode=='200') {
 
 318                                 // Customer found by ID. FLow to proceed.
 
 319                                 utils.log("DEBUG",msg, isDebugEnabled)
 
 322                                 //we might verify that service-subscription with matching name exists
 
 323                                 //and throw error if not. If not checked, we will get exception in subsequent step on Create call
 
 324                                 //in 1610 we assume both customer & service subscription were pre-created
 
 327                                 if (returnCode=='404') {
 
 328                                         msg = "GlobalCustomerId:" + globalCustomerId + " not found (404) in AAI"
 
 329                                         utils.log("DEBUG", msg, isDebugEnabled)
 
 330                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
 
 333                                         if (aaiResponseAsString.contains("RESTFault")) {
 
 334                                                 utils.log("ERROR", aaiResponseAsString)
 
 335                                                 WorkflowException workflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
 
 336                                                 execution.setVariable("WorkflowException", workflowException)
 
 337                                                 throw new BpmnError("MSOWorkflowException")
 
 341                                                 msg = "Error in getAAICustomerById ResponseCode:" + returnCode
 
 342                                                 utils.log("DEBUG", msg, isDebugEnabled)
 
 343                                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
 
 348                 } catch (BpmnError e) {
 
 350                 } catch (Exception ex) {
 
 351                         msg = "Exception in getAAICustomerById. " + ex.getMessage()
 
 352                         utils.log("DEBUG", msg, isDebugEnabled)
 
 353                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 355                 utils.log("DEBUG"," *****Exit getAAICustomerById *****", isDebugEnabled)
 
 359         public void postProcessAAIGET(Execution execution) {
 
 360                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
 
 361                 utils.log("DEBUG"," ***** postProcessAAIGET ***** ", isDebugEnabled)
 
 365                         String serviceInstanceName = execution.getVariable("serviceInstanceName")
 
 366                         boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
 
 367                         if(succInAAI != true){
 
 368                                 utils.log("DEBUG","Error getting Service-instance from AAI", + serviceInstanceName, isDebugEnabled)
 
 369                                 WorkflowException workflowException = execution.getVariable("WorkflowException")
 
 370                                 utils.logAudit("workflowException: " + workflowException)
 
 371                                 if(workflowException != null){
 
 372                                         exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
 
 376                                         msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
 
 377                                         utils.log("DEBUG", msg, isDebugEnabled)
 
 378                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
 
 383                                 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
 
 384                                 if(foundInAAI == true){
 
 385                                         utils.log("DEBUG","Found Service-instance in AAI", isDebugEnabled)
 
 386                                         msg = "ServiceInstance already exists in AAI:" + serviceInstanceName
 
 387                                         utils.log("DEBUG", msg, isDebugEnabled)
 
 388                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
 
 391                 } catch (BpmnError e) {
 
 393                 } catch (Exception ex) {
 
 394                         msg = "Exception in DoCreateServiceInstance.postProcessAAIGET. " + ex.getMessage()
 
 395                         utils.log("DEBUG", msg, isDebugEnabled)
 
 396                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 398                 utils.log("DEBUG"," *** Exit postProcessAAIGET *** ", isDebugEnabled)
 
 401         public void postProcessAAIPUT(Execution execution) {
 
 402                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
 
 403                 utils.log("DEBUG"," ***** postProcessAAIPUT ***** ", isDebugEnabled)
 
 406                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
 
 407                         boolean succInAAI = execution.getVariable("GENPS_SuccessIndicator")
 
 408                         if(succInAAI != true){
 
 409                                 utils.log("DEBUG","Error putting Service-instance in AAI", + serviceInstanceId, isDebugEnabled)
 
 410                                 WorkflowException workflowException = execution.getVariable("WorkflowException")
 
 411                                 utils.logAudit("workflowException: " + workflowException)
 
 412                                 if(workflowException != null){
 
 413                                         exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
 
 418                                 //start rollback set up
 
 419                                 RollbackData rollbackData = new RollbackData()
 
 420                                 def disableRollback = execution.getVariable("disableRollback")
 
 421                                 rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
 
 422                                 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
 
 423                                 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)
 
 424                                 rollbackData.put("SERVICEINSTANCE", "subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
 
 425                                 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
 
 426                                 execution.setVariable("rollbackData", rollbackData)
 
 429                 } catch (BpmnError e) {
 
 431                 } catch (Exception ex) {
 
 432                         msg = "Exception in DoCreateServiceInstance.postProcessAAIDEL. " + ex.getMessage()
 
 433                         utils.log("DEBUG", msg, isDebugEnabled)
 
 434                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 436                 utils.log("DEBUG"," *** Exit postProcessAAIPUT *** ", isDebugEnabled)
 
 439         public void preProcessSDNCAssignRequest(Execution execution) {
 
 440                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
 
 442                 utils.log("DEBUG"," ***** preProcessSDNCAssignRequest *****", isDebugEnabled)
 
 445                         def serviceInstanceId = execution.getVariable("serviceInstanceId")
 
 446                         def serviceInstanceName = execution.getVariable("serviceInstanceName")
 
 447                         def callbackURL = execution.getVariable("sdncCallbackUrl")
 
 448                         def requestId = execution.getVariable("msoRequestId")
 
 449                         def serviceId = execution.getVariable("productFamilyId")
 
 450                         def subscriptionServiceType = execution.getVariable("subscriptionServiceType")
 
 451                         def globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
 
 452                         def serviceType = execution.getVariable("serviceType")
 
 454                         def modelInvariantUuid = execution.getVariable("modelInvariantUuid")
 
 455                         def modelVersion = execution.getVariable("modelVersion")
 
 456                         def modelUuid = execution.getVariable("modelUuid")
 
 457                         def modelName = execution.getVariable("modelName")
 
 459                         def sdncRequestId = UUID.randomUUID().toString()
 
 461                         def siParamsXml = execution.getVariable("siParamsXml")
 
 463                         String sdncAssignRequest =
 
 464                                         """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
 
 465                                                                                                         xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
 
 466                                                                                                         xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
 
 467                                    <sdncadapter:RequestHeader>
 
 468                                                         <sdncadapter:RequestId>${sdncRequestId}</sdncadapter:RequestId>
 
 469                                                         <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId>
 
 470                                                         <sdncadapter:SvcAction>assign</sdncadapter:SvcAction>
 
 471                                                         <sdncadapter:SvcOperation>service-topology-operation</sdncadapter:SvcOperation>
 
 472                                                         <sdncadapter:CallbackUrl>${callbackURL}</sdncadapter:CallbackUrl>
 
 473                                                         <sdncadapter:MsoAction>${serviceType}</sdncadapter:MsoAction>
 
 474                                         </sdncadapter:RequestHeader>
 
 475                                 <sdncadapterworkflow:SDNCRequestData>
 
 476                                         <request-information>
 
 477                                                 <request-id>${requestId}</request-id>
 
 482                                                 <request-action>CreateServiceInstance</request-action>
 
 483                                         </request-information>
 
 484                                         <service-information>
 
 485                                                 <service-id>${serviceId}</service-id>
 
 486                                                 <subscription-service-type>${subscriptionServiceType}</subscription-service-type>
 
 487                                                 <ecomp-model-information>
 
 488                                                  <model-invariant-uuid>${modelInvariantUuid}</model-invariant-uuid>
 
 489                                                  <model-uuid>${modelUuid}</model-uuid>
 
 490                                                  <model-version>${modelVersion}</model-version>
 
 491                                                  <model-name>${modelName}</model-name>
 
 492                                             </ecomp-model-information>
 
 493                                                 <service-instance-id>${serviceInstanceId}</service-instance-id>
 
 495                                                 <global-customer-id>${globalSubscriberId}</global-customer-id>
 
 496                                         </service-information>
 
 497                                         <service-request-input>
 
 498                                                 <service-instance-name>${serviceInstanceName}</service-instance-name>
 
 500                                         </service-request-input>
 
 501                                 </sdncadapterworkflow:SDNCRequestData>
 
 502                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
 
 504                         utils.log("DEBUG","sdncAssignRequest:\n" + sdncAssignRequest, isDebugEnabled)
 
 505                         sdncAssignRequest = utils.formatXml(sdncAssignRequest)
 
 506                         execution.setVariable("sdncAssignRequest", sdncAssignRequest)
 
 507                         utils.logAudit("sdncAssignRequest:  " + sdncAssignRequest)
 
 509                         def sdncRequestId2 = UUID.randomUUID().toString()
 
 510                         String sdncDelete = sdncAssignRequest.replace(">assign<", ">delete<").replace(">CreateServiceInstance<", ">DeleteServiceInstance<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
 
 511                         def sdncRequestId3 = UUID.randomUUID().toString()
 
 512                         String sdncDeactivate = sdncDelete.replace(">delete<", ">deactivate<").replace(">${sdncRequestId2}<", ">${sdncRequestId3}<")
 
 513                         def rollbackData = execution.getVariable("rollbackData")
 
 514                         rollbackData.put("SERVICEINSTANCE", "sdncDeactivate", sdncDeactivate)
 
 515                         rollbackData.put("SERVICEINSTANCE", "sdncDelete", sdncDelete)
 
 516                         execution.setVariable("rollbackData", rollbackData)
 
 518                         utils.log("DEBUG","rollbackData:\n" + rollbackData.toString(), isDebugEnabled)
 
 520                 } catch (BpmnError e) {
 
 522                 } catch(Exception ex) {
 
 523                         msg = "Exception in preProcessSDNCAssignRequest. " + ex.getMessage()
 
 524                         utils.log("DEBUG", msg, isDebugEnabled)
 
 525                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 527                 utils.log("DEBUG"," *****Exit preProcessSDNCAssignRequest *****", isDebugEnabled)
 
 530         public void postProcessSDNCAssign (Execution execution) {
 
 531                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
 
 532                 utils.log("DEBUG"," ***** postProcessSDNCAssign ***** ", isDebugEnabled)
 
 534                         WorkflowException workflowException = execution.getVariable("WorkflowException")
 
 535                         utils.logAudit("workflowException: " + workflowException)
 
 537                         boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
 
 539                         String response = execution.getVariable("sdncAdapterResponse")
 
 540                         utils.logAudit("SDNCResponse: " + response)
 
 542                         SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
 
 543                         sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
 
 545                         if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
 
 546                                 utils.log("DEBUG","Good response from SDNC Adapter for service-instance  topology assign: \n" + response, isDebugEnabled)
 
 548                                 def rollbackData = execution.getVariable("rollbackData")
 
 549                                 rollbackData.put("SERVICEINSTANCE", "rollbackSDNC", "true")
 
 550                                 execution.setVariable("rollbackData", rollbackData)
 
 553                                 utils.log("DEBUG","Bad Response from SDNC Adapter for service-instance assign", isDebugEnabled)
 
 554                                 throw new BpmnError("MSOWorkflowException")
 
 557                 } catch (BpmnError e) {
 
 559                 } catch(Exception ex) {
 
 560                         msg = "Exception in postProcessSDNCAssign. " + ex.getMessage()
 
 561                         utils.log("DEBUG", msg, isDebugEnabled)
 
 562                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 564                 utils.log("DEBUG"," *** Exit postProcessSDNCAssign *** ", isDebugEnabled)
 
 567         public void postProcessAAIGET2(Execution execution) {
 
 568                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
 
 569                 utils.log("DEBUG"," ***** postProcessAAIGET2 ***** ", isDebugEnabled)
 
 573                         String serviceInstanceName = execution.getVariable("serviceInstanceName")
 
 574                         boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
 
 575                         if(succInAAI != true){
 
 576                                 utils.log("DEBUG","Error getting Service-instance from AAI in postProcessAAIGET2", + serviceInstanceName, isDebugEnabled)
 
 577                                 WorkflowException workflowException = execution.getVariable("WorkflowException")
 
 578                                 utils.logAudit("workflowException: " + workflowException)
 
 579                                 if(workflowException != null){
 
 580                                         exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
 
 584                                         msg = "Failure in postProcessAAIGET2 GENGS_SuccessIndicator:" + succInAAI
 
 585                                         utils.log("DEBUG", msg, isDebugEnabled)
 
 586                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
 
 591                                 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
 
 592                                 if(foundInAAI == true){
 
 593                                         String aaiService = execution.getVariable("GENGS_service")
 
 594                                         if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "service-instance-name"))) {
 
 595                                                 execution.setVariable("serviceInstanceName",  utils.getNodeText1(aaiService, "service-instance-name"))
 
 596                                                 utils.log("DEBUG","Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"), isDebugEnabled)
 
 600                 } catch (BpmnError e) {
 
 602                 } catch (Exception ex) {
 
 603                         msg = "Exception in DoCreateServiceInstance.postProcessAAIGET2 " + ex.getMessage()
 
 604                         utils.log("DEBUG", msg, isDebugEnabled)
 
 605                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 607                 utils.log("DEBUG"," *** Exit postProcessAAIGET2 *** ", isDebugEnabled)
 
 610         public void preProcessRollback (Execution execution) {
 
 611                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
 
 612                 utils.log("DEBUG"," ***** preProcessRollback ***** ", isDebugEnabled)
 
 615                         Object workflowException = execution.getVariable("WorkflowException");
 
 617                         if (workflowException instanceof WorkflowException) {
 
 618                                 utils.log("DEBUG", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)
 
 619                                 execution.setVariable("prevWorkflowException", workflowException);
 
 620                                 //execution.setVariable("WorkflowException", null);
 
 622                 } catch (BpmnError e) {
 
 623                         utils.log("DEBUG", "BPMN Error during preProcessRollback", isDebugEnabled)
 
 624                 } catch(Exception ex) {
 
 625                         String msg = "Exception in preProcessRollback. " + ex.getMessage()
 
 626                         utils.log("DEBUG", msg, isDebugEnabled)
 
 628                 utils.log("DEBUG"," *** Exit preProcessRollback *** ", isDebugEnabled)
 
 631         public void postProcessRollback (Execution execution) {
 
 632                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
 
 633                 utils.log("DEBUG"," ***** postProcessRollback ***** ", isDebugEnabled)
 
 636                         Object workflowException = execution.getVariable("prevWorkflowException");
 
 637                         if (workflowException instanceof WorkflowException) {
 
 638                                 utils.log("DEBUG", "Setting prevException to WorkflowException: ", isDebugEnabled)
 
 639                                 execution.setVariable("WorkflowException", workflowException);
 
 641                         execution.setVariable("rollbackData", null)
 
 642                 } catch (BpmnError b) {
 
 643                         utils.log("DEBUG", "BPMN Error during postProcessRollback", isDebugEnabled)
 
 645                 } catch(Exception ex) {
 
 646                         msg = "Exception in postProcessRollback. " + ex.getMessage()
 
 647                         utils.log("DEBUG", msg, isDebugEnabled)
 
 649                 utils.log("DEBUG"," *** Exit postProcessRollback *** ", isDebugEnabled)