2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  # Copyright (c) 2019, CMCC Technologies Co., Ltd.
 
   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 groovy.json.JsonSlurper
 
  24 import org.camunda.bpm.engine.delegate.BpmnError
 
  25 import org.camunda.bpm.engine.delegate.DelegateExecution
 
  26 import org.json.JSONObject
 
  27 import org.onap.aai.domain.yang.Relationship
 
  28 import org.onap.aai.domain.yang.ServiceInstance
 
  29 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
 
  30 import org.onap.so.bpmn.common.scripts.ExceptionUtil
 
  31 import org.onap.so.bpmn.common.scripts.MsoUtils
 
  32 import org.onap.so.bpmn.common.scripts.RequestDBUtil
 
  33 import org.onap.so.bpmn.core.UrnPropertiesReader
 
  34 import org.onap.so.bpmn.core.WorkflowException
 
  35 import org.onap.so.bpmn.core.domain.ServiceDecomposition
 
  36 import org.onap.so.bpmn.core.domain.ServiceInfo
 
  37 import org.onap.so.bpmn.core.domain.ServiceProxy
 
  38 import org.onap.so.bpmn.core.json.JsonUtils
 
  39 import org.onap.aaiclient.client.aai.AAIObjectType
 
  40 import org.onap.aaiclient.client.aai.AAIResourcesClient
 
  41 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
 
  42 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
 
  43 import org.onap.so.db.request.beans.OperationStatus
 
  44 import org.slf4j.Logger
 
  45 import org.slf4j.LoggerFactory
 
  46 import org.springframework.web.util.UriUtils
 
  48 import static org.apache.commons.lang3.StringUtils.isBlank
 
  51  * This groovy class supports the <class>DoCreateCommunicationService.bpmn</class> process.
 
  52  * AlaCarte flow for 1702 ServiceInstance Create
 
  55 class CreateCommunicationService extends AbstractServiceTaskProcessor {
 
  59     ExceptionUtil exceptionUtil = new ExceptionUtil()
 
  61     RequestDBUtil requestDBUtil = new RequestDBUtil()
 
  63     JsonUtils jsonUtil = new JsonUtils()
 
  65     AAIResourcesClient client = getAAIClient()
 
  67     private static final Logger logger = LoggerFactory.getLogger(CreateCommunicationService.class)
 
  70     void preProcessRequest(DelegateExecution execution) {
 
  71         logger.debug(Prefix + "preProcessRequest Start")
 
  72         execution.setVariable("prefix", Prefix)
 
  73         execution.setVariable("startTime", System.currentTimeMillis())
 
  75         //execution.setVariable("bpmnRequest", InputString)
 
  78             String siRequest = execution.getVariable("bpmnRequest")
 
  79             logger.debug(siRequest)
 
  81             //String requestId = execution.getVariable("mso-request-id")
 
  82             String requestId = execution.getVariable("mso-request-id")
 
  83             execution.setVariable("msoRequestId", requestId)
 
  84             logger.debug("Input Request:" + siRequest + " reqId:" + requestId)
 
  86             String serviceInstanceId = execution.getVariable("serviceInstanceId")
 
  87             if (isBlank(serviceInstanceId)) {
 
  88                 serviceInstanceId = UUID.randomUUID().toString()
 
  90             logger.debug("Generated new Service Instance:" + serviceInstanceId)
 
  91             serviceInstanceId = UriUtils.encode(serviceInstanceId,"UTF-8")
 
  92             execution.setVariable("serviceInstanceId", serviceInstanceId)
 
  95             String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "requestDetails.subscriberInfo.globalSubscriberId")
 
  96             if (isBlank(globalSubscriberId)) {
 
  97                 msg = "Input globalSubscriberId' is null"
 
  98                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
 100                 execution.setVariable("globalSubscriberId", globalSubscriberId)
 
 104             execution.setVariable("source", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.source"))
 
 105             execution.setVariable("serviceInstanceName", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.instanceName"))
 
 106             execution.setVariable("disableRollback", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.suppressRollback"))
 
 107             String productFamilyId = jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.productFamilyId")
 
 108             if (isBlank(productFamilyId))
 
 110                 msg = "Input productFamilyId is null"
 
 112                 //exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
 114                 execution.setVariable("productFamilyId", productFamilyId)
 
 118             String serviceModelInfo = jsonUtil.getJsonValue(siRequest, "requestDetails.modelInfo")
 
 119             if (isBlank(serviceModelInfo)) {
 
 120                 msg = "Input serviceModelInfo is null"
 
 122                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
 125                 execution.setVariable("csServiceModelInfo", serviceModelInfo)
 
 128             logger.debug("modelInfo: " + serviceModelInfo)
 
 130             //requestParameters, subscriptionServiceType is 5G
 
 131             String subscriptionServiceType = jsonUtil.getJsonValue(siRequest, "requestDetails.requestParameters.subscriptionServiceType")
 
 132             if (isBlank(subscriptionServiceType)) {
 
 133                 msg = "Input subscriptionServiceType is null"
 
 135                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
 137                 // todo: in create e2e interface, this value is write "MOG", so write it as "5G"
 
 138                 execution.setVariable("subscriptionServiceType", "5G")
 
 143              * Extracting User Parameters from incoming Request and converting into a Map
 
 145             def jsonSlurper = new JsonSlurper()
 
 147             Map reqMap = jsonSlurper.parseText(siRequest) as Map
 
 150             def userParamsList = reqMap.requestDetails?.requestParameters?.userParams
 
 152             Map<String, String> inputMap = [:]
 
 153             if (userParamsList) {
 
 154                 for (def i=0; i<userParamsList.size(); i++) {
 
 155                     def userParams1 = userParamsList.get(i)
 
 156                     userParams1.each { param -> inputMap.put(param.key, param.value)}
 
 160             logger.debug("User Input Parameters map: " + inputMap.toString())
 
 161             execution.setVariable("serviceInputParams", inputMap)
 
 162             execution.setVariable("uuiRequest", inputMap.get("UUIRequest"))
 
 163             execution.setVariable("isAllNSMFFinished", "false")
 
 164             String operationId = UUID.randomUUID().toString()
 
 165             execution.setVariable("operationId", operationId)
 
 167         } catch(BpmnError e) {
 
 169         } catch(Exception ex) {
 
 170             msg = "Exception in CreateCommunicationService.preProcessRequest " + ex.getMessage()
 
 172             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 174         logger.debug(Prefix + "preProcessRequest Exit")
 
 179      * create operation status in request db
 
 181      * Init the Operation Status
 
 183     def prepareInitOperationStatus = { DelegateExecution execution ->
 
 184         logger.debug(Prefix + "prepareInitOperationStatus Start")
 
 186         String serviceId = execution.getVariable("serviceInstanceId")
 
 188         String operationId = execution.getVariable("operationId")
 
 189         logger.debug("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId)
 
 191         OperationStatus initStatus = new OperationStatus()
 
 192         initStatus.setServiceId(serviceId)
 
 193         initStatus.setOperationId(operationId)
 
 194         initStatus.setOperation("CREATE")
 
 195         initStatus.setUserId(execution.getVariable("globalSubscriberId") as String)
 
 196         initStatus.setResult("processing")
 
 197         initStatus.setProgress("0")
 
 198         initStatus.setReason("")
 
 199         initStatus.setOperationContent("communication service create operation start")
 
 201         requestDBUtil.prepareUpdateOperationStatus(execution, initStatus)
 
 203         logger.debug(Prefix + "prepareInitOperationStatus Exit")
 
 208      * return sync response
 
 210     def sendSyncResponse = { DelegateExecution execution ->
 
 211         logger.debug(Prefix + "sendSyncResponse Start")
 
 213             String operationId = execution.getVariable("operationId")
 
 214             String serviceInstanceId = execution.getVariable("serviceInstanceId")
 
 215             String createServiceRestRequest = """
 
 218                             "serviceId":"${serviceInstanceId}",
 
 219                             "operationId":"${operationId}"
 
 222                     """.trim().replaceAll(" ", "")
 
 224             logger.debug("sendSyncResponse to APIH:" + "\n" + createServiceRestRequest)
 
 225             sendWorkflowResponse(execution, 202, createServiceRestRequest)
 
 227             execution.setVariable("sentSyncResponse", true)
 
 228         } catch (Exception ex) {
 
 229             String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
 
 231             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 233         logger.debug(Prefix + "sendSyncResponse Exit")
 
 241     def prepareDoComposeE2E = { DelegateExecution execution ->
 
 242         logger.debug(Prefix + "prepareDoComposeE2E Start")
 
 244             ServiceDecomposition serviceDecomposition = execution.getVariable(
 
 245                     "csServiceDecomposition") as ServiceDecomposition
 
 247             logger.debug("serviceDecomposition is:" + serviceDecomposition.toJsonString())
 
 249             List<ServiceProxy> serviceProxies = serviceDecomposition.getServiceProxy()
 
 250             String sourceModelUuid = serviceProxies.get(0).getSourceModelUuid()
 
 252             JSONObject queryJson = new JSONObject()
 
 253             queryJson.put("modelUuid", sourceModelUuid)
 
 255             execution.setVariable("e2eServiceModelInfo", queryJson.toString())
 
 256         } catch (BpmnError e) {
 
 258         } catch (Exception ex) {
 
 259             String msg = "Exception in CreateCommunicationService.prepareDoComposeE2E. " + ex.getMessage()
 
 261             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 264         logger.debug(Prefix + "prepareDoComposeE2E Exit")
 
 269      * parse communication service params from request
 
 272     def parseCSParamsFromReq = { DelegateExecution execution ->
 
 273         logger.debug(Prefix + "parseCSParamsFromReq Start")
 
 277             String modelInfo = execution.getVariable("csServiceModelInfo")
 
 278             String modelInvariantUuid = jsonUtil.getJsonValue(modelInfo, "modelInvariantUuid")
 
 279             String modelUuid = jsonUtil.getJsonValue(modelInfo, "modelUuid")
 
 281             //String modelInvariantUuid = execution.getVariable("modelInvariantId")
 
 282             //String modelUuid = execution.getVariable("modelUuid")
 
 283             String uuiRequest = execution.getVariable("uuiRequest")
 
 284             String useInterval = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.useInterval")
 
 285             String csServiceName = jsonUtil.getJsonValue(uuiRequest, "service.name")
 
 286             String csServiceDescription = jsonUtil.getJsonValue(uuiRequest, "service.description")
 
 288             execution.setVariable("modelInvariantUuid", modelInvariantUuid)
 
 289             execution.setVariable("modelUuid", modelUuid)
 
 290             execution.setVariable("useInterval", useInterval)
 
 291             execution.setVariable("csServiceName", csServiceName)
 
 292             execution.setVariable("csServiceDescription", csServiceDescription)
 
 296             Integer expDataRateDL = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.expDataRateDL") as Integer
 
 297             Integer expDataRateUL = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.expDataRateUL") as Integer
 
 298             Integer latency = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.latency") as Integer
 
 299             Integer maxNumberOfUEs = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.maxNumberofUEs") as Integer
 
 300             String uEMobilityLevel = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.uEMobilityLevel")
 
 301             String resourceSharingLevel = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.resourceSharingLevel")
 
 302             String coverageArea = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.coverageAreaList")
 
 304             // from template construct input map
 
 305             //String cstTemplate = execution.getVariable("cstTemplate")
 
 306             ServiceDecomposition csServiceDecomposition = execution.getVariable(
 
 307                     "csServiceDecomposition") as ServiceDecomposition
 
 308             //String csServiceType = jsonUtil.getJsonValue(cstTemplate, "serviceResources.serviceType")
 
 309             String csServiceType = csServiceDecomposition.getServiceType()
 
 310             execution.setVariable("csServiceType", csServiceType)
 
 312             //String cstTemplateInfo = jsonUtil.getJsonValue(cstTemplate, "serviceResources.serviceInfo.serviceInput")
 
 313             ServiceInfo csServiceInfo = csServiceDecomposition.getServiceInfo()
 
 314             String cstTemplateInfo = csServiceInfo.getServiceProperties()
 
 316             List<String> csInputs = jsonUtil.StringArrayToList(cstTemplateInfo)
 
 318             Map<String, ?> csInputMap = new HashMap<>()
 
 319             for (String csInput : csInputs) {
 
 321                 if (jsonUtil.getJsonValue(csInput, "type") == "integer") {
 
 322                     value = jsonUtil.getJsonValue(csInput, "default")
 
 323                     csInputMap.put(jsonUtil.getJsonValue(csInput, "name"), isBlank(value) ? 0 : (value as Integer))
 
 324                 } else if (jsonUtil.getJsonValue(csInput, "type") == "string") {
 
 325                     csInputMap.put(jsonUtil.getJsonValue(csInput, "name"),
 
 326                             jsonUtil.getJsonValue(csInput, "default"))
 
 329             csInputMap.put("expDataRateDL", expDataRateDL)
 
 330             csInputMap.put("expDataRateUL", expDataRateUL)
 
 331             csInputMap.put("latency", latency)
 
 332             csInputMap.put("maxNumberofUEs", maxNumberOfUEs)
 
 333             csInputMap.put("uEMobilityLevel", uEMobilityLevel)
 
 334             csInputMap.put("resourceSharingLevel", resourceSharingLevel)
 
 335             csInputMap.put("coverageAreaTAList", coverageArea)
 
 336             csInputMap.put("useInterval", useInterval)
 
 338             execution.setVariable("csInputMap", csInputMap)
 
 339         } catch (BpmnError e) {
 
 341         } catch (Exception ex) {
 
 342             String msg = "Exception in CreateCommunicationService.parseCSParamsFromReq. " + ex.getMessage()
 
 344             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 346         logger.debug(Prefix + "parseCSParamsFromReq Exit")
 
 351      * get E2EST id through CST id and change communication profile to E2E service profile
 
 352      * 1. get E2EST id from cst
 
 353      * 1.1 查source service id
 
 355      * 1.3 source service input, init e2e profile
 
 357     def generateE2EServiceProfile = { DelegateExecution execution ->
 
 358         logger.debug(Prefix + "generateE2EServiceProfile Start")
 
 360             ServiceDecomposition e2eServiceDecomposition = execution.getVariable(
 
 361                     "e2eServiceDecomposition") as ServiceDecomposition
 
 362             String e2estTemplateInfo = e2eServiceDecomposition.getServiceInfo().getServiceProperties()
 
 364             List<String> e2eInputs = jsonUtil.StringArrayToList(e2estTemplateInfo)
 
 366             Map<String, ?> csInputMap = execution.getVariable("csInputMap") as Map
 
 367             Map<String, ?> e2eInputMap = new HashMap<>()
 
 372             for (String e2eInput in e2eInputs) {
 
 373                 if (jsonUtil.getJsonValue(e2eInput, "type") == "integer") {
 
 375                     key = jsonUtil.getJsonValue(e2eInput, "name")
 
 376                     value = csInputMap.containsKey(key) ? csInputMap.getOrDefault(key, 0) : (isBlank(temp = jsonUtil.getJsonValue(e2eInput, "default")) ? 0 : temp)
 
 378                     e2eInputMap.put(key, value as Integer)
 
 380                     e2eInputMap.put(key = jsonUtil.getJsonValue(e2eInput, "name"), csInputMap.containsKey(key)
 
 381                             ? csInputMap.getOrDefault(key, null) : (jsonUtil.getJsonValue(e2eInput, "default")))
 
 385             e2eInputMap.put("sNSSAI", execution.getVariable("sNSSAI_id"))
 
 386             e2eInputMap.put("sST", execution.getVariable("csServiceType"))
 
 387             execution.setVariable("e2eInputMap", e2eInputMap)
 
 388             execution.setVariable("e2eServiceType", e2eServiceDecomposition.getServiceType())
 
 389             execution.setVariable("e2eModelInvariantUuid", e2eServiceDecomposition.getModelInfo().getModelInvariantUuid())
 
 390             execution.setVariable("e2eModelUuid", e2eServiceDecomposition.getModelInfo().getModelUuid())
 
 392         } catch (BpmnError e) {
 
 394         } catch (Exception ex) {
 
 395             String msg = "Exception in DoCreateE2EServiceInstance.createRelationShipInAAI. " + ex.getMessage()
 
 397             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 400         logger.debug(Prefix + "generateE2EServiceProfile Exit")
 
 405      * call createE2EService get operation id,
 
 408     def preRequestSend2NSMF(DelegateExecution execution) {
 
 409         logger.debug(Prefix + "preRequestSend2NSMF Start")
 
 412             //String NSMF_endpoint = "/onap/so/infra/e2eServiceInstances/v3"
 
 413             def NSMF_endpoint = UrnPropertiesReader.getVariable("mso.infra.endpoint.url", execution)
 
 414             def url = NSMF_endpoint + "/e2eServiceInstances/v3"
 
 415             execution.setVariable("NSMF_endpoint", url)
 
 416             //get from model catalog inputs
 
 420                         "name": "${execution.getVariable("csServiceName")}",
 
 421                         "description": "e2eService of ${execution.getVariable("modelUuid")}",
 
 422                         "serviceInvariantUuid": "${execution.getVariable("e2eModelInvariantUuid")}",
 
 423                         "serviceUuid": "${execution.getVariable("e2eModelUuid")}",
 
 424                         "globalSubscriberId": "${execution.getVariable("globalSubscriberId")}",
 
 425                         "serviceType": "${execution.getVariable("subscriptionServiceType")}",
 
 427                             "requestInputs": ${execution.getVariable("e2eInputMap") as JSONObject}
 
 432             execution.setVariable("CSMF_NSMFRequest", payload.replaceAll("\\s+", ""))
 
 434         } catch (BpmnError e) {
 
 436         } catch (Exception ex) {
 
 437             String msg = "Exception in CreateCommunicationService.preRequestSend2NSMF. " + ex.getMessage()
 
 439             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 442         logger.debug(Prefix + "preRequestSend2NSMF Exit")
 
 446     def processNSMFResponse = { DelegateExecution execution ->
 
 447         logger.debug(Prefix + "processNSMFResponse Start")
 
 450             def CSMF_NSMFResponseCode = execution.getVariable("CSMF_NSMFResponseCode") as Integer
 
 451             if (CSMF_NSMFResponseCode >= 200 && CSMF_NSMFResponseCode < 400) {
 
 452                 def CSMF_NSMFResponse = execution.getVariable("CSMF_NSMFResponse") as String
 
 453                 def e2eServiceInstanceId = jsonUtil.getJsonValue(CSMF_NSMFResponse, "service.serviceId")
 
 454                 def e2eOperationId = jsonUtil.getJsonValue(CSMF_NSMFResponse, "service.operationId")
 
 456                 execution.setVariable("e2eServiceInstanceId", e2eServiceInstanceId)
 
 457                 execution.setVariable("e2eOperationId", e2eOperationId)
 
 458                 execution.setVariable("ProcessNsmfSuccess", "OK")
 
 460                 execution.setVariable("ProcessNsmfSuccess", "ERROR")
 
 461                 execution.setVariable("operationStatus", "error")
 
 462                 execution.setVariable("operationContent",
 
 463                         "communication service create operation error: nsmf response fail")
 
 464                 execution.setVariable("orchestrationStatus", "error")
 
 467         } catch (BpmnError e) {
 
 469         } catch (Exception ex) {
 
 470             String msg = "Exception in " + Prefix + "processOOFResponse. " + ex.getMessage()
 
 472             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 474         logger.debug(Prefix + "processNSMFResponse Exit")
 
 479      * create communication service and e2e service relationship
 
 482     def createCSAndSSRelationship = { DelegateExecution execution ->
 
 483         logger.debug(Prefix + "createCSAndSSRelationship Start")
 
 486             def e2eServiceInstanceId = execution.getVariable("e2eServiceInstanceId")
 
 487             String globalSubscriberId = execution.getVariable("globalSubscriberId")
 
 488             String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
 
 490             Relationship relationship = new Relationship()
 
 491             String relatedLink = "aai/v16/business/customers/customer/${globalSubscriberId}/service-subscriptions/service-subscription/${subscriptionServiceType}/service-instances/service-instance/${e2eServiceInstanceId}"
 
 492             relationship.setRelatedLink(relatedLink)
 
 494             // create CS and SS relationship in AAI
 
 495             createRelationShipInAAI(execution, relationship)
 
 497         } catch (BpmnError e) {
 
 499         } catch (Exception ex) {
 
 501             msg = "Exception in DoCreateE2EServiceInstance.createCustomRelationship. " + ex.getMessage()
 
 503             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 505         logger.debug(Prefix + "createCSAndSSRelationship Exit")
 
 510      * prepare update operation status to 50% after create relationship in aai
 
 513     def prepareUpdateOperationStatus = { DelegateExecution execution ->
 
 514         logger.debug(Prefix + "prepareUpdateOperationStatus Start")
 
 515         // update status creating
 
 516         OperationStatus status = new OperationStatus()
 
 517         status.setServiceId(execution.getVariable("serviceInstanceId") as String)
 
 518         status.setOperationId(execution.getVariable("operationId") as String)
 
 519         status.setOperation("CREATE")
 
 520         status.setResult("processing")
 
 521         status.setProgress("20")
 
 522         status.setOperationContent("communication service create operation processing: waiting nsmf service create finished")
 
 523         status.setUserId(execution.getVariable("globalSubscriberId") as String)
 
 525         requestDBUtil.prepareUpdateOperationStatus(execution, status)
 
 526         logger.debug(Prefix + "prepareUpdateOperationStatus Exit")
 
 531      * create relationship in AAI
 
 533     private createRelationShipInAAI = { DelegateExecution execution, final Relationship relationship ->
 
 534         logger.debug(Prefix + "createRelationShipInAAI Start")
 
 537             String serviceInstanceId = execution.getVariable("serviceInstanceId")
 
 538             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
 
 539                     execution.getVariable("globalSubscriberId"),
 
 540                     execution.getVariable("subscriptionServiceType"),
 
 541                     serviceInstanceId).relationshipAPI()
 
 542             client.create(uri, relationship)
 
 544         } catch (BpmnError e) {
 
 546         } catch (Exception ex) {
 
 547             msg = "Exception in CreateCommunicationService.createRelationShipInAAI. " + ex.getMessage()
 
 549             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 551         logger.debug(Prefix + "createRelationShipInAAI Exit")
 
 556     def prepareCallCheckProcessStatus = { DelegateExecution execution ->
 
 557         logger.debug(Prefix + "prepareCallCheckProcessStatus Start")
 
 559         def successConditions = new ArrayList<>()
 
 560         successConditions.add("finished")
 
 561         execution.setVariable("successConditions", successConditions)
 
 563         def errorConditions = new ArrayList<>()
 
 564         errorConditions.add("error")
 
 565         execution.setVariable("errorConditions", errorConditions)
 
 567         execution.setVariable("processServiceType", "communication service")
 
 569         execution.setVariable("subOperationType", "CREATE")
 
 571         execution.setVariable("timeOut", 3 * 60 * 60 * 1000)
 
 573         def successParamMap = new HashMap<String, Object>()
 
 574         successParamMap.put("orchestrationStatus", "deactivated")
 
 576         execution.setVariable("successParamMap", successParamMap)
 
 578         def errorParamMap = new HashMap<String, Object>()
 
 579         errorParamMap.put("orchestrationStatus", "error")
 
 581         execution.setVariable("errorParamMap", errorParamMap)
 
 583         def timeOutParamMap = new HashMap<String, Object>()
 
 584         timeOutParamMap.put("orchestrationStatus", "error")
 
 586         execution.setVariable("timeOutParamMap", timeOutParamMap)
 
 588         execution.setVariable("initProgress", 20)
 
 589         execution.setVariable("endProgress", 90)
 
 591         logger.debug(Prefix + "prepareCallCheckProcessStatus Exit")
 
 596      * prepare update operation status to complete after NSMF process success
 
 599     def prepareCompleteStatus = { DelegateExecution execution ->
 
 600         logger.debug(Prefix + "prepareCompleteStatus Start")
 
 601         OperationStatus status = new OperationStatus()
 
 602         status.setServiceId(execution.getVariable("serviceInstanceId") as String)
 
 603         status.setOperationId(execution.getVariable("operationId") as String)
 
 604         status.setOperation("CREATE")
 
 605         status.setResult(execution.getVariable("operationStatus") as String)
 
 606         status.setProgress("100")
 
 607         status.setOperationContent(execution.getVariable("operationContent") as String)
 
 608         status.setUserId(execution.getVariable("globalSubscriberId") as String)
 
 610         requestDBUtil.prepareUpdateOperationStatus(execution, status)
 
 611         logger.debug("prepareCompleteStatus end, serviceInstanceId: " + execution.getVariable("serviceInstanceId")
 
 612                 + ", operationId: " + execution.getVariable("operationId"))
 
 613         logger.debug(Prefix + "prepareCompleteStatus Exit")
 
 618      * update NSMF complete status to AAI when the NSMF process finished
 
 621     def updateFinishStatusInAAI = { DelegateExecution execution ->
 
 622         logger.debug(Prefix + "updateFinishStatusInAAI Start")
 
 626             String serviceInstanceId = execution.getVariable("serviceInstanceId")
 
 627             String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
 
 628             String globalSubscriberId = execution.getVariable("globalSubscriberId")
 
 629             String orchestrationStatus = execution.getVariable("orchestrationStatus")
 
 631             ServiceInstance csi = new ServiceInstance()
 
 632             csi.setOrchestrationStatus(orchestrationStatus)
 
 633             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
 
 634                     globalSubscriberId, subscriptionServiceType, serviceInstanceId)
 
 635             client.update(uri, csi)
 
 636             logger.debug(Prefix + "updateFinishStatusInAAI update communication service status to deactivated")
 
 638         } catch (BpmnError e) {
 
 640         } catch (Exception ex) {
 
 641             msg = "Exception in complete communication service " + ex.getMessage()
 
 643             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 645         logger.debug(Prefix + "updateFinishStatusInAAI Exit")
 
 649     public sendSyncError = { DelegateExecution execution ->
 
 650         logger.debug("sendSyncError Start")
 
 653             if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
 
 654                 WorkflowException wfe = execution.getVariable("WorkflowException") as WorkflowException
 
 655                 errorMessage = wfe.getErrorMessage()
 
 657                 errorMessage = "Sending Sync Error."
 
 660             String buildWorkflowException =
 
 661                     """<aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
 
 662                                         <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorMessage)}</aetgt:ErrorMessage>
 
 663                                         <aetgt:ErrorCode>7000</aetgt:ErrorCode>
 
 664                                    </aetgt:WorkflowException>"""
 
 666             logger.debug(buildWorkflowException)
 
 667             sendWorkflowResponse(execution, 500, buildWorkflowException)
 
 669         } catch (Exception ex) {
 
 670             logger.debug("Sending Sync Error Activity Failed. " + "\n" + ex.getMessage())
 
 672         logger.debug(Prefix + "sendSyncError Exit")