Merge "add junit coverage"
[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                 if(action.equals("allocate")){
360                         JsonObject endpoints = new JsonObject()
361                         if(domainType.equals("TN_FH")) {
362                                 serviceInfo.addProperty("serviceInvariantUuid", execution.getVariable("TNFH_modelInvariantUuid"))
363                                 serviceInfo.addProperty("serviceUuid", execution.getVariable("TNFH_modelUuid"))
364                                 serviceInfo.addProperty("nssiName", "nssi_"+execution.getVariable("TNFH_modelName"))
365                                 serviceInfo.addProperty("sst",  execution.getVariable("sst"))
366                                 allocateTnNssi.addProperty("nsstId", execution.getVariable("TNFH_modelUuid"))
367                                 allocateTnNssi.addProperty("nssiName", execution.getVariable("TNFH_modelName"))
368                                 Map<String,Object> sliceProfile = objectMapper.readValue(execution.getVariable("tnFhSliceProfile"), Map.class)
369                                 sliceProfile.put("sliceProfileId", execution.getVariable("TNFH_sliceProfileInstanceId"))
370                                 allocateTnNssi.add("sliceProfile", jsonConverter.toJsonTree(sliceProfile))
371                                 endpoints.addProperty("transportEndpointA", execution.getVariable("tranportEp_ID_RU"))
372                                 endpoints.addProperty("transportEndpointB", execution.getVariable("tranportEp_ID_DUIN"))
373                                 connectionLinksList.add(endpoints)
374                         }else if(domainType.equals("TN_MH")) {
375                                 serviceInfo.addProperty("serviceInvariantUuid", execution.getVariable("TNMH_modelInvariantUuid"))
376                                 serviceInfo.addProperty("serviceUuid", execution.getVariable("TNMH_modelUuid"))
377                                 serviceInfo.addProperty("nssiName", "nssi_"+execution.getVariable("TNMH_modelName"))
378                                 serviceInfo.addProperty("sst",  execution.getVariable("sst"))
379                                 allocateTnNssi.addProperty("nsstId", execution.getVariable("TNMH_modelUuid"))
380                                 allocateTnNssi.addProperty("nssiName", execution.getVariable("TNMH_modelName"))
381                                 Map<String,Object> sliceProfile = objectMapper.readValue(execution.getVariable("tnMhSliceProfile"), Map.class)
382                                 sliceProfile.put("sliceProfileId", execution.getVariable("TNMH_sliceProfileInstanceId"))
383                                 allocateTnNssi.add("sliceProfile", jsonConverter.toJsonTree(sliceProfile))
384                                 endpoints.addProperty("transportEndpointA", execution.getVariable("tranportEp_ID_DUEG"))
385                                 endpoints.addProperty("transportEndpointB", execution.getVariable("tranportEp_ID_CUIN"))
386                                 connectionLinksList.add(endpoints)
387                         }
388                 }else if(action.equals("modify-allocate")) {
389                         JsonObject endpoints = new JsonObject()
390                         if(domainType.equals("TN_FH")) {
391                                 allocateTnNssi.addProperty("nssiName", execution.getVariable("TNFH_nssiName"))
392                                 allocateTnNssi.addProperty("sliceProfileId", execution.getVariable("TNFH_sliceProfileInstanceId"))
393                                 allocateTnNssi.addProperty("nssiId", execution.getVariable("TNFH_NSSI"))
394                                 serviceInfo.addProperty("nssiId", execution.getVariable("TNFH_NSSI"))
395                                 serviceInfo.addProperty("nssiName", execution.getVariable("TNFH_nssiName"))
396                                 Map<String,Object> sliceProfile = objectMapper.readValue(execution.getVariable("tnFhSliceProfile"), Map.class)
397                                 sliceProfile.put("sliceProfileId", execution.getVariable("TNFH_sliceProfileInstanceId"))
398                                 allocateTnNssi.add("sliceProfile", jsonConverter.toJsonTree(sliceProfile))
399                                 endpoints.addProperty("transportEndpointA", execution.getVariable("tranportEp_ID_RU"))
400                                 endpoints.addProperty("transportEndpointB", execution.getVariable("tranportEp_ID_DUIN"))
401                                 connectionLinksList.add(endpoints)
402                         }else if(domainType.equals("TN_MH")) {
403                                 allocateTnNssi.addProperty("nssiName", execution.getVariable("TNMH_nssiName"))
404                                 allocateTnNssi.addProperty("sliceProfileId", execution.getVariable("TNMH_sliceProfileInstanceId"))
405                                 allocateTnNssi.addProperty("nssiId", execution.getVariable("TNMH_NSSI"))
406                                 serviceInfo.addProperty("nssiId", execution.getVariable("TNMH_NSSI"))
407                                 serviceInfo.addProperty("nssiName", execution.getVariable("TNMH_nssiName"))
408                                 Map<String,Object> sliceProfile = objectMapper.readValue(execution.getVariable("tnMhSliceProfile"), Map.class)
409                                 sliceProfile.put("sliceProfileId", execution.getVariable("TNMH_sliceProfileInstanceId"))
410                                 allocateTnNssi.add("sliceProfile", jsonConverter.toJsonTree(sliceProfile))
411                                 endpoints.addProperty("transportEndpointA", execution.getVariable("tranportEp_ID_DUEG"))
412                                 endpoints.addProperty("transportEndpointB", execution.getVariable("tranportEp_ID_CUIN"))
413                                 connectionLinksList.add(endpoints)
414                         }
415                 }
416
417                 //Connection links
418                 connectionLinks.add("connectionLinks", connectionLinksList)
419                 transportSliceNetworksList.add(connectionLinks)
420                 allocateTnNssi.add("transportSliceNetworks", transportSliceNetworksList)
421
422                 JsonParser parser = new JsonParser()
423                 String nsiInfo = jsonUtil.getJsonValue(execution.getVariable("sliceParams"), "nsiInfo")
424                 allocateTnNssi.add("nsiInfo",(JsonObject) parser.parse(nsiInfo))
425                 allocateTnNssi.addProperty("scriptName", "TN1")
426                 serviceInfo.addProperty("nsiId", execution.getVariable("nsiId"))
427                 serviceInfo.addProperty("globalSubscriberId", execution.getVariable("globalSubscriberId"))
428                 serviceInfo.addProperty("subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
429                 response.add("esrInfo", esrInfo)
430                 response.add("serviceInfo", serviceInfo)
431                 response.add("allocateTnNssi", allocateTnNssi)
432                 return response.toString()
433         }
434         
435         public String buildDeallocateNssiRequest(DelegateExecution execution,String domainType) {
436                 String globalSubscriberId = execution.getVariable("globalSubscriberId")
437                 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
438            
439                 JsonObject deAllocateNssi = new JsonObject()
440                 deAllocateNssi.addProperty("snssaiList", execution.getVariable("snssaiList"))
441                 deAllocateNssi.addProperty("nsiId", execution.getVariable("nsiId"))
442                 deAllocateNssi.addProperty("modifyAction", true)
443                 deAllocateNssi.addProperty("terminateNssiOption", 0)
444                 deAllocateNssi.addProperty("scriptName", "TN1")
445                 
446                 
447                 JsonObject esrInfo = new JsonObject()
448                 esrInfo.addProperty("networkType", "tn")
449                 esrInfo.addProperty("vendor", "ONAP_internal")
450            
451                 JsonObject serviceInfo = new JsonObject()
452                 serviceInfo.addProperty("globalSubscriberId", globalSubscriberId)
453                 serviceInfo.addProperty("subscriptionServiceType", subscriptionServiceType)
454                 
455                 if(domainType.equals("TN_FH")) {
456                         deAllocateNssi.addProperty("nssiId", execution.getVariable("TNFH_NSSI"))
457                         serviceInfo.addProperty("nssiId", execution.getVariable("TNFH_NSSI"))
458                         deAllocateNssi.addProperty("sliceProfileId", execution.getVariable("TNFH_sliceProfileInstanceId"))
459                 }else if(domainType.equals("TN_MH")) {
460                         deAllocateNssi.addProperty("nssiId", execution.getVariable("TNMH_NSSI"))
461                         serviceInfo.addProperty("nssiId", execution.getVariable("TNMH_NSSI"))
462                         deAllocateNssi.addProperty("sliceProfileId", execution.getVariable("TNMH_sliceProfileInstanceId"))
463                 }
464
465                 JsonObject json = new JsonObject()
466                 json.add("deAllocateNssi", deAllocateNssi)
467                 json.add("esrInfo", esrInfo)
468                 json.add("serviceInfo", serviceInfo)
469                 return json.toString()
470            
471         }
472
473         public String getModelUuid(DelegateExecution execution, String instanceId) {
474                 String globalSubscriberId = execution.getVariable("globalSubscriberId")
475                 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
476                 ServiceInstance serviceInstance = new ServiceInstance()
477                 AAIResourcesClient client = new AAIResourcesClient()
478                 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(instanceId))
479                 if (!client.exists(uri)) {
480                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai : ${instanceId}")
481                 }
482                 AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
483                 Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
484                 
485                 if(si.isPresent()) {
486                         serviceInstance = si.get()
487                 }
488                 return serviceInstance.getModelVersionId()
489         }
490 }