2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
6 * ================================================================================
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 org.camunda.bpm.engine.delegate.BpmnError
24 import org.camunda.bpm.engine.delegate.DelegateExecution
25 import org.onap.aai.domain.yang.NetworkPolicy
26 import org.onap.aai.domain.yang.SliceProfile
27 import org.onap.aaiclient.client.aai.AAIResourcesClient
28 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
29 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
30 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
31 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
32 import org.onap.so.bpmn.common.scripts.ExceptionUtil
33 import org.onap.so.bpmn.core.json.JsonUtils
34 import org.slf4j.Logger
35 import org.slf4j.LoggerFactory
37 class DoCreateTnNssiInstance extends AbstractServiceTaskProcessor {
39 private static final Logger logger = LoggerFactory.getLogger(DoCreateTnNssiInstance.class);
40 final String AAI_VERSION = "v21"
41 JsonUtils jsonUtil = new JsonUtils()
42 TnNssmfUtils tnNssmfUtils = new TnNssmfUtils()
43 ExceptionUtil exceptionUtil = new ExceptionUtil()
44 String Prefix = "DCTN_"
46 void preProcessRequest(DelegateExecution execution) {
48 logger.trace("Enter preProcessRequest()")
50 execution.setVariable("prefix", Prefix)
52 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
53 String modelUuid = execution.getVariable("modelUuid")
54 //here modelVersion is not set, we use modelUuid to decompose the service.
55 def isDebugLogEnabled = true
56 execution.setVariable("isDebugLogEnabled", isDebugLogEnabled)
57 String serviceModelInfo = """{
58 "modelInvariantUuid":"${modelInvariantUuid}",
59 "modelUuid":"${modelUuid}",
62 execution.setVariable("serviceModelInfo", serviceModelInfo)
64 logger.trace("Exit preProcessRequest")
68 void createSliceProfile(DelegateExecution execution) {
70 String ssInstanceId = execution.getVariable("sliceServiceInstanceId")
71 String sliceProfileStr = execution.getVariable("sliceProfile")
72 String sliceProfileId = UUID.randomUUID().toString()
73 SliceProfile sliceProfile = new SliceProfile();
74 sliceProfile.setProfileId(sliceProfileId)
75 sliceProfile.setLatency(Integer.parseInt(jsonUtil.getJsonValue(sliceProfileStr, "latency")))
76 sliceProfile.setResourceSharingLevel(jsonUtil.getJsonValue(sliceProfileStr, "resourceSharingLevel"))
77 //sliceProfile.setSNssai(tnNssmfUtils.getFirstSnssaiFromSliceProfile(sliceProfileStr))
79 sliceProfile.setMaxBandwidth(Integer.parseInt(jsonUtil.getJsonValue(sliceProfileStr, "maxBandwidth")))
81 //sliceProfile.setReliability(new Object())
83 AAIResourcesClient client = getAAIClient()
85 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
86 .customer(execution.getVariable("globalSubscriberId"))
87 .serviceSubscription(execution.getVariable("subscriptionServiceType"))
88 .serviceInstance(ssInstanceId)
89 .sliceProfile(sliceProfileId))
90 client.create(uri, sliceProfile)
92 } catch (BpmnError e) {
94 } catch (Exception ex) {
95 String msg = "Exception in DoCreateSliceServiceInstance.instantiateSliceService. " + ex.getMessage()
97 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
102 void createServiceInstance(DelegateExecution execution) {
104 String serviceRole = "TN"
105 String serviceType = execution.getVariable("subscriptionServiceType")
106 String ssInstanceId = execution.getVariable("sliceServiceInstanceId")
107 String sliceProfileStr = execution.getVariable("sliceProfile")
109 org.onap.aai.domain.yang.ServiceInstance ss = new org.onap.aai.domain.yang.ServiceInstance()
110 ss.setServiceInstanceId(ssInstanceId)
111 String sliceInstanceName = execution.getVariable("sliceServiceInstanceName")
112 ss.setServiceInstanceName(sliceInstanceName)
113 ss.setServiceType(serviceType)
114 String serviceStatus = "activated"
115 ss.setOrchestrationStatus(serviceStatus)
116 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
117 String modelUuid = execution.getVariable("modelUuid")
118 //TODO: need valid model ID from the caller, as AAI does not accept invalid IDs
119 //ss.setModelInvariantId(modelInvariantUuid)
120 //ss.setModelVersionId(modelUuid)
121 String serviceInstanceLocationid = tnNssmfUtils.getFirstPlmnIdFromSliceProfile(sliceProfileStr)
122 ss.setServiceInstanceLocationId(serviceInstanceLocationid)
123 String snssai = tnNssmfUtils.getFirstSnssaiFromSliceProfile(sliceProfileStr)
124 //ss.setEnvironmentContext(snssai)
125 ss.setEnvironmentContext("tn")
126 ss.setServiceRole(serviceRole)
127 AAIResourcesClient client = getAAIClient()
129 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
130 .customer(execution.getVariable("globalSubscriberId"))
131 .serviceSubscription(execution.getVariable("subscriptionServiceType"))
132 .serviceInstance(ssInstanceId))
133 client.create(uri, ss)
134 } catch (BpmnError e) {
136 } catch (Exception ex) {
137 String msg = "Exception in DoCreateTnNssiInstance.createServiceInstance: " + ex.getMessage()
139 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
144 void createAllottedResource(DelegateExecution execution) {
145 String ssInstanceId = execution.getVariable('sliceServiceInstanceId')
148 List<String> networkStrList = jsonUtil.StringArrayToList(execution.getVariable("transportSliceNetworks"))
150 for (String networkStr : networkStrList) {
151 String allottedResourceId = UUID.randomUUID().toString()
152 AAIResourceUri allottedResourceUri =
153 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
154 .customer(execution.getVariable("globalSubscriberId"))
155 .serviceSubscription(execution.getVariable("subscriptionServiceType"))
156 .serviceInstance(execution.getVariable("sliceServiceInstanceId"))
157 .allottedResource(allottedResourceId))
158 execution.setVariable("allottedResourceUri", allottedResourceUri)
159 String modelInvariantId = execution.getVariable("modelInvariantUuid")
160 String modelVersionId = execution.getVariable("modelUuid")
162 org.onap.aai.domain.yang.AllottedResource resource = new org.onap.aai.domain.yang.AllottedResource()
163 resource.setId(allottedResourceId)
164 resource.setType("TsciNetwork")
165 resource.setAllottedResourceName("network_" + execution.getVariable("sliceServiceInstanceName"))
166 getAAIClient().create(allottedResourceUri, resource)
168 createNetworkPolicyForAllocatedResource(execution, ssInstanceId, allottedResourceId)
170 String linkArrayStr = jsonUtil.getJsonValue(networkStr, "connectionLinks")
171 createLogicalLinksForAllocatedResource(execution, linkArrayStr, ssInstanceId, allottedResourceId)
173 } catch (BpmnError e) {
175 } catch (Exception ex) {
176 String msg = "Exception in DoCreateTnNssiInstance.createAllottedResource: " + ex.getMessage()
178 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
182 void createNetworkPolicy(DelegateExecution execution, String ssInstanceId, String networkPolicyId) {
185 String sliceProfileStr = execution.getVariable("sliceProfile")
186 if (sliceProfileStr == null || sliceProfileStr.isEmpty()) {
187 String msg = "ERROR: createNetworkPolicy: sliceProfile is null"
189 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
192 NetworkPolicy networkPolicy = new NetworkPolicy();
193 networkPolicy.setNetworkPolicyId(networkPolicyId)
194 networkPolicy.setName("TSCi policy")
195 networkPolicy.setType("SLA")
196 networkPolicy.setNetworkPolicyFqdn(ssInstanceId)
198 String latencyStr = jsonUtil.getJsonValue(sliceProfileStr, "latency")
199 if (latencyStr != null && !latencyStr.isEmpty()) {
200 networkPolicy.setLatency(Integer.parseInt(latencyStr))
203 String bwStr = jsonUtil.getJsonValue(sliceProfileStr, "maxBandwidth")
204 if (bwStr != null && !bwStr.isEmpty()) {
205 networkPolicy.setMaxBandwidth(Integer.parseInt(bwStr))
207 log.debug("ERROR: createNetworkPolicy: maxBandwidth is null")
210 //networkPolicy.setReliability(new Object())
212 AAIResourceUri networkPolicyUri =
213 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().networkPolicy(networkPolicyId))
214 getAAIClient().create(networkPolicyUri, networkPolicy)
216 } catch (BpmnError e) {
218 } catch (Exception ex) {
219 String msg = "Exception in DoCreateSliceServiceInstance.instantiateSliceService. " + ex.getMessage()
221 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
225 void createNetworkPolicyForAllocatedResource(DelegateExecution execution,
227 String allottedResourceId) {
229 AAIResourceUri allottedResourceUri =
230 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
231 .customer(execution.getVariable("globalSubscriberId"))
232 .serviceSubscription(execution.getVariable("subscriptionServiceType"))
233 .serviceInstance(ssInstanceId)
234 .allottedResource(allottedResourceId))
236 if (!getAAIClient().exists(allottedResourceUri)) {
237 logger.info("ERROR: createLogicalLinksForAllocatedResource: allottedResource not exist: uri={}",
242 String networkPolicyId = UUID.randomUUID().toString()
243 createNetworkPolicy(execution, ssInstanceId, networkPolicyId)
245 tnNssmfUtils.attachNetworkPolicyToAllottedResource(execution, AAI_VERSION, allottedResourceUri, networkPolicyId);
247 } catch (BpmnError e) {
249 } catch (Exception ex) {
250 String msg = "Exception in DoCreateSliceServiceInstance.instantiateSliceService. " + ex.getMessage()
252 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
256 void createLogicalLinksForAllocatedResource(DelegateExecution execution,
257 String linkArrayStr, String ssInstanceId,
258 String allottedResourceId) {
260 AAIResourceUri allottedResourceUri =
261 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
262 .customer(execution.getVariable("globalSubscriberId"))
263 .serviceSubscription(execution.getVariable("subscriptionServiceType"))
264 .serviceInstance(ssInstanceId)
265 .allottedResource(allottedResourceId))
267 if (!getAAIClient().exists(allottedResourceUri)) {
268 logger.info("ERROR: createLogicalLinksForAllocatedResource: allottedResource not exist: uri={}",
273 List<String> linkStrList = jsonUtil.StringArrayToList(linkArrayStr)
275 for (String linkStr : linkStrList) {
276 String logicalLinkId = UUID.randomUUID().toString()
277 String epA = jsonUtil.getJsonValue(linkStr, "transportEndpointA")
278 String epB = jsonUtil.getJsonValue(linkStr, "transportEndpointB")
279 String modelInvariantId = execution.getVariable("modelInvariantUuid")
280 String modelVersionId = execution.getVariable("modelUuid")
282 org.onap.aai.domain.yang.LogicalLink resource = new org.onap.aai.domain.yang.LogicalLink()
283 resource.setLinkId(logicalLinkId)
284 resource.setLinkName(epA)
285 resource.setLinkName2(epB)
286 resource.setLinkType("TsciConnectionLink")
287 resource.setInMaint(false)
290 AAIResourceUri logicalLinkUri =
291 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().logicalLink(epA))
292 getAAIClient().create(logicalLinkUri, resource)
294 tnNssmfUtils.attachLogicalLinkToAllottedResource(execution, AAI_VERSION, allottedResourceUri, epA);
296 } catch (BpmnError e) {
298 } catch (Exception ex) {
299 String msg = "Exception in DoCreateTnNssiInstance.createLogicalLinksForAllocatedResource: " + ex.getMessage()
301 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
305 void preprocessSdncAllocateTnNssiRequest(DelegateExecution execution) {
306 def method = getClass().getSimpleName() + '.preProcessSDNCActivateRequest(' +
307 'execution=' + execution.getId() +
309 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
310 logger.trace('Entered ' + method)
312 logger.trace("STARTED preProcessSDNCActivateRequest Process")
314 String serviceInstanceId = execution.getVariable("sliceServiceInstanceId")
316 String createSDNCRequest = tnNssmfUtils.buildSDNCRequest(execution, serviceInstanceId, "create")
318 execution.setVariable("TNNSSMF_SDNCRequest", createSDNCRequest)
319 logger.debug("Outgoing SDNCRequest is: \n" + createSDNCRequest)
321 } catch (Exception e) {
322 logger.debug("Exception Occured Processing preProcessSDNCActivateRequest. Exception is:\n" + e)
323 exceptionUtil.buildAndThrowWorkflowException(execution, 1002,
324 "Error Occured during preProcessSDNCActivateRequest Method:\n" + e.getMessage())
326 logger.trace("COMPLETED preProcessSDNCActivateRequest Process")
330 void validateSDNCResponse(DelegateExecution execution, String response, String method) {
331 tnNssmfUtils.validateSDNCResponse(execution, response, method)