aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateCommunicationService.groovy
blob: c7302d001ca4419d65032b506d73eededd1dd230 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
/*-
 * ============LICENSE_START=======================================================
 * ONAP - SO
 * ================================================================================
 # Copyright (c) 2019, CMCC Technologies Co., Ltd.
 #
 # Licensed under the Apache License, Version 2.0 (the "License")
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
 #
 #       http://www.apache.org/licenses/LICENSE-2.0
 #
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.onap.so.bpmn.infrastructure.scripts

import groovy.json.JsonSlurper
import org.camunda.bpm.engine.delegate.BpmnError
import org.camunda.bpm.engine.delegate.DelegateExecution
import org.json.JSONObject
import org.onap.aai.domain.yang.Relationship
import org.onap.aai.domain.yang.ServiceInstance
import org.onap.aaiclient.client.aai.AAIResourcesClient
import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
import org.onap.so.bpmn.common.scripts.ExceptionUtil
import org.onap.so.bpmn.common.scripts.MsoUtils
import org.onap.so.bpmn.common.scripts.RequestDBUtil
import org.onap.so.bpmn.core.UrnPropertiesReader
import org.onap.so.bpmn.core.WorkflowException
import org.onap.so.bpmn.core.domain.ServiceDecomposition
import org.onap.so.bpmn.core.domain.ServiceInfo
import org.onap.so.bpmn.core.domain.ServiceProxy
import org.onap.so.bpmn.core.json.JsonUtils
import org.onap.so.db.request.beans.OperationStatus
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.util.StringUtils
import org.springframework.web.util.UriUtils

import static org.apache.commons.lang3.StringUtils.isBlank

/**
 * This groovy class supports the <class>DoCreateCommunicationService.bpmn</class> process.
 * AlaCarte flow for 1702 ServiceInstance Create
 *
 */
class CreateCommunicationService extends AbstractServiceTaskProcessor {

    String Prefix="CCS_"

    ExceptionUtil exceptionUtil = new ExceptionUtil()

    RequestDBUtil requestDBUtil = new RequestDBUtil()

    JsonUtils jsonUtil = new JsonUtils()

    AAIResourcesClient client = getAAIClient()

    private static final Logger logger = LoggerFactory.getLogger(CreateCommunicationService.class)

    @Override
    void preProcessRequest(DelegateExecution execution) {
        logger.debug(Prefix + "preProcessRequest Start")
        execution.setVariable("prefix", Prefix)
        execution.setVariable("startTime", System.currentTimeMillis())
        def msg
        //execution.setVariable("bpmnRequest", InputString)
        try {
            // get request input
            String siRequest = execution.getVariable("bpmnRequest")
            logger.debug(siRequest)

            //String requestId = execution.getVariable("mso-request-id")
            String requestId = execution.getVariable("mso-request-id")
            execution.setVariable("msoRequestId", requestId)
            logger.debug("Input Request:" + siRequest + " reqId:" + requestId)

            String serviceInstanceId = execution.getVariable("serviceInstanceId")
            if (isBlank(serviceInstanceId)) {
                serviceInstanceId = UUID.randomUUID().toString()
            }
            logger.debug("Generated new Service Instance:" + serviceInstanceId)
            serviceInstanceId = UriUtils.encode(serviceInstanceId,"UTF-8")
            execution.setVariable("serviceInstanceId", serviceInstanceId)

            //subscriberInfo
            String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "requestDetails.subscriberInfo.globalSubscriberId")
            if (isBlank(globalSubscriberId)) {
                msg = "Input globalSubscriberId' is null"
                exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
            } else {
                execution.setVariable("globalSubscriberId", globalSubscriberId)
            }

            //requestInfo
            execution.setVariable("source", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.source"))
            execution.setVariable("serviceInstanceName", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.instanceName"))
            execution.setVariable("disableRollback", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.suppressRollback"))
            String productFamilyId = jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.productFamilyId")
            if (isBlank(productFamilyId))
            {
                msg = "Input productFamilyId is null"
                logger.debug(msg)
                //exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
            } else {
                execution.setVariable("productFamilyId", productFamilyId)
            }

            //modelInfo
            String serviceModelInfo = jsonUtil.getJsonValue(siRequest, "requestDetails.modelInfo")
            if (isBlank(serviceModelInfo)) {
                msg = "Input serviceModelInfo is null"
                logger.debug(msg)
                exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
            } else
            {
                execution.setVariable("csServiceModelInfo", serviceModelInfo)
            }

            logger.debug("modelInfo: " + serviceModelInfo)

            //requestParameters, subscriptionServiceType is 5G
            String subscriptionServiceType = jsonUtil.getJsonValue(siRequest, "requestDetails.requestParameters.subscriptionServiceType")
            if (isBlank(subscriptionServiceType)) {
                msg = "Input subscriptionServiceType is null"
                logger.debug(msg)
                exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
            } else {
                // todo: in create e2e interface, this value is write "MOG", so write it as "5G"
                execution.setVariable("subscriptionServiceType", "5G")
            }


            /*
             * Extracting User Parameters from incoming Request and converting into a Map
             */
            def jsonSlurper = new JsonSlurper()

            Map reqMap = jsonSlurper.parseText(siRequest) as Map

            //InputParams
            def userParamsList = reqMap.requestDetails?.requestParameters?.userParams

            Map<String, String> inputMap = [:]
            if (userParamsList) {
                for (def i=0; i<userParamsList.size(); i++) {
                    def userParams1 = userParamsList.get(i)
                    userParams1.each { param -> inputMap.put(param.key, param.value)}
                }
            }

            logger.debug("User Input Parameters map: " + inputMap.toString())
            execution.setVariable("serviceInputParams", inputMap)
            execution.setVariable("uuiRequest", inputMap.get("UUIRequest"))
            execution.setVariable("isAllNSMFFinished", "false")
            String operationId = UUID.randomUUID().toString()
            execution.setVariable("operationId", operationId)

        } catch(BpmnError e) {
            throw e
        } catch(Exception ex) {
            msg = "Exception in CreateCommunicationService.preProcessRequest " + ex.getMessage()
            logger.debug(msg)
            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
        }
        logger.debug(Prefix + "preProcessRequest Exit")
    }


    /**
     * create operation status in request db
     *
     * Init the Operation Status
     */
    def prepareInitOperationStatus = { DelegateExecution execution ->
        logger.debug(Prefix + "prepareInitOperationStatus Start")

        String serviceId = execution.getVariable("serviceInstanceId")
        //operationId is generated
        String operationId = execution.getVariable("operationId")
        logger.debug("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId)

        OperationStatus initStatus = new OperationStatus()
        initStatus.setServiceId(serviceId)
        initStatus.setOperationId(operationId)
        initStatus.setOperation("CREATE")
        initStatus.setUserId(execution.getVariable("globalSubscriberId") as String)
        initStatus.setResult("processing")
        initStatus.setProgress("0")
        initStatus.setReason("")
        initStatus.setOperationContent("communication service create operation start")

        requestDBUtil.prepareUpdateOperationStatus(execution, initStatus)

        logger.debug(Prefix + "prepareInitOperationStatus Exit")
    }


    /**
     * return sync response
     */
    def sendSyncResponse = { DelegateExecution execution ->
        logger.debug(Prefix + "sendSyncResponse Start")
        try {
            String operationId = execution.getVariable("operationId")
            String serviceInstanceId = execution.getVariable("serviceInstanceId")
            String createServiceRestRequest = """
                    {
                        "service": {
                            "serviceId":"${serviceInstanceId}",
                            "operationId":"${operationId}"
                        }
                    }
                    """.trim().replaceAll(" ", "")

            logger.debug("sendSyncResponse to APIH:" + "\n" + createServiceRestRequest)
            sendWorkflowResponse(execution, 202, createServiceRestRequest)

            execution.setVariable("sentSyncResponse", true)
        } catch (Exception ex) {
            String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
            logger.debug(msg)
            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
        }
        logger.debug(Prefix + "sendSyncResponse Exit")
    }


    /**
     * query e2e service
     * @param execution
     */
    def prepareDoComposeE2E = { DelegateExecution execution ->
        logger.debug(Prefix + "prepareDoComposeE2E Start")
        try {
            ServiceDecomposition serviceDecomposition = execution.getVariable(
                    "csServiceDecomposition") as ServiceDecomposition

            logger.debug("serviceDecomposition is:" + serviceDecomposition.toJsonString())

            List<ServiceProxy> serviceProxies = serviceDecomposition.getServiceProxy()
            String sourceModelUuid = serviceProxies.get(0).getSourceModelUuid()

            JSONObject queryJson = new JSONObject()
            queryJson.put("modelUuid", sourceModelUuid)

            execution.setVariable("e2eServiceModelInfo", queryJson.toString())
        } catch (BpmnError e) {
            throw e
        } catch (Exception ex) {
            String msg = "Exception in CreateCommunicationService.prepareDoComposeE2E. " + ex.getMessage()
            logger.info(msg)
            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
        }

        logger.debug(Prefix + "prepareDoComposeE2E Exit")
    }


    /**
     * parse communication service params from request
     * @param execution
     */
    def parseCSParamsFromReq = { DelegateExecution execution ->
        logger.debug(Prefix + "parseCSParamsFromReq Start")
        try {
            //1. CMS info

            String modelInfo = execution.getVariable("csServiceModelInfo")
            String modelInvariantUuid = jsonUtil.getJsonValue(modelInfo, "modelInvariantUuid")
            String modelUuid = jsonUtil.getJsonValue(modelInfo, "modelUuid")

            //String modelInvariantUuid = execution.getVariable("modelInvariantId")
            //String modelUuid = execution.getVariable("modelUuid")
            String uuiRequest = execution.getVariable("uuiRequest")
            String useInterval = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.useInterval")
            String csServiceName = jsonUtil.getJsonValue(uuiRequest, "service.name")
            String csServiceDescription = jsonUtil.getJsonValue(uuiRequest, "service.description")

            execution.setVariable("modelInvariantUuid", modelInvariantUuid)
            execution.setVariable("modelUuid", modelUuid)
            execution.setVariable("useInterval", useInterval)
            execution.setVariable("csServiceName", csServiceName)
            execution.setVariable("csServiceDescription", csServiceDescription)


            //2. profile info
            Integer expDataRateDL = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.expDataRateDL") as Integer
            Integer expDataRateUL = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.expDataRateUL") as Integer
            Integer latency = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.latency") as Integer
            Integer maxNumberOfUEs = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.maxNumberofUEs") as Integer
            String uEMobilityLevel = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.uEMobilityLevel")
            String resourceSharingLevel = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.resourceSharingLevel")
            String coverageArea = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.coverageAreaList")

            // from template construct input map
            //String cstTemplate = execution.getVariable("cstTemplate")
            ServiceDecomposition csServiceDecomposition = execution.getVariable(
                    "csServiceDecomposition") as ServiceDecomposition
            //String csServiceType = jsonUtil.getJsonValue(cstTemplate, "serviceResources.serviceType")
            String csServiceType = csServiceDecomposition.getServiceType()
            execution.setVariable("csServiceType", csServiceType)

            //String cstTemplateInfo = jsonUtil.getJsonValue(cstTemplate, "serviceResources.serviceInfo.serviceInput")
            ServiceInfo csServiceInfo = csServiceDecomposition.getServiceInfo()
            String cstTemplateInfo = csServiceInfo.getServiceProperties()

            List<String> csInputs = jsonUtil.StringArrayToList(cstTemplateInfo)

            Map<String, ?> csInputMap = new HashMap<>()
            for (String csInput : csInputs) {
                String key = jsonUtil.getJsonValue(csInput, "name")
                def value = jsonUtil.getJsonValue(csInput, "default")
                csInputMap.put(key, getDefaultPropertiesByType(value, key))
            }
            csInputMap.put("expDataRateDL", expDataRateDL)
            csInputMap.put("expDataRateUL", expDataRateUL)
            csInputMap.put("latency", latency)
            csInputMap.put("maxNumberofUEs", maxNumberOfUEs)
            csInputMap.put("uEMobilityLevel", uEMobilityLevel)
            csInputMap.put("resourceSharingLevel", resourceSharingLevel)
            csInputMap.put("coverageAreaTAList", coverageArea)
            csInputMap.put("useInterval", useInterval)

            execution.setVariable("csInputMap", csInputMap)
            logger.debug(Prefix + "csInputMap is = " + csInputMap.toString())
        } catch (BpmnError e) {
            throw e
        } catch (Exception ex) {
            String msg = "Exception in CreateCommunicationService.parseCSParamsFromReq. " + ex.getMessage()
            logger.info(msg)
            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
        }
        logger.debug(Prefix + "parseCSParamsFromReq Exit")
    }


    /**
     * get E2EST id through CST id and change communication profile to E2E service profile
     * 1. get E2EST id from cst
     * 1.1 source service id
     * 1.2 source service
     * 1.3 source service input, init e2e profile
     */
    def generateE2EServiceProfile = { DelegateExecution execution ->
        logger.debug(Prefix + "generateE2EServiceProfile Start")
        try {
            ServiceDecomposition e2eServiceDecomposition = execution.getVariable(
                    "e2eServiceDecomposition") as ServiceDecomposition
            String e2estTemplateInfo = e2eServiceDecomposition.getServiceInfo().getServiceProperties()

            List<String> e2eInputs = jsonUtil.StringArrayToList(e2estTemplateInfo)

            Map<String, ?> csInputMap = execution.getVariable("csInputMap") as Map
            Map<String, ?> e2eInputMap = new HashMap<>()

            for (String e2eInput in e2eInputs) {
                String key = jsonUtil.getJsonValue(e2eInput, "name")
                String type = jsonUtil.getJsonValue(e2eInput, "type")
                def value
                if (csInputMap.containsKey(key)) {
                    value = csInputMap.get(key)
                } else {
                    value = jsonUtil.getJsonValue(e2eInput, "default")

                }
                e2eInputMap.put(key, getDefaultPropertiesByType(value, type))
            }

            //TODO temp solution
            e2eInputMap.put("sNSSAI", execution.getVariable("sNSSAI_id"))
	        e2eInputMap.put("sST", execution.getVariable("csServiceType"))

            Integer activityFactor = Integer.parseInt(e2eInputMap.get("activityFactor").toString())
            Integer random = new Random().nextInt(5) + 2
            Integer dLThptPerUE = Integer.parseInt(csInputMap.get("expDataRateDL").toString())
            Integer uLThptPerUE = Integer.parseInt(csInputMap.get("expDataRateUL").toString())
            Integer maxNumberofUEs = Integer.parseInt(e2eInputMap.get("maxNumberofUEs").toString())
            Integer dLThptPerSlice = dLThptPerUE * maxNumberofUEs * activityFactor * random
            Integer uLThptPerSlice = uLThptPerUE * maxNumberofUEs * activityFactor * random
            Integer maxNumberofConns = maxNumberofUEs * activityFactor * 3

            e2eInputMap.put("jitter", 10)
            e2eInputMap.put("dLThptPerUE", dLThptPerUE)
            e2eInputMap.put("uLThptPerUE", uLThptPerUE)
            e2eInputMap.put("dLThptPerSlice", dLThptPerSlice)
            e2eInputMap.put("uLThptPerSlice", uLThptPerSlice)
            e2eInputMap.put("maxNumberofConns", maxNumberofConns)
            //TODO temp solution - service to slice profile mapping
            e2eInputMap.put("expDataRateDL", dLThptPerSlice)
            e2eInputMap.put("expDataRateUL", uLThptPerSlice)
            e2eInputMap.put("maxNumberofPDUSession", maxNumberofConns)

            execution.setVariable("e2eInputMap", e2eInputMap)
            execution.setVariable("e2eServiceType", e2eServiceDecomposition.getServiceType())
            execution.setVariable("e2eModelInvariantUuid", e2eServiceDecomposition.getModelInfo().getModelInvariantUuid())
            execution.setVariable("e2eModelUuid", e2eServiceDecomposition.getModelInfo().getModelUuid())
            logger.debug(Prefix + "e2eInputMap is = " + e2eInputMap.toString())
        } catch (BpmnError e) {
            throw e
        } catch (Exception ex) {
            String msg = "Exception in DoCreateE2EServiceInstance.createRelationShipInAAI. " + ex.getMessage()
            logger.info(msg)
            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
        }

        logger.debug(Prefix + "generateE2EServiceProfile Exit")
    }

    static def getDefaultPropertiesByType(def value, String type) {

        def defaultValue
        switch (type) {
            case "string":
                defaultValue = ""
                break
            case "integer":
                defaultValue = 0
                break
            case "float":
                defaultValue = 0.0
                break
            default:
                defaultValue = null
                break
        }
        return StringUtils.isEmpty(value) ? defaultValue : value
    }

    /**
     * call createE2EService get operation id,
     * created/processing
     */
    def preRequestSend2NSMF(DelegateExecution execution) {
        logger.debug(Prefix + "preRequestSend2NSMF Start")
        try {

            //String NSMF_endpoint = "/onap/so/infra/e2eServiceInstances/v3"
            def NSMF_endpoint = UrnPropertiesReader.getVariable("mso.infra.endpoint.url", execution)
            def url = NSMF_endpoint + "/e2eServiceInstances/v3"
            execution.setVariable("NSMF_endpoint", url)
            //get from model catalog inputs
            String payload = """
                {
                    "service":{
                        "name": "${execution.getVariable("csServiceName")}",
                        "description": "e2eService of ${execution.getVariable("modelUuid")}",
                        "serviceInvariantUuid": "${execution.getVariable("e2eModelInvariantUuid")}",
                        "serviceUuid": "${execution.getVariable("e2eModelUuid")}",
                        "globalSubscriberId": "${execution.getVariable("globalSubscriberId")}",
                        "serviceType": "${execution.getVariable("subscriptionServiceType")}",
                        "parameters":{
                            "requestInputs": ${execution.getVariable("e2eInputMap") as JSONObject}
                        }
                    }
                }
            """
            execution.setVariable("CSMF_NSMFRequest", payload.replaceAll("\\s+", ""))
            logger.debug(Prefix + "Sent to NSMF Request = " + payload)
        } catch (BpmnError e) {
            throw e
        } catch (Exception ex) {
            String msg = "Exception in CreateCommunicationService.preRequestSend2NSMF. " + ex.getMessage()
            logger.error(msg)
            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
        }

        logger.debug(Prefix + "preRequestSend2NSMF Exit")
    }


    def processNSMFResponse = { DelegateExecution execution ->
        logger.debug(Prefix + "processNSMFResponse Start")
        //oof
        try {
            def CSMF_NSMFResponseCode = execution.getVariable("CSMF_NSMFResponseCode") as Integer
            if (CSMF_NSMFResponseCode >= 200 && CSMF_NSMFResponseCode < 400) {
                def CSMF_NSMFResponse = execution.getVariable("CSMF_NSMFResponse") as String
                def e2eServiceInstanceId = jsonUtil.getJsonValue(CSMF_NSMFResponse, "service.serviceId")
                def e2eOperationId = jsonUtil.getJsonValue(CSMF_NSMFResponse, "service.operationId")

                execution.setVariable("e2eServiceInstanceId", e2eServiceInstanceId)
                execution.setVariable("e2eOperationId", e2eOperationId)
                execution.setVariable("ProcessNsmfSuccess", "OK")
            } else {
                execution.setVariable("ProcessNsmfSuccess", "ERROR")
                execution.setVariable("operationStatus", "error")
                execution.setVariable("operationContent",
                        "communication service create operation error: nsmf response fail")
                execution.setVariable("orchestrationStatus", "error")
            }

        } catch (BpmnError e) {
            throw e
        } catch (Exception ex) {
            String msg = "Exception in " + Prefix + "processOOFResponse. " + ex.getMessage()
            logger.info(msg)
            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
        }
        logger.debug(Prefix + "processNSMFResponse Exit")
    }


    /**
     * create communication service and e2e service relationship
     *
     */
    def createCSAndSSRelationship = { DelegateExecution execution ->
        logger.debug(Prefix + "createCSAndSSRelationship Start")
        String msg = ""
        try {
            def e2eServiceInstanceId = execution.getVariable("e2eServiceInstanceId")
            String globalSubscriberId = execution.getVariable("globalSubscriberId")
            String subscriptionServiceType = execution.getVariable("subscriptionServiceType")

            Relationship relationship = new Relationship()
            String relatedLink = "aai/v16/business/customers/customer/${globalSubscriberId}/service-subscriptions/service-subscription/${subscriptionServiceType}/service-instances/service-instance/${e2eServiceInstanceId}"
            relationship.setRelatedLink(relatedLink)

            // create CS and SS relationship in AAI
            createRelationShipInAAI(execution, relationship)

        } catch (BpmnError e) {
            throw e
        } catch (Exception ex) {

            msg = "Exception in DoCreateE2EServiceInstance.createCustomRelationship. " + ex.getMessage()
            logger.info(msg)
            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
        }
        logger.debug(Prefix + "createCSAndSSRelationship Exit")
    }


    /**
     * prepare update operation status to 50% after create relationship in aai
     * @param execution
     */
    def prepareUpdateOperationStatus = { DelegateExecution execution ->
        logger.debug(Prefix + "prepareUpdateOperationStatus Start")
        // update status creating
        OperationStatus status = new OperationStatus()
        status.setServiceId(execution.getVariable("serviceInstanceId") as String)
        status.setOperationId(execution.getVariable("operationId") as String)
        status.setOperation("CREATE")
        status.setResult("processing")
        status.setProgress("20")
        status.setOperationContent("communication service create operation processing: waiting nsmf service create finished")
        status.setUserId(execution.getVariable("globalSubscriberId") as String)

        requestDBUtil.prepareUpdateOperationStatus(execution, status)
        logger.debug(Prefix + "prepareUpdateOperationStatus Exit")
    }


    /**
     * create relationship in AAI
     */
    private createRelationShipInAAI = { DelegateExecution execution, final Relationship relationship ->
        logger.debug(Prefix + "createRelationShipInAAI Start")
        String msg
        try {
            String serviceInstanceId = execution.getVariable("serviceInstanceId")
            AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(serviceInstanceId)).relationshipAPI()
            client.create(uri, relationship)

        } catch (BpmnError e) {
            throw e
        } catch (Exception ex) {
            msg = "Exception in CreateCommunicationService.createRelationShipInAAI. " + ex.getMessage()
            logger.info(msg)
            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
        }
        logger.debug(Prefix + "createRelationShipInAAI Exit")

    }


    def prepareCallCheckProcessStatus = { DelegateExecution execution ->
        logger.debug(Prefix + "prepareCallCheckProcessStatus Start")

        def successConditions = new ArrayList<>()
        successConditions.add("finished")
        execution.setVariable("successConditions", successConditions)

        def errorConditions = new ArrayList<>()
        errorConditions.add("error")
        execution.setVariable("errorConditions", errorConditions)

        execution.setVariable("processServiceType", "communication service")

        execution.setVariable("subOperationType", "CREATE")

        execution.setVariable("timeOut", 3 * 60 * 60 * 1000)

        def successParamMap = new HashMap<String, Object>()
        successParamMap.put("orchestrationStatus", "deactivated")

        execution.setVariable("successParamMap", successParamMap)

        def errorParamMap = new HashMap<String, Object>()
        errorParamMap.put("orchestrationStatus", "error")

        execution.setVariable("errorParamMap", errorParamMap)

        def timeOutParamMap = new HashMap<String, Object>()
        timeOutParamMap.put("orchestrationStatus", "error")

        execution.setVariable("timeOutParamMap", timeOutParamMap)

        execution.setVariable("initProgress", 20)
        execution.setVariable("endProgress", 90)

        logger.debug(Prefix + "prepareCallCheckProcessStatus Exit")
    }


    /**
     * prepare update operation status to complete after NSMF process success
     * @param execution
     */
    def prepareCompleteStatus = { DelegateExecution execution ->
        logger.debug(Prefix + "prepareCompleteStatus Start")
        OperationStatus status = new OperationStatus()
        status.setServiceId(execution.getVariable("serviceInstanceId") as String)
        status.setOperationId(execution.getVariable("operationId") as String)
        status.setOperation("CREATE")
        status.setResult(execution.getVariable("operationStatus") as String)
        status.setProgress("100")
        status.setOperationContent(execution.getVariable("operationContent") as String)
        status.setUserId(execution.getVariable("globalSubscriberId") as String)

        requestDBUtil.prepareUpdateOperationStatus(execution, status)
        logger.debug("prepareCompleteStatus end, serviceInstanceId: " + execution.getVariable("serviceInstanceId")
                + ", operationId: " + execution.getVariable("operationId"))
        logger.debug(Prefix + "prepareCompleteStatus Exit")
    }


    /**
     * update NSMF complete status to AAI when the NSMF process finished
     * @param execution
     */
    def updateFinishStatusInAAI = { DelegateExecution execution ->
        logger.debug(Prefix + "updateFinishStatusInAAI Start")
        String msg
        try {

            String serviceInstanceId = execution.getVariable("serviceInstanceId")
            String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
            String globalSubscriberId = execution.getVariable("globalSubscriberId")
            String orchestrationStatus = execution.getVariable("orchestrationStatus")
            // create service
            ServiceInstance csi = new ServiceInstance()
            csi.setOrchestrationStatus(orchestrationStatus)
            AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(serviceInstanceId))
            client.update(uri, csi)
            logger.debug(Prefix + "updateFinishStatusInAAI update communication service status to deactivated")

        } catch (BpmnError e) {
            throw e
        } catch (Exception ex) {
            msg = "Exception in complete communication service " + ex.getMessage()
            logger.debug(msg)
            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
        }
        logger.debug(Prefix + "updateFinishStatusInAAI Exit")
    }


    public sendSyncError = { DelegateExecution execution ->
        logger.debug("sendSyncError Start")
        try {
            String errorMessage
            if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
                WorkflowException wfe = execution.getVariable("WorkflowException") as WorkflowException
                errorMessage = wfe.getErrorMessage()
            } else {
                errorMessage = "Sending Sync Error."
            }

            String buildWorkflowException =
                    """<aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
					<aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorMessage)}</aetgt:ErrorMessage>
					<aetgt:ErrorCode>7000</aetgt:ErrorCode>
				   </aetgt:WorkflowException>"""

            logger.debug(buildWorkflowException)
            sendWorkflowResponse(execution, 500, buildWorkflowException)

        } catch (Exception ex) {
            logger.debug("Sending Sync Error Activity Failed. " + "\n" + ex.getMessage())
        }
        logger.debug(Prefix + "sendSyncError Exit")
    }

}