aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateAccessNSSI.groovy
blob: 2564b11295022eb85c9c20009113406f19a8e91f (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
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
/*
 * ============LICENSE_START=======================================================
 * ONAP - SO
 * ================================================================================
 # Copyright (c) 2020, Wipro Limited.
 #
 # 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 org.camunda.bpm.engine.delegate.BpmnError
import org.camunda.bpm.engine.delegate.DelegateExecution
import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
import org.onap.so.bpmn.common.scripts.ExceptionUtil
import org.onap.so.bpmn.common.scripts.NssmfAdapterUtils
import org.onap.so.bpmn.common.scripts.OofUtils
import org.onap.so.bpmn.common.scripts.RequestDBUtil
import org.onap.so.bpmn.core.json.JsonUtils
import org.onap.so.db.request.beans.ResourceOperationStatus
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.util.List
import static org.apache.commons.lang3.StringUtils.isBlank
import com.google.gson.JsonObject
import com.google.gson.Gson
import com.fasterxml.jackson.databind.ObjectMapper
import com.google.gson.JsonArray
import com.google.gson.JsonParser
import org.onap.aai.domain.yang.Relationship
import org.onap.aaiclient.client.aai.AAIResourcesClient
import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
import org.onap.so.beans.nsmf.AllocateTnNssi
import org.onap.so.bpmn.core.UrnPropertiesReader
import org.onap.so.bpmn.core.domain.ServiceDecomposition
import org.onap.so.bpmn.core.domain.ServiceInstance
import org.onap.so.bpmn.core.domain.ServiceProxy
import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
import org.onap.aaiclient.client.aai.AAINamespaceConstants
import org.onap.aaiclient.client.aai.AAIObjectType
import org.onap.aai.domain.yang.NetworkPolicy
import org.onap.aai.domain.yang.NetworkRoute
import org.json.JSONArray

class DoAllocateAccessNSSI extends AbstractServiceTaskProcessor {

	String Prefix="AASS_"
	ExceptionUtil exceptionUtil = new ExceptionUtil()
	RequestDBUtil requestDBUtil = new RequestDBUtil()
	JsonUtils jsonUtil = new JsonUtils()
	OofUtils oofUtils = new OofUtils()
	AnNssmfUtils anNssmfUtils = new AnNssmfUtils()
	ObjectMapper objectMapper = new ObjectMapper();
	private NssmfAdapterUtils nssmfAdapterUtils = new NssmfAdapterUtils(httpClientFactory, jsonUtil)

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

	@Override
	void preProcessRequest(DelegateExecution execution) {
		logger.debug(Prefix + "preProcessRequest Start")
		execution.setVariable("prefix", Prefix)
		execution.setVariable("startTime", System.currentTimeMillis())
		def msg
		try {

			logger.debug("input variables : msoRequestId - "+execution.getVariable("msoRequestId")
					+" modelInvariantUuid - "+execution.getVariable("modelInvariantUuid")+
					" modelUuid - "+execution.getVariable("modelUuid")+
					" globalSubscriberId - "+execution.getVariable("globalSubscriberId")+
					" dummyServiceId - "+ execution.getVariable("dummyServiceId")+
					" nsiId - "+execution.getVariable("nsiId")+
					" networkType - "+execution.getVariable("networkType")+
					" subscriptionServiceType - "+execution.getVariable("subscriptionServiceType")+
					" jobId - "+execution.getVariable("jobId")+
					" sliceParams - "+execution.getVariable("sliceParams")+
					" servicename - "+ execution.getVariable("servicename")+
                                        " sst - "+ execution.getVariable("sst"))

			//validate slice subnet inputs

			String sliceParams = execution.getVariable("sliceParams")
			String sliceProfile = jsonUtil.getJsonValue(sliceParams, "sliceProfile")
			if (isBlank(sliceProfile)) {
				msg = "Input sliceProfile is null"
				logger.debug(msg)
				exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
			} else {
				execution.setVariable("sliceProfile", sliceProfile)
			}
			String sliceProfileId = jsonUtil.getJsonValue(sliceProfile, "sliceProfileId")
			def snssaiList = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(sliceProfile, "snssaiList"))
			def plmnIdList = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(sliceProfile, "pLMNIdList"))
                        String jsonArray = jsonUtil.getJsonValue(sliceProfile, "coverageAreaTAList")
                        List<Integer> list = new ArrayList<>();
                        JSONArray arr = new JSONArray(jsonArray);
                        for (int i = 0; i < arr.length(); i++) {
                                 int s = (int) arr.get(i);
                                 list.add(s);
                        }
                        def coverageAreaTAList = list;

			if (isBlank(sliceProfileId) || (snssaiList.empty) || (plmnIdList.empty)
			|| (coverageAreaTAList.empty)) {

				msg = "Mandatory slice profile fields are empty"
				logger.debug(msg)
				exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
			} else {
				execution.setVariable("sliceProfileId", sliceProfileId)
				execution.setVariable("snssaiList", snssaiList)
				execution.setVariable("pLMNIdList", plmnIdList)
				execution.setVariable("coverageAreaTAList", coverageAreaTAList)
			}
			String nsiName = jsonUtil.getJsonValue(sliceParams, "nsiInfo.nsiName")
			String scriptName = jsonUtil.getJsonValue(sliceParams, "scriptName")
			execution.setVariable("nsiName", nsiName)
			execution.setVariable("scriptName", scriptName)
			//generate RAN,RAN NF NSSIs - will be re assigned if oof returns existing NSSI
			String RANServiceInstanceId = UUID.randomUUID().toString()
			String RANNFServiceInstanceId = UUID.randomUUID().toString()
			logger.debug("RAN serviceInstance Id "+RANServiceInstanceId)
			logger.debug("RAN NF serviceInstance Id "+RANNFServiceInstanceId)			
			execution.setVariable("RANServiceInstanceId", RANServiceInstanceId)
			execution.setVariable("RANNFServiceInstanceId", RANNFServiceInstanceId)
			execution.setVariable("ranNssiPreferReuse", true)
			execution.setVariable("ranNfNssiPreferReuse", true)
			execution.setVariable("job_timeout", 10)
			
			//set BH end point
			def BH_endPoints = jsonUtil.getJsonValue(sliceParams, "endPoint")
                        logger.debug("BH end points list : "+BH_endPoints)
                        if(isBlank(BH_endPoints)) {
                                msg = "End point info is empty"
                                logger.debug(msg)
                                exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
                        }else {
                                execution.setVariable("bh_endpoint", BH_endPoints)
                        }

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

	/*
	 * Prepare request params for decomposing RAN NSST
	 */

	def prepareDecomposeService = { DelegateExecution execution ->
		logger.debug(Prefix+"prepareDecomposeService method start")
		String RANServiceInstanceId = execution.getVariable("RANServiceInstanceId")
		String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
		String modelUuid = execution.getVariable("modelUuid")
		String serviceModelInfo = """{
            "modelInvariantUuid":"${modelInvariantUuid}",
            "modelUuid":"${modelUuid}",
            "modelVersion":""
             }"""
		execution.setVariable("serviceModelInfo", serviceModelInfo)
		execution.setVariable("serviceInstanceId", RANServiceInstanceId)
		logger.debug("serviceModelInfo : "+serviceModelInfo)
		logger.debug("Finish RAN NSST prepareDecomposeService")
	}

	/* process the decompose service(RAN NSST) response
	 * 
	 */
	def processDecomposition = { DelegateExecution execution ->
		logger.debug(Prefix+"processDecomposition method start")
		ServiceDecomposition ranNsstServiceDecomposition = execution.getVariable("ranNsstServiceDecomposition")
		logger.debug("ranNsstServiceDecomposition : "+ranNsstServiceDecomposition.toString())
		//RAN NSST decomposition
		String ranModelVersion = ranNsstServiceDecomposition.getModelInfo().getModelVersion()
		String ranModelName = ranNsstServiceDecomposition.getModelInfo().getModelName()
		List<ServiceProxy> serviceProxyList = ranNsstServiceDecomposition.getServiceProxy()
		List<String> nsstInfoList = new ArrayList<>()
		for(ServiceProxy serviceProxy : serviceProxyList)
		{
			String nsstModelUuid = serviceProxy.getSourceModelUuid()
			String nsstModelInvariantUuid = serviceProxy.getModelInfo().getModelInvariantUuid()
			String name = serviceProxy.getModelInfo().getModelName()
			String nsstServiceModelInfo = """{
            "UUID":"${nsstModelUuid}",
            "invariantUUID":"${nsstModelInvariantUuid}",
            "name":"${name}"
             }"""
			nsstInfoList.add(nsstServiceModelInfo)
		}
		int currentIndex=0
		int maxIndex=nsstInfoList.size()
		if(maxIndex < 1)
		{
			String msg = "Exception in RAN NSST processDecomposition. There is no NSST associated with RAN NSST "
			logger.info(msg)
			exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
		}
		execution.setVariable("ranNsstInfoList", objectMapper.writeValueAsString(nsstInfoList))
		execution.setVariable("ranModelVersion", ranModelVersion)
		execution.setVariable("ranModelName", ranModelName)
		execution.setVariable("currentIndex",currentIndex)
		execution.setVariable("maxIndex",maxIndex)
		logger.debug(Prefix+"processDecomposition maxIndex value - "+maxIndex)
	}

	/*
	 * Function to subnet capabilities from nssmf adapter
	 */
	def getSubnetCapabilities = { DelegateExecution execution ->
		logger.debug(Prefix+"getSubnetCapabilities method start")

		String tnNssmfRequest = anNssmfUtils.buildCreateTNNSSMFSubnetCapabilityRequest()

		String urlString = "/api/rest/provMns/v1/NSS/subnetCapabilityQuery"

		String tnNssmfResponse = nssmfAdapterUtils.sendPostRequestNSSMF(execution, urlString, tnNssmfRequest)

		if (tnNssmfResponse != null) {
			String FHCapabilities= jsonUtil.getJsonValue(tnNssmfResponse, "TN_FH")
			String MHCapabilities = jsonUtil.getJsonValue(tnNssmfResponse, "TN_MH")
			execution.setVariable("FHCapabilities",FHCapabilities)
			execution.setVariable("MHCapabilities",MHCapabilities)

		} else {
			logger.error("received error message from NSSMF : "+ tnNssmfResponse)
			exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"Received a Bad Sync Response from NSSMF.")
		}
		String anNssmfRequest = anNssmfUtils.buildCreateANNFNSSMFSubnetCapabilityRequest()

		String anNssmfResponse = nssmfAdapterUtils.sendPostRequestNSSMF(execution, urlString, anNssmfRequest)

		if (anNssmfResponse != null) {
			String ANNFCapabilities = jsonUtil.getJsonValue(anNssmfResponse, "AN_NF")
			execution.setVariable("ANNFCapabilities",ANNFCapabilities)

		} else {
			logger.error("received error message from NSSMF : "+ anNssmfResponse)
			exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"Received a Bad Sync Response from NSSMF.")
		}
	}

	/*
	 * prepare OOF request for RAN NSSI selection
	 */
	def prepareOofRequestForRanNSS = { DelegateExecution execution ->
		logger.debug(Prefix+"prepareOofRequestForRanNSS method start")

		String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution)
		logger.debug( "get NSSI option OOF Url: " + urlString)
		JsonParser parser = new JsonParser()
		//build oof request body
		boolean ranNssiPreferReuse = execution.getVariable("ranNssiPreferReuse");
		String requestId = execution.getVariable("msoRequestId")
		String messageType = "NSISelectionResponse"
		Map<String, Object> profileInfo = objectMapper.readValue(execution.getVariable("sliceProfile"), Map.class)
                profileInfo.put("sST",execution.getVariable("sst"))
		String modelUuid = execution.getVariable("modelUuid")
		String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
		String modelName = execution.getVariable("ranModelName")
		String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution);
		List<String> nsstInfoList =  objectMapper.readValue(execution.getVariable("ranNsstInfoList"), List.class)
		JsonArray capabilitiesList = new JsonArray()
		String FHCapabilities = execution.getVariable("FHCapabilities")
		String MHCapabilities = execution.getVariable("MHCapabilities")
		String ANNFCapabilities = execution.getVariable("ANNFCapabilities")
		JsonObject FH = new JsonObject()
		JsonObject MH = new JsonObject()
		JsonObject ANNF = new JsonObject()
		FH.addProperty("domainType", "TN_FH")
		FH.add("capabilityDetails", (JsonObject) parser.parse(FHCapabilities))
		MH.addProperty("domainType", "TN_MH")
		MH.add("capabilityDetails", (JsonObject) parser.parse(MHCapabilities))
		ANNF.addProperty("domainType", "AN_NF")
		ANNF.add("capabilityDetails", (JsonObject) parser.parse(ANNFCapabilities))
		capabilitiesList.add(FH)
		capabilitiesList.add(MH)
		capabilitiesList.add(ANNF)

		execution.setVariable("nssiSelection_Url", "/api/oof/selection/nsi/v1")
		execution.setVariable("nssiSelection_messageType",messageType)
		execution.setVariable("nssiSelection_correlator",requestId)
		execution.setVariable("nssiSelection_timeout",timeout)

		String oofRequest = anNssmfUtils.buildSelectRANNSSIRequest(requestId, messageType, modelUuid,modelInvariantUuid,
				modelName, profileInfo, nsstInfoList, capabilitiesList, ranNssiPreferReuse)

		execution.setVariable("nssiSelection_oofRequest",oofRequest)
		logger.debug("Sending request to OOF: " + oofRequest)
	}
	/*
	 * process OOF response for RAN NSSI selection
	 */
	def processOofResponseForRanNSS = { DelegateExecution execution ->
		logger.debug(Prefix+"processOofResponseForRanNSS method start")
		String oofResponse = execution.getVariable("nssiSelection_asyncCallbackResponse")
		String requestStatus = jsonUtil.getJsonValue(oofResponse, "requestStatus")
		if(requestStatus.equals("completed")) {
			String solutions = jsonUtil.getJsonValue(oofResponse, "solutions")
			logger.debug("solutions value : "+solutions)
			JsonParser parser = new JsonParser()
			JsonArray solution = parser.parse(solutions)
			JsonObject sol = solution.get(0)
			boolean existingNSI = sol.get("existingNSI").getAsBoolean()
			logger.debug("existingNSI value : "+existingNSI)
			if(existingNSI) {
				JsonObject sharedNSISolution = sol.get("sharedNSISolution").getAsJsonObject()
				execution.setVariable("sharedRanNSSISolution", sharedNSISolution.toString())
				logger.debug("sharedRanNSSISolution from OOF "+sharedNSISolution)
				String RANServiceInstanceId = sharedNSISolution.get("NSIId").getAsString()
				execution.setVariable("RANServiceInstanceId", RANServiceInstanceId)
				ServiceInstance serviceInstance = new ServiceInstance();
				serviceInstance.setInstanceId(RANServiceInstanceId);
				ServiceDecomposition serviceDecomposition = execution.getVariable("ranNsstServiceDecomposition")
				serviceDecomposition.setServiceInstance(serviceInstance);
				execution.setVariable("ranNsstServiceDecomposition", serviceDecomposition)
				execution.setVariable("isRspRanNssi", true)
			}else {
				JsonObject newNSISolution = sol.get("newNSISolution").getAsJsonObject()
				JsonArray sliceProfiles = newNSISolution.get("sliceProfiles").getAsJsonArray()
				logger.debug("RanConstituentSliceProfiles list from OOF "+sliceProfiles)
				execution.setVariable("RanConstituentSliceProfiles", sliceProfiles.toString())
			}
		}else {
			String statusMessage = jsonUtil.getJsonValue(oofResponse, "statusMessage")
			logger.error("received failed status from oof "+ statusMessage)
			exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"Received a failed Async Response from OOF : "+statusMessage)
		}

	}

	def prepareModifyAccessNssiInputs = { DelegateExecution execution ->
		logger.debug(Prefix+"prepareModifyAccessNssiInputs method start")
		String jobId = UUID.randomUUID().toString()
		execution.setVariable("modifyRanNssiJobId", jobId)		
		String snssaiList = execution.getVariable("snssaiList")
		String sliceParams = execution.getVariable("sliceParams")
		String sliceProfileId = execution.getVariable("sliceProfileId")
		String nsiInfo = jsonUtil.getJsonValue(sliceParams, "nsiInfo")
		String scriptName = execution.getVariable("scriptName")
		
		JsonObject modifySliceParams = new JsonObject()
		modifySliceParams.addProperty("modifyAction", "allocate")
		modifySliceParams.addProperty("snssaiList", snssaiList)
		modifySliceParams.addProperty("sliceProfileId", sliceProfileId)
		modifySliceParams.addProperty("nsiInfo", nsiInfo)
		modifySliceParams.addProperty("scriptName", scriptName)
		
		execution.setVariable("modifySliceParams", modifySliceParams.toString())
		//create operation status in request db
		String nsiId = execution.getVariable("nsiId")
		String modelUuid = execution.getVariable("modelUuid")
		logger.debug("Generated new job for Service Instance serviceId:" + nsiId + "jobId:" + jobId)

		ResourceOperationStatus initStatus = new ResourceOperationStatus()
		initStatus.setServiceId(nsiId)
		initStatus.setOperationId(jobId)
		initStatus.setResourceTemplateUUID(modelUuid)
		initStatus.setOperType("Modify")
		requestDBUtil.prepareInitResourceOperationStatus(execution, initStatus)
	}
	
	def createModifyNssiQueryJobStatus = { DelegateExecution execution ->
		logger.debug(Prefix+"createModifyNssiQueryJobStatus method start")
		JsonObject esrInfo = new JsonObject()
	    esrInfo.addProperty("networkType", "tn")
	    esrInfo.addProperty("vendor", "ONAP_internal")

		execution.setVariable("esrInfo", esrInfo.toString())
		JsonObject serviceInfo = new JsonObject()
		serviceInfo.addProperty("nssiId", execution.getVariable("RANServiceInstanceId"))
		serviceInfo.addProperty("nsiId", execution.getVariable("nsiId"))
		serviceInfo.addProperty("nssiName", execution.getVariable("servicename"))
                serviceInfo.addProperty("sST", execution.getVariable("sst"))
		serviceInfo.addProperty("PLMNIdList", objectMapper.writeValueAsString(execution.getVariable("pLMNIdList")))
		serviceInfo.addProperty("globalSubscriberId", execution.getVariable("globalSubscriberId"))
		serviceInfo.addProperty("subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
		serviceInfo.addProperty("serviceInvariantUuid", execution.getVariable("modelInvariantUuid"))
		serviceInfo.addProperty("serviceUuid", execution.getVariable("modelUuid"))
		execution.setVariable("serviceInfo", serviceInfo.toString())
		execution.setVariable("responseId", "")
	}
	def prepareNsstDecomposeService = { DelegateExecution execution ->
		logger.debug(Prefix+"prepareNsstDecomposeService method start")
		List<String> nsstInfoList = objectMapper.readValue(execution.getVariable("ranNsstInfoList"), List.class)
		int currentIndex = execution.getVariable("currentIndex")
		int maxIndex = execution.getVariable("maxIndex")
		logger.debug(Prefix+"prepareNsstDecomposeService : currentIndex value - "+currentIndex+" maxIndex : "+maxIndex)
		if(currentIndex<maxIndex) {
			String nsstInfo = nsstInfoList.get(currentIndex)
			String modelInvariantUuid = jsonUtil.getJsonValue(nsstInfo, "invariantUUID")
			String modelUuid = jsonUtil.getJsonValue(nsstInfo, "UUID")
			
			String serviceModelInfo = """{
            "modelInvariantUuid":"${modelInvariantUuid}",
            "modelUuid":"${modelUuid}",
            "modelVersion":""
             }"""
			execution.setVariable("serviceModelInfo", serviceModelInfo)
			execution.setVariable("serviceInstanceId", "")
			logger.debug("serviceModelInfo : "+serviceModelInfo)
			currentIndex++
			execution.setVariable("currentIndex", currentIndex)
		}else {
			logger.error("nsstList decomposition error ")
			exceptionUtil.buildAndThrowWorkflowException(execution, 1000, "nsstList decomposition error ")
		}
		
	}
	def processNsstDecomposition = { DelegateExecution execution ->
		logger.debug(Prefix+"processNsstDecomposition method start")
		ServiceDecomposition decomposedNsst = execution.getVariable("nsstServiceDecomposition")
		logger.debug("decomposedNsst : "+decomposedNsst.toString())
		
		String nsstType = decomposedNsst.getServiceRole() //domainType
		String modelVersion = decomposedNsst.getModelInfo().getModelVersion()
		String modelName = decomposedNsst.getModelInfo().getModelName()
		String modelUuid = decomposedNsst.getModelInfo().getModelUuid()
		String modelInvariantUuid = decomposedNsst.getModelInfo().getModelInvariantUuid()
		
		switch(nsstType) {
			case "AN_NF":
				execution.setVariable("ANNF_modelInvariantUuid", modelInvariantUuid)
				execution.setVariable("ANNF_modelUuid", modelUuid)
				execution.setVariable("ANNF_modelVersion", modelVersion)
				execution.setVariable("ANNF_modelName", modelName)
				execution.setVariable("ANNF_ServiceDecomposition", decomposedNsst)
				break
			case "TN_FH":
				execution.setVariable("TNFH_modelInvariantUuid", modelInvariantUuid)
				execution.setVariable("TNFH_modelUuid", modelUuid)
				execution.setVariable("TNFH_modelVersion", modelVersion)
				execution.setVariable("TNFH_modelName", modelName)
				execution.setVariable("TNFH_ServiceDecomposition", decomposedNsst)
				break
			case "TN_MH":
				execution.setVariable("TNMH_modelInvariantUuid", modelInvariantUuid)
				execution.setVariable("TNMH_modelUuid", modelUuid)
				execution.setVariable("TNMH_modelVersion", modelVersion)
				execution.setVariable("TNMH_modelName", modelName)
				execution.setVariable("TNMH_ServiceDecomposition", decomposedNsst)
				break
			default:
				logger.debug("No expected match found for current nsstType")
				logger.error("No expected match found for current nsstType "+ nsstType)
				exceptionUtil.buildAndThrowWorkflowException(execution, 1000,"No expected match found for current nsstType "+ nsstType)
		}
		boolean isAllNsstsDecomposed = false
		int currentIndex = execution.getVariable("currentIndex")
		int maxIndex = execution.getVariable("maxIndex")
		if(currentIndex == maxIndex) {
			isAllNsstsDecomposed = true
		}
		execution.setVariable("isAllNsstsDecomposed", isAllNsstsDecomposed)
	}
	/*
	 * prepare OOF request for NF RAN NSSI selection
	 */
	def prepareOofRequestForRanNfNSS = { DelegateExecution execution ->
		logger.debug(Prefix+"prepareOofRequestForRanNfNSS method start")
		String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution)
		logger.debug( "get NSSI option OOF Url: " + urlString)

		//build oof request body
		boolean ranNfNssiPreferReuse = execution.getVariable("ranNfNssiPreferReuse");
		String requestId = execution.getVariable("msoRequestId")
		String messageType = "NSSISelectionResponse"
		List<String> ranConstituentSliceProfiles = jsonUtil.StringArrayToList(execution.getVariable("RanConstituentSliceProfiles"))
		anNssmfUtils.createDomainWiseSliceProfiles(ranConstituentSliceProfiles, execution)
		Map<String, Object> profileInfo = objectMapper.readValue(execution.getVariable("ranNfSliceProfile"), Map.class)
		profileInfo.put("sST",execution.getVariable("sst"))
		String modelUuid = execution.getVariable("ANNF_modelUuid")
		String modelInvariantUuid = execution.getVariable("ANNF_modelInvariantUuid")
		String modelName = execution.getVariable("ANNF_modelName")
		String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution);

		execution.setVariable("nssiSelection_Url", "/api/oof/selection/nssi/v1")
		execution.setVariable("nssiSelection_messageType",messageType)
		execution.setVariable("nssiSelection_correlator",requestId)
		execution.setVariable("nssiSelection_timeout",timeout)

		String oofRequest = oofUtils.buildSelectNSSIRequest(requestId, messageType, modelUuid, modelInvariantUuid, modelName, profileInfo)

		execution.setVariable("nssiSelection_oofRequest",oofRequest)
	}
	/*
	 * process OOF response for RAN NF NSSI selection
	 */
	def processOofResponseForRanNfNSS = { DelegateExecution execution ->
		logger.debug(Prefix+"processOofResponseForRanNfNSS method start")
		String oofResponse = execution.getVariable("nfNssiSelection_asyncCallbackResponse")
		String requestStatus = jsonUtil.getJsonValue(oofResponse, "requestStatus")
		if(requestStatus.equals("completed")) {
			String solutions = jsonUtil.getJsonValue(oofResponse, "solutions")
			logger.debug("nssi solutions value : "+solutions)
			JsonParser parser = new JsonParser()
			JsonArray solution = parser.parse(solutions)		
			if(solution.size()>=1) {
				JsonObject sol = solution.get(0)
				String ranNfNssiId = sol.get("NSSIId").getAsString()
				String invariantUuid = sol.get("invariantUUID").getAsString()
				String uuid = sol.get("UUID").getAsString()
				String nssiName = sol.get("NSSIName").getAsString()
				execution.setVariable("RANNFServiceInstanceId", ranNfNssiId)
				execution.setVariable("RANNFInvariantUUID", invariantUuid)
				execution.setVariable("RANNFUUID", uuid)
				execution.setVariable("RANNFNssiName", nssiName)
				logger.debug("RANNFServiceInstanceId from OOF "+ranNfNssiId)
				
				ServiceInstance serviceInstance = new ServiceInstance();
				serviceInstance.setInstanceId(ranNfNssiId);
				ServiceDecomposition serviceDecomposition = execution.getVariable("ANNF_ServiceDecomposition")
				serviceDecomposition.setServiceInstance(serviceInstance);
				execution.setVariable("ANNF_ServiceDecomposition", serviceDecomposition)
                                execution.setVariable("modifyAction","allocate")
				execution.setVariable("isRspRanNfNssi", true)
			}else {
				logger.debug("No solutions returned from OOF .. Create new RAN NF NSSI")
			}
		}else {
			String statusMessage = jsonUtil.getJsonValue(oofResponse, "statusMessage")
			logger.error("received failed status from oof "+ statusMessage)
			exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"Received a failed Async Response from OOF : "+statusMessage)
		}
	}

	def createSliceProfilesInAai = { DelegateExecution execution ->
		logger.debug(Prefix+"createSliceProfilesInAai method start")
		anNssmfUtils.createSliceProfilesInAai(execution)
	}

	def processRanNfModifyRsp = { DelegateExecution execution ->
		logger.debug(Prefix+"processRanNfModifyRsp method start")
		anNssmfUtils.processRanNfModifyRsp(execution)
		//create RAN NSSI 
		org.onap.aai.domain.yang.ServiceInstance ANServiceInstance = new org.onap.aai.domain.yang.ServiceInstance();
		//AN instance creation
		ANServiceInstance.setServiceInstanceId(execution.getVariable("RANServiceInstanceId"))
		String sliceInstanceName = execution.getVariable("servicename")
		ANServiceInstance.setServiceInstanceName(sliceInstanceName)
		String serviceType = jsonUtil.getJsonValue(execution.getVariable("sliceProfile"), "sST")
                ANServiceInstance.setServiceType(execution.getVariable("sst"))
		String serviceStatus = "deactivated"
		ANServiceInstance.setOrchestrationStatus(serviceStatus)
		String serviceInstanceLocationid = jsonUtil.getJsonValue(execution.getVariable("sliceProfile"), "pLMNIdList")
                ANServiceInstance.setServiceInstanceLocationId(jsonUtil.StringArrayToList(serviceInstanceLocationid).get(0))
		String serviceRole = "nssi"
		ANServiceInstance.setServiceRole(serviceRole)
                List<String> snssaiList = execution.getVariable("snssaiList")
		String snssai = snssaiList.get(0)
		//ANServiceInstance.setEnvironmentContext(snssai)
                ANServiceInstance.setEnvironmentContext(execution.getVariable("networkType")) //Network Type
		ANServiceInstance.setWorkloadContext("AN") //domain Type
		
		logger.debug("completed AN service instance build "+ ANServiceInstance.toString())
		String msg = ""
		try {
	
			AAIResourcesClient client = new AAIResourcesClient()
			AAIResourceUri nssiServiceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(execution.getVariable("RANServiceInstanceId")))
			client.create(nssiServiceUri, ANServiceInstance)
	
		} catch (BpmnError e) {
			throw e
		} catch (Exception ex) {
			msg = "Exception in AnNssmfUtils.createSliceProfilesInAai " + ex.getMessage()
			logger.info(msg)
			exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
		}
		//end point update
		createEndPointsInAai(execution)
	}
	
	def createSdnrRequest = { DelegateExecution execution ->
		logger.debug(Prefix+"createSdnrRequest method start")
		String callbackUrl = UrnPropertiesReader.getVariable("mso.workflow.message.endpoint") + "/AsyncSdnrResponse/"+execution.getVariable("msoRequestId")
		String sdnrRequest = buildSdnrAllocateRequest(execution, "allocate", "instantiateRANSlice", callbackUrl)
		execution.setVariable("createNSSI_sdnrRequest", sdnrRequest)
		execution.setVariable("createNSSI_timeout", "PT10M")
		execution.setVariable("createNSSI_correlator", execution.getVariable("msoRequestId"))
		execution.setVariable("createNSSI_messageType", "AsyncSdnrResponse");
	}

	def processSdnrResponse = { DelegateExecution execution ->
		logger.debug(Prefix+"processSdnrResponse method start")
		String SDNRResponse = execution.getVariable("SDNR_asyncCallbackResponse")
		String status = jsonUtil.getJsonValue(SDNRResponse, "status")
		if(status.equalsIgnoreCase("success")) {
			String nfIds = jsonUtil.getJsonValue(SDNRResponse, "nfIds")
			execution.setVariable("ranNfIdsJson", nfIds)
		}else {
			String reason = jsonUtil.getJsonValue(SDNRResponse, "reason")
			logger.error("received failed status from SDNR "+ reason)
			exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"received failed status from SDNR "+ reason)
		}
		logger.debug("response from SDNR "+SDNRResponse)
	}

	def updateAaiWithRANInstances = { DelegateExecution execution ->
		logger.debug(Prefix+"updateAaiWithRANInstances method start")
		//create RAN NSSI 
		org.onap.aai.domain.yang.ServiceInstance ANServiceInstance = new org.onap.aai.domain.yang.ServiceInstance();
		org.onap.aai.domain.yang.ServiceInstance ANNFServiceInstance = new org.onap.aai.domain.yang.ServiceInstance();
		//AN instance creation
		ANServiceInstance.setServiceInstanceId(execution.getVariable("RANServiceInstanceId"))
		String sliceInstanceName = execution.getVariable("servicename")
		ANServiceInstance.setServiceInstanceName(sliceInstanceName)
		String serviceType = jsonUtil.getJsonValue(execution.getVariable("sliceProfile"), "sST")
                ANServiceInstance.setServiceType(execution.getVariable("sst"))
		String serviceStatus = "deactivated"
		ANServiceInstance.setOrchestrationStatus(serviceStatus)
		String serviceInstanceLocationid = jsonUtil.getJsonValue(execution.getVariable("sliceProfile"), "pLMNIdList")
		ANServiceInstance.setServiceInstanceLocationId(serviceInstanceLocationid)
		String serviceRole = "nssi"
		ANServiceInstance.setServiceRole(serviceRole)
		List<String> snssaiList = execution.getVariable("snssaiList")
		String snssai = snssaiList.get(0)
		//ANServiceInstance.setEnvironmentContext(snssai)
                ANServiceInstance.setEnvironmentContext(execution.getVariable("networkType"))
                String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
                String modelUuid = execution.getVariable("modelUuid")
                ANServiceInstance.setModelInvariantId(modelInvariantUuid)
                ANServiceInstance.setModelVersionId(modelUuid)
		ANServiceInstance.setWorkloadContext("AN")
		String serviceFunctionAn = jsonUtil.getJsonValue(execution.getVariable("sliceProfile"), "resourceSharingLevel")
		ANServiceInstance.setServiceFunction(serviceFunctionAn)
		logger.debug("completed AN service instance build "+ ANServiceInstance.toString())
		//create RAN NF NSSI
		ANNFServiceInstance.setServiceInstanceId(execution.getVariable("RANNFServiceInstanceId"))
		sliceInstanceName = "nssi_"+execution.getVariable("ANNF_modelName")
		ANNFServiceInstance.setServiceInstanceName(sliceInstanceName)
		ANNFServiceInstance.setServiceType(execution.getVariable("sst"))
		ANNFServiceInstance.setOrchestrationStatus(serviceStatus)
		serviceInstanceLocationid = jsonUtil.getJsonValue(execution.getVariable("ranNfSliceProfile"), "pLMNIdList")
                ANNFServiceInstance.setServiceInstanceLocationId(jsonUtil.StringArrayToList(serviceInstanceLocationid).get(0))
		ANNFServiceInstance.setServiceRole(serviceRole)
		snssaiList = execution.getVariable("snssaiList")
		snssai = snssaiList.get(0)
		//ANNFServiceInstance.setEnvironmentContext(snssai)
                ANNFServiceInstance.setEnvironmentContext(execution.getVariable("networkType"))
                ANNFServiceInstance.setModelInvariantId(execution.getVariable("ANNF_modelInvariantUuid"))
                ANNFServiceInstance.setModelVersionId(execution.getVariable("ANNF_modelUuid"))
		ANNFServiceInstance.setWorkloadContext("AN_NF")
		String serviceFunctionAnnf = jsonUtil.getJsonValue(execution.getVariable("ranNfSliceProfile"), "resourceSharingLevel")
		ANNFServiceInstance.setServiceFunction(serviceFunctionAnnf)
		logger.debug("completed AN service instance build "+ ANNFServiceInstance.toString())
		
		String msg = ""
		try {
	
			AAIResourcesClient client = new AAIResourcesClient()
			AAIResourceUri nssiServiceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(execution.getVariable("RANServiceInstanceId")))
			client.create(nssiServiceUri, ANServiceInstance)
	
			AAIResourceUri nssiServiceUri1 = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(execution.getVariable("RANNFServiceInstanceId")))
			client.create(nssiServiceUri1, ANNFServiceInstance)
	
		} catch (BpmnError e) {
			throw e
		} catch (Exception ex) {
			msg = "Exception in AnNssmfUtils.createSliceProfilesInAai " + ex.getMessage()
			logger.info(msg)
			exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
		}
		//end point update
		createEndPointsInAai(execution)
	}
	def prepareTnFhRequest = { DelegateExecution execution ->
		logger.debug(Prefix+"prepareTnFhRequest method start")

		String nssmfRequest = anNssmfUtils.buildCreateNSSMFRequest(execution, "TN_FH", "allocate")
		String urlString = "/api/rest/provMns/v1/NSS/SliceProfiles"
		String nssmfResponse = nssmfAdapterUtils.sendPostRequestNSSMF(execution, urlString, nssmfRequest)

		if (nssmfResponse != null) {
			execution.setVariable("nssmfResponse", nssmfResponse)
			String jobId = jsonUtil.getJsonValue(nssmfResponse, "jobId")
			execution.setVariable("TNFH_jobId",jobId)
		} else {
			logger.error("received error message from NSSMF : "+ nssmfResponse)
			exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"Received a Bad Sync Response from NSSMF.")
		}
		logger.debug("Exit prepareTnFhRequest")

	}
	def prepareTnMhRequest = { DelegateExecution execution ->
		logger.debug(Prefix+"prepareTnMhRequest method start")

		String nssmfRequest = anNssmfUtils.buildCreateNSSMFRequest(execution, "TN_MH", "allocate")
		String urlString = "/api/rest/provMns/v1/NSS/SliceProfiles"
		String nssmfResponse = nssmfAdapterUtils.sendPostRequestNSSMF(execution, urlString, nssmfRequest)

		if (nssmfResponse != null) {
			execution.setVariable("nssmfResponse", nssmfResponse)
			String jobId = jsonUtil.getJsonValue(nssmfResponse, "jobId")
			execution.setVariable("TNMH_jobId",jobId)
		} else {
			logger.error("received error message from NSSMF : "+ nssmfResponse)
			exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"Received a Bad Sync Response from NSSMF.")
		}
		logger.debug("Exit prepareTnMhRequest")
	}
	
	def createFhAllocateNssiJobQuery = { DelegateExecution execution ->
		logger.debug(Prefix+"createFhAllocateNssiJobQuery method start")
		createTnAllocateNssiJobQuery(execution, "TN_FH")		
	}
	
	def createMhAllocateNssiJobQuery = { DelegateExecution execution ->
		logger.debug(Prefix+"createMhAllocateNssiJobQuery method start")
		createTnAllocateNssiJobQuery(execution, "TN_MH")
	}
	
	private void createTnAllocateNssiJobQuery(DelegateExecution execution, String domainType) {
		JsonObject esrInfo = new JsonObject()
	    esrInfo.addProperty("networkType", "tn")
	    esrInfo.addProperty("vendor", "ONAP_internal")
		execution.setVariable("esrInfo", esrInfo.toString())
		JsonObject serviceInfo = new JsonObject()
		serviceInfo.addProperty("nsiId", execution.getVariable("nsiId"))
                serviceInfo.addProperty("sST", execution.getVariable("sst"))
		serviceInfo.addProperty("PLMNIdList", objectMapper.writeValueAsString(execution.getVariable("pLMNIdList")))
		serviceInfo.addProperty("globalSubscriberId", execution.getVariable("globalSubscriberId"))
		serviceInfo.addProperty("subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
		if(domainType.equals("TN_FH")) {
			serviceInfo.addProperty("nssiName", execution.getVariable("TNFH_modelName"))
			serviceInfo.addProperty("serviceInvariantUuid", execution.getVariable("TNFH_modelInvariantUuid"))
			serviceInfo.addProperty("serviceUuid", execution.getVariable("TNFH_modelUuid"))
		}else if(domainType.equals("TN_MH")) {
			serviceInfo.addProperty("nssiName", execution.getVariable("TNMH_modelName"))
			serviceInfo.addProperty("serviceInvariantUuid", execution.getVariable("TNMH_modelInvariantUuid"))
			serviceInfo.addProperty("serviceUuid", execution.getVariable("TNMH_modelUuid"))
		}
		execution.setVariable("serviceInfo", serviceInfo.toString())
		execution.setVariable("responseId", "")
	}
	
	def processFhAllocateNssiJobStatusRsp = { DelegateExecution execution ->
		logger.debug(Prefix+"processJobStatusRsp method start")
		String jobResponse = execution.getVariable("TNFH_jobResponse")
		logger.debug("Job status response "+jobResponse)
		String status = jsonUtil.getJsonValue(jobResponse, "status")
		String nssi = jsonUtil.getJsonValue(jobResponse, "nssiId")
		if(status.equalsIgnoreCase("finished")) {
			execution.setVariable("TNFH_NSSI", nssi)
			logger.debug("Job successfully completed ... proceeding with flow for nssi : "+nssi)
		}
		else {
			String statusDescription = jsonUtil.getJsonValue(jobResponse, "statusDescription")
			logger.error("received failed status from job status query for nssi : "+nssi+" with status description : "+ statusDescription)
			exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"received failed status from job status query for nssi : "+nssi+" with status description : "+ statusDescription)
		}
	}
	
	def processMhAllocateNssiJobStatusRsp = { DelegateExecution execution ->
		logger.debug(Prefix+"processJobStatusRsp method start")
		String jobResponse = execution.getVariable("TNMH_jobResponse")
		logger.debug("Job status response "+jobResponse)
		String status = jsonUtil.getJsonValue(jobResponse, "status")
		String nssi = jsonUtil.getJsonValue(jobResponse, "nssiId")
		if(status.equalsIgnoreCase("finished")) {
			execution.setVariable("TNMH_NSSI", nssi)
			logger.debug("Job successfully completed ... proceeding with flow for nssi : "+nssi)
		}
		else {
			String statusDescription = jsonUtil.getJsonValue(jobResponse, "statusDescription")
			logger.error("received failed status from job status query for nssi : "+nssi+" with status description : "+ statusDescription)
			exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"received failed status from job status query for nssi : "+nssi+" with status description : "+ statusDescription)
		}
	}
	
	def processModifyJobStatusRsp = { DelegateExecution execution ->
		logger.debug(Prefix+"processJobStatusRsp method start")
		String jobResponse = execution.getVariable("jobResponse")
		logger.debug("Job status response "+jobResponse)
		String status = jsonUtil.getJsonValue(jobResponse, "status")
		String nssi = jsonUtil.getJsonValue(jobResponse, "nssiId")
		if(status.equalsIgnoreCase("finished")) {
			logger.debug("Job successfully completed ... proceeding with flow for nssi : "+nssi)
		}
		else {
			String statusDescription = jsonUtil.getJsonValue(jobResponse, "statusDescription")
			logger.error("received failed status from job status query for nssi : "+nssi+" with status description : "+ statusDescription)
			exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"received failed status from job status query for nssi : "+nssi+" with status description : "+ statusDescription)
		}
	}

	def updateAairelationships = { DelegateExecution execution ->
		logger.debug(Prefix + "updateAairelationships Start")
		String msg = ""
		try {
			def ANNF_serviceInstanceId = execution.getVariable("RANNFServiceInstanceId")
			def TNFH_serviceInstanceId = execution.getVariable("TNFH_NSSI")
			def TNMH_serviceInstanceId = execution.getVariable("TNMH_NSSI")
			def AN_profileInstanceId = execution.getVariable("sliceProfileId")
			def AN_NSSI = execution.getVariable("RANServiceInstanceId")
			def ANNF_profileInstanceId = execution.getVariable("ANNF_sliceProfileInstanceId")
			def TNFH_profileInstanceId = execution.getVariable("TNFH_sliceProfileInstanceId")
			def TNMH_profileInstanceId = execution.getVariable("TNMH_sliceProfileInstanceId")
			String globalSubscriberId = execution.getVariable("globalSubscriberId")
			String subscriptionServiceType = execution.getVariable("subscriptionServiceType")

			Relationship ANNF_relationship = new Relationship()
			Relationship TNFH_relationship = new Relationship()
			Relationship TNMH_relationship = new Relationship()
			
			String ANNF_relatedLink = "aai/v21/business/customers/customer/${globalSubscriberId}/service-subscriptions/service-subscription/${subscriptionServiceType}/service-instances/service-instance/${ANNF_profileInstanceId}"
			String TNFH_relatedLink = "aai/v21/business/customers/customer/${globalSubscriberId}/service-subscriptions/service-subscription/${subscriptionServiceType}/service-instances/service-instance/${TNFH_profileInstanceId}"
			String TNMH_relatedLink = "aai/v21/business/customers/customer/${globalSubscriberId}/service-subscriptions/service-subscription/${subscriptionServiceType}/service-instances/service-instance/${TNMH_profileInstanceId}"
			
			String ANNF_NSSI_relatedLink = "aai/v21/business/customers/customer/${globalSubscriberId}/service-subscriptions/service-subscription/${subscriptionServiceType}/service-instances/service-instance/${ANNF_serviceInstanceId}"
			String TNFH_NSSI_relatedLink = "aai/v21/business/customers/customer/${globalSubscriberId}/service-subscriptions/service-subscription/${subscriptionServiceType}/service-instances/service-instance/${TNFH_serviceInstanceId}"
			String TNMH_NSSI_relatedLink = "aai/v21/business/customers/customer/${globalSubscriberId}/service-subscriptions/service-subscription/${subscriptionServiceType}/service-instances/service-instance/${TNMH_serviceInstanceId}"
			
			ANNF_relationship.setRelatedLink(ANNF_relatedLink)
			ANNF_relationship.setRelatedTo("service-instance")
			ANNF_relationship.setRelationshipLabel("org.onap.relationships.inventory.ComposedOf")
			TNFH_relationship.setRelatedLink(TNFH_relatedLink)
			TNFH_relationship.setRelatedTo("service-instance")
			TNFH_relationship.setRelationshipLabel("org.onap.relationships.inventory.ComposedOf")
			TNMH_relationship.setRelatedLink(TNMH_relatedLink)
			TNMH_relationship.setRelatedTo("service-instance")
			TNMH_relationship.setRelationshipLabel("org.onap.relationships.inventory.ComposedOf")
			
			// create SliceProfile and NSSI relationship in AAI
			anNssmfUtils.createRelationShipInAAI(execution, ANNF_relationship,ANNF_serviceInstanceId)
			anNssmfUtils.createRelationShipInAAI(execution, TNFH_relationship,TNFH_serviceInstanceId)
			anNssmfUtils.createRelationShipInAAI(execution, TNMH_relationship,TNMH_serviceInstanceId)
			anNssmfUtils.createRelationShipInAAI(execution, ANNF_relationship,AN_profileInstanceId)
			anNssmfUtils.createRelationShipInAAI(execution, TNFH_relationship,AN_profileInstanceId)
			anNssmfUtils.createRelationShipInAAI(execution, TNMH_relationship,AN_profileInstanceId)
			
			//create AN NSSI and ANNF,TNFH,TNMH relationship in AAI
			ANNF_relationship.setRelatedLink(ANNF_NSSI_relatedLink)
			TNFH_relationship.setRelatedLink(TNFH_NSSI_relatedLink)
			TNMH_relationship.setRelatedLink(TNMH_NSSI_relatedLink)
			anNssmfUtils.createRelationShipInAAI(execution, ANNF_relationship,AN_NSSI)
			anNssmfUtils.createRelationShipInAAI(execution, TNFH_relationship,AN_NSSI)
			anNssmfUtils.createRelationShipInAAI(execution, TNMH_relationship,AN_NSSI)

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

			msg = "Exception in DoCreateE2EServiceInstance.createCustomRelationship. " + ex.getMessage()
			logger.info(msg)
			exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
		}
	}
	
	/**
	 * update operation status in request db
	 *
	 */
	def prepareOperationStatusUpdate = { DelegateExecution execution ->
		logger.debug(Prefix + "prepareOperationStatusUpdate Start")

		String jobId = execution.getVariable("jobId")
		String nsiId = execution.getVariable("nsiId")
		String modelUuid = execution.getVariable("modelUuid")
		String nssiId = execution.getVariable("RANServiceInstanceId")
		logger.debug("Service Instance serviceId:" + nsiId + " jobId:" + jobId)

		ResourceOperationStatus updateStatus = new ResourceOperationStatus()
		updateStatus.setServiceId(nsiId)
		updateStatus.setOperationId(jobId)
		updateStatus.setResourceTemplateUUID(modelUuid)
		updateStatus.setResourceInstanceID(nssiId)
		updateStatus.setOperType("Allocate")
		updateStatus.setProgress("100")
		updateStatus.setStatus("finished")
		requestDBUtil.prepareUpdateResourceOperationStatus(execution, updateStatus)

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

	def prepareFailedOperationStatusUpdate = { DelegateExecution execution ->
		logger.debug(Prefix + "prepareFailedOperationStatusUpdate Start")
		
		String jobId = execution.getVariable("jobId")
		String nsiId = execution.getVariable("nsiId")
		String modelUuid = execution.getVariable("modelUuid")
		String nssiId = execution.getVariable("RANServiceInstanceId")
		logger.debug("Service Instance serviceId:" + nsiId + " jobId:" + jobId)

		ResourceOperationStatus updateStatus = new ResourceOperationStatus()
		updateStatus.setServiceId(nsiId)
		updateStatus.setOperationId(jobId)
		updateStatus.setResourceTemplateUUID(modelUuid)
		updateStatus.setResourceInstanceID(nssiId)
		updateStatus.setOperType("Allocate")
		updateStatus.setProgress("0")
		updateStatus.setStatus("failed")
		requestDBUtil.prepareUpdateResourceOperationStatus(execution, updateStatus)
	}
	
	private String buildSdnrAllocateRequest(DelegateExecution execution, String action, String rpcName, String callbackUrl) {
		
		String requestId = execution.getVariable("msoRequestId")
		Map<String,Object> sliceProfile = objectMapper.readValue(execution.getVariable("ranNfSliceProfile"), Map.class)
		sliceProfile.put("sliceProfileId", execution.getVariable("ANNF_sliceProfileInstanceId"))
		sliceProfile.put("maxNumberofConns", sliceProfile.get("maxNumberofPDUSession"))
		sliceProfile.put("uLThptPerSlice", sliceProfile.get("expDataRateUL"))
		sliceProfile.put("dLThptPerSlice", sliceProfile.get("expDataRateDL"))

		JsonObject response = new JsonObject()
		JsonObject body = new JsonObject()
		JsonObject input = new JsonObject()
		JsonObject commonHeader = new JsonObject()
		JsonObject payload = new JsonObject()
		JsonObject payloadInput = new JsonObject()
		commonHeader.addProperty("timestamp",new Date(System.currentTimeMillis()).format("yyyy-MM-dd'T'HH:mm:ss.sss'Z'", TimeZone.getDefault()))
		commonHeader.addProperty("api-ver", "1.0")
                commonHeader.addProperty("originator-id", "testing")
		commonHeader.addProperty("request-id", requestId)
		commonHeader.addProperty("sub-request-id", "1")
		commonHeader.add("flags", new JsonObject())
	        Gson jsonConverter = new Gson() 
         	payloadInput.add("sliceProfile", jsonConverter.toJsonTree(sliceProfile))
		payloadInput.addProperty("RANNSSIId", execution.getVariable("RANServiceInstanceId"))
		payloadInput.addProperty("NSIID", execution.getVariable("nsiId"))
		payloadInput.addProperty("RANNFNSSIId", execution.getVariable("RANNFServiceInstanceId"))
		payloadInput.addProperty("callbackURL", callbackUrl)
                payloadInput.addProperty("globalSubscriberId", execution.getVariable("globalSubscriberId"))
		payloadInput.addProperty("subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
		payloadInput.add("additionalproperties", new JsonObject())
		payload.add("input", payloadInput)
		input.add("common-header", commonHeader)
		input.addProperty("action", action)
		input.addProperty("payload", payload.toString())
		body.add("input", input)
		response.add("body", body)
		response.addProperty("version", "1.0")
		response.addProperty("rpc-name", rpcName)
		response.addProperty("correlation-id", (requestId+"-1"))
		response.addProperty("type", "request")
		return response.toString()
	}
	
	private void createEndPointsInAai(DelegateExecution execution) {
		String type = "endpoint"
		String function = "transport_EP"
		int prefixLength = 24
		String addressFamily = "ipv4"
		//BH RAN end point update
		String bh_endpoint = execution.getVariable("bh_endpoint")
		String bh_routeId = UUID.randomUUID().toString()
		execution.setVariable("tranportEp_ID_bh", bh_routeId)
		String role = "CU"
                String CU_IpAddress = jsonUtil.getJsonValue(bh_endpoint, "ipAddress")
                String LogicalLinkId = jsonUtil.getJsonValue(bh_endpoint, "logicInterfaceId")
		String nextHopInfo = jsonUtil.getJsonValue(bh_endpoint, "nextHopInfo")
		NetworkRoute bh_ep = new NetworkRoute()
		bh_ep.setRouteId(bh_routeId)
		bh_ep.setFunction(function)
		bh_ep.setRole(role)
		bh_ep.setType(type)
		bh_ep.setIpAddress(CU_IpAddress)
		bh_ep.setLogicalInterfaceId(LogicalLinkId)
		bh_ep.setNextHop(nextHopInfo)
		bh_ep.setPrefixLength(prefixLength)
		bh_ep.setAddressFamily(addressFamily)
		//FH RAN end points update
		//RU
		String RU_routeId = UUID.randomUUID().toString()
		execution.setVariable("tranportEp_ID_RU", RU_routeId)
		role = "RU"
		NetworkRoute RU_ep = new NetworkRoute()
		RU_ep.setRouteId(RU_routeId)
		RU_ep.setFunction(function)
		RU_ep.setRole(role)
		RU_ep.setType(type)
		RU_ep.setIpAddress("192.168.100.4")
		RU_ep.setLogicalInterfaceId("1234")
		RU_ep.setNextHop("Host1")
		RU_ep.setPrefixLength(prefixLength)
		RU_ep.setAddressFamily(addressFamily)
		//DU Ingress
		String DUIN_routeId = UUID.randomUUID().toString()
		execution.setVariable("tranportEp_ID_DUIN", DUIN_routeId)
		role = "DU"
		NetworkRoute DU_ep = new NetworkRoute()
		DU_ep.setRouteId(DUIN_routeId)
		DU_ep.setFunction(function)
		DU_ep.setRole(role)
		DU_ep.setType(type)
		DU_ep.setIpAddress("192.168.100.5")
		DU_ep.setLogicalInterfaceId("1234")
		DU_ep.setNextHop("Host2")
		DU_ep.setPrefixLength(prefixLength)
		DU_ep.setAddressFamily(addressFamily)
		//MH RAN end point update
		//DUEG
		String DUEG_routeId = UUID.randomUUID().toString()
		execution.setVariable("tranportEp_ID_DUEG", DUEG_routeId)
		NetworkRoute DUEG_ep = new NetworkRoute()
                DUEG_ep.setRouteId(DUEG_routeId)
                DUEG_ep.setFunction(function)
                DUEG_ep.setRole(role)
                DUEG_ep.setType(type)
                DUEG_ep.setIpAddress("192.168.100.5")
                DUEG_ep.setLogicalInterfaceId("1234")
                DUEG_ep.setPrefixLength(prefixLength)
                DUEG_ep.setAddressFamily(addressFamily)
		DUEG_ep.setNextHop("Host3")
		//CUIN
		String CUIN_routeId = UUID.randomUUID().toString()
		execution.setVariable("tranportEp_ID_CUIN", CUIN_routeId)
		NetworkRoute CUIN_ep = new NetworkRoute()
		CUIN_ep.setRouteId(CUIN_routeId)
		CUIN_ep.setFunction(function)
		CUIN_ep.setRole(role)
		CUIN_ep.setType(type)
		CUIN_ep.setIpAddress("192.168.100.6")
		CUIN_ep.setLogicalInterfaceId("1234")
		CUIN_ep.setNextHop("Host4")
		CUIN_ep.setPrefixLength(prefixLength)
		CUIN_ep.setAddressFamily(addressFamily)
		try {
			AAIResourcesClient client = new AAIResourcesClient()
			logger.debug("creating bh endpoint . ID : "+bh_routeId+" node details : "+bh_ep.toString())
			AAIResourceUri networkRouteUri = AAIUriFactory.createResourceUri( new AAIObjectType(AAINamespaceConstants.NETWORK, NetworkRoute.class), bh_routeId)
			client.create(networkRouteUri, bh_ep)
			logger.debug("creating RU endpoint . ID : "+RU_routeId+" node details : "+RU_ep.toString())
			networkRouteUri = AAIUriFactory.createResourceUri( new AAIObjectType(AAINamespaceConstants.NETWORK, NetworkRoute.class), RU_routeId)
			client.create(networkRouteUri, RU_ep)
			logger.debug("creating DUIN endpoint . ID : "+DUIN_routeId+" node details : "+DU_ep.toString())
			networkRouteUri = AAIUriFactory.createResourceUri( new AAIObjectType(AAINamespaceConstants.NETWORK, NetworkRoute.class), DUIN_routeId)
			client.create(networkRouteUri, DU_ep)
			logger.debug("creating DUEG endpoint . ID : "+DUEG_routeId+" node details : "+DUEG_ep.toString())
			networkRouteUri = AAIUriFactory.createResourceUri( new AAIObjectType(AAINamespaceConstants.NETWORK, NetworkRoute.class), DUEG_routeId)
			client.create(networkRouteUri, DUEG_ep)
			logger.debug("creating CUIN endpoint . ID : "+CUIN_routeId+" node details : "+CUIN_ep.toString())
			networkRouteUri = AAIUriFactory.createResourceUri( new AAIObjectType(AAINamespaceConstants.NETWORK, NetworkRoute.class), CUIN_routeId)
			client.create(networkRouteUri, CUIN_ep)
			//relationship b/w bh_ep and RAN NSSI
			def AN_NSSI = execution.getVariable("RANServiceInstanceId")
			Relationship relationship = new Relationship()
			String relatedLink = "aai/v21/network/network-routes/network-route/${bh_routeId}"		
			relationship.setRelatedLink(relatedLink)
			relationship.setRelatedTo("network-route")
			relationship.setRelationshipLabel("org.onap.relationships.inventory.ComposedOf")
			anNssmfUtils.createRelationShipInAAI(execution, relationship, AN_NSSI)
			def ANNF_serviceInstanceId = execution.getVariable("RANNFServiceInstanceId")
			relatedLink = "aai/v21/network/network-routes/network-route/${RU_routeId}"
			relationship.setRelatedLink(relatedLink)
			anNssmfUtils.createRelationShipInAAI(execution, relationship, ANNF_serviceInstanceId)
			relatedLink = "aai/v21/network/network-routes/network-route/${DUIN_routeId}"
			relationship.setRelatedLink(relatedLink)
			anNssmfUtils.createRelationShipInAAI(execution, relationship, ANNF_serviceInstanceId)
			relatedLink = "aai/v21/network/network-routes/network-route/${DUEG_routeId}"
			relationship.setRelatedLink(relatedLink)
			anNssmfUtils.createRelationShipInAAI(execution, relationship, ANNF_serviceInstanceId)
			relatedLink = "aai/v21/network/network-routes/network-route/${CUIN_routeId}"
			relationship.setRelatedLink(relatedLink)
			anNssmfUtils.createRelationShipInAAI(execution, relationship, ANNF_serviceInstanceId)
		} catch (BpmnError e) {
		throw e
	} catch (Exception ex) {
		String msg = "Exception in createEndPointsInAai " + ex.getMessage()
		logger.info(msg)
		exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
	}
	}
}