2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 # Copyright (c) 2019, 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.core.type.TypeReference
24 import com.fasterxml.jackson.databind.ObjectMapper
25 import org.apache.commons.lang3.StringUtils
26 import org.camunda.bpm.engine.delegate.DelegateExecution
27 import org.onap.aai.domain.yang.ServiceInstance
28 import org.onap.aaiclient.client.aai.AAIObjectType
29 import org.onap.aaiclient.client.aai.AAIResourcesClient
30 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
31 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
32 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
33 import org.onap.logging.filter.base.ONAPComponents
34 import org.onap.so.beans.nsmf.*
35 import org.onap.so.beans.nsmf.oof.SubnetCapability
36 import org.onap.so.beans.nsmf.oof.TemplateInfo
37 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
38 import org.onap.so.bpmn.common.scripts.ExceptionUtil
39 import org.onap.so.bpmn.common.scripts.NssmfAdapterUtils
40 import org.onap.so.bpmn.common.scripts.OofUtils
41 import org.onap.so.bpmn.core.UrnPropertiesReader
42 import org.onap.so.bpmn.core.domain.ServiceDecomposition
43 import org.onap.so.bpmn.core.domain.ServiceProxy
44 import org.onap.so.bpmn.core.json.JsonUtils
45 import org.onap.so.client.HttpClient
46 import org.onap.so.client.HttpClientFactory
47 import org.slf4j.Logger
48 import org.slf4j.LoggerFactory
50 import javax.ws.rs.NotFoundException
51 import javax.ws.rs.core.Response
53 class DoCreateSliceServiceOptionV2 extends AbstractServiceTaskProcessor{
55 private static final Logger logger = LoggerFactory.getLogger( DoCreateSliceServiceOptionV2.class)
57 ExceptionUtil exceptionUtil = new ExceptionUtil()
59 JsonUtils jsonUtil = new JsonUtils()
61 OofUtils oofUtils = new OofUtils()
63 ObjectMapper objectMapper = new ObjectMapper()
65 void preProcessRequest (DelegateExecution execution) {
70 * prepare select nsi request
73 void prepareSelectNSIRequest(DelegateExecution execution) {
75 String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution)
76 logger.debug( "get NSI option OOF Url: " + urlString)
78 boolean isNSISuggested = true
79 execution.setVariable("isNSISuggested",isNSISuggested)
80 String requestId = execution.getVariable("msoRequestId")
81 String messageType = "NSISelectionResponse"
83 Map<String, Object> profileInfo = execution.getVariable("serviceProfile")
84 Map<String, Object> nstSolution = execution.getVariable("nstSolution")
85 logger.debug("Get NST selection from OOF: " + nstSolution.toString())
87 "modelInvariantId":"${nstSolution.invariantUUID}",
88 "modelVersionId":"${nstSolution.UUID}",
89 "modelName":"${nstSolution.NSTName}"
92 execution.setVariable("nsiSelectionUrl", "/api/oof/selection/nsi/v1")
93 execution.setVariable("nsiSelection_messageType",messageType)
94 execution.setVariable("nsiSelection_correlator",requestId)
95 String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution);
96 execution.setVariable("nsiSelection_timeout",timeout)
97 String oofRequest = oofUtils.buildSelectNSIRequest(requestId, nstInfo,messageType, profileInfo)
98 execution.setVariable("nsiSelection_oofRequest",oofRequest)
99 logger.debug("Sending request to OOF: " + oofRequest)
103 * process select nsi response
106 void processOOFResponse(DelegateExecution execution) {
108 SliceTaskParams sliceTaskParams = execution.getVariable("sliceTaskParams") as SliceTaskParams
109 String OOFResponse = execution.getVariable("nsiSelection_oofResponse")
110 logger.debug("NSI OOFResponse is: " + OOFResponse)
111 execution.setVariable("OOFResponse", OOFResponse)
112 //This needs to be changed to derive a value when we add policy to decide the solution options.
114 Map<String, Object> resMap = objectMapper.readValue(OOFResponse, Map.class)
115 List<Map<String, Object>> nsiSolutions = (List<Map<String, Object>>) resMap.get("solutions")
116 Map<String, Object> solutions = nsiSolutions.get(0)
118 String resourceSharingLevel = execution.getVariable("resourceSharingLevel")
119 Boolean isSharable = resourceSharingLevel == "shared"
121 if (solutions != null) {
122 if (isSharable && solutions.get("existingNSI")) {
124 processSharedNSISolutions(solutions, execution)
126 else if(solutions.containsKey("newNSISolution")) {
127 processNewNSISolutions(solutions, execution)
130 execution.setVariable("sliceTaskParams", sliceTaskParams)
131 logger.debug("sliceTaskParams: "+sliceTaskParams.convertToJson())
132 logger.debug("*** Completed options Call to OOF ***")
134 logger.debug("start parseServiceProfile")
135 parseServiceProfile(execution)
136 logger.debug("end parseServiceProfile")
140 private void processNewNSISolutions(Map solutions, DelegateExecution execution) {
142 List<Map> newNSISolutions = solutions.get("newNSISolution")
143 List<Map> NSSImap = new ArrayList<>()
144 if (newNSISolutions != null && newNSISolutions.size() > 0) {
145 NSSImap = newNSISolutions.get(index).get("NSSISolutions") as List<Map>
146 for (Map nssi : NSSImap) {
147 Map oofSliceProfile = nssi.get("sliceProfile")
148 String domain = oofSliceProfile.getOrDefault("domainType","")
149 logger.debug("OOF newNSISolutions SliceProfile: " +oofSliceProfile.toString()+",domain:${domain}")
152 // def nssiSolution = nssi.get("NSSISolution") as Map<String, ?>
153 // String nssiName = nssiSolution.getOrDefault("NSSIName", "")
154 // String nssiId = nssiSolution.getOrDefault("NSSIId", "")
155 // saveNSSIId(nssi, sliceTaskParams)
156 Map<String, Object> sliceProfile = getSliceProfile(domain, execution, oofSliceProfile)
157 saveSliceProfile(execution, domain, sliceProfile)
164 private void processSharedNSISolutions(Map solutions, DelegateExecution execution) {
165 String nsiName, nsiInstanceId, nssiId, nssiName
166 SliceTaskParams sliceTaskParams = execution.getVariable("sliceTaskParams")
168 Map sharedNSIsolution = ((List) solutions.get("sharedNSISolutions"))?.get(0)
169 nsiInstanceId = sharedNSIsolution.getOrDefault("NSIId", "")
170 nsiName = sharedNSIsolution.getOrDefault("NSIName", "")
171 sliceTaskParams.setSuggestNsiId(nsiInstanceId)
172 sliceTaskParams.setSuggestNsiName(nsiName)
174 //Temporary modification
175 List NSSIs = sharedNSIsolution.get("NSSIs")
176 for(Map nssi : NSSIs){
177 Map oofSliceProfile = ((List)nssi.get("sliceProfile"))?.get(0)
178 String domain = oofSliceProfile.getOrDefault("domainType","")
179 nssiId = nssi.getOrDefault("NSSIId","")
180 nssiName = nssi.getOrDefault("NSSIName","")
181 saveNSSIId(domain, nssiId, nssiName,execution)
182 Map<String, Object> sliceProfile = getSliceProfile(domain, execution, oofSliceProfile)
183 saveSliceProfile(execution, domain, sliceProfile)
184 logger.debug("OOF sharedNSISolution SliceProfile:"+oofSliceProfile.toString()+",domain:${domain}")
185 logger.debug("OOF sharedNSISolution nsiInstanceId:${nsiInstanceId}, nsiName:${nsiName}, nssiId:${nssiId}, nssiName:${nssiName}")
189 private void parseServiceProfile(DelegateExecution execution) {
190 logger.debug("Start parseServiceProfile")
191 String serviceType = execution.getVariable("serviceType")
192 Map<String, Object> serviceProfile = execution.getVariable("serviceProfile")
193 SliceTaskParams sliceTaskParams = execution.getVariable("sliceTaskParams")
194 // set sliceProfile for three domains
195 if(!sliceTaskParams.getSliceProfileAn()){
196 Map<String, Object> sliceProfileAn = getSliceProfile( "AN", execution,null)
197 saveSliceProfile(execution,"AN",sliceProfileAn)
200 if(!sliceTaskParams.getSliceProfileTn()){
201 Map<String, Object> sliceProfileTn = getSliceProfile( "TN", execution,null)
202 saveSliceProfile(execution,"TN",sliceProfileTn)
205 if(!sliceTaskParams.getSliceProfileCn()){
206 Map<String, Object> sliceProfileCn = getSliceProfile( "CN", execution,null, )
207 saveSliceProfile(execution,"CN",sliceProfileCn)
210 logger.debug("Finish parseServiceProfile")
213 private void saveSliceProfile(DelegateExecution execution, String domain, Map<String, Object> sliceProfile){
214 SliceTaskParams sliceTaskParams = execution.getVariable("sliceTaskParams")
215 if(domain.equalsIgnoreCase("AN")){
216 execution.setVariable("sliceProfileAn", sliceProfile)
217 sliceTaskParams.setSliceProfileAn(sliceProfile)
218 logger.debug("sliceProfileAn: " + sliceProfile)
220 else if(domain.equalsIgnoreCase("TN")){
221 execution.setVariable("sliceProfileTn", sliceProfile)
222 sliceTaskParams.setSliceProfileTn(sliceProfile)
223 logger.debug("sliceProfileTn: " + sliceProfile)
225 else if(domain.equalsIgnoreCase("CN")){
226 execution.setVariable("sliceProfileCn", sliceProfile)
227 sliceTaskParams.setSliceProfileCn(sliceProfile)
228 logger.debug("sliceProfileCn: " + sliceProfile)
232 private void saveNSSIId(String domain, String nssiId, String nssiName, DelegateExecution execution) {
233 SliceTaskParams sliceTaskParams = execution.getVariable("sliceTaskParams")
234 if(domain.equalsIgnoreCase("AN")){
235 sliceTaskParams.setAnSuggestNssiId(nssiId)
236 sliceTaskParams.setAnSuggestNssiName(nssiName)
238 else if(domain.equalsIgnoreCase("CN")){
239 sliceTaskParams.setCnSuggestNssiId(nssiId)
240 sliceTaskParams.setCnSuggestNssiName(nssiName)
242 else if(domain.equalsIgnoreCase("TN")){
243 sliceTaskParams.setTnSuggestNssiId(nssiId)
244 sliceTaskParams.setTnSuggestNssiName(nssiName)
248 private Map getSliceProfile(String domain, DelegateExecution execution, Map<String, Object> oofSliceProfile) {
250 Map<String, Object> serviceProfile = execution.getVariable("serviceProfile")
251 Integer domainLatency = (Integer) serviceProfile.get("latency")/3
253 if(domain.equalsIgnoreCase("AN")){
254 profileMapStr = """ {
255 "latency": ${domainLatency},
257 "uEMobilityLevel": "uEMobilityLevel",
258 "coverageAreaTAList": "coverageAreaTAList",
262 else if(domain.equalsIgnoreCase("TN")){
264 "latency":${domainLatency},
266 "e2eLatency":"latency",
270 else if(domain.equalsIgnoreCase("CN")){
271 profileMapStr = """ {
272 "areaTrafficCapDL":"areaTrafficCapDL",
273 "maxNumberofUEs":"maxNumberofUEs",
274 "latency":${domainLatency},
275 "expDataRateUL":"expDataRateUL",
277 "areaTrafficCapUL":"areaTrafficCapUL",
278 "uEMobilityLevel":"uEMobilityLevel",
279 "expDataRateDL":"expDataRateDL",
280 "activityFactor":"activityFactor",
281 "resourceSharingLevel":"resourceSharingLevel"
285 logger.debug("Profile map for " + domain + " : " + profileMapStr)
286 Map<String, Object> profileMaps = objectMapper.readValue(profileMapStr.trim().replaceAll(" ", ""), new TypeReference<Map<String, String>>(){})
287 Map<String, Object> sliceProfile = [:]
288 for (Map.Entry<String, String> profileMap : profileMaps) {
289 String key = profileMap.key
290 String value = profileMaps.get(key)
291 if(null != oofSliceProfile && oofSliceProfile.keySet().contains(key)){
292 sliceProfile.put(key, oofSliceProfile.get(key))
293 logger.debug("Get from oof, key:${key}, value: ${oofSliceProfile.get(key)}")
295 else if(serviceProfile.keySet().contains(value)){
296 sliceProfile.put(key, serviceProfile.get(value))
299 sliceProfile.put(key, profileMaps.get(key))
305 void processDecomposition(DelegateExecution execution){
306 logger.debug("Start processDecomposition")
308 ServiceDecomposition serviceDecomposition= execution.getVariable("serviceDecomposition")
309 SliceTaskParams sliceTaskParams = execution.getVariable("sliceTaskParams")
310 String nstName = serviceDecomposition.getModelInfo().getModelName()
311 String nstId = serviceDecomposition.getModelInfo().getModelUuid()
312 sliceTaskParams.setNstName(nstName)
313 sliceTaskParams.setNstId(nstId)
315 logger.debug("End processDecomposition")
319 void prepareNSTDecompose(DelegateExecution execution) {
321 String modelUuid = execution.getVariable("nstModelUuid")
322 String modelInvariantUuid = execution.getVariable("nstModelInvariantUuid")
324 String serviceModelInfo = """{
325 "modelInvariantUuid":"${modelInvariantUuid}",
326 "modelUuid":"${modelUuid}",
329 execution.setVariable("serviceModelInfo", serviceModelInfo)
332 void prepareNSSTDecompose(DelegateExecution execution) {
333 Boolean isMoreNSSTtoProcess = false
334 Integer maxNSST = execution.getVariable("maxNSST")
335 Integer currentNSST=execution.getVariable("currentNSST")
336 List<String> nsstModelUUIDList = new ArrayList<>()
337 nsstModelUUIDList = execution.getVariable("nsstModelUUIDList")
338 String modelUuid = nsstModelUUIDList.get(currentNSST)
339 String serviceModelInfo = """{
340 "modelInvariantUuid":"",
341 "modelUuid":"${modelUuid}",
344 execution.setVariable("serviceModelInfo", serviceModelInfo)
345 currentNSST=currentNSST+1
346 if(currentNSST<maxNSST)
347 isMoreNSSTtoProcess=true
348 execution.setVariable("isMoreNSSTtoProcess",isMoreNSSTtoProcess)
349 execution.setVariable("maxNSST",maxNSST)
350 execution.setVariable("currentNSST",currentNSST)
354 void prepareNSSTlistfromNST(DelegateExecution execution) {
355 //Need to update this part from decomposition.
356 logger.trace("Enter prepareNSSTlistfromNST()")
357 Boolean isMoreNSSTtoProcess = false
358 ServiceDecomposition serviceDecomposition= execution.getVariable("serviceDecomposition")
359 SliceTaskParams sliceTaskParams = execution.getVariable("sliceTaskParams")
360 String nstName = serviceDecomposition.getModelInfo().getModelName()
361 sliceTaskParams.setNstName(nstName)
362 String nstId = serviceDecomposition.getModelInfo().getModelUuid()
363 sliceTaskParams.setNstId(nstId)
364 execution.setVariable("sliceTaskParams",sliceTaskParams)
366 List<ServiceProxy> proxyList = serviceDecomposition.getServiceProxy()
367 List<String> nsstModelUUIDList = new ArrayList<>()
368 for(ServiceProxy serviceProxy:proxyList)
369 nsstModelUUIDList.add(serviceProxy.getSourceModelUuid())
370 execution.setVariable("nsstModelUUIDList",nsstModelUUIDList)
371 Integer maxNSST = nsstModelUUIDList.size()
372 Integer currentNSST=0
373 execution.setVariable("maxNSST",maxNSST)
374 execution.setVariable("currentNSST",currentNSST)
375 if(currentNSST<maxNSST)
376 isMoreNSSTtoProcess=true
377 execution.setVariable("isMoreNSSTtoProcess",isMoreNSSTtoProcess)
378 logger.trace("Exit prepareNSSTlistfromNST()")
382 void getNSSTOption(DelegateExecution execution) {
383 ServiceDecomposition serviceDecomposition= execution.getVariable("serviceDecomposition")
384 String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution)
385 String globalSubscriberId = execution.getVariable("globalSubscriberId")
386 String serviceType = execution.getVariable("subscriptionServiceType")
387 String nssiInstanceId =""
389 SliceTaskParams sliceTaskParams = execution.getVariable("sliceTaskParams")
390 logger.debug( "get NSI option OOF Url: " + urlString)
391 boolean isNSISuggested = false
392 execution.setVariable("isNSISuggested",isNSISuggested)
394 //Prepare auth for OOF - Begin
396 String basicAuth = UrnPropertiesReader.getVariable("mso.oof.auth", execution)
397 String msokey = UrnPropertiesReader.getVariable("mso.msoKey", execution)
399 String basicAuthValue = utils.encrypt(basicAuth, msokey)
400 if (basicAuthValue != null) {
401 logger.debug( "Obtained BasicAuth username and password for OOF: " + basicAuthValue)
403 authHeader = utils.getBasicAuth(basicAuthValue, msokey)
404 execution.setVariable("BasicAuthHeaderValue", authHeader)
405 } catch (Exception ex) {
406 logger.debug( "Unable to encode username and password string: " + ex)
407 exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Internal Error - Unable to " +
408 "encode username and password string")
411 logger.debug( "Unable to obtain BasicAuth - BasicAuth value null")
412 exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Internal Error - BasicAuth " +
415 //Prepare auth for OOF - End
416 //Prepare send request to OOF - Begin
417 String requestId = execution.getVariable("msoRequestId")
418 Map<String, Object> profileInfo = execution.getVariable("serviceProfile")
419 String nsstModelInvariantUuid = serviceDecomposition.getModelInfo().getModelInvariantUuid()
420 String nsstModelUuid = serviceDecomposition.getModelInfo().getModelUuid()
421 String nsstInfo = """"NSSTInfo": {
422 "invariantUUID":"${nsstModelInvariantUuid}",
423 "UUID":"${nsstModelUuid}"
425 String oofRequest = oofUtils.buildSelectNSSIRequest(execution, requestId, nsstInfo ,profileInfo)
428 URL url = new URL(urlString+"/api/oof/v1/selectnssi")
429 HttpClient httpClient = new HttpClientFactory().newJsonClient(url, ONAPComponents.OOF)
430 httpClient.addAdditionalHeader("Authorization", authHeader)
431 Response httpResponse = httpClient.post(oofRequest)
433 int responseCode = httpResponse.getStatus()
434 logger.debug("OOF sync response code is: " + responseCode)
436 if(responseCode != 200){
437 exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Sync Response from OOF.")
440 if(httpResponse.hasEntity()){
441 String OOFResponse = httpResponse.readEntity(String.class)
442 execution.setVariable("OOFResponse", OOFResponse)
443 nssiInstanceId = jsonUtil.getJsonValue(OOFResponse, "NSSIIInfo.NSSIID")
444 nssiName = jsonUtil.getJsonValue(OOFResponse, "NSSIInfo.NSSIName")
445 execution.setVariable("nssiInstanceId",nssiInstanceId)
446 execution.setVariable("nssiName",nssiName)
448 if(StringUtils.isBlank(nssiInstanceId)){
449 logger.debug( "There is no valid NSST suggested by OOF.")
453 AAIResourcesClient resourceClient = new AAIResourcesClient()
454 AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, nssiInstanceId)
455 AAIResultWrapper wrapper = resourceClient.get(serviceInstanceUri, NotFoundException.class)
456 Optional<ServiceInstance> si = wrapper.asBean(org.onap.aai.domain.yang.ServiceInstance.class)
457 org.onap.aai.domain.yang.ServiceInstance nssi = si.get()
459 String domain = nssi.getEnvironmentContext().toString().toUpperCase()
462 sliceTaskParams.setAnSuggestNssiId(nssi.getServiceInstanceId())
463 sliceTaskParams.setAnSuggestNssiName(nssi.getServiceInstanceName())
466 sliceTaskParams.setCnSuggestNssiId(nssi.getServiceInstanceId())
467 sliceTaskParams.setCnSuggestNssiName(nssi.getServiceInstanceName())
470 sliceTaskParams.setTnSuggestNssiId(nssi.getServiceInstanceId())
471 sliceTaskParams.setTnSuggestNssiName(nssi.getServiceInstanceName())
476 }catch(NotFoundException e)
478 logger.debug("NSSI Service Instance not found in AAI: " + nssiInstanceId)
481 logger.debug("NSSI Service Instance not found in AAI: " + nssiInstanceId)
484 logger.debug("Prepare NSSI option completed ")
492 private static final ObjectMapper MAPPER = new ObjectMapper()
494 private NssmfAdapterUtils nssmfAdapterUtils = new NssmfAdapterUtils(httpClientFactory, jsonUtil)
496 private static final String QUERY_SUB_NET_CAPABILITY = "/api/rest/provMns/v1/NSS/subnetCapabilityQuery"
498 private static final String QUERY_NSSI_SELECTION_CAPABILITY = "/api/rest/provMns/v1/NSS/NSSISelectionCapability"
501 * query Subnet Capability of TN
504 public void queryTNSubnetCapability(DelegateExecution execution) {
506 String vendor = execution.getVariable("vendor")
508 List<String> subnetTypes = new ArrayList<>()
509 subnetTypes.add("TN_FH")
510 subnetTypes.add("TN_MH")
511 subnetTypes.add("TN_BH")
513 String strRequest = MAPPER.writeValueAsString(
514 buildQuerySubnetCapRequest(vendor, subnetTypes, NetworkType.TRANSPORT))
516 String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_SUB_NET_CAPABILITY, strRequest)
517 execution.setVariable("subnetCapabilityOfTN", response)
521 * query Subnet Capability of CN
524 public void queryCNSubnetCapability(DelegateExecution execution) {
526 String vendor = execution.getVariable("vendor")
528 List<String> subnetTypes = new ArrayList<>()
529 subnetTypes.add("CN")
531 String strRequest = MAPPER.writeValueAsString(buildQuerySubnetCapRequest(vendor, subnetTypes, NetworkType.CORE))
533 String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_SUB_NET_CAPABILITY, strRequest)
535 execution.setVariable("subnetCapabilityOfCN", response)
539 * query Subnet Capability of AN
542 public void queryANSubnetCapability(DelegateExecution execution) {
544 String vendor = execution.getVariable("vendor")
546 List<String> subnetTypes = new ArrayList<>()
547 subnetTypes.add("AN-NF")
549 String strRequest = MAPPER.writeValueAsString(buildQuerySubnetCapRequest(vendor, subnetTypes, NetworkType.ACCESS))
551 String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_SUB_NET_CAPABILITY, strRequest)
553 execution.setVariable("subnetCapabilityOfAN", response)
557 * build request body for querying Subnet Capability
563 private static String buildQuerySubnetCapRequest(String vendor, List<String> subnetTypes, NetworkType networkType) {
564 NssmfAdapterNBIRequest request = new NssmfAdapterNBIRequest()
566 Map<String, Object> paramMap = new HashMap()
567 paramMap.put("subnetTypes", subnetTypes)
569 request.setSubnetCapabilityQuery(MAPPER.writeValueAsString(paramMap))
571 EsrInfo esrInfo = new EsrInfo()
572 esrInfo.setVendor(vendor)
573 esrInfo.setNetworkType(networkType)
575 request.setEsrInfo(esrInfo)
577 String strRequest = MAPPER.writeValueAsString(request)
583 * handle response of Subnet Capability, generate SubnetCapabilities Info for request to oof
586 public void generateSubnetCapabilities(DelegateExecution execution) {
588 execution.setVariable("subnetCapabilities", [])
592 * prepare the params for decompose nst
595 public void prepareDecomposeNST(DelegateExecution execution) {
597 String modelUuid = execution.getVariable("nstModelUuid")
598 String modelInvariantUuid = execution.getVariable("nstModelInvariantUuid")
600 String serviceModelInfo = """{
601 "modelInvariantUuid":"${modelInvariantUuid}",
602 "modelUuid":"${modelUuid}",
605 execution.setVariable("nstServiceModelInfo", serviceModelInfo)
609 * process the result of NST Decomposition
612 public void processDecompositionNST(DelegateExecution execution) {
614 ServiceDecomposition nstServiceDecomposition = execution.getVariable("nstServiceDecomposition")
621 * prepare the params for decompose nsst
624 public void prepareDecomposeNSST(DelegateExecution execution) {
625 Boolean isMoreNSSTtoProcess = false
626 def maxNSST = execution.getVariable("maxNSST") as Integer
627 def currentNSST = execution.getVariable("currentNSST") as Integer
628 def nsstModelUUIDList = execution.getVariable("nsstModelUUIDList") as List
629 String modelUuid = nsstModelUUIDList.get(currentNSST)
630 String serviceModelInfo = """{
631 "modelInvariantUuid":"",
632 "modelUuid":"${modelUuid}",
635 execution.setVariable("nsstServiceModelInfo", serviceModelInfo)
636 currentNSST = currentNSST + 1
638 if(currentNSST < maxNSST) {
639 isMoreNSSTtoProcess = true
642 execution.setVariable("isMoreNSSTtoProcess", isMoreNSSTtoProcess)
643 execution.setVariable("maxNSST", maxNSST)
644 execution.setVariable("currentNSST", currentNSST)
650 * process the result of NSST Decomposition
653 public void processDecompositionNSST(DelegateExecution execution) {
654 ServiceDecomposition nsstServiceDecomposition = execution.getVariable("nsstServiceDecomposition")
660 * prepare select nsi request
663 public void preNSIRequest(DelegateExecution execution) {
665 String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution)
666 logger.debug( "get NSI option OOF Url: " + urlString)
668 boolean isNSISuggested = true
669 execution.setVariable("isNSISuggested", isNSISuggested)
670 String requestId = execution.getVariable("msoRequestId")
671 String messageType = "NSISelectionResponse"
673 ServiceProfile profileInfo = execution.getVariable("serviceProfile") as ServiceProfile
674 Map<String, Object> nstSolution = execution.getVariable("nstSolution") as Map
675 logger.debug("Get NST selection from OOF: " + nstSolution.toString())
677 execution.setVariable("nsiSelectionUrl", "/api/oof/selection/nsi/v1")
678 execution.setVariable("nsiSelection_messageType", messageType)
679 execution.setVariable("nsiSelection_correlator", requestId)
680 String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution)
681 execution.setVariable("nsiSelection_timeout", timeout)
684 TemplateInfo nstInfo = new TemplateInfo()
685 nstInfo.setInvariantUUID(nstSolution.get("invariantUUID") as String)
686 nstInfo.setUUID(nstSolution.get("UUID") as String)
687 nstInfo.setName(nstSolution.get("NSTName") as String)
689 execution.setVariable("NSTInfo", nstInfo)
691 List<TemplateInfo> nsstInfos = execution.getVariable("NSSTInfos") as List<TemplateInfo>
693 List<SubnetCapability> subnetCapabilities = execution.getVariable("subnetCapabilities") as List<SubnetCapability>
695 String oofRequest = oofUtils.buildSelectNSIRequest(requestId, nstInfo, nsstInfos,
696 messageType, profileInfo, subnetCapabilities, timeout as Integer)
698 execution.setVariable("nsiSelection_oofRequest", oofRequest)
699 logger.debug("Sending request to OOF: " + oofRequest)
704 * process select nsi response
707 public void processNSIResp(DelegateExecution execution) {
709 SliceTaskParams sliceTaskParams = execution.getVariable("sliceTaskParams") as SliceTaskParams
710 String OOFResponse = execution.getVariable("nsiSelection_oofResponse")
711 logger.debug("NSI OOFResponse is: " + OOFResponse)
712 execution.setVariable("OOFResponse", OOFResponse)
713 //This needs to be changed to derive a value when we add policy to decide the solution options.
715 Map<String, Object> resMap = objectMapper.readValue(OOFResponse, Map.class)
716 List<Map<String, Object>> nsiSolutions = (List<Map<String, Object>>) resMap.get("solutions")
717 Map<String, Object> solutions = nsiSolutions.get(0)
719 String resourceSharingLevel = execution.getVariable("resourceSharingLevel")
720 Boolean isSharable = resourceSharingLevel == "shared"
722 if (solutions != null) {
723 if (isSharable && solutions.get("existingNSI")) {
725 processSharedNSISolutions(solutions, execution)
727 else if(solutions.containsKey("newNSISolution")) {
728 processNewNSISolutions(solutions, execution)
731 execution.setVariable("sliceTaskParams", sliceTaskParams)
732 logger.debug("sliceTaskParams: " + sliceTaskParams.convertToJson())
733 logger.debug("*** Completed options Call to OOF ***")
735 logger.debug("start parseServiceProfile")
736 parseServiceProfile(execution)
737 logger.debug("end parseServiceProfile")
741 * get NSSI Selection Capability for AN
744 public void getNSSISelectionCap4AN(DelegateExecution execution) {
746 def vendor = execution.getVariable("vendor") as String
748 String strRequest = buildNSSISelectionReq(vendor, NetworkType.ACCESS)
750 String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_NSSI_SELECTION_CAPABILITY, strRequest)
752 Map<String, Object> resMap = objectMapper.readValue(response, Map.class)
754 String selection = resMap.get("selection")
757 if ("NSMF".equalsIgnoreCase(selection)) {
758 execution.setVariable("NEED_AN_NSSI_SELECTION", true)
763 * get NSSI Selection Capability for TN
766 public void getNSSISelectionCap4TN(DelegateExecution execution) {
768 def vendor = execution.getVariable("vendor") as String
770 String strRequest = buildNSSISelectionReq(vendor, NetworkType.TRANSPORT)
772 String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_NSSI_SELECTION_CAPABILITY, strRequest)
774 Map<String, Object> resMap = objectMapper.readValue(response, Map.class)
776 String selection = resMap.get("selection")
778 if ("NSMF".equalsIgnoreCase(selection)) {
779 execution.setVariable("NEED_TN_NSSI_SELECTION", true)
784 * get NSSI Selection Capability for CN
787 public void getNSSISelectionCap4CN(DelegateExecution execution) {
789 def vendor = execution.getVariable("vendor") as String
791 String strRequest = buildNSSISelectionReq(vendor, NetworkType.CORE)
793 String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_NSSI_SELECTION_CAPABILITY, strRequest)
795 Map<String, Object> resMap = objectMapper.readValue(response, Map.class)
797 String selection = resMap.get("selection")
799 if ("NSMF".equalsIgnoreCase(selection)) {
800 execution.setVariable("NEED_CN_NSSI_SELECTION", true)
805 * build NSSI Selection Capability Request body to nssmf adapter
810 private static String buildNSSISelectionReq(String vendor, NetworkType networkType) {
811 NssmfAdapterNBIRequest request = new NssmfAdapterNBIRequest()
812 EsrInfo esrInfo = new EsrInfo()
813 esrInfo.setVendor(vendor)
814 esrInfo.setNetworkType(networkType)
815 request.setEsrInfo(esrInfo)
817 return MAPPER.writeValueAsString(request)
821 * if exist nssi need to select?
824 public void handleNssiSelect(DelegateExecution execution) {
826 SliceTaskParamsAdapter sliceTaskParams =
827 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
829 execution.setVariable()
834 * prepare select nssi request
837 public void preNSSIRequest(DelegateExecution execution) {
839 String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution)
840 logger.debug( "get NSI option OOF Url: " + urlString)
842 boolean isNSISuggested = true
843 execution.setVariable("isNSISuggested", isNSISuggested)
844 String requestId = execution.getVariable("msoRequestId")
845 String messageType = "NSISelectionResponse"
847 Map<String, Object> profileInfo = execution.getVariable("serviceProfile") as Map
848 Map<String, Object> nstSolution = execution.getVariable("nstSolution") as Map
849 logger.debug("Get NST selection from OOF: " + nstSolution.toString())
850 String nstInfo = """{
851 "modelInvariantId":"${nstSolution.invariantUUID}",
852 "modelVersionId":"${nstSolution.UUID}",
853 "modelName":"${nstSolution.NSTName}"
856 execution.setVariable("nsiSelectionUrl", "/api/oof/selection/nsi/v1")
857 execution.setVariable("nsiSelection_messageType", messageType)
858 execution.setVariable("nsiSelection_correlator", requestId)
859 String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution)
860 execution.setVariable("nsiSelection_timeout", timeout)
863 String oofRequest = oofUtils.buildSelectNSIRequest(requestId, nstInfo, messageType, profileInfo)
865 execution.setVariable("nsiSelection_oofRequest", oofRequest)
866 logger.debug("Sending request to OOF: " + oofRequest)
870 * process select nssi response
873 public void processNSSIResp(DelegateExecution execution) {
875 SliceTaskParams sliceTaskParams = execution.getVariable("sliceTaskParams") as SliceTaskParams
876 String OOFResponse = execution.getVariable("nsiSelection_oofResponse")
877 logger.debug("NSI OOFResponse is: " + OOFResponse)
878 execution.setVariable("OOFResponse", OOFResponse)
879 //This needs to be changed to derive a value when we add policy to decide the solution options.
881 Map<String, Object> resMap = objectMapper.readValue(OOFResponse, Map.class)
882 List<Map<String, Object>> nsiSolutions = (List<Map<String, Object>>) resMap.get("solutions")
883 Map<String, Object> solutions = nsiSolutions.get(0)
885 String resourceSharingLevel = execution.getVariable("resourceSharingLevel")
886 Boolean isSharable = resourceSharingLevel == "shared"
888 if (solutions != null) {
889 if (isSharable && solutions.get("existingNSI")) {
891 processSharedNSISolutions(solutions, execution)
893 else if(solutions.containsKey("newNSISolution")) {
894 processNewNSISolutions(solutions, execution)
897 execution.setVariable("sliceTaskParams", sliceTaskParams)
898 logger.debug("sliceTaskParams: "+sliceTaskParams.convertToJson())
899 logger.debug("*** Completed options Call to OOF ***")
901 logger.debug("start parseServiceProfile")
902 parseServiceProfile(execution)
903 logger.debug("end parseServiceProfile")