079a31be9485d429c89e72e67119ddf8ea409a35
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  # Copyright (c) 2020, CMCC Technologies Co., Ltd.
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 com.fasterxml.jackson.databind.ObjectMapper
24 import org.camunda.bpm.engine.delegate.DelegateExecution
25 import org.onap.so.beans.nsmf.AnSliceProfile
26 import org.onap.so.beans.nsmf.CnSliceProfile
27 import org.onap.so.beans.nsmf.EsrInfo
28 import org.onap.so.beans.nsmf.NetworkType
29 import org.onap.so.beans.nsmf.NssmfAdapterNBIRequest
30 import org.onap.so.beans.nsmf.SliceTaskParamsAdapter
31 import org.onap.so.beans.nsmf.TnSliceProfile
32 import org.onap.so.beans.nsmf.oof.SubnetCapability
33 import org.onap.so.beans.nsmf.oof.SubnetType
34 import org.onap.so.beans.nsmf.oof.TemplateInfo
35 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
36 import org.onap.so.bpmn.common.scripts.ExceptionUtil
37 import org.onap.so.bpmn.common.scripts.NssmfAdapterUtils
38 import org.onap.so.bpmn.common.scripts.OofUtils
39 import org.onap.so.bpmn.core.UrnPropertiesReader
40 import org.onap.so.bpmn.core.domain.AllottedResource
41 import org.onap.so.bpmn.core.domain.ModelInfo
42 import org.onap.so.bpmn.core.domain.ServiceDecomposition
43 import org.onap.so.bpmn.core.json.JsonUtils
44 import org.slf4j.Logger
45 import org.slf4j.LoggerFactory
46 import org.springframework.http.ResponseEntity
47
48 class DoCreateSliceServiceOption extends AbstractServiceTaskProcessor{
49
50     private static final Logger logger = LoggerFactory.getLogger(DoCreateSliceServiceOption.class)
51
52     ExceptionUtil exceptionUtil = new ExceptionUtil()
53
54     JsonUtils jsonUtil = new JsonUtils()
55
56     OofUtils oofUtils = new OofUtils()
57
58     private static final ObjectMapper objectMapper = new ObjectMapper()
59
60     private NssmfAdapterUtils nssmfAdapterUtils = new NssmfAdapterUtils(httpClientFactory, jsonUtil)
61
62     private static final String QUERY_SUB_NET_CAPABILITY = "/api/rest/provMns/v1/NSS/subnetCapabilityQuery"
63
64     private static final String QUERY_NSSI_SELECTION_CAPABILITY = "/api/rest/provMns/v1/NSS/NSSISelectionCapability"
65
66     void preProcessRequest (DelegateExecution execution) {
67     }
68
69     /**
70      * prepare the params for decompose nst
71      * @param execution
72      */
73     public void prepareDecomposeNST(DelegateExecution execution) {
74
75         SliceTaskParamsAdapter sliceTaskParams =
76                 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
77
78         String modelUuid = sliceTaskParams.getNSTInfo().getUUID()
79         String modelInvariantUuid = sliceTaskParams.getNSTInfo().getInvariantUUID()
80
81         String serviceModelInfo = """{
82             "modelInvariantUuid":"${modelInvariantUuid}",
83             "modelUuid":"${modelUuid}",
84             "modelVersion":""
85              }"""
86         execution.setVariable("nstServiceModelInfo", serviceModelInfo)
87     }
88
89     /**
90      * process the result of NST Decomposition
91      * @param execution
92      */
93     public void processDecompositionNST(DelegateExecution execution) {
94
95         List<TemplateInfo> nsstInfos = new ArrayList<>()
96         ServiceDecomposition nstServiceDecomposition =
97                 execution.getVariable("nstServiceDecomposition") as ServiceDecomposition
98         //todo:
99         List<AllottedResource> allottedResources = nstServiceDecomposition.getAllottedResources()
100         for (AllottedResource allottedResource : allottedResources) {
101             TemplateInfo nsstInfo = new TemplateInfo()
102             nsstInfo.setUUID(allottedResource.getProvidingServiceModelUuid())
103             nsstInfo.setInvariantUUID(allottedResource.getProvidingServiceModelInvariantUuid())
104             nsstInfo.setName(allottedResource.getProvidingServiceModelName())
105             nsstInfos.add(nsstInfo)
106         }
107         execution.setVariable("nsstInfos", nsstInfos)
108
109         execution.setVariable("maxNsstIndex", allottedResources.size() - 1)
110         execution.setVariable("currentNsstIndex", 0)
111
112         List<ServiceDecomposition> nsstServiceDecompositions = new ArrayList<>()
113         execution.setVariable("nsstServiceDecompositions", nsstServiceDecompositions)
114     }
115
116     /**
117      * prepare the params for decompose nsst
118      * @param execution
119      */
120     public void prepareDecomposeNSST(DelegateExecution execution) {
121
122         List<TemplateInfo> nsstInfos = execution.getVariable("nsstInfos") as List<TemplateInfo>
123         int index = execution.getVariable("currentNsstIndex") as Integer
124
125         String modelUuid = nsstInfos.get(index).getUUID()
126         String modelInvariantUuid = nsstInfos.get(index).getInvariantUUID()
127
128         String serviceModelInfo = """{
129             "modelInvariantUuid":"${modelInvariantUuid}",
130             "modelUuid":"${modelUuid}",
131             "modelVersion":""
132              }"""
133         execution.setVariable("nsstServiceModelInfo", serviceModelInfo)
134
135     }
136
137     /**
138      * process the result of NSST Decomposition
139      * @param execution
140      */
141     public void processDecompositionNSST(DelegateExecution execution) {
142
143         List<ServiceDecomposition> nsstServiceDecompositions =
144                 execution.getVariable("nsstServiceDecompositions") as List<ServiceDecomposition>
145
146         ServiceDecomposition nsstServiceDecomposition =
147                 execution.getVariable("nsstServiceDecomposition") as ServiceDecomposition
148
149         nsstServiceDecompositions.add(nsstServiceDecomposition)
150
151         execution.setVariable("nsstServiceDecompositions", nsstServiceDecompositions)
152
153
154
155
156         int num = execution.getVariable("maxNsstIndex") as Integer
157         int index = execution.getVariable("currentNsstIndex") as Integer
158
159         execution.setVariable("currentNsstIndex", index + 1)
160
161         if (index >= num) {
162             execution.setVariable("nsstHandleContinue", false)
163         } else {
164             execution.setVariable("nsstHandleContinue", true)
165         }
166
167     }
168
169     /**
170      * set nsst info to sliceTaskParams by type
171      * @param execution
172      */
173     public void handleNsstByType(DelegateExecution execution) {
174
175         SliceTaskParamsAdapter sliceParams =
176                 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
177
178         List<ServiceDecomposition> nsstServiceDecompositions =
179                 execution.getVariable("nsstServiceDecompositions") as List<ServiceDecomposition>
180
181         List<SubnetCapability> subnetCapabilities = new ArrayList<>()
182
183
184
185         for (ServiceDecomposition serviceDecomposition : nsstServiceDecompositions) {
186             SubnetCapability subnetCapability = new SubnetCapability()
187             handleByType(execution, serviceDecomposition, sliceParams, subnetCapability)
188             subnetCapabilities.add(subnetCapability)
189         }
190
191         execution.setVariable("sliceTaskParams", sliceParams)
192         execution.setVariable("subnetCapabilities", subnetCapabilities)
193     }
194
195     private void handleByType(DelegateExecution execution, ServiceDecomposition serviceDecomposition,
196                               SliceTaskParamsAdapter sliceParams, SubnetCapability subnetCapability) {
197         //todo:
198         String domainType = ""
199         ModelInfo modelInfo = serviceDecomposition.getModelInfo()
200         String vendor = serviceDecomposition.getServiceRole()
201         SubnetType subnetType
202
203         switch (domainType) {
204             case "tn_bh":
205                 subnetType = SubnetType.TN_BH
206                 sliceParams.tnBHSliceTaskInfo.vendor = vendor
207                 sliceParams.tnBHSliceTaskInfo.subnetType = subnetType
208                 sliceParams.tnBHSliceTaskInfo.networkType = subnetType.networkType
209                 sliceParams.tnBHSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
210                 sliceParams.tnBHSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
211                 sliceParams.tnBHSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
212
213                 break
214             case "tn_mh":
215                 subnetType = SubnetType.TN_MH
216                 sliceParams.tnMHSliceTaskInfo.vendor = vendor
217                 sliceParams.tnMHSliceTaskInfo.subnetType = subnetType
218                 sliceParams.tnMHSliceTaskInfo.networkType = subnetType.networkType
219                 sliceParams.tnMHSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
220                 sliceParams.tnMHSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
221                 sliceParams.tnMHSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
222
223                 break
224             case "an_nf":
225                 subnetType = SubnetType.AN_NF
226                 sliceParams.anSliceTaskInfo.vendor = vendor
227                 sliceParams.anSliceTaskInfo.subnetType = subnetType
228                 sliceParams.anSliceTaskInfo.networkType = subnetType.networkType
229                 sliceParams.anSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
230                 sliceParams.anSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
231                 sliceParams.anSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
232                 break
233             case "cn":
234                 subnetType = SubnetType.CN
235                 sliceParams.cnSliceTaskInfo.vendor = vendor
236                 sliceParams.cnSliceTaskInfo.subnetType = subnetType
237                 sliceParams.cnSliceTaskInfo.networkType = subnetType.networkType
238                 sliceParams.cnSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
239                 sliceParams.cnSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
240                 sliceParams.cnSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
241                 break
242             default:
243                 subnetType = null
244                 break
245
246         //todo
247
248         }
249         if (subnetType == null) {
250             //todo: throw error
251             return
252         }
253         String response = querySubnetCapability(execution, vendor, subnetType)
254         ResponseEntity responseEntity = objectMapper.readValue(response, ResponseEntity.class)
255
256         Map<String, Object> result = responseEntity.getBody() as Map
257         for (Map.Entry<String, Object> entry : result.entrySet()) {
258             subnetCapability.setDomainType(entry.getKey())
259             subnetCapability.setCapabilityDetails(entry.getValue())
260         }
261     }
262
263     /**
264      * query Subnet Capability of TN AN CN
265      * @param execution
266      */
267     private String querySubnetCapability(DelegateExecution execution, String vendor, SubnetType subnetType) {
268
269         String strRequest = objectMapper.writeValueAsString(buildQuerySubnetCapRequest(vendor, subnetType))
270
271         String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_SUB_NET_CAPABILITY, strRequest)
272         return response
273     }
274
275     /**
276      * build request body for querying Subnet Capability
277      * @param vendor
278      * @param subnetTypes
279      * @param networkType
280      * @return
281      */
282     private static String buildQuerySubnetCapRequest(String vendor, SubnetType subnetType) {
283         NssmfAdapterNBIRequest request = new NssmfAdapterNBIRequest()
284
285         List<String> subnetTypes =  new ArrayList<>()
286         subnetTypes.add(subnetType.subnetType)
287         Map<String, Object> paramMap = new HashMap()
288         paramMap.put("subnetTypes", subnetTypes)
289
290         request.setSubnetCapabilityQuery(objectMapper.writeValueAsString(paramMap))
291
292         EsrInfo esrInfo = new EsrInfo()
293         esrInfo.setVendor(vendor)
294         esrInfo.setNetworkType(subnetType.networkType)
295
296         request.setEsrInfo(esrInfo)
297
298         String strRequest = objectMapper.writeValueAsString(request)
299
300         return strRequest
301     }
302
303     /**
304      * todo: need rewrite
305      * prepare select nsi request
306      * @param execution
307      */
308     public void preNSIRequest(DelegateExecution execution) {
309
310         String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution)
311         logger.debug( "get NSI option OOF Url: " + urlString)
312
313
314         String requestId = execution.getVariable("msoRequestId")
315         String messageType = "NSISelectionResponse"
316
317         execution.setVariable("nsiSelectionUrl", "/api/oof/selection/nsi/v1")
318         execution.setVariable("nsiSelection_messageType", messageType)
319         execution.setVariable("nsiSelection_correlator", requestId)
320         String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution)
321         execution.setVariable("nsiSelection_timeout", timeout)
322
323         SliceTaskParamsAdapter sliceParams =
324                 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
325
326         Map<String, Object> profileInfo = sliceParams.getServiceProfile()
327         TemplateInfo nstInfo = sliceParams.getNSTInfo()
328
329         List<TemplateInfo> nsstInfos = execution.getVariable("nsstInfos") as List<TemplateInfo>
330
331         List<SubnetCapability> subnetCapabilities =
332                 execution.getVariable("subnetCapabilities") as List<SubnetCapability>
333
334         String oofRequest = oofUtils.buildSelectNSIRequest(requestId, nstInfo, nsstInfos,
335                 messageType, profileInfo, subnetCapabilities, timeout as Integer)
336
337         execution.setVariable("nsiSelection_oofRequest", oofRequest)
338         logger.debug("Sending request to OOF: " + oofRequest)
339     }
340
341     /**
342      * todo: need rewrite
343      * process select nsi response
344      * @param execution
345      */
346     public void processNSIResp(DelegateExecution execution) {
347
348         SliceTaskParamsAdapter sliceTaskParams =
349                 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
350
351         String OOFResponse = execution.getVariable("nsiSelection_oofResponse")
352         logger.debug("NSI OOFResponse is: " + OOFResponse)
353         execution.setVariable("OOFResponse", OOFResponse)
354         //This needs to be changed to derive a value when we add policy to decide the solution options.
355
356         Map<String, Object> resMap = objectMapper.readValue(OOFResponse, Map.class)
357         List<Map<String, Object>> nsiSolutions = (List<Map<String, Object>>) resMap.get("solutions")
358         Map<String, Object> solution = nsiSolutions.get(0)
359
360         String resourceSharingLevel = execution.getVariable("resourceSharingLevel")
361         Boolean isSharable = resourceSharingLevel == "shared"
362
363         if (solution != null) {
364             if (isSharable && solution.get("existingNSI")) {
365                 //sharedNSISolution
366                 processSharedNSI(solution, sliceTaskParams)
367             }
368             else if(solution.containsKey("newNSISolution")) {
369                 processNewNSI(solution, sliceTaskParams)
370             }
371         }
372         execution.setVariable("sliceTaskParams", sliceTaskParams)
373         //logger.debug("sliceTaskParams: " + sliceTaskParams.convertToJson())
374         logger.debug("*** Completed options Call to OOF ***")
375     }
376
377     private void processSharedNSI(Map<String, Object> solution, SliceTaskParamsAdapter sliceParams) {
378         Map<String, Object> sharedNSISolution = solution.get("sharedNSISolution") as Map
379
380         String nsiId = sharedNSISolution.get("NSIId")
381         String nsiName = sharedNSISolution.get("NSIName")
382         sliceParams.setSuggestNsiId(nsiId)
383         sliceParams.setSuggestNsiName(nsiName)
384     }
385
386     private void processNewNSI(Map<String, Object> solution, SliceTaskParamsAdapter sliceParams) {
387         Map<String, Object> newNSISolution = solution.get("newNSISolution") as Map
388         List<Map> sliceProfiles = newNSISolution.get("sliceProfiles") as List<Map>
389         for (Map sliceProfile : sliceProfiles) {
390             String domainType = sliceProfile.get("domainType")
391             switch (domainType.toLowerCase()) {
392                 case "tn-bh":
393                     sliceParams.tnBHSliceTaskInfo.sliceProfile = sliceProfile as TnSliceProfile
394                     break
395                 case "an-nf":
396                     sliceParams.anSliceTaskInfo.sliceProfile = sliceProfile as AnSliceProfile
397                     break
398                 case "cn":
399                     sliceParams.cnSliceTaskInfo.sliceProfile = sliceProfile as CnSliceProfile
400                     break
401                 default:
402                     break
403             }
404
405             //todo
406
407         }
408     }
409
410     /**
411      * get NSSI Selection Capability for AN
412      * @param execution
413      */
414     public void getNSSISelectionCap4AN(DelegateExecution execution) {
415
416         def vendor = execution.getVariable("vendor") as String
417
418         String strRequest = buildNSSISelectionReq(vendor, NetworkType.ACCESS)
419
420         String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_NSSI_SELECTION_CAPABILITY, strRequest)
421
422         Map<String, Object> resMap = objectMapper.readValue(response, Map.class)
423
424         String selection = resMap.get("selection")
425
426
427         if ("NSMF".equalsIgnoreCase(selection)) {
428             execution.setVariable("NEED_AN_NSSI_SELECTION", true)
429         }
430     }
431
432     /**
433      * get NSSI Selection Capability for TN
434      * @param execution
435      */
436     public void getNSSISelectionCap4TN(DelegateExecution execution) {
437
438         def vendor = execution.getVariable("vendor") as String
439
440         String strRequest = buildNSSISelectionReq(vendor, NetworkType.TRANSPORT)
441
442         String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_NSSI_SELECTION_CAPABILITY, strRequest)
443
444         Map<String, Object> resMap = objectMapper.readValue(response, Map.class)
445
446         String selection = resMap.get("selection")
447
448         if ("NSMF".equalsIgnoreCase(selection)) {
449             execution.setVariable("NEED_TN_NSSI_SELECTION", true)
450         }
451     }
452
453     /**
454      * get NSSI Selection Capability for CN
455      * @param execution
456      */
457     public void getNSSISelectionCap4CN(DelegateExecution execution) {
458
459         def vendor = execution.getVariable("vendor") as String
460
461         String strRequest = buildNSSISelectionReq(vendor, NetworkType.CORE)
462
463         String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_NSSI_SELECTION_CAPABILITY, strRequest)
464
465         Map<String, Object> resMap = objectMapper.readValue(response, Map.class)
466
467         String selection = resMap.get("selection")
468
469         if ("NSMF".equalsIgnoreCase(selection)) {
470             execution.setVariable("NEED_CN_NSSI_SELECTION", true)
471         }
472     }
473
474     /**
475      * build NSSI Selection Capability Request body to nssmf adapter
476      * @param vendor
477      * @param networkType
478      * @return
479      */
480     private static String buildNSSISelectionReq(String vendor, NetworkType networkType) {
481         NssmfAdapterNBIRequest request = new NssmfAdapterNBIRequest()
482         EsrInfo esrInfo = new EsrInfo()
483         esrInfo.setVendor(vendor)
484         esrInfo.setNetworkType(networkType)
485         request.setEsrInfo(esrInfo)
486
487         return objectMapper.writeValueAsString(request)
488     }
489
490     /**
491      * if exist nssi need to select?
492      * @param execution
493      */
494     public void handleNssiSelect(DelegateExecution execution) {
495
496         SliceTaskParamsAdapter sliceTaskParams =
497                 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
498
499         //todo
500         boolean needCnNssiSelection = execution.getVariable("NEED_CN_NSSI_SELECTION") as Boolean
501         boolean needAnNssiSelection = execution.getVariable("NEED_AN_NSSI_SELECTION") as Boolean
502         boolean needTnNssiSelection = execution.getVariable("NEED_TN_NSSI_SELECTION") as Boolean
503
504         /**
505          * [
506          * ​  {
507          * ​          "subType":  subtype,
508          * ​          "nsstInfo": object,
509          * ​          "sliceProfile": object
510          * ​  },
511          *      {
512          *          "subType":  subtype,
513          *          "nsstInfo": object,
514          *          "sliceProfile": object
515          *      }
516          * ]
517          */
518         List<Map> nssiNeedHandlerInfos = new ArrayList<>()
519         Map<String, Object> nssiNeedHandlerMap = new HashMap()
520
521         //List<TemplateInfo> nssiNeedHandlers = new ArrayList<>()
522         //List<Object> nssiProfileNeedHandlers = new ArrayList<>()
523         if (needCnNssiSelection) {
524             nssiNeedHandlerMap.put("subnetType", sliceTaskParams.cnSliceTaskInfo.subnetType)
525             nssiNeedHandlerMap.put("nsstInfo", sliceTaskParams.cnSliceTaskInfo.NSSTInfo)
526             nssiNeedHandlerMap.put("sliceProfile", sliceTaskParams.cnSliceTaskInfo.sliceProfile)
527             nssiNeedHandlerInfos.add(nssiNeedHandlerMap)
528         }
529         if (needAnNssiSelection) {
530             nssiNeedHandlerMap.clear()
531             nssiNeedHandlerMap.put("subnetType", sliceTaskParams.anSliceTaskInfo.subnetType)
532             nssiNeedHandlerMap.put("nsstInfo", sliceTaskParams.anSliceTaskInfo.NSSTInfo)
533             nssiNeedHandlerMap.put("sliceProfile", sliceTaskParams.anSliceTaskInfo.sliceProfile)
534             nssiNeedHandlerInfos.add(nssiNeedHandlerMap)
535         }
536         if (needTnNssiSelection) {
537             nssiNeedHandlerMap.clear()
538             nssiNeedHandlerMap.put("subnetType", sliceTaskParams.tnBHSliceTaskInfo.subnetType)
539             nssiNeedHandlerMap.put("nsstInfo", sliceTaskParams.tnBHSliceTaskInfo.NSSTInfo)
540             nssiNeedHandlerMap.put("sliceProfile", sliceTaskParams.tnBHSliceTaskInfo.sliceProfile)
541             nssiNeedHandlerInfos.add(nssiNeedHandlerMap)
542
543             nssiNeedHandlerMap.clear()
544             nssiNeedHandlerMap.put("subnetType", sliceTaskParams.tnMHSliceTaskInfo.subnetType)
545             nssiNeedHandlerMap.put("nsstInfo", sliceTaskParams.tnMHSliceTaskInfo.NSSTInfo)
546             nssiNeedHandlerMap.put("sliceProfile", sliceTaskParams.tnMHSliceTaskInfo.sliceProfile)
547             nssiNeedHandlerInfos.add(nssiNeedHandlerMap)
548
549             nssiNeedHandlerMap.clear()
550             nssiNeedHandlerMap.put("subnetType", sliceTaskParams.tnFHSliceTaskInfo.subnetType)
551             nssiNeedHandlerMap.put("nsstInfo", sliceTaskParams.tnFHSliceTaskInfo.NSSTInfo)
552             nssiNeedHandlerMap.put("sliceProfile", sliceTaskParams.tnFHSliceTaskInfo.sliceProfile)
553             nssiNeedHandlerInfos.add(nssiNeedHandlerMap)
554
555         }
556
557         if (nssiNeedHandlerInfos.size() > 0) {
558             execution.setVariable("needSelectNssi", true)
559             execution.setVariable("currNssiIndex", 0)
560             execution.setVariable("nssiNeedHandlerInfos", nssiNeedHandlerInfos)
561         } else {
562             execution.setVariable("needSelectNssi", false)
563         }
564
565         execution.setVariable("sliceTaskParams", sliceTaskParams)
566     }
567
568     /**
569      * prepare select nssi request
570      * @param execution
571      */
572     public void preNSSIRequest(DelegateExecution execution) {
573
574         List<Map> nssiNeedHandlerInfos =
575                 execution.getVariable("nssiNeedHandlerInfos") as List<Map>
576
577         int currNssiIndex = execution.getVariable("currNssiIndex") as Integer
578         Map nssiNeedHandlerInfo = nssiNeedHandlerInfos.get(currNssiIndex) as Map
579
580         TemplateInfo nsstInfo = nssiNeedHandlerInfo.get("nsstInfo") as TemplateInfo
581         Object profileInfo = nssiNeedHandlerInfo.get("sliceProfile")
582
583         String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution)
584         logger.debug( "get NSI option OOF Url: " + urlString)
585
586         String requestId = execution.getVariable("msoRequestId")
587         String messageType = "NSSISelectionResponse"
588
589         execution.setVariable("nssiSelectionUrl", "/api/oof/selection/nssi/v1")
590         execution.setVariable("nssiSelection_messageType", messageType)
591         execution.setVariable("nssiSelection_correlator", requestId)
592         String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution)
593         execution.setVariable("nssiSelection_timeout", timeout)
594
595         String oofRequest = oofUtils.buildSelectNSSIRequest(requestId, nsstInfo, messageType,
596                 profileInfo, timeout as Integer)
597
598         execution.setVariable("nssiSelection_oofRequest", oofRequest)
599         logger.debug("Sending request to OOF: " + oofRequest)
600     }
601
602     /**
603      * process select nssi response
604      * @param execution
605      */
606     public void processNSSIResp(DelegateExecution execution) {
607
608         List<Map> nssiNeedHandlerInfos =
609                 execution.getVariable("nssiNeedHandlerInfos") as List<Map>
610
611         int currNssiIndex = execution.getVariable("currNssiIndex") as Integer
612         Map nssiNeedHandlerInfo = nssiNeedHandlerInfos.get(currNssiIndex) as Map
613         SubnetType subnetType = nssiNeedHandlerInfo.get("subnetType") as SubnetType
614
615         SliceTaskParamsAdapter sliceTaskParams =
616                 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
617
618
619         String OOFResponse = execution.getVariable("nssiSelection_oofResponse")
620         logger.debug("NSI OOFResponse is: " + OOFResponse)
621         execution.setVariable("OOFResponse", OOFResponse)
622         //This needs to be changed to derive a value when we add policy to decide the solution options.
623
624         Map<String, Object> resMap = objectMapper.readValue(OOFResponse, Map.class)
625         List<Map<String, Object>> nsiSolutions = (List<Map<String, Object>>) resMap.get("solutions")
626         Map<String, Object> solution = nsiSolutions.get(0)
627
628         String resourceSharingLevel = execution.getVariable("resourceSharingLevel")
629         Boolean isSharable = resourceSharingLevel == "shared"   //todo
630
631         if (isSharable && solution != null) {
632             processNssiResult(sliceTaskParams, subnetType, solution)
633         }
634
635         execution.setVariable("sliceTaskParams", sliceTaskParams)
636         //logger.debug("sliceTaskParams: "+ sliceTaskParams.convertToJson())
637         logger.debug("*** Completed options Call to OOF ***")
638
639         logger.debug("start parseServiceProfile")
640         //parseServiceProfile(execution)
641         logger.debug("end parseServiceProfile")
642
643         if (currNssiIndex >= nssiNeedHandlerInfos.size() - 1) {
644             execution.setVariable("needSelectNssi", false)
645         } else {
646             execution.setVariable("currNssiIndex", currNssiIndex + 1)
647             execution.setVariable("needSelectNssi", true)
648         }
649
650     }
651
652     private void processNssiResult(SliceTaskParamsAdapter sliceTaskParams, SubnetType subnetType,
653                                    Map<String, Object> solution) {
654         switch (subnetType) {
655             case SubnetType.CN:
656                 sliceTaskParams.cnSliceTaskInfo.suggestNssiId = solution.get("NSSIId")
657                 sliceTaskParams.cnSliceTaskInfo.suggestNssiName = solution.get("NSSIName")
658                 break
659             case SubnetType.AN_NF:
660                 sliceTaskParams.anSliceTaskInfo.suggestNssiId = solution.get("NSSIId")
661                 sliceTaskParams.anSliceTaskInfo.suggestNssiName = solution.get("NSSIName")
662                 break
663             case SubnetType.TN_BH:
664                 sliceTaskParams.tnBHSliceTaskInfo.suggestNssiId = solution.get("NSSIId")
665                 sliceTaskParams.tnBHSliceTaskInfo.suggestNssiName = solution.get("NSSIName")
666                 break
667             case SubnetType.TN_FH:
668                 sliceTaskParams.tnFHSliceTaskInfo.suggestNssiId = solution.get("NSSIId")
669                 sliceTaskParams.tnFHSliceTaskInfo.suggestNssiName = solution.get("NSSIName")
670                 break
671             case SubnetType.TN_MH:
672                 sliceTaskParams.tnMHSliceTaskInfo.suggestNssiId = solution.get("NSSIId")
673                 sliceTaskParams.tnMHSliceTaskInfo.suggestNssiName = solution.get("NSSIName")
674                 break
675         }
676     }
677
678 }