33724bd011ddfc1bfcc98a5f88b2c12be4a676aa
[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.google.gson.Gson
38 import com.fasterxml.jackson.databind.ObjectMapper
39 import com.google.gson.JsonArray
40 import com.google.gson.JsonParser
41 import org.onap.aai.domain.yang.Relationship
42 import org.onap.aaiclient.client.aai.AAIResourcesClient
43 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
44 import org.onap.so.beans.nsmf.AllocateTnNssi
45 import org.onap.so.bpmn.core.UrnPropertiesReader
46 import org.onap.so.bpmn.core.domain.ServiceDecomposition
47 import org.onap.so.bpmn.core.domain.ServiceInstance
48 import org.onap.so.bpmn.core.domain.ServiceProxy
49 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
50 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
51 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
52 import org.onap.aaiclient.client.aai.AAINamespaceConstants
53 import org.onap.aaiclient.client.aai.AAIObjectType
54 import org.onap.aai.domain.yang.NetworkPolicy
55 import org.onap.aai.domain.yang.NetworkRoute
56
57 class DoAllocateAccessNSSI extends AbstractServiceTaskProcessor {
58
59         String Prefix="AASS_"
60         ExceptionUtil exceptionUtil = new ExceptionUtil()
61         RequestDBUtil requestDBUtil = new RequestDBUtil()
62         JsonUtils jsonUtil = new JsonUtils()
63         OofUtils oofUtils = new OofUtils()
64         AnNssmfUtils anNssmfUtils = new AnNssmfUtils()
65         ObjectMapper objectMapper = new ObjectMapper();
66         private NssmfAdapterUtils nssmfAdapterUtils = new NssmfAdapterUtils(httpClientFactory, jsonUtil)
67
68         private static final Logger logger = LoggerFactory.getLogger(DoAllocateAccessNSSI.class)
69
70         @Override
71         void preProcessRequest(DelegateExecution execution) {
72                 logger.debug(Prefix + "preProcessRequest Start")
73                 execution.setVariable("prefix", Prefix)
74                 execution.setVariable("startTime", System.currentTimeMillis())
75                 def msg
76                 try {
77
78                         logger.debug("input variables : msoRequestId - "+execution.getVariable("msoRequestId")
79                                         +" modelInvariantUuid - "+execution.getVariable("modelInvariantUuid")+
80                                         " modelUuid - "+execution.getVariable("modelUuid")+
81                                         " globalSubscriberId - "+execution.getVariable("globalSubscriberId")+
82                                         " dummyServiceId - "+ execution.getVariable("dummyServiceId")+
83                                         " nsiId - "+execution.getVariable("nsiId")+
84                                         " networkType - "+execution.getVariable("networkType")+
85                                         " subscriptionServiceType - "+execution.getVariable("subscriptionServiceType")+
86                                         " jobId - "+execution.getVariable("jobId")+
87                                         " sliceParams - "+execution.getVariable("sliceParams")+
88                                         " servicename - "+ execution.getVariable("servicename"))
89
90                         //validate slice subnet inputs
91
92                         String sliceParams = execution.getVariable("sliceParams")
93                         String sliceProfile = jsonUtil.getJsonValue(sliceParams, "sliceProfile")
94                         if (isBlank(sliceProfile)) {
95                                 msg = "Input sliceProfile is null"
96                                 logger.debug(msg)
97                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
98                         } else {
99                                 execution.setVariable("sliceProfile", sliceProfile)
100                         }
101                         String sliceProfileId = jsonUtil.getJsonValue(sliceProfile, "sliceProfileId")
102                         def snssaiList = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(sliceProfile, "snssaiList"))
103                         def plmnIdList = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(sliceProfile, "plmnIdList"))
104                         def coverageAreaTAList = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(sliceProfile, "coverageAreaTAList"))
105
106                         if (isBlank(sliceProfileId) || (snssaiList.empty) || (plmnIdList.empty)
107                         || (coverageAreaTAList.empty)) {
108
109                                 msg = "Mandatory slice profile fields are empty"
110                                 logger.debug(msg)
111                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
112                         } else {
113                                 execution.setVariable("sliceProfileId", sliceProfileId)
114                                 execution.setVariable("snssaiList", snssaiList)
115                                 execution.setVariable("plmnIdList", plmnIdList)
116                                 execution.setVariable("coverageAreaTAList", coverageAreaTAList)
117                         }
118                         String nsiName = jsonUtil.getJsonValue(sliceParams, "nsiInfo.nsiName")
119                         String scriptName = jsonUtil.getJsonValue(sliceParams, "scriptName")
120                         execution.setVariable("nsiName", nsiName)
121                         execution.setVariable("scriptName", scriptName)
122                         //generate RAN,RAN NF NSSIs - will be re assigned if oof returns existing NSSI
123                         String RANServiceInstanceId = UUID.randomUUID().toString()
124                         String RANNFServiceInstanceId = UUID.randomUUID().toString()
125                         logger.debug("RAN serviceInstance Id "+RANServiceInstanceId)
126                         logger.debug("RAN NF serviceInstance Id "+RANNFServiceInstanceId)                       
127                         execution.setVariable("RANServiceInstanceId", RANServiceInstanceId)
128                         execution.setVariable("RANNFServiceInstanceId", RANNFServiceInstanceId)
129                         execution.setVariable("ranNssiPreferReuse", true)
130                         execution.setVariable("ranNfNssiPreferReuse", true)
131                         execution.setVariable("job_timeout", 10)
132                         
133                         //set BH end point
134                         List<String> BH_endPoints = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(sliceParams, "endPoints"))
135                         logger.debug("BH end points list : "+BH_endPoints)
136                         if(BH_endPoints.empty) {
137                                 msg = "End point info is empty"
138                                 logger.debug(msg)
139                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
140                         }else {
141                                 execution.setVariable("bh_endpoint", BH_endPoints.get(0))
142                         }
143                         
144                 } catch(BpmnError e) {
145                         throw e
146                 } catch(Exception ex) {
147                         msg = "Exception in DoAllocateAccessNSSI.preProcessRequest " + ex.getMessage()
148                         logger.debug(msg)
149                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
150                 }
151                 logger.debug(Prefix + "preProcessRequest Exit")
152         }
153
154         /*
155          * Prepare request params for decomposing RAN NSST
156          */
157
158         def prepareDecomposeService = { DelegateExecution execution ->
159                 logger.debug(Prefix+"prepareDecomposeService method start")
160                 String RANServiceInstanceId = execution.getVariable("RANServiceInstanceId")
161                 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
162                 String modelUuid = execution.getVariable("modelUuid")
163                 String serviceModelInfo = """{
164             "modelInvariantUuid":"${modelInvariantUuid}",
165             "modelUuid":"${modelUuid}",
166             "modelVersion":""
167              }"""
168                 execution.setVariable("serviceModelInfo", serviceModelInfo)
169                 execution.setVariable("serviceInstanceId", RANServiceInstanceId)
170                 logger.debug("serviceModelInfo : "+serviceModelInfo)
171                 logger.debug("Finish RAN NSST prepareDecomposeService")
172         }
173
174         /* process the decompose service(RAN NSST) response
175          * 
176          */
177         def processDecomposition = { DelegateExecution execution ->
178                 logger.debug(Prefix+"processDecomposition method start")
179                 ServiceDecomposition ranNsstServiceDecomposition = execution.getVariable("ranNsstServiceDecomposition")
180                 logger.debug("ranNsstServiceDecomposition : "+ranNsstServiceDecomposition.toString())
181                 //RAN NSST decomposition
182                 String ranModelVersion = ranNsstServiceDecomposition.getModelInfo().getModelVersion()
183                 String ranModelName = ranNsstServiceDecomposition.getModelInfo().getModelName()
184                 List<ServiceProxy> serviceProxyList = ranNsstServiceDecomposition.getServiceProxy()
185                 List<String> nsstInfoList = new ArrayList<>()
186                 for(ServiceProxy serviceProxy : serviceProxyList)
187                 {
188                         String nsstModelUuid = serviceProxy.getSourceModelUuid()
189                         String nsstModelInvariantUuid = serviceProxy.getModelInfo().getModelInvariantUuid()
190                         String name = serviceProxy.getModelInfo().getModelName()
191                         String nsstServiceModelInfo = """{
192             "UUID":"${nsstModelUuid}",
193             "invariantUUID":"${nsstModelInvariantUuid}",
194             "name":"${name}"
195              }"""
196                         nsstInfoList.add(nsstServiceModelInfo)
197                 }
198                 int currentIndex=0
199                 int maxIndex=nsstInfoList.size()
200                 if(maxIndex < 1)
201                 {
202                         String msg = "Exception in RAN NSST processDecomposition. There is no NSST associated with RAN NSST "
203                         logger.info(msg)
204                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
205                 }
206                 execution.setVariable("ranNsstInfoList", objectMapper.writeValueAsString(nsstInfoList))
207                 execution.setVariable("ranModelVersion", ranModelVersion)
208                 execution.setVariable("ranModelName", ranModelName)
209                 execution.setVariable("currentIndex",currentIndex)
210                 execution.setVariable("maxIndex",maxIndex)
211                 logger.debug(Prefix+"processDecomposition maxIndex value - "+maxIndex)
212         }
213
214         /*
215          * Function to subnet capabilities from nssmf adapter
216          */
217         def getSubnetCapabilities = { DelegateExecution execution ->
218                 logger.debug(Prefix+"getSubnetCapabilities method start")
219
220                 String tnNssmfRequest = anNssmfUtils.buildCreateTNNSSMFSubnetCapabilityRequest()
221
222                 String urlString = "/api/rest/provMns/v1/NSS/subnetCapabilityQuery"
223
224                 String tnNssmfResponse = nssmfAdapterUtils.sendPostRequestNSSMF(execution, urlString, tnNssmfRequest)
225
226                 if (tnNssmfResponse != null) {
227                         String FHCapabilities= jsonUtil.getJsonValue(tnNssmfResponse, "TN_FH")
228                         String MHCapabilities = jsonUtil.getJsonValue(tnNssmfResponse, "TN_MH")
229                         execution.setVariable("FHCapabilities",FHCapabilities)
230                         execution.setVariable("MHCapabilities",MHCapabilities)
231
232                 } else {
233                         logger.error("received error message from NSSMF : "+ tnNssmfResponse)
234                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"Received a Bad Sync Response from NSSMF.")
235                 }
236                 String anNssmfRequest = anNssmfUtils.buildCreateANNFNSSMFSubnetCapabilityRequest()
237
238                 String anNssmfResponse = nssmfAdapterUtils.sendPostRequestNSSMF(execution, urlString, anNssmfRequest)
239
240                 if (anNssmfResponse != null) {
241                         String ANNFCapabilities = jsonUtil.getJsonValue(anNssmfResponse, "AN_NF")
242                         execution.setVariable("ANNFCapabilities",ANNFCapabilities)
243
244                 } else {
245                         logger.error("received error message from NSSMF : "+ anNssmfResponse)
246                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"Received a Bad Sync Response from NSSMF.")
247                 }
248         }
249
250         /*
251          * prepare OOF request for RAN NSSI selection
252          */
253         def prepareOofRequestForRanNSS = { DelegateExecution execution ->
254                 logger.debug(Prefix+"prepareOofRequestForRanNSS method start")
255
256                 String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution)
257                 logger.debug( "get NSSI option OOF Url: " + urlString)
258                 JsonParser parser = new JsonParser()
259                 //build oof request body
260                 boolean ranNssiPreferReuse = execution.getVariable("ranNssiPreferReuse");
261                 String requestId = execution.getVariable("msoRequestId")
262                 String messageType = "NSISelectionResponse"
263                 Map<String, Object> profileInfo = objectMapper.readValue(execution.getVariable("sliceProfile"), Map.class)
264                 String modelUuid = execution.getVariable("modelUuid")
265                 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
266                 String modelName = execution.getVariable("ranModelName")
267                 String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution);
268                 List<String> nsstInfoList =  objectMapper.readValue(execution.getVariable("ranNsstInfoList"), List.class)
269                 JsonArray capabilitiesList = new JsonArray()
270                 String FHCapabilities = execution.getVariable("FHCapabilities")
271                 String MHCapabilities = execution.getVariable("MHCapabilities")
272                 String ANNFCapabilities = execution.getVariable("ANNFCapabilities")
273                 JsonObject FH = new JsonObject()
274                 JsonObject MH = new JsonObject()
275                 JsonObject ANNF = new JsonObject()
276                 FH.addProperty("domainType", "TN_FH")
277                 FH.add("capabilityDetails", (JsonObject) parser.parse(FHCapabilities))
278                 MH.addProperty("domainType", "TN_MH")
279                 MH.add("capabilityDetails", (JsonObject) parser.parse(MHCapabilities))
280                 ANNF.addProperty("domainType", "AN_NF")
281                 ANNF.add("capabilityDetails", (JsonObject) parser.parse(ANNFCapabilities))
282                 capabilitiesList.add(FH)
283                 capabilitiesList.add(MH)
284                 capabilitiesList.add(ANNF)
285
286                 execution.setVariable("nssiSelection_Url", "/api/oof/selection/nsi/v1")
287                 execution.setVariable("nssiSelection_messageType",messageType)
288                 execution.setVariable("nssiSelection_correlator",requestId)
289                 execution.setVariable("nssiSelection_timeout",timeout)
290
291                 String oofRequest = anNssmfUtils.buildSelectRANNSSIRequest(requestId, messageType, modelUuid,modelInvariantUuid,
292                                 modelName, profileInfo, nsstInfoList, capabilitiesList, ranNssiPreferReuse)
293
294                 execution.setVariable("nssiSelection_oofRequest",oofRequest)
295                 logger.debug("Sending request to OOF: " + oofRequest)
296         }
297         /*
298          * process OOF response for RAN NSSI selection
299          */
300         def processOofResponseForRanNSS = { DelegateExecution execution ->
301                 logger.debug(Prefix+"processOofResponseForRanNSS method start")
302                 String oofResponse = execution.getVariable("nssiSelection_asyncCallbackResponse")
303                 String requestStatus = jsonUtil.getJsonValue(oofResponse, "requestStatus")
304                 if(requestStatus.equals("completed")) {
305                         String solutions = jsonUtil.getJsonValue(oofResponse, "solutions")
306                         logger.debug("solutions value : "+solutions)
307                         JsonParser parser = new JsonParser()
308                         JsonArray solution = parser.parse(solutions)
309                         JsonObject sol = solution.get(0)
310                         boolean existingNSI = sol.get("existingNSI").getAsBoolean()
311                         logger.debug("existingNSI value : "+existingNSI)
312                         if(existingNSI) {
313                                 JsonObject sharedNSISolution = sol.get("sharedNSISolution").getAsJsonObject()
314                                 execution.setVariable("sharedRanNSSISolution", sharedNSISolution.toString())
315                                 logger.debug("sharedRanNSSISolution from OOF "+sharedNSISolution)
316                                 String RANServiceInstanceId = sharedNSISolution.get("NSIId").getAsString()
317                                 execution.setVariable("RANServiceInstanceId", RANServiceInstanceId)
318                                 ServiceInstance serviceInstance = new ServiceInstance();
319                                 serviceInstance.setInstanceId(RANServiceInstanceId);
320                                 ServiceDecomposition serviceDecomposition = execution.getVariable("ranNsstServiceDecomposition")
321                                 serviceDecomposition.setServiceInstance(serviceInstance);
322                                 execution.setVariable("ranNsstServiceDecomposition", serviceDecomposition)
323                                 execution.setVariable("isRspRanNssi", true)
324                         }else {
325                                 JsonObject newNSISolution = sol.get("newNSISolution").getAsJsonObject()
326                                 JsonArray sliceProfiles = newNSISolution.get("slice_profiles").getAsJsonArray()
327                                 logger.debug("RanConstituentSliceProfiles list from OOF "+sliceProfiles)
328                                 execution.setVariable("RanConstituentSliceProfiles", sliceProfiles.toString())
329                         }
330                 }else {
331                         String statusMessage = jsonUtil.getJsonValue(oofResponse, "statusMessage")
332                         logger.error("received failed status from oof "+ statusMessage)
333                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"Received a failed Async Response from OOF : "+statusMessage)
334                 }
335
336         }
337
338         def prepareModifyAccessNssiInputs = { DelegateExecution execution ->
339                 logger.debug(Prefix+"prepareModifyAccessNssiInputs method start")
340                 String jobId = UUID.randomUUID().toString()
341                 execution.setVariable("modifyRanNssiJobId", jobId)              
342                 String snssaiList = execution.getVariable("snssaiList")
343                 String sliceParams = execution.getVariable("sliceParams")
344                 String sliceProfileId = execution.getVariable("sliceProfileId")
345                 String nsiInfo = jsonUtil.getJsonValue(sliceParams, "nsiInfo")
346                 String scriptName = execution.getVariable("scriptName")
347                 
348                 JsonObject modifySliceParams = new JsonObject()
349                 modifySliceParams.addProperty("modifyAction", "allocate")
350                 modifySliceParams.addProperty("snssaiList", snssaiList)
351                 modifySliceParams.addProperty("sliceProfileId", sliceProfileId)
352                 modifySliceParams.addProperty("nsiInfo", nsiInfo)
353                 modifySliceParams.addProperty("scriptName", scriptName)
354                 
355                 execution.setVariable("modifySliceParams", modifySliceParams.toString())
356                 //create operation status in request db
357                 String serviceId = execution.getVariable("RANServiceInstanceId")
358                 String nsiId = execution.getVariable("nsiId")
359                 logger.debug("Generated new job for Service Instance serviceId:" + serviceId + "jobId:" + jobId)
360
361                 ResourceOperationStatus initStatus = new ResourceOperationStatus()
362                 initStatus.setServiceId(serviceId)
363                 initStatus.setOperationId(jobId)
364                 initStatus.setResourceTemplateUUID(nsiId)
365                 initStatus.setOperType("Modify")
366                 requestDBUtil.prepareInitResourceOperationStatus(execution, initStatus)
367         }
368         
369         def createModifyNssiQueryJobStatus = { DelegateExecution execution ->
370                 logger.debug(Prefix+"createModifyNssiQueryJobStatus method start")
371                 JsonObject esrInfo = new JsonObject()
372             esrInfo.addProperty("networkType", "tn")
373             esrInfo.addProperty("vendor", "ONAP_internal")
374
375                 execution.setVariable("esrInfo", esrInfo.toString())
376                 JsonObject serviceInfo = new JsonObject()
377                 serviceInfo.addProperty("nssiId", execution.getVariable("RANServiceInstanceId"))
378                 serviceInfo.addProperty("nsiId", execution.getVariable("nsiId"))
379                 serviceInfo.addProperty("nssiName", execution.getVariable("servicename"))
380                 String sST = jsonUtil.getJsonValue(execution.getVariable("sliceProfile"), "sST")
381                 serviceInfo.addProperty("sST", sST)
382                 serviceInfo.addProperty("PLMNIdList", objectMapper.writeValueAsString(execution.getVariable("plmnIdList")))
383                 serviceInfo.addProperty("globalSubscriberId", execution.getVariable("globalSubscriberId"))
384                 serviceInfo.addProperty("subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
385                 serviceInfo.addProperty("serviceInvariantUuid", execution.getVariable("modelInvariantUuid"))
386                 serviceInfo.addProperty("serviceUuid", execution.getVariable("modelUuid"))
387                 execution.setVariable("serviceInfo", serviceInfo.toString())
388                 execution.setVariable("responseId", "")
389         }
390         def prepareNsstDecomposeService = { DelegateExecution execution ->
391                 logger.debug(Prefix+"prepareNsstDecomposeService method start")
392                 List<String> nsstInfoList = objectMapper.readValue(execution.getVariable("ranNsstInfoList"), List.class)
393                 int currentIndex = execution.getVariable("currentIndex")
394                 int maxIndex = execution.getVariable("maxIndex")
395                 logger.debug(Prefix+"prepareNsstDecomposeService : currentIndex value - "+currentIndex+" maxIndex : "+maxIndex)
396                 if(currentIndex<maxIndex) {
397                         String nsstInfo = nsstInfoList.get(currentIndex)
398                         String modelInvariantUuid = jsonUtil.getJsonValue(nsstInfo, "invariantUUID")
399                         String modelUuid = jsonUtil.getJsonValue(nsstInfo, "UUID")
400                         
401                         String serviceModelInfo = """{
402             "modelInvariantUuid":"${modelInvariantUuid}",
403             "modelUuid":"${modelUuid}",
404             "modelVersion":""
405              }"""
406                         execution.setVariable("serviceModelInfo", serviceModelInfo)
407                         execution.setVariable("serviceInstanceId", "")
408                         logger.debug("serviceModelInfo : "+serviceModelInfo)
409                         currentIndex++
410                         execution.setVariable("currentIndex", currentIndex)
411                 }else {
412                         logger.error("nsstList decomposition error ")
413                         exceptionUtil.buildAndThrowWorkflowException(execution, 1000, "nsstList decomposition error ")
414                 }
415                 
416         }
417         def processNsstDecomposition = { DelegateExecution execution ->
418                 logger.debug(Prefix+"processNsstDecomposition method start")
419                 ServiceDecomposition decomposedNsst = execution.getVariable("nsstServiceDecomposition")
420                 logger.debug("decomposedNsst : "+decomposedNsst.toString())
421                 
422                 String nsstType = decomposedNsst.getServiceRole() //domainType
423                 String modelVersion = decomposedNsst.getModelInfo().getModelVersion()
424                 String modelName = decomposedNsst.getModelInfo().getModelName()
425                 String modelUuid = decomposedNsst.getModelInfo().getModelUuid()
426                 String modelInvariantUuid = decomposedNsst.getModelInfo().getModelInvariantUuid()
427                 
428                 switch(nsstType) {
429                         case "AN_NF":
430                                 execution.setVariable("ANNF_modelInvariantUuid", modelInvariantUuid)
431                                 execution.setVariable("ANNF_modelUuid", modelUuid)
432                                 execution.setVariable("ANNF_modelVersion", modelVersion)
433                                 execution.setVariable("ANNF_modelName", modelName)
434                                 execution.setVariable("ANNF_ServiceDecomposition", decomposedNsst)
435                                 break
436                         case "TN_FH":
437                                 execution.setVariable("TNFH_modelInvariantUuid", modelInvariantUuid)
438                                 execution.setVariable("TNFH_modelUuid", modelUuid)
439                                 execution.setVariable("TNFH_modelVersion", modelVersion)
440                                 execution.setVariable("TNFH_modelName", modelName)
441                                 execution.setVariable("TNFH_ServiceDecomposition", decomposedNsst)
442                                 break
443                         case "TN_MH":
444                                 execution.setVariable("TNMH_modelInvariantUuid", modelInvariantUuid)
445                                 execution.setVariable("TNMH_modelUuid", modelUuid)
446                                 execution.setVariable("TNMH_modelVersion", modelVersion)
447                                 execution.setVariable("TNMH_modelName", modelName)
448                                 execution.setVariable("TNMH_ServiceDecomposition", decomposedNsst)
449                                 break
450                         default:
451                                 logger.debug("No expected match found for current nsstType")
452                                 logger.error("No expected match found for current nsstType "+ nsstType)
453                                 exceptionUtil.buildAndThrowWorkflowException(execution, 1000,"No expected match found for current nsstType "+ nsstType)
454                 }
455                 boolean isAllNsstsDecomposed = false
456                 int currentIndex = execution.getVariable("currentIndex")
457                 int maxIndex = execution.getVariable("maxIndex")
458                 if(currentIndex == maxIndex) {
459                         isAllNsstsDecomposed = true
460                 }
461                 execution.setVariable("isAllNsstsDecomposed", isAllNsstsDecomposed)
462         }
463         /*
464          * prepare OOF request for NF RAN NSSI selection
465          */
466         def prepareOofRequestForRanNfNSS = { DelegateExecution execution ->
467                 logger.debug(Prefix+"prepareOofRequestForRanNfNSS method start")
468                 String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution)
469                 logger.debug( "get NSSI option OOF Url: " + urlString)
470
471                 //build oof request body
472                 boolean ranNfNssiPreferReuse = execution.getVariable("ranNfNssiPreferReuse");
473                 String requestId = execution.getVariable("msoRequestId")
474                 String messageType = "NSSISelectionResponse"
475                 List<String> ranConstituentSliceProfiles = jsonUtil.StringArrayToList(execution.getVariable("RanConstituentSliceProfiles"))
476                 anNssmfUtils.createDomainWiseSliceProfiles(ranConstituentSliceProfiles, execution)
477                 Map<String, Object> profileInfo = objectMapper.readValue(execution.getVariable("ranNfSliceProfile"), Map.class)
478                 String modelUuid = execution.getVariable("ANNF_modelUuid")
479                 String modelInvariantUuid = execution.getVariable("ANNF_modelInvariantUuid")
480                 String modelName = execution.getVariable("ANNF_modelName")
481                 String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution);
482
483                 execution.setVariable("nssiSelection_Url", "/api/oof/selection/nssi/v1")
484                 execution.setVariable("nssiSelection_messageType",messageType)
485                 execution.setVariable("nssiSelection_correlator",requestId)
486                 execution.setVariable("nssiSelection_timeout",timeout)
487
488                 String oofRequest = oofUtils.buildSelectNSSIRequest(requestId, messageType, modelUuid, modelInvariantUuid, modelName, profileInfo)
489
490                 execution.setVariable("nssiSelection_oofRequest",oofRequest)
491         }
492         /*
493          * process OOF response for RAN NF NSSI selection
494          */
495         def processOofResponseForRanNfNSS = { DelegateExecution execution ->
496                 logger.debug(Prefix+"processOofResponseForRanNfNSS method start")
497                 String oofResponse = execution.getVariable("nfNssiSelection_asyncCallbackResponse")
498                 String requestStatus = jsonUtil.getJsonValue(oofResponse, "requestStatus")
499                 if(requestStatus.equals("completed")) {
500                         String solutions = jsonUtil.getJsonValue(oofResponse, "solutions")
501                         logger.debug("nssi solutions value : "+solutions)
502                         JsonParser parser = new JsonParser()
503                         JsonArray solution = parser.parse(solutions)            
504                         if(solution.size()>=1) {
505                                 JsonObject sol = solution.get(0)
506                                 String ranNfNssiId = sol.get("NSSIId").getAsString()
507                                 String invariantUuid = sol.get("invariantUUID").getAsString()
508                                 String uuid = sol.get("UUID").getAsString()
509                                 String nssiName = sol.get("NSSIName").getAsString()
510                                 execution.setVariable("RANNFServiceInstanceId", ranNfNssiId)
511                                 execution.setVariable("RANNFInvariantUUID", invariantUuid)
512                                 execution.setVariable("RANNFUUID", uuid)
513                                 execution.setVariable("RANNFNssiName", nssiName)
514                                 logger.debug("RANNFServiceInstanceId from OOF "+ranNfNssiId)
515                                 
516                                 ServiceInstance serviceInstance = new ServiceInstance();
517                                 serviceInstance.setInstanceId(ranNfNssiId);
518                                 ServiceDecomposition serviceDecomposition = execution.getVariable("ANNF_ServiceDecomposition")
519                                 serviceDecomposition.setServiceInstance(serviceInstance);
520                                 execution.setVariable("ANNF_ServiceDecomposition", serviceDecomposition)
521                                 execution.setVariable("isRspRanNfNssi", true)
522                         }else {
523                                 logger.debug("No solutions returned from OOF .. Create new RAN NF NSSI")
524                         }
525                 }else {
526                         String statusMessage = jsonUtil.getJsonValue(oofResponse, "statusMessage")
527                         logger.error("received failed status from oof "+ statusMessage)
528                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"Received a failed Async Response from OOF : "+statusMessage)
529                 }
530         }
531
532         def createSliceProfilesInAai = { DelegateExecution execution ->
533                 logger.debug(Prefix+"createSliceProfilesInAai method start")
534                 anNssmfUtils.createSliceProfilesInAai(execution)
535         }
536
537         def processRanNfModifyRsp = { DelegateExecution execution ->
538                 logger.debug(Prefix+"processRanNfModifyRsp method start")
539                 anNssmfUtils.processRanNfModifyRsp(execution)
540                 //create RAN NSSI 
541                 org.onap.aai.domain.yang.ServiceInstance ANServiceInstance = new org.onap.aai.domain.yang.ServiceInstance();
542                 //AN instance creation
543                 ANServiceInstance.setServiceInstanceId(execution.getVariable("RANServiceInstanceId"))
544                 String sliceInstanceName = execution.getVariable("servicename")
545                 ANServiceInstance.setServiceInstanceName(sliceInstanceName)
546                 String serviceType = jsonUtil.getJsonValue(execution.getVariable("sliceProfile"), "sST")
547                 ANServiceInstance.setServiceType(serviceType)
548                 String serviceStatus = "deactivated"
549                 ANServiceInstance.setOrchestrationStatus(serviceStatus)
550                 String serviceInstanceLocationid = jsonUtil.getJsonValue(execution.getVariable("sliceProfile"), "plmnIdList")
551                 ANServiceInstance.setServiceInstanceLocationId(serviceInstanceLocationid)
552                 String serviceRole = "nssi"
553                 ANServiceInstance.setServiceRole(serviceRole)
554                 List<String> snssaiList = objectMapper.readValue(execution.getVariable("snssaiList"), List.class)
555                 String snssai = snssaiList.get(0)
556                 ANServiceInstance.setEnvironmentContext(snssai)
557                 ANServiceInstance.setWorkloadContext("AN")
558                 
559                 logger.debug("completed AN service instance build "+ ANServiceInstance.toString())
560                 String msg = ""
561                 try {
562         
563                         AAIResourcesClient client = new AAIResourcesClient()
564                         AAIResourceUri nssiServiceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(execution.getVariable("RANServiceInstanceId")))
565                         client.create(nssiServiceUri, ANServiceInstance)
566         
567                 } catch (BpmnError e) {
568                         throw e
569                 } catch (Exception ex) {
570                         msg = "Exception in AnNssmfUtils.createSliceProfilesInAai " + ex.getMessage()
571                         logger.info(msg)
572                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
573                 }
574                 //end point update
575                 createEndPointsInAai(execution)
576         }
577         
578         def createSdnrRequest = { DelegateExecution execution ->
579                 logger.debug(Prefix+"createSdnrRequest method start")
580                 String callbackUrl = UrnPropertiesReader.getVariable("mso.workflow.message.endpoint") + "/AsyncSdnrResponse/"+execution.getVariable("msoRequestId")
581                 String sdnrRequest = buildSdnrAllocateRequest(execution, "allocate", "instantiateRANSlice", callbackUrl)
582                 execution.setVariable("createNSSI_sdnrRequest", sdnrRequest)
583                 execution.setVariable("createNSSI_timeout", "PT10M")
584                 execution.setVariable("createNSSI_correlator", execution.getVariable("msoRequestId"))
585                 execution.setVariable("createNSSI_messageType", "AsyncSdnrResponse");
586         }
587
588         def processSdnrResponse = { DelegateExecution execution ->
589                 logger.debug(Prefix+"processSdnrResponse method start")
590                 String SDNRResponse = execution.getVariable("SDNR_asyncCallbackResponse")
591                 String status = jsonUtil.getJsonValue(SDNRResponse, "status")
592                 if(status.equalsIgnoreCase("success")) {
593                         String nfIds = jsonUtil.getJsonValue(SDNRResponse, "nfIds")
594                         execution.setVariable("ranNfIdsJson", nfIds)
595                 }else {
596                         String reason = jsonUtil.getJsonValue(SDNRResponse, "reason")
597                         logger.error("received failed status from SDNR "+ reason)
598                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"received failed status from SDNR "+ reason)
599                 }
600                 logger.debug("response from SDNR "+SDNRResponse)
601         }
602
603         def updateAaiWithRANInstances = { DelegateExecution execution ->
604                 logger.debug(Prefix+"updateAaiWithRANInstances method start")
605                 //create RAN NSSI 
606                 org.onap.aai.domain.yang.ServiceInstance ANServiceInstance = new org.onap.aai.domain.yang.ServiceInstance();
607                 org.onap.aai.domain.yang.ServiceInstance ANNFServiceInstance = new org.onap.aai.domain.yang.ServiceInstance();
608                 //AN instance creation
609                 ANServiceInstance.setServiceInstanceId(execution.getVariable("RANServiceInstanceId"))
610                 String sliceInstanceName = execution.getVariable("servicename")
611                 ANServiceInstance.setServiceInstanceName(sliceInstanceName)
612                 String serviceType = jsonUtil.getJsonValue(execution.getVariable("sliceProfile"), "sST")
613                 ANServiceInstance.setServiceType(serviceType)
614                 String serviceStatus = "deactivated"
615                 ANServiceInstance.setOrchestrationStatus(serviceStatus)
616                 String serviceInstanceLocationid = jsonUtil.getJsonValue(execution.getVariable("sliceProfile"), "pLMNIdList")
617                 ANServiceInstance.setServiceInstanceLocationId(serviceInstanceLocationid)
618                 String serviceRole = "nssi"
619                 ANServiceInstance.setServiceRole(serviceRole)
620                 List<String> snssaiList = execution.getVariable("snssaiList")
621                 String snssai = snssaiList.get(0)
622                 ANServiceInstance.setEnvironmentContext(snssai)
623                 ANServiceInstance.setWorkloadContext("AN")
624                 String serviceFunctionAn = jsonUtil.getJsonValue(execution.getVariable("sliceProfile"), "resourceSharingLevel")
625                 ANServiceInstance.setServiceFunction(serviceFunctionAn)
626                 logger.debug("completed AN service instance build "+ ANServiceInstance.toString())
627                 //create RAN NF NSSI
628                 ANNFServiceInstance.setServiceInstanceId(execution.getVariable("RANNFServiceInstanceId"))
629                 sliceInstanceName = execution.getVariable("ANNF_modelName")
630                 ANNFServiceInstance.setServiceInstanceName(sliceInstanceName)
631                 ANNFServiceInstance.setServiceType(serviceType)
632                 ANNFServiceInstance.setOrchestrationStatus(serviceStatus)
633                 serviceInstanceLocationid = jsonUtil.getJsonValue(execution.getVariable("ranNfSliceProfile"), "pLMNIdList")
634                 ANNFServiceInstance.setServiceInstanceLocationId(serviceInstanceLocationid)
635                 ANNFServiceInstance.setServiceRole(serviceRole)
636                 snssaiList = execution.getVariable("snssaiList")
637                 snssai = snssaiList.get(0)
638                 ANNFServiceInstance.setEnvironmentContext(snssai)
639                 ANNFServiceInstance.setWorkloadContext("AN-NF")
640                 String serviceFunctionAnnf = jsonUtil.getJsonValue(execution.getVariable("ranNfSliceProfile"), "resourceSharingLevel")
641                 ANNFServiceInstance.setServiceFunction(serviceFunctionAnnf)
642                 logger.debug("completed AN service instance build "+ ANNFServiceInstance.toString())
643                 
644                 String msg = ""
645                 try {
646         
647                         AAIResourcesClient client = new AAIResourcesClient()
648                         AAIResourceUri nssiServiceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(execution.getVariable("RANServiceInstanceId")))
649                         client.create(nssiServiceUri, ANServiceInstance)
650         
651                         AAIResourceUri nssiServiceUri1 = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(execution.getVariable("RANNFServiceInstanceId")))
652                         client.create(nssiServiceUri1, ANNFServiceInstance)
653         
654                 } catch (BpmnError e) {
655                         throw e
656                 } catch (Exception ex) {
657                         msg = "Exception in AnNssmfUtils.createSliceProfilesInAai " + ex.getMessage()
658                         logger.info(msg)
659                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
660                 }
661                 //end point update
662                 createEndPointsInAai(execution)
663         }
664         def prepareTnFhRequest = { DelegateExecution execution ->
665                 logger.debug(Prefix+"prepareTnFhRequest method start")
666
667                 String nssmfRequest = anNssmfUtils.buildCreateNSSMFRequest(execution, "TN_FH", "allocate")
668                 String urlString = "/api/rest/provMns/v1/NSS/SliceProfiles"
669                 String nssmfResponse = nssmfAdapterUtils.sendPostRequestNSSMF(execution, urlString, nssmfRequest)
670
671                 if (nssmfResponse != null) {
672                         execution.setVariable("nssmfResponse", nssmfResponse)
673                         String jobId = jsonUtil.getJsonValue(nssmfResponse, "jobId")
674                         execution.setVariable("TNFH_jobId",jobId)
675                 } else {
676                         logger.error("received error message from NSSMF : "+ nssmfResponse)
677                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"Received a Bad Sync Response from NSSMF.")
678                 }
679                 logger.debug("Exit prepareTnFhRequest")
680
681         }
682         def prepareTnMhRequest = { DelegateExecution execution ->
683                 logger.debug(Prefix+"prepareTnMhRequest method start")
684
685                 String nssmfRequest = anNssmfUtils.buildCreateNSSMFRequest(execution, "TN_MH", "allocate")
686                 String urlString = "/api/rest/provMns/v1/NSS/SliceProfiles"
687                 String nssmfResponse = nssmfAdapterUtils.sendPostRequestNSSMF(execution, urlString, nssmfRequest)
688
689                 if (nssmfResponse != null) {
690                         execution.setVariable("nssmfResponse", nssmfResponse)
691                         String jobId = jsonUtil.getJsonValue(nssmfResponse, "jobId")
692                         execution.setVariable("TNMH_jobId",jobId)
693                 } else {
694                         logger.error("received error message from NSSMF : "+ nssmfResponse)
695                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"Received a Bad Sync Response from NSSMF.")
696                 }
697                 logger.debug("Exit prepareTnMhRequest")
698         }
699         
700         def createFhAllocateNssiJobQuery = { DelegateExecution execution ->
701                 logger.debug(Prefix+"createFhAllocateNssiJobQuery method start")
702                 createTnAllocateNssiJobQuery(execution, "TN_FH")                
703         }
704         
705         def createMhAllocateNssiJobQuery = { DelegateExecution execution ->
706                 logger.debug(Prefix+"createMhAllocateNssiJobQuery method start")
707                 createTnAllocateNssiJobQuery(execution, "TN_MH")
708         }
709         
710         private void createTnAllocateNssiJobQuery(DelegateExecution execution, String domainType) {
711                 JsonObject esrInfo = new JsonObject()
712             esrInfo.addProperty("networkType", "tn")
713             esrInfo.addProperty("vendor", "ONAP_internal")
714                 execution.setVariable("esrInfo", esrInfo.toString())
715                 JsonObject serviceInfo = new JsonObject()
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, "status")
740                 String nssi = jsonUtil.getJsonValue(jobResponse, "nssiId")
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, "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, "status")
757                 String nssi = jsonUtil.getJsonValue(jobResponse, "nssiId")
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, "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, "status")
774                 String nssi = jsonUtil.getJsonValue(jobResponse, "nssiId")
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, "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
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'Z'", TimeZone.getDefault()))
910                 commonHeader.addProperty("api-ver", "1.0")
911                 commonHeader.addProperty("request-id", requestId)
912                 commonHeader.addProperty("sub-request-id", "1")
913                 commonHeader.add("request-track", new JsonObject())
914                 commonHeader.add("flags", new JsonObject())
915                 Gson jsonConverter = new Gson() 
916                 payloadInput.add("sliceProfile", jsonConverter.toJsonTree(sliceProfile))
917                 payloadInput.addProperty("RANNSSIId", execution.getVariable("RANServiceInstanceId"))
918                 payloadInput.addProperty("NSIID", execution.getVariable("nsiId"))
919                 payloadInput.addProperty("RANNFNSSIId", execution.getVariable("RANNFServiceInstanceId"))
920                 payloadInput.addProperty("callbackURL", callbackUrl)
921                 payloadInput.add("additionalproperties", new JsonObject())
922                 payload.add("input", payloadInput)
923                 input.add("common-header", commonHeader)
924                 input.addProperty("action", action)
925                 input.addProperty("payload", payload.toString())
926                 body.add("input", input)
927                 response.add("body", body)
928                 response.addProperty("version", "1.0")
929                 response.addProperty("rpc-name", rpcName)
930                 response.addProperty("correlation-id", (requestId+"-1"))
931                 response.addProperty("type", "request")
932                 return response.toString()
933         }
934         
935         private void createEndPointsInAai(DelegateExecution execution) {
936                 String type = "endpoint"
937                 String function = "transport_EP"
938                 int prefixLength = 24
939                 String addressFamily = "ipv4"
940                 //BH RAN end point update
941                 String bh_endpoint = execution.getVariable("bh_endpoint")
942                 String bh_routeId = UUID.randomUUID().toString()
943                 execution.setVariable("tranportEp_ID_bh", bh_routeId)
944                 String role = "CU"
945                 String CU_IpAddress = jsonUtil.getJsonValue(bh_endpoint, "IpAddress")
946                 String LogicalLinkId = jsonUtil.getJsonValue(bh_endpoint, "LogicalLinkId")
947                 String nextHopInfo = jsonUtil.getJsonValue(bh_endpoint, "nextHopInfo")
948                 NetworkRoute bh_ep = new NetworkRoute()
949                 bh_ep.setRouteId(bh_routeId)
950                 bh_ep.setFunction(function)
951                 bh_ep.setRole(role)
952                 bh_ep.setType(type)
953                 bh_ep.setIpAddress(CU_IpAddress)
954                 bh_ep.setLogicalInterfaceId(LogicalLinkId)
955                 bh_ep.setNextHop(nextHopInfo)
956                 bh_ep.setPrefixLength(prefixLength)
957                 bh_ep.setAddressFamily(addressFamily)
958                 //FH RAN end points update
959                 //RU
960                 String RU_routeId = UUID.randomUUID().toString()
961                 execution.setVariable("tranportEp_ID_RU", RU_routeId)
962                 role = "RU"
963                 NetworkRoute RU_ep = new NetworkRoute()
964                 RU_ep.setRouteId(RU_routeId)
965                 RU_ep.setFunction(function)
966                 RU_ep.setRole(role)
967                 RU_ep.setType(type)
968                 RU_ep.setIpAddress("192.168.100.4")
969                 RU_ep.setLogicalInterfaceId("1234")
970                 RU_ep.setNextHop("Host1")
971                 RU_ep.setPrefixLength(prefixLength)
972                 RU_ep.setAddressFamily(addressFamily)
973                 //DU Ingress
974                 String DUIN_routeId = UUID.randomUUID().toString()
975                 execution.setVariable("tranportEp_ID_DUIN", DUIN_routeId)
976                 role = "DU"
977                 NetworkRoute DU_ep = new NetworkRoute()
978                 DU_ep.setRouteId(DUIN_routeId)
979                 DU_ep.setFunction(function)
980                 DU_ep.setRole(role)
981                 DU_ep.setType(type)
982                 DU_ep.setIpAddress("192.168.100.5")
983                 DU_ep.setLogicalInterfaceId("1234")
984                 DU_ep.setNextHop("Host2")
985                 DU_ep.setPrefixLength(prefixLength)
986                 DU_ep.setAddressFamily(addressFamily)
987                 //MH RAN end point update
988                 //DUEG
989                 String DUEG_routeId = UUID.randomUUID().toString()
990                 execution.setVariable("tranportEp_ID_DUEG", DUEG_routeId)
991                 NetworkRoute DUEG_ep = new NetworkRoute()
992                 DUEG_ep.setRouteId(DUEG_routeId)
993                 DUEG_ep.setFunction(function)
994                 DUEG_ep.setRole(role)
995                 DUEG_ep.setType(type)
996                 DUEG_ep.setIpAddress("192.168.100.5")
997                 DUEG_ep.setLogicalInterfaceId("1234")
998                 DUEG_ep.setPrefixLength(prefixLength)
999                 DUEG_ep.setAddressFamily(addressFamily)
1000                 DUEG_ep.setNextHop("Host3")
1001                 //CUIN
1002                 String CUIN_routeId = UUID.randomUUID().toString()
1003                 execution.setVariable("tranportEp_ID_CUIN", CUIN_routeId)
1004                 NetworkRoute CUIN_ep = new NetworkRoute()
1005                 CUIN_ep.setRouteId(CUIN_routeId)
1006                 CUIN_ep.setFunction(function)
1007                 CUIN_ep.setRole(role)
1008                 CUIN_ep.setType(type)
1009                 CUIN_ep.setIpAddress("192.168.100.6")
1010                 CUIN_ep.setLogicalInterfaceId("1234")
1011                 CUIN_ep.setNextHop("Host4")
1012                 CUIN_ep.setPrefixLength(prefixLength)
1013                 CUIN_ep.setAddressFamily(addressFamily)
1014                 try {
1015                         AAIResourcesClient client = new AAIResourcesClient()
1016                         logger.debug("creating bh endpoint . ID : "+bh_routeId+" node details : "+bh_ep.toString())
1017                         AAIResourceUri networkRouteUri = AAIUriFactory.createResourceUri( new AAIObjectType(AAINamespaceConstants.NETWORK, NetworkRoute.class), bh_routeId)
1018                         client.create(networkRouteUri, bh_ep)
1019                         logger.debug("creating RU endpoint . ID : "+RU_routeId+" node details : "+RU_ep.toString())
1020                         networkRouteUri = AAIUriFactory.createResourceUri( new AAIObjectType(AAINamespaceConstants.NETWORK, NetworkRoute.class), RU_routeId)
1021                         client.create(networkRouteUri, RU_ep)
1022                         logger.debug("creating DUIN endpoint . ID : "+DUIN_routeId+" node details : "+DU_ep.toString())
1023                         networkRouteUri = AAIUriFactory.createResourceUri( new AAIObjectType(AAINamespaceConstants.NETWORK, NetworkRoute.class), DUIN_routeId)
1024                         client.create(networkRouteUri, DU_ep)
1025                         logger.debug("creating DUEG endpoint . ID : "+DUEG_routeId+" node details : "+DUEG_ep.toString())
1026                         networkRouteUri = AAIUriFactory.createResourceUri( new AAIObjectType(AAINamespaceConstants.NETWORK, NetworkRoute.class), DUEG_routeId)
1027                         client.create(networkRouteUri, DUEG_ep)
1028                         logger.debug("creating CUIN endpoint . ID : "+CUIN_routeId+" node details : "+CUIN_ep.toString())
1029                         networkRouteUri = AAIUriFactory.createResourceUri( new AAIObjectType(AAINamespaceConstants.NETWORK, NetworkRoute.class), CUIN_routeId)
1030                         client.create(networkRouteUri, CUIN_ep)
1031                         //relationship b/w bh_ep and RAN NSSI
1032                         def AN_NSSI = execution.getVariable("RANServiceInstanceId")
1033                         Relationship relationship = new Relationship()
1034                         String relatedLink = "aai/v21/network/network-routes/network-route/${bh_routeId}"               
1035                         relationship.setRelatedLink(relatedLink)
1036                         relationship.setRelatedTo("network-route")
1037                         relationship.setRelationshipLabel("org.onap.relationships.inventory.ComposedOf")
1038                         anNssmfUtils.createRelationShipInAAI(execution, relationship, AN_NSSI)
1039                         def ANNF_serviceInstanceId = execution.getVariable("RANNFServiceInstanceId")
1040                         relatedLink = "aai/v21/network/network-routes/network-route/${RU_routeId}"
1041                         relationship.setRelatedLink(relatedLink)
1042                         anNssmfUtils.createRelationShipInAAI(execution, relationship, ANNF_serviceInstanceId)
1043                         relatedLink = "aai/v21/network/network-routes/network-route/${DUIN_routeId}"
1044                         relationship.setRelatedLink(relatedLink)
1045                         anNssmfUtils.createRelationShipInAAI(execution, relationship, ANNF_serviceInstanceId)
1046                         relatedLink = "aai/v21/network/network-routes/network-route/${DUEG_routeId}"
1047                         relationship.setRelatedLink(relatedLink)
1048                         anNssmfUtils.createRelationShipInAAI(execution, relationship, ANNF_serviceInstanceId)
1049                         relatedLink = "aai/v21/network/network-routes/network-route/${CUIN_routeId}"
1050                         relationship.setRelatedLink(relatedLink)
1051                         anNssmfUtils.createRelationShipInAAI(execution, relationship, ANNF_serviceInstanceId)
1052                 } catch (BpmnError e) {
1053                 throw e
1054         } catch (Exception ex) {
1055                 String msg = "Exception in createEndPointsInAai " + ex.getMessage()
1056                 logger.info(msg)
1057                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
1058         }
1059         }
1060 }
1061