2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Telecom Italia
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 com.fasterxml.jackson.databind.ObjectMapper
24 import org.camunda.bpm.engine.delegate.DelegateExecution
25 import org.onap.aai.domain.yang.v19.AllottedResource
26 import org.onap.aai.domain.yang.v19.AllottedResources
27 import org.onap.aai.domain.yang.v19.ServiceInstance
28 import org.onap.aai.domain.yang.v19.SliceProfile
29 import org.onap.aai.domain.yang.v19.SliceProfiles
30 import org.onap.aaiclient.client.aai.AAIResourcesClient
31 import org.onap.aaiclient.client.aai.entities.AAIEdgeLabel
32 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
33 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
34 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
35 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
36 import org.onap.so.bpmn.common.scripts.ExceptionUtil
37 import org.onap.so.bpmn.common.scripts.MsoUtils
38 import org.onap.so.bpmn.common.scripts.RequestDBUtil
39 import org.onap.so.bpmn.core.json.JsonUtils
40 import org.slf4j.Logger
41 import org.slf4j.LoggerFactory
43 import static org.apache.commons.lang3.StringUtils.isAllLowerCase
44 import static org.apache.commons.lang3.StringUtils.isBlank
46 class DoModifyCoreNSSI extends DoCommonCoreNSSI {
48 private final String PREFIX ="DoModifyCoreNSSI"
49 private final String ACTION = "Modify"
51 private ExceptionUtil exceptionUtil = new ExceptionUtil()
52 private RequestDBUtil requestDBUtil = new RequestDBUtil()
53 private MsoUtils utils = new MsoUtils()
54 private JsonUtils jsonUtil = new JsonUtils()
56 private static final Logger LOGGER = LoggerFactory.getLogger( DoModifyCoreNSSI.class)
60 * Prepares Slice Profile
62 * @return SLice Profile
64 SliceProfile prepareSliceProfile(DelegateExecution execution) {
65 def currentNSSI = execution.getVariable("currentNSSI")
67 String sliceProfileID = currentNSSI['sliceProfileId']
68 Map<String,Object> sliceProfileMap = new ObjectMapper().readValue(currentNSSI['sliceProfile'], Map.class)
70 SliceProfile sliceProfile = new SliceProfile()
71 sliceProfile.setServiceAreaDimension("")
72 sliceProfile.setPayloadSize(0)
73 sliceProfile.setJitter(0)
74 sliceProfile.setSurvivalTime(0)
75 sliceProfile.setExpDataRate(0)
76 sliceProfile.setTrafficDensity(0)
77 sliceProfile.setConnDensity(0)
78 sliceProfile.setSNssai(currentNSSI['S-NSSAI'])
80 if(!isBlank(sliceProfileMap.get("expDataRateUL"))) {
81 sliceProfile.setExpDataRateUL(Integer.parseInt(sliceProfileMap.get("expDataRateUL").toString()))
84 if(!isBlank(sliceProfileMap.get("expDataRateDL"))) {
85 sliceProfile.setExpDataRateDL(Integer.parseInt(sliceProfileMap.get("expDataRateDL").toString()))
88 if(!isBlank(sliceProfileMap.get("activityFactor"))) {
89 sliceProfile.setActivityFactor(Integer.parseInt(sliceProfileMap.get("activityFactor").toString()))
92 if(!isBlank(sliceProfileMap.get("resourceSharingLevel"))) {
93 sliceProfile.setResourceSharingLevel(sliceProfileMap.get("resourceSharingLevel").toString())
96 if(!isBlank(sliceProfileMap.get("uEMobilityLevel"))) {
97 sliceProfile.setUeMobilityLevel(sliceProfileMap.get("uEMobilityLevel").toString())
100 if(!isBlank(sliceProfileMap.get("coverageAreaTAList"))) {
101 sliceProfile.setCoverageAreaTAList(sliceProfileMap.get("coverageAreaTAList").toString())
104 if(!isBlank(sliceProfileMap.get("maxNumberofUEs"))) {
105 sliceProfile.setMaxNumberOfUEs(Integer.parseInt(sliceProfileMap.get("maxNumberofUEs").toString()))
108 if(!isBlank(sliceProfileMap.get("latency"))) {
109 sliceProfile.setLatency(Integer.parseInt(sliceProfileMap.get("latency").toString()))
112 sliceProfile.setProfileId(sliceProfileID)
113 sliceProfile.setE2ELatency(0)
120 * Prepares Slice Profile Instance
122 * @return Slice Profile Instance
124 ServiceInstance prepareSliceProfileInstance(DelegateExecution execution) {
126 def currentNSSI = execution.getVariable("currentNSSI")
128 ServiceInstance sliceProfileInstance = new ServiceInstance()
129 String sliceProfileInstanceId = UUID.randomUUID().toString()
130 sliceProfileInstance.setServiceInstanceId(sliceProfileInstanceId)
133 String sliceInstanceName = "sliceprofile_" + sliceProfileInstanceId
134 sliceProfileInstance.setServiceInstanceName(sliceInstanceName)
136 String serviceType = jsonUtil.getJsonValue(currentNSSI['sliceProfile'], "sST")
137 sliceProfileInstance.setServiceType(serviceType)
139 String serviceStatus = "deactivated"
140 sliceProfileInstance.setOrchestrationStatus(serviceStatus)
142 String serviceInstanceLocationid = jsonUtil.getJsonValue(currentNSSI['sliceProfile'], "plmnIdList")
143 sliceProfileInstance.setServiceInstanceLocationId(serviceInstanceLocationid)
145 String serviceRole = "slice-profile-instance"
146 sliceProfileInstance.setServiceRole(serviceRole)
147 List<String> snssaiList = (List<String>)currentNSSI['S-NSSAIs']
148 String snssai = snssaiList.get(0)
150 sliceProfileInstance.setEnvironmentContext(snssai)
151 sliceProfileInstance.setWorkloadContext("CN-NF")
155 return sliceProfileInstance
161 * Creates Slice Profile Instance
164 void createSliceProfileInstance(DelegateExecution execution) {
165 LOGGER.trace("${PREFIX} Start createSliceProfileInstance")
167 def currentNSSI = execution.getVariable("currentNSSI")
169 String globalSubscriberId = execution.getVariable("globalSubscriberId")
170 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
172 SliceProfile sliceProfile = prepareSliceProfile(execution)
174 ServiceInstance sliceProfileInstance = prepareSliceProfileInstance(execution)
176 SliceProfiles sliceProfiles = new SliceProfiles()
177 sliceProfiles.getSliceProfile().add(sliceProfile)
178 sliceProfileInstance.setSliceProfiles(sliceProfiles)
181 AAIResourcesClient client = getAAIClient()
182 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).
183 serviceInstance(sliceProfileInstance.getServiceInstanceId()))
184 client.create(uri, sliceProfileInstance)
186 currentNSSI['createdSliceProfileInstanceId'] = sliceProfileInstance.getServiceInstanceId()
187 } catch (Exception ex) {
188 exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occurred while Slice Profile create call:" + ex.getMessage())
191 LOGGER.trace("${PREFIX} Exit createSliceProfileInstance")
196 * Creates Allotted Resource
198 * @return AllottedResource
200 AllottedResource createAllottedResource(DelegateExecution execution) {
201 def currentNSSI = execution.getVariable("currentNSSI")
203 String globalSubscriberId = execution.getVariable("globalSubscriberId")
204 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
205 String sliceProfileInstanceId = currentNSSI['createdSliceProfileInstanceId']
207 AllottedResource allottedResource = new AllottedResource()
209 String allottedResourceId = UUID.randomUUID().toString()
211 allottedResource.setId(allottedResourceId)
213 // TO DO: No other info
216 AAIResourcesClient client = getAAIClient()
217 AAIResourceUri allottedResourceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(sliceProfileInstanceId).allottedResource(allottedResourceId))
219 client.create(allottedResourceUri, allottedResource)
221 currentNSSI['allottedResourceUri'] = allottedResourceUri
222 } catch (Exception ex) {
223 exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occurred while Allotted Resource create call:" + ex.getMessage())
226 return allottedResource
232 * Creates Slice Profile association with NSSI
235 void associateSliceProfileInstanceWithNSSI(DelegateExecution execution) {
236 LOGGER.trace("${PREFIX} Start associateSliceProfileInstanceWithNSSI")
238 def currentNSSI = execution.getVariable("currentNSSI")
240 String nssiId = currentNSSI['nssiId']
242 String sliceProfileInstanceId = currentNSSI['createdSliceProfileInstanceId']
244 AAIResourcesClient client = getAAIClient()
246 // Creates Allotted Resource
247 AllottedResource allottedResource = createAllottedResource(execution)
248 AAIResourceUri allottedResourceUri = (AAIResourceUri)currentNSSI['allottedResourceUri']
250 // Updates Slice Profile Instance with Allotted Resource
252 AAIResourceUri sliceProfileInstanceUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(sliceProfileInstanceId))
253 Optional<ServiceInstance> sliceProfileInstanceOpt = client.get(ServiceInstance.class, sliceProfileInstanceUri)
254 if (sliceProfileInstanceOpt.isPresent()) {
255 ServiceInstance sliceProfileInstance = sliceProfileInstanceOpt.get()
257 AllottedResources allottedResources = sliceProfileInstance.getAllottedResources()
258 if(allottedResources == null) {
259 allottedResources = new AllottedResources()
262 allottedResources.getAllottedResource().add(allottedResource)
263 sliceProfileInstance.setAllottedResources(allottedResources)
265 client.update(sliceProfileInstanceUri, sliceProfileInstance)
268 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No slice profile instance found with id = " + sliceProfileInstanceId)
271 } catch(Exception e){
272 exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile Instance update call: " + e.getMessage())
276 // Associates NSSI with Allotted Resource
278 AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
279 client.connect(nssiUri, allottedResourceUri, AAIEdgeLabel.USES)
280 } catch(Exception e){
281 exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while NSSI with Allotted Resource connect call: " + e.getMessage())
284 LOGGER.trace("${PREFIX} Exit associateSliceProfileInstanceWithNSSI")