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.vcpe.scripts;
 
  23 import org.onap.so.bpmn.common.scripts.*;
 
  24 import org.onap.so.bpmn.common.scripts.AaiUtil
 
  25 import org.onap.so.bpmn.core.RollbackData
 
  26 import org.onap.so.bpmn.core.WorkflowException
 
  27 import org.onap.so.bpmn.core.UrnPropertiesReader
 
  28 import org.onap.so.bpmn.core.json.JsonUtils
 
  29 import org.onap.so.rest.APIResponse
 
  31 import java.util.UUID;
 
  32 import org.camunda.bpm.engine.delegate.BpmnError
 
  33 import org.camunda.bpm.engine.delegate.DelegateExecution
 
  34 import org.apache.commons.lang3.*
 
  35 import org.springframework.web.util.UriUtils;
 
  36 import static org.apache.commons.lang3.StringUtils.*
 
  38 import org.onap.so.logger.MessageEnum
 
  39 import org.onap.so.logger.MsoLogger
 
  40 import org.onap.so.client.aai.AAIResourcesClient
 
  41 import org.onap.so.client.aai.AAIObjectType
 
  42 import org.onap.so.client.aai.entities.AAIResultWrapper
 
  43 import org.onap.so.client.aai.entities.Relationships
 
  44 import org.onap.so.client.aai.entities.uri.AAIResourceUri
 
  45 import org.onap.so.client.aai.entities.uri.AAIUriFactory
 
  46 import org.json.JSONObject
 
  47 import javax.ws.rs.NotFoundException
 
  49  * This groovy class supports the <class>DoCreateAllottedResourceBRG.bpmn</class> process.
 
  54  * @param - msoRequestId
 
  55  * @param - isDEbugLogEnabled
 
  56  * @param - disableRollback
 
  57  * @param - failExists  - O
 
  58  * @param - serviceInstanceId
 
  59  * @param - globalCustomerId - O
 
  60  * @param - subscriptionServiceType - O
 
  61  * @param - parentServiceInstanceId
 
  62  * @param - allottedReourceId - O
 
  63  * @param - allottedResourceModelInfo
 
  64  * @param - allottedResourceRole
 
  65  * @param - allottedResourceType
 
  66  * @param - brgWanMacAddress
 
  68  * @param - vgmuxBearerIP
 
  71  * @param - rollbackData (localRB->null)
 
  72  * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
 
  73  * @param - WorkflowException - O
 
  74  * @param - allottedResourceId
 
  75  * @param - allottedResourceName
 
  78 public class DoCreateAllottedResourceBRG extends AbstractServiceTaskProcessor{
 
  79         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateAllottedResourceBRG.class);
 
  81         String Prefix="DCARBRG_"
 
  82         ExceptionUtil exceptionUtil = new ExceptionUtil()
 
  83         JsonUtils jsonUtil = new JsonUtils()
 
  85         public void preProcessRequest (DelegateExecution execution) {
 
  89                 msoLogger.trace("start preProcessRequest")
 
  92                         execution.setVariable("prefix", Prefix)
 
  95                         String sdncCallbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
 
  96                         if (isBlank(sdncCallbackUrl)) {
 
  97                                 msg = "mso.workflow.sdncadapter.callback is null"
 
  99                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
 101                         execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
 
 102                         msoLogger.debug("SDNC Callback URL: " + sdncCallbackUrl)
 
 104                         String sdncReplDelay = UrnPropertiesReader.getVariable("mso.workflow.sdnc.replication.delay",execution)
 
 105                         if (isBlank(sdncReplDelay)) {
 
 106                                 msg = "mso.workflow.sdnc.replication.delay is null"
 
 108                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
 110                         execution.setVariable("sdncReplDelay", sdncReplDelay)
 
 111                         msoLogger.debug("SDNC replication delay: " + sdncReplDelay)
 
 114                         if (isBlank(execution.getVariable("serviceInstanceId"))){
 
 115                                 msg = "Input serviceInstanceId is null"
 
 117                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
 119                         if (isBlank(execution.getVariable("parentServiceInstanceId"))) {
 
 120                                 msg = "Input parentServiceInstanceId is null"
 
 122                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
 124                         if (isBlank(execution.getVariable("allottedResourceModelInfo"))) {
 
 125                                 msg = "Input allottedResourceModelInfo is null"
 
 127                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
 129                         if (isBlank(execution.getVariable("vni"))) {
 
 130                                 msg = "Input vni is null"
 
 132                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
 134                         if (isBlank(execution.getVariable("vgmuxBearerIP"))) {
 
 135                                 msg = "Input vgmuxBearerIP is null"
 
 137                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
 139                         if (isBlank(execution.getVariable("brgWanMacAddress"))) {
 
 140                                 msg = "Input brgWanMacAddress is null"
 
 142                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
 144                         if (isBlank(execution.getVariable("allottedResourceRole"))) {
 
 145                                 msg = "Input allottedResourceRole is null"
 
 147                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
 149                         if (isBlank(execution.getVariable("allottedResourceType"))) {
 
 150                                 msg = "Input allottedResourceType is null"
 
 152                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
 155                         msoLogger.debug("Rethrowing MSOWorkflowException")
 
 157                 } catch (Exception ex){
 
 158                         msg = "Exception in preProcessRequest " + ex.getMessage()
 
 160                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 162                 msoLogger.trace("end preProcessRequest")
 
 166          * Gets the service instance uri from aai
 
 168         public void getServiceInstance(DelegateExecution execution) {
 
 169                 msoLogger.trace("getServiceInstance ")
 
 171                         String serviceInstanceId = execution.getVariable('serviceInstanceId')
 
 173                         AAIResourcesClient resourceClient = new AAIResourcesClient()
 
 174                         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId)
 
 176                         if(resourceClient.exists(uri)){
 
 177                                 execution.setVariable("CSI_resourceLink", uri.build().toString())
 
 179                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service instance was not found in aai")
 
 182                 }catch(BpmnError e) {
 
 184                 }catch (Exception ex){
 
 185                         String msg = "Exception in getServiceInstance. " + ex.getMessage()
 
 187                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 189                 msoLogger.trace("Exit getServiceInstance ")
 
 192         public void getAaiAR (DelegateExecution execution) {
 
 195                 msoLogger.trace("start getAaiAR")
 
 197                 String arType = execution.getVariable("allottedResourceType")
 
 198                 String arRole = execution.getVariable("allottedResourceRole")
 
 200                 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
 
 201                 String orchStatus = arUtils.getAROrchStatus(execution)
 
 205                 if (orchStatus != null) // AR was found
 
 207                         if ("true".equals(execution.getVariable("failExists")))
 
 209                                 errorMsg = "Allotted resource " + arType + " with Role " + arRole + " already exists"
 
 213                                 if ("Active".equals(orchStatus))
 
 215                                         execution.setVariable("foundActiveAR", true)
 
 217                                 else // blanks included
 
 219                                         errorMsg = "Allotted Resource " + arType + " with Role " + arRole + " already exists in an incomplete state -"  +  orchStatus
 
 223                 if (!isBlank(errorMsg)) {
 
 224                         msoLogger.debug(errorMsg)
 
 225                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, errorMsg)
 
 227                 msoLogger.trace("end getAaiAR")
 
 230         public void getParentServiceInstance(DelegateExecution execution) {
 
 231                 msoLogger.trace("getParentServiceInstance ")
 
 233                         String serviceInstanceId = execution.getVariable('parentServiceInstanceId')
 
 235                         AAIResourcesClient resourceClient = new AAIResourcesClient()
 
 236                         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.NODES_QUERY, "").queryParam("search-node-type", "service-instance").queryParam("filter", "service-instance-id:EQUALS:" + serviceInstanceId)
 
 237                         String json = resourceClient.get(uri).getJson()
 
 239                         JSONObject obj = new JSONObject(json)
 
 240                         if(obj.has("result-data")){
 
 241                                 JSONObject ob = obj.getJSONArray("result-data").getJSONObject(0)
 
 242                                 String resourceLink = ob.getString("resource-link")
 
 244                                 String[] split = resourceLink.split("/aai/")
 
 245                                 String siRelatedLink = "/aai/" + split[1]
 
 247                                 execution.setVariable("PSI_resourceLink", resourceLink)
 
 249                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service instance was not found in aai")
 
 252                 }catch(BpmnError e) {
 
 254                 }catch (Exception ex){
 
 255                         String msg = "Exception in getParentServiceInstance. " + ex.getMessage()
 
 257                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 259                 msoLogger.trace("Exit getParentServiceInstance ")
 
 263         public void createAaiAR(DelegateExecution execution) {
 
 266                 msoLogger.trace("start createAaiAR")
 
 269                 String allottedResourceId = execution.getVariable("allottedResourceId")
 
 270                 if (isBlank(allottedResourceId))
 
 272                         allottedResourceId = UUID.randomUUID().toString()
 
 273                         execution.setVariable("allottedResourceId", allottedResourceId)
 
 279                         AaiUtil aaiUriUtil = new AaiUtil(this)
 
 280                         String aaiEndpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
 
 281                         String siResourceLink= execution.getVariable("PSI_resourceLink")
 
 284                         msoLogger.debug("PSI_resourceLink:" + siResourceLink)
 
 286                         if(!isBlank(siResourceLink)) {
 
 287                                 msoLogger.debug("Incoming PSI Resource Link is: " + siResourceLink)
 
 288                                 String[] split = siResourceLink.split("/aai/")
 
 289                                 siUri = "/aai/" + split[1]
 
 293                                 msg = "Parent Service Link in AAI is null"
 
 295                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
 298                         arUrl = "${aaiEndpoint}${siUri}"  + "/allotted-resources/allotted-resource/" + UriUtils.encode(allottedResourceId,"UTF-8")
 
 299                         execution.setVariable("aaiARPath", arUrl)
 
 300                         msoLogger.debug("GET AllottedResource AAI URL is:\n" + arUrl)
 
 302                         String namespace = aaiUriUtil.getNamespaceFromUri(execution, arUrl)
 
 304                         String arType = execution.getVariable("allottedResourceType")
 
 305                         String arRole = execution.getVariable("allottedResourceRole")
 
 306                         String CSI_resourceLink = execution.getVariable("CSI_resourceLink")
 
 307                         String arModelInfo = execution.getVariable("allottedResourceModelInfo")
 
 308                         String modelInvariantId = jsonUtil.getJsonValue(arModelInfo, "modelInvariantUuid")
 
 309                         String modelVersionId = jsonUtil.getJsonValue(arModelInfo, "modelUuid")
 
 310                         String modelCustomizationId = jsonUtil.getJsonValue(arModelInfo, "modelCustomizationUuid")
 
 312                         if (modelInvariantId == null) {
 
 313                                 modelInvariantId = ""
 
 315                         if (modelVersionId == null) {
 
 318                         if (modelCustomizationId == null) {
 
 319                                 modelCustomizationId = ""
 
 323                         """<allotted-resource xmlns="${namespace}">
 
 324                                 <id>${MsoUtils.xmlEscape(allottedResourceId)}</id>
 
 325                                 <description></description>
 
 326                                 <type>${MsoUtils.xmlEscape(arType)}</type>
 
 327                                 <role>${MsoUtils.xmlEscape(arRole)}</role>
 
 328                                 <selflink></selflink>
 
 329                                 <model-invariant-id>${MsoUtils.xmlEscape(modelInvariantId)}</model-invariant-id>
 
 330                                 <model-version-id>${MsoUtils.xmlEscape(modelVersionId)}</model-version-id>
 
 331                                 <model-customization-id>${MsoUtils.xmlEscape(modelCustomizationId)}</model-customization-id>
 
 332                                 <orchestration-status>PendingCreate</orchestration-status>
 
 333                                 <operation-status></operation-status>
 
 336                                 <related-to>service-instance</related-to>
 
 337                                 <related-link>${MsoUtils.xmlEscape(CSI_resourceLink)}</related-link>
 
 340                         </allotted-resource>""".trim()
 
 342                         execution.setVariable("AaiARPayload", payload)
 
 343                         msoLogger.debug(" payload to create AllottedResource in AAI:" + "\n" + payload)
 
 345                         APIResponse response = aaiUriUtil.executeAAIPutCall(execution, arUrl, payload)
 
 346                         int responseCode = response.getStatusCode()
 
 347                         msoLogger.debug("AllottedResource AAI PUT responseCode:" + responseCode)
 
 349                         String aaiResponse = response.getResponseBodyAsString()
 
 350                         msoLogger.debug("AllottedResource AAI PUT responseStr:" + aaiResponse)
 
 352                         //200 OK 201 CREATED 202 ACCEPTED
 
 353                         if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
 
 355                                 msoLogger.debug("AAI PUT AllottedResource received a Good Response")
 
 358                                 msoLogger.debug("AAI Put AllottedResouce received a Bad Response Code: " + responseCode)
 
 359                                 exceptionUtil.MapAAIExceptionToWorkflowExceptionGeneric(execution, aaiResponse, responseCode)
 
 360                                 throw new BpmnError("MSOWorkflowException")
 
 363                         msoLogger.debug("Rethrowing MSOWorkflowException")
 
 365                 } catch (Exception ex) {
 
 366                         msg = "Exception in createAaiAR " + ex.getMessage()
 
 368                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 371                 //start rollback set up
 
 372                 RollbackData rollbackData = new RollbackData()
 
 373                 def disableRollback = execution.getVariable("disableRollback")
 
 374                 rollbackData.put(Prefix, "disableRollback", disableRollback.toString())
 
 375                 rollbackData.put(Prefix, "rollbackAAI", "true")
 
 376                 rollbackData.put(Prefix, "allottedResourceId", allottedResourceId)
 
 377                 rollbackData.put(Prefix, "serviceInstanceId", execution.getVariable("serviceInstanceId"))
 
 378                 rollbackData.put(Prefix, "parentServiceInstanceId", execution.getVariable("parentServiceInstanceId"))
 
 379                 rollbackData.put(Prefix, "aaiARPath", arUrl)
 
 380                 execution.setVariable("rollbackData", rollbackData)
 
 381                 msoLogger.trace("end createAaiAR")
 
 384         public String buildSDNCRequest(DelegateExecution execution, String action, String sdncRequestId) {
 
 388                 msoLogger.trace("start buildSDNCRequest")
 
 389                 String sdncReq = null
 
 393                         String allottedResourceId = execution.getVariable("allottedResourceId")
 
 394                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
 
 395                         String globalCustomerId = execution.getVariable("globalCustomerId")
 
 396                         String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
 
 397                         String parentServiceInstanceId = execution.getVariable("parentServiceInstanceId")
 
 398                         String callbackUrl = execution.getVariable("sdncCallbackUrl")
 
 399                         String requestId = execution.getVariable("msoRequestId")
 
 401                         String brgWanMacAddress = execution.getVariable("brgWanMacAddress")
 
 402                         String vni = execution.getVariable("vni")
 
 403                         String vgmuxBearerIP = execution.getVariable("vgmuxBearerIP")
 
 405                         String arModelInfo = execution.getVariable("allottedResourceModelInfo")
 
 406                         String modelInvariantId = jsonUtil.getJsonValue(arModelInfo, "modelInvariantUuid")
 
 407                         String modelVersion = jsonUtil.getJsonValue(arModelInfo, "modelVersion")
 
 408                         String modelUUId = jsonUtil.getJsonValue(arModelInfo, "modelUuid")
 
 409                         String modelCustomizationId = jsonUtil.getJsonValue(arModelInfo, "modelCustomizationUuid")
 
 410                         String modelName = jsonUtil.getJsonValue(arModelInfo, "modelName")
 
 412                         if (modelInvariantId == null) {
 
 413                                 modelInvariantId = ""
 
 415                         if (modelVersion == null) {
 
 418                         if (modelUUId == null) {
 
 421                         if (modelName == null) {
 
 424                         if (modelCustomizationId == null) {
 
 425                                 modelCustomizationId = ""
 
 429                         """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
 
 430                                                                                                         xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
 
 431                                                                                                         xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
 
 432                                    <sdncadapter:RequestHeader>
 
 433                                                         <sdncadapter:RequestId>${MsoUtils.xmlEscape(sdncRequestId)}</sdncadapter:RequestId>
 
 434                                                         <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
 
 435                                                         <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
 
 436                                                         <sdncadapter:SvcOperation>brg-topology-operation</sdncadapter:SvcOperation>
 
 437                                                         <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
 
 438                                         </sdncadapter:RequestHeader>
 
 439                                 <sdncadapterworkflow:SDNCRequestData>
 
 440                                         <request-information>
 
 441                                                 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
 
 442                                                 <request-action>CreateBRGInstance</request-action>
 
 447                                         </request-information>
 
 448                                         <service-information>
 
 449                                                 <service-id></service-id>
 
 450                                                 <subscription-service-type>${MsoUtils.xmlEscape(subscriptionServiceType)}</subscription-service-type>
 
 451                                                 <onap-model-information></onap-model-information>
 
 452                                                 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
 
 454                                                 <global-customer-id>${MsoUtils.xmlEscape(globalCustomerId)}</global-customer-id>
 
 455                                         </service-information>
 
 456                                         <allotted-resource-information>
 
 457                                                 <allotted-resource-id>${MsoUtils.xmlEscape(allottedResourceId)}</allotted-resource-id>
 
 458                                                 <allotted-resource-type>brg</allotted-resource-type>
 
 459                                                 <parent-service-instance-id>${MsoUtils.xmlEscape(parentServiceInstanceId)}</parent-service-instance-id>
 
 460                                                 <onap-model-information>
 
 461                                                         <model-invariant-uuid>${MsoUtils.xmlEscape(modelInvariantId)}</model-invariant-uuid>
 
 462                                                         <model-uuid>${MsoUtils.xmlEscape(modelUUId)}</model-uuid>
 
 463                                                         <model-customization-uuid>${MsoUtils.xmlEscape(modelCustomizationId)}</model-customization-uuid>
 
 464                                                         <model-version>${MsoUtils.xmlEscape(modelVersion)}</model-version>
 
 465                                                         <model-name>${MsoUtils.xmlEscape(modelName)}</model-name>
 
 466                                                 </onap-model-information>
 
 467                                         </allotted-resource-information>
 
 469                                                         <brg-wan-mac-address>${MsoUtils.xmlEscape(brgWanMacAddress)}</brg-wan-mac-address>
 
 470                                                         <vni>${MsoUtils.xmlEscape(vni)}</vni>
 
 471                                                         <vgmux-bearer-ip>${MsoUtils.xmlEscape(vgmuxBearerIP)}</vgmux-bearer-ip>
 
 473                                 </sdncadapterworkflow:SDNCRequestData>
 
 474                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
 
 476                         msoLogger.debug("sdncRequest:\n" + sdncReq)
 
 477                         sdncReq = utils.formatXml(sdncReq)
 
 479                 } catch(Exception ex) {
 
 480                         msg = "Exception in buildSDNCRequest. " + ex.getMessage()
 
 482                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 484                 msoLogger.trace("end buildSDNCRequest")
 
 488         public void preProcessSDNCAssign(DelegateExecution execution) {
 
 492                 msoLogger.trace("start preProcessSDNCAssign")
 
 495                         String sdncRequestId = UUID.randomUUID().toString()
 
 496                         String sdncAssignReq = buildSDNCRequest(execution, "assign", sdncRequestId)
 
 497                         execution.setVariable("sdncAssignRequest", sdncAssignReq)
 
 498                         msoLogger.debug("sdncAssignRequest:  " + sdncAssignReq)
 
 499                         def sdncRequestId2 = UUID.randomUUID().toString()
 
 500                         String sdncAssignRollbackReq = sdncAssignReq.replace(">assign<", ">unassign<").replace(">CreateBRGInstance<", ">DeleteBRGInstance<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
 
 501                         def rollbackData = execution.getVariable("rollbackData")
 
 502                         rollbackData.put(Prefix, "sdncAssignRollbackReq", sdncAssignRollbackReq)
 
 503                         execution.setVariable("rollbackData", rollbackData)
 
 505                         msoLogger.debug("sdncAssignRollbackReq:\n" + sdncAssignRollbackReq)
 
 506                         msoLogger.debug("rollbackData:\n" + rollbackData.toString())
 
 508                 } catch (BpmnError e) {
 
 510                 } catch(Exception ex) {
 
 511                         msg = "Exception in preProcessSDNCAssign. " + ex.getMessage()
 
 513                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 515                 msoLogger.trace("end preProcessSDNCAssign")
 
 518         public void preProcessSDNCCreate(DelegateExecution execution) {
 
 522                 msoLogger.trace("start preProcessSDNCCreate")
 
 525                         String sdncRequestId = UUID.randomUUID().toString()
 
 526                         String sdncCreateReq = buildSDNCRequest(execution, "create", sdncRequestId)
 
 527                         execution.setVariable("sdncCreateRequest", sdncCreateReq)
 
 528                         msoLogger.debug("sdncCreateReq:  " + sdncCreateReq)
 
 529                         def sdncRequestId2 = UUID.randomUUID().toString()
 
 530                         String sdncCreateRollbackReq = sdncCreateReq.replace(">create<", ">delete<").replace(">CreateBRGInstance<", ">DeleteBRGInstance<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
 
 531                         def rollbackData = execution.getVariable("rollbackData")
 
 532                         rollbackData.put(Prefix, "sdncCreateRollbackReq", sdncCreateRollbackReq)
 
 533                         execution.setVariable("rollbackData", rollbackData)
 
 535                         msoLogger.debug("sdncCreateRollbackReq:\n" + sdncCreateRollbackReq)
 
 536                         msoLogger.debug("rollbackData:\n" + rollbackData.toString())
 
 538                 } catch (BpmnError e) {
 
 540                 } catch(Exception ex) {
 
 541                         msg = "Exception in preProcessSDNCCreate. " + ex.getMessage()
 
 543                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 545                 msoLogger.trace("end preProcessSDNCCreate")
 
 548         public void preProcessSDNCActivate(DelegateExecution execution) {
 
 552                 msoLogger.trace("start preProcessSDNCActivate")
 
 555                         String sdncRequestId = UUID.randomUUID().toString()
 
 556                         String sdncActivateReq = buildSDNCRequest(execution, "activate", sdncRequestId)
 
 557                         execution.setVariable("sdncActivateRequest", sdncActivateReq)
 
 558                         msoLogger.debug("sdncActivateReq:  " + sdncActivateReq)
 
 559                         def sdncRequestId2 = UUID.randomUUID().toString()
 
 560                         String sdncActivateRollbackReq = sdncActivateReq.replace(">activate<", ">deactivate<").replace(">CreateBRGInstance<", ">DeleteBRGInstance<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
 
 561                         def rollbackData = execution.getVariable("rollbackData")
 
 562                         rollbackData.put(Prefix, "sdncActivateRollbackReq", sdncActivateRollbackReq)
 
 563                         execution.setVariable("rollbackData", rollbackData)
 
 565                         msoLogger.debug("sdncActivateRollbackReq:\n" + sdncActivateRollbackReq)
 
 566                         msoLogger.debug("rollbackData:\n" + rollbackData.toString())
 
 568                 } catch (BpmnError e) {
 
 570                 } catch(Exception ex) {
 
 571                         msg = "Exception in preProcessSDNCActivate. " + ex.getMessage()
 
 573                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 575                 msoLogger.trace("end preProcessSDNCActivate")
 
 578         public void validateSDNCResp(DelegateExecution execution, String response, String method){
 
 581                 msoLogger.trace("ValidateSDNCResponse Process")
 
 585                         WorkflowException workflowException = execution.getVariable("WorkflowException")
 
 586                         msoLogger.debug("workflowException: " + workflowException)
 
 588                         boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
 
 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("Received a Good Response from SDNC Adapter for " + method + " SDNC Call.  Response is: \n" + response)
 
 597                                 if (!"get".equals(method))
 
 599                                         def rollbackData = execution.getVariable("rollbackData")
 
 600                                         rollbackData.put(Prefix, "rollback" +  "SDNC" + method, "true")
 
 601                                         execution.setVariable("rollbackData", rollbackData)
 
 605                                 msoLogger.debug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.")
 
 606                                 throw new BpmnError("MSOWorkflowException")
 
 608                 } catch (BpmnError e) {
 
 610                 } catch(Exception ex) {
 
 611                         msg = "Exception in validateSDNCResp. " + ex.getMessage()
 
 613                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 615                 msoLogger.trace("End ValidateSDNCResp Process")
 
 618         public void preProcessSDNCGet(DelegateExecution execution){
 
 620                 msoLogger.trace("start preProcessSDNCGet")
 
 623                         def callbackUrl = execution.getVariable("sdncCallbackUrl")
 
 624                         // serviceOperation (URI for topology GET) will be retrieved from "selflink" from AAI if active AR exists in AAI
 
 625                         // or from  "object-path" in SDNC response for assign when AR does not exist in AA
 
 627                         String serviceOperation = ""
 
 629                         if (execution.getVariable("foundActiveAR")) {
 
 630                                 def aaiQueryResponse = execution.getVariable("aaiARGetResponse")
 
 631                                 serviceOperation = utils.getNodeText(aaiQueryResponse, "selflink")
 
 632                                 msoLogger.debug("AR service operation/aaiARSelfLink: " + serviceOperation)
 
 636                                 String response = execution.getVariable("sdncAssignResponse")
 
 637                                 String data = utils.getNodeXml(response, "response-data")
 
 638                                 msoLogger.debug("Assign responseData: " + data)
 
 639                                 serviceOperation = utils.getNodeText(data, "object-path")
 
 640                                 msoLogger.debug("AR service operation:" + serviceOperation)
 
 643                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
 
 644                         String sdncRequestId = UUID.randomUUID().toString()
 
 646                         //neeed the same url as used by vfmodules
 
 647                         String SDNCGetRequest =
 
 648                         """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
 
 649                                                                                         xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
 
 650                                                                                         xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
 
 651                                         <sdncadapter:RequestHeader>
 
 652                                         <sdncadapter:RequestId>${MsoUtils.xmlEscape(sdncRequestId)}</sdncadapter:RequestId>
 
 653                                         <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
 
 654                                         <sdncadapter:SvcAction>query</sdncadapter:SvcAction>
 
 655                                         <sdncadapter:SvcOperation>${MsoUtils.xmlEscape(serviceOperation)}</sdncadapter:SvcOperation>
 
 656                                         <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
 
 657                                         <sdncadapter:MsoAction>vfmodule</sdncadapter:MsoAction>
 
 658                                 </sdncadapter:RequestHeader>
 
 659                                         <sdncadapterworkflow:SDNCRequestData></sdncadapterworkflow:SDNCRequestData>
 
 660                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
 
 662                         execution.setVariable("sdncGetRequest", SDNCGetRequest)
 
 665                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occurred Processing preProcessSDNCGetRequest.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
 
 666                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + e.getMessage())
 
 668                 msoLogger.trace("end preProcessSDNCGet")
 
 671         public void updateAaiAROrchStatus(DelegateExecution execution, String status){
 
 673                 msoLogger.trace("start updateAaiAROrchStatus")
 
 674                 String aaiARPath = execution.getVariable("aaiARPath") //set during query (existing AR) or create
 
 675                 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
 
 676                 String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath)
 
 677                 msoLogger.trace("end updateAaiAROrchStatus")
 
 680         public void generateOutputs(DelegateExecution execution)
 
 683                 msoLogger.trace("start generateOutputs")
 
 685                         String sdncGetResponse = execution.getVariable("enhancedCallbackRequestData") //unescaped
 
 686                         msoLogger.debug("resp:" + sdncGetResponse)
 
 687                         String arData = utils.getNodeXml(sdncGetResponse, "brg-topology")
 
 688                         arData = utils.removeXmlNamespaces(arData)
 
 690                         String brga = utils.getNodeXml(arData, "brg-assignments")
 
 691                         String ari = utils.getNodeXml(arData, "allotted-resource-identifiers")
 
 692                         execution.setVariable("allotedResourceName", utils.getNodeText(ari, "allotted-resource-name"))
 
 693                 } catch (BpmnError e) {
 
 694                         msoLogger.debug("BPMN Error in generateOutputs ")
 
 695                 } catch(Exception ex) {
 
 696                         String msg = "Exception in generateOutputs " + ex.getMessage()
 
 699                 msoLogger.trace("end generateOutputs")
 
 703         public void preProcessRollback (DelegateExecution execution) {
 
 705                 msoLogger.trace("start preProcessRollback")
 
 708                         Object workflowException = execution.getVariable("WorkflowException");
 
 710                         if (workflowException instanceof WorkflowException) {
 
 711                                 msoLogger.debug("Prev workflowException: " + workflowException.getErrorMessage())
 
 712                                 execution.setVariable("prevWorkflowException", workflowException);
 
 713                                 //execution.setVariable("WorkflowException", null);
 
 715                 } catch (BpmnError e) {
 
 716                         msoLogger.debug("BPMN Error during preProcessRollback")
 
 717                 } catch(Exception ex) {
 
 718                         String msg = "Exception in preProcessRollback. " + ex.getMessage()
 
 721                 msoLogger.trace("end preProcessRollback")
 
 724         public void postProcessRollback (DelegateExecution execution) {
 
 726                 msoLogger.trace("start postProcessRollback")
 
 729                         Object workflowException = execution.getVariable("prevWorkflowException");
 
 730                         if (workflowException instanceof WorkflowException) {
 
 731                                 msoLogger.debug("Setting prevException to WorkflowException: ")
 
 732                                 execution.setVariable("WorkflowException", workflowException);
 
 734                         execution.setVariable("rollbackData", null)
 
 735                 } catch (BpmnError b) {
 
 736                         msoLogger.debug("BPMN Error during postProcessRollback")
 
 738                 } catch(Exception ex) {
 
 739                         msg = "Exception in postProcessRollback. " + ex.getMessage()
 
 742                 msoLogger.trace("end postProcessRollback")