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.camunda.bpm.engine.delegate.BpmnError
24 import org.camunda.bpm.engine.delegate.DelegateExecution
25 import org.onap.aai.domain.yang.AllottedResource
26 import org.onap.aai.domain.yang.ServiceInstance
27 import org.onap.aai.domain.yang.ServiceProfile;
28 import org.onap.aaiclient.client.aai.AAIResourcesClient
29 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
30 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
31 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
32 import org.onap.so.beans.nsmf.SliceTaskParamsAdapter
33 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
34 import org.onap.so.bpmn.common.scripts.ExceptionUtil
35 import org.onap.so.bpmn.core.RollbackData
36 import org.onap.so.bpmn.core.domain.ModelInfo
37 import org.onap.so.bpmn.core.domain.ServiceDecomposition
38 import org.onap.so.bpmn.core.json.JsonUtils
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 globalSubscriberId = execution.getVariable("globalSubscriberId")
104 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
106 Map<String, Object> serviceProfile = sliceParams.getServiceProfile()
107 String ssInstanceId = execution.getVariable("serviceInstanceId")
109 ServiceInstance ss = new ServiceInstance()
110 ss.setServiceInstanceId(ssInstanceId)
111 String sliceInstanceName = execution.getVariable("serviceInstanceName")
112 ss.setServiceInstanceName(sliceInstanceName)
113 ss.setServiceType(serviceProfile.get("sST"))
114 String serviceStatus = "deactivated"
115 ss.setOrchestrationStatus(serviceStatus)
116 String modelInvariantUuid = modelInfo.getModelInvariantUuid()
117 String modelUuid = modelInfo.getModelUuid()
118 ss.setModelInvariantId(modelInvariantUuid)
119 ss.setModelVersionId(modelUuid)
120 String serviceInstanceLocationid = serviceProfile.get("pLMNIdList")
121 ss.setServiceInstanceLocationId(serviceInstanceLocationid)
122 String snssai = serviceProfile.get("sNSSAI")
123 ss.setEnvironmentContext(snssai)
124 ss.setServiceRole(serviceRole)
126 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
127 .customer(globalSubscriberId)
128 .serviceSubscription(subscriptionServiceType)
129 .serviceInstance(ssInstanceId))
130 client.create(uri, ss)
131 } catch (BpmnError e) {
133 } catch (Exception ex) {
134 String msg = "Exception in DoCreateSliceServiceInstance.instantiateSliceService. " + ex.getMessage()
136 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
140 RollbackData rollbackData = execution.getVariable("RollbackData")
141 if (rollbackData == null) {
142 rollbackData = new RollbackData()
144 //rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
145 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
146 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", ssInstanceId)
147 rollbackData.put("SERVICEINSTANCE", "subscriptionServiceType", subscriptionServiceType)
148 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", globalSubscriberId)
149 execution.setVariable("rollbackData", rollbackData)
150 execution.setVariable("RollbackData", rollbackData)
151 logger.debug("RollbackData:" + rollbackData)
156 * create service profile in aai
159 void createServiceProfile(DelegateExecution execution) {
162 * todo: ServiceProfile params changed
164 String globalSubscriberId = execution.getVariable("globalSubscriberId")
165 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
166 SliceTaskParamsAdapter sliceParams =
167 execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter
168 Map<String, Object> serviceProfileMap = sliceParams.getServiceProfile()
170 String serviceProfileInstanceId = execution.getVariable("serviceInstanceId")
171 String serviceProfileId = UUID.randomUUID().toString()
172 sliceParams.serviceProfile.put("profileId", serviceProfileId)
174 ServiceProfile serviceProfile = new ServiceProfile()
175 serviceProfile.setProfileId(serviceProfileId)
176 serviceProfile.setLatency(Integer.parseInt(serviceProfileMap.get("latency").toString()))
177 serviceProfile.setMaxNumberOfUEs(Integer.parseInt(serviceProfileMap.get("maxNumberofUEs").toString()))
178 serviceProfile.setCoverageAreaTAList(serviceProfileMap.get("coverageAreaTAList").toString())
179 serviceProfile.setUeMobilityLevel(serviceProfileMap.get("uEMobilityLevel").toString())
180 serviceProfile.setResourceSharingLevel(serviceProfileMap.get("resourceSharingLevel").toString())
181 serviceProfile.setDlThptPerSlice(Integer.parseInt(serviceProfileMap.get("dLThptPerSlice").toString()))
182 serviceProfile.setDlThptPerUE(Integer.parseInt(serviceProfileMap.get("dLThptPerUE").toString()))
183 serviceProfile.setUlThptPerSlice(Integer.parseInt(serviceProfileMap.get("uLThptPerSlice").toString()))
184 serviceProfile.setUlThptPerUE(Integer.parseInt(serviceProfileMap.get("uLThptPerUE").toString()))
185 serviceProfile.setActivityFactor(Integer.parseInt(serviceProfileMap.get("activityFactor").toString()))
186 serviceProfile.setMaxNumberOfConns(Integer.parseInt(serviceProfileMap.get("maxNumberofConns").toString()))
188 serviceProfile.setJitter(Integer.parseInt(serviceProfileMap.get("jitter").toString()))
189 serviceProfile.setSurvivalTime("0")
190 serviceProfile.setReliability("")
192 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
193 .customer(globalSubscriberId)
194 .serviceSubscription(subscriptionServiceType)
195 .serviceInstance(serviceProfileInstanceId)
196 .serviceProfile(serviceProfileId))
197 client.create(uri, serviceProfile)
198 execution.setVariable("sliceTaskParams", sliceParams)
200 } catch (BpmnError e) {
202 } catch (Exception ex) {
203 String msg = "Exception in DoCreateSliceServiceInstance.instantiateSliceService. " + ex.getMessage()
205 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
210 * create allotted resource
214 public void createAllottedResource(DelegateExecution execution) {
217 String globalSubscriberId = execution.getVariable("globalSubscriberId")
218 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
219 ServiceDecomposition serviceDecomposition =
220 execution.getVariable("serviceProfileDecomposition") as ServiceDecomposition
221 String serviceInstanceId = execution.getVariable("serviceInstanceId")
223 List<org.onap.so.bpmn.core.domain.AllottedResource> allottedResourceList = serviceDecomposition.getAllottedResources()
224 for(org.onap.so.bpmn.core.domain.AllottedResource allottedResource : allottedResourceList) {
225 String allottedResourceId = UUID.randomUUID().toString()
227 AAIResourceUri allottedResourceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
228 .customer(globalSubscriberId)
229 .serviceSubscription(subscriptionServiceType)
230 .serviceInstance(serviceInstanceId)
231 .allottedResource(allottedResourceId))
233 execution.setVariable("allottedResourceUri", allottedResourceUri)
234 String arType = allottedResource.getAllottedResourceType()
235 String arRole = allottedResource.getAllottedResourceRole()
236 String modelInvariantId = allottedResource.getModelInfo().getModelInvariantUuid()
237 String modelVersionId = allottedResource.getModelInfo().getModelUuid()
239 AllottedResource resource = new AllottedResource()
240 resource.setId(allottedResourceId)
241 resource.setType(arType)
242 resource.setAllottedResourceName("Allotted_"+ execution.getVariable("serviceInstanceName"))
243 resource.setRole(arRole)
244 resource.setModelInvariantId(modelInvariantId)
245 resource.setModelVersionId(modelVersionId)
247 client.create(allottedResourceUri, resource)
249 execution.setVariable("allottedResourceId", allottedResourceId)
252 }catch (Exception ex) {
253 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Exception in createAaiAR " + ex.getMessage())