07a23481d7180c0abea80c7932bcf97df3e7fb98
[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 import com.google.gson.Gson
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(jsonUtil.StringArrayToList(serviceInstanceLocationid).get(0))
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(jsonUtil.StringArrayToList(serviceInstanceLocationid).get(0))
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(jsonUtil.StringArrayToList(serviceInstanceLocationid).get(0))
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 - cSReliabilityMeanTime, cSAvailabilityTarget, terminalDensity, msgSizeByte
272                         result.setJitter(profile.get("jitter"))
273                         result.setLatency(profile.get("latency"))
274                         result.setMaxBandwidth(profile.get("maxbandwidth"))
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").toString())
280                         result.setExpDataRateDL(profile.get("expDataRateDL"))
281                         result.setExpDataRateUL(profile.get("expDataRateUL"))
282                         result.setSurvivalTime(profile.get("survivalTime"))
283                         result.setMaxNumberOfPDUSession(profile.get("maxNumberOfPDUSession")) 
284                         result.setAreaTrafficCapDL(profile.get("areaTrafficCapDL"))
285                         result.setAreaTrafficCapUL(profile.get("areaTrafficCapUL"))
286                         result.setOverallUserDensity(profile.get("overallUserDensity")) 
287                         result.setTransferIntervalTarget(profile.get("transferIntervalTarget"))
288                         result.setExpDataRate(profile.get("expDataRate"))
289                         result.setProfileId(execution.getVariable("ANNF_sliceProfileId"))
290                         break
291                 case "TN_FH":
292                         profile = objectMapper.readValue(execution.getVariable("tnFhSliceProfile"), Map.class) 
293                         result.setJitter(profile.get("jitter"))
294                         result.setLatency(profile.get("latency"))
295                         result.setMaxBandwidth(profile.get("maxbandwidth"))
296                         result.setResourceSharingLevel(profile.get("resourceSharingLevel"))
297                         result.setProfileId(execution.getVariable("TNFH_sliceProfileId"))
298                         break
299                 case "TN_MH":
300                         profile = objectMapper.readValue(execution.getVariable("tnMhSliceProfile"), Map.class)
301                         result.setJitter(profile.get("jitter"))
302                         result.setLatency(profile.get("latency"))
303                         result.setMaxBandwidth(profile.get("maxbandwidth"))
304                         result.setResourceSharingLevel(profile.get("resourceSharingLevel"))
305                         result.setProfileId(execution.getVariable("TNMH_sliceProfileId"))
306                         break
307                 default:
308                         logger.debug("No expected match found for current domainType")
309                         logger.error("No expected match found for current domainType "+ domainType)
310                         exceptionUtil.buildAndThrowWorkflowException(execution, 1000,"No expected match found for current domainType "+ domainType)
311         }
312         return result
313 }
314
315  /**
316      * create relationship in AAI
317      */
318     public createRelationShipInAAI = { DelegateExecution execution, final Relationship relationship, String instanceId ->
319         logger.debug("createRelationShipInAAI Start")
320         String msg
321                 AAIResourcesClient client = new AAIResourcesClient()
322         try {
323             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(instanceId)).relationshipAPI()
324             client.create(uri, relationship)
325
326         } catch (BpmnError e) {
327             throw e
328         } catch (Exception ex) {
329             msg = "Exception in AN NSSMF Utils : CreateRelationShipInAAI. " + ex.getMessage()
330             logger.info(msg)
331             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
332         }
333         logger.debug("createRelationShipInAAI Exit")
334
335     }
336         
337         public void processRanNfModifyRsp(DelegateExecution execution) {
338                 String status = execution.getVariable("ranNfStatus")
339                 if(status.equals("success")) {
340                         logger.debug("completed Ran NF NSSI modification ... proceeding with the flow")
341                 }
342                 else {
343                         logger.error("failed to modify ran Nf nssi")
344                         exceptionUtil.buildAndThrowWorkflowException(execution, 1000, "modify ran nf nssi not successfull")
345                 }
346         }
347         
348         public String buildCreateNSSMFRequest(DelegateExecution execution, String domainType, String action) {
349                 JsonObject esrInfo = new JsonObject()
350                 esrInfo.addProperty("networkType", "tn")
351                 esrInfo.addProperty("vendor", "ONAP_internal")
352                 JsonObject response = new JsonObject()
353                 JsonObject allocateTnNssi = new JsonObject()
354                 JsonObject serviceInfo = new JsonObject()
355                 JsonArray transportSliceNetworksList  = new JsonArray()
356                 JsonArray connectionLinksList = new JsonArray()
357                 JsonObject connectionLinks = new JsonObject()
358                 Gson jsonConverter = new Gson()
359                 String TNFH_nssiInstanceId = UUID.randomUUID().toString()
360                 String TNMH_nssiInstanceId = UUID.randomUUID().toString()
361
362                 if(action.equals("allocate")){
363                         JsonObject endpoints = new JsonObject()
364                         if(domainType.equals("TN_FH")) {
365                                 serviceInfo.addProperty("serviceInvariantUuid", execution.getVariable("TNFH_modelInvariantUuid"))
366                                 serviceInfo.addProperty("serviceUuid", execution.getVariable("TNFH_modelUuid"))
367                                 serviceInfo.addProperty("nssiName", "nssi_tn_fh_"+TNFH_nssiInstanceId)
368                                 serviceInfo.addProperty("sst",  execution.getVariable("sst"))
369                                 allocateTnNssi.addProperty("nsstId", execution.getVariable("TNFH_modelUuid"))
370                                 allocateTnNssi.addProperty("nssiName", execution.getVariable("TNFH_modelName"))
371                                 Map<String,Object> sliceProfile = objectMapper.readValue(execution.getVariable("tnFhSliceProfile"), Map.class)
372                                 sliceProfile.put("sliceProfileId", execution.getVariable("TNFH_sliceProfileInstanceId"))
373                                 allocateTnNssi.add("sliceProfile", jsonConverter.toJsonTree(sliceProfile))
374                                 endpoints.addProperty("transportEndpointA", execution.getVariable("tranportEp_ID_RU"))
375                                 endpoints.addProperty("transportEndpointB", execution.getVariable("tranportEp_ID_DUIN"))
376                                 connectionLinksList.add(endpoints)
377                         }else if(domainType.equals("TN_MH")) {
378                                 serviceInfo.addProperty("serviceInvariantUuid", execution.getVariable("TNMH_modelInvariantUuid"))
379                                 serviceInfo.addProperty("serviceUuid", execution.getVariable("TNMH_modelUuid"))
380                                 serviceInfo.addProperty("nssiName", "nssi_tn_mh_"+TNMH_nssiInstanceId)
381                                 serviceInfo.addProperty("sst",  execution.getVariable("sst"))
382                                 allocateTnNssi.addProperty("nsstId", execution.getVariable("TNMH_modelUuid"))
383                                 allocateTnNssi.addProperty("nssiName", execution.getVariable("TNMH_modelName"))
384                                 Map<String,Object> sliceProfile = objectMapper.readValue(execution.getVariable("tnMhSliceProfile"), Map.class)
385                                 sliceProfile.put("sliceProfileId", execution.getVariable("TNMH_sliceProfileInstanceId"))
386                                 allocateTnNssi.add("sliceProfile", jsonConverter.toJsonTree(sliceProfile))
387                                 endpoints.addProperty("transportEndpointA", execution.getVariable("tranportEp_ID_DUEG"))
388                                 endpoints.addProperty("transportEndpointB", execution.getVariable("tranportEp_ID_CUIN"))
389                                 connectionLinksList.add(endpoints)
390                         }
391                 }else if(action.equals("modify-allocate")) {
392                         JsonObject endpoints = new JsonObject()
393                         if(domainType.equals("TN_FH")) {
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                                 serviceInfo.addProperty("nssiName", execution.getVariable("TNFH_nssiName"))
399                                 Map<String,Object> sliceProfile = objectMapper.readValue(execution.getVariable("tnFhSliceProfile"), Map.class)
400                                 sliceProfile.put("sliceProfileId", execution.getVariable("TNFH_sliceProfileInstanceId"))
401                                 allocateTnNssi.add("sliceProfile", jsonConverter.toJsonTree(sliceProfile))
402                                 endpoints.addProperty("transportEndpointA", execution.getVariable("tranportEp_ID_RU"))
403                                 endpoints.addProperty("transportEndpointB", execution.getVariable("tranportEp_ID_DUIN"))
404                                 connectionLinksList.add(endpoints)
405                         }else if(domainType.equals("TN_MH")) {
406                                 allocateTnNssi.addProperty("nssiName", execution.getVariable("TNMH_nssiName"))
407                                 allocateTnNssi.addProperty("sliceProfileId", execution.getVariable("TNMH_sliceProfileInstanceId"))
408                                 allocateTnNssi.addProperty("nssiId", execution.getVariable("TNMH_NSSI"))
409                                 serviceInfo.addProperty("nssiId", execution.getVariable("TNMH_NSSI"))
410                                 serviceInfo.addProperty("nssiName", execution.getVariable("TNMH_nssiName"))
411                                 Map<String,Object> sliceProfile = objectMapper.readValue(execution.getVariable("tnMhSliceProfile"), Map.class)
412                                 sliceProfile.put("sliceProfileId", execution.getVariable("TNMH_sliceProfileInstanceId"))
413                                 allocateTnNssi.add("sliceProfile", jsonConverter.toJsonTree(sliceProfile))
414                                 endpoints.addProperty("transportEndpointA", execution.getVariable("tranportEp_ID_DUEG"))
415                                 endpoints.addProperty("transportEndpointB", execution.getVariable("tranportEp_ID_CUIN"))
416                                 connectionLinksList.add(endpoints)
417                         }
418                 }
419
420                 //Connection links
421                 connectionLinks.add("connectionLinks", connectionLinksList)
422                 transportSliceNetworksList.add(connectionLinks)
423                 allocateTnNssi.add("transportSliceNetworks", transportSliceNetworksList)
424
425                 JsonParser parser = new JsonParser()
426                 String nsiInfo = jsonUtil.getJsonValue(execution.getVariable("sliceParams"), "nsiInfo")
427                 allocateTnNssi.add("nsiInfo",(JsonObject) parser.parse(nsiInfo))
428                 allocateTnNssi.addProperty("scriptName", "TN1")
429                 serviceInfo.addProperty("nsiId", execution.getVariable("nsiId"))
430                 serviceInfo.addProperty("globalSubscriberId", execution.getVariable("globalSubscriberId"))
431                 serviceInfo.addProperty("subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
432                 response.add("esrInfo", esrInfo)
433                 response.add("serviceInfo", serviceInfo)
434                 response.add("allocateTnNssi", allocateTnNssi)
435                 return response.toString()
436         }
437         
438         public String buildDeallocateNssiRequest(DelegateExecution execution,String domainType) {
439                 String globalSubscriberId = execution.getVariable("globalSubscriberId")
440                 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
441
442                 List<String> sNssaiList =  execution.getVariable("snssaiList")
443
444                 DeAllocateNssi deallocateNssi = new DeAllocateNssi()
445                 deallocateNssi.setNsiId(execution.getVariable("nsiId"))
446                 deallocateNssi.setScriptName("TN1")
447                 deallocateNssi.setSnssaiList(sNssaiList)
448                 deallocateNssi.setTerminateNssiOption(0)
449            
450                 JsonObject esrInfo = new JsonObject()
451                 esrInfo.addProperty("networkType", "tn")
452                 esrInfo.addProperty("vendor", "ONAP_internal")
453            
454                 JsonObject serviceInfo = new JsonObject()
455                 serviceInfo.addProperty("globalSubscriberId", globalSubscriberId)
456                 serviceInfo.addProperty("subscriptionServiceType", subscriptionServiceType)
457                 serviceInfo.addProperty("modifyAction", true)
458
459                 if(domainType.equals("TN_FH")) {
460                         deallocateNssi.setNssiId(execution.getVariable("TNFH_NSSI"))
461                         deallocateNssi.setSliceProfileId(execution.getVariable("TNFH_sliceProfileInstanceId"))
462                         serviceInfo.addProperty("nssiId", execution.getVariable("TNFH_NSSI"))
463                 }else if(domainType.equals("TN_MH")) {
464                         deallocateNssi.setNssiId(execution.getVariable("TNMH_NSSI"))
465                         deallocateNssi.setSliceProfileId(execution.getVariable("TNMH_sliceProfileInstanceId"))
466                         serviceInfo.addProperty("nssiId", execution.getVariable("TNMH_NSSI"))
467                 }
468
469                 JsonObject json = new JsonObject()
470                 Gson jsonConverter = new Gson()
471                 json.add("deAllocateNssi", jsonConverter.toJsonTree(deallocateNssi))
472                 json.add("esrInfo", esrInfo)
473                 json.add("serviceInfo", serviceInfo)
474                 return json.toString()
475            
476         }
477
478         public String getModelUuid(DelegateExecution execution, String instanceId) {
479                 String globalSubscriberId = execution.getVariable("globalSubscriberId")
480                 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
481                 ServiceInstance serviceInstance = new ServiceInstance()
482                 AAIResourcesClient client = new AAIResourcesClient()
483                 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(instanceId))
484                 if (!client.exists(uri)) {
485                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai : ${instanceId}")
486                 }
487                 AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
488                 Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
489                 
490                 if(si.isPresent()) {
491                         serviceInstance = si.get()
492                 }
493                 return serviceInstance.getModelVersionId()
494         }
495 }