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 import static org.apache.commons.lang3.StringUtils.isBlank
39 class DoCreateTnNssiInstance extends AbstractServiceTaskProcessor {
41 private static final Logger logger = LoggerFactory.getLogger(DoCreateTnNssiInstance.class);
42 final String AAI_VERSION = "v21"
43 JsonUtils jsonUtil = new JsonUtils()
44 TnNssmfUtils tnNssmfUtils = new TnNssmfUtils()
45 ExceptionUtil exceptionUtil = new ExceptionUtil()
46 String Prefix = "DCTN_"
48 void preProcessRequest(DelegateExecution execution) {
50 logger.trace("Enter preProcessRequest()")
52 execution.setVariable("prefix", Prefix)
54 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
55 String modelUuid = execution.getVariable("modelUuid")
56 //here modelVersion is not set, we use modelUuid to decompose the service.
57 def isDebugLogEnabled = true
58 execution.setVariable("isDebugLogEnabled", isDebugLogEnabled)
59 String serviceModelInfo = """{
60 "modelInvariantUuid":"${modelInvariantUuid}",
61 "modelUuid":"${modelUuid}",
64 execution.setVariable("serviceModelInfo", serviceModelInfo)
66 tnNssmfUtils.setEnableSdncConfig(execution)
68 logger.trace("Exit preProcessRequest")
72 void createSliceProfile(DelegateExecution execution) {
74 String ssInstanceId = execution.getVariable("sliceServiceInstanceId")
75 String sliceProfileStr = execution.getVariable("sliceProfile")
76 String sliceProfileId = UUID.randomUUID().toString()
77 SliceProfile sliceProfile = new SliceProfile();
78 sliceProfile.setProfileId(sliceProfileId)
79 sliceProfile.setLatency(Integer.parseInt(jsonUtil.getJsonValue(sliceProfileStr, "latency")))
80 sliceProfile.setResourceSharingLevel(jsonUtil.getJsonValue(sliceProfileStr, "resourceSharingLevel"))
81 //sliceProfile.setSNssai(tnNssmfUtils.getFirstSnssaiFromSliceProfile(sliceProfileStr))
83 sliceProfile.setMaxBandwidth(Integer.parseInt(jsonUtil.getJsonValue(sliceProfileStr, "maxBandwidth")))
85 //sliceProfile.setReliability(new Object())
87 AAIResourcesClient client = getAAIClient()
89 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
90 .customer(execution.getVariable("globalSubscriberId"))
91 .serviceSubscription(execution.getVariable("subscriptionServiceType"))
92 .serviceInstance(ssInstanceId)
93 .sliceProfile(sliceProfileId))
94 client.create(uri, sliceProfile)
96 } catch (BpmnError e) {
98 } catch (Exception ex) {
99 String msg = "Exception in DoCreateSliceServiceInstance.instantiateSliceService. " + ex.getMessage()
101 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
106 void createServiceInstance(DelegateExecution execution) {
108 String serviceRole = "nssi"
109 String serviceType = execution.getVariable("subscriptionServiceType")
110 String ssInstanceId = execution.getVariable("sliceServiceInstanceId")
111 String sliceProfileStr = execution.getVariable("sliceProfile")
113 org.onap.aai.domain.yang.ServiceInstance ss = new org.onap.aai.domain.yang.ServiceInstance()
114 ss.setServiceInstanceId(ssInstanceId)
115 String sliceInstanceName = execution.getVariable("sliceServiceInstanceName")
116 if (isBlank(sliceInstanceName)) {
117 logger.error("ERROR: createServiceInstance: sliceInstanceName is null")
118 sliceInstanceName = ssInstanceId
120 ss.setServiceInstanceName(sliceInstanceName)
121 ss.setServiceType(serviceType)
122 String serviceStatus = "deactivated"
123 ss.setOrchestrationStatus(serviceStatus)
124 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
125 String modelUuid = execution.getVariable("modelUuid")
126 ss.setModelInvariantId(modelInvariantUuid)
127 ss.setModelVersionId(modelUuid)
128 String serviceInstanceLocationid = tnNssmfUtils.getFirstPlmnIdFromSliceProfile(sliceProfileStr)
129 ss.setServiceInstanceLocationId(serviceInstanceLocationid)
130 String snssai = tnNssmfUtils.getFirstSnssaiFromSliceProfile(sliceProfileStr)
131 //ss.setEnvironmentContext(snssai)
132 ss.setEnvironmentContext("tn")
133 ss.setServiceRole(serviceRole)
134 AAIResourcesClient client = getAAIClient()
136 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
137 .customer(execution.getVariable("globalSubscriberId"))
138 .serviceSubscription(execution.getVariable("subscriptionServiceType"))
139 .serviceInstance(ssInstanceId))
140 client.create(uri, ss)
141 } catch (BpmnError e) {
143 } catch (Exception ex) {
144 String msg = "Exception in DoCreateTnNssiInstance.createServiceInstance: " + ex.getMessage()
146 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
151 void createAllottedResource(DelegateExecution execution) {
152 String ssInstanceId = execution.getVariable('sliceServiceInstanceId')
155 List<String> networkStrList = jsonUtil.StringArrayToList(execution.getVariable("transportSliceNetworks"))
157 for (String networkStr : networkStrList) {
158 String allottedResourceId = UUID.randomUUID().toString()
159 AAIResourceUri allottedResourceUri =
160 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
161 .customer(execution.getVariable("globalSubscriberId"))
162 .serviceSubscription(execution.getVariable("subscriptionServiceType"))
163 .serviceInstance(execution.getVariable("sliceServiceInstanceId"))
164 .allottedResource(allottedResourceId))
165 execution.setVariable("allottedResourceUri", allottedResourceUri)
166 String modelInvariantId = execution.getVariable("modelInvariantUuid")
167 String modelVersionId = execution.getVariable("modelUuid")
169 org.onap.aai.domain.yang.AllottedResource resource = new org.onap.aai.domain.yang.AllottedResource()
170 resource.setId(allottedResourceId)
171 resource.setType("TsciNetwork")
172 resource.setAllottedResourceName("network_" + execution.getVariable("sliceServiceInstanceName"))
173 getAAIClient().create(allottedResourceUri, resource)
175 createNetworkPolicyForAllocatedResource(execution, ssInstanceId, allottedResourceId)
177 String linkArrayStr = jsonUtil.getJsonValue(networkStr, "connectionLinks")
178 createLogicalLinksForAllocatedResource(execution, linkArrayStr, ssInstanceId, allottedResourceId)
180 } catch (BpmnError e) {
182 } catch (Exception ex) {
183 String msg = "Exception in DoCreateTnNssiInstance.createAllottedResource: " + ex.getMessage()
185 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
189 void createNetworkPolicy(DelegateExecution execution, String ssInstanceId, String networkPolicyId) {
192 String sliceProfileStr = execution.getVariable("sliceProfile")
193 if (sliceProfileStr == null || sliceProfileStr.isEmpty()) {
194 String msg = "ERROR: createNetworkPolicy: sliceProfile is null"
196 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
199 NetworkPolicy networkPolicy = new NetworkPolicy();
200 networkPolicy.setNetworkPolicyId(networkPolicyId)
201 networkPolicy.setName("TSCi policy")
202 networkPolicy.setType("SLA")
203 networkPolicy.setNetworkPolicyFqdn(ssInstanceId)
205 String latencyStr = jsonUtil.getJsonValue(sliceProfileStr, "latency")
206 if (latencyStr != null && !latencyStr.isEmpty()) {
207 networkPolicy.setLatency(Integer.parseInt(latencyStr))
210 String bwStr = jsonUtil.getJsonValue(sliceProfileStr, "maxBandwidth")
211 if (bwStr != null && !bwStr.isEmpty()) {
212 networkPolicy.setMaxBandwidth(Integer.parseInt(bwStr))
214 log.debug("ERROR: createNetworkPolicy: maxBandwidth is null")
217 //networkPolicy.setReliability(new Object())
219 AAIResourceUri networkPolicyUri =
220 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().networkPolicy(networkPolicyId))
221 getAAIClient().create(networkPolicyUri, networkPolicy)
223 } catch (BpmnError e) {
225 } catch (Exception ex) {
226 String msg = "Exception in DoCreateSliceServiceInstance.instantiateSliceService. " + ex.getMessage()
228 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
232 void createNetworkPolicyForAllocatedResource(DelegateExecution execution,
234 String allottedResourceId) {
236 AAIResourceUri allottedResourceUri =
237 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
238 .customer(execution.getVariable("globalSubscriberId"))
239 .serviceSubscription(execution.getVariable("subscriptionServiceType"))
240 .serviceInstance(ssInstanceId)
241 .allottedResource(allottedResourceId))
243 if (!getAAIClient().exists(allottedResourceUri)) {
244 logger.info("ERROR: createLogicalLinksForAllocatedResource: allottedResource not exist: uri={}",
249 String networkPolicyId = UUID.randomUUID().toString()
250 createNetworkPolicy(execution, ssInstanceId, networkPolicyId)
252 tnNssmfUtils.attachNetworkPolicyToAllottedResource(execution, AAI_VERSION, allottedResourceUri, networkPolicyId);
254 } catch (BpmnError e) {
256 } catch (Exception ex) {
257 String msg = "Exception in DoCreateSliceServiceInstance.instantiateSliceService. " + ex.getMessage()
259 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
263 void createLogicalLinksForAllocatedResource(DelegateExecution execution,
264 String linkArrayStr, String ssInstanceId,
265 String allottedResourceId) {
267 AAIResourceUri allottedResourceUri =
268 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
269 .customer(execution.getVariable("globalSubscriberId"))
270 .serviceSubscription(execution.getVariable("subscriptionServiceType"))
271 .serviceInstance(ssInstanceId)
272 .allottedResource(allottedResourceId))
274 if (!getAAIClient().exists(allottedResourceUri)) {
275 logger.info("ERROR: createLogicalLinksForAllocatedResource: allottedResource not exist: uri={}",
280 List<String> linkStrList = jsonUtil.StringArrayToList(linkArrayStr)
282 for (String linkStr : linkStrList) {
283 String logicalLinkId = UUID.randomUUID().toString()
284 String epA = jsonUtil.getJsonValue(linkStr, "transportEndpointA")
285 String epB = jsonUtil.getJsonValue(linkStr, "transportEndpointB")
286 String modelInvariantId = execution.getVariable("modelInvariantUuid")
287 String modelVersionId = execution.getVariable("modelUuid")
289 org.onap.aai.domain.yang.LogicalLink resource = new org.onap.aai.domain.yang.LogicalLink()
290 resource.setLinkId(logicalLinkId)
291 resource.setLinkName(epA)
292 resource.setLinkName2(epB)
293 resource.setLinkType("TsciConnectionLink")
294 resource.setInMaint(false)
297 AAIResourceUri logicalLinkUri =
298 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().logicalLink(epA))
299 getAAIClient().create(logicalLinkUri, resource)
301 tnNssmfUtils.attachLogicalLinkToAllottedResource(execution, AAI_VERSION, allottedResourceUri, epA);
303 } catch (BpmnError e) {
305 } catch (Exception ex) {
306 String msg = "Exception in DoCreateTnNssiInstance.createLogicalLinksForAllocatedResource: " + ex.getMessage()
308 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
312 void preprocessSdncAllocateTnNssiRequest(DelegateExecution execution) {
313 def method = getClass().getSimpleName() + '.preProcessSDNCActivateRequest(' +
314 'execution=' + execution.getId() +
316 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
317 logger.trace('Entered ' + method)
319 logger.trace("STARTED preProcessSDNCActivateRequest Process")
321 String serviceInstanceId = execution.getVariable("sliceServiceInstanceId")
323 String createSDNCRequest = tnNssmfUtils.buildSDNCRequest(execution, serviceInstanceId, "create")
325 execution.setVariable("TNNSSMF_SDNCRequest", createSDNCRequest)
326 logger.debug("Outgoing SDNCRequest is: \n" + createSDNCRequest)
328 } catch (Exception e) {
329 logger.debug("Exception Occured Processing preProcessSDNCActivateRequest. Exception is:\n" + e)
330 exceptionUtil.buildAndThrowWorkflowException(execution, 1002,
331 "Error Occured during preProcessSDNCActivateRequest Method:\n" + e.getMessage())
333 logger.trace("COMPLETED preProcessSDNCActivateRequest Process")
337 void validateSDNCResponse(DelegateExecution execution, String response, String method) {
338 tnNssmfUtils.validateSDNCResponse(execution, response, method)