Merge "Implement subprocess for calling SDNR from RAN NSSMF -Also added common...
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / groovy / org / onap / so / bpmn / infrastructure / scripts / AnNssmfutils.groovy
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  # Copyright (c) 2020, Wipro Limited.
6  #
7  # Licensed under the Apache License, Version 2.0 (the "License")
8  # you may not use this file except in compliance with the License.
9  # You may obtain a copy of the License at
10  #
11  #       http://www.apache.org/licenses/LICENSE-2.0
12  #
13  # Unless required by applicable law or agreed to in writing, software
14  # distributed under the License is distributed on an "AS IS" BASIS,
15  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  # See the License for the specific language governing permissions and
17  # limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.scripts
22
23 import com.google.gson.JsonArray
24 import org.camunda.bpm.engine.delegate.BpmnError
25 import org.camunda.bpm.engine.delegate.DelegateExecution
26 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
27 import org.onap.so.bpmn.common.scripts.ExceptionUtil
28 import org.onap.so.bpmn.common.scripts.NssmfAdapterUtils
29 import org.onap.so.bpmn.common.scripts.OofUtils
30 import org.onap.so.bpmn.common.scripts.RequestDBUtil
31 import org.onap.so.bpmn.core.json.JsonUtils
32 import org.onap.so.db.request.beans.ResourceOperationStatus
33 import org.slf4j.Logger
34 import org.slf4j.LoggerFactory
35 import java.sql.Timestamp
36 import java.util.List
37 import static org.apache.commons.lang3.StringUtils.isBlank
38 import com.google.gson.JsonObject
39 import com.fasterxml.jackson.databind.ObjectMapper
40 import org.onap.aaiclient.client.aai.AAIObjectType
41 import org.onap.aaiclient.client.aai.AAIResourcesClient
42 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
43 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
44 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
45 import javax.ws.rs.NotFoundException
46 import org.onap.so.beans.nsmf.AllocateTnNssi
47 import org.onap.so.beans.nsmf.DeAllocateNssi
48 import org.onap.so.beans.nsmf.EsrInfo
49 import org.onap.so.beans.nsmf.ServiceInfo
50 import org.onap.so.bpmn.core.UrnPropertiesReader
51 import org.onap.aai.domain.yang.ServiceInstance
52 import org.onap.aai.domain.yang.SliceProfile
53 import org.onap.aai.domain.yang.SliceProfiles
54 import org.onap.aai.domain.yang.Relationship
55
56 class AnNssmfUtils {
57
58         private static final Logger logger = LoggerFactory.getLogger(AnNssmfUtils.class)
59         ObjectMapper objectMapper = new ObjectMapper();
60         ExceptionUtil exceptionUtil = new ExceptionUtil()
61         JsonUtils jsonUtil = new JsonUtils()
62         public String buildSelectRANNSSIRequest(String requestId, String messageType, String UUID,String invariantUUID,
63                 String name, Map<String, Object> profileInfo, List<String> nsstInfoList, JsonArray capabilitiesList, Boolean preferReuse){
64
65         def transactionId = requestId
66         logger.debug( "transactionId is: " + transactionId)
67         String correlator = requestId
68         String callbackUrl = UrnPropertiesReader.getVariable("mso.adapters.oof.callback.endpoint") + "/" + messageType + "/" + correlator
69         ObjectMapper objectMapper = new ObjectMapper();
70         String profileJson = objectMapper.writeValueAsString(profileInfo);
71         String nsstInfoListString = objectMapper.writeValueAsString(nsstInfoList);
72         //Prepare requestInfo object
73         JsonObject requestInfo = new JsonObject()
74         requestInfo.addProperty("transactionId", transactionId)
75         requestInfo.addProperty("requestId", requestId)
76         requestInfo.addProperty("callbackUrl", callbackUrl)
77         requestInfo.addProperty("sourceId","SO" )
78         requestInfo.addProperty("timeout", 600)
79         requestInfo.addProperty("numSolutions", 1)
80
81         //Prepare serviceInfo object
82         JsonObject ranNsstInfo = new JsonObject()
83         ranNsstInfo.addProperty("UUID", UUID)
84         ranNsstInfo.addProperty("invariantUUID", invariantUUID)
85         ranNsstInfo.addProperty("name", name)
86
87         JsonObject json = new JsonObject()
88         json.add("requestInfo", requestInfo)
89         json.add("NSTInfo", ranNsstInfo)
90         json.addProperty("serviceProfile", profileJson)
91         json.addProperty("NSSTInfo", nsstInfoListString)
92         json.add("subnetCapabilities", capabilitiesList)
93         json.addProperty("preferReuse", preferReuse)
94
95         return json.toString()
96 }
97
98 public String buildCreateTNNSSMFSubnetCapabilityRequest() {
99         EsrInfo esrInfo = new EsrInfo()
100         esrInfo.setNetworkType("TN")
101         esrInfo.setVendor("ONAP")
102
103         JsonArray subnetTypes = new JsonArray()
104         subnetTypes.add("TN_FH")
105         subnetTypes.add("TN_MH")
106         JsonObject response = new JsonObject()
107         response.add("subnetCapabilityQuery", subnetTypes)
108         response.addProperty("esrInfo", objectMapper.writeValueAsString(esrInfo))
109         return response.toString()
110 }
111
112 public String buildCreateANNFNSSMFSubnetCapabilityRequest() {
113         EsrInfo esrInfo = new EsrInfo()
114         esrInfo.setNetworkType("AN")
115         esrInfo.setVendor("ONAP")
116
117         JsonArray subnetTypes = new JsonArray()
118         subnetTypes.add("AN_NF")
119         JsonObject response = new JsonObject()
120         response.add("subnetCapabilityQuery", subnetTypes)
121         response.addProperty("esrInfo", objectMapper.writeValueAsString(esrInfo))
122         return response.toString()
123 }
124 public void createDomainWiseSliceProfiles(List<String> ranConstituentSliceProfiles, DelegateExecution execution) {
125         
126         for(String profile : ranConstituentSliceProfiles) {
127                 String domainType = jsonUtil.getJsonValue(profile, "domainType")
128                 switch(domainType) {
129                         case "AN_NF":
130                                 execution.setVariable("ranNfSliceProfile", profile)
131                                 break
132                         case "TN_FH":
133                                 execution.setVariable("tnFhSliceProfile", profile)
134                                 break
135                         case "TN_MH":
136                                 execution.setVariable("tnMhSliceProfile", profile)
137                                 break
138                         default:
139                                 logger.debug("No expected match found for current domainType")
140                                 logger.error("No expected match found for current domainType "+ domainType)
141                                 exceptionUtil.buildAndThrowWorkflowException(execution, 1000,"No expected match found for current domainType "+ domainType)
142                 }
143                 
144         }
145 }
146
147 public void createSliceProfilesInAai(DelegateExecution execution) {
148         
149         org.onap.aai.domain.yang.ServiceInstance ANNF_sliceProfileInstance = new ServiceInstance();
150         org.onap.aai.domain.yang.ServiceInstance TNFH_sliceProfileInstance = new ServiceInstance();
151         org.onap.aai.domain.yang.ServiceInstance TNMH_sliceProfileInstance = new ServiceInstance();
152         //generate slice profile ids and slice profile instance ids
153         String ANNF_sliceProfileInstanceId = UUID.randomUUID().toString()
154         String ANNF_sliceProfileId = UUID.randomUUID().toString()
155         String TNFH_sliceProfileInstanceId = UUID.randomUUID().toString()
156         String TNFH_sliceProfileId = UUID.randomUUID().toString()
157         String TNMH_sliceProfileInstanceId = UUID.randomUUID().toString()
158         String TNMH_sliceProfileId = UUID.randomUUID().toString()
159         execution.setVariable("ANNF_sliceProfileInstanceId",ANNF_sliceProfileInstanceId)
160         execution.setVariable("ANNF_sliceProfileId",ANNF_sliceProfileId)
161         execution.setVariable("TNFH_sliceProfileInstanceId",TNFH_sliceProfileInstanceId)
162         execution.setVariable("TNFH_sliceProfileId",TNFH_sliceProfileId)
163         execution.setVariable("TNMH_sliceProfileInstanceId",TNMH_sliceProfileInstanceId)
164         execution.setVariable("TNMH_sliceProfileId",TNMH_sliceProfileId)
165         //slice profiles assignment
166         org.onap.aai.domain.yang.SliceProfiles ANNF_SliceProfiles = new SliceProfiles()
167         org.onap.aai.domain.yang.SliceProfiles TNFH_SliceProfiles = new SliceProfiles()
168         org.onap.aai.domain.yang.SliceProfiles TNMH_SliceProfiles = new SliceProfiles()
169         org.onap.aai.domain.yang.SliceProfile ANNF_SliceProfile = new SliceProfile()
170         org.onap.aai.domain.yang.SliceProfile TNFH_SliceProfile = new SliceProfile()
171         org.onap.aai.domain.yang.SliceProfile TNMH_SliceProfile = new SliceProfile()
172         ANNF_SliceProfile = createSliceProfile("AN-NF", execution)
173         TNFH_SliceProfile = createSliceProfile("TN-FH",execution)
174         TNMH_SliceProfile = createSliceProfile("TN-MH",execution)
175         
176         ANNF_SliceProfiles.getSliceProfile().add(ANNF_SliceProfile)
177         TNFH_SliceProfiles.getSliceProfile().add(TNFH_SliceProfile)
178         TNMH_SliceProfiles.getSliceProfile().add(TNMH_SliceProfile)
179         
180         logger.debug("sliceProfiles : 1. "+ANNF_SliceProfiles.toString()+"\n 2. "+TNFH_SliceProfiles.toString()+"\n 3. "+TNMH_SliceProfiles.toString())
181         //ANNF slice profile instance creation
182         ANNF_sliceProfileInstance.setServiceInstanceId(ANNF_sliceProfileInstanceId)
183         String sliceInstanceName = "sliceprofile_"+ANNF_sliceProfileId
184         ANNF_sliceProfileInstance.setServiceInstanceName(sliceInstanceName)
185         String serviceType = jsonUtil.getJsonValue(execution.getVariable("ranNfSliceProfile"), "sST")
186         ANNF_sliceProfileInstance.setServiceType(serviceType)
187         String serviceStatus = "deactivated"
188         ANNF_sliceProfileInstance.setOrchestrationStatus(serviceStatus)
189         String serviceInstanceLocationid = jsonUtil.getJsonValue(execution.getVariable("ranNfSliceProfile"), "plmnIdList")
190         ANNF_sliceProfileInstance.setServiceInstanceLocationId(serviceInstanceLocationid)
191         String serviceRole = "slice-profile-instance"
192         ANNF_sliceProfileInstance.setServiceRole(serviceRole)
193         List<String> snssaiList = objectMapper.readValue(execution.getVariable("snssaiList"), List.class)
194         String snssai = snssaiList.get(0)
195         ANNF_sliceProfileInstance.setEnvironmentContext(snssai)
196         ANNF_sliceProfileInstance.setWorkloadContext("AN-NF")    
197         ANNF_sliceProfileInstance.setSliceProfiles(ANNF_SliceProfiles)
198         logger.debug("completed ANNF sliceprofileinstance build "+ ANNF_sliceProfileInstance.toString())
199         //TNFH slice profile instance creation
200         TNFH_sliceProfileInstance.setServiceInstanceId(TNFH_sliceProfileInstanceId)
201         sliceInstanceName = "sliceprofile_"+TNFH_sliceProfileId
202         TNFH_sliceProfileInstance.setServiceInstanceName(sliceInstanceName)
203         serviceType = jsonUtil.getJsonValue(execution.getVariable("tnFhSliceProfile"), "sST")
204         TNFH_sliceProfileInstance.setServiceType(serviceType)
205         TNFH_sliceProfileInstance.setOrchestrationStatus(serviceStatus)
206         serviceInstanceLocationid = jsonUtil.getJsonValue(execution.getVariable("tnFhSliceProfile"), "plmnIdList")
207         TNFH_sliceProfileInstance.setServiceInstanceLocationId(serviceInstanceLocationid)
208         TNFH_sliceProfileInstance.setServiceRole(serviceRole)
209         TNFH_sliceProfileInstance.setEnvironmentContext(snssai)
210         TNFH_sliceProfileInstance.setWorkloadContext("TN-FH")
211         TNFH_sliceProfileInstance.setSliceProfiles(TNFH_SliceProfiles)
212         logger.debug("completed TNFH sliceprofileinstance build "+TNFH_sliceProfileInstance)
213         //TNMH slice profile instance creation
214         TNMH_sliceProfileInstance.setServiceInstanceId(TNMH_sliceProfileInstanceId)
215         sliceInstanceName = "sliceprofile_"+TNMH_sliceProfileId
216         TNMH_sliceProfileInstance.setServiceInstanceName(sliceInstanceName)
217         serviceType = jsonUtil.getJsonValue(execution.getVariable("tnMhSliceProfile"), "sST")
218         TNMH_sliceProfileInstance.setServiceType(serviceType)
219         TNMH_sliceProfileInstance.setOrchestrationStatus(serviceStatus)
220         serviceInstanceLocationid = jsonUtil.getJsonValue(execution.getVariable("tnMhSliceProfile"), "plmnIdList")
221         TNMH_sliceProfileInstance.setServiceInstanceLocationId(serviceInstanceLocationid)
222         TNMH_sliceProfileInstance.setServiceRole(serviceRole)
223         TNMH_sliceProfileInstance.setEnvironmentContext(snssai)
224         TNMH_sliceProfileInstance.setWorkloadContext("TN-MH")
225         TNMH_sliceProfileInstance.setSliceProfiles(TNMH_SliceProfiles)
226         logger.debug("completed TNMH sliceprofileinstance build "+TNMH_sliceProfileInstance)
227         String msg = ""
228         try {
229
230                 AAIResourcesClient client = new AAIResourcesClient()
231                 AAIResourceUri sliceProfileUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, execution.getVariable("globalSubscriberId"), execution.getVariable("subscriptionServiceType"), ANNF_sliceProfileInstanceId)
232                 client.create(sliceProfileUri, ANNF_sliceProfileInstance)
233
234                 AAIResourceUri sliceProfileUri1 = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, execution.getVariable("globalSubscriberId"), execution.getVariable("subscriptionServiceType"), TNFH_sliceProfileInstanceId)
235                 client.create(sliceProfileUri1, TNFH_sliceProfileInstance)
236
237                 AAIResourceUri sliceProfileUri2 = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, execution.getVariable("globalSubscriberId"), execution.getVariable("subscriptionServiceType"), TNMH_sliceProfileInstanceId)
238                 client.create(sliceProfileUri2, TNMH_sliceProfileInstance)
239
240         } catch (BpmnError e) {
241                 throw e
242         } catch (Exception ex) {
243                 msg = "Exception in AnNssmfUtils.createSliceProfilesInAai " + ex.getMessage()
244                 logger.info(msg)
245                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
246         }
247
248 }
249 private SliceProfile createSliceProfile(String domainType, DelegateExecution execution) {
250
251         SliceProfile result = new SliceProfile()
252         Map<String,Object> profile
253         switch(domainType) {
254                 case "AN-NF":
255                         profile = objectMapper.readValue(execution.getVariable("ranNfSliceProfile"), Map.class)//pending fields - maxBandwidth, sST, pLMNIdList, cSReliabilityMeanTime, 
256                                                                                                                                                                                                         //msgSizeByte, maxNumberofPDUSessions,overallUserDensity,transferIntervalTarget
257                         result.setJitter(profile.get("jitter"))
258                         result.setLatency(profile.get("latency"))
259                         result.setResourceSharingLevel(profile.get("resourceSharingLevel"))
260                         result.setSNssai(profile.get("sNSSAI"))
261                         result.setUeMobilityLevel(profile.get("uEMobilityLevel"))
262                         result.setMaxNumberOfUEs(profile.get("maxNumberofUEs"))
263                         result.setActivityFactor(profile.get("activityFactor"))
264                         result.setCoverageAreaTAList(profile.get("coverageAreaTAList"))
265                         result.setCsAvailability(profile.get("cSAvailabilityTarget"))
266                         result.setExpDataRateDL(profile.get("expDataRateDL"))
267                         result.setExpDataRateUL(profile.get("expDataRateUL"))
268                         result.setSurvivalTime(profile.get("survivalTime"))
269                         result.setAreaTrafficCapDL(profile.get("areaTrafficCapDL"))
270                         result.setAreaTrafficCapUL(profile.get("areaTrafficCapUL"))
271                         result.setExpDataRate(profile.get("expDataRate"))
272                         result.setProfileId(execution.getVariable("ANNF_sliceProfileId"))
273                         break
274                 case "TN-FH":
275                         profile = objectMapper.readValue(execution.getVariable("tnFhSliceProfile"), Map.class) //pending fields - maxBandwidth, sST, pLMNIdList
276                         result.setJitter(profile.get("jitter"))
277                         result.setLatency(profile.get("latency"))
278                         result.setResourceSharingLevel(profile.get("resourceSharingLevel"))
279                         result.setSNssai(profile.get("sNSSAI"))
280                         result.setProfileId(execution.getVariable("TNFH_sliceProfileId"))
281                         break
282                 case "TN-MH":
283                         profile = objectMapper.readValue(execution.getVariable("tnMhSliceProfile"), Map.class)//pending fields - maxBandwidth, sST, pLMNIdList
284                         result.setJitter(profile.get("jitter"))
285                         result.setLatency(profile.get("latency"))
286                         result.setResourceSharingLevel(profile.get("resourceSharingLevel"))
287                         result.setSNssai(profile.get("sNSSAI"))
288                         result.setProfileId(execution.getVariable("TNMH_sliceProfileId"))
289                         break
290                 default:
291                         logger.debug("No expected match found for current domainType")
292                         logger.error("No expected match found for current domainType "+ domainType)
293                         exceptionUtil.buildAndThrowWorkflowException(execution, 1000,"No expected match found for current domainType "+ domainType)
294         }
295         return result
296 }
297
298  /**
299      * create relationship in AAI
300      */
301     public createRelationShipInAAI = { DelegateExecution execution, final Relationship relationship, String instanceId ->
302         logger.debug("createRelationShipInAAI Start")
303         String msg
304                 AAIResourcesClient client = new AAIResourcesClient()
305         try {
306             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
307                     execution.getVariable("globalSubscriberId"),
308                     execution.getVariable("subscriptionServiceType"),
309                     instanceId).relationshipAPI()
310             client.create(uri, relationship)
311
312         } catch (BpmnError e) {
313             throw e
314         } catch (Exception ex) {
315             msg = "Exception in CreateCommunicationService.createRelationShipInAAI. " + ex.getMessage()
316             logger.info(msg)
317             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
318         }
319         logger.debug("createRelationShipInAAI Exit")
320
321     }
322         
323         public void processRanNfModifyRsp(DelegateExecution execution) {
324                 String status = execution.getVariable("ranNfStatus")
325                 if(status.equals("success")) {
326                         logger.debug("completed Ran NF NSSI modification ... proceeding with the flow")
327                 }
328                 else {
329                         logger.error("failed to modify ran Nf nssi")
330                         exceptionUtil.buildAndThrowWorkflowException(execution, 1000, "modify ran nf nssi not successfull")
331                 }
332         }
333         
334         public String buildCreateNSSMFRequest(DelegateExecution execution, String domainType, String action) {
335                 EsrInfo esrInfo = new EsrInfo()
336                 esrInfo.setNetworkType("TN")
337                 esrInfo.setVendor("ONAP")
338                 String esrInfoString = objectMapper.writeValueAsString(esrInfo)
339                 JsonObject response = new JsonObject()
340                 JsonObject allocateTnNssi = new JsonObject()
341                 JsonObject serviceInfo = new JsonObject()
342                 JsonArray transportSliceNetworksList  = new JsonArray()
343                 JsonArray connectionLinksList = new JsonArray()
344                 JsonObject connectionLinks = new JsonObject()
345                 if(action.equals("allocate")){
346                         Map<String, String> endpoints
347                         if(domainType.equals("TN_FH")) {
348                                 serviceInfo.addProperty("serviceInvariantUuid", execution.getVariable("TNFH_modelInvariantUuid"))
349                                 serviceInfo.addProperty("serviceUuid", execution.getVariable("TNFH_modelUuid"))
350                                 allocateTnNssi.addProperty("nsstId", execution.getVariable("TNFH_modelUuid"))
351                                 allocateTnNssi.addProperty("nssiName", execution.getVariable("TNFH_modelName"))
352                                 Map<String,Object> sliceProfile = objectMapper.readValue(execution.getVariable("tnFhSliceProfile"), Map.class)
353                                 sliceProfile.put("sliceProfileId", execution.getVariable("TNFH_sliceProfileInstanceId"))
354                                 String sliceProfileString = objectMapper.writeValueAsString(sliceProfile)
355                                 allocateTnNssi.addProperty("sliceProfile", sliceProfileString)
356                                 endpoints.put("transportEndpointA", execution.getVariable("tranportEp_ID_RU"))
357                                 endpoints.put("transportEndpointB", execution.getVariable("tranportEp_ID_DUIN"))
358                                 String endpointsString = objectMapper.writeValueAsString(endpoints)
359                                 connectionLinksList.add(endpointsString)
360                         }else if(domainType.equals("TN_MH")) {
361                                 serviceInfo.addProperty("serviceInvariantUuid", execution.getVariable("TNMH_modelInvariantUuid"))
362                                 serviceInfo.addProperty("serviceUuid", execution.getVariable("TNMH_modelUuid"))
363                                 allocateTnNssi.addProperty("nsstId", execution.getVariable("TNMH_modelUuid"))
364                                 allocateTnNssi.addProperty("nssiName", execution.getVariable("TNMH_modelName"))
365                                 Map<String,Object> sliceProfile = objectMapper.readValue(execution.getVariable("tnMhSliceProfile"), Map.class)
366                                 sliceProfile.put("sliceProfileId", execution.getVariable("TNMH_sliceProfileInstanceId"))
367                                 String sliceProfileString = objectMapper.writeValueAsString(sliceProfile)
368                                 allocateTnNssi.addProperty("sliceProfile", sliceProfileString)
369                                 endpoints.put("transportEndpointA", execution.getVariable("tranportEp_ID_DUEG"))
370                                 endpoints.put("transportEndpointB", execution.getVariable("tranportEp_ID_CUIN"))
371                                 String endpointsString = objectMapper.writeValueAsString(endpoints)
372                                 connectionLinksList.add(endpointsString)
373                         }
374                         
375                         //Connection links
376                         connectionLinks.add("connectionLinks", connectionLinksList)
377                         transportSliceNetworksList.add(connectionLinks)
378                         allocateTnNssi.add("transportSliceNetworks", transportSliceNetworksList)
379                         allocateTnNssi.addProperty("nssiId", null)
380                         serviceInfo.addProperty("nssiId", null)
381                 }else if(action.equals("modify-allocate")) {
382                         if(domainType.equals("TN_FH")) {
383                                 serviceInfo.addProperty("serviceInvariantUuid", null)
384                                 serviceInfo.addProperty("serviceUuid", null)
385                                 allocateTnNssi.addProperty("nsstId", null)
386                                 allocateTnNssi.addProperty("nssiName", execution.getVariable("TNFH_nssiName"))
387                                 allocateTnNssi.addProperty("sliceProfileId", execution.getVariable("TNFH_sliceProfileInstanceId"))
388                                 allocateTnNssi.addProperty("nssiId", execution.getVariable("TNFH_NSSI"))
389                                 serviceInfo.addProperty("nssiId", execution.getVariable("TNFH_NSSI"))
390                         }else if(domainType.equals("TN_MH")) {
391                                 serviceInfo.addProperty("serviceInvariantUuid", null)
392                                 serviceInfo.addProperty("serviceUuid", null)
393                                 allocateTnNssi.addProperty("nsstId", null)
394                                 allocateTnNssi.addProperty("nssiName", execution.getVariable("TNMH_nssiName"))
395                                 allocateTnNssi.addProperty("sliceProfileId", execution.getVariable("TNMH_sliceProfileInstanceId"))
396                                 allocateTnNssi.addProperty("nssiId", execution.getVariable("TNMH_NSSI"))
397                                 serviceInfo.addProperty("nssiId", execution.getVariable("TNMH_NSSI"))
398                         }
399                 }
400                 String nsiInfo = jsonUtil.getJsonValue(execution.getVariable("sliceParams"), "nsiInfo")
401                 allocateTnNssi.addProperty("nsiInfo", nsiInfo)
402                 allocateTnNssi.addProperty("scriptName", "TN1")
403                 serviceInfo.addProperty("nsiId", execution.getVariable("nsiId"))
404                 serviceInfo.addProperty("globalSubscriberId", execution.getVariable("globalSubscriberId"))
405                 serviceInfo.addProperty("subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
406                 response.addProperty("esrInfo", esrInfoString)
407                 response.add("serviceInfo", serviceInfo)
408                 response.add("allocateTnNssi", allocateTnNssi)
409                 return response.toString()
410         }
411         
412         public String buildDeallocateNssiRequest(DelegateExecution execution,String domainType) {
413                 String globalSubscriberId = execution.getVariable("globalSubscriberId")
414                 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
415            
416                 JsonObject deAllocateNssi = new JsonObject()
417                 deAllocateNssi.addProperty("snssaiList", execution.getVariable("snssaiList"))
418                 deAllocateNssi.addProperty("nsiId", execution.getVariable("nsiId"))
419                 deAllocateNssi.addProperty("modifyAction", true)
420                 deAllocateNssi.addProperty("terminateNssiOption", 0)
421                 deAllocateNssi.addProperty("scriptName", "TN1")
422                 
423                 if(domainType.equals("TN_FH")) {
424                         deAllocateNssi.addProperty("nssiId", execution.getVariable("TNFH_NSSI"))
425                         deAllocateNssi.addProperty("sliceProfileId", execution.getVariable("TNFH_sliceProfileInstanceId"))
426                 }else if(domainType.equals("TN_MH")) {
427                         deAllocateNssi.addProperty("nssiId", execution.getVariable("TNMH_NSSI"))
428                         deAllocateNssi.addProperty("sliceProfileId", execution.getVariable("TNMH_sliceProfileInstanceId"))
429                 }
430                 
431                 EsrInfo esrInfo = new EsrInfo()
432                 esrInfo.setVendor("ONAP")
433                 esrInfo.setNetworkType("TN")
434            
435                 JsonObject serviceInfo = new JsonObject()
436                 serviceInfo.addProperty("serviceInvariantUuid", null)
437                 serviceInfo.addProperty("serviceUuid", null)
438                 serviceInfo.addProperty("globalSubscriberId", globalSubscriberId)
439                 serviceInfo.addProperty("subscriptionServiceType", subscriptionServiceType)
440            
441                 JsonObject json = new JsonObject()
442                 json.add("deAllocateNssi", deAllocateNssi)
443                 json.addProperty("esrInfo", objectMapper.writeValueAsString(esrInfo))
444                 json.add("serviceInfo", serviceInfo)
445                 return json.toString()
446            
447         }
448 }