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
45 import org.onap.so.client.HttpClient
46 import org.onap.so.client.HttpClientFactory
47 import org.onap.aaiclient.client.aai.AAIObjectType
48 import org.onap.aaiclient.client.aai.AAIResourcesClient
49 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
50 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
51 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
52 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
53 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
54 import org.slf4j.Logger
55 import org.slf4j.LoggerFactory
56 import org.springframework.http.ResponseEntity
58 class DoCreateSliceServiceOption extends AbstractServiceTaskProcessor{
60 private static final Logger logger = LoggerFactory.getLogger(DoCreateSliceServiceOption.class)
62 ExceptionUtil exceptionUtil = new ExceptionUtil()
64 JsonUtils jsonUtil = new JsonUtils()
66 OofUtils oofUtils = new OofUtils()
68 private static final ObjectMapper objectMapper = new ObjectMapper()
70 private NssmfAdapterUtils nssmfAdapterUtils = new NssmfAdapterUtils(httpClientFactory, jsonUtil)
72 private static final String QUERY_SUB_NET_CAPABILITY = "/api/rest/provMns/v1/NSS/subnetCapabilityQuery"
74 private static final String QUERY_NSSI_SELECTION_CAPABILITY = "/api/rest/provMns/v1/NSS/NSSISelectionCapability"
76 void preProcessRequest (DelegateExecution execution) {
80 * prepare the params for decompose nst
83 public void prepareDecomposeNST(DelegateExecution execution) {
85 SliceTaskParamsAdapter sliceTaskParams =
86 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
88 String modelUuid = sliceTaskParams.getNSTInfo().getUUID()
89 String modelInvariantUuid = sliceTaskParams.getNSTInfo().getInvariantUUID()
91 String serviceModelInfo = """{
92 "modelInvariantUuid":"${modelInvariantUuid}",
93 "modelUuid":"${modelUuid}",
96 execution.setVariable("nstServiceModelInfo", serviceModelInfo)
100 * process the result of NST Decomposition
103 public void processDecompositionNST(DelegateExecution execution) {
105 List<TemplateInfo> nsstInfos = new ArrayList<>()
106 ServiceDecomposition nstServiceDecomposition =
107 execution.getVariable("nstServiceDecomposition") as ServiceDecomposition
109 List<AllottedResource> allottedResources = nstServiceDecomposition.getAllottedResources()
110 for (AllottedResource allottedResource : allottedResources) {
111 TemplateInfo nsstInfo = new TemplateInfo()
112 nsstInfo.setUUID(allottedResource.getProvidingServiceModelUuid())
113 nsstInfo.setInvariantUUID(allottedResource.getProvidingServiceModelInvariantUuid())
114 nsstInfo.setName(allottedResource.getProvidingServiceModelName())
115 nsstInfos.add(nsstInfo)
117 execution.setVariable("nsstInfos", nsstInfos)
119 execution.setVariable("maxNsstIndex", allottedResources.size() - 1)
120 execution.setVariable("currentNsstIndex", 0)
122 List<ServiceDecomposition> nsstServiceDecompositions = new ArrayList<>()
123 execution.setVariable("nsstServiceDecompositions", nsstServiceDecompositions)
127 * prepare the params for decompose nsst
130 public void prepareDecomposeNSST(DelegateExecution execution) {
132 List<TemplateInfo> nsstInfos = execution.getVariable("nsstInfos") as List<TemplateInfo>
133 int index = execution.getVariable("currentNsstIndex") as Integer
135 String modelUuid = nsstInfos.get(index).getUUID()
136 String modelInvariantUuid = nsstInfos.get(index).getInvariantUUID()
138 String serviceModelInfo = """{
139 "modelInvariantUuid":"${modelInvariantUuid}",
140 "modelUuid":"${modelUuid}",
143 execution.setVariable("nsstServiceModelInfo", serviceModelInfo)
148 * process the result of NSST Decomposition
151 public void processDecompositionNSST(DelegateExecution execution) {
153 List<ServiceDecomposition> nsstServiceDecompositions =
154 execution.getVariable("nsstServiceDecompositions") as List<ServiceDecomposition>
156 ServiceDecomposition nsstServiceDecomposition =
157 execution.getVariable("nsstServiceDecomposition") as ServiceDecomposition
159 nsstServiceDecompositions.add(nsstServiceDecomposition)
161 execution.setVariable("nsstServiceDecompositions", nsstServiceDecompositions)
166 int num = execution.getVariable("maxNsstIndex") as Integer
167 int index = execution.getVariable("currentNsstIndex") as Integer
169 execution.setVariable("currentNsstIndex", index + 1)
172 execution.setVariable("nsstHandleContinue", false)
174 execution.setVariable("nsstHandleContinue", true)
180 * set nsst info to sliceTaskParams by type
183 public void handleNsstByType(DelegateExecution execution) {
184 //todo: set to sliceTaskParams by type
186 SliceTaskParamsAdapter sliceParams =
187 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
189 List<ServiceDecomposition> nsstServiceDecompositions =
190 execution.getVariable("nsstServiceDecompositions") as List<ServiceDecomposition>
192 List<SubnetCapability> subnetCapabilities = new ArrayList<>()
196 for (ServiceDecomposition serviceDecomposition : nsstServiceDecompositions) {
198 SubnetCapability subnetCapability = new SubnetCapability()
200 handleByType(execution, serviceDecomposition, sliceParams, subnetCapability)
202 subnetCapabilities.add(subnetCapability)
205 execution.setVariable("sliceTaskParams", sliceParams)
206 execution.setVariable("subnetCapabilities", subnetCapabilities)
209 private void handleByType(DelegateExecution execution, ServiceDecomposition serviceDecomposition,
210 SliceTaskParamsAdapter sliceParams, SubnetCapability subnetCapability) {
212 String domainType = ""
213 ModelInfo modelInfo = serviceDecomposition.getModelInfo()
214 String vendor = serviceDecomposition.getServiceRole()
215 SubnetType subnetType
217 switch (domainType) {
219 subnetType = SubnetType.TN_BH
220 sliceParams.tnBHSliceTaskInfo.vendor = vendor
221 sliceParams.tnBHSliceTaskInfo.subnetType = subnetType
222 sliceParams.tnBHSliceTaskInfo.networkType = subnetType.networkType
223 sliceParams.tnBHSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
224 sliceParams.tnBHSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
225 sliceParams.tnBHSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
229 subnetType = SubnetType.TN_MH
230 sliceParams.tnMHSliceTaskInfo.vendor = vendor
231 sliceParams.tnMHSliceTaskInfo.subnetType = subnetType
232 sliceParams.tnMHSliceTaskInfo.networkType = subnetType.networkType
233 sliceParams.tnMHSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
234 sliceParams.tnMHSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
235 sliceParams.tnMHSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
239 subnetType = SubnetType.AN_NF
240 sliceParams.anSliceTaskInfo.vendor = vendor
241 sliceParams.anSliceTaskInfo.subnetType = subnetType
242 sliceParams.anSliceTaskInfo.networkType = subnetType.networkType
243 sliceParams.anSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
244 sliceParams.anSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
245 sliceParams.anSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
248 subnetType = SubnetType.CN
249 sliceParams.cnSliceTaskInfo.vendor = vendor
250 sliceParams.cnSliceTaskInfo.subnetType = subnetType
251 sliceParams.cnSliceTaskInfo.networkType = subnetType.networkType
252 sliceParams.cnSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid()
253 sliceParams.cnSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid()
254 sliceParams.cnSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName()
263 if (subnetType == null) {
267 String response = querySubnetCapability(execution, vendor, subnetType)
268 ResponseEntity responseEntity = objectMapper.readValue(response, ResponseEntity.class)
270 Map<String, Object> result = responseEntity.getBody() as Map
271 for (Map.Entry<String, Object> entry : result.entrySet()) {
272 subnetCapability.setDomainType(entry.getKey())
273 subnetCapability.setCapabilityDetails(entry.getValue())
278 * query Subnet Capability of TN AN CN
281 private String querySubnetCapability(DelegateExecution execution, String vendor, SubnetType subnetType) {
283 String strRequest = objectMapper.writeValueAsString(buildQuerySubnetCapRequest(vendor, subnetType))
285 String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_SUB_NET_CAPABILITY, strRequest)
290 * build request body for querying Subnet Capability
296 private static String buildQuerySubnetCapRequest(String vendor, SubnetType subnetType) {
297 NssmfAdapterNBIRequest request = new NssmfAdapterNBIRequest()
299 List<String> subnetTypes = new ArrayList<>()
300 subnetTypes.add(subnetType.subnetType)
301 Map<String, Object> paramMap = new HashMap()
302 paramMap.put("subnetTypes", subnetTypes)
304 request.setSubnetCapabilityQuery(objectMapper.writeValueAsString(paramMap))
306 EsrInfo esrInfo = new EsrInfo()
307 esrInfo.setVendor(vendor)
308 esrInfo.setNetworkType(subnetType.networkType)
310 request.setEsrInfo(esrInfo)
312 String strRequest = objectMapper.writeValueAsString(request)
319 * prepare select nsi request
322 public void preNSIRequest(DelegateExecution execution) {
324 String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution)
325 logger.debug( "get NSI option OOF Url: " + urlString)
328 String requestId = execution.getVariable("msoRequestId")
329 String messageType = "NSISelectionResponse"
331 execution.setVariable("nsiSelectionUrl", "/api/oof/selection/nsi/v1")
332 execution.setVariable("nsiSelection_messageType", messageType)
333 execution.setVariable("nsiSelection_correlator", requestId)
334 String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution)
335 execution.setVariable("nsiSelection_timeout", timeout)
337 SliceTaskParamsAdapter sliceParams =
338 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
340 Map<String, Object> profileInfo = sliceParams.getServiceProfile()
341 TemplateInfo nstInfo = sliceParams.getNSTInfo()
343 List<TemplateInfo> nsstInfos = execution.getVariable("nsstInfos") as List<TemplateInfo>
345 List<SubnetCapability> subnetCapabilities =
346 execution.getVariable("subnetCapabilities") as List<SubnetCapability>
348 String oofRequest = oofUtils.buildSelectNSIRequest(requestId, nstInfo, nsstInfos,
349 messageType, profileInfo, subnetCapabilities, timeout as Integer)
351 execution.setVariable("nsiSelection_oofRequest", oofRequest)
352 logger.debug("Sending request to OOF: " + oofRequest)
357 * process select nsi response
360 public void processNSIResp(DelegateExecution execution) {
362 SliceTaskParamsAdapter sliceTaskParams =
363 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
365 String OOFResponse = execution.getVariable("nsiSelection_oofResponse")
366 logger.debug("NSI OOFResponse is: " + OOFResponse)
367 execution.setVariable("OOFResponse", OOFResponse)
368 //This needs to be changed to derive a value when we add policy to decide the solution options.
370 Map<String, Object> resMap = objectMapper.readValue(OOFResponse, Map.class)
371 List<Map<String, Object>> nsiSolutions = (List<Map<String, Object>>) resMap.get("solutions")
372 Map<String, Object> solution = nsiSolutions.get(0)
374 String resourceSharingLevel = execution.getVariable("resourceSharingLevel")
375 Boolean isSharable = resourceSharingLevel == "shared"
377 if (solution != null) {
378 if (isSharable && solution.get("existingNSI")) {
380 processSharedNSI(solution, sliceTaskParams)
382 else if(solution.containsKey("newNSISolution")) {
383 processNewNSI(solution, sliceTaskParams)
386 execution.setVariable("sliceTaskParams", sliceTaskParams)
387 //logger.debug("sliceTaskParams: " + sliceTaskParams.convertToJson())
388 logger.debug("*** Completed options Call to OOF ***")
391 private void processSharedNSI(Map<String, Object> solution, SliceTaskParamsAdapter sliceParams) {
392 Map<String, Object> sharedNSISolution = solution.get("sharedNSISolution") as Map
394 String nsiId = sharedNSISolution.get("NSIId")
395 String nsiName = sharedNSISolution.get("NSIName")
396 sliceParams.setSuggestNsiId(nsiId)
397 sliceParams.setSuggestNsiName(nsiName)
400 private void processNewNSI(Map<String, Object> solution, SliceTaskParamsAdapter sliceParams) {
401 Map<String, Object> newNSISolution = solution.get("newNSISolution") as Map
402 List<Map> sliceProfiles = newNSISolution.get("sliceProfiles") as List<Map>
403 for (Map sliceProfile : sliceProfiles) {
404 String domainType = sliceProfile.get("domainType")
405 switch (domainType.toLowerCase()) {
407 sliceParams.tnBHSliceTaskInfo.sliceProfile = sliceProfile as TnSliceProfile
410 sliceParams.anSliceTaskInfo.sliceProfile = sliceProfile as AnSliceProfile
413 sliceParams.cnSliceTaskInfo.sliceProfile = sliceProfile as CnSliceProfile
425 * get NSSI Selection Capability for AN
428 public void getNSSISelectionCap4AN(DelegateExecution execution) {
430 def vendor = execution.getVariable("vendor") as String
432 String strRequest = buildNSSISelectionReq(vendor, NetworkType.ACCESS)
434 String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_NSSI_SELECTION_CAPABILITY, strRequest)
436 Map<String, Object> resMap = objectMapper.readValue(response, Map.class)
438 String selection = resMap.get("selection")
441 if ("NSMF".equalsIgnoreCase(selection)) {
442 execution.setVariable("NEED_AN_NSSI_SELECTION", true)
447 * get NSSI Selection Capability for TN
450 public void getNSSISelectionCap4TN(DelegateExecution execution) {
452 def vendor = execution.getVariable("vendor") as String
454 String strRequest = buildNSSISelectionReq(vendor, NetworkType.TRANSPORT)
456 String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_NSSI_SELECTION_CAPABILITY, strRequest)
458 Map<String, Object> resMap = objectMapper.readValue(response, Map.class)
460 String selection = resMap.get("selection")
462 if ("NSMF".equalsIgnoreCase(selection)) {
463 execution.setVariable("NEED_TN_NSSI_SELECTION", true)
468 * get NSSI Selection Capability for CN
471 public void getNSSISelectionCap4CN(DelegateExecution execution) {
473 def vendor = execution.getVariable("vendor") as String
475 String strRequest = buildNSSISelectionReq(vendor, NetworkType.CORE)
477 String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_NSSI_SELECTION_CAPABILITY, strRequest)
479 Map<String, Object> resMap = objectMapper.readValue(response, Map.class)
481 String selection = resMap.get("selection")
483 if ("NSMF".equalsIgnoreCase(selection)) {
484 execution.setVariable("NEED_CN_NSSI_SELECTION", true)
489 * build NSSI Selection Capability Request body to nssmf adapter
494 private static String buildNSSISelectionReq(String vendor, NetworkType networkType) {
495 NssmfAdapterNBIRequest request = new NssmfAdapterNBIRequest()
496 EsrInfo esrInfo = new EsrInfo()
497 esrInfo.setVendor(vendor)
498 esrInfo.setNetworkType(networkType)
499 request.setEsrInfo(esrInfo)
501 return objectMapper.writeValueAsString(request)
505 * if exist nssi need to select?
508 public void handleNssiSelect(DelegateExecution execution) {
510 SliceTaskParamsAdapter sliceTaskParams =
511 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
518 * prepare select nssi request
521 public void preNSSIRequest(DelegateExecution execution) {
523 String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution)
524 logger.debug( "get NSI option OOF Url: " + urlString)
526 boolean isNSISuggested = true
527 execution.setVariable("isNSISuggested", isNSISuggested)
528 String requestId = execution.getVariable("msoRequestId")
529 String messageType = "NSISelectionResponse"
531 Map<String, Object> profileInfo = execution.getVariable("serviceProfile") as Map
532 Map<String, Object> nstSolution = execution.getVariable("nstSolution") as Map
533 logger.debug("Get NST selection from OOF: " + nstSolution.toString())
534 String nstInfo = """{
535 "modelInvariantId":"${nstSolution.invariantUUID}",
536 "modelVersionId":"${nstSolution.UUID}",
537 "modelName":"${nstSolution.NSTName}"
540 execution.setVariable("nsiSelectionUrl", "/api/oof/selection/nsi/v1")
541 execution.setVariable("nsiSelection_messageType", messageType)
542 execution.setVariable("nsiSelection_correlator", requestId)
543 String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution)
544 execution.setVariable("nsiSelection_timeout", timeout)
547 String oofRequest = oofUtils.buildSelectNSIRequest(requestId, nstInfo, messageType, profileInfo)
549 execution.setVariable("nsiSelection_oofRequest", oofRequest)
550 logger.debug("Sending request to OOF: " + oofRequest)
554 * process select nssi response
558 public void processNSSIResp(DelegateExecution execution) {
560 SliceTaskParams sliceTaskParams = execution.getVariable("sliceTaskParams") as SliceTaskParams
561 String OOFResponse = execution.getVariable("nsiSelection_oofResponse")
562 logger.debug("NSI OOFResponse is: " + OOFResponse)
563 execution.setVariable("OOFResponse", OOFResponse)
564 //This needs to be changed to derive a value when we add policy to decide the solution options.
566 Map<String, Object> resMap = objectMapper.readValue(OOFResponse, Map.class)
567 List<Map<String, Object>> nsiSolutions = (List<Map<String, Object>>) resMap.get("solutions")
568 Map<String, Object> solutions = nsiSolutions.get(0)
570 String resourceSharingLevel = execution.getVariable("resourceSharingLevel")
571 Boolean isSharable = resourceSharingLevel == "shared"
573 if (solutions != null) {
574 if (isSharable && solutions.get("existingNSI")) {
576 //processSharedNSISolutions(solutions, execution)
578 else if(solutions.containsKey("newNSISolution")) {
579 //processNewNSISolutions(solutions, execution)
582 execution.setVariable("sliceTaskParams", sliceTaskParams)
583 logger.debug("sliceTaskParams: "+sliceTaskParams.convertToJson())
584 logger.debug("*** Completed options Call to OOF ***")
586 logger.debug("start parseServiceProfile")
587 //parseServiceProfile(execution)
588 logger.debug("end parseServiceProfile")