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