summaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateSliceServiceOption.groovy
blob: ac7f1af8905a3ab8cfc1210ca330e01c3e762cd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
/*-
 * ============LICENSE_START=======================================================
 * ONAP - SO
 * ================================================================================
 # Copyright (c) 2020, CMCC Technologies Co., Ltd.
 #
 # Licensed under the Apache License, Version 2.0 (the "License")
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
 #
 #       http://www.apache.org/licenses/LICENSE-2.0
 #
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.onap.so.bpmn.infrastructure.scripts

import com.fasterxml.jackson.databind.ObjectMapper
import org.camunda.bpm.engine.delegate.DelegateExecution
import org.onap.aai.domain.yang.ServiceInstance
import org.onap.so.beans.nsmf.EsrInfo
import org.onap.so.beans.nsmf.NetworkType
import org.onap.so.beans.nsmf.NssmfAdapterNBIRequest
import org.onap.so.beans.nsmf.QuerySubnetCapability
import org.onap.so.beans.nsmf.SliceProfileAdapter
import org.onap.so.beans.nsmf.SliceTaskParamsAdapter
import org.onap.so.beans.nsmf.oof.SubnetCapability
import org.onap.so.beans.nsmf.oof.SubnetType
import org.onap.so.beans.nsmf.oof.TemplateInfo
import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
import org.onap.so.bpmn.common.scripts.ExceptionUtil
import org.onap.so.bpmn.common.scripts.NssmfAdapterUtils
import org.onap.so.bpmn.common.scripts.OofUtils
import org.onap.so.bpmn.core.UrnPropertiesReader
import org.onap.so.bpmn.core.domain.AllottedResource
import org.onap.so.bpmn.core.domain.ModelInfo
import org.onap.so.bpmn.core.domain.ServiceDecomposition
import org.onap.so.bpmn.core.json.JsonUtils
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.util.StringUtils


class DoCreateSliceServiceOption extends AbstractServiceTaskProcessor{

    private static final Logger logger = LoggerFactory.getLogger(DoCreateSliceServiceOption.class)

    ExceptionUtil exceptionUtil = new ExceptionUtil()

    JsonUtils jsonUtil = new JsonUtils()

    OofUtils oofUtils = new OofUtils()

    AAISliceUtil aaiSliceUtil = new AAISliceUtil()

    private static final ObjectMapper objectMapper = new ObjectMapper()

    private NssmfAdapterUtils nssmfAdapterUtils = new NssmfAdapterUtils(httpClientFactory, jsonUtil)

    private static final String QUERY_SUB_NET_CAPABILITY = "/api/rest/provMns/v1/NSS/subnetCapabilityQuery"

    private static final String QUERY_NSSI_SELECTION_CAPABILITY = "/api/rest/provMns/v1/NSS/NSSISelectionCapability"

    void preProcessRequest (DelegateExecution execution) {
    }

    /**
     * prepare the params for decompose nst
     * @param execution
     */
    void prepareDecomposeNST(DelegateExecution execution) {

        SliceTaskParamsAdapter sliceTaskParams =
                execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter

        String modelUuid = sliceTaskParams.getNSTInfo().getUUID()
        String modelInvariantUuid = sliceTaskParams.getNSTInfo().getInvariantUUID()

        String serviceModelInfo = """{
            "modelInvariantUuid":"${modelInvariantUuid}",
            "modelUuid":"${modelUuid}",
            "modelVersion":""
             }"""
        execution.setVariable("nstServiceModelInfo", serviceModelInfo)
    }

    /**
     * process the result of NST Decomposition
     * @param execution
     */
    public void processDecompositionNST(DelegateExecution execution) {

        List<TemplateInfo> nsstInfos = new ArrayList<>()
        ServiceDecomposition nstServiceDecomposition =
                execution.getVariable("nstServiceDecomposition") as ServiceDecomposition

        List<AllottedResource> allottedResources = nstServiceDecomposition.getAllottedResources()
        for (AllottedResource allottedResource : allottedResources) {
            TemplateInfo nsstInfo = new TemplateInfo()
            nsstInfo.setUUID(allottedResource.getProvidingServiceModelUuid())
            nsstInfo.setInvariantUUID(allottedResource.getProvidingServiceModelInvariantUuid())
            nsstInfo.setName(allottedResource.getProvidingServiceModelName())
            nsstInfos.add(nsstInfo)
        }
        execution.setVariable("nsstInfos", nsstInfos)

        execution.setVariable("maxNsstIndex", allottedResources.size() - 1)
        execution.setVariable("currentNsstIndex", 0)

        List<ServiceDecomposition> nsstServiceDecompositions = new ArrayList<>()
        execution.setVariable("nsstServiceDecompositions", nsstServiceDecompositions)
    }

    /**
     * prepare the params for decompose nsst
     * @param execution
     */
    public void prepareDecomposeNSST(DelegateExecution execution) {

        List<TemplateInfo> nsstInfos = execution.getVariable("nsstInfos") as List<TemplateInfo>
        int index = execution.getVariable("currentNsstIndex") as Integer

        String modelUuid = nsstInfos.get(index).getUUID()
        String modelInvariantUuid = nsstInfos.get(index).getInvariantUUID()

        String serviceModelInfo = """{
            "modelInvariantUuid":"${modelInvariantUuid}",
            "modelUuid":"${modelUuid}",
            "modelVersion":""
             }"""
        execution.setVariable("nsstServiceModelInfo", serviceModelInfo)

    }

    /**
     * process the result of NSST Decomposition
     * @param execution
     */
    public void processDecompositionNSST(DelegateExecution execution) {
        List<ServiceDecomposition> nsstServiceDecompositions =
                execution.getVariable("nsstServiceDecompositions") as List<ServiceDecomposition>

        ServiceDecomposition nsstServiceDecomposition =
                execution.getVariable("nsstServiceDecomposition") as ServiceDecomposition

        nsstServiceDecompositions.add(nsstServiceDecomposition)

        execution.setVariable("nsstServiceDecompositions", nsstServiceDecompositions)

        int num = execution.getVariable("maxNsstIndex") as Integer
        int index = execution.getVariable("currentNsstIndex") as Integer

        List<TemplateInfo> nsstInfos = execution.getVariable("nsstInfos") as List<TemplateInfo>
        nsstInfos.get(index).name = nsstServiceDecomposition.modelInfo.modelName
        execution.setVariable("nsstInfos", nsstInfos)
        execution.setVariable("currentNsstIndex", index + 1)

        if (index >= num) {
            execution.setVariable("nsstHandleContinue", false)
        } else {
            execution.setVariable("nsstHandleContinue", true)
        }

    }

    /**
     * set nsst info to sliceTaskParams by type
     * @param execution
     */
    public void handleNsstByType(DelegateExecution execution) {

        SliceTaskParamsAdapter sliceParams =
                execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter

        List<ServiceDecomposition> nsstServiceDecompositions =
                execution.getVariable("nsstServiceDecompositions") as List<ServiceDecomposition>

        List<SubnetCapability> subnetCapabilities = new ArrayList<>()

        for (ServiceDecomposition serviceDecomposition : nsstServiceDecompositions) {
            handleByType(execution, serviceDecomposition, sliceParams, subnetCapabilities)
        }

        execution.setVariable("sliceTaskParams", sliceParams)
        execution.setVariable("subnetCapabilities", subnetCapabilities)
        execution.setVariable("queryNsiFirst", true)
        logger.debug("sliceTaskParams= " + sliceParams.toString())
    }

    private void handleByType(DelegateExecution execution, ServiceDecomposition serviceDecomposition,
                              SliceTaskParamsAdapter sliceParams, List<SubnetCapability> subnetCapabilities) {
        ModelInfo modelInfo = serviceDecomposition.getModelInfo()
        String vendor = serviceDecomposition.getServiceRole()
        SubnetType subnetType = convertServiceCategory(serviceDecomposition.getServiceCategory())

        switch (subnetType) {
            case SubnetType.TN_BH:
                sliceParams.tnBHSliceTaskInfo.vendor = vendor
                sliceParams.tnBHSliceTaskInfo.subnetType = subnetType
                sliceParams.tnBHSliceTaskInfo.networkType = subnetType.networkType
                sliceParams.tnBHSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
                sliceParams.tnBHSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
                sliceParams.tnBHSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
                break
            case SubnetType.TN_MH:
                sliceParams.tnMHSliceTaskInfo.vendor = vendor
                sliceParams.tnMHSliceTaskInfo.subnetType = subnetType
                sliceParams.tnMHSliceTaskInfo.networkType = subnetType.networkType
                sliceParams.tnMHSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
                sliceParams.tnMHSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
                sliceParams.tnMHSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
                break
            case SubnetType.AN:
                sliceParams.anSliceTaskInfo.vendor = vendor
                sliceParams.anSliceTaskInfo.subnetType = subnetType
                sliceParams.anSliceTaskInfo.networkType = subnetType.networkType
                sliceParams.anSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
                sliceParams.anSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
                sliceParams.anSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
                break
            case SubnetType.CN:
                sliceParams.cnSliceTaskInfo.vendor = vendor
                sliceParams.cnSliceTaskInfo.subnetType = subnetType
                sliceParams.cnSliceTaskInfo.networkType = subnetType.networkType
                sliceParams.cnSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
                sliceParams.cnSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
                sliceParams.cnSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
                break
            default:
                subnetType = null
                break
        }
        if (null == subnetType) {
            def msg = "Get subnetType failed, modelUUId=" + modelInfo.getModelUuid()
            logger.error(msg)
            exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
        }
        String response = querySubnetCapability(execution, vendor, subnetType)
        if (!StringUtils.isEmpty(response)) {
            SubnetCapability subnetCapability = new SubnetCapability()
            Map<String, Object> result = objectMapper.readValue(response, Map.class)
            for (Map.Entry<String, Object> entry : result.entrySet()) {
                subnetCapability.setDomainType(entry.getKey())
                subnetCapability.setCapabilityDetails(entry.getValue())
            }
            subnetCapabilities.add(subnetCapability)
        }
    }

    /**
     * get subnetType from serviceCategory
     * @return
     */
    private SubnetType convertServiceCategory(String serviceCategory){
        if(serviceCategory ==~ /CN.*/){
            return SubnetType.CN
        }
        if (serviceCategory ==~ /AN.*/){
            return SubnetType.AN
        }
        if (serviceCategory ==~ /TN.*BH.*/){
            return SubnetType.TN_BH
        }
        if(serviceCategory ==~ /TN.*MH.*/){
            return SubnetType.TN_MH
        }
        return null
    }

    /**
     * query Subnet Capability of TN AN CN
     * @param execution
     */
    private String querySubnetCapability(DelegateExecution execution, String vendor, SubnetType subnetType) {

        String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_SUB_NET_CAPABILITY,
                buildQuerySubnetCapRequest(vendor, subnetType))
        return response
    }

    /**
     * build request body for querying Subnet Capability
     * @param vendor
     * @param subnetTypes
     * @param networkType
     * @return
     */
    private static NssmfAdapterNBIRequest buildQuerySubnetCapRequest(String vendor, SubnetType subnetType) {
        NssmfAdapterNBIRequest request = new NssmfAdapterNBIRequest()

        List<String> subnetTypes =  new ArrayList<>()
        subnetTypes.add(subnetType.subnetType)

        QuerySubnetCapability req = new QuerySubnetCapability()
        req.setSubnetTypes(subnetTypes)

        request.setSubnetCapabilityQuery(req)

        EsrInfo esrInfo = new EsrInfo()
        esrInfo.setVendor(vendor)
        esrInfo.setNetworkType(subnetType.networkType)
        request.setEsrInfo(esrInfo)

        return request
    }

    /**
     * todo: need rewrite
     * prepare select nsi request
     * @param execution
     */
    public void preNSIRequest(DelegateExecution execution) {
        boolean preferReuse = execution.getVariable("needQuerySliceProfile") ? false : true

        String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution)
        logger.debug( "get NSI option OOF Url: " + urlString)

        String requestId = execution.getVariable("msoRequestId")
        String messageType = "NSISelectionResponse"

        execution.setVariable("nsiSelectionUrl", "/api/oof/selection/nsi/v1")
        execution.setVariable("nsiSelection_messageType", messageType)
        execution.setVariable("nsiSelection_correlator", requestId)
        String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution)
        execution.setVariable("nsiSelection_timeout", timeout)

        SliceTaskParamsAdapter sliceParams =
                execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter

        Map<String, Object> profileInfo = sliceParams.getServiceProfile()
        profileInfo.remove("profileId")
        TemplateInfo nstInfo = sliceParams.getNSTInfo()

        List<TemplateInfo> nsstInfos = execution.getVariable("nsstInfos") as List<TemplateInfo>

        List<SubnetCapability> subnetCapabilities =
                execution.getVariable("subnetCapabilities") as List<SubnetCapability>

        String oofRequest = oofUtils.buildSelectNSIRequest(requestId, nstInfo, nsstInfos,
                messageType, profileInfo, subnetCapabilities, 600, preferReuse)

        execution.setVariable("nsiSelection_oofRequest", oofRequest)
        logger.debug("Sending request to OOF: " + oofRequest)
    }

    /**
     * process select nsi response
     * @param execution
     */
    public void processNSIResp(DelegateExecution execution) {

        SliceTaskParamsAdapter sliceTaskParams =
                execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter

        String oofResponse = execution.getVariable("nsiSelection_oofResponse")
        logger.debug("NSI oofResponse is: " + oofResponse)
        execution.setVariable("oofResponse", oofResponse)
        //This needs to be changed to derive a value when we add policy to decide the solution options.

        Map<String, Object> resMap = objectMapper.readValue(oofResponse, Map.class)
        String requestStatus = resMap.get("requestStatus")
        if (!StringUtils.isEmpty(requestStatus) && requestStatus == "error") {
            exceptionUtil.buildWorkflowException(execution, 7000, "get nsi from oof error: " + oofResponse)
            return
        }

        List<Map<String, Object>> nsiSolutions = (List<Map<String, Object>>) resMap.get("solutions")

        Map<String, Object> solution = nsiSolutions?.get(0)

        if (solution != null) {
            if (execution.getVariable("queryNsiFirst")) {
                if (solution.get("existingNSI")) {
                    execution.setVariable("needQuerySliceProfile", true)
                } else {
                    processNewNSI(solution, sliceTaskParams)
                    execution.setVariable("needQuerySliceProfile", false)
                }
                execution.setVariable("queryNsiFirst", false)
            } else {
                processSharedNSI(solution, sliceTaskParams, execution)
                execution.setVariable("needQuerySliceProfile", false)
            }
        }
        execution.setVariable("sliceTaskParams", sliceTaskParams)
        logger.debug("after req to oof for nis select, sliceTaskParams = " + sliceTaskParams)
        logger.debug("*** Completed options Call to OOF ***")
    }

    private void processSharedNSI(Map<String, Object> solution, SliceTaskParamsAdapter sliceParams, DelegateExecution execution) {
        Map<String, Object> sharedNSISolution = solution.get("sharedNSISolution") as Map
        String nsiId = sharedNSISolution.get("NSIId")
        String nsiName = sharedNSISolution.get("NSIName")
        sliceParams.setSuggestNsiId(nsiId)
        sliceParams.setSuggestNsiName(nsiName)

        List<String> nssiId = aaiSliceUtil.getNSSIIdList(execution,nsiId)
        List<ServiceInstance> nssiInstances = aaiSliceUtil.getNSSIListFromAAI(execution, nssiId)

        List<Map> sliceProfiles = sharedNSISolution.get("sliceProfiles") as List<Map>
        handleSliceProfiles(sliceProfiles, sliceParams)
        Map<String, Object> nssiSolution = new HashMap<>()
        for(ServiceInstance instance: nssiInstances){
            nssiSolution.put("NSSIId", instance.getServiceInstanceId())
            nssiSolution.put("NSSIName", instance.getServiceInstanceName())
            processNssiResult(sliceParams, instance.getEnvironmentContext(), nssiSolution)
        }

    }

    private void processNewNSI(Map<String, Object> solution, SliceTaskParamsAdapter sliceParams) {
        Map<String, Object> newNSISolution = solution.get("newNSISolution") as Map
        List<Map> sliceProfiles = newNSISolution.get("sliceProfiles") as List<Map>
        handleSliceProfiles(sliceProfiles, sliceParams)
    }

    static def handleSliceProfiles(List<Map> sliceProfiles, SliceTaskParamsAdapter sliceParams) {
        for (Map sliceProfile : sliceProfiles) {
            String domainType = sliceProfile.get("domainType")
            sliceProfile.remove("domainType")
            SliceProfileAdapter adapter = objectMapper.readValue(objectMapper.writeValueAsString(sliceProfile), SliceProfileAdapter.class)
            switch (domainType.toLowerCase()) {
                case "tn_bh":
                    sliceParams.tnBHSliceTaskInfo.sliceProfile = adapter
                    break
                case "an_nf":
                case "an":
                    sliceParams.anSliceTaskInfo.sliceProfile = adapter
                    break
                case "cn":
                    sliceParams.cnSliceTaskInfo.sliceProfile = adapter
                    break
                default:
                    break
            }
        }
    }

    /**
     * get NSSI Selection Capability for AN
     * @param execution
     */
    void getNSSISelectionCap4AN(DelegateExecution execution) {

        def vendor = execution.getVariable("vendor") as String

        String strRequest = buildNSSISelectionReq(vendor, NetworkType.ACCESS)

        String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_NSSI_SELECTION_CAPABILITY, strRequest)

        Map<String, Object> resMap = objectMapper.readValue(response, Map.class)

        String selection = resMap.get("selection")


        if ("NSMF".equalsIgnoreCase(selection)) {
            execution.setVariable("NEED_AN_NSSI_SELECTION", true)
        }
    }

    /**
     * get NSSI Selection Capability for TN
     * @param execution
     */
    void getNSSISelectionCap4TN(DelegateExecution execution) {

        def vendor = execution.getVariable("vendor") as String

        String strRequest = buildNSSISelectionReq(vendor, NetworkType.TRANSPORT)

        String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_NSSI_SELECTION_CAPABILITY, strRequest)

        Map<String, Object> resMap = objectMapper.readValue(response, Map.class)

        String selection = resMap.get("selection")

        if ("NSMF".equalsIgnoreCase(selection)) {
            execution.setVariable("NEED_TN_NSSI_SELECTION", true)
        }
    }

    /**
     * get NSSI Selection Capability for CN
     * @param execution
     */
    void getNSSISelectionCap4CN(DelegateExecution execution) {

        def vendor = execution.getVariable("vendor") as String

        String strRequest = buildNSSISelectionReq(vendor, NetworkType.CORE)

        String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_NSSI_SELECTION_CAPABILITY, strRequest)

        Map<String, Object> resMap = objectMapper.readValue(response, Map.class)

        String selection = resMap.get("selection")

        if ("NSMF".equalsIgnoreCase(selection)) {
            //execution.setVariable("NEED_CN_NSSI_SELECTION", true)
        }
    }

    /**
     * build NSSI Selection Capability Request body to nssmf adapter
     * @param vendor
     * @param networkType
     * @return
     */
    private static String buildNSSISelectionReq(String vendor, NetworkType networkType) {
        NssmfAdapterNBIRequest request = new NssmfAdapterNBIRequest()
        EsrInfo esrInfo = new EsrInfo()
        esrInfo.setVendor(vendor)
        esrInfo.setNetworkType(networkType)
        request.setEsrInfo(esrInfo)

        return objectMapper.writeValueAsString(request)
    }

    /**
     * if exist nssi need to select
     * @param execution
     */
    public void handleNssiSelect(DelegateExecution execution) {

        SliceTaskParamsAdapter sliceTaskParams =
                execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter

        //todo
        boolean needCnNssiSelection = execution.getVariable("NEED_CN_NSSI_SELECTION") as Boolean
        boolean needAnNssiSelection = execution.getVariable("NEED_AN_NSSI_SELECTION") as Boolean
        boolean needTnNssiSelection = execution.getVariable("NEED_TN_NSSI_SELECTION") as Boolean

        /**
         * [
         * ​	{
         * ​		"subType":  subtype,
         * ​		"nsstInfo": object,
         * ​		"sliceProfile": object
         * ​	},
         *      {
         *          "subType":  subtype,
         *          "nsstInfo": object,
         *          "sliceProfile": object
         *      }
         * ]
         */
        List<Map> nssiNeedHandlerInfos = new ArrayList<>()
        Map<String, Object> nssiNeedHandlerMap = new HashMap()

        //List<TemplateInfo> nssiNeedHandlers = new ArrayList<>()
        //List<Object> nssiProfileNeedHandlers = new ArrayList<>()
        if (needCnNssiSelection) {
            nssiNeedHandlerMap.put("subnetType", sliceTaskParams.cnSliceTaskInfo.subnetType)
            nssiNeedHandlerMap.put("nsstInfo", sliceTaskParams.cnSliceTaskInfo.NSSTInfo)
            nssiNeedHandlerMap.put("sliceProfile", sliceTaskParams.cnSliceTaskInfo.sliceProfile)
            nssiNeedHandlerInfos.add(nssiNeedHandlerMap)
        }
        if (needAnNssiSelection) {
            nssiNeedHandlerMap.clear()
            nssiNeedHandlerMap.put("subnetType", sliceTaskParams.anSliceTaskInfo.subnetType)
            nssiNeedHandlerMap.put("nsstInfo", sliceTaskParams.anSliceTaskInfo.NSSTInfo)
            nssiNeedHandlerMap.put("sliceProfile", sliceTaskParams.anSliceTaskInfo.sliceProfile)
            nssiNeedHandlerInfos.add(nssiNeedHandlerMap)
        }
        if (needTnNssiSelection) {
            nssiNeedHandlerMap.clear()
            nssiNeedHandlerMap.put("subnetType", sliceTaskParams.tnBHSliceTaskInfo.subnetType)
            nssiNeedHandlerMap.put("nsstInfo", sliceTaskParams.tnBHSliceTaskInfo.NSSTInfo)
            nssiNeedHandlerMap.put("sliceProfile", sliceTaskParams.tnBHSliceTaskInfo.sliceProfile)
            nssiNeedHandlerInfos.add(nssiNeedHandlerMap)

            nssiNeedHandlerMap.clear()
            nssiNeedHandlerMap.put("subnetType", sliceTaskParams.tnMHSliceTaskInfo.subnetType)
            nssiNeedHandlerMap.put("nsstInfo", sliceTaskParams.tnMHSliceTaskInfo.NSSTInfo)
            nssiNeedHandlerMap.put("sliceProfile", sliceTaskParams.tnMHSliceTaskInfo.sliceProfile)
            nssiNeedHandlerInfos.add(nssiNeedHandlerMap)

            nssiNeedHandlerMap.clear()
            nssiNeedHandlerMap.put("subnetType", sliceTaskParams.tnFHSliceTaskInfo.subnetType)
            nssiNeedHandlerMap.put("nsstInfo", sliceTaskParams.tnFHSliceTaskInfo.NSSTInfo)
            nssiNeedHandlerMap.put("sliceProfile", sliceTaskParams.tnFHSliceTaskInfo.sliceProfile)
            nssiNeedHandlerInfos.add(nssiNeedHandlerMap)

        }

        if (nssiNeedHandlerInfos.size() > 0) {
            execution.setVariable("needSelectNssi", true)
            execution.setVariable("currNssiIndex", 0)
            execution.setVariable("nssiNeedHandlerInfos", nssiNeedHandlerInfos)
        } else {
            execution.setVariable("needSelectNssi", false)
        }

        execution.setVariable("sliceTaskParams", sliceTaskParams)
    }

    /**
     * prepare select nssi request
     * @param execution
     */
    public void preNSSIRequest(DelegateExecution execution) {

        List<Map> nssiNeedHandlerInfos =
                execution.getVariable("nssiNeedHandlerInfos") as List<Map>

        int currNssiIndex = execution.getVariable("currNssiIndex") as Integer
        Map nssiNeedHandlerInfo = nssiNeedHandlerInfos.get(currNssiIndex) as Map

        TemplateInfo nsstInfo = nssiNeedHandlerInfo.get("nsstInfo") as TemplateInfo
        Map<String, Object> profileInfo = nssiNeedHandlerInfo.get("sliceProfile") as Map
        //profileInfo.remove("profileId")

        String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution)
        logger.debug( "get NSI option OOF Url: " + urlString)

        String requestId = execution.getVariable("msoRequestId")
        String messageType = "NSSISelectionResponse"

        execution.setVariable("nssiSelectionUrl", "/api/oof/selection/nssi/v1")
        execution.setVariable("nssiSelection_messageType", messageType)
        execution.setVariable("nssiSelection_correlator", requestId)
        String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution)
        execution.setVariable("nssiSelection_timeout", timeout)

        String oofRequest = oofUtils.buildSelectNSSIRequest(requestId, nsstInfo, messageType,
                profileInfo, 600)

        execution.setVariable("nssiSelection_oofRequest", oofRequest)
        logger.debug("Sending request to OOF: " + oofRequest)
    }

    /**
     * process select nssi response
     * @param execution
     */
    public void processNSSIResp(DelegateExecution execution) {

        List<Map> nssiNeedHandlerInfos =
                execution.getVariable("nssiNeedHandlerInfos") as List<Map>

        int currNssiIndex = execution.getVariable("currNssiIndex") as Integer
        Map nssiNeedHandlerInfo = nssiNeedHandlerInfos.get(currNssiIndex) as Map
        SubnetType subnetType = nssiNeedHandlerInfo.get("subnetType") as SubnetType

        SliceTaskParamsAdapter sliceTaskParams =
                execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter


        String OOFResponse = execution.getVariable("nssiSelection_oofResponse")
        logger.debug("NSI OOFResponse is: " + OOFResponse)
        execution.setVariable("OOFResponse", OOFResponse)
        //This needs to be changed to derive a value when we add policy to decide the solution options.

        Map<String, Object> resMap = objectMapper.readValue(OOFResponse, Map.class)
        List<Map<String, Object>> nsiSolutions = (List<Map<String, Object>>) resMap.get("solutions")
        Map<String, Object> solution = nsiSolutions.get(0)

        String resourceSharingLevel = execution.getVariable("resourceSharingLevel")
        Boolean isSharable = resourceSharingLevel == "shared"   //todo

        if (isSharable && solution != null) {
            processNssiResult(sliceTaskParams, subnetType, solution)
        }

        execution.setVariable("sliceTaskParams", sliceTaskParams)
        //logger.debug("sliceTaskParams: "+ sliceTaskParams.convertToJson())
        logger.debug("*** Completed options Call to OOF ***")

        logger.debug("start parseServiceProfile")
        //parseServiceProfile(execution)
        logger.debug("end parseServiceProfile")

        if (currNssiIndex >= nssiNeedHandlerInfos.size() - 1) {
            execution.setVariable("needSelectNssi", false)
        } else {
            execution.setVariable("currNssiIndex", currNssiIndex + 1)
            execution.setVariable("needSelectNssi", true)
        }

    }

    private void processNssiResult(SliceTaskParamsAdapter sliceTaskParams, SubnetType subnetType,
                                   Map<String, Object> solution) {
        switch (subnetType) {
            case SubnetType.CN:
                sliceTaskParams.cnSliceTaskInfo.suggestNssiId = solution.get("NSSIId")
                sliceTaskParams.cnSliceTaskInfo.suggestNssiName = solution.get("NSSIName")
                break
            case SubnetType.AN:
                sliceTaskParams.anSliceTaskInfo.suggestNssiId = solution.get("NSSIId")
                sliceTaskParams.anSliceTaskInfo.suggestNssiName = solution.get("NSSIName")
                break
            case SubnetType.TN_BH:
                sliceTaskParams.tnBHSliceTaskInfo.suggestNssiId = solution.get("NSSIId")
                sliceTaskParams.tnBHSliceTaskInfo.suggestNssiName = solution.get("NSSIName")
                break
            case SubnetType.TN_FH:
                sliceTaskParams.tnFHSliceTaskInfo.suggestNssiId = solution.get("NSSIId")
                sliceTaskParams.tnFHSliceTaskInfo.suggestNssiName = solution.get("NSSIName")
                break
            case SubnetType.TN_MH:
                sliceTaskParams.tnMHSliceTaskInfo.suggestNssiId = solution.get("NSSIId")
                sliceTaskParams.tnMHSliceTaskInfo.suggestNssiName = solution.get("NSSIName")
                break
        }
    }

}