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 org.camunda.bpm.engine.delegate.DelegateExecution
25 import org.onap.so.beans.nsmf.AnSliceProfile
26 import org.onap.so.beans.nsmf.CnSliceProfile
27 import org.onap.so.beans.nsmf.EsrInfo
28 import org.onap.so.beans.nsmf.NetworkType
29 import org.onap.so.beans.nsmf.NssmfAdapterNBIRequest
30 import org.onap.so.beans.nsmf.SliceTaskParams
31 import org.onap.so.beans.nsmf.SliceTaskParamsAdapter
32 import org.onap.so.beans.nsmf.TnSliceProfile
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
46 import org.slf4j.Logger
47 import org.slf4j.LoggerFactory
48 import org.springframework.http.ResponseEntity
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 private static final ObjectMapper objectMapper = new ObjectMapper()
62 private NssmfAdapterUtils nssmfAdapterUtils = new NssmfAdapterUtils(httpClientFactory, jsonUtil)
64 private static final String QUERY_SUB_NET_CAPABILITY = "/api/rest/provMns/v1/NSS/subnetCapabilityQuery"
66 private static final String QUERY_NSSI_SELECTION_CAPABILITY = "/api/rest/provMns/v1/NSS/NSSISelectionCapability"
68 void preProcessRequest (DelegateExecution execution) {
72 * prepare the params for decompose nst
75 public void prepareDecomposeNST(DelegateExecution execution) {
77 SliceTaskParamsAdapter sliceTaskParams =
78 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
80 String modelUuid = sliceTaskParams.getNSTInfo().getUUID()
81 String modelInvariantUuid = sliceTaskParams.getNSTInfo().getInvariantUUID()
83 String serviceModelInfo = """{
84 "modelInvariantUuid":"${modelInvariantUuid}",
85 "modelUuid":"${modelUuid}",
88 execution.setVariable("nstServiceModelInfo", serviceModelInfo)
92 * process the result of NST Decomposition
95 public void processDecompositionNST(DelegateExecution execution) {
97 List<TemplateInfo> nsstInfos = new ArrayList<>()
98 ServiceDecomposition nstServiceDecomposition =
99 execution.getVariable("nstServiceDecomposition") as ServiceDecomposition
101 List<AllottedResource> allottedResources = nstServiceDecomposition.getAllottedResources()
102 for (AllottedResource allottedResource : allottedResources) {
103 TemplateInfo nsstInfo = new TemplateInfo()
104 nsstInfo.setUUID(allottedResource.getProvidingServiceModelUuid())
105 nsstInfo.setInvariantUUID(allottedResource.getProvidingServiceModelInvariantUuid())
106 nsstInfo.setName(allottedResource.getProvidingServiceModelName())
107 nsstInfos.add(nsstInfo)
109 execution.setVariable("nsstInfos", nsstInfos)
111 execution.setVariable("maxNsstIndex", allottedResources.size() - 1)
112 execution.setVariable("currentNsstIndex", 0)
114 List<ServiceDecomposition> nsstServiceDecompositions = new ArrayList<>()
115 execution.setVariable("nsstServiceDecompositions", nsstServiceDecompositions)
119 * prepare the params for decompose nsst
122 public void prepareDecomposeNSST(DelegateExecution execution) {
124 List<TemplateInfo> nsstInfos = execution.getVariable("nsstInfos") as List<TemplateInfo>
125 int index = execution.getVariable("currentNsstIndex") as Integer
127 String modelUuid = nsstInfos.get(index).getUUID()
128 String modelInvariantUuid = nsstInfos.get(index).getInvariantUUID()
130 String serviceModelInfo = """{
131 "modelInvariantUuid":"${modelInvariantUuid}",
132 "modelUuid":"${modelUuid}",
135 execution.setVariable("nsstServiceModelInfo", serviceModelInfo)
140 * process the result of NSST Decomposition
143 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)
158 int num = execution.getVariable("maxNsstIndex") as Integer
159 int index = execution.getVariable("currentNsstIndex") as Integer
161 execution.setVariable("currentNsstIndex", index + 1)
164 execution.setVariable("nsstHandleContinue", false)
166 execution.setVariable("nsstHandleContinue", true)
172 * set nsst info to sliceTaskParams by type
175 public void handleNsstByType(DelegateExecution execution) {
176 //todo: set to sliceTaskParams by type
178 SliceTaskParamsAdapter sliceParams =
179 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
181 List<ServiceDecomposition> nsstServiceDecompositions =
182 execution.getVariable("nsstServiceDecompositions") as List<ServiceDecomposition>
184 List<SubnetCapability> subnetCapabilities = new ArrayList<>()
188 for (ServiceDecomposition serviceDecomposition : nsstServiceDecompositions) {
190 SubnetCapability subnetCapability = new SubnetCapability()
192 handleByType(execution, serviceDecomposition, sliceParams, subnetCapability)
194 subnetCapabilities.add(subnetCapability)
197 execution.setVariable("sliceTaskParams", sliceParams)
198 execution.setVariable("subnetCapabilities", subnetCapabilities)
201 private void handleByType(DelegateExecution execution, ServiceDecomposition serviceDecomposition,
202 SliceTaskParamsAdapter sliceParams, SubnetCapability subnetCapability) {
204 String domainType = ""
205 ModelInfo modelInfo = serviceDecomposition.getModelInfo()
206 String vendor = serviceDecomposition.getServiceRole()
207 SubnetType subnetType
209 switch (domainType) {
211 subnetType = SubnetType.TN_BH
212 sliceParams.tnBHSliceTaskInfo.vendor = vendor
213 sliceParams.tnBHSliceTaskInfo.subnetType = subnetType
214 sliceParams.tnBHSliceTaskInfo.networkType = subnetType.networkType
215 sliceParams.tnBHSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
216 sliceParams.tnBHSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
217 sliceParams.tnBHSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
221 subnetType = SubnetType.TN_MH
222 sliceParams.tnMHSliceTaskInfo.vendor = vendor
223 sliceParams.tnMHSliceTaskInfo.subnetType = subnetType
224 sliceParams.tnMHSliceTaskInfo.networkType = subnetType.networkType
225 sliceParams.tnMHSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
226 sliceParams.tnMHSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
227 sliceParams.tnMHSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
231 subnetType = SubnetType.AN_NF
232 sliceParams.anSliceTaskInfo.vendor = vendor
233 sliceParams.anSliceTaskInfo.subnetType = subnetType
234 sliceParams.anSliceTaskInfo.networkType = subnetType.networkType
235 sliceParams.anSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
236 sliceParams.anSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
237 sliceParams.anSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
240 subnetType = SubnetType.CN
241 sliceParams.cnSliceTaskInfo.vendor = vendor
242 sliceParams.cnSliceTaskInfo.subnetType = subnetType
243 sliceParams.cnSliceTaskInfo.networkType = subnetType.networkType
244 sliceParams.cnSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
245 sliceParams.cnSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
246 sliceParams.cnSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
255 if (subnetType == null) {
259 String response = querySubnetCapability(execution, vendor, subnetType)
260 ResponseEntity responseEntity = objectMapper.readValue(response, ResponseEntity.class)
262 Map<String, Object> result = responseEntity.getBody() as Map
263 for (Map.Entry<String, Object> entry : result.entrySet()) {
264 subnetCapability.setDomainType(entry.getKey())
265 subnetCapability.setCapabilityDetails(entry.getValue())
270 * query Subnet Capability of TN AN CN
273 private String querySubnetCapability(DelegateExecution execution, String vendor, SubnetType subnetType) {
275 String strRequest = objectMapper.writeValueAsString(buildQuerySubnetCapRequest(vendor, subnetType))
277 String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_SUB_NET_CAPABILITY, strRequest)
282 * build request body for querying Subnet Capability
288 private static String buildQuerySubnetCapRequest(String vendor, SubnetType subnetType) {
289 NssmfAdapterNBIRequest request = new NssmfAdapterNBIRequest()
291 List<String> subnetTypes = new ArrayList<>()
292 subnetTypes.add(subnetType.subnetType)
293 Map<String, Object> paramMap = new HashMap()
294 paramMap.put("subnetTypes", subnetTypes)
296 request.setSubnetCapabilityQuery(objectMapper.writeValueAsString(paramMap))
298 EsrInfo esrInfo = new EsrInfo()
299 esrInfo.setVendor(vendor)
300 esrInfo.setNetworkType(subnetType.networkType)
302 request.setEsrInfo(esrInfo)
304 String strRequest = objectMapper.writeValueAsString(request)
311 * prepare select nsi request
314 public void preNSIRequest(DelegateExecution execution) {
316 String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution)
317 logger.debug( "get NSI option OOF Url: " + urlString)
320 String requestId = execution.getVariable("msoRequestId")
321 String messageType = "NSISelectionResponse"
323 execution.setVariable("nsiSelectionUrl", "/api/oof/selection/nsi/v1")
324 execution.setVariable("nsiSelection_messageType", messageType)
325 execution.setVariable("nsiSelection_correlator", requestId)
326 String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution)
327 execution.setVariable("nsiSelection_timeout", timeout)
329 SliceTaskParamsAdapter sliceParams =
330 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
332 Map<String, Object> profileInfo = sliceParams.getServiceProfile()
333 TemplateInfo nstInfo = sliceParams.getNSTInfo()
335 List<TemplateInfo> nsstInfos = execution.getVariable("nsstInfos") as List<TemplateInfo>
337 List<SubnetCapability> subnetCapabilities =
338 execution.getVariable("subnetCapabilities") as List<SubnetCapability>
340 String oofRequest = oofUtils.buildSelectNSIRequest(requestId, nstInfo, nsstInfos,
341 messageType, profileInfo, subnetCapabilities, timeout as Integer)
343 execution.setVariable("nsiSelection_oofRequest", oofRequest)
344 logger.debug("Sending request to OOF: " + oofRequest)
349 * process select nsi response
352 public void processNSIResp(DelegateExecution execution) {
354 SliceTaskParamsAdapter sliceTaskParams =
355 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
357 String OOFResponse = execution.getVariable("nsiSelection_oofResponse")
358 logger.debug("NSI OOFResponse is: " + OOFResponse)
359 execution.setVariable("OOFResponse", OOFResponse)
360 //This needs to be changed to derive a value when we add policy to decide the solution options.
362 Map<String, Object> resMap = objectMapper.readValue(OOFResponse, Map.class)
363 List<Map<String, Object>> nsiSolutions = (List<Map<String, Object>>) resMap.get("solutions")
364 Map<String, Object> solution = nsiSolutions.get(0)
366 String resourceSharingLevel = execution.getVariable("resourceSharingLevel")
367 Boolean isSharable = resourceSharingLevel == "shared"
369 if (solution != null) {
370 if (isSharable && solution.get("existingNSI")) {
372 processSharedNSI(solution, sliceTaskParams)
374 else if(solution.containsKey("newNSISolution")) {
375 processNewNSI(solution, sliceTaskParams)
378 execution.setVariable("sliceTaskParams", sliceTaskParams)
379 //logger.debug("sliceTaskParams: " + sliceTaskParams.convertToJson())
380 logger.debug("*** Completed options Call to OOF ***")
383 private void processSharedNSI(Map<String, Object> solution, SliceTaskParamsAdapter sliceParams) {
384 Map<String, Object> sharedNSISolution = solution.get("sharedNSISolution") as Map
386 String nsiId = sharedNSISolution.get("NSIId")
387 String nsiName = sharedNSISolution.get("NSIName")
388 sliceParams.setSuggestNsiId(nsiId)
389 sliceParams.setSuggestNsiName(nsiName)
392 private void processNewNSI(Map<String, Object> solution, SliceTaskParamsAdapter sliceParams) {
393 Map<String, Object> newNSISolution = solution.get("newNSISolution") as Map
394 List<Map> sliceProfiles = newNSISolution.get("sliceProfiles") as List<Map>
395 for (Map sliceProfile : sliceProfiles) {
396 String domainType = sliceProfile.get("domainType")
397 switch (domainType.toLowerCase()) {
399 sliceParams.tnBHSliceTaskInfo.sliceProfile = sliceProfile as TnSliceProfile
402 sliceParams.anSliceTaskInfo.sliceProfile = sliceProfile as AnSliceProfile
405 sliceParams.cnSliceTaskInfo.sliceProfile = sliceProfile as CnSliceProfile
417 * get NSSI Selection Capability for AN
420 public void getNSSISelectionCap4AN(DelegateExecution execution) {
422 def vendor = execution.getVariable("vendor") as String
424 String strRequest = buildNSSISelectionReq(vendor, NetworkType.ACCESS)
426 String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_NSSI_SELECTION_CAPABILITY, strRequest)
428 Map<String, Object> resMap = objectMapper.readValue(response, Map.class)
430 String selection = resMap.get("selection")
433 if ("NSMF".equalsIgnoreCase(selection)) {
434 execution.setVariable("NEED_AN_NSSI_SELECTION", true)
439 * get NSSI Selection Capability for TN
442 public void getNSSISelectionCap4TN(DelegateExecution execution) {
444 def vendor = execution.getVariable("vendor") as String
446 String strRequest = buildNSSISelectionReq(vendor, NetworkType.TRANSPORT)
448 String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_NSSI_SELECTION_CAPABILITY, strRequest)
450 Map<String, Object> resMap = objectMapper.readValue(response, Map.class)
452 String selection = resMap.get("selection")
454 if ("NSMF".equalsIgnoreCase(selection)) {
455 execution.setVariable("NEED_TN_NSSI_SELECTION", true)
460 * get NSSI Selection Capability for CN
463 public void getNSSISelectionCap4CN(DelegateExecution execution) {
465 def vendor = execution.getVariable("vendor") as String
467 String strRequest = buildNSSISelectionReq(vendor, NetworkType.CORE)
469 String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_NSSI_SELECTION_CAPABILITY, strRequest)
471 Map<String, Object> resMap = objectMapper.readValue(response, Map.class)
473 String selection = resMap.get("selection")
475 if ("NSMF".equalsIgnoreCase(selection)) {
476 execution.setVariable("NEED_CN_NSSI_SELECTION", true)
481 * build NSSI Selection Capability Request body to nssmf adapter
486 private static String buildNSSISelectionReq(String vendor, NetworkType networkType) {
487 NssmfAdapterNBIRequest request = new NssmfAdapterNBIRequest()
488 EsrInfo esrInfo = new EsrInfo()
489 esrInfo.setVendor(vendor)
490 esrInfo.setNetworkType(networkType)
491 request.setEsrInfo(esrInfo)
493 return objectMapper.writeValueAsString(request)
497 * if exist nssi need to select?
500 public void handleNssiSelect(DelegateExecution execution) {
502 SliceTaskParamsAdapter sliceTaskParams =
503 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
510 * prepare select nssi request
513 public void preNSSIRequest(DelegateExecution execution) {
515 String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution)
516 logger.debug( "get NSI option OOF Url: " + urlString)
518 boolean isNSISuggested = true
519 execution.setVariable("isNSISuggested", isNSISuggested)
520 String requestId = execution.getVariable("msoRequestId")
521 String messageType = "NSISelectionResponse"
523 Map<String, Object> profileInfo = execution.getVariable("serviceProfile") as Map
524 Map<String, Object> nstSolution = execution.getVariable("nstSolution") as Map
525 logger.debug("Get NST selection from OOF: " + nstSolution.toString())
526 String nstInfo = """{
527 "modelInvariantId":"${nstSolution.invariantUUID}",
528 "modelVersionId":"${nstSolution.UUID}",
529 "modelName":"${nstSolution.NSTName}"
532 execution.setVariable("nsiSelectionUrl", "/api/oof/selection/nsi/v1")
533 execution.setVariable("nsiSelection_messageType", messageType)
534 execution.setVariable("nsiSelection_correlator", requestId)
535 String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution)
536 execution.setVariable("nsiSelection_timeout", timeout)
539 String oofRequest = oofUtils.buildSelectNSIRequest(requestId, nstInfo, messageType, profileInfo)
541 execution.setVariable("nsiSelection_oofRequest", oofRequest)
542 logger.debug("Sending request to OOF: " + oofRequest)
546 * process select nssi response
550 public void processNSSIResp(DelegateExecution execution) {
552 SliceTaskParams sliceTaskParams = execution.getVariable("sliceTaskParams") as SliceTaskParams
553 String OOFResponse = execution.getVariable("nsiSelection_oofResponse")
554 logger.debug("NSI OOFResponse is: " + OOFResponse)
555 execution.setVariable("OOFResponse", OOFResponse)
556 //This needs to be changed to derive a value when we add policy to decide the solution options.
558 Map<String, Object> resMap = objectMapper.readValue(OOFResponse, Map.class)
559 List<Map<String, Object>> nsiSolutions = (List<Map<String, Object>>) resMap.get("solutions")
560 Map<String, Object> solutions = nsiSolutions.get(0)
562 String resourceSharingLevel = execution.getVariable("resourceSharingLevel")
563 Boolean isSharable = resourceSharingLevel == "shared"
565 if (solutions != null) {
566 if (isSharable && solutions.get("existingNSI")) {
568 //processSharedNSISolutions(solutions, execution)
570 else if(solutions.containsKey("newNSISolution")) {
571 //processNewNSISolutions(solutions, execution)
574 execution.setVariable("sliceTaskParams", sliceTaskParams)
575 logger.debug("sliceTaskParams: "+sliceTaskParams.convertToJson())
576 logger.debug("*** Completed options Call to OOF ***")
578 logger.debug("start parseServiceProfile")
579 //parseServiceProfile(execution)
580 logger.debug("end parseServiceProfile")