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.AAIObjectType
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.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 JsonUtils jsonUtil = new JsonUtils()
40 TnNssmfUtils tnNssmfUtils = new TnNssmfUtils()
41 ExceptionUtil exceptionUtil = new ExceptionUtil()
42 String Prefix = "DCTN_"
44 void preProcessRequest(DelegateExecution execution) {
46 logger.trace("Enter preProcessRequest()")
48 execution.setVariable("prefix", Prefix)
50 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
51 String modelUuid = execution.getVariable("modelUuid")
52 //here modelVersion is not set, we use modelUuid to decompose the service.
53 def isDebugLogEnabled = true
54 execution.setVariable("isDebugLogEnabled", isDebugLogEnabled)
55 String serviceModelInfo = """{
56 "modelInvariantUuid":"${modelInvariantUuid}",
57 "modelUuid":"${modelUuid}",
60 execution.setVariable("serviceModelInfo", serviceModelInfo)
62 logger.trace("Exit preProcessRequest")
66 void createSliceProfile(DelegateExecution execution) {
68 String sliceserviceInstanceId = execution.getVariable("sliceServiceInstanceId")
69 String sliceProfileStr = execution.getVariable("sliceProfile")
70 String sliceProfileId = UUID.randomUUID().toString()
71 SliceProfile sliceProfile = new SliceProfile();
72 sliceProfile.setProfileId(sliceProfileId)
73 sliceProfile.setLatency(Integer.parseInt(jsonUtil.getJsonValue(sliceProfileStr, "latency")))
74 sliceProfile.setResourceSharingLevel(jsonUtil.getJsonValue(sliceProfileStr, "resourceSharingLevel"))
75 sliceProfile.setSNssai(tnNssmfUtils.getFirstSnssaiFromSliceProfile(sliceProfileStr)) //TODO: should be list
77 sliceProfile.setE2ELatency(Integer.parseInt(jsonUtil.getJsonValue(sliceProfileStr, "latency")))
78 sliceProfile.setMaxBandwidth(Integer.parseInt(jsonUtil.getJsonValue(sliceProfileStr, "maxBandwidth")))
81 sliceProfile.setReliability(new Object())
83 AAIResourcesClient client = getAAIClient()
84 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE, execution.getVariable
85 ("globalSubscriberId"),
86 execution.getVariable("subscriptionServiceType"), sliceserviceInstanceId, sliceProfileId)
87 client.create(uri, sliceProfile)
89 } catch (BpmnError e) {
91 } catch (Exception ex) {
92 String msg = "Exception in DoCreateSliceServiceInstance.instantiateSliceService. " + ex.getMessage()
94 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
99 void createServiceInstance(DelegateExecution execution) {
101 String serviceRole = "TN"
102 String serviceType = execution.getVariable("subscriptionServiceType")
103 String ssInstanceId = execution.getVariable("sliceServiceInstanceId")
104 String sliceProfileStr = execution.getVariable("sliceProfile")
106 org.onap.aai.domain.yang.ServiceInstance ss = new org.onap.aai.domain.yang.ServiceInstance()
107 ss.setServiceInstanceId(ssInstanceId)
108 String sliceInstanceName = execution.getVariable("sliceServiceInstanceName")
109 ss.setServiceInstanceName(sliceInstanceName)
110 ss.setServiceType(serviceType)
111 String serviceStatus = "allocated"
112 ss.setOrchestrationStatus(serviceStatus)
113 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
114 String modelUuid = execution.getVariable("modelUuid")
115 ss.setModelInvariantId(modelInvariantUuid)
116 ss.setModelVersionId(modelUuid)
117 String serviceInstanceLocationid = tnNssmfUtils.getFirstPlmnIdFromSliceProfile(sliceProfileStr)
118 ss.setServiceInstanceLocationId(serviceInstanceLocationid)
119 String snssai = tnNssmfUtils.getFirstSnssaiFromSliceProfile(sliceProfileStr)
120 ss.setEnvironmentContext(snssai)
121 ss.setServiceRole(serviceRole)
122 AAIResourcesClient client = getAAIClient()
123 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, execution.getVariable("globalSubscriberId"), execution.getVariable("subscriptionServiceType"), ssInstanceId)
124 client.create(uri, ss)
125 } catch (BpmnError e) {
127 } catch (Exception ex) {
128 String msg = "Exception in DoCreateTnNssiInstance.createServiceInstance. " + ex.getMessage()
130 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
135 void createAllottedResource(DelegateExecution execution) {
136 String serviceInstanceId = execution.getVariable('sliceServiceInstanceId')
138 AAIResourcesClient resourceClient = getAAIClient()
139 AAIResourceUri ssServiceuri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId)
142 List<String> networkStrList = jsonUtil.StringArrayToList(execution.getVariable("transportSliceNetworks"))
144 for (String networkStr : networkStrList) {
145 String allottedResourceId = UUID.randomUUID().toString()
146 AAIResourceUri allottedResourceUri = AAIUriFactory.createResourceUri(AAIObjectType.ALLOTTED_RESOURCE,
147 execution.getVariable("globalSubscriberId"), execution.getVariable("subscriptionServiceType"),
148 execution.getVariable("sliceserviceInstanceId"), allottedResourceId)
149 execution.setVariable("allottedResourceUri", allottedResourceUri)
150 String modelInvariantId = execution.getVariable("modelInvariantUuid")
151 String modelVersionId = execution.getVariable("modelUuid")
153 org.onap.aai.domain.yang.AllottedResource resource = new org.onap.aai.domain.yang.AllottedResource()
154 resource.setId(allottedResourceId)
155 resource.setType("TsciNetwork")
156 resource.setAllottedResourceName("network_" + execution.getVariable("sliceServiceInstanceName"))
157 resource.setModelInvariantId(modelInvariantId)
158 resource.setModelVersionId(modelVersionId)
159 getAAIClient().create(allottedResourceUri, resource)
160 //AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceFromExistingURI(AAIObjectType.SERVICE_INSTANCE, UriBuilder.fromPath(ssServiceuri).build())
161 //getAAIClient().connect(allottedResourceUri,ssServiceuri)
162 //execution.setVariable("aaiARPath", allottedResourceUri.build().toString());
164 String linkArrayStr = jsonUtil.getJsonValue(networkStr, "connectionLinks")
165 createLogicalLinksForAllocatedResource(execution, linkArrayStr, serviceInstanceId, allottedResourceId)
168 } catch (Exception ex) {
169 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Exception in createAaiAR " + ex.getMessage())
173 void createLogicalLinksForAllocatedResource(DelegateExecution execution,
174 String linkArrayStr, String serviceInstanceId,
175 String allottedResourceId) {
178 List<String> linkStrList = jsonUtil.StringArrayToList(linkArrayStr)
180 for (String linkStr : linkStrList) {
181 String logicalLinkId = UUID.randomUUID().toString()
182 String epA = jsonUtil.getJsonValue(linkStr, "transportEndpointA")
183 String epB = jsonUtil.getJsonValue(linkStr, "transportEndpointB")
184 String modelInvariantId = execution.getVariable("modelInvariantUuid")
185 String modelVersionId = execution.getVariable("modelUuid")
187 org.onap.aai.domain.yang.LogicalLink resource = new org.onap.aai.domain.yang.LogicalLink()
188 resource.setLinkId(logicalLinkId)
189 resource.setLinkName(epA)
190 resource.setLinkName2(epB)
191 resource.setModelInvariantId(modelInvariantId)
192 resource.setModelVersionId(modelVersionId)
194 AAIResourceUri logicalLinkUri = AAIUriFactory.createResourceUri(AAIObjectType.LOGICAL_LINK, logicalLinkId)
195 getAAIClient().create(logicalLinkUri, resource)
197 } catch (Exception ex) {
198 exceptionUtil.buildAndThrowWorkflowException(execution, 7000,
199 "Exception in createLogicalLinksForAllocatedResource" + ex.getMessage())
203 void preprocessSdncAllocateTnNssiRequest(DelegateExecution execution) {
204 def method = getClass().getSimpleName() + '.preProcessSDNCActivateRequest(' +
205 'execution=' + execution.getId() +
207 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
208 logger.trace('Entered ' + method)
210 logger.trace("STARTED preProcessSDNCActivateRequest Process")
212 String serviceInstanceId = execution.getVariable("sliceServiceInstanceId")
214 String createSDNCRequest = tnNssmfUtils.buildSDNCRequest(execution, serviceInstanceId, "create")
216 execution.setVariable("TNNSSMF_SDNCRequest", createSDNCRequest)
217 logger.debug("Outgoing SDNCRequest is: \n" + createSDNCRequest)
219 } catch (Exception e) {
220 logger.debug("Exception Occured Processing preProcessSDNCActivateRequest. Exception is:\n" + e)
221 exceptionUtil.buildAndThrowWorkflowException(execution, 1002,
222 "Error Occured during preProcessSDNCActivateRequest Method:\n" + e.getMessage())
224 logger.trace("COMPLETED preProcessSDNCActivateRequest Process")
228 void validateSDNCResponse(DelegateExecution execution, String response, String method) {
229 tnNssmfUtils.validateSDNCResponse(execution, response, method)