Merge "update the committers list with Ramesh"
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / groovy / org / onap / so / bpmn / infrastructure / scripts / DoAllocateAccessNSSI.groovy
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  # Copyright (c) 2020, Wipro Limited.
6  #
7  # Licensed under the Apache License, Version 2.0 (the "License")
8  # you may not use this file except in compliance with the License.
9  # You may obtain a copy of the License at
10  #
11  #       http://www.apache.org/licenses/LICENSE-2.0
12  #
13  # Unless required by applicable law or agreed to in writing, software
14  # distributed under the License is distributed on an "AS IS" BASIS,
15  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  # See the License for the specific language governing permissions and
17  # limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.scripts
22
23 import org.camunda.bpm.engine.delegate.BpmnError
24 import org.camunda.bpm.engine.delegate.DelegateExecution
25 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
26 import org.onap.so.bpmn.common.scripts.ExceptionUtil
27 import org.onap.so.bpmn.common.scripts.NssmfAdapterUtils
28 import org.onap.so.bpmn.common.scripts.OofUtils
29 import org.onap.so.bpmn.common.scripts.RequestDBUtil
30 import org.onap.so.bpmn.core.json.JsonUtils
31 import org.onap.so.db.request.beans.ResourceOperationStatus
32 import org.slf4j.Logger
33 import org.slf4j.LoggerFactory
34 import java.util.List
35 import static org.apache.commons.lang3.StringUtils.isBlank
36 import com.google.gson.JsonObject
37 import com.fasterxml.jackson.databind.ObjectMapper
38 import com.google.gson.JsonArray
39 import com.google.gson.JsonParser
40 import org.onap.aai.domain.yang.Relationship
41 import org.onap.aaiclient.client.aai.AAIResourcesClient
42 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
43 import org.onap.so.beans.nsmf.AllocateTnNssi
44 import org.onap.so.bpmn.core.UrnPropertiesReader
45 import org.onap.so.bpmn.core.domain.ServiceDecomposition
46 import org.onap.so.bpmn.core.domain.ServiceInstance
47 import org.onap.so.bpmn.core.domain.ServiceProxy
48 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
49 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
50 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
51 import org.onap.aaiclient.client.aai.AAINamespaceConstants
52 import org.onap.aaiclient.client.aai.AAIObjectType
53 import org.onap.aai.domain.yang.NetworkPolicy
54 import org.onap.aai.domain.yang.NetworkRoute
55
56 class DoAllocateAccessNSSI extends AbstractServiceTaskProcessor {
57
58         String Prefix="AASS_"
59         ExceptionUtil exceptionUtil = new ExceptionUtil()
60         RequestDBUtil requestDBUtil = new RequestDBUtil()
61         JsonUtils jsonUtil = new JsonUtils()
62         OofUtils oofUtils = new OofUtils()
63         AnNssmfUtils anNssmfUtils = new AnNssmfUtils()
64         ObjectMapper objectMapper = new ObjectMapper();
65         private NssmfAdapterUtils nssmfAdapterUtils = new NssmfAdapterUtils(httpClientFactory, jsonUtil)
66
67         private static final Logger logger = LoggerFactory.getLogger(DoAllocateAccessNSSI.class)
68
69         @Override
70         void preProcessRequest(DelegateExecution execution) {
71                 logger.debug(Prefix + "preProcessRequest Start")
72                 execution.setVariable("prefix", Prefix)
73                 execution.setVariable("startTime", System.currentTimeMillis())
74                 def msg
75                 try {
76
77                         logger.debug("input variables : msoRequestId - "+execution.getVariable("msoRequestId")
78                                         +" modelInvariantUuid - "+execution.getVariable("modelInvariantUuid")+
79                                         " modelUuid - "+execution.getVariable("modelUuid")+
80                                         " globalSubscriberId - "+execution.getVariable("globalSubscriberId")+
81                                         " dummyServiceId - "+ execution.getVariable("dummyServiceId")+
82                                         " nsiId - "+execution.getVariable("nsiId")+
83                                         " networkType - "+execution.getVariable("networkType")+
84                                         " subscriptionServiceType - "+execution.getVariable("subscriptionServiceType")+
85                                         " jobId - "+execution.getVariable("jobId")+
86                                         " sliceParams - "+execution.getVariable("sliceParams")+
87                                         " servicename - "+ execution.getVariable("servicename"))
88
89                         //validate slice subnet inputs
90
91                         String sliceParams = execution.getVariable("sliceParams")
92                         String sliceProfile = jsonUtil.getJsonValue(sliceParams, "sliceProfile")
93                         if (isBlank(sliceProfile)) {
94                                 msg = "Input sliceProfile is null"
95                                 logger.debug(msg)
96                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
97                         } else {
98                                 execution.setVariable("sliceProfile", sliceProfile)
99                         }
100                         String sliceProfileId = jsonUtil.getJsonValue(sliceProfile, "sliceProfileId")
101                         def snssaiList = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(sliceProfile, "sNSSAI"))
102                         def plmnIdList = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(sliceProfile, "pLMNIdList"))
103                         def coverageAreaTAList = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(sliceProfile, "coverageAreaTAList"))
104
105                         if (isBlank(sliceProfileId) || (snssaiList.empty) || (plmnIdList.empty)
106                         || (coverageAreaTAList.empty)) {
107
108                                 msg = "Mandatory slice profile fields are empty"
109                                 logger.debug(msg)
110                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
111                         } else {
112                                 execution.setVariable("sliceProfileId", sliceProfileId)
113                                 execution.setVariable("snssaiList", snssaiList)
114                                 execution.setVariable("plmnIdList", plmnIdList)
115                                 execution.setVariable("coverageAreaTAList", coverageAreaTAList)
116                         }
117                         String nsiName = jsonUtil.getJsonValue(sliceParams, "nsiInfo.nsiName")
118                         String scriptName = jsonUtil.getJsonValue(sliceParams, "scriptName")
119                         execution.setVariable("nsiName", nsiName)
120                         execution.setVariable("scriptName", scriptName)
121                         //generate RAN,RAN NF NSSIs - will be re assigned if oof returns existing NSSI
122                         String RANServiceInstanceId = UUID.randomUUID().toString()
123                         String RANNFServiceInstanceId = UUID.randomUUID().toString()
124                         logger.debug("RAN serviceInstance Id "+RANServiceInstanceId)
125                         logger.debug("RAN NF serviceInstance Id "+RANNFServiceInstanceId)                       
126                         execution.setVariable("RANServiceInstanceId", RANServiceInstanceId)
127                         execution.setVariable("RANNFServiceInstanceId", RANNFServiceInstanceId)
128                         execution.setVariable("ranNssiPreferReuse", true)
129                         execution.setVariable("ranNfNssiPreferReuse", true)
130                         execution.setVariable("job_timeout", 10)
131                         
132                         //set BH end point
133                         List<String> BH_endPoints = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(sliceParams, "endPoints"))
134                         logger.debug("BH end points list : "+BH_endPoints)
135                         if(BH_endPoints.empty) {
136                                 msg = "End point info is empty"
137                                 logger.debug(msg)
138                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
139                         }else {
140                                 execution.setVariable("bh_endpoint", BH_endPoints.get(0))
141                         }
142                         
143                 } catch(BpmnError e) {
144                         throw e
145                 } catch(Exception ex) {
146                         msg = "Exception in DoAllocateAccessNSSI.preProcessRequest " + ex.getMessage()
147                         logger.debug(msg)
148                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
149                 }
150                 logger.debug(Prefix + "preProcessRequest Exit")
151         }
152
153         /*
154          * Prepare request params for decomposing RAN NSST
155          */
156
157         def prepareDecomposeService = { DelegateExecution execution ->
158                 logger.debug(Prefix+"prepareDecomposeService method start")
159                 String RANServiceInstanceId = execution.getVariable("RANServiceInstanceId")
160                 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
161                 String modelUuid = execution.getVariable("modelUuid")
162                 String serviceModelInfo = """{
163             "modelInvariantUuid":"${modelInvariantUuid}",
164             "modelUuid":"${modelUuid}",
165             "modelVersion":""
166              }"""
167                 execution.setVariable("serviceModelInfo", serviceModelInfo)
168                 execution.setVariable("serviceInstanceId", RANServiceInstanceId)
169                 logger.debug("serviceModelInfo : "+serviceModelInfo)
170                 logger.debug("Finish RAN NSST prepareDecomposeService")
171         }
172
173         /* process the decompose service(RAN NSST) response
174          * 
175          */
176         def processDecomposition = { DelegateExecution execution ->
177                 logger.debug(Prefix+"processDecomposition method start")
178                 ServiceDecomposition ranNsstServiceDecomposition = execution.getVariable("ranNsstServiceDecomposition")
179                 logger.debug("ranNsstServiceDecomposition : "+ranNsstServiceDecomposition.toString())
180                 //RAN NSST decomposition
181                 String ranModelVersion = ranNsstServiceDecomposition.getModelInfo().getModelVersion()
182                 String ranModelName = ranNsstServiceDecomposition.getModelInfo().getModelName()
183                 List<ServiceProxy> serviceProxyList = ranNsstServiceDecomposition.getServiceProxy()
184                 List<String> nsstInfoList = new ArrayList<>()
185                 for(ServiceProxy serviceProxy : serviceProxyList)
186                 {
187                         String nsstModelUuid = serviceProxy.getSourceModelUuid()
188                         String nsstModelInvariantUuid = serviceProxy.getModelInfo().getModelInvariantUuid()
189                         String name = serviceProxy.getModelInfo().getModelName()
190                         String nsstServiceModelInfo = """{
191             "UUID":"${nsstModelUuid}",
192             "invariantUUID":"${nsstModelInvariantUuid}",
193             "name":"${name}"
194              }"""
195                         nsstInfoList.add(nsstServiceModelInfo)
196                 }
197                 int currentIndex=0
198                 int maxIndex=nsstInfoList.size()
199                 if(maxIndex < 1)
200                 {
201                         String msg = "Exception in RAN NSST processDecomposition. There is no NSST associated with RAN NSST "
202                         logger.info(msg)
203                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
204                 }
205                 execution.setVariable("ranNsstInfoList", objectMapper.writeValueAsString(nsstInfoList))
206                 execution.setVariable("ranModelVersion", ranModelVersion)
207                 execution.setVariable("ranModelName", ranModelName)
208                 execution.setVariable("currentIndex",currentIndex)
209                 execution.setVariable("maxIndex",maxIndex)
210                 logger.debug(Prefix+"processDecomposition maxIndex value - "+maxIndex)
211         }
212
213         /*
214          * Function to subnet capabilities from nssmf adapter
215          */
216         def getSubnetCapabilities = { DelegateExecution execution ->
217                 logger.debug(Prefix+"getSubnetCapabilities method start")
218
219                 String tnNssmfRequest = anNssmfUtils.buildCreateTNNSSMFSubnetCapabilityRequest()
220
221                 String urlString = "/api/rest/provMns/v1/NSS/subnetCapabilityQuery"
222
223                 String tnNssmfResponse = nssmfAdapterUtils.sendPostRequestNSSMF(execution, urlString, tnNssmfRequest)
224
225                 if (tnNssmfResponse != null) {
226                         String FHCapabilities= jsonUtil.getJsonValue(tnNssmfResponse, "TN_FH")
227                         String MHCapabilities = jsonUtil.getJsonValue(tnNssmfResponse, "TN_MH")
228                         execution.setVariable("FHCapabilities",FHCapabilities)
229                         execution.setVariable("MHCapabilities",MHCapabilities)
230
231                 } else {
232                         logger.error("received error message from NSSMF : "+ tnNssmfResponse)
233                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"Received a Bad Sync Response from NSSMF.")
234                 }
235                 String anNssmfRequest = anNssmfUtils.buildCreateANNFNSSMFSubnetCapabilityRequest()
236
237                 String anNssmfResponse = nssmfAdapterUtils.sendPostRequestNSSMF(execution, urlString, anNssmfRequest)
238
239                 if (anNssmfResponse != null) {
240                         String ANNFCapabilities = jsonUtil.getJsonValue(anNssmfResponse, "AN_NF")
241                         execution.setVariable("ANNFCapabilities",ANNFCapabilities)
242
243                 } else {
244                         logger.error("received error message from NSSMF : "+ anNssmfResponse)
245                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"Received a Bad Sync Response from NSSMF.")
246                 }
247         }
248
249         /*
250          * prepare OOF request for RAN NSSI selection
251          */
252         def prepareOofRequestForRanNSS = { DelegateExecution execution ->
253                 logger.debug(Prefix+"prepareOofRequestForRanNSS method start")
254
255                 String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution)
256                 logger.debug( "get NSSI option OOF Url: " + urlString)
257                 JsonParser parser = new JsonParser()
258                 //build oof request body
259                 boolean ranNssiPreferReuse = execution.getVariable("ranNssiPreferReuse");
260                 String requestId = execution.getVariable("msoRequestId")
261                 String messageType = "NSISelectionResponse"
262                 Map<String, Object> profileInfo = objectMapper.readValue(execution.getVariable("sliceProfile"), Map.class)
263                 String modelUuid = execution.getVariable("modelUuid")
264                 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
265                 String modelName = execution.getVariable("ranModelName")
266                 String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution);
267                 List<String> nsstInfoList =  objectMapper.readValue(execution.getVariable("ranNsstInfoList"), List.class)
268                 JsonArray capabilitiesList = new JsonArray()
269                 String FHCapabilities = execution.getVariable("FHCapabilities")
270                 String MHCapabilities = execution.getVariable("MHCapabilities")
271                 String ANNFCapabilities = execution.getVariable("ANNFCapabilities")
272                 JsonObject FH = new JsonObject()
273                 JsonObject MH = new JsonObject()
274                 JsonObject ANNF = new JsonObject()
275                 FH.addProperty("domainType", "TN_FH")
276                 FH.add("capabilityDetails", (JsonObject) parser.parse(FHCapabilities))
277                 MH.addProperty("domainType", "TN_MH")
278                 MH.add("capabilityDetails", (JsonObject) parser.parse(MHCapabilities))
279                 ANNF.addProperty("domainType", "AN_NF")
280                 ANNF.add("capabilityDetails", (JsonObject) parser.parse(ANNFCapabilities))
281                 capabilitiesList.add(FH)
282                 capabilitiesList.add(MH)
283                 capabilitiesList.add(ANNF)
284
285                 execution.setVariable("nssiSelection_Url", "/api/oof/selection/nsi/v1")
286                 execution.setVariable("nssiSelection_messageType",messageType)
287                 execution.setVariable("nssiSelection_correlator",requestId)
288                 execution.setVariable("nssiSelection_timeout",timeout)
289
290                 String oofRequest = anNssmfUtils.buildSelectRANNSSIRequest(requestId, messageType, modelUuid,modelInvariantUuid,
291                                 modelName, profileInfo, nsstInfoList, capabilitiesList, ranNssiPreferReuse)
292
293                 execution.setVariable("nssiSelection_oofRequest",oofRequest)
294                 logger.debug("Sending request to OOF: " + oofRequest)
295         }
296         /*
297          * process OOF response for RAN NSSI selection
298          */
299         def processOofResponseForRanNSS = { DelegateExecution execution ->
300                 logger.debug(Prefix+"processOofResponseForRanNSS method start")
301                 String oofResponse = execution.getVariable("nssiSelection_asyncCallbackResponse")
302                 String requestStatus = jsonUtil.getJsonValue(oofResponse, "requestStatus")
303                 if(requestStatus.equals("completed")) {
304                         String solutions = jsonUtil.getJsonValue(oofResponse, "solutions")
305                         logger.debug("solutions value : "+solutions)
306                         JsonParser parser = new JsonParser()
307                         JsonArray solution = parser.parse(solutions)
308                         JsonObject sol = solution.get(0)
309                         boolean existingNSI = sol.get("existingNSI").getAsBoolean()
310                         logger.debug("existingNSI value : "+existingNSI)
311                         if(existingNSI) {
312                                 JsonObject sharedNSISolution = sol.get("sharedNSISolution").getAsJsonObject()
313                                 execution.setVariable("sharedRanNSSISolution", sharedNSISolution.toString())
314                                 logger.debug("sharedRanNSSISolution from OOF "+sharedNSISolution)
315                                 String RANServiceInstanceId = sharedNSISolution.get("NSIId").getAsString()
316                                 execution.setVariable("RANServiceInstanceId", RANServiceInstanceId)
317                                 ServiceInstance serviceInstance = new ServiceInstance();
318                                 serviceInstance.setInstanceId(RANServiceInstanceId);
319                                 ServiceDecomposition serviceDecomposition = execution.getVariable("ranNsstServiceDecomposition")
320                                 serviceDecomposition.setServiceInstance(serviceInstance);
321                                 execution.setVariable("ranNsstServiceDecomposition", serviceDecomposition)
322                                 execution.setVariable("isRspRanNssi", true)
323                         }else {
324                                 JsonObject newNSISolution = sol.get("newNSISolution").getAsJsonObject()
325                                 JsonArray sliceProfiles = newNSISolution.get("slice_profiles").getAsJsonArray()
326                                 logger.debug("RanConstituentSliceProfiles list from OOF "+sliceProfiles)
327                                 execution.setVariable("RanConstituentSliceProfiles", sliceProfiles.toString())
328                         }
329                 }else {
330                         String statusMessage = jsonUtil.getJsonValue(oofResponse, "statusMessage")
331                         logger.error("received failed status from oof "+ statusMessage)
332                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"Received a failed Async Response from OOF : "+statusMessage)
333                 }
334
335         }
336
337         def prepareModifyAccessNssiInputs = { DelegateExecution execution ->
338                 logger.debug(Prefix+"prepareModifyAccessNssiInputs method start")
339                 String jobId = UUID.randomUUID().toString()
340                 execution.setVariable("modifyRanNssiJobId", jobId)              
341                 String snssaiList = execution.getVariable("snssaiList")
342                 String sliceParams = execution.getVariable("sliceParams")
343                 String sliceProfileId = execution.getVariable("sliceProfileId")
344                 String nsiInfo = jsonUtil.getJsonValue(sliceParams, "nsiInfo")
345                 String scriptName = execution.getVariable("scriptName")
346                 
347                 JsonObject modifySliceParams = new JsonObject()
348                 modifySliceParams.addProperty("modifyAction", "allocate")
349                 modifySliceParams.addProperty("snssaiList", snssaiList)
350                 modifySliceParams.addProperty("sliceProfileId", sliceProfileId)
351                 modifySliceParams.addProperty("nsiInfo", nsiInfo)
352                 modifySliceParams.addProperty("scriptName", scriptName)
353                 
354                 execution.setVariable("modifySliceParams", modifySliceParams.toString())
355                 //create operation status in request db
356                 String serviceId = execution.getVariable("RANServiceInstanceId")
357                 String nsiId = execution.getVariable("nsiId")
358                 logger.debug("Generated new job for Service Instance serviceId:" + serviceId + "jobId:" + jobId)
359
360                 ResourceOperationStatus initStatus = new ResourceOperationStatus()
361                 initStatus.setServiceId(serviceId)
362                 initStatus.setOperationId(jobId)
363                 initStatus.setResourceTemplateUUID(nsiId)
364                 initStatus.setOperType("Modify")
365                 requestDBUtil.prepareInitResourceOperationStatus(execution, initStatus)
366         }
367         
368         def createModifyNssiQueryJobStatus = { DelegateExecution execution ->
369                 logger.debug(Prefix+"createModifyNssiQueryJobStatus method start")
370                 JsonObject esrInfo = new JsonObject()
371             esrInfo.addProperty("networkType", "tn")
372             esrInfo.addProperty("vendor", "ONAP_internal")
373
374                 execution.setVariable("esrInfo", esrInfo.toString())
375                 JsonObject serviceInfo = new JsonObject()
376                 serviceInfo.addProperty("nssiId", execution.getVariable("RANServiceInstanceId"))
377                 serviceInfo.addProperty("nsiId", execution.getVariable("nsiId"))
378                 serviceInfo.addProperty("nssiName", execution.getVariable("servicename"))
379                 String sST = jsonUtil.getJsonValue(execution.getVariable("sliceProfile"), "sST")
380                 serviceInfo.addProperty("sST", sST)
381                 serviceInfo.addProperty("PLMNIdList", objectMapper.writeValueAsString(execution.getVariable("plmnIdList")))
382                 serviceInfo.addProperty("globalSubscriberId", execution.getVariable("globalSubscriberId"))
383                 serviceInfo.addProperty("subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
384                 serviceInfo.addProperty("serviceInvariantUuid", execution.getVariable("modelInvariantUuid"))
385                 serviceInfo.addProperty("serviceUuid", execution.getVariable("modelUuid"))
386                 execution.setVariable("serviceInfo", serviceInfo.toString())
387                 execution.setVariable("responseId", "")
388         }
389         def prepareNsstDecomposeService = { DelegateExecution execution ->
390                 logger.debug(Prefix+"prepareNsstDecomposeService method start")
391                 List<String> nsstInfoList = objectMapper.readValue(execution.getVariable("ranNsstInfoList"), List.class)
392                 int currentIndex = execution.getVariable("currentIndex")
393                 int maxIndex = execution.getVariable("maxIndex")
394                 logger.debug(Prefix+"prepareNsstDecomposeService : currentIndex value - "+currentIndex+" maxIndex : "+maxIndex)
395                 if(currentIndex<maxIndex) {
396                         String nsstInfo = nsstInfoList.get(currentIndex)
397                         String modelInvariantUuid = jsonUtil.getJsonValue(nsstInfo, "invariantUUID")
398                         String modelUuid = jsonUtil.getJsonValue(nsstInfo, "UUID")
399                         
400                         String serviceModelInfo = """{
401             "modelInvariantUuid":"${modelInvariantUuid}",
402             "modelUuid":"${modelUuid}",
403             "modelVersion":""
404              }"""
405                         execution.setVariable("serviceModelInfo", serviceModelInfo)
406                         execution.setVariable("serviceInstanceId", "")
407                         logger.debug("serviceModelInfo : "+serviceModelInfo)
408                         currentIndex++
409                         execution.setVariable("currentIndex", currentIndex)
410                 }else {
411                         logger.error("nsstList decomposition error ")
412                         exceptionUtil.buildAndThrowWorkflowException(execution, 1000, "nsstList decomposition error ")
413                 }
414                 
415         }
416         def processNsstDecomposition = { DelegateExecution execution ->
417                 logger.debug(Prefix+"processNsstDecomposition method start")
418                 ServiceDecomposition decomposedNsst = execution.getVariable("nsstServiceDecomposition")
419                 logger.debug("decomposedNsst : "+decomposedNsst.toString())
420                 
421                 String nsstType = decomposedNsst.getServiceRole() //domainType
422                 String modelVersion = decomposedNsst.getModelInfo().getModelVersion()
423                 String modelName = decomposedNsst.getModelInfo().getModelName()
424                 String modelUuid = decomposedNsst.getModelInfo().getModelUuid()
425                 String modelInvariantUuid = decomposedNsst.getModelInfo().getModelInvariantUuid()
426                 
427                 switch(nsstType) {
428                         case "AN_NF":
429                                 execution.setVariable("ANNF_modelInvariantUuid", modelInvariantUuid)
430                                 execution.setVariable("ANNF_modelUuid", modelUuid)
431                                 execution.setVariable("ANNF_modelVersion", modelVersion)
432                                 execution.setVariable("ANNF_modelName", modelName)
433                                 execution.setVariable("ANNF_ServiceDecomposition", decomposedNsst)
434                                 break
435                         case "TN_FH":
436                                 execution.setVariable("TNFH_modelInvariantUuid", modelInvariantUuid)
437                                 execution.setVariable("TNFH_modelUuid", modelUuid)
438                                 execution.setVariable("TNFH_modelVersion", modelVersion)
439                                 execution.setVariable("TNFH_modelName", modelName)
440                                 execution.setVariable("TNFH_ServiceDecomposition", decomposedNsst)
441                                 break
442                         case "TN_MH":
443                                 execution.setVariable("TNMH_modelInvariantUuid", modelInvariantUuid)
444                                 execution.setVariable("TNMH_modelUuid", modelUuid)
445                                 execution.setVariable("TNMH_modelVersion", modelVersion)
446                                 execution.setVariable("TNMH_modelName", modelName)
447                                 execution.setVariable("TNMH_ServiceDecomposition", decomposedNsst)
448                                 break
449                         default:
450                                 logger.debug("No expected match found for current nsstType")
451                                 logger.error("No expected match found for current nsstType "+ nsstType)
452                                 exceptionUtil.buildAndThrowWorkflowException(execution, 1000,"No expected match found for current nsstType "+ nsstType)
453                 }
454                 boolean isAllNsstsDecomposed = false
455                 int currentIndex = execution.getVariable("currentIndex")
456                 int maxIndex = execution.getVariable("maxIndex")
457                 if(currentIndex == maxIndex) {
458                         isAllNsstsDecomposed = true
459                 }
460                 execution.setVariable("isAllNsstsDecomposed", isAllNsstsDecomposed)
461         }
462         /*
463          * prepare OOF request for NF RAN NSSI selection
464          */
465         def prepareOofRequestForRanNfNSS = { DelegateExecution execution ->
466                 logger.debug(Prefix+"prepareOofRequestForRanNfNSS method start")
467                 String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution)
468                 logger.debug( "get NSSI option OOF Url: " + urlString)
469
470                 //build oof request body
471                 boolean ranNfNssiPreferReuse = execution.getVariable("ranNfNssiPreferReuse");
472                 String requestId = execution.getVariable("msoRequestId")
473                 String messageType = "NSSISelectionResponse"
474                 List<String> ranConstituentSliceProfiles = jsonUtil.StringArrayToList(execution.getVariable("RanConstituentSliceProfiles"))
475                 anNssmfUtils.createDomainWiseSliceProfiles(ranConstituentSliceProfiles, execution)
476                 Map<String, Object> profileInfo = objectMapper.readValue(execution.getVariable("ranNfSliceProfile"), Map.class)
477                 String modelUuid = execution.getVariable("ANNF_modelUuid")
478                 String modelInvariantUuid = execution.getVariable("ANNF_modelInvariantUuid")
479                 String modelName = execution.getVariable("ANNF_modelName")
480                 String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution);
481
482                 execution.setVariable("nssiSelection_Url", "/api/oof/selection/nssi/v1")
483                 execution.setVariable("nssiSelection_messageType",messageType)
484                 execution.setVariable("nssiSelection_correlator",requestId)
485                 execution.setVariable("nssiSelection_timeout",timeout)
486
487                 String oofRequest = oofUtils.buildSelectNSSIRequest(requestId, messageType, modelUuid, modelInvariantUuid, modelName, profileInfo)
488
489                 execution.setVariable("nssiSelection_oofRequest",oofRequest)
490         }
491         /*
492          * process OOF response for RAN NF NSSI selection
493          */
494         def processOofResponseForRanNfNSS = { DelegateExecution execution ->
495                 logger.debug(Prefix+"processOofResponseForRanNfNSS method start")
496                 String oofResponse = execution.getVariable("nfNssiSelection_asyncCallbackResponse")
497                 String requestStatus = jsonUtil.getJsonValue(oofResponse, "requestStatus")
498                 if(requestStatus.equals("completed")) {
499                         String solutions = jsonUtil.getJsonValue(oofResponse, "solutions")
500                         logger.debug("nssi solutions value : "+solutions)
501                         JsonParser parser = new JsonParser()
502                         JsonArray solution = parser.parse(solutions)            
503                         if(solution.size()>=1) {
504                                 JsonObject sol = solution.get(0)
505                                 String ranNfNssiId = sol.get("NSSIId").getAsString()
506                                 String invariantUuid = sol.get("invariantUUID").getAsString()
507                                 String uuid = sol.get("UUID").getAsString()
508                                 String nssiName = sol.get("NSSIName").getAsString()
509                                 execution.setVariable("RANNFServiceInstanceId", ranNfNssiId)
510                                 execution.setVariable("RANNFInvariantUUID", invariantUuid)
511                                 execution.setVariable("RANNFUUID", uuid)
512                                 execution.setVariable("RANNFNssiName", nssiName)
513                                 logger.debug("RANNFServiceInstanceId from OOF "+ranNfNssiId)
514                                 
515                                 ServiceInstance serviceInstance = new ServiceInstance();
516                                 serviceInstance.setInstanceId(ranNfNssiId);
517                                 ServiceDecomposition serviceDecomposition = execution.getVariable("ANNF_ServiceDecomposition")
518                                 serviceDecomposition.setServiceInstance(serviceInstance);
519                                 execution.setVariable("ANNF_ServiceDecomposition", serviceDecomposition)
520                                 execution.setVariable("isRspRanNfNssi", true)
521                         }else {
522                                 logger.debug("No solutions returned from OOF .. Create new RAN NF NSSI")
523                         }
524                 }else {
525                         String statusMessage = jsonUtil.getJsonValue(oofResponse, "statusMessage")
526                         logger.error("received failed status from oof "+ statusMessage)
527                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"Received a failed Async Response from OOF : "+statusMessage)
528                 }
529         }
530
531         def createSliceProfilesInAai = { DelegateExecution execution ->
532                 logger.debug(Prefix+"createSliceProfilesInAai method start")
533                 anNssmfUtils.createSliceProfilesInAai(execution)
534         }
535
536         def processRanNfModifyRsp = { DelegateExecution execution ->
537                 logger.debug(Prefix+"processRanNfModifyRsp method start")
538                 anNssmfUtils.processRanNfModifyRsp(execution)
539                 //create RAN NSSI 
540                 org.onap.aai.domain.yang.ServiceInstance ANServiceInstance = new org.onap.aai.domain.yang.ServiceInstance();
541                 //AN instance creation
542                 ANServiceInstance.setServiceInstanceId(execution.getVariable("RANServiceInstanceId"))
543                 String sliceInstanceName = execution.getVariable("servicename")
544                 ANServiceInstance.setServiceInstanceName(sliceInstanceName)
545                 String serviceType = jsonUtil.getJsonValue(execution.getVariable("sliceProfile"), "sST")
546                 ANServiceInstance.setServiceType(serviceType)
547                 String serviceStatus = "deactivated"
548                 ANServiceInstance.setOrchestrationStatus(serviceStatus)
549                 String serviceInstanceLocationid = jsonUtil.getJsonValue(execution.getVariable("sliceProfile"), "plmnIdList")
550                 ANServiceInstance.setServiceInstanceLocationId(serviceInstanceLocationid)
551                 String serviceRole = "nssi"
552                 ANServiceInstance.setServiceRole(serviceRole)
553                 List<String> snssaiList = objectMapper.readValue(execution.getVariable("snssaiList"), List.class)
554                 String snssai = snssaiList.get(0)
555                 ANServiceInstance.setEnvironmentContext(snssai)
556                 ANServiceInstance.setWorkloadContext("AN")
557                 
558                 logger.debug("completed AN service instance build "+ ANServiceInstance.toString())
559                 String msg = ""
560                 try {
561         
562                         AAIResourcesClient client = new AAIResourcesClient()
563                         AAIResourceUri nssiServiceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(execution.getVariable("RANServiceInstanceId")))
564                         client.create(nssiServiceUri, ANServiceInstance)
565         
566                 } catch (BpmnError e) {
567                         throw e
568                 } catch (Exception ex) {
569                         msg = "Exception in AnNssmfUtils.createSliceProfilesInAai " + ex.getMessage()
570                         logger.info(msg)
571                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
572                 }
573                 //end point update
574                 createEndPointsInAai(execution)
575         }
576         
577         def createSdnrRequest = { DelegateExecution execution ->
578                 logger.debug(Prefix+"createSdnrRequest method start")
579                 String callbackUrl = UrnPropertiesReader.getVariable("mso.workflow.message.endpoint") + "/AsyncSdnrResponse/"+execution.getVariable("msoRequestId")
580                 String sdnrRequest = buildSdnrAllocateRequest(execution, "allocate", "InstantiateRANSlice", callbackUrl)
581                 execution.setVariable("createNSSI_sdnrRequest", sdnrRequest)
582                 execution.setVariable("createNSSI_timeout", "PT10M")
583                 execution.setVariable("createNSSI_correlator", execution.getVariable("msoRequestId"))
584                 execution.setVariable("createNSSI_messageType", "AsyncSdnrResponse");
585         }
586
587         def processSdnrResponse = { DelegateExecution execution ->
588                 logger.debug(Prefix+"processSdnrResponse method start")
589                 String SDNRResponse = execution.getVariable("SDNR_asyncCallbackResponse")
590                 String status = jsonUtil.getJsonValue(SDNRResponse, "status")
591                 if(status.equalsIgnoreCase("success")) {
592                         String nfIds = jsonUtil.getJsonValue(SDNRResponse, "nfIds")
593                         execution.setVariable("ranNfIdsJson", nfIds)
594                 }else {
595                         String reason = jsonUtil.getJsonValue(SDNRResponse, "reason")
596                         logger.error("received failed status from SDNR "+ reason)
597                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"received failed status from SDNR "+ reason)
598                 }
599                 logger.debug("response from SDNR "+SDNRResponse)
600         }
601
602         def updateAaiWithRANInstances = { DelegateExecution execution ->
603                 logger.debug(Prefix+"updateAaiWithRANInstances method start")
604                 //create RAN NSSI 
605                 org.onap.aai.domain.yang.ServiceInstance ANServiceInstance = new org.onap.aai.domain.yang.ServiceInstance();
606                 org.onap.aai.domain.yang.ServiceInstance ANNFServiceInstance = new org.onap.aai.domain.yang.ServiceInstance();
607                 //AN instance creation
608                 ANServiceInstance.setServiceInstanceId(execution.getVariable("RANServiceInstanceId"))
609                 String sliceInstanceName = execution.getVariable("servicename")
610                 ANServiceInstance.setServiceInstanceName(sliceInstanceName)
611                 String serviceType = jsonUtil.getJsonValue(execution.getVariable("sliceProfile"), "sST")
612                 ANServiceInstance.setServiceType(serviceType)
613                 String serviceStatus = "deactivated"
614                 ANServiceInstance.setOrchestrationStatus(serviceStatus)
615                 String serviceInstanceLocationid = jsonUtil.getJsonValue(execution.getVariable("sliceProfile"), "pLMNIdList")
616                 ANServiceInstance.setServiceInstanceLocationId(serviceInstanceLocationid)
617                 String serviceRole = "nssi"
618                 ANServiceInstance.setServiceRole(serviceRole)
619                 List<String> snssaiList = execution.getVariable("snssaiList")
620                 String snssai = snssaiList.get(0)
621                 ANServiceInstance.setEnvironmentContext(snssai)
622                 ANServiceInstance.setWorkloadContext("AN")
623                 String serviceFunctionAn = jsonUtil.getJsonValue(execution.getVariable("sliceProfile"), "resourceSharingLevel")
624                 ANServiceInstance.setServiceFunction(serviceFunctionAn)
625                 logger.debug("completed AN service instance build "+ ANServiceInstance.toString())
626                 //create RAN NF NSSI
627                 ANNFServiceInstance.setServiceInstanceId(execution.getVariable("RANNFServiceInstanceId"))
628                 sliceInstanceName = execution.getVariable("ANNF_modelName")
629                 ANNFServiceInstance.setServiceInstanceName(sliceInstanceName)
630                 ANNFServiceInstance.setServiceType(serviceType)
631                 ANNFServiceInstance.setOrchestrationStatus(serviceStatus)
632                 serviceInstanceLocationid = jsonUtil.getJsonValue(execution.getVariable("ranNfSliceProfile"), "pLMNIdList")
633                 ANNFServiceInstance.setServiceInstanceLocationId(serviceInstanceLocationid)
634                 ANNFServiceInstance.setServiceRole(serviceRole)
635                 snssaiList = execution.getVariable("snssaiList")
636                 snssai = snssaiList.get(0)
637                 ANNFServiceInstance.setEnvironmentContext(snssai)
638                 ANNFServiceInstance.setWorkloadContext("AN-NF")
639                 String serviceFunctionAnnf = jsonUtil.getJsonValue(execution.getVariable("ranNfSliceProfile"), "resourceSharingLevel")
640                 ANNFServiceInstance.setServiceFunction(serviceFunctionAnnf)
641                 logger.debug("completed AN service instance build "+ ANNFServiceInstance.toString())
642                 
643                 String msg = ""
644                 try {
645         
646                         AAIResourcesClient client = new AAIResourcesClient()
647                         AAIResourceUri nssiServiceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(execution.getVariable("RANServiceInstanceId")))
648                         client.create(nssiServiceUri, ANServiceInstance)
649         
650                         AAIResourceUri nssiServiceUri1 = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(execution.getVariable("RANNFServiceInstanceId")))
651                         client.create(nssiServiceUri1, ANNFServiceInstance)
652         
653                 } catch (BpmnError e) {
654                         throw e
655                 } catch (Exception ex) {
656                         msg = "Exception in AnNssmfUtils.createSliceProfilesInAai " + ex.getMessage()
657                         logger.info(msg)
658                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
659                 }
660                 //end point update
661                 createEndPointsInAai(execution)
662         }
663         def prepareTnFhRequest = { DelegateExecution execution ->
664                 logger.debug(Prefix+"prepareTnFhRequest method start")
665
666                 String nssmfRequest = anNssmfUtils.buildCreateNSSMFRequest(execution, "TN_FH", "allocate")
667                 String urlString = "/api/rest/provMns/v1/NSS/SliceProfiles"
668                 String nssmfResponse = nssmfAdapterUtils.sendPostRequestNSSMF(execution, urlString, nssmfRequest)
669
670                 if (nssmfResponse != null) {
671                         execution.setVariable("nssmfResponse", nssmfResponse)
672                         String jobId = jsonUtil.getJsonValue(nssmfResponse, "jobId")
673                         execution.setVariable("TNFH_jobId",jobId)
674                 } else {
675                         logger.error("received error message from NSSMF : "+ nssmfResponse)
676                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"Received a Bad Sync Response from NSSMF.")
677                 }
678                 logger.debug("Exit prepareTnFhRequest")
679
680         }
681         def prepareTnMhRequest = { DelegateExecution execution ->
682                 logger.debug(Prefix+"prepareTnMhRequest method start")
683
684                 String nssmfRequest = anNssmfUtils.buildCreateNSSMFRequest(execution, "TN_MH", "allocate")
685                 String urlString = "/api/rest/provMns/v1/NSS/SliceProfiles"
686                 String nssmfResponse = nssmfAdapterUtils.sendPostRequestNSSMF(execution, urlString, nssmfRequest)
687
688                 if (nssmfResponse != null) {
689                         execution.setVariable("nssmfResponse", nssmfResponse)
690                         String jobId = jsonUtil.getJsonValue(nssmfResponse, "jobId")
691                         execution.setVariable("TNMH_jobId",jobId)
692                 } else {
693                         logger.error("received error message from NSSMF : "+ nssmfResponse)
694                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"Received a Bad Sync Response from NSSMF.")
695                 }
696                 logger.debug("Exit prepareTnMhRequest")
697         }
698         
699         def createFhAllocateNssiJobQuery = { DelegateExecution execution ->
700                 logger.debug(Prefix+"createModifyNssiQueryJobStatus method start")
701                 createTnAllocateNssiJobQuery(execution, "TN_FH")                
702         }
703         
704         def createMhAllocateNssiJobQuery = { DelegateExecution execution ->
705                 logger.debug(Prefix+"createModifyNssiQueryJobStatus method start")
706                 createTnAllocateNssiJobQuery(execution, "TN_MH")
707         }
708         
709         private void createTnAllocateNssiJobQuery(DelegateExecution execution, String domainType) {
710                 JsonObject esrInfo = new JsonObject()
711             esrInfo.addProperty("networkType", "tn")
712             esrInfo.addProperty("vendor", "ONAP_internal")
713                 execution.setVariable("esrInfo", esrInfo.toString())
714                 JsonObject serviceInfo = new JsonObject()
715                 serviceInfo.addProperty("nssiId", null)
716                 serviceInfo.addProperty("nsiId", execution.getVariable("nsiId"))
717                 String sST = jsonUtil.getJsonValue(execution.getVariable("sliceProfile"), "sST")
718                 serviceInfo.addProperty("sST", sST)
719                 serviceInfo.addProperty("PLMNIdList", objectMapper.writeValueAsString(execution.getVariable("plmnIdList")))
720                 serviceInfo.addProperty("globalSubscriberId", execution.getVariable("globalSubscriberId"))
721                 serviceInfo.addProperty("subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
722                 if(domainType.equals("TN_FH")) {
723                         serviceInfo.addProperty("nssiName", execution.getVariable("TNFH_modelName"))
724                         serviceInfo.addProperty("serviceInvariantUuid", execution.getVariable("TNFH_modelInvariantUuid"))
725                         serviceInfo.addProperty("serviceUuid", execution.getVariable("TNFH_modelUuid"))
726                 }else if(domainType.equals("TN_MH")) {
727                         serviceInfo.addProperty("nssiName", execution.getVariable("TNMH_modelName"))
728                         serviceInfo.addProperty("serviceInvariantUuid", execution.getVariable("TNMH_modelInvariantUuid"))
729                         serviceInfo.addProperty("serviceUuid", execution.getVariable("TNMH_modelUuid"))
730                 }
731                 execution.setVariable("serviceInfo", serviceInfo.toString())
732                 execution.setVariable("responseId", "")
733         }
734         
735         def processFhAllocateNssiJobStatusRsp = { DelegateExecution execution ->
736                 logger.debug(Prefix+"processJobStatusRsp method start")
737                 String jobResponse = execution.getVariable("TNFH_jobResponse")
738                 logger.debug("Job status response "+jobResponse)
739                 String status = jsonUtil.getJsonValue(jobResponse, "responseDescriptor.status")
740                 String nssi = jsonUtil.getJsonValue(jobResponse, "responseDescriptor.nssi")
741                 if(status.equalsIgnoreCase("finished")) {
742                         execution.setVariable("TNFH_NSSI", nssi)
743                         logger.debug("Job successfully completed ... proceeding with flow for nssi : "+nssi)
744                 }
745                 else {
746                         String statusDescription = jsonUtil.getJsonValue(jobResponse, "responseDescriptor.statusDescription")
747                         logger.error("received failed status from job status query for nssi : "+nssi+" with status description : "+ statusDescription)
748                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"received failed status from job status query for nssi : "+nssi+" with status description : "+ statusDescription)
749                 }
750         }
751         
752         def processMhAllocateNssiJobStatusRsp = { DelegateExecution execution ->
753                 logger.debug(Prefix+"processJobStatusRsp method start")
754                 String jobResponse = execution.getVariable("TNMH_jobResponse")
755                 logger.debug("Job status response "+jobResponse)
756                 String status = jsonUtil.getJsonValue(jobResponse, "responseDescriptor.status")
757                 String nssi = jsonUtil.getJsonValue(jobResponse, "responseDescriptor.nssi")
758                 if(status.equalsIgnoreCase("finished")) {
759                         execution.setVariable("TNMH_NSSI", nssi)
760                         logger.debug("Job successfully completed ... proceeding with flow for nssi : "+nssi)
761                 }
762                 else {
763                         String statusDescription = jsonUtil.getJsonValue(jobResponse, "responseDescriptor.statusDescription")
764                         logger.error("received failed status from job status query for nssi : "+nssi+" with status description : "+ statusDescription)
765                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"received failed status from job status query for nssi : "+nssi+" with status description : "+ statusDescription)
766                 }
767         }
768         
769         def processModifyJobStatusRsp = { DelegateExecution execution ->
770                 logger.debug(Prefix+"processJobStatusRsp method start")
771                 String jobResponse = execution.getVariable("jobResponse")
772                 logger.debug("Job status response "+jobResponse)
773                 String status = jsonUtil.getJsonValue(jobResponse, "responseDescriptor.status")
774                 String nssi = jsonUtil.getJsonValue(jobResponse, "responseDescriptor.nssi")
775                 if(status.equalsIgnoreCase("finished")) {
776                         logger.debug("Job successfully completed ... proceeding with flow for nssi : "+nssi)
777                 }
778                 else {
779                         String statusDescription = jsonUtil.getJsonValue(jobResponse, "responseDescriptor.statusDescription")
780                         logger.error("received failed status from job status query for nssi : "+nssi+" with status description : "+ statusDescription)
781                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"received failed status from job status query for nssi : "+nssi+" with status description : "+ statusDescription)
782                 }
783         }
784
785         def updateAairelationships = { DelegateExecution execution ->
786                 logger.debug(Prefix + "updateAairelationships Start")
787                 String msg = ""
788                 try {
789                         def ANNF_serviceInstanceId = execution.getVariable("RANNFServiceInstanceId")
790                         def TNFH_serviceInstanceId = execution.getVariable("TNFH_NSSI")
791                         def TNMH_serviceInstanceId = execution.getVariable("TNMH_NSSI")
792                         def AN_profileInstanceId = execution.getVariable("sliceProfileId")
793                         def AN_NSSI = execution.getVariable("RANServiceInstanceId")
794                         def ANNF_profileInstanceId = execution.getVariable("ANNF_sliceProfileInstanceId")
795                         def TNFH_profileInstanceId = execution.getVariable("TNFH_sliceProfileInstanceId")
796                         def TNMH_profileInstanceId = execution.getVariable("TNMH_sliceProfileInstanceId")
797                         String globalSubscriberId = execution.getVariable("globalSubscriberId")
798                         String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
799
800                         Relationship ANNF_relationship = new Relationship()
801                         Relationship TNFH_relationship = new Relationship()
802                         Relationship TNMH_relationship = new Relationship()
803                         
804                         String ANNF_relatedLink = "aai/v21/business/customers/customer/${globalSubscriberId}/service-subscriptions/service-subscription/${subscriptionServiceType}/service-instances/service-instance/${ANNF_profileInstanceId}"
805                         String TNFH_relatedLink = "aai/v21/business/customers/customer/${globalSubscriberId}/service-subscriptions/service-subscription/${subscriptionServiceType}/service-instances/service-instance/${TNFH_profileInstanceId}"
806                         String TNMH_relatedLink = "aai/v21/business/customers/customer/${globalSubscriberId}/service-subscriptions/service-subscription/${subscriptionServiceType}/service-instances/service-instance/${TNMH_profileInstanceId}"
807                         
808                         String ANNF_NSSI_relatedLink = "aai/v21/business/customers/customer/${globalSubscriberId}/service-subscriptions/service-subscription/${subscriptionServiceType}/service-instances/service-instance/${ANNF_serviceInstanceId}"
809                         String TNFH_NSSI_relatedLink = "aai/v21/business/customers/customer/${globalSubscriberId}/service-subscriptions/service-subscription/${subscriptionServiceType}/service-instances/service-instance/${TNFH_serviceInstanceId}"
810                         String TNMH_NSSI_relatedLink = "aai/v21/business/customers/customer/${globalSubscriberId}/service-subscriptions/service-subscription/${subscriptionServiceType}/service-instances/service-instance/${TNMH_serviceInstanceId}"
811                         
812                         ANNF_relationship.setRelatedLink(ANNF_relatedLink)
813                         ANNF_relationship.setRelatedTo("service-instance")
814                         ANNF_relationship.setRelationshipLabel("org.onap.relationships.inventory.ComposedOf")
815                         TNFH_relationship.setRelatedLink(TNFH_relatedLink)
816                         TNFH_relationship.setRelatedTo("service-instance")
817                         TNFH_relationship.setRelationshipLabel("org.onap.relationships.inventory.ComposedOf")
818                         TNMH_relationship.setRelatedLink(TNMH_relatedLink)
819                         TNMH_relationship.setRelatedTo("service-instance")
820                         TNMH_relationship.setRelationshipLabel("org.onap.relationships.inventory.ComposedOf")
821                         
822                         // create SliceProfile and NSSI relationship in AAI
823                         anNssmfUtils.createRelationShipInAAI(execution, ANNF_relationship,ANNF_serviceInstanceId)
824                         anNssmfUtils.createRelationShipInAAI(execution, TNFH_relationship,TNFH_serviceInstanceId)
825                         anNssmfUtils.createRelationShipInAAI(execution, TNMH_relationship,TNMH_serviceInstanceId)
826                         anNssmfUtils.createRelationShipInAAI(execution, ANNF_relationship,AN_profileInstanceId)
827                         anNssmfUtils.createRelationShipInAAI(execution, TNFH_relationship,AN_profileInstanceId)
828                         anNssmfUtils.createRelationShipInAAI(execution, TNMH_relationship,AN_profileInstanceId)
829                         
830                         //create AN NSSI and ANNF,TNFH,TNMH relationship in AAI
831                         ANNF_relationship.setRelatedLink(ANNF_NSSI_relatedLink)
832                         TNFH_relationship.setRelatedLink(TNFH_NSSI_relatedLink)
833                         TNMH_relationship.setRelatedLink(TNMH_NSSI_relatedLink)
834                         anNssmfUtils.createRelationShipInAAI(execution, ANNF_relationship,AN_NSSI)
835                         anNssmfUtils.createRelationShipInAAI(execution, TNFH_relationship,AN_NSSI)
836                         anNssmfUtils.createRelationShipInAAI(execution, TNMH_relationship,AN_NSSI)
837
838                 } catch (BpmnError e) {
839                         throw e
840                 } catch (Exception ex) {
841
842                         msg = "Exception in DoCreateE2EServiceInstance.createCustomRelationship. " + ex.getMessage()
843                         logger.info(msg)
844                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
845                 }
846         }
847         
848         /**
849          * update operation status in request db
850          *
851          */
852         def prepareOperationStatusUpdate = { DelegateExecution execution ->
853                 logger.debug(Prefix + "prepareOperationStatusUpdate Start")
854
855                 String serviceId = execution.getVariable("dummyServiceId")
856                 String jobId = execution.getVariable("jobId")
857                 String nsiId = execution.getVariable("nsiId")
858                 String nssiId = execution.getVariable("RANServiceInstanceId")
859                 logger.debug("Service Instance serviceId:" + serviceId + " jobId:" + jobId)
860
861                 ResourceOperationStatus updateStatus = new ResourceOperationStatus()
862                 updateStatus.setServiceId(serviceId)
863                 updateStatus.setOperationId(jobId)
864                 updateStatus.setResourceTemplateUUID(nsiId)
865                 updateStatus.setResourceInstanceID(nssiId)
866                 updateStatus.setOperType("Allocate")
867                 updateStatus.setProgress("100")
868                 updateStatus.setStatus("finished")
869                 requestDBUtil.prepareUpdateResourceOperationStatus(execution, updateStatus)
870
871                 logger.debug(Prefix + "prepareOperationStatusUpdate Exit")
872         }
873
874         def prepareFailedOperationStatusUpdate = { DelegateExecution execution ->
875                 logger.debug(Prefix + "prepareFailedOperationStatusUpdate Start")
876                 
877                 String serviceId = execution.getVariable("dummyServiceId")
878                 String jobId = execution.getVariable("jobId")
879                 String nsiId = execution.getVariable("nsiId")
880                 String nssiId = execution.getVariable("RANServiceInstanceId")
881                 logger.debug("Service Instance serviceId:" + serviceId + " jobId:" + jobId)
882
883                 ResourceOperationStatus updateStatus = new ResourceOperationStatus()
884                 updateStatus.setServiceId(serviceId)
885                 updateStatus.setOperationId(jobId)
886                 updateStatus.setResourceTemplateUUID(nsiId)
887                 updateStatus.setResourceInstanceID(nssiId)
888                 updateStatus.setOperType("Allocate")
889                 updateStatus.setProgress("0")
890                 updateStatus.setStatus("failed")
891                 requestDBUtil.prepareUpdateResourceOperationStatus(execution, updateStatus)
892         }
893         
894         private String buildSdnrAllocateRequest(DelegateExecution execution, String action, String rpcName, String callbackUrl) {
895                 
896                 String requestId = execution.getVariable("msoRequestId")
897                 Map<String,Object> sliceProfile = objectMapper.readValue(execution.getVariable("ranNfSliceProfile"), Map.class)
898                 sliceProfile.put("sliceProfileId", execution.getVariable("ANNF_sliceProfileInstanceId"))
899                 sliceProfile.put("maxNumberofConns", sliceProfile.get("maxNumberofPDUSessions"))
900                 sliceProfile.put("uLThptPerSlice", sliceProfile.get("expDataRateUL"))
901                 sliceProfile.put("dLThptPerSlice", sliceProfile.get("expDataRateDL"))
902                 String sliceProfileString = objectMapper.writeValueAsString(sliceProfile)
903                 JsonObject response = new JsonObject()
904                 JsonObject body = new JsonObject()
905                 JsonObject input = new JsonObject()
906                 JsonObject commonHeader = new JsonObject()
907                 JsonObject payload = new JsonObject()
908                 JsonObject payloadInput = new JsonObject()
909                 commonHeader.addProperty("TimeStamp",new Date(System.currentTimeMillis()).format("yyyy-MM-dd'T'HH:mm:ss.sss", TimeZone.getDefault()))
910                 commonHeader.addProperty("APIver", "1.0")
911                 commonHeader.addProperty("RequestID", requestId)
912                 commonHeader.addProperty("SubRequestID", "1")
913                 commonHeader.add("RequestTrack", new JsonObject())
914                 commonHeader.add("Flags", new JsonObject())
915                 payloadInput.addProperty("sliceProfile", sliceProfileString)
916                 payloadInput.addProperty("RANNSSIId", execution.getVariable("RANServiceInstanceId"))
917                 payloadInput.addProperty("NSIID", execution.getVariable("nsiId"))
918                 payloadInput.addProperty("RANNFNSSIId", execution.getVariable("RANNFServiceInstanceId"))
919                 payloadInput.addProperty("callbackURL", callbackUrl)
920                 payloadInput.add("additionalproperties", new JsonObject())
921                 payload.add("input", payloadInput)
922                 input.add("CommonHeader", commonHeader)
923                 input.addProperty("Action", action)
924                 input.addProperty("Payload", payload.toString())
925                 body.add("input", input)
926                 response.add("body", body)
927                 response.addProperty("version", "1.0")
928                 response.addProperty("rpc-name", rpcName)
929                 response.addProperty("correlation-id", (requestId+"-1"))
930                 response.addProperty("type", "request")
931                 return response.toString()
932         }
933         
934         private void createEndPointsInAai(DelegateExecution execution) {
935                 String type = "endpoint"
936                 String function = "transport_EP"
937                 int prefixLength = 24
938                 String addressFamily = "ipv4"
939                 //BH RAN end point update
940                 String bh_endpoint = execution.getVariable("bh_endpoint")
941                 String bh_routeId = UUID.randomUUID().toString()
942                 execution.setVariable("tranportEp_ID_bh", bh_routeId)
943                 String role = "CU"
944                 String CU_IpAddress = jsonUtil.getJsonValue(bh_endpoint, "IpAddress")
945                 String LogicalLinkId = jsonUtil.getJsonValue(bh_endpoint, "LogicalLinkId")
946                 String nextHopInfo = jsonUtil.getJsonValue(bh_endpoint, "nextHopInfo")
947                 NetworkRoute bh_ep = new NetworkRoute()
948                 bh_ep.setRouteId(bh_routeId)
949                 bh_ep.setFunction(function)
950                 bh_ep.setRole(role)
951                 bh_ep.setType(type)
952                 bh_ep.setIpAddress(CU_IpAddress)
953                 bh_ep.setLogicalInterfaceId(LogicalLinkId)
954                 bh_ep.setNextHop(nextHopInfo)
955                 bh_ep.setPrefixLength(prefixLength)
956                 bh_ep.setAddressFamily(addressFamily)
957                 //FH RAN end points update
958                 //RU
959                 String RU_routeId = UUID.randomUUID().toString()
960                 execution.setVariable("tranportEp_ID_RU", RU_routeId)
961                 role = "RU"
962                 NetworkRoute RU_ep = new NetworkRoute()
963                 RU_ep.setRouteId(RU_routeId)
964                 RU_ep.setFunction(function)
965                 RU_ep.setRole(role)
966                 RU_ep.setType(type)
967                 RU_ep.setIpAddress("192.168.100.4")
968                 RU_ep.setLogicalInterfaceId("1234")
969                 RU_ep.setNextHop("Host1")
970                 RU_ep.setPrefixLength(prefixLength)
971                 RU_ep.setAddressFamily(addressFamily)
972                 //DU Ingress
973                 String DUIN_routeId = UUID.randomUUID().toString()
974                 execution.setVariable("tranportEp_ID_DUIN", DUIN_routeId)
975                 role = "DU"
976                 NetworkRoute DU_ep = new NetworkRoute()
977                 DU_ep.setRouteId(DUIN_routeId)
978                 DU_ep.setFunction(function)
979                 DU_ep.setRole(role)
980                 DU_ep.setType(type)
981                 DU_ep.setIpAddress("192.168.100.5")
982                 DU_ep.setLogicalInterfaceId("1234")
983                 DU_ep.setNextHop("Host2")
984                 DU_ep.setPrefixLength(prefixLength)
985                 DU_ep.setAddressFamily(addressFamily)
986                 //MH RAN end point update
987                 //DUEG
988                 String DUEG_routeId = UUID.randomUUID().toString()
989                 execution.setVariable("tranportEp_ID_DUEG", DUEG_routeId)
990                 NetworkRoute DUEG_ep = new NetworkRoute()
991                 DUEG_ep.setRouteId(DUEG_routeId)
992                 DUEG_ep.setFunction(function)
993                 DUEG_ep.setRole(role)
994                 DUEG_ep.setType(type)
995                 DUEG_ep.setIpAddress("192.168.100.5")
996                 DUEG_ep.setLogicalInterfaceId("1234")
997                 DUEG_ep.setPrefixLength(prefixLength)
998                 DUEG_ep.setAddressFamily(addressFamily)
999                 DUEG_ep.setNextHop("Host3")
1000                 //CUIN
1001                 String CUIN_routeId = UUID.randomUUID().toString()
1002                 execution.setVariable("tranportEp_ID_CUIN", CUIN_routeId)
1003                 NetworkRoute CUIN_ep = new NetworkRoute()
1004                 CUIN_ep.setRouteId(CUIN_routeId)
1005                 CUIN_ep.setFunction(function)
1006                 CUIN_ep.setRole(role)
1007                 CUIN_ep.setType(type)
1008                 CUIN_ep.setIpAddress("192.168.100.6")
1009                 CUIN_ep.setLogicalInterfaceId("1234")
1010                 CUIN_ep.setNextHop("Host4")
1011                 CUIN_ep.setPrefixLength(prefixLength)
1012                 CUIN_ep.setAddressFamily(addressFamily)
1013                 try {
1014                         AAIResourcesClient client = new AAIResourcesClient()
1015                         logger.debug("creating bh endpoint . ID : "+bh_routeId+" node details : "+bh_ep.toString())
1016                         AAIResourceUri networkRouteUri = AAIUriFactory.createResourceUri( new AAIObjectType(AAINamespaceConstants.NETWORK, NetworkRoute.class), bh_routeId)
1017                         client.create(networkRouteUri, bh_ep)
1018                         logger.debug("creating RU endpoint . ID : "+RU_routeId+" node details : "+RU_ep.toString())
1019                         networkRouteUri = AAIUriFactory.createResourceUri( new AAIObjectType(AAINamespaceConstants.NETWORK, NetworkRoute.class), RU_routeId)
1020                         client.create(networkRouteUri, RU_ep)
1021                         logger.debug("creating DUIN endpoint . ID : "+DUIN_routeId+" node details : "+DU_ep.toString())
1022                         networkRouteUri = AAIUriFactory.createResourceUri( new AAIObjectType(AAINamespaceConstants.NETWORK, NetworkRoute.class), DUIN_routeId)
1023                         client.create(networkRouteUri, DU_ep)
1024                         logger.debug("creating DUEG endpoint . ID : "+DUEG_routeId+" node details : "+DUEG_ep.toString())
1025                         networkRouteUri = AAIUriFactory.createResourceUri( new AAIObjectType(AAINamespaceConstants.NETWORK, NetworkRoute.class), DUEG_routeId)
1026                         client.create(networkRouteUri, DUEG_ep)
1027                         logger.debug("creating CUIN endpoint . ID : "+CUIN_routeId+" node details : "+CUIN_ep.toString())
1028                         networkRouteUri = AAIUriFactory.createResourceUri( new AAIObjectType(AAINamespaceConstants.NETWORK, NetworkRoute.class), CUIN_routeId)
1029                         client.create(networkRouteUri, CUIN_ep)
1030                         //relationship b/w bh_ep and RAN NSSI
1031                         def AN_NSSI = execution.getVariable("RANServiceInstanceId")
1032                         Relationship relationship = new Relationship()
1033                         String relatedLink = "aai/v21/network/network-routes/network-route/${bh_routeId}"               
1034                         relationship.setRelatedLink(relatedLink)
1035                         relationship.setRelatedTo("network-route")
1036                         relationship.setRelationshipLabel("org.onap.relationships.inventory.ComposedOf")
1037                         anNssmfUtils.createRelationShipInAAI(execution, relationship, AN_NSSI)
1038                         def ANNF_serviceInstanceId = execution.getVariable("RANNFServiceInstanceId")
1039                         relatedLink = "aai/v21/network/network-routes/network-route/${RU_routeId}"
1040                         relationship.setRelatedLink(relatedLink)
1041                         anNssmfUtils.createRelationShipInAAI(execution, relationship, ANNF_serviceInstanceId)
1042                         relatedLink = "aai/v21/network/network-routes/network-route/${DUIN_routeId}"
1043                         relationship.setRelatedLink(relatedLink)
1044                         anNssmfUtils.createRelationShipInAAI(execution, relationship, ANNF_serviceInstanceId)
1045                         relatedLink = "aai/v21/network/network-routes/network-route/${DUEG_routeId}"
1046                         relationship.setRelatedLink(relatedLink)
1047                         anNssmfUtils.createRelationShipInAAI(execution, relationship, ANNF_serviceInstanceId)
1048                         relatedLink = "aai/v21/network/network-routes/network-route/${CUIN_routeId}"
1049                         relationship.setRelatedLink(relatedLink)
1050                         anNssmfUtils.createRelationShipInAAI(execution, relationship, ANNF_serviceInstanceId)
1051                 } catch (BpmnError e) {
1052                 throw e
1053         } catch (Exception ex) {
1054                 String msg = "Exception in createEndPointsInAai " + ex.getMessage()
1055                 logger.info(msg)
1056                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
1057         }
1058         }
1059 }
1060