8993127dbc2d27eba2bdcaa6aaf0f59c2310286b
[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         ModelInfo modelInfo = serviceDecomposition.getModelInfo()
198         String vendor = serviceDecomposition.getServiceRole()
199         SubnetType subnetType = convertServiceCategory(serviceDecomposition.getServiceCategory())
200
201         switch (subnetType) {
202             case SubnetType.TN_BH:
203                 sliceParams.tnBHSliceTaskInfo.vendor = vendor
204                 sliceParams.tnBHSliceTaskInfo.subnetType = subnetType
205                 sliceParams.tnBHSliceTaskInfo.networkType = subnetType.networkType
206                 sliceParams.tnBHSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
207                 sliceParams.tnBHSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
208                 sliceParams.tnBHSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
209
210                 break
211             case SubnetType.TN_MH:
212                 sliceParams.tnMHSliceTaskInfo.vendor = vendor
213                 sliceParams.tnMHSliceTaskInfo.subnetType = subnetType
214                 sliceParams.tnMHSliceTaskInfo.networkType = subnetType.networkType
215                 sliceParams.tnMHSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
216                 sliceParams.tnMHSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
217                 sliceParams.tnMHSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
218
219                 break
220             case SubnetType.AN_NF:
221                 sliceParams.anSliceTaskInfo.vendor = vendor
222                 sliceParams.anSliceTaskInfo.subnetType = subnetType
223                 sliceParams.anSliceTaskInfo.networkType = subnetType.networkType
224                 sliceParams.anSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
225                 sliceParams.anSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
226                 sliceParams.anSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
227                 break
228             case SubnetType.CN:
229                 sliceParams.cnSliceTaskInfo.vendor = vendor
230                 sliceParams.cnSliceTaskInfo.subnetType = subnetType
231                 sliceParams.cnSliceTaskInfo.networkType = subnetType.networkType
232                 sliceParams.cnSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
233                 sliceParams.cnSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
234                 sliceParams.cnSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
235                 break
236             default:
237                 subnetType = null
238                 break
239
240         //todo
241
242         }
243         if (null == subnetType) {
244             def msg = "Get subnetType failed, modelUUId=" + modelInfo.getModelUuid()
245             logger.error(msg)
246             exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
247         }
248         String response = querySubnetCapability(execution, vendor, subnetType)
249         ResponseEntity responseEntity = objectMapper.readValue(response, ResponseEntity.class)
250
251         Map<String, Object> result = responseEntity.getBody() as Map
252         for (Map.Entry<String, Object> entry : result.entrySet()) {
253             subnetCapability.setDomainType(entry.getKey())
254             subnetCapability.setCapabilityDetails(entry.getValue())
255         }
256     }
257
258     /**
259      * get subnetType from serviceCategory
260      * @return
261      */
262     private SubnetType convertServiceCategory(String serviceCategory){
263         if(serviceCategory ==~ /CN.*/){
264             return SubnetType.CN
265         }
266         if (serviceCategory ==~ /AN.*NF.*/){
267             return SubnetType.AN_NF
268         }
269         if (serviceCategory ==~ /TN.*BH.*/){
270             return SubnetType.TN_BH
271         }
272         if(serviceCategory ==~ /TN.*MH.*/){
273             return SubnetType.TN_MH
274         }
275         return null
276     }
277
278     /**
279      * query Subnet Capability of TN AN CN
280      * @param execution
281      */
282     private String querySubnetCapability(DelegateExecution execution, String vendor, SubnetType subnetType) {
283
284         String strRequest = objectMapper.writeValueAsString(buildQuerySubnetCapRequest(vendor, subnetType))
285
286         String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_SUB_NET_CAPABILITY, strRequest)
287         return response
288     }
289
290     /**
291      * build request body for querying Subnet Capability
292      * @param vendor
293      * @param subnetTypes
294      * @param networkType
295      * @return
296      */
297     private static String buildQuerySubnetCapRequest(String vendor, SubnetType subnetType) {
298         NssmfAdapterNBIRequest request = new NssmfAdapterNBIRequest()
299
300         List<String> subnetTypes =  new ArrayList<>()
301         subnetTypes.add(subnetType.subnetType)
302         Map<String, Object> paramMap = new HashMap()
303         paramMap.put("subnetTypes", subnetTypes)
304
305         request.setSubnetCapabilityQuery(objectMapper.writeValueAsString(paramMap))
306
307         EsrInfo esrInfo = new EsrInfo()
308         esrInfo.setVendor(vendor)
309         esrInfo.setNetworkType(subnetType.networkType)
310
311         request.setEsrInfo(esrInfo)
312
313         String strRequest = objectMapper.writeValueAsString(request)
314
315         return strRequest
316     }
317
318     /**
319      * todo: need rewrite
320      * prepare select nsi request
321      * @param execution
322      */
323     public void preNSIRequest(DelegateExecution execution, boolean preferReuse) {
324
325         String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution)
326         logger.debug( "get NSI option OOF Url: " + urlString)
327
328         String requestId = execution.getVariable("msoRequestId")
329         String messageType = "NSISelectionResponse"
330
331         execution.setVariable("nsiSelectionUrl", "/api/oof/selection/nsi/v1")
332         execution.setVariable("nsiSelection_messageType", messageType)
333         execution.setVariable("nsiSelection_correlator", requestId)
334         String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution)
335         execution.setVariable("nsiSelection_timeout", timeout)
336
337         SliceTaskParamsAdapter sliceParams =
338                 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
339
340         Map<String, Object> profileInfo = sliceParams.getServiceProfile()
341         TemplateInfo nstInfo = sliceParams.getNSTInfo()
342
343         List<TemplateInfo> nsstInfos = execution.getVariable("nsstInfos") as List<TemplateInfo>
344
345         List<SubnetCapability> subnetCapabilities =
346                 execution.getVariable("subnetCapabilities") as List<SubnetCapability>
347
348         String oofRequest = oofUtils.buildSelectNSIRequest(requestId, nstInfo, nsstInfos,
349                 messageType, profileInfo, subnetCapabilities, timeout as Integer, preferReuse)
350
351         execution.setVariable("nsiSelection_oofRequest", oofRequest)
352         logger.debug("Sending request to OOF: " + oofRequest)
353     }
354
355     /**
356      * todo: need rewrite
357      * process select nsi response
358      * @param execution
359      */
360     public void processNSIResp(DelegateExecution execution) {
361
362         SliceTaskParamsAdapter sliceTaskParams =
363                 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
364
365         String oofResponse = execution.getVariable("nsiSelection_oofResponse")
366         logger.debug("NSI oofResponse is: " + oofResponse)
367         execution.setVariable("oofResponse", oofResponse)
368         //This needs to be changed to derive a value when we add policy to decide the solution options.
369
370         Map<String, Object> resMap = objectMapper.readValue(oofResponse, Map.class)
371         List<Map<String, Object>> nsiSolutions = (List<Map<String, Object>>) resMap.get("solutions")
372         Map<String, Object> solution = nsiSolutions.get(0)
373
374         String resourceSharingLevel = execution.getVariable("resourceSharingLevel")
375         Boolean isSharable = resourceSharingLevel == "shared"
376
377         if (solution != null) {
378             if (isSharable && solution.get("existingNSI")) {
379                 //sharedNSISolution
380                 processSharedNSI(solution, sliceTaskParams)
381             }
382             else if(solution.containsKey("newNSISolution")) {
383                 processNewNSI(solution, sliceTaskParams)
384             }
385         }
386         execution.setVariable("sliceTaskParams", sliceTaskParams)
387         //logger.debug("sliceTaskParams: " + sliceTaskParams.convertToJson())
388         logger.debug("*** Completed options Call to OOF ***")
389     }
390
391     private void processSharedNSI(Map<String, Object> solution, SliceTaskParamsAdapter sliceParams) {
392         Map<String, Object> sharedNSISolution = solution.get("sharedNSISolution") as Map
393
394         String nsiId = sharedNSISolution.get("NSIId")
395         String nsiName = sharedNSISolution.get("NSIName")
396         sliceParams.setSuggestNsiId(nsiId)
397         sliceParams.setSuggestNsiName(nsiName)
398     }
399
400     private void processNewNSI(Map<String, Object> solution, SliceTaskParamsAdapter sliceParams) {
401         Map<String, Object> newNSISolution = solution.get("newNSISolution") as Map
402         List<Map> sliceProfiles = newNSISolution.get("sliceProfiles") as List<Map>
403         for (Map sliceProfile : sliceProfiles) {
404             String domainType = sliceProfile.get("domainType")
405             switch (domainType.toLowerCase()) {
406                 case "tn-bh":
407                     sliceParams.tnBHSliceTaskInfo.sliceProfile = sliceProfile as TnSliceProfile
408                     break
409                 case "an-nf":
410                     sliceParams.anSliceTaskInfo.sliceProfile = sliceProfile as AnSliceProfile
411                     break
412                 case "cn":
413                     sliceParams.cnSliceTaskInfo.sliceProfile = sliceProfile as CnSliceProfile
414                     break
415                 default:
416                     break
417             }
418
419             //todo
420
421         }
422     }
423
424     /**
425      * get NSSI Selection Capability for AN
426      * @param execution
427      */
428     public void getNSSISelectionCap4AN(DelegateExecution execution) {
429
430         def vendor = execution.getVariable("vendor") as String
431
432         String strRequest = buildNSSISelectionReq(vendor, NetworkType.ACCESS)
433
434         String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_NSSI_SELECTION_CAPABILITY, strRequest)
435
436         Map<String, Object> resMap = objectMapper.readValue(response, Map.class)
437
438         String selection = resMap.get("selection")
439
440
441         if ("NSMF".equalsIgnoreCase(selection)) {
442             execution.setVariable("NEED_AN_NSSI_SELECTION", true)
443         }
444     }
445
446     /**
447      * get NSSI Selection Capability for TN
448      * @param execution
449      */
450     public void getNSSISelectionCap4TN(DelegateExecution execution) {
451
452         def vendor = execution.getVariable("vendor") as String
453
454         String strRequest = buildNSSISelectionReq(vendor, NetworkType.TRANSPORT)
455
456         String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_NSSI_SELECTION_CAPABILITY, strRequest)
457
458         Map<String, Object> resMap = objectMapper.readValue(response, Map.class)
459
460         String selection = resMap.get("selection")
461
462         if ("NSMF".equalsIgnoreCase(selection)) {
463             execution.setVariable("NEED_TN_NSSI_SELECTION", true)
464         }
465     }
466
467     /**
468      * get NSSI Selection Capability for CN
469      * @param execution
470      */
471     public void getNSSISelectionCap4CN(DelegateExecution execution) {
472
473         def vendor = execution.getVariable("vendor") as String
474
475         String strRequest = buildNSSISelectionReq(vendor, NetworkType.CORE)
476
477         String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_NSSI_SELECTION_CAPABILITY, strRequest)
478
479         Map<String, Object> resMap = objectMapper.readValue(response, Map.class)
480
481         String selection = resMap.get("selection")
482
483         if ("NSMF".equalsIgnoreCase(selection)) {
484             execution.setVariable("NEED_CN_NSSI_SELECTION", true)
485         }
486     }
487
488     /**
489      * build NSSI Selection Capability Request body to nssmf adapter
490      * @param vendor
491      * @param networkType
492      * @return
493      */
494     private static String buildNSSISelectionReq(String vendor, NetworkType networkType) {
495         NssmfAdapterNBIRequest request = new NssmfAdapterNBIRequest()
496         EsrInfo esrInfo = new EsrInfo()
497         esrInfo.setVendor(vendor)
498         esrInfo.setNetworkType(networkType)
499         request.setEsrInfo(esrInfo)
500
501         return objectMapper.writeValueAsString(request)
502     }
503
504     /**
505      * if exist nssi need to select?
506      * @param execution
507      */
508     public void handleNssiSelect(DelegateExecution execution) {
509
510         SliceTaskParamsAdapter sliceTaskParams =
511                 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
512
513         //todo
514         boolean needCnNssiSelection = execution.getVariable("NEED_CN_NSSI_SELECTION") as Boolean
515         boolean needAnNssiSelection = execution.getVariable("NEED_AN_NSSI_SELECTION") as Boolean
516         boolean needTnNssiSelection = execution.getVariable("NEED_TN_NSSI_SELECTION") as Boolean
517
518         /**
519          * [
520          * ​  {
521          * ​          "subType":  subtype,
522          * ​          "nsstInfo": object,
523          * ​          "sliceProfile": object
524          * ​  },
525          *      {
526          *          "subType":  subtype,
527          *          "nsstInfo": object,
528          *          "sliceProfile": object
529          *      }
530          * ]
531          */
532         List<Map> nssiNeedHandlerInfos = new ArrayList<>()
533         Map<String, Object> nssiNeedHandlerMap = new HashMap()
534
535         //List<TemplateInfo> nssiNeedHandlers = new ArrayList<>()
536         //List<Object> nssiProfileNeedHandlers = new ArrayList<>()
537         if (needCnNssiSelection) {
538             nssiNeedHandlerMap.put("subnetType", sliceTaskParams.cnSliceTaskInfo.subnetType)
539             nssiNeedHandlerMap.put("nsstInfo", sliceTaskParams.cnSliceTaskInfo.NSSTInfo)
540             nssiNeedHandlerMap.put("sliceProfile", sliceTaskParams.cnSliceTaskInfo.sliceProfile)
541             nssiNeedHandlerInfos.add(nssiNeedHandlerMap)
542         }
543         if (needAnNssiSelection) {
544             nssiNeedHandlerMap.clear()
545             nssiNeedHandlerMap.put("subnetType", sliceTaskParams.anSliceTaskInfo.subnetType)
546             nssiNeedHandlerMap.put("nsstInfo", sliceTaskParams.anSliceTaskInfo.NSSTInfo)
547             nssiNeedHandlerMap.put("sliceProfile", sliceTaskParams.anSliceTaskInfo.sliceProfile)
548             nssiNeedHandlerInfos.add(nssiNeedHandlerMap)
549         }
550         if (needTnNssiSelection) {
551             nssiNeedHandlerMap.clear()
552             nssiNeedHandlerMap.put("subnetType", sliceTaskParams.tnBHSliceTaskInfo.subnetType)
553             nssiNeedHandlerMap.put("nsstInfo", sliceTaskParams.tnBHSliceTaskInfo.NSSTInfo)
554             nssiNeedHandlerMap.put("sliceProfile", sliceTaskParams.tnBHSliceTaskInfo.sliceProfile)
555             nssiNeedHandlerInfos.add(nssiNeedHandlerMap)
556
557             nssiNeedHandlerMap.clear()
558             nssiNeedHandlerMap.put("subnetType", sliceTaskParams.tnMHSliceTaskInfo.subnetType)
559             nssiNeedHandlerMap.put("nsstInfo", sliceTaskParams.tnMHSliceTaskInfo.NSSTInfo)
560             nssiNeedHandlerMap.put("sliceProfile", sliceTaskParams.tnMHSliceTaskInfo.sliceProfile)
561             nssiNeedHandlerInfos.add(nssiNeedHandlerMap)
562
563             nssiNeedHandlerMap.clear()
564             nssiNeedHandlerMap.put("subnetType", sliceTaskParams.tnFHSliceTaskInfo.subnetType)
565             nssiNeedHandlerMap.put("nsstInfo", sliceTaskParams.tnFHSliceTaskInfo.NSSTInfo)
566             nssiNeedHandlerMap.put("sliceProfile", sliceTaskParams.tnFHSliceTaskInfo.sliceProfile)
567             nssiNeedHandlerInfos.add(nssiNeedHandlerMap)
568
569         }
570
571         if (nssiNeedHandlerInfos.size() > 0) {
572             execution.setVariable("needSelectNssi", true)
573             execution.setVariable("currNssiIndex", 0)
574             execution.setVariable("nssiNeedHandlerInfos", nssiNeedHandlerInfos)
575         } else {
576             execution.setVariable("needSelectNssi", false)
577         }
578
579         execution.setVariable("sliceTaskParams", sliceTaskParams)
580     }
581
582     /**
583      * prepare select nssi request
584      * @param execution
585      */
586     public void preNSSIRequest(DelegateExecution execution) {
587
588         List<Map> nssiNeedHandlerInfos =
589                 execution.getVariable("nssiNeedHandlerInfos") as List<Map>
590
591         int currNssiIndex = execution.getVariable("currNssiIndex") as Integer
592         Map nssiNeedHandlerInfo = nssiNeedHandlerInfos.get(currNssiIndex) as Map
593
594         TemplateInfo nsstInfo = nssiNeedHandlerInfo.get("nsstInfo") as TemplateInfo
595         Object profileInfo = nssiNeedHandlerInfo.get("sliceProfile")
596
597         String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution)
598         logger.debug( "get NSI option OOF Url: " + urlString)
599
600         String requestId = execution.getVariable("msoRequestId")
601         String messageType = "NSSISelectionResponse"
602
603         execution.setVariable("nssiSelectionUrl", "/api/oof/selection/nssi/v1")
604         execution.setVariable("nssiSelection_messageType", messageType)
605         execution.setVariable("nssiSelection_correlator", requestId)
606         String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution)
607         execution.setVariable("nssiSelection_timeout", timeout)
608
609         String oofRequest = oofUtils.buildSelectNSSIRequest(requestId, nsstInfo, messageType,
610                 profileInfo, timeout as Integer)
611
612         execution.setVariable("nssiSelection_oofRequest", oofRequest)
613         logger.debug("Sending request to OOF: " + oofRequest)
614     }
615
616     /**
617      * process select nssi response
618      * @param execution
619      */
620     public void processNSSIResp(DelegateExecution execution) {
621
622         List<Map> nssiNeedHandlerInfos =
623                 execution.getVariable("nssiNeedHandlerInfos") as List<Map>
624
625         int currNssiIndex = execution.getVariable("currNssiIndex") as Integer
626         Map nssiNeedHandlerInfo = nssiNeedHandlerInfos.get(currNssiIndex) as Map
627         SubnetType subnetType = nssiNeedHandlerInfo.get("subnetType") as SubnetType
628
629         SliceTaskParamsAdapter sliceTaskParams =
630                 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
631
632
633         String OOFResponse = execution.getVariable("nssiSelection_oofResponse")
634         logger.debug("NSI OOFResponse is: " + OOFResponse)
635         execution.setVariable("OOFResponse", OOFResponse)
636         //This needs to be changed to derive a value when we add policy to decide the solution options.
637
638         Map<String, Object> resMap = objectMapper.readValue(OOFResponse, Map.class)
639         List<Map<String, Object>> nsiSolutions = (List<Map<String, Object>>) resMap.get("solutions")
640         Map<String, Object> solution = nsiSolutions.get(0)
641
642         String resourceSharingLevel = execution.getVariable("resourceSharingLevel")
643         Boolean isSharable = resourceSharingLevel == "shared"   //todo
644
645         if (isSharable && solution != null) {
646             processNssiResult(sliceTaskParams, subnetType, solution)
647         }
648
649         execution.setVariable("sliceTaskParams", sliceTaskParams)
650         //logger.debug("sliceTaskParams: "+ sliceTaskParams.convertToJson())
651         logger.debug("*** Completed options Call to OOF ***")
652
653         logger.debug("start parseServiceProfile")
654         //parseServiceProfile(execution)
655         logger.debug("end parseServiceProfile")
656
657         if (currNssiIndex >= nssiNeedHandlerInfos.size() - 1) {
658             execution.setVariable("needSelectNssi", false)
659         } else {
660             execution.setVariable("currNssiIndex", currNssiIndex + 1)
661             execution.setVariable("needSelectNssi", true)
662         }
663
664     }
665
666     private void processNssiResult(SliceTaskParamsAdapter sliceTaskParams, SubnetType subnetType,
667                                    Map<String, Object> solution) {
668         switch (subnetType) {
669             case SubnetType.CN:
670                 sliceTaskParams.cnSliceTaskInfo.suggestNssiId = solution.get("NSSIId")
671                 sliceTaskParams.cnSliceTaskInfo.suggestNssiName = solution.get("NSSIName")
672                 break
673             case SubnetType.AN_NF:
674                 sliceTaskParams.anSliceTaskInfo.suggestNssiId = solution.get("NSSIId")
675                 sliceTaskParams.anSliceTaskInfo.suggestNssiName = solution.get("NSSIName")
676                 break
677             case SubnetType.TN_BH:
678                 sliceTaskParams.tnBHSliceTaskInfo.suggestNssiId = solution.get("NSSIId")
679                 sliceTaskParams.tnBHSliceTaskInfo.suggestNssiName = solution.get("NSSIName")
680                 break
681             case SubnetType.TN_FH:
682                 sliceTaskParams.tnFHSliceTaskInfo.suggestNssiId = solution.get("NSSIId")
683                 sliceTaskParams.tnFHSliceTaskInfo.suggestNssiName = solution.get("NSSIName")
684                 break
685             case SubnetType.TN_MH:
686                 sliceTaskParams.tnMHSliceTaskInfo.suggestNssiId = solution.get("NSSIId")
687                 sliceTaskParams.tnMHSliceTaskInfo.suggestNssiName = solution.get("NSSIName")
688                 break
689         }
690     }
691
692 }