2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 # Copyright (c) 2019, 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
22 import org.camunda.bpm.engine.delegate.BpmnError
23 import org.camunda.bpm.engine.delegate.DelegateExecution
24 import org.onap.aai.domain.yang.AllottedResource
25 import org.onap.aai.domain.yang.AllottedResources
26 import org.onap.aai.domain.yang.Relationship
27 import org.onap.aai.domain.yang.ServiceInstance
28 import org.onap.aai.domain.yang.SliceProfiles
29 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
30 import org.onap.so.bpmn.common.scripts.ExceptionUtil
31 import org.onap.so.client.aai.AAIObjectType
32 import org.onap.so.client.aai.AAIResourcesClient
33 import org.onap.so.client.aai.entities.AAIResultWrapper
34 import org.onap.so.client.aai.entities.uri.AAIResourceUri
35 import org.onap.so.client.aai.entities.uri.AAIUriFactory
36 import org.slf4j.Logger
37 import org.slf4j.LoggerFactory
39 import javax.ws.rs.NotFoundException
41 import static org.apache.commons.lang3.StringUtils.isBlank
44 * This groovy class supports the <class>DoDeleteSliceService.bpmn</class> process.
47 * @param - msoRequestId
48 * @param - globalSubscriberId - O
49 * @param - subscriptionServiceType - O
50 * @param - serviceInstanceId
53 class DoDeleteSliceService extends AbstractServiceTaskProcessor {
54 private final String PREFIX ="DoDeleteSliceService"
55 ExceptionUtil exceptionUtil = new ExceptionUtil()
56 private static final Logger LOGGER = LoggerFactory.getLogger( DoDeleteSliceService.class)
59 void preProcessRequest(DelegateExecution execution) {
60 LOGGER.debug(" *****${PREFIX} preProcessRequest *****")
64 //String requestId = execution.getVariable("msoRequestId")
65 execution.setVariable("prefix",PREFIX)
68 //requestDetails.subscriberInfo. for AAI GET & PUT
69 execution.getVariable("globalSubscriberId") ?: execution.setVariable("globalSubscriberId", "")
71 //requestDetails.requestParameters. for AAI PUT
72 execution.getVariable("serviceType") ?: execution.setVariable("serviceType", "")
74 //Generated in parent for AAI PUT
75 String serviceInstanceId = execution.getVariable("serviceInstanceId")
76 if (isBlank(serviceInstanceId)){
77 msg = "Input serviceInstanceId is null"
79 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
81 } catch (BpmnError e) {
83 } catch (Exception ex){
84 msg = "Exception in preProcessRequest " + ex.getMessage()
86 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
88 LOGGER.debug("*****${PREFIX} Exit preProcessRequest *****")
92 * query E2ESliceService from AAI
96 void queryE2ESliceSeriveFromAAI(DelegateExecution execution)
98 LOGGER.trace(" *****${PREFIX} Start queryE2ESliceSeriveFromAAI *****")
99 String serviceInstanceId = execution.getVariable("serviceInstanceId")
101 String errorMsg = "query e2e slice service from aai failed"
102 AAIResultWrapper wrapper = queryAAI(execution, AAIObjectType.SERVICE_INSTANCE, serviceInstanceId, errorMsg)
103 Optional<ServiceInstance> si =wrapper.asBean(ServiceInstance.class)
106 String snssai = si.get()?.getEnvironmentContext()
107 execution.setVariable("snssai", snssai ?: "")
108 LOGGER.info("serviceInstanceId: ${serviceInstanceId}, snssai: ${snssai}")
110 LOGGER.trace(" *****${PREFIX} Exit queryE2ESliceSeriveFromAAI *****")
114 * get allotted resource from AAI
118 void getAllottedResFromAAI(DelegateExecution execution)
120 LOGGER.trace(" *****${PREFIX} Start getAllottedResFromAAI *****")
121 String serviceInstanceId = execution.getVariable("serviceInstanceId")
124 String errorMsg = "query allotted resource from aai failed."
125 AAIResultWrapper wrapper = queryAAI(execution, AAIObjectType.ALLOTTED_RESOURCE_ALL, serviceInstanceId, errorMsg)
126 Optional<AllottedResources> ars = wrapper?.asBean(AllottedResources.class)
127 if(ars.isPresent() && ars.get().getAllottedResource())
129 List<AllottedResource> allottedResourceList = ars.get().getAllottedResource()
130 AllottedResource ar = allottedResourceList.first()
131 String relatedLink = ar?.getRelationshipList()?.getRelationship()?.first()?.getRelatedLink()
132 String nsiId = relatedLink ? relatedLink.substring(relatedLink.lastIndexOf("/") + 1,relatedLink.length()) : ""
133 execution.setVariable("nsiId", nsiId)
134 LOGGER.info("serviceInstanceId: ${serviceInstanceId}, nsiId:${nsiId}")
140 catch (Exception ex){
141 String msg = "Exception in getAllottedResFromAAI " + ex.getMessage()
143 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
145 LOGGER.trace(" *****${PREFIX} Exit getAllottedResFromAAI *****")
149 * get nsi service instance from aai
153 void getNSIFromAAI(DelegateExecution execution)
155 LOGGER.trace(" *****${PREFIX} Start getNSIFromAAI *****")
156 String nsiId = execution.getVariable("nsiId")
159 String errorMsg = "query nsi from aai failed."
160 AAIResultWrapper wrapper = queryAAI(execution, AAIObjectType.SERVICE_INSTANCE, nsiId, errorMsg)
161 Optional<ServiceInstance> si =wrapper.asBean(ServiceInstance.class)
162 List<String> nssiIdList = []
163 String msg = "nsiId:${nsiId},nssiIdList:"
166 List<Relationship> relationshipList = si.get().getRelationshipList()?.getRelationship()
167 for (Relationship relationship : relationshipList)
169 String relatedTo = relationship.getRelatedTo()
170 if (relatedTo == "service-instance")
172 String relatedLink = relationship.getRelatedLink()?:""
173 String nssiId = relatedLink ? relatedLink.substring(relatedLink.lastIndexOf("/") + 1,relatedLink.length()) : ""
174 nssiIdList.add(nssiId)
180 execution.setVariable("nssiIdList", nssiIdList)
185 catch (Exception ex){
186 String msg = "Exception in getNSIFromAAI " + ex.getMessage()
188 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
190 LOGGER.trace(" *****${PREFIX} Exit getNSIFromAAI *****")
194 * get nssi service from AAI
198 void getNSSIListFromAAI(DelegateExecution execution)
200 LOGGER.trace("*****${PREFIX} Start getNSSIListFromAAI *****")
201 List<String> nssiIdList = execution.getVariable("nssiIdList")
202 List<ServiceInstance> nssiInstanceList = []
203 String errorMsg = "query nssi list from aai failed"
204 for(String nssiId : nssiIdList)
206 AAIResultWrapper wrapper = queryAAI(execution, AAIObjectType.SERVICE_INSTANCE, nssiId, errorMsg)
207 Optional<ServiceInstance> si =wrapper.asBean(ServiceInstance.class)
210 nssiInstanceList.add(si.get())
213 int size = nssiInstanceList.size()
214 int proportion = size >0 ?((90/size) as int) : 90
215 execution.setVariable("nssiInstanceList", nssiInstanceList)
216 execution.setVariable("currentNSSIIndex", 0)
217 execution.setVariable("proportion", proportion)
218 String msg ="nssiInstanceList size: ${nssiInstanceList.size()}, proportion:${proportion}"
220 LOGGER.trace(" *****${PREFIX} Exit getNSSIListFromAAI *****")
227 void getCurrentNSSI(DelegateExecution execution)
229 LOGGER.trace(" *****${PREFIX} Start getCurrentNSSI *****")
230 List<ServiceInstance> nssiInstanceList = execution.getVariable("nssiInstanceList")
231 int currentIndex = execution.getVariable("currentNSSIIndex") as int
232 ServiceInstance nssi = nssiInstanceList?.get(currentIndex)
233 def currentNSSI = [:]
234 currentNSSI['nssiServiceInstanceId'] = nssi?.getServiceInstanceId()
235 currentNSSI['modelInvariantId'] = nssi?.getModelInvariantId()
236 currentNSSI['modelVersionId'] = nssi?.getModelVersionId()
237 currentNSSI['snssai'] = execution.getVariable("snssai") ?: ""
238 currentNSSI['nsiServiceInstanceId'] = execution.getVariable("nsiId") ?: ""
239 currentNSSI['operationId'] = execution.getVariable("operationId") ?: ""
240 currentNSSI['e2eServiceInstanceId'] = execution.getVariable("serviceInstanceId") ?: ""
241 currentNSSI['msoRequestId'] = execution.getVariable("msoRequestId") ?: ""
242 currentNSSI['globalSubscriberId'] = execution.getVariable("globalSubscriberId") ?: ""
243 currentNSSI['serviceType'] = execution.getVariable("serviceType") ?: ""
244 currentNSSI['serviceModelInfo'] = execution.getVariable("serviceModelInfo") ?: ""
245 currentNSSI['proportion'] = (execution.getVariable("proportion") as int)*(currentIndex+1)
246 execution.setVariable("currentNSSI", currentNSSI)
247 String msg = "Now we deal with nssiServiceInstanceId: ${currentNSSI['nssiServiceInstanceId']}, current Index: ${currentIndex}, current proportion:${currentNSSI['proportion']}"
249 LOGGER.trace(" *****${PREFIX} Exit getCurrentNSSI *****")
256 void parseNextNSSI(DelegateExecution execution)
258 LOGGER.trace(" *****${PREFIX} Start parseNextNSSI *****")
259 if(execution.getVariable("WorkflowException") != null){
260 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "current job failure!")
262 def currentIndex = execution.getVariable("currentNSSIIndex")
263 List<ServiceInstance> nssiInstanceList = execution.getVariable("nssiInstanceList")
264 def nextIndex = ++currentIndex
265 LOGGER.info("nextIndex: ${nextIndex}")
266 if(nextIndex >= nssiInstanceList.size()){
267 execution.setVariable("isAllNSSIFinished", "true")
269 execution.setVariable("isAllNSSIFinished", "false")
270 execution.setVariable("currentNSSIIndex", nextIndex)
272 LOGGER.trace(" *****${PREFIX} Exit parseNextNSSI *****")
277 * query sliceProfile from AAI
281 void querySliceProfileFromAAI(DelegateExecution execution)
283 LOGGER.trace(" *****${PREFIX} Start querySliceProfileFromAAI *****")
284 def currentNSSI = execution.getVariable("currentNSSI")
285 String nssiId = currentNSSI['nssiServiceInstanceId']
286 String errorMsg = "query slice profile failed"
287 AAIResultWrapper wrapper = queryAAI(execution, AAIObjectType.SLICE_PROFILE_ALL, nssiId, errorMsg)
288 Optional<SliceProfiles> sliceProfiles =wrapper.asBean(SliceProfiles.class)
289 if(sliceProfiles.isPresent())
291 String profileId = sliceProfiles.get().getSliceProfile()?.get(0)?.getProfileId()
292 currentNSSI['profileId'] = profileId ?: ""
293 LOGGER.info("nssiId: ${nssiId}, profileId: ${profileId}")
295 execution.setVariable("currentNSSI", currentNSSI)
296 LOGGER.trace(" *****${PREFIX} Exit querySliceProfileFromAAI *****")
302 * @param aaiObjectType
304 * @return AAIResultWrapper
306 private AAIResultWrapper queryAAI(DelegateExecution execution, AAIObjectType aaiObjectType, String instanceId, String errorMsg)
308 LOGGER.trace(" *****${PREFIX} Start queryAAI *****")
309 String globalSubscriberId = execution.getVariable("globalSubscriberId")
310 String serviceType = execution.getVariable("serviceType")
312 AAIResourcesClient resourceClient = new AAIResourcesClient()
313 AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(aaiObjectType, globalSubscriberId, serviceType, instanceId)
314 if (!resourceClient.exists(resourceUri)) {
315 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMsg)
317 AAIResultWrapper wrapper = resourceClient.get(resourceUri, NotFoundException.class)
318 LOGGER.trace(" *****${PREFIX} Exit queryAAI *****")