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.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
31 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
32 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
33 import org.onap.so.bpmn.common.scripts.ExceptionUtil
34 import org.onap.so.bpmn.core.json.JsonUtils
35 import org.slf4j.Logger
36 import org.slf4j.LoggerFactory
38 class DoCreateTnNssiInstance extends AbstractServiceTaskProcessor {
40 private static final Logger logger = LoggerFactory.getLogger(DoCreateTnNssiInstance.class);
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 sliceserviceInstanceId = 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)) //TODO: should be list
79 sliceProfile.setE2ELatency(Integer.parseInt(jsonUtil.getJsonValue(sliceProfileStr, "latency")))
80 sliceProfile.setMaxBandwidth(Integer.parseInt(jsonUtil.getJsonValue(sliceProfileStr, "maxBandwidth")))
83 sliceProfile.setReliability(new Object())
85 AAIResourcesClient client = getAAIClient()
86 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(sliceserviceInstanceId).sliceProfile(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(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(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(Types.SERVICE_INSTANCE.getFragment(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(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(execution.getVariable("sliceserviceInstanceId")).allottedResource(allottedResourceId))
147 execution.setVariable("allottedResourceUri", allottedResourceUri)
148 String modelInvariantId = execution.getVariable("modelInvariantUuid")
149 String modelVersionId = execution.getVariable("modelUuid")
151 org.onap.aai.domain.yang.AllottedResource resource = new org.onap.aai.domain.yang.AllottedResource()
152 resource.setId(allottedResourceId)
153 resource.setType("TsciNetwork")
154 resource.setAllottedResourceName("network_" + execution.getVariable("sliceServiceInstanceName"))
155 resource.setModelInvariantId(modelInvariantId)
156 resource.setModelVersionId(modelVersionId)
157 getAAIClient().create(allottedResourceUri, resource)
158 //AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceFromExistingURI(Types.SERVICE_INSTANCE, UriBuilder.fromPath(ssServiceuri).build())
159 //getAAIClient().connect(allottedResourceUri,ssServiceuri)
160 //execution.setVariable("aaiARPath", allottedResourceUri.build().toString());
162 String linkArrayStr = jsonUtil.getJsonValue(networkStr, "connectionLinks")
163 createLogicalLinksForAllocatedResource(execution, linkArrayStr, serviceInstanceId, allottedResourceId)
166 } catch (Exception ex) {
167 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Exception in createAaiAR " + ex.getMessage())
171 void createLogicalLinksForAllocatedResource(DelegateExecution execution,
172 String linkArrayStr, String serviceInstanceId,
173 String allottedResourceId) {
176 List<String> linkStrList = jsonUtil.StringArrayToList(linkArrayStr)
178 for (String linkStr : linkStrList) {
179 String logicalLinkId = UUID.randomUUID().toString()
180 String epA = jsonUtil.getJsonValue(linkStr, "transportEndpointA")
181 String epB = jsonUtil.getJsonValue(linkStr, "transportEndpointB")
182 String modelInvariantId = execution.getVariable("modelInvariantUuid")
183 String modelVersionId = execution.getVariable("modelUuid")
185 org.onap.aai.domain.yang.LogicalLink resource = new org.onap.aai.domain.yang.LogicalLink()
186 resource.setLinkId(logicalLinkId)
187 resource.setLinkName(epA)
188 resource.setLinkName2(epB)
189 resource.setModelInvariantId(modelInvariantId)
190 resource.setModelVersionId(modelVersionId)
192 AAIResourceUri logicalLinkUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().logicalLink(logicalLinkId))
193 getAAIClient().create(logicalLinkUri, resource)
195 } catch (Exception ex) {
196 exceptionUtil.buildAndThrowWorkflowException(execution, 7000,
197 "Exception in createLogicalLinksForAllocatedResource" + ex.getMessage())
201 void preprocessSdncAllocateTnNssiRequest(DelegateExecution execution) {
202 def method = getClass().getSimpleName() + '.preProcessSDNCActivateRequest(' +
203 'execution=' + execution.getId() +
205 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
206 logger.trace('Entered ' + method)
208 logger.trace("STARTED preProcessSDNCActivateRequest Process")
210 String serviceInstanceId = execution.getVariable("sliceServiceInstanceId")
212 String createSDNCRequest = tnNssmfUtils.buildSDNCRequest(execution, serviceInstanceId, "create")
214 execution.setVariable("TNNSSMF_SDNCRequest", createSDNCRequest)
215 logger.debug("Outgoing SDNCRequest is: \n" + createSDNCRequest)
217 } catch (Exception e) {
218 logger.debug("Exception Occured Processing preProcessSDNCActivateRequest. Exception is:\n" + e)
219 exceptionUtil.buildAndThrowWorkflowException(execution, 1002,
220 "Error Occured during preProcessSDNCActivateRequest Method:\n" + e.getMessage())
222 logger.trace("COMPLETED preProcessSDNCActivateRequest Process")
226 void validateSDNCResponse(DelegateExecution execution, String response, String method) {
227 tnNssmfUtils.validateSDNCResponse(execution, response, method)