2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 # Copyright (c) 2020, CMCC Technologies Co., Ltd.
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=========================================================
20 package org.onap.so.bpmn.infrastructure.scripts
23 import org.onap.aai.domain.yang.AllottedResource
24 import org.onap.aai.domain.yang.ServiceInstance
25 import org.onap.so.beans.nsmf.SliceTaskParamsAdapter
26 import org.camunda.bpm.engine.delegate.BpmnError
27 import org.camunda.bpm.engine.delegate.DelegateExecution
28 import org.onap.aai.domain.yang.ServiceProfile
29 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
30 import org.onap.so.bpmn.common.scripts.ExceptionUtil
31 import org.onap.so.bpmn.core.RollbackData
32 import org.onap.so.bpmn.core.domain.ModelInfo
33 import org.onap.so.bpmn.core.domain.ServiceDecomposition
34 import org.onap.so.bpmn.core.json.JsonUtils
35 import org.onap.aaiclient.client.aai.AAIObjectType
36 import org.onap.aaiclient.client.aai.AAIResourcesClient
37 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
38 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
39 import org.slf4j.Logger
40 import org.slf4j.LoggerFactory
44 class DoCreateSliceServiceInstance extends AbstractServiceTaskProcessor{
46 private static final Logger logger = LoggerFactory.getLogger( DoCreateSliceServiceInstance.class)
48 JsonUtils jsonUtil = new JsonUtils()
50 ExceptionUtil exceptionUtil = new ExceptionUtil()
52 AAIResourcesClient client = getAAIClient()
54 * Pre Process the BPMN Flow Request
56 * generate the nsOperationKey
57 * generate the nsParameters
59 void preProcessRequest (DelegateExecution execution) {
60 logger.trace("Enter preProcessRequest()")
61 //here modelVersion is not set, we use modelUuid to decompose the service.
62 def isDebugLogEnabled = true
63 execution.setVariable("isDebugLogEnabled", isDebugLogEnabled)
65 logger.trace("Exit preProcessRequest")
69 * prepare decompose service profile instance template
72 public void prepareDecomposeService(DelegateExecution execution) {
74 String uuiRequest = execution.getVariable("uuiRequest")
75 String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceInvariantUuid")
76 String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceUuid")
77 String serviceModelInfo = """{
78 "modelInvariantUuid":"${modelInvariantUuid}",
79 "modelUuid":"${modelUuid}",
82 execution.setVariable("serviceModelInfo", serviceModelInfo)
86 * create service-profile instance in aai
89 void createServiceProfileInstance(DelegateExecution execution) {
91 SliceTaskParamsAdapter sliceParams =
92 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
94 ServiceDecomposition serviceDecomposition =
95 execution.getVariable("serviceProfileDecomposition") as ServiceDecomposition
96 ModelInfo modelInfo = serviceDecomposition.getModelInfo()
97 //String serviceRole = "e2eslice-service"
99 * todo: ServiceProfile params changed
102 String serviceRole = "service-profile"
103 String serviceType = execution.getVariable("serviceType")
104 Map<String, Object> serviceProfile = sliceParams.getServiceProfile()
105 String ssInstanceId = execution.getVariable("serviceInstanceId")
107 ServiceInstance ss = new ServiceInstance()
108 ss.setServiceInstanceId(ssInstanceId)
109 String sliceInstanceName = execution.getVariable("serviceInstanceName")
110 ss.setServiceInstanceName(sliceInstanceName)
111 ss.setServiceType(serviceType)
112 String serviceStatus = "deactivated"
113 ss.setOrchestrationStatus(serviceStatus)
114 String modelInvariantUuid = modelInfo.getModelInvariantUuid()
115 String modelUuid = modelInfo.getModelUuid()
116 ss.setModelInvariantId(modelInvariantUuid)
117 ss.setModelVersionId(modelUuid)
118 String serviceInstanceLocationid = serviceProfile.get("plmnIdList")
119 ss.setServiceInstanceLocationId(serviceInstanceLocationid)
120 String snssai = serviceProfile.get("sNSSAI")
121 ss.setEnvironmentContext(snssai)
122 ss.setServiceRole(serviceRole)
124 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
125 execution.getVariable("globalSubscriberId"),
126 execution.getVariable("subscriptionServiceType"),
128 client.create(uri, ss)
129 } catch (BpmnError e) {
131 } catch (Exception ex) {
132 String msg = "Exception in DoCreateSliceServiceInstance.instantiateSliceService. " + ex.getMessage()
134 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
138 def rollbackData = execution.getVariable("RollbackData")
139 if (rollbackData == null) {
140 rollbackData = new RollbackData()
142 //rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
143 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
144 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", ssInstanceId)
145 rollbackData.put("SERVICEINSTANCE", "subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
146 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
147 execution.setVariable("rollbackData", rollbackData)
148 execution.setVariable("RollbackData", rollbackData)
149 logger.debug("RollbackData:" + rollbackData)
154 * create service profile in aai
157 void createServiceProfile(DelegateExecution execution) {
160 * todo: ServiceProfile params changed
162 SliceTaskParamsAdapter sliceParams =
163 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
164 Map<String, Object> serviceProfileMap = sliceParams.getServiceProfile()
166 String serviceProfileInstanceId = execution.getVariable("serviceInstanceId")
167 String serviceProfileId = UUID.randomUUID().toString()
168 sliceParams.serviceProfile.put("profileId", serviceProfileId)
170 ServiceProfile serviceProfile = new ServiceProfile()
171 serviceProfile.setProfileId(serviceProfileId)
172 serviceProfile.setLatency(Integer.parseInt(serviceProfileMap.get("latency").toString()))
173 serviceProfile.setMaxNumberOfUEs(Integer.parseInt(serviceProfileMap.get("maxNumberofUEs").toString()))
174 serviceProfile.setCoverageAreaTAList(serviceProfileMap.get("coverageAreaTAList").toString())
175 serviceProfile.setUeMobilityLevel(serviceProfileMap.get("uEMobilityLevel").toString())
176 serviceProfile.setResourceSharingLevel(serviceProfileMap.get("resourceSharingLevel").toString())
177 serviceProfile.setExpDataRateUL(Integer.parseInt(serviceProfileMap.get("expDataRateUL").toString()))
178 serviceProfile.setExpDataRateDL(Integer.parseInt(serviceProfileMap.get("expDataRateDL").toString()))
179 serviceProfile.setAreaTrafficCapUL(Integer.parseInt(serviceProfileMap.get("areaTrafficCapUL").toString()))
180 serviceProfile.setAreaTrafficCapDL(Integer.parseInt(serviceProfileMap.get("areaTrafficCapDL").toString()))
181 serviceProfile.setActivityFactor(Integer.parseInt(serviceProfileMap.get("activityFactor").toString()))
183 serviceProfile.setJitter(0)
184 serviceProfile.setSurvivalTime("0")
185 serviceProfile.setCsAvailability(new Object())
186 serviceProfile.setReliability("")
187 serviceProfile.setExpDataRate(0)
188 serviceProfile.setTrafficDensity(0)
189 serviceProfile.setConnDensity(0)
191 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_PROFILE,
192 execution.getVariable("globalSubscriberId"),
193 execution.getVariable("subscriptionServiceType"),
194 serviceProfileInstanceId,
196 client.create(uri, serviceProfile)
197 execution.setVariable("sliceTaskParams", sliceParams)
199 } catch (BpmnError e) {
201 } catch (Exception ex) {
202 String msg = "Exception in DoCreateSliceServiceInstance.instantiateSliceService. " + ex.getMessage()
204 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
209 * create allotted resource
213 public void createAllottedResource(DelegateExecution execution) {
217 ServiceDecomposition serviceDecomposition =
218 execution.getVariable("serviceProfileDecomposition") as ServiceDecomposition
220 List<org.onap.so.bpmn.core.domain.AllottedResource> allottedResourceList = serviceDecomposition.getAllottedResources()
221 for(org.onap.so.bpmn.core.domain.AllottedResource allottedResource : allottedResourceList) {
222 String allottedResourceId = UUID.randomUUID().toString()
224 AAIResourceUri allottedResourceUri = AAIUriFactory.createResourceUri(AAIObjectType.ALLOTTED_RESOURCE,
225 execution.getVariable("globalSubscriberId"),
226 execution.getVariable("subscriptionServiceType"),
227 execution.getVariable("serviceInstanceId"),
230 execution.setVariable("allottedResourceUri", allottedResourceUri)
231 String arType = allottedResource.getAllottedResourceType()
232 String arRole = allottedResource.getAllottedResourceRole()
233 String modelInvariantId = allottedResource.getModelInfo().getModelInvariantUuid()
234 String modelVersionId = allottedResource.getModelInfo().getModelUuid()
236 AllottedResource resource = new AllottedResource()
237 resource.setId(allottedResourceId)
238 resource.setType(arType)
239 resource.setAllottedResourceName("Allotted_"+ execution.getVariable("serviceInstanceName"))
240 resource.setRole(arRole)
241 resource.setModelInvariantId(modelInvariantId)
242 resource.setModelVersionId(modelVersionId)
244 client.create(allottedResourceUri, resource)
248 }catch (Exception ex) {
249 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Exception in createAaiAR " + ex.getMessage())