2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 
   6  * ================================================================================
 
   7  * Licensed under the Apache License, Version 2.0 (the "License");
 
   8  * you may not use this file except in compliance with the License.
 
   9  * You may obtain a copy of the License at
 
  11  *      http://www.apache.org/licenses/LICENSE-2.0
 
  13  * Unless required by applicable law or agreed to in writing, software
 
  14  * distributed under the License is distributed on an "AS IS" BASIS,
 
  15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  16  * See the License for the specific language governing permissions and
 
  17  * limitations under the License.
 
  18  * ============LICENSE_END=========================================================
 
  21 package org.onap.so.bpmn.infrastructure.scripts
 
  23 import static org.apache.commons.lang3.StringUtils.*
 
  25 import org.camunda.bpm.engine.delegate.BpmnError
 
  26 import org.camunda.bpm.engine.delegate.DelegateExecution
 
  27 import org.onap.so.bpmn.common.scripts.AaiUtil
 
  28 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
 
  29 import org.onap.so.bpmn.common.scripts.ExceptionUtil
 
  30 import org.onap.so.bpmn.common.scripts.MsoUtils
 
  31 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
 
  32 import org.onap.so.bpmn.common.scripts.VidUtils
 
  33 import org.onap.so.bpmn.core.RollbackData
 
  34 import org.onap.so.bpmn.core.UrnPropertiesReader
 
  35 import org.onap.so.bpmn.core.WorkflowException
 
  36 import org.onap.so.bpmn.core.domain.VnfResource
 
  37 import org.onap.so.bpmn.core.json.JsonUtils
 
  38 import org.onap.so.logger.MessageEnum
 
  39 import org.onap.so.logger.MsoLogger
 
  40 import org.onap.so.client.aai.AAIObjectType;
 
  41 import org.onap.so.client.aai.AAIResourcesClient
 
  42 import org.onap.so.client.aai.entities.AAIResultWrapper
 
  43 import org.onap.so.client.aai.entities.uri.AAIResourceUri
 
  44 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
 
  45 import org.springframework.web.util.UriUtils
 
  46 import org.json.JSONObject
 
  50  * This class supports the DoCreateVnf building block subflow
 
  51  * with the creation of a generic vnf for
 
  55 class DoCreateVnf extends AbstractServiceTaskProcessor {
 
  57         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateVnf.class);
 
  58         String Prefix="DoCVNF_"
 
  59         ExceptionUtil exceptionUtil = new ExceptionUtil()
 
  60         JsonUtils jsonUtil = new JsonUtils()
 
  61         VidUtils vidUtils = new VidUtils(this)
 
  62         SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
 
  65          * This method gets and validates the incoming
 
  71         public void preProcessRequest(DelegateExecution execution) {
 
  72                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
 
  73                 execution.setVariable("prefix",Prefix)
 
  74                 msoLogger.debug("STARTED DoCreateVnf PreProcessRequest Process")
 
  76                 // DISABLE SDNC INTERACTION FOR NOW
 
  77                 execution.setVariable("SDNCInteractionEnabled", false)
 
  84                         def rollbackData = execution.getVariable("rollbackData")
 
  85                         if (rollbackData == null) {
 
  86                                 rollbackData = new RollbackData()
 
  89                         String vnfModelInfo = execution.getVariable("vnfModelInfo")
 
  90                         String serviceModelInfo = execution.getVariable("serviceModelInfo")
 
  92                         String requestId = execution.getVariable("msoRequestId")
 
  93                         execution.setVariable("DoCVNF_requestId", requestId)
 
  94                         execution.setVariable("mso-request-id", requestId)
 
  95                         msoLogger.debug("Incoming Request Id is: " + requestId)
 
  97                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
 
  98                         execution.setVariable("DoCVNF_serviceInstanceId", serviceInstanceId)
 
  99                         rollbackData.put("VNF", "serviceInstanceId", serviceInstanceId)
 
 100                         msoLogger.debug("Incoming Service Instance Id is: " + serviceInstanceId)
 
 102                         String vnfType = execution.getVariable("vnfType")
 
 103                         execution.setVariable("DoCVNF_vnfType", vnfType)
 
 104                         msoLogger.debug("Incoming Vnf Type is: " + vnfType)
 
 106                         String vnfName = execution.getVariable("vnfName")
 
 107                         if (vnfName.equals("") || vnfName.equals("null")) {
 
 110                         execution.setVariable("DoCVNF_vnfName", vnfName)
 
 111                         msoLogger.debug("Incoming Vnf Name is: " + vnfName)
 
 113                         String serviceId = execution.getVariable("productFamilyId")
 
 114                         execution.setVariable("DoCVNF_serviceId", serviceId)
 
 115                         msoLogger.debug("Incoming Service Id is: " + serviceId)
 
 117                         String source = "VID"
 
 118                         execution.setVariable("DoCVNF_source", source)
 
 119                         rollbackData.put("VNF", "source", source)
 
 120                         msoLogger.debug("Incoming Source is: " + source)
 
 122                         String suppressRollback = execution.getVariable("disableRollback")
 
 123                         execution.setVariable("DoCVNF_suppressRollback", suppressRollback)
 
 124                         msoLogger.debug("Incoming Suppress Rollback is: " + suppressRollback)
 
 126                         String modelInvariantId = jsonUtil.getJsonValue(vnfModelInfo, "modelInvariantUuid")
 
 127                         execution.setVariable("DoCVNF_modelInvariantId", modelInvariantId)
 
 128                         msoLogger.debug("Incoming Invariant Id is: " + modelInvariantId)
 
 130                         String modelVersionId = jsonUtil.getJsonValue(vnfModelInfo, "modelUuid")
 
 131                         if (modelVersionId == null) {
 
 134                         execution.setVariable("DoCVNF_modelVersionId", modelVersionId)
 
 135                         msoLogger.debug("Incoming Version Id is: " + modelVersionId)
 
 137                         String modelVersion = jsonUtil.getJsonValue(vnfModelInfo, "modelVersion")
 
 138                         execution.setVariable("DoCVNF_modelVersion", modelVersion)
 
 139                         msoLogger.debug("Incoming Model Version is: " + modelVersion)
 
 141                         String modelName = jsonUtil.getJsonValue(vnfModelInfo, "modelName")
 
 142                         execution.setVariable("DoCVNF_modelName", modelName)
 
 143                         msoLogger.debug("Incoming Model Name is: " + modelName)
 
 145                         String modelCustomizationId = jsonUtil.getJsonValue(vnfModelInfo, "modelCustomizationUuid")
 
 146                         if (modelCustomizationId == null) {
 
 147                                 modelCustomizationId = ""
 
 149                         execution.setVariable("DoCVNF_modelCustomizationId", modelCustomizationId)
 
 150                         msoLogger.debug("Incoming Model Customization Id is: " + modelCustomizationId)
 
 152                         String cloudSiteId = execution.getVariable("lcpCloudRegionId")
 
 153                         execution.setVariable("DoCVNF_cloudSiteId", cloudSiteId)
 
 154                         rollbackData.put("VNF", "cloudSiteId", cloudSiteId)
 
 155                         msoLogger.debug("Incoming Cloud Site Id is: " + cloudSiteId)
 
 157                         String tenantId = execution.getVariable("tenantId")
 
 158                         execution.setVariable("DoCVNF_tenantId", tenantId)
 
 159                         rollbackData.put("VNF", "tenantId", tenantId)
 
 160                         msoLogger.debug("Incoming Tenant Id is: " + tenantId)
 
 162                         String globalSubscriberId = execution.getVariable("globalSubscriberId")
 
 163                         if (globalSubscriberId == null) {
 
 164                                 globalSubscriberId = ""
 
 166                         execution.setVariable("DoCVNF_globalSubscriberId", globalSubscriberId)
 
 167                         msoLogger.debug("Incoming Global Subscriber Id is: " + globalSubscriberId)
 
 169                         String sdncVersion = execution.getVariable("sdncVersion")
 
 170                         if (sdncVersion == null) {
 
 173                         execution.setVariable("DoCVNF_sdncVersion", sdncVersion)
 
 174                         msoLogger.debug("Incoming Sdnc Version is: " + sdncVersion)
 
 176                         //For Completion Handler & Fallout Handler
 
 178                                 """<request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
 
 179                                         <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
 
 180                                         <action>CREATE</action>
 
 181                                         <source>${MsoUtils.xmlEscape(source)}</source>
 
 184                         execution.setVariable("DoCVNF_requestInfo", requestInfo)
 
 185                         //TODO: Orch Status - TBD, will come from SDN-C Response in 1702
 
 186                         String orchStatus = "Created"
 
 187                         execution.setVariable("DoCVNF_orchStatus", orchStatus)
 
 189                         //TODO: Equipment Role - Should come from SDN-C Response in 1702
 
 190                         String equipmentRole = " "
 
 191                         execution.setVariable("DoCVNF_equipmentRole", equipmentRole)
 
 192                         String vnfId = execution.getVariable("testVnfId") // for junits
 
 194                                 vnfId = execution.getVariable("vnfId")
 
 195                                 if (isBlank(vnfId)) {
 
 196                                         vnfId = UUID.randomUUID().toString()
 
 197                                         msoLogger.debug("Generated Vnf Id is: " + vnfId)
 
 200                         execution.setVariable("DoCVNF_vnfId", vnfId)
 
 202                         // Setting for Sub Flow Calls
 
 203                         execution.setVariable("DoCVNF_type", "generic-vnf")
 
 204                         execution.setVariable("GENGS_type", "service-instance")
 
 206                         String sdncCallbackUrl = (String) UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
 
 207                         if (sdncCallbackUrl == null || sdncCallbackUrl.trim().isEmpty()) {
 
 208                                 def msg = 'Required variable \'mso.workflow.sdncadapter.callback\' is missing'
 
 209                                 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError);
 
 210                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
 
 212                         execution.setVariable("DoCVNF_sdncCallbackUrl", sdncCallbackUrl)
 
 213                         rollbackData.put("VNF", "sdncCallbackUrl", sdncCallbackUrl)
 
 214                         msoLogger.debug("SDNC Callback URL is: " + sdncCallbackUrl)
 
 216                         VnfResource vnfResource = (VnfResource) execution.getVariable((String)"vnfResourceDecomposition")
 
 217                         String nfRole = vnfResource.getNfRole()
 
 219                         execution.setVariable("DoCVNF_nfRole", nfRole)
 
 220                         msoLogger.debug("NF Role is: " + nfRole)
 
 222                         String nfNamingCode = vnfResource.getNfNamingCode()
 
 223                         execution.setVariable("DoCVNF_nfNamingCode", nfNamingCode)
 
 224                         msoLogger.debug("NF Naming Code is: " + nfNamingCode)
 
 226                         String nfType = vnfResource.getNfType()
 
 227                         execution.setVariable("DoCVNF_nfType", nfType)
 
 228                         msoLogger.debug("NF Type is: " + nfType)
 
 230                         String nfFunction = vnfResource.getNfFunction()
 
 231                         execution.setVariable("DoCVNF_nfFunction", nfFunction)
 
 232                         msoLogger.debug("NF Function is: " + nfFunction)
 
 234                         rollbackData.put("VNF", "rollbackSDNCAssign", "false")
 
 235                         rollbackData.put("VNF", "rollbackSDNCActivate", "false")
 
 236                         rollbackData.put("VNF", "rollbackVnfCreate", "false")
 
 238                         execution.setVariable("rollbackData", rollbackData)
 
 241                         msoLogger.debug("Rethrowing MSOWorkflowException")
 
 244                         msoLogger.debug(" Error Occured in DoCreateVnf PreProcessRequest method!" + e.getMessage())
 
 245                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoCreateVnf PreProcessRequest")
 
 248                 msoLogger.trace("COMPLETED DoCreateVnf PreProcessRequest Process")
 
 252          * Gets the service instance from aai
 
 254         public void getServiceInstance(DelegateExecution execution) {
 
 256                         String serviceInstanceId = execution.getVariable('DoCVNF_serviceInstanceId')
 
 258                         AAIResourcesClient resourceClient = new AAIResourcesClient()
 
 259                         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId)
 
 261                         if(resourceClient.exists(uri)){
 
 262                                 Map<String, String> keys = uri.getURIKeys()
 
 263                                 execution.setVariable("globalCustomerId", keys.get("global-customer-id"))
 
 264                                 execution.setVariable("serviceType", keys.get("service-type"))
 
 265                                 execution.setVariable("GENGS_siResourceLink", uri.build().toString())
 
 268                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service instance was not found in aai")
 
 271                 }catch(BpmnError e) {
 
 273                 }catch(Exception ex) {
 
 274                         String msg = "Exception in getServiceInstance. " + ex.getMessage()
 
 276                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 280         private Object getVariableEnforced(DelegateExecution execution, String name){
 
 281                 Object enforced = execution.getVariable(name)
 
 288         public void createGenericVnf (DelegateExecution execution) {
 
 289                 execution.setVariable("prefix",Prefix)
 
 290                 msoLogger.trace("STARTED DoCreateVnf CreateGenericVnf Process")
 
 293                         String vnfId = getVariableEnforced(execution, "DoCVNF_vnfId")
 
 294                         String vnfName = getVariableEnforced(execution, "DoCVNF_vnfName")
 
 295                         if (vnfName == null) {
 
 296                                 vnfName = "sdncGenerated"
 
 297                                 msoLogger.debug("Sending a dummy VNF name to AAI - the name will be generated by SDNC: " + vnfName)
 
 299                         String vnfType = getVariableEnforced(execution, "DoCVNF_vnfType")
 
 300                         String serviceId = getVariableEnforced(execution, "DoCVNF_serviceId")
 
 301                         String orchStatus = getVariableEnforced(execution, "DoCVNF_orchStatus")
 
 302                         String modelInvariantId = getVariableEnforced(execution, "DoCVNF_modelInvariantId")
 
 303                         String modelVersionId = getVariableEnforced(execution, "DoCVNF_modelVersionId")
 
 304                         String modelCustomizationId = getVariableEnforced(execution, "DoCVNF_modelCustomizationId")
 
 305                         String equipmentRole = getVariableEnforced(execution, "DoCVNF_equipmentRole")
 
 306                         String nfType = getVariableEnforced(execution, "DoCVNF_nfType")
 
 307                         String nfRole = getVariableEnforced(execution, "DoCVNF_nfRole")
 
 308                         String nfFunction = getVariableEnforced(execution, "DoCVNF_nfFunction")
 
 309                         String nfNamingCode = getVariableEnforced(execution, "DoCVNF_nfNamingCode")
 
 311                         //Get Service Instance Info
 
 312                         String serviceInstanceId = getVariableEnforced(execution, "DoCVNF_serviceInstanceId")
 
 314                         String globalCustId = execution.getVariable("globalCustomerId")
 
 315                         String serviceType = execution.getVariable("serviceType")
 
 317                         Map<String, String> payload = new LinkedHashMap<>();
 
 318                         payload.put("vnf-id", vnfId);
 
 319                         payload.put("vnf-name", vnfName);
 
 320                         payload.put("service-id", serviceId);
 
 321                         payload.put("vnf-type", vnfType);
 
 322                         payload.put("prov-status", "PREPROV");
 
 323                         payload.put("orchestration-status", orchStatus);
 
 324                         payload.put("model-invariant-id", modelInvariantId);
 
 325                         payload.put("model-version-id", modelVersionId);
 
 326                         payload.put("model-customization-id", modelCustomizationId);
 
 327                         payload.put("nf-type", nfType);
 
 328                         payload.put("nf-role", nfRole);
 
 329                         payload.put("nf-function", nfFunction);
 
 330                         payload.put("nf-naming-code", nfNamingCode);
 
 332                         AAIResourcesClient resourceClient = new AAIResourcesClient();
 
 333                         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
 
 334                         resourceClient.create(uri, payload)
 
 336                         AAIResourceUri siUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalCustId, serviceType, serviceInstanceId)
 
 337                         resourceClient.connect(uri, siUri)
 
 339                 }catch(Exception ex) {
 
 340                         msoLogger.debug("Error Occured in DoCreateVnf CreateGenericVnf Process ", ex)
 
 341                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoCreateVnf CreateGenericVnf Process")
 
 343                 msoLogger.trace("COMPLETED DoCreateVnf CreateGenericVnf Process")
 
 346         public void postProcessCreateGenericVnf (DelegateExecution execution) {
 
 347                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
 
 348                 execution.setVariable("prefix",Prefix)
 
 350                 msoLogger.trace("STARTED DoCreateVnf PostProcessCreateGenericVnf Process")
 
 353                         String vnfId = execution.getVariable("DoCVNF_vnfId")
 
 354                         def rollbackData = execution.getVariable("rollbackData")
 
 355                         rollbackData.put("VNF", "vnfId", vnfId)
 
 356                         rollbackData.put("VNF", "rollbackVnfCreate", "true")
 
 357                         execution.setVariable("rollbackData", rollbackData)
 
 358                 }catch(Exception ex) {
 
 359                         msoLogger.debug("Error Occured in DoCreateVnf PostProcessCreateGenericVnf Process " + ex.getMessage())
 
 360                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoCreateVnf PostProcessCreateGenericVnf Process")
 
 362                 msoLogger.trace("COMPLETED DoCreateVnf PostProcessCreateGenericVnf Process")
 
 366         public void preProcessSDNCAssignRequest(DelegateExecution execution){
 
 367                 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
 
 368                 execution.setVariable("prefix", Prefix)
 
 369                 msoLogger.trace("STARTED preProcessSDNCAssignRequest")
 
 370                 def vnfId = execution.getVariable("DoCVNF_vnfId")
 
 371                 def serviceInstanceId = execution.getVariable("DoCVNF_serviceInstanceId")
 
 372                 msoLogger.debug("NEW VNF ID: " + vnfId)
 
 377                         String assignSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "assign")
 
 379                         assignSDNCRequest = utils.formatXml(assignSDNCRequest)
 
 380                         execution.setVariable("DoCVNF_assignSDNCRequest", assignSDNCRequest)
 
 381                         msoLogger.debug("Outgoing AssignSDNCRequest is: \n" + assignSDNCRequest)
 
 384                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing preProcessSDNCAssignRequest" , "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e)
 
 385                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessSDNCAssignRequest Method:\n" + e.getMessage())
 
 387                 msoLogger.trace("COMPLETED preProcessSDNCAssignRequest")
 
 390         public void preProcessSDNCActivateRequest(DelegateExecution execution) {
 
 391                 def method = getClass().getSimpleName() + '.preProcessSDNCActivateRequest(' +
 
 392                         'execution=' + execution.getId() +
 
 394                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
 
 395                 msoLogger.trace('Entered ' + method)
 
 396                 execution.setVariable("prefix", Prefix)
 
 397                 msoLogger.trace("STARTED preProcessSDNCActivateRequest Process")
 
 399                         String vnfId = execution.getVariable("DoCVNF_vnfId")
 
 400                         String serviceInstanceId = execution.getVariable("DoCVNF_serviceInstanceId")
 
 402                         String activateSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "activate")
 
 404                         execution.setVariable("DoCVNF_activateSDNCRequest", activateSDNCRequest)
 
 405                         msoLogger.debug("Outgoing CommitSDNCRequest is: \n" + activateSDNCRequest)
 
 408                         msoLogger.debug("Exception Occured Processing preProcessSDNCActivateRequest. Exception is:\n" + e)
 
 409                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during  preProcessSDNCActivateRequest Method:\n" + e.getMessage())
 
 411                 msoLogger.trace("COMPLETED  preProcessSDNCActivateRequest Process")
 
 414         public String buildSDNCRequest(DelegateExecution execution, String svcInstId, String action){
 
 416                                 String uuid = execution.getVariable('testReqId') // for junits
 
 418                                         uuid = execution.getVariable("DoCVNF_requestId") + "-" +        System.currentTimeMillis()
 
 420                                 def callbackURL = execution.getVariable("DoCVNF_sdncCallbackUrl")
 
 421                                 def requestId = execution.getVariable("DoCVNF_requestId")
 
 422                                 def serviceId = execution.getVariable("DoCVNF_serviceId")
 
 423                                 def vnfType = execution.getVariable("DoCVNF_vnfType")
 
 424                                 def vnfName = execution.getVariable("DoCVNF_vnfName")
 
 425                                 // Only send vnfName to SDNC if it is not null, otherwise it will get generated by SDNC on Assign
 
 426                                 String vnfNameString = ""
 
 427                                 if (vnfName != null) {
 
 428                                         vnfNameString = """<vnf-name>${MsoUtils.xmlEscape(vnfName)}</vnf-name>"""
 
 430                                 def tenantId = execution.getVariable("DoCVNF_tenantId")
 
 431                                 def source = execution.getVariable("DoCVNF_source")
 
 432                                 def vnfId = execution.getVariable("DoCVNF_vnfId")
 
 433                                 def cloudSiteId = execution.getVariable("DoCVNF_cloudSiteId")
 
 434                                 def modelCustomizationId = execution.getVariable("DoCVNF_modelCustomizationId")
 
 435                                 def serviceModelInfo = execution.getVariable("serviceModelInfo")
 
 436                                 def vnfModelInfo = execution.getVariable("vnfModelInfo")
 
 437                                 String serviceEcompModelInformation = sdncAdapterUtils.modelInfoToEcompModelInformation(serviceModelInfo)
 
 438                                 String vnfEcompModelInformation = sdncAdapterUtils.modelInfoToEcompModelInformation(vnfModelInfo)
 
 439                                 def globalSubscriberId = execution.getVariable("DoCVNF_globalSubscriberId")
 
 440                                 def sdncVersion = execution.getVariable("DoCVNF_sdncVersion")
 
 442                                 String sdncVNFParamsXml = ""
 
 444                                 if(execution.getVariable("DoCVNF_vnfParamsExistFlag") == true){
 
 445                                         sdncVNFParamsXml = buildSDNCParamsXml(execution)
 
 447                                         sdncVNFParamsXml = ""
 
 451                                 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
 
 452                                                                                                         xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
 
 453                                                                                                         xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
 
 454            <sdncadapter:RequestHeader>
 
 455                                 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
 
 456                                 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstId)}</sdncadapter:SvcInstanceId>
 
 457                                 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
 
 458                                 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
 
 459                                 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
 
 460                                 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
 
 461                 </sdncadapter:RequestHeader>
 
 462         <sdncadapterworkflow:SDNCRequestData>
 
 463                 <request-information>
 
 464                         <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
 
 465                         <request-action>CreateVnfInstance</request-action>
 
 466                         <source>${MsoUtils.xmlEscape(source)}</source>
 
 470                 </request-information>
 
 471                 <service-information>
 
 472                         <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
 
 473                         <subscription-service-type>${MsoUtils.xmlEscape(serviceId)}</subscription-service-type>
 
 474                         ${serviceEcompModelInformation}
 
 475                         <service-instance-id>${MsoUtils.xmlEscape(svcInstId)}</service-instance-id>
 
 476                         <global-customer-id>${MsoUtils.xmlEscape(globalSubscriberId)}</global-customer-id>
 
 477                 </service-information>
 
 479                         <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
 
 480                         <vnf-type>${MsoUtils.xmlEscape(vnfType)}</vnf-type>
 
 481                         ${vnfEcompModelInformation}
 
 485                         <tenant>${MsoUtils.xmlEscape(tenantId)}</tenant>
 
 486                         <aic-cloud-region>${MsoUtils.xmlEscape(cloudSiteId)}</aic-cloud-region>
 
 489         </sdncadapterworkflow:SDNCRequestData>
 
 490         </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
 
 492                         msoLogger.debug("sdncRequest:  " + sdncRequest)
 
 496         public void validateSDNCResponse(DelegateExecution execution, String response, String method){
 
 497                 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
 
 498                 execution.setVariable("prefix",Prefix)
 
 499                 msoLogger.debug("STARTED ValidateSDNCResponse Process")
 
 501                 WorkflowException workflowException = execution.getVariable("WorkflowException")
 
 502                 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
 
 504                 msoLogger.debug("workflowException: " + workflowException)
 
 506                 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
 
 507                 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
 
 509                 msoLogger.debug("SDNCResponse: " + response)
 
 511                 String sdncResponse = response
 
 512                 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
 
 513                         msoLogger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call.  Response is: \n" + sdncResponse)
 
 514                         if(method.equals("get")){
 
 515                                 String topologyGetResponse = execution.getVariable("DoCVNF_getSDNCAdapterResponse")
 
 516                                 String data = utils.getNodeXml(topologyGetResponse, "response-data")
 
 517                                 msoLogger.debug("topologyGetResponseData: " + data)
 
 518                                 String vnfName = utils.getNodeText(data, "vnf-name")
 
 519                                 msoLogger.debug("vnfName received from SDNC: " + vnfName)
 
 520                                 execution.setVariable("vnfName", vnfName)
 
 521                                 execution.setVariable("DoCVNF_vnfName", vnfName)
 
 523                         def rollbackData = execution.getVariable("rollbackData")
 
 524                         if (method.equals("assign")) {
 
 525                                 rollbackData.put("VNF", "rollbackSDNCAssign", "true")
 
 527                         else if (method.equals("activate")) {
 
 528                                 rollbackData.put("VNF", "rollbackSDNCActivate", "true")
 
 530                         execution.setVariable("rollbackData", rollbackData)
 
 534                         msoLogger.debug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.")
 
 535                         throw new BpmnError("MSOWorkflowException")
 
 537                 msoLogger.debug("COMPLETED ValidateSDNCResponse Process")
 
 540         public void preProcessSDNCGetRequest(DelegateExecution execution){
 
 541                 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
 
 542                 execution.setVariable("prefix", Prefix)
 
 543                 msoLogger.trace("STARTED preProcessSDNCGetRequest Process")
 
 545                         def serviceInstanceId = execution.getVariable('DoCVNF_serviceInstanceId')
 
 547                         String uuid = execution.getVariable('testReqId') // for junits
 
 549                                 uuid = execution.getVariable("mso-request-id") + "-" +  System.currentTimeMillis()
 
 552                         def callbackUrl = execution.getVariable("DoCVFM_sdncCallbackUrl")
 
 553                         msoLogger.debug("callbackUrl:" + callbackUrl)
 
 555                         def vnfId = execution.getVariable('DCVFM_vnfId')
 
 558                         if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
 
 562                                 svcInstId = serviceInstanceId
 
 564                         // serviceOperation will be retrieved from "object-path" element
 
 565                         // in SDNC Assign Response for VNF
 
 566                         String response = execution.getVariable("DoCVNF_assignSDNCAdapterResponse")
 
 567                         msoLogger.debug("DoCVNF_assignSDNCAdapterResponse is: \n" + response)
 
 569                         String serviceOperation = ""
 
 571                         String data = utils.getNodeXml(response, "response-data")
 
 572                         msoLogger.debug("responseData: " + data)
 
 573                         serviceOperation = utils.getNodeText(data, "object-path")
 
 574                         msoLogger.debug("VNF with sdncVersion of 1707 or later - service operation: " + serviceOperation)
 
 577                         //!!!! TEMPORARY WORKAROUND FOR SDNC REPLICATION ISSUE
 
 580                         String SDNCGetRequest =
 
 581                                         """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
 
 582                                                                                         xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
 
 583                                                                                         xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
 
 584                                         <sdncadapter:RequestHeader>
 
 585                                         <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
 
 586                                         <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstId)}</sdncadapter:SvcInstanceId>
 
 587                                         <sdncadapter:SvcAction>query</sdncadapter:SvcAction>
 
 588                                         <sdncadapter:SvcOperation>${MsoUtils.xmlEscape(serviceOperation)}</sdncadapter:SvcOperation>
 
 589                                         <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
 
 590                                         <sdncadapter:MsoAction>vfmodule</sdncadapter:MsoAction>
 
 591                                 </sdncadapter:RequestHeader>
 
 592                                         <sdncadapterworkflow:SDNCRequestData></sdncadapterworkflow:SDNCRequestData>
 
 593                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
 
 596                         execution.setVariable("DoCVNF_getSDNCRequest", SDNCGetRequest)
 
 597                         msoLogger.debug("Outgoing GetSDNCRequest is: \n" + SDNCGetRequest)
 
 600                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occurred Processing preProcessSDNCGetRequest. ", "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
 
 601                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during prepareProvision Method:\n" + e.getMessage())
 
 603                 msoLogger.trace("COMPLETED preProcessSDNCGetRequest Process")
 
 607          * Prepare a Request for invoking the UpdateAAIGenericVnf subflow.
 
 609          * @param execution The flow's execution instance.
 
 611         public void prepUpdateAAIGenericVnf(DelegateExecution execution) {
 
 612                 def method = getClass().getSimpleName() + '.prepUpdateAAIGenericVnf(' +
 
 613                         'execution=' + execution.getId() +
 
 615                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
 
 616                 msoLogger.trace('Entered ' + method)
 
 619                         def vnfId = execution.getVariable('DoCVNF_vnfId')
 
 620                         msoLogger.debug("VNF ID: " + vnfId)
 
 622                         String updateAAIGenericVnfRequest = """
 
 623                                         <UpdateAAIGenericVnfRequest>
 
 624                                                 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
 
 625                                                 <orchestration-status>Active</orchestration-status>
 
 626                                         </UpdateAAIGenericVnfRequest>
 
 628                                 updateAAIGenericVnfRequest = utils.formatXml(updateAAIGenericVnfRequest)
 
 629                                 execution.setVariable('DoCVNF_updateAAIGenericVnfRequest', updateAAIGenericVnfRequest)
 
 630                                 msoLogger.debug('Request for UpdateAAIGenericVnf:\n' + updateAAIGenericVnfRequest)
 
 633                         msoLogger.trace('Exited ' + method)
 
 634                 } catch (BpmnError e) {
 
 636                 } catch (Exception e) {
 
 637                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Caught exception in " + method , "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
 
 638                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepUpdateAAIGenericVnf(): ' + e.getMessage())