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