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.aaiclient.client.aai.AAIObjectType
32 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
33 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
34 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
35 import org.slf4j.Logger
36 import org.slf4j.LoggerFactory
38 import javax.ws.rs.NotFoundException
40 import static org.apache.commons.lang3.StringUtils.isBlank
43 * This groovy class supports the <class>DoDeleteSliceService.bpmn</class> process.
46 * @param - msoRequestId
47 * @param - globalSubscriberId - O
48 * @param - subscriptionServiceType - O
49 * @param - serviceInstanceId
52 class DoDeleteSliceService extends AbstractServiceTaskProcessor {
53 private final String PREFIX ="DoDeleteSliceService"
54 ExceptionUtil exceptionUtil = new ExceptionUtil()
55 private static final Logger LOGGER = LoggerFactory.getLogger( DoDeleteSliceService.class)
58 void preProcessRequest(DelegateExecution execution) {
59 LOGGER.debug(" *****${PREFIX} preProcessRequest *****")
63 //String requestId = execution.getVariable("msoRequestId")
64 execution.setVariable("prefix",PREFIX)
67 //requestDetails.subscriberInfo. for AAI GET & PUT
68 execution.getVariable("globalSubscriberId") ?: execution.setVariable("globalSubscriberId", "")
70 //requestDetails.requestParameters. for AAI PUT
71 execution.getVariable("serviceType") ?: execution.setVariable("serviceType", "")
73 //Generated in parent for AAI PUT
74 String serviceInstanceId = execution.getVariable("serviceInstanceId")
75 if (isBlank(serviceInstanceId)){
76 msg = "Input serviceInstanceId is null"
78 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
80 } catch (BpmnError e) {
82 } catch (Exception ex){
83 msg = "Exception in preProcessRequest " + ex.getMessage()
85 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
87 LOGGER.debug("*****${PREFIX} Exit preProcessRequest *****")
91 * query E2ESliceService from AAI
95 void queryE2ESliceSeriveFromAAI(DelegateExecution execution)
97 LOGGER.trace(" *****${PREFIX} Start queryE2ESliceSeriveFromAAI *****")
98 String serviceInstanceId = execution.getVariable("serviceInstanceId")
100 String errorMsg = "query e2e slice service from aai failed"
101 AAIResultWrapper wrapper = queryAAI(execution, AAIObjectType.SERVICE_INSTANCE, serviceInstanceId, errorMsg)
102 Optional<ServiceInstance> si =wrapper.asBean(ServiceInstance.class)
105 String snssai = si.get()?.getEnvironmentContext()
106 execution.setVariable("snssai", snssai ?: "")
107 LOGGER.info("serviceInstanceId: ${serviceInstanceId}, snssai: ${snssai}")
109 LOGGER.trace(" *****${PREFIX} Exit queryE2ESliceSeriveFromAAI *****")
113 * get allotted resource from AAI
117 void getAllottedResFromAAI(DelegateExecution execution)
119 LOGGER.trace(" *****${PREFIX} Start getAllottedResFromAAI *****")
120 String serviceInstanceId = execution.getVariable("serviceInstanceId")
123 String errorMsg = "query allotted resource from aai failed."
124 AAIResultWrapper wrapper = queryAAI(execution, AAIObjectType.ALLOTTED_RESOURCE_ALL, serviceInstanceId, errorMsg)
125 Optional<AllottedResources> ars = wrapper?.asBean(AllottedResources.class)
126 if(ars.isPresent() && ars.get().getAllottedResource())
128 List<AllottedResource> allottedResourceList = ars.get().getAllottedResource()
129 AllottedResource ar = allottedResourceList.first()
130 String relatedLink = ar?.getRelationshipList()?.getRelationship()?.first()?.getRelatedLink()
131 String nsiId = relatedLink ? relatedLink.substring(relatedLink.lastIndexOf("/") + 1,relatedLink.length()) : ""
132 execution.setVariable("nsiId", nsiId)
133 LOGGER.info("serviceInstanceId: ${serviceInstanceId}, nsiId:${nsiId}")
139 catch (Exception ex){
140 String msg = "Exception in getAllottedResFromAAI " + ex.getMessage()
142 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
144 LOGGER.trace(" *****${PREFIX} Exit getAllottedResFromAAI *****")
148 * get nsi service instance from aai
152 void getNSIFromAAI(DelegateExecution execution)
154 LOGGER.trace(" *****${PREFIX} Start getNSIFromAAI *****")
155 String nsiId = execution.getVariable("nsiId")
158 String errorMsg = "query nsi from aai failed."
159 AAIResultWrapper wrapper = queryAAI(execution, AAIObjectType.SERVICE_INSTANCE, nsiId, errorMsg)
160 Optional<ServiceInstance> si =wrapper.asBean(ServiceInstance.class)
161 List<String> nssiIdList = []
162 String msg = "nsiId:${nsiId},nssiIdList:"
165 List<Relationship> relationshipList = si.get().getRelationshipList()?.getRelationship()
166 for (Relationship relationship : relationshipList)
168 String relatedTo = relationship.getRelatedTo()
169 if (relatedTo == "service-instance")
171 String relatedLink = relationship.getRelatedLink()?:""
172 String nssiId = relatedLink ? relatedLink.substring(relatedLink.lastIndexOf("/") + 1,relatedLink.length()) : ""
173 nssiIdList.add(nssiId)
179 execution.setVariable("nssiIdList", nssiIdList)
184 catch (Exception ex){
185 String msg = "Exception in getNSIFromAAI " + ex.getMessage()
187 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
189 LOGGER.trace(" *****${PREFIX} Exit getNSIFromAAI *****")
193 * get nssi service from AAI
197 void getNSSIListFromAAI(DelegateExecution execution)
199 LOGGER.trace("*****${PREFIX} Start getNSSIListFromAAI *****")
200 List<String> nssiIdList = execution.getVariable("nssiIdList")
201 List<ServiceInstance> nssiInstanceList = []
202 String errorMsg = "query nssi list from aai failed"
203 for(String nssiId : nssiIdList)
205 AAIResultWrapper wrapper = queryAAI(execution, AAIObjectType.SERVICE_INSTANCE, nssiId, errorMsg)
206 Optional<ServiceInstance> si =wrapper.asBean(ServiceInstance.class)
209 nssiInstanceList.add(si.get())
212 int size = nssiInstanceList.size()
213 int proportion = size >0 ?((90/size) as int) : 90
214 execution.setVariable("nssiInstanceList", nssiInstanceList)
215 execution.setVariable("currentNSSIIndex", 0)
216 execution.setVariable("proportion", proportion)
217 String msg ="nssiInstanceList size: ${nssiInstanceList.size()}, proportion:${proportion}"
219 LOGGER.trace(" *****${PREFIX} Exit getNSSIListFromAAI *****")
226 void getCurrentNSSI(DelegateExecution execution)
228 LOGGER.trace(" *****${PREFIX} Start getCurrentNSSI *****")
229 List<ServiceInstance> nssiInstanceList = execution.getVariable("nssiInstanceList")
230 int currentIndex = execution.getVariable("currentNSSIIndex") as int
231 ServiceInstance nssi = nssiInstanceList?.get(currentIndex)
232 def currentNSSI = [:]
233 currentNSSI['nssiServiceInstanceId'] = nssi?.getServiceInstanceId()
234 currentNSSI['modelInvariantId'] = nssi?.getModelInvariantId()
235 currentNSSI['modelVersionId'] = nssi?.getModelVersionId()
236 currentNSSI['snssai'] = execution.getVariable("snssai") ?: ""
237 currentNSSI['nsiServiceInstanceId'] = execution.getVariable("nsiId") ?: ""
238 currentNSSI['operationId'] = execution.getVariable("operationId") ?: ""
239 currentNSSI['e2eServiceInstanceId'] = execution.getVariable("serviceInstanceId") ?: ""
240 currentNSSI['msoRequestId'] = execution.getVariable("msoRequestId") ?: ""
241 currentNSSI['globalSubscriberId'] = execution.getVariable("globalSubscriberId") ?: ""
242 currentNSSI['serviceType'] = execution.getVariable("serviceType") ?: ""
243 currentNSSI['serviceModelInfo'] = execution.getVariable("serviceModelInfo") ?: ""
244 currentNSSI['proportion'] = (execution.getVariable("proportion") as int)*(currentIndex+1)
245 execution.setVariable("currentNSSI", currentNSSI)
246 String msg = "Now we deal with nssiServiceInstanceId: ${currentNSSI['nssiServiceInstanceId']}, current Index: ${currentIndex}, current proportion:${currentNSSI['proportion']}"
248 LOGGER.trace(" *****${PREFIX} Exit getCurrentNSSI *****")
255 void parseNextNSSI(DelegateExecution execution)
257 LOGGER.trace(" *****${PREFIX} Start parseNextNSSI *****")
258 if(execution.getVariable("WorkflowException") != null){
259 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "current job failure!")
261 def currentIndex = execution.getVariable("currentNSSIIndex")
262 List<ServiceInstance> nssiInstanceList = execution.getVariable("nssiInstanceList")
263 def nextIndex = ++currentIndex
264 LOGGER.info("nextIndex: ${nextIndex}")
265 if(nextIndex >= nssiInstanceList.size()){
266 execution.setVariable("isAllNSSIFinished", "true")
268 execution.setVariable("isAllNSSIFinished", "false")
269 execution.setVariable("currentNSSIIndex", nextIndex)
271 LOGGER.trace(" *****${PREFIX} Exit parseNextNSSI *****")
276 * query sliceProfile from AAI
280 void querySliceProfileFromAAI(DelegateExecution execution)
282 LOGGER.trace(" *****${PREFIX} Start querySliceProfileFromAAI *****")
283 def currentNSSI = execution.getVariable("currentNSSI")
284 String nssiId = currentNSSI['nssiServiceInstanceId']
285 String errorMsg = "query slice profile failed"
286 AAIResultWrapper wrapper = queryAAI(execution, AAIObjectType.SLICE_PROFILE_ALL, nssiId, errorMsg)
287 Optional<SliceProfiles> sliceProfiles =wrapper.asBean(SliceProfiles.class)
288 if(sliceProfiles.isPresent())
290 String profileId = sliceProfiles.get().getSliceProfile()?.get(0)?.getProfileId()
291 currentNSSI['profileId'] = profileId ?: ""
292 LOGGER.info("nssiId: ${nssiId}, profileId: ${profileId}")
294 execution.setVariable("currentNSSI", currentNSSI)
295 LOGGER.trace(" *****${PREFIX} Exit querySliceProfileFromAAI *****")
301 * @param aaiObjectType
303 * @return AAIResultWrapper
305 private AAIResultWrapper queryAAI(DelegateExecution execution, AAIObjectType aaiObjectType, String instanceId, String errorMsg)
307 LOGGER.trace(" *****${PREFIX} Start queryAAI *****")
308 String globalSubscriberId = execution.getVariable("globalSubscriberId")
309 String serviceType = execution.getVariable("serviceType")
311 AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(aaiObjectType, globalSubscriberId, serviceType, instanceId)
312 if (!getAAIClient().exists(resourceUri)) {
313 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMsg)
315 AAIResultWrapper wrapper = getAAIClient().get(resourceUri, NotFoundException.class)
316 LOGGER.trace(" *****${PREFIX} Exit queryAAI *****")