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.SliceProfile
26 import org.onap.aaiclient.client.aai.AAIResourcesClient
27 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
28 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
29 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
30 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
31 import org.onap.so.bpmn.common.scripts.ExceptionUtil
32 import org.onap.so.bpmn.core.json.JsonUtils
33 import org.slf4j.Logger
34 import org.slf4j.LoggerFactory
36 class DoCreateTnNssiInstance extends AbstractServiceTaskProcessor {
38 private static final Logger logger = LoggerFactory.getLogger(DoCreateTnNssiInstance.class);
39 final String AAI_VERSION = "v21"
40 JsonUtils jsonUtil = new JsonUtils()
41 TnNssmfUtils tnNssmfUtils = new TnNssmfUtils()
42 ExceptionUtil exceptionUtil = new ExceptionUtil()
43 String Prefix = "DCTN_"
45 void preProcessRequest(DelegateExecution execution) {
47 logger.trace("Enter preProcessRequest()")
49 execution.setVariable("prefix", Prefix)
51 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
52 String modelUuid = execution.getVariable("modelUuid")
53 //here modelVersion is not set, we use modelUuid to decompose the service.
54 def isDebugLogEnabled = true
55 execution.setVariable("isDebugLogEnabled", isDebugLogEnabled)
56 String serviceModelInfo = """{
57 "modelInvariantUuid":"${modelInvariantUuid}",
58 "modelUuid":"${modelUuid}",
61 execution.setVariable("serviceModelInfo", serviceModelInfo)
63 logger.trace("Exit preProcessRequest")
67 void createSliceProfile(DelegateExecution execution) {
69 String ssInstanceId = execution.getVariable("sliceServiceInstanceId")
70 String sliceProfileStr = execution.getVariable("sliceProfile")
71 String sliceProfileId = UUID.randomUUID().toString()
72 SliceProfile sliceProfile = new SliceProfile();
73 sliceProfile.setProfileId(sliceProfileId)
74 sliceProfile.setLatency(Integer.parseInt(jsonUtil.getJsonValue(sliceProfileStr, "latency")))
75 sliceProfile.setResourceSharingLevel(jsonUtil.getJsonValue(sliceProfileStr, "resourceSharingLevel"))
76 //sliceProfile.setSNssai(tnNssmfUtils.getFirstSnssaiFromSliceProfile(sliceProfileStr))
78 sliceProfile.setMaxBandwidth(Integer.parseInt(jsonUtil.getJsonValue(sliceProfileStr, "maxBandwidth")))
80 //sliceProfile.setReliability(new Object())
82 AAIResourcesClient client = getAAIClient()
84 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
85 .customer(execution.getVariable("globalSubscriberId"))
86 .serviceSubscription(execution.getVariable("subscriptionServiceType"))
87 .serviceInstance(ssInstanceId)
88 .sliceProfile(sliceProfileId))
89 client.create(uri, sliceProfile)
91 } catch (BpmnError e) {
93 } catch (Exception ex) {
94 String msg = "Exception in DoCreateSliceServiceInstance.instantiateSliceService. " + ex.getMessage()
96 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
101 void createServiceInstance(DelegateExecution execution) {
103 String serviceRole = "TN"
104 String serviceType = execution.getVariable("subscriptionServiceType")
105 String ssInstanceId = execution.getVariable("sliceServiceInstanceId")
106 String sliceProfileStr = execution.getVariable("sliceProfile")
108 org.onap.aai.domain.yang.ServiceInstance ss = new org.onap.aai.domain.yang.ServiceInstance()
109 ss.setServiceInstanceId(ssInstanceId)
110 String sliceInstanceName = execution.getVariable("sliceServiceInstanceName")
111 ss.setServiceInstanceName(sliceInstanceName)
112 ss.setServiceType(serviceType)
113 String serviceStatus = "allocated"
114 ss.setOrchestrationStatus(serviceStatus)
115 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
116 String modelUuid = execution.getVariable("modelUuid")
117 //TODO: need valid model ID from the caller, as AAI does not accept invalid IDs
118 //ss.setModelInvariantId(modelInvariantUuid)
119 //ss.setModelVersionId(modelUuid)
120 String serviceInstanceLocationid = tnNssmfUtils.getFirstPlmnIdFromSliceProfile(sliceProfileStr)
121 ss.setServiceInstanceLocationId(serviceInstanceLocationid)
122 String snssai = tnNssmfUtils.getFirstSnssaiFromSliceProfile(sliceProfileStr)
123 ss.setEnvironmentContext(snssai)
124 ss.setServiceRole(serviceRole)
125 AAIResourcesClient client = getAAIClient()
127 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
128 .customer(execution.getVariable("globalSubscriberId"))
129 .serviceSubscription(execution.getVariable("subscriptionServiceType"))
130 .serviceInstance(ssInstanceId))
131 client.create(uri, ss)
132 } catch (BpmnError e) {
134 } catch (Exception ex) {
135 String msg = "Exception in DoCreateTnNssiInstance.createServiceInstance: " + ex.getMessage()
137 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
142 void createAllottedResource(DelegateExecution execution) {
143 String ssInstanceId = execution.getVariable('sliceServiceInstanceId')
146 List<String> networkStrList = jsonUtil.StringArrayToList(execution.getVariable("transportSliceNetworks"))
148 for (String networkStr : networkStrList) {
149 String allottedResourceId = UUID.randomUUID().toString()
150 AAIResourceUri allottedResourceUri =
151 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
152 .customer(execution.getVariable("globalSubscriberId"))
153 .serviceSubscription(execution.getVariable("subscriptionServiceType"))
154 .serviceInstance(execution.getVariable("sliceServiceInstanceId"))
155 .allottedResource(allottedResourceId))
156 execution.setVariable("allottedResourceUri", allottedResourceUri)
157 String modelInvariantId = execution.getVariable("modelInvariantUuid")
158 String modelVersionId = execution.getVariable("modelUuid")
160 org.onap.aai.domain.yang.AllottedResource resource = new org.onap.aai.domain.yang.AllottedResource()
161 resource.setId(allottedResourceId)
162 resource.setType("TsciNetwork")
163 resource.setAllottedResourceName("network_" + execution.getVariable("sliceServiceInstanceName"))
164 getAAIClient().create(allottedResourceUri, resource)
166 String linkArrayStr = jsonUtil.getJsonValue(networkStr, "connectionLinks")
167 createLogicalLinksForAllocatedResource(execution, linkArrayStr, ssInstanceId, allottedResourceId)
169 } catch (BpmnError e) {
171 } catch (Exception ex) {
172 String msg = "Exception in DoCreateTnNssiInstance.createAllottedResource: " + ex.getMessage()
174 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
178 void createLogicalLinksForAllocatedResource(DelegateExecution execution,
179 String linkArrayStr, String ssInstanceId,
180 String allottedResourceId) {
182 AAIResourceUri allottedResourceUri =
183 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
184 .customer(execution.getVariable("globalSubscriberId"))
185 .serviceSubscription(execution.getVariable("subscriptionServiceType"))
186 .serviceInstance(ssInstanceId)
187 .allottedResource(allottedResourceId))
189 if (!getAAIClient().exists(allottedResourceUri)) {
190 logger.info("ERROR: createLogicalLinksForAllocatedResource: allottedResource not exist: uri={}",
195 List<String> linkStrList = jsonUtil.StringArrayToList(linkArrayStr)
197 for (String linkStr : linkStrList) {
198 String logicalLinkId = UUID.randomUUID().toString()
199 String epA = jsonUtil.getJsonValue(linkStr, "transportEndpointA")
200 String epB = jsonUtil.getJsonValue(linkStr, "transportEndpointB")
201 String modelInvariantId = execution.getVariable("modelInvariantUuid")
202 String modelVersionId = execution.getVariable("modelUuid")
204 org.onap.aai.domain.yang.LogicalLink resource = new org.onap.aai.domain.yang.LogicalLink()
205 resource.setLinkId(logicalLinkId)
206 resource.setLinkName(epA)
207 resource.setLinkName2(epB)
208 resource.setLinkType("TsciConnectionLink")
209 resource.setInMaint(false)
212 AAIResourceUri logicalLinkUri =
213 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().logicalLink(epA))
214 getAAIClient().create(logicalLinkUri, resource)
216 tnNssmfUtils.attachLogicalLinkToAllottedResource(execution, AAI_VERSION, allottedResourceUri, epA);
218 } catch (BpmnError e) {
220 } catch (Exception ex) {
221 String msg = "Exception in DoCreateTnNssiInstance.createLogicalLinksForAllocatedResource: " + ex.getMessage()
223 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
227 void preprocessSdncAllocateTnNssiRequest(DelegateExecution execution) {
228 def method = getClass().getSimpleName() + '.preProcessSDNCActivateRequest(' +
229 'execution=' + execution.getId() +
231 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
232 logger.trace('Entered ' + method)
234 logger.trace("STARTED preProcessSDNCActivateRequest Process")
236 String serviceInstanceId = execution.getVariable("sliceServiceInstanceId")
238 String createSDNCRequest = tnNssmfUtils.buildSDNCRequest(execution, serviceInstanceId, "create")
240 execution.setVariable("TNNSSMF_SDNCRequest", createSDNCRequest)
241 logger.debug("Outgoing SDNCRequest is: \n" + createSDNCRequest)
243 } catch (Exception e) {
244 logger.debug("Exception Occured Processing preProcessSDNCActivateRequest. Exception is:\n" + e)
245 exceptionUtil.buildAndThrowWorkflowException(execution, 1002,
246 "Error Occured during preProcessSDNCActivateRequest Method:\n" + e.getMessage())
248 logger.trace("COMPLETED preProcessSDNCActivateRequest Process")
252 void validateSDNCResponse(DelegateExecution execution, String response, String method) {
253 tnNssmfUtils.validateSDNCResponse(execution, response, method)