2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 # Copyright (c) 2020, CMCC Technologies Co., Ltd.
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
11 # http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.bpmn.infrastructure.scripts
23 import com.fasterxml.jackson.databind.ObjectMapper
24 import com.fasterxml.jackson.core.type.TypeReference
25 import org.camunda.bpm.engine.delegate.DelegateExecution
26 import org.onap.aai.domain.yang.ServiceInstance
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.QuerySubnetCapability
31 import org.onap.so.beans.nsmf.SliceProfileAdapter
32 import org.onap.so.beans.nsmf.SliceTaskParamsAdapter
33 import org.onap.so.beans.nsmf.oof.SubnetCapability
34 import org.onap.so.beans.nsmf.oof.SubnetType
35 import org.onap.so.beans.nsmf.oof.TemplateInfo
36 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
37 import org.onap.so.bpmn.common.scripts.ExceptionUtil
38 import org.onap.so.bpmn.common.scripts.NssmfAdapterUtils
39 import org.onap.so.bpmn.common.scripts.OofUtils
40 import org.onap.so.bpmn.core.UrnPropertiesReader
41 import org.onap.so.bpmn.core.domain.AllottedResource
42 import org.onap.so.bpmn.core.domain.ModelInfo
43 import org.onap.so.bpmn.core.domain.ServiceDecomposition
44 import org.onap.so.bpmn.core.json.JsonUtils
45 import org.slf4j.Logger
46 import org.slf4j.LoggerFactory
47 import org.springframework.util.StringUtils
50 class DoCreateSliceServiceOption extends AbstractServiceTaskProcessor{
52 private static final Logger logger = LoggerFactory.getLogger(DoCreateSliceServiceOption.class)
54 ExceptionUtil exceptionUtil = new ExceptionUtil()
56 JsonUtils jsonUtil = new JsonUtils()
58 OofUtils oofUtils = new OofUtils()
60 AAISliceUtil aaiSliceUtil = new AAISliceUtil()
62 private static final ObjectMapper objectMapper = new ObjectMapper()
64 private NssmfAdapterUtils nssmfAdapterUtils = new NssmfAdapterUtils(httpClientFactory, jsonUtil)
66 private static final String QUERY_SUB_NET_CAPABILITY = "/api/rest/provMns/v1/NSS/subnetCapabilityQuery"
68 private static final String QUERY_NSSI_SELECTION_CAPABILITY = "/api/rest/provMns/v1/NSS/NSSISelectionCapability"
70 void preProcessRequest (DelegateExecution execution) {
74 * prepare the params for decompose nst
77 void prepareDecomposeNST(DelegateExecution execution) {
79 SliceTaskParamsAdapter sliceTaskParams =
80 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
82 String modelUuid = sliceTaskParams.getNSTInfo().getUUID()
83 String modelInvariantUuid = sliceTaskParams.getNSTInfo().getInvariantUUID()
85 String serviceModelInfo = """{
86 "modelInvariantUuid":"${modelInvariantUuid}",
87 "modelUuid":"${modelUuid}",
90 execution.setVariable("nstServiceModelInfo", serviceModelInfo)
94 * process the result of NST Decomposition
97 public void processDecompositionNST(DelegateExecution execution) {
99 List<TemplateInfo> nsstInfos = new ArrayList<>()
100 ServiceDecomposition nstServiceDecomposition =
101 execution.getVariable("nstServiceDecomposition") as ServiceDecomposition
103 List<AllottedResource> allottedResources = nstServiceDecomposition.getAllottedResources()
104 for (AllottedResource allottedResource : allottedResources) {
105 TemplateInfo nsstInfo = new TemplateInfo()
106 nsstInfo.setUUID(allottedResource.getProvidingServiceModelUuid())
107 nsstInfo.setInvariantUUID(allottedResource.getProvidingServiceModelInvariantUuid())
108 nsstInfo.setName(allottedResource.getProvidingServiceModelName())
109 nsstInfos.add(nsstInfo)
111 execution.setVariable("nsstInfos", nsstInfos)
113 execution.setVariable("maxNsstIndex", allottedResources.size() - 1)
114 execution.setVariable("currentNsstIndex", 0)
116 List<ServiceDecomposition> nsstServiceDecompositions = new ArrayList<>()
117 execution.setVariable("nsstServiceDecompositions", nsstServiceDecompositions)
121 * prepare the params for decompose nsst
124 public void prepareDecomposeNSST(DelegateExecution execution) {
126 List<TemplateInfo> nsstInfos = execution.getVariable("nsstInfos") as List<TemplateInfo>
127 int index = execution.getVariable("currentNsstIndex") as Integer
129 String modelUuid = nsstInfos.get(index).getUUID()
130 String modelInvariantUuid = nsstInfos.get(index).getInvariantUUID()
132 String serviceModelInfo = """{
133 "modelInvariantUuid":"${modelInvariantUuid}",
134 "modelUuid":"${modelUuid}",
137 execution.setVariable("nsstServiceModelInfo", serviceModelInfo)
141 * process the result of NSST Decomposition
144 public void processDecompositionNSST(DelegateExecution execution) {
145 List<ServiceDecomposition> nsstServiceDecompositions =
146 execution.getVariable("nsstServiceDecompositions") as List<ServiceDecomposition>
148 ServiceDecomposition nsstServiceDecomposition =
149 execution.getVariable("nsstServiceDecomposition") as ServiceDecomposition
151 nsstServiceDecompositions.add(nsstServiceDecomposition)
153 execution.setVariable("nsstServiceDecompositions", nsstServiceDecompositions)
155 int num = execution.getVariable("maxNsstIndex") as Integer
156 int index = execution.getVariable("currentNsstIndex") as Integer
158 List<TemplateInfo> nsstInfos = execution.getVariable("nsstInfos") as List<TemplateInfo>
159 nsstInfos.get(index).name = nsstServiceDecomposition.modelInfo.modelName
160 execution.setVariable("nsstInfos", nsstInfos)
161 execution.setVariable("currentNsstIndex", index + 1)
164 execution.setVariable("nsstHandleContinue", false)
166 execution.setVariable("nsstHandleContinue", true)
171 * set nsst info to sliceTaskParams by type
174 public void handleNsstByType(DelegateExecution execution) {
176 SliceTaskParamsAdapter sliceParams =
177 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
179 List<ServiceDecomposition> nsstServiceDecompositions =
180 execution.getVariable("nsstServiceDecompositions") as List<ServiceDecomposition>
182 List<SubnetCapability> subnetCapabilities = new ArrayList<>()
184 for (ServiceDecomposition serviceDecomposition : nsstServiceDecompositions) {
185 handleByType(execution, serviceDecomposition, sliceParams, subnetCapabilities)
188 execution.setVariable("sliceTaskParams", sliceParams)
189 execution.setVariable("subnetCapabilities", subnetCapabilities)
190 execution.setVariable("queryNsiFirst", true)
191 logger.debug("sliceTaskParams= " + sliceParams.toString())
194 private void handleByType(DelegateExecution execution, ServiceDecomposition serviceDecomposition,
195 SliceTaskParamsAdapter sliceParams, List<SubnetCapability> subnetCapabilities) {
196 ModelInfo modelInfo = serviceDecomposition.getModelInfo()
197 String vendor = serviceDecomposition.getServiceRole()
198 SubnetType subnetType = convertServiceCategory(serviceDecomposition.getServiceCategory())
200 switch (subnetType) {
201 case SubnetType.TN_BH:
202 sliceParams.tnBHSliceTaskInfo.vendor = vendor
203 sliceParams.tnBHSliceTaskInfo.subnetType = subnetType
204 sliceParams.tnBHSliceTaskInfo.networkType = subnetType.networkType
205 sliceParams.tnBHSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
206 sliceParams.tnBHSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
207 sliceParams.tnBHSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
209 case SubnetType.TN_MH:
210 sliceParams.tnMHSliceTaskInfo.vendor = vendor
211 sliceParams.tnMHSliceTaskInfo.subnetType = subnetType
212 sliceParams.tnMHSliceTaskInfo.networkType = subnetType.networkType
213 sliceParams.tnMHSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
214 sliceParams.tnMHSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
215 sliceParams.tnMHSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
217 case SubnetType.TN_FH:
218 sliceParams.tnFHSliceTaskInfo.vendor = vendor
219 sliceParams.tnFHSliceTaskInfo.subnetType = subnetType
220 sliceParams.tnFHSliceTaskInfo.networkType = subnetType.networkType
221 sliceParams.tnFHSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
222 sliceParams.tnFHSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
223 sliceParams.tnFHSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
225 case SubnetType.AN_NF:
226 sliceParams.anNFSliceTaskInfo.vendor = vendor
227 sliceParams.anNFSliceTaskInfo.subnetType = subnetType
228 sliceParams.anNFSliceTaskInfo.networkType = subnetType.networkType
229 sliceParams.anNFSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
230 sliceParams.anNFSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
231 sliceParams.anNFSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
234 sliceParams.anSliceTaskInfo.vendor = vendor
235 sliceParams.anSliceTaskInfo.subnetType = subnetType
236 sliceParams.anSliceTaskInfo.networkType = subnetType.networkType
237 sliceParams.anSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
238 sliceParams.anSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
239 sliceParams.anSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
242 sliceParams.cnSliceTaskInfo.vendor = vendor
243 sliceParams.cnSliceTaskInfo.subnetType = subnetType
244 sliceParams.cnSliceTaskInfo.networkType = subnetType.networkType
245 sliceParams.cnSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
246 sliceParams.cnSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
247 sliceParams.cnSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
253 if (null == subnetType) {
254 def msg = "Get subnetType failed, modelUUId=" + modelInfo.getModelUuid()
256 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
258 String response = querySubnetCapability(execution, vendor, subnetType)
259 if (!StringUtils.isEmpty(response)) {
260 SubnetCapability subnetCapability = new SubnetCapability()
261 Map<String, Object> result = objectMapper.readValue(response, Map.class)
262 for (Map.Entry<String, Object> entry : result.entrySet()) {
263 subnetCapability.setDomainType(entry.getKey())
264 subnetCapability.setCapabilityDetails(entry.getValue())
266 subnetCapabilities.add(subnetCapability)
271 * get subnetType from serviceCategory
274 private SubnetType convertServiceCategory(String serviceCategory){
275 if(serviceCategory ==~ /CN.*/){
278 if (serviceCategory ==~ /AN.*/){
281 if (serviceCategory ==~ /TN.*BH.*/){
282 return SubnetType.TN_BH
284 if(serviceCategory ==~ /TN.*MH.*/){
285 return SubnetType.TN_MH
287 if(serviceCategory ==~ /TN.*FH.*/){
288 return SubnetType.TN_FH
295 * query Subnet Capability of TN AN CN
298 private String querySubnetCapability(DelegateExecution execution, String vendor, SubnetType subnetType) {
300 String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_SUB_NET_CAPABILITY,
301 buildQuerySubnetCapRequest(vendor, subnetType))
306 * build request body for querying Subnet Capability
312 private static NssmfAdapterNBIRequest buildQuerySubnetCapRequest(String vendor, SubnetType subnetType) {
313 NssmfAdapterNBIRequest request = new NssmfAdapterNBIRequest()
315 List<String> subnetTypes = new ArrayList<>()
316 subnetTypes.add(subnetType.subnetType)
318 QuerySubnetCapability req = new QuerySubnetCapability()
319 req.setSubnetTypes(subnetTypes)
321 request.setSubnetCapabilityQuery(req)
323 EsrInfo esrInfo = new EsrInfo()
324 esrInfo.setVendor(vendor)
325 esrInfo.setNetworkType(subnetType.networkType)
326 request.setEsrInfo(esrInfo)
333 * prepare select nsi request
336 public void preNSIRequest(DelegateExecution execution) {
337 boolean preferReuse = execution.getVariable("needQuerySliceProfile") ? false : true
339 String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution)
340 logger.debug( "get NSI option OOF Url: " + urlString)
342 String requestId = execution.getVariable("msoRequestId")
343 String messageType = "NSISelectionResponse"
345 execution.setVariable("nsiSelectionUrl", "/api/oof/selection/nsi/v1")
346 execution.setVariable("nsiSelection_messageType", messageType)
347 execution.setVariable("nsiSelection_correlator", requestId)
348 String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution)
349 execution.setVariable("nsiSelection_timeout", timeout)
351 SliceTaskParamsAdapter sliceParams =
352 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
354 Map<String, Object> profileInfo = sliceParams.getServiceProfile()
355 profileInfo.remove("profileId")
356 TemplateInfo nstInfo = sliceParams.getNSTInfo()
358 List<TemplateInfo> nsstInfos = execution.getVariable("nsstInfos") as List<TemplateInfo>
360 List<SubnetCapability> subnetCapabilities =
361 execution.getVariable("subnetCapabilities") as List<SubnetCapability>
363 String oofRequest = oofUtils.buildSelectNSIRequest(requestId, nstInfo, nsstInfos,
364 messageType, profileInfo, subnetCapabilities, 600, preferReuse)
366 execution.setVariable("nsiSelection_oofRequest", oofRequest)
367 logger.debug("Sending request to OOF: " + oofRequest)
371 * process select nsi response
374 public void processNSIResp(DelegateExecution execution) {
376 SliceTaskParamsAdapter sliceTaskParams =
377 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
379 String oofResponse = execution.getVariable("nsiSelection_oofResponse")
380 logger.debug("NSI oofResponse is: " + oofResponse)
381 execution.setVariable("oofResponse", oofResponse)
382 //This needs to be changed to derive a value when we add policy to decide the solution options.
384 Map<String, Object> resMap = objectMapper.readValue(oofResponse, Map.class)
385 String requestStatus = resMap.get("requestStatus")
386 if (!StringUtils.isEmpty(requestStatus) && requestStatus == "error") {
387 exceptionUtil.buildWorkflowException(execution, 7000, "get nsi from oof error: " + oofResponse)
391 List<Map<String, Object>> nsiSolutions = (List<Map<String, Object>>) resMap.get("solutions")
393 Map<String, Object> solution = nsiSolutions?.get(0)
395 if (solution != null) {
396 if (execution.getVariable("queryNsiFirst")) {
397 if (solution.get("existingNSI")) {
398 processSharedNSI(solution, sliceTaskParams, execution)
399 execution.setVariable("needQuerySliceProfile", true)
401 processNewSliceProfiles(solution, sliceTaskParams)
402 execution.setVariable("needQuerySliceProfile", false)
404 execution.setVariable("queryNsiFirst", false)
406 processNewSliceProfiles(solution, sliceTaskParams)
407 execution.setVariable("needQuerySliceProfile", false)
410 execution.setVariable("sliceTaskParams", sliceTaskParams)
411 logger.debug("after req to oof for nis select, sliceTaskParams = " + sliceTaskParams)
412 logger.debug("*** Completed options Call to OOF ***")
415 private void processSharedNSI(Map<String, Object> solution, SliceTaskParamsAdapter sliceParams, DelegateExecution execution) {
416 Map<String, Object> sharedNSISolution = solution.get("sharedNSISolution") as Map
417 String nsiId = sharedNSISolution.get("NSIId")
418 String nsiName = sharedNSISolution.get("NSIName")
419 sliceParams.setSuggestNsiId(nsiId)
420 sliceParams.setSuggestNsiName(nsiName)
422 List<String> nssiId = aaiSliceUtil.getNSSIIdList(execution,nsiId)
423 List<ServiceInstance> nssiInstances = aaiSliceUtil.getNSSIListFromAAI(execution, nssiId)
425 Map<String, Object> nssiSolution = new HashMap<>()
426 for(ServiceInstance instance: nssiInstances){
427 nssiSolution.put("NSSIId", instance.getServiceInstanceId())
428 nssiSolution.put("NSSIName", instance.getServiceInstanceName())
429 SubnetType subnetType = instance.getWorkloadContext() as SubnetType
430 processNssiResult(sliceParams, subnetType, nssiSolution)
435 private void processNewSliceProfiles(Map<String, Object> solution, SliceTaskParamsAdapter sliceParams) {
436 Map<String, Object> newNSISolution = solution.get("newNSISolution") as Map
437 List<Map> sliceProfiles = newNSISolution.get("sliceProfiles") as List<Map>
438 handleSliceProfiles(sliceProfiles, sliceParams)
441 static def handleSliceProfiles(List<Map> sliceProfiles, SliceTaskParamsAdapter sliceParams) {
442 for (Map sliceProfile : sliceProfiles) {
443 String domainType = sliceProfile.get("domainType")
444 sliceProfile.remove("domainType")
445 SliceProfileAdapter adapter = objectMapper.readValue(objectMapper.writeValueAsString(sliceProfile), SliceProfileAdapter.class)
446 switch (domainType.toLowerCase()) {
448 sliceParams.tnBHSliceTaskInfo.sliceProfile = adapter
451 sliceParams.tnFHSliceTaskInfo.sliceProfile = adapter
454 sliceParams.tnMHSliceTaskInfo.sliceProfile = adapter
457 sliceParams.anNFSliceTaskInfo.sliceProfile = adapter
460 sliceParams.anSliceTaskInfo.sliceProfile = adapter
463 sliceParams.cnSliceTaskInfo.sliceProfile = adapter
472 * get NSSI Selection Capability for AN
475 void getNSSISelectionCap4AN(DelegateExecution execution) {
477 SliceTaskParamsAdapter sliceParams =
478 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
480 def vendor = sliceParams.anSliceTaskInfo.vendor
482 String strRequest = buildNSSISelectionReq(vendor, NetworkType.ACCESS)
484 String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_NSSI_SELECTION_CAPABILITY, strRequest)
486 Map<String, Object> resMap = objectMapper.readValue(response, Map.class)
488 String selection = resMap.get("selection")
491 if ("NSMF".equalsIgnoreCase(selection)) {
492 execution.setVariable("NEED_AN_NSSI_SELECTION", true)
497 * get NSSI Selection Capability for TN
500 void getNSSISelectionCap4TN(DelegateExecution execution) {
502 SliceTaskParamsAdapter sliceParams =
503 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
505 def vendor = sliceParams.tnBHSliceTaskInfo.vendor
507 String strRequest = buildNSSISelectionReq(vendor, NetworkType.TRANSPORT)
509 String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_NSSI_SELECTION_CAPABILITY, strRequest)
511 Map<String, Object> resMap = objectMapper.readValue(response, Map.class)
513 String selection = resMap.get("selection")
515 if ("NSMF".equalsIgnoreCase(selection)) {
516 execution.setVariable("NEED_TN_NSSI_SELECTION", true)
521 * get NSSI Selection Capability for CN
524 void getNSSISelectionCap4CN(DelegateExecution execution) {
526 SliceTaskParamsAdapter sliceParams =
527 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
529 def vendor = sliceParams.cnSliceTaskInfo.vendor
531 String strRequest = buildNSSISelectionReq(vendor, NetworkType.CORE)
533 String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_NSSI_SELECTION_CAPABILITY, strRequest)
535 Map<String, Object> resMap = objectMapper.readValue(response, Map.class)
537 String selection = resMap.get("selection")
539 if ("NSMF".equalsIgnoreCase(selection)) {
540 //execution.setVariable("NEED_CN_NSSI_SELECTION", true)
545 * build NSSI Selection Capability Request body to nssmf adapter
550 private static String buildNSSISelectionReq(String vendor, NetworkType networkType) {
551 NssmfAdapterNBIRequest request = new NssmfAdapterNBIRequest()
552 EsrInfo esrInfo = new EsrInfo()
553 esrInfo.setVendor(vendor)
554 esrInfo.setNetworkType(networkType)
555 request.setEsrInfo(esrInfo)
557 return objectMapper.writeValueAsString(request)
561 * if exist nssi need to select
564 public void handleNssiSelect(DelegateExecution execution) {
566 SliceTaskParamsAdapter sliceTaskParams =
567 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
570 boolean needCnNssiSelection = execution.getVariable("NEED_CN_NSSI_SELECTION") as Boolean
571 boolean needAnNssiSelection = execution.getVariable("NEED_AN_NSSI_SELECTION") as Boolean
572 boolean needTnNssiSelection = execution.getVariable("NEED_TN_NSSI_SELECTION") as Boolean
574 List<Map> nssiNeedHandlerInfos = new ArrayList<>()
575 Map<String, Object> nssiNeedHandlerMap = new HashMap()
577 //List<TemplateInfo> nssiNeedHandlers = new ArrayList<>()
578 //List<Object> nssiProfileNeedHandlers = new ArrayList<>()
579 if (needCnNssiSelection) {
580 nssiNeedHandlerMap.put("subnetType", sliceTaskParams.cnSliceTaskInfo.subnetType)
581 nssiNeedHandlerMap.put("nsstInfo", sliceTaskParams.cnSliceTaskInfo.NSSTInfo)
582 nssiNeedHandlerMap.put("sliceProfile", sliceTaskParams.cnSliceTaskInfo.sliceProfile)
583 nssiNeedHandlerInfos.add(nssiNeedHandlerMap)
585 if (needAnNssiSelection) {
586 nssiNeedHandlerMap.clear()
587 nssiNeedHandlerMap.put("subnetType", sliceTaskParams.anSliceTaskInfo.subnetType)
588 nssiNeedHandlerMap.put("nsstInfo", sliceTaskParams.anSliceTaskInfo.NSSTInfo)
589 nssiNeedHandlerMap.put("sliceProfile", sliceTaskParams.anSliceTaskInfo.sliceProfile)
590 nssiNeedHandlerInfos.add(nssiNeedHandlerMap)
592 if (needTnNssiSelection) {
593 nssiNeedHandlerMap.clear()
594 nssiNeedHandlerMap.put("subnetType", sliceTaskParams.tnBHSliceTaskInfo.subnetType)
595 nssiNeedHandlerMap.put("nsstInfo", sliceTaskParams.tnBHSliceTaskInfo.NSSTInfo)
596 nssiNeedHandlerMap.put("sliceProfile", sliceTaskParams.tnBHSliceTaskInfo.sliceProfile)
597 nssiNeedHandlerInfos.add(nssiNeedHandlerMap)
599 nssiNeedHandlerMap.clear()
600 nssiNeedHandlerMap.put("subnetType", sliceTaskParams.tnMHSliceTaskInfo.subnetType)
601 nssiNeedHandlerMap.put("nsstInfo", sliceTaskParams.tnMHSliceTaskInfo.NSSTInfo)
602 nssiNeedHandlerMap.put("sliceProfile", sliceTaskParams.tnMHSliceTaskInfo.sliceProfile)
603 nssiNeedHandlerInfos.add(nssiNeedHandlerMap)
605 nssiNeedHandlerMap.clear()
606 nssiNeedHandlerMap.put("subnetType", sliceTaskParams.tnFHSliceTaskInfo.subnetType)
607 nssiNeedHandlerMap.put("nsstInfo", sliceTaskParams.tnFHSliceTaskInfo.NSSTInfo)
608 nssiNeedHandlerMap.put("sliceProfile", sliceTaskParams.tnFHSliceTaskInfo.sliceProfile)
609 nssiNeedHandlerInfos.add(nssiNeedHandlerMap)
613 if (nssiNeedHandlerInfos.size() > 0) {
614 execution.setVariable("needSelectNssi", true)
615 execution.setVariable("currNssiIndex", 0)
616 execution.setVariable("nssiNeedHandlerInfos", nssiNeedHandlerInfos)
618 execution.setVariable("needSelectNssi", false)
621 execution.setVariable("sliceTaskParams", sliceTaskParams)
625 * prepare select nssi request
628 public void preNSSIRequest(DelegateExecution execution) {
630 List<Map> nssiNeedHandlerInfos =
631 execution.getVariable("nssiNeedHandlerInfos") as List<Map>
633 int currNssiIndex = execution.getVariable("currNssiIndex") as Integer
634 Map nssiNeedHandlerInfo = nssiNeedHandlerInfos.get(currNssiIndex) as Map
636 TemplateInfo nsstInfo = nssiNeedHandlerInfo.get("nsstInfo") as TemplateInfo
637 SliceProfileAdapter sliceProfileInfo = nssiNeedHandlerInfo.get("sliceProfile") as SliceProfileAdapter
639 Map profileInfo = objectMapper.convertValue(sliceProfileInfo, new TypeReference<Map<String, Object>>() {});
640 while (profileInfo.values().remove(null));
642 String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution)
643 logger.debug( "get NSI option OOF Url: " + urlString)
645 String requestId = execution.getVariable("msoRequestId")
646 String messageType = "NSSISelectionResponse"
648 execution.setVariable("nssiSelectionUrl", "/api/oof/selection/nssi/v1")
649 execution.setVariable("nssiSelection_messageType", messageType)
650 execution.setVariable("nssiSelection_correlator", requestId)
651 String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution)
652 execution.setVariable("nssiSelection_timeout", timeout)
654 String oofRequest = oofUtils.buildSelectNSSIRequest(requestId, messageType, nsstInfo.UUID,
655 nsstInfo.invariantUUID, nsstInfo.name, profileInfo)
657 execution.setVariable("nssiSelection_oofRequest", oofRequest)
658 logger.debug("Sending request to OOF: " + oofRequest)
662 * process select nssi response
665 public void processNSSIResp(DelegateExecution execution) {
667 List<Map> nssiNeedHandlerInfos =
668 execution.getVariable("nssiNeedHandlerInfos") as List<Map>
670 int currNssiIndex = execution.getVariable("currNssiIndex") as Integer
671 Map nssiNeedHandlerInfo = nssiNeedHandlerInfos.get(currNssiIndex) as Map
672 SubnetType subnetType = nssiNeedHandlerInfo.get("subnetType") as SubnetType
674 SliceTaskParamsAdapter sliceTaskParams =
675 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
678 String OOFResponse = execution.getVariable("nssiSelection_oofResponse")
679 logger.debug("NSI OOFResponse is: " + OOFResponse)
680 execution.setVariable("OOFResponse", OOFResponse)
681 //This needs to be changed to derive a value when we add policy to decide the solution options.
683 Map<String, Object> resMap = objectMapper.readValue(OOFResponse, Map.class)
684 List<Map<String, Object>> nsiSolutions = (List<Map<String, Object>>) resMap.get("solutions")
686 if(nsiSolutions.size()>=1) {
687 Map<String,Object> solution = nsiSolutions.get(0) as Map
688 processNssiResult(sliceTaskParams, subnetType, solution)
691 execution.setVariable("sliceTaskParams", sliceTaskParams)
692 //logger.debug("sliceTaskParams: "+ sliceTaskParams.convertToJson())
693 logger.debug("*** Completed options Call to OOF ***")
695 logger.debug("start parseServiceProfile")
696 //parseServiceProfile(execution)
697 logger.debug("end parseServiceProfile")
699 if (currNssiIndex >= nssiNeedHandlerInfos.size() - 1) {
700 execution.setVariable("needSelectNssi", false)
702 execution.setVariable("currNssiIndex", currNssiIndex + 1)
703 execution.setVariable("needSelectNssi", true)
708 private void processNssiResult(SliceTaskParamsAdapter sliceTaskParams, SubnetType subnetType,
709 Map<String, Object> solution) {
710 switch (subnetType) {
712 sliceTaskParams.cnSliceTaskInfo.suggestNssiId = solution.get("NSSIId")
713 sliceTaskParams.cnSliceTaskInfo.suggestNssiName = solution.get("NSSIName")
716 sliceTaskParams.anSliceTaskInfo.suggestNssiId = solution.get("NSSIId")
717 sliceTaskParams.anSliceTaskInfo.suggestNssiName = solution.get("NSSIName")
719 case SubnetType.TN_BH:
720 sliceTaskParams.tnBHSliceTaskInfo.suggestNssiId = solution.get("NSSIId")
721 sliceTaskParams.tnBHSliceTaskInfo.suggestNssiName = solution.get("NSSIName")
723 case SubnetType.TN_FH:
724 sliceTaskParams.tnFHSliceTaskInfo.suggestNssiId = solution.get("NSSIId")
725 sliceTaskParams.tnFHSliceTaskInfo.suggestNssiName = solution.get("NSSIName")
727 case SubnetType.TN_MH:
728 sliceTaskParams.tnMHSliceTaskInfo.suggestNssiId = solution.get("NSSIId")
729 sliceTaskParams.tnMHSliceTaskInfo.suggestNssiName = solution.get("NSSIName")