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
38 import static org.apache.commons.lang3.StringUtils.isNotBlank
40 class DoCreateTnNssiInstance extends AbstractServiceTaskProcessor {
42 private static final Logger logger = LoggerFactory.getLogger(DoCreateTnNssiInstance.class);
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 if (isBlank(execution.getVariable("enableSdnc"))) {
67 tnNssmfUtils.setEnableSdncConfig(execution)
70 logger.trace("Exit preProcessRequest")
74 void createSliceProfile(DelegateExecution execution) {
76 String ssInstanceId = execution.getVariable("sliceServiceInstanceId")
77 String sliceProfileStr = execution.getVariable("sliceProfile")
78 String sliceProfileId = UUID.randomUUID().toString()
79 SliceProfile sliceProfile = new SliceProfile();
80 sliceProfile.setProfileId(sliceProfileId)
81 sliceProfile.setLatency(Integer.parseInt(jsonUtil.getJsonValue(sliceProfileStr, "latency")))
82 sliceProfile.setResourceSharingLevel(jsonUtil.getJsonValue(sliceProfileStr, "resourceSharingLevel"))
83 //sliceProfile.setSNssai(tnNssmfUtils.getFirstSnssaiFromSliceProfile(sliceProfileStr))
85 sliceProfile.setMaxBandwidth(Integer.parseInt(jsonUtil.getJsonValue(sliceProfileStr, "maxBandwidth")))
87 //sliceProfile.setReliability(new Object())
89 AAIResourcesClient client = getAAIClient()
91 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
92 .customer(execution.getVariable("globalSubscriberId"))
93 .serviceSubscription(execution.getVariable("subscriptionServiceType"))
94 .serviceInstance(ssInstanceId)
95 .sliceProfile(sliceProfileId))
96 client.create(uri, sliceProfile)
98 } catch (BpmnError e) {
100 } catch (Exception ex) {
101 String msg = "Exception in DoCreateSliceServiceInstance.instantiateSliceService. " + ex.getMessage()
103 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
108 void createServiceInstance(DelegateExecution execution) {
110 String serviceRole = "nssi"
111 String serviceType = execution.getVariable("subscriptionServiceType")
112 String ssInstanceId = execution.getVariable("sliceServiceInstanceId")
113 String sliceProfileStr = execution.getVariable("sliceProfile")
115 if (sliceProfileStr == null || sliceProfileStr.isEmpty()) {
116 String msg = "ERROR: createServiceInstance: sliceProfile is null"
118 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
121 org.onap.aai.domain.yang.ServiceInstance ss = new org.onap.aai.domain.yang.ServiceInstance()
122 ss.setServiceInstanceId(ssInstanceId)
123 String sliceInstanceName = execution.getVariable("sliceServiceInstanceName")
124 if (isBlank(sliceInstanceName)) {
125 logger.error("ERROR: createServiceInstance: sliceInstanceName is null")
126 sliceInstanceName = ssInstanceId
128 ss.setServiceInstanceName(sliceInstanceName)
129 ss.setServiceType(serviceType)
130 String serviceStatus = "deactivated"
131 ss.setOrchestrationStatus(serviceStatus)
132 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
133 String modelUuid = execution.getVariable("modelUuid")
134 ss.setModelInvariantId(modelInvariantUuid)
135 ss.setModelVersionId(modelUuid)
136 String serviceInstanceLocationId = tnNssmfUtils.getFirstPlmnIdFromSliceProfile(sliceProfileStr)
137 ss.setServiceInstanceLocationId(serviceInstanceLocationId)
138 String snssai = tnNssmfUtils.getFirstSnssaiFromSliceProfile(sliceProfileStr)
139 //ss.setEnvironmentContext(snssai)
140 ss.setEnvironmentContext("tn")
141 ss.setServiceRole(serviceRole)
143 String domainTypeStr = jsonUtil.getJsonValue(sliceProfileStr, "domainType")
144 if (isNotBlank(domainTypeStr)) {
145 ss.setWorkloadContext(domainTypeStr)
148 AAIResourcesClient client = getAAIClient()
150 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
151 .customer(execution.getVariable("globalSubscriberId"))
152 .serviceSubscription(execution.getVariable("subscriptionServiceType"))
153 .serviceInstance(ssInstanceId))
154 client.create(uri, ss)
155 } catch (BpmnError e) {
157 } catch (Exception ex) {
158 String msg = "Exception in DoCreateTnNssiInstance.createServiceInstance: " + ex.getMessage()
160 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
165 void createAllottedResource(DelegateExecution execution) {
166 String ssInstanceId = execution.getVariable('sliceServiceInstanceId')
169 List<String> networkStrList = jsonUtil.StringArrayToList(execution.getVariable("transportSliceNetworks"))
171 for (String networkStr : networkStrList) {
172 String allottedResourceId = UUID.randomUUID().toString()
173 AAIResourceUri allottedResourceUri =
174 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
175 .customer(execution.getVariable("globalSubscriberId"))
176 .serviceSubscription(execution.getVariable("subscriptionServiceType"))
177 .serviceInstance(execution.getVariable("sliceServiceInstanceId"))
178 .allottedResource(allottedResourceId))
179 execution.setVariable("allottedResourceUri", allottedResourceUri)
180 String modelInvariantId = execution.getVariable("modelInvariantUuid")
181 String modelVersionId = execution.getVariable("modelUuid")
183 org.onap.aai.domain.yang.AllottedResource resource = new org.onap.aai.domain.yang.AllottedResource()
184 resource.setId(allottedResourceId)
185 resource.setType("TsciNetwork")
186 resource.setAllottedResourceName("network_" + execution.getVariable("sliceServiceInstanceName"))
187 getAAIClient().create(allottedResourceUri, resource)
189 createNetworkPolicyForAllocatedResource(execution, ssInstanceId, allottedResourceId)
191 String linkArrayStr = jsonUtil.getJsonValue(networkStr, "connectionLinks")
192 createLogicalLinksForAllocatedResource(execution, linkArrayStr, ssInstanceId, allottedResourceId)
194 } catch (BpmnError e) {
196 } catch (Exception ex) {
197 String msg = "Exception in DoCreateTnNssiInstance.createAllottedResource: " + ex.getMessage()
199 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
203 void createNetworkPolicy(DelegateExecution execution, String ssInstanceId, String networkPolicyId) {
206 String sliceProfileStr = execution.getVariable("sliceProfile")
207 if (sliceProfileStr == null || sliceProfileStr.isEmpty()) {
208 String msg = "ERROR: createNetworkPolicy: sliceProfile is null"
210 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
213 NetworkPolicy networkPolicy = new NetworkPolicy();
214 networkPolicy.setNetworkPolicyId(networkPolicyId)
215 networkPolicy.setName("TSCi policy")
216 networkPolicy.setType("SLA")
217 networkPolicy.setNetworkPolicyFqdn(ssInstanceId)
219 String latencyStr = jsonUtil.getJsonValue(sliceProfileStr, "latency")
220 if (latencyStr != null && !latencyStr.isEmpty()) {
221 networkPolicy.setLatency(Integer.parseInt(latencyStr))
224 String bwStr = jsonUtil.getJsonValue(sliceProfileStr, "maxBandwidth")
225 if (bwStr != null && !bwStr.isEmpty()) {
226 networkPolicy.setMaxBandwidth(Integer.parseInt(bwStr))
228 logger.debug("ERROR: createNetworkPolicy: maxBandwidth is null")
231 //networkPolicy.setReliability(new Object())
233 AAIResourceUri networkPolicyUri =
234 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().networkPolicy(networkPolicyId))
235 getAAIClient().create(networkPolicyUri, networkPolicy)
237 } catch (BpmnError e) {
239 } catch (Exception ex) {
240 String msg = "Exception in DoCreateSliceServiceInstance.instantiateSliceService. " + ex.getMessage()
242 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
246 void createNetworkPolicyForAllocatedResource(DelegateExecution execution,
248 String allottedResourceId) {
250 AAIResourceUri allottedResourceUri =
251 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
252 .customer(execution.getVariable("globalSubscriberId"))
253 .serviceSubscription(execution.getVariable("subscriptionServiceType"))
254 .serviceInstance(ssInstanceId)
255 .allottedResource(allottedResourceId))
257 if (!getAAIClient().exists(allottedResourceUri)) {
258 logger.info("ERROR: createLogicalLinksForAllocatedResource: allottedResource not exist: uri={}",
263 String networkPolicyId = UUID.randomUUID().toString()
264 createNetworkPolicy(execution, ssInstanceId, networkPolicyId)
266 tnNssmfUtils.attachNetworkPolicyToAllottedResource(execution, tnNssmfUtils.AAI_VERSION,
270 } catch (BpmnError e) {
272 } catch (Exception ex) {
273 String msg = "Exception in DoCreateSliceServiceInstance.instantiateSliceService. " + ex.getMessage()
275 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
279 void createLogicalLinksForAllocatedResource(DelegateExecution execution,
280 String linkArrayStr, String ssInstanceId,
281 String allottedResourceId) {
283 AAIResourceUri allottedResourceUri =
284 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
285 .customer(execution.getVariable("globalSubscriberId"))
286 .serviceSubscription(execution.getVariable("subscriptionServiceType"))
287 .serviceInstance(ssInstanceId)
288 .allottedResource(allottedResourceId))
290 if (!getAAIClient().exists(allottedResourceUri)) {
291 logger.info("ERROR: createLogicalLinksForAllocatedResource: allottedResource not exist: uri={}",
296 List<String> linkStrList = jsonUtil.StringArrayToList(linkArrayStr)
298 for (String linkStr : linkStrList) {
299 String linkId = jsonUtil.getJsonValue(linkStr, "id")
300 if (isBlank(linkId)) {
301 linkId = "tn-nssmf-" + UUID.randomUUID().toString()
303 logger.debug("createLogicalLinksForAllocatedResource: linkId=" + linkId)
305 String epA = jsonUtil.getJsonValue(linkStr, "transportEndpointA")
306 String epB = jsonUtil.getJsonValue(linkStr, "transportEndpointB")
307 String modelInvariantId = execution.getVariable("modelInvariantUuid")
308 String modelVersionId = execution.getVariable("modelUuid")
310 org.onap.aai.domain.yang.LogicalLink resource = new org.onap.aai.domain.yang.LogicalLink()
311 resource.setLinkId(linkId)
312 resource.setLinkName(epA)
313 resource.setLinkName2(epB)
314 resource.setLinkType("TsciConnectionLink")
315 resource.setInMaint(false)
318 AAIResourceUri logicalLinkUri =
319 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().logicalLink(epA))
320 getAAIClient().create(logicalLinkUri, resource)
322 tnNssmfUtils.attachLogicalLinkToAllottedResource(execution, tnNssmfUtils.AAI_VERSION,
323 allottedResourceUri, epA);
325 } catch (BpmnError e) {
327 } catch (Exception ex) {
328 String msg = "Exception in DoCreateTnNssiInstance.createLogicalLinksForAllocatedResource: " + ex.getMessage()
330 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
334 void preprocessSdncAllocateTnNssiRequest(DelegateExecution execution) {
335 def method = getClass().getSimpleName() + '.preProcessSDNCActivateRequest(' +
336 'execution=' + execution.getId() +
338 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
339 logger.trace('Entered ' + method)
341 logger.trace("STARTED preProcessSDNCActivateRequest Process")
343 String serviceInstanceId = execution.getVariable("sliceServiceInstanceId")
345 String createSDNCRequest = tnNssmfUtils.buildSDNCRequest(execution, serviceInstanceId, "create")
347 execution.setVariable("TNNSSMF_SDNCRequest", createSDNCRequest)
348 logger.debug("Outgoing SDNCRequest is: \n" + createSDNCRequest)
350 } catch (Exception e) {
351 logger.debug("Exception Occured Processing preProcessSDNCActivateRequest. Exception is:\n" + e)
352 exceptionUtil.buildAndThrowWorkflowException(execution, 1002,
353 "Error Occured during preProcessSDNCActivateRequest Method:\n" + e.getMessage())
355 logger.trace("COMPLETED preProcessSDNCActivateRequest Process")
359 void validateSDNCResponse(DelegateExecution execution, String response, String method) {
360 tnNssmfUtils.validateSDNCResponse(execution, response, method)