diff options
author | zm330 <zhangminyj@chinamobile.com> | 2021-01-07 20:14:45 +0800 |
---|---|---|
committer | zm330 <zhangminyj@chinamobile.com> | 2021-01-07 20:14:58 +0800 |
commit | 01d865e89f94af25b477659608b7311b3ddadc1e (patch) | |
tree | 7f508a97cb3976155325fd792c3e135dbf2e48e6 /bpmn/so-bpmn-infrastructure-common | |
parent | 67160220ddd1463696f3d56fde035dc4f3949f73 (diff) |
Fix some deallocate issues
Issue-ID: SO-3411
Signed-off-by: zm330 <zhangminyj@chinamobile.com>
Change-Id: Ie61983b9e9567bd21e5cd12cda4d76ec422c5dee
Diffstat (limited to 'bpmn/so-bpmn-infrastructure-common')
2 files changed, 53 insertions, 20 deletions
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteCommunicationService.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteCommunicationService.groovy index b94c81b41f..d00f349690 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteCommunicationService.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteCommunicationService.groovy @@ -19,6 +19,7 @@ */ package org.onap.so.bpmn.infrastructure.scripts +import org.onap.aaiclient.client.aai.entities.uri.AAISimpleUri import static org.apache.commons.lang3.StringUtils.isBlank import javax.ws.rs.NotFoundException @@ -319,12 +320,12 @@ class DeleteCommunicationService extends AbstractServiceTaskProcessor { CommunicationServiceProfile csProfile = csProfiles.getCommunicationServiceProfile().get(0) profileId = csProfile ? csProfile.getProfileId() : "" } - resourceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(serviceType).serviceInstance(serviceInstanceId).communicationServiceProfile(profileId)) - if (!getAAIClient().exists(resourceUri)) { + AAISimpleUri profileUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(serviceType).serviceInstance(serviceInstanceId).communicationServiceProfile(profileId)) + if (!getAAIClient().exists(profileUri)) { exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "communication service profile was not found in aai") } - getAAIClient().delete(resourceUri) + getAAIClient().delete(profileUri) LOGGER.debug("end delete communication service profile from AAI") } catch (any) diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteSliceService.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteSliceService.groovy index 2889f79c30..5fd06fd8d4 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteSliceService.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteSliceService.groovy @@ -19,22 +19,15 @@ */ package org.onap.so.bpmn.infrastructure.scripts -import org.onap.aai.domain.yang.SliceProfiles -import org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri - -import static org.apache.commons.lang3.StringUtils.isBlank -import javax.ws.rs.NotFoundException -import javax.ws.rs.core.Response import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.delegate.DelegateExecution import org.onap.aai.domain.yang.AllottedResource import org.onap.aai.domain.yang.AllottedResources import org.onap.aai.domain.yang.Relationship import org.onap.aai.domain.yang.ServiceInstance -import org.onap.aai.domain.yang.ServiceProfile -import org.onap.aai.domain.yang.ServiceProfiles import org.onap.aaiclient.client.aai.AAIObjectName import org.onap.aaiclient.client.aai.entities.AAIResultWrapper +import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types @@ -48,6 +41,11 @@ import org.onap.so.client.HttpClientFactory import org.slf4j.Logger import org.slf4j.LoggerFactory +import javax.ws.rs.NotFoundException +import javax.ws.rs.core.Response + +import static org.apache.commons.lang3.StringUtils.isBlank + /** * This groovy class supports the <class>DoDeleteSliceService.bpmn</class> process. * @@ -193,13 +191,27 @@ class DoDeleteSliceService extends AbstractServiceTaskProcessor { { LOGGER.trace(" *****${PREFIX} Start getNSIFromAAI *****") String nsiId = execution.getVariable("nsiId") + List<String> nssiIdList = getNSSIIdList(execution, nsiId) + String msg = "nsiId: ${nsiId}, nssiIdList:" + msg+= nssiIdList.join(",") + LOGGER.info(msg) + execution.setVariable("nssiIdList", nssiIdList) + LOGGER.trace(" *****${PREFIX} Exit getNSIFromAAI *****") + } + /** + * Get NSSI Id from AAI + * @param execution + * @param nsiId + * @return + */ + private List<String> getNSSIIdList(DelegateExecution execution, String nsiId){ + List<String> nssiIdList = [] + try { - String errorMsg = "query nsi from aai failed." + String errorMsg = "query nssi from aai failed." AAIResultWrapper wrapper = queryAAI(execution, Types.SERVICE_INSTANCE, nsiId, errorMsg) - Optional<ServiceInstance> si =wrapper.asBean(ServiceInstance.class) - List<String> nssiIdList = [] - String msg = "nsiId:${nsiId},nssiIdList:" + Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class) if(si.isPresent()) { List<Relationship> relationshipList = si.get().getRelationshipList()?.getRelationship() @@ -217,15 +229,12 @@ class DoDeleteSliceService extends AbstractServiceTaskProcessor { ServiceInstance instance = serviceInstance.get() if ("nssi".equalsIgnoreCase(instance.getServiceRole())) { nssiId = instance.getServiceInstanceId() + nssiIdList.add(nssiId) } } - nssiIdList.add(nssiId) - msg+="${nssiId}, " } } } - LOGGER.info(msg) - execution.setVariable("nssiIdList", nssiIdList) } catch(BpmnError e){ throw e @@ -235,7 +244,7 @@ class DoDeleteSliceService extends AbstractServiceTaskProcessor { LOGGER.error(msg) exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) } - LOGGER.trace(" *****${PREFIX} Exit getNSIFromAAI *****") + return nssiIdList } /** @@ -396,6 +405,7 @@ class DoDeleteSliceService extends AbstractServiceTaskProcessor { LOGGER.debug("Start terminateNSIQuery") return + //To test String requestId = execution.getVariable("msoRequestId") String nxlId = currentNSSI['nsiServiceInstanceId'] @@ -446,4 +456,26 @@ class DoDeleteSliceService extends AbstractServiceTaskProcessor { } LOGGER.debug("Finish terminateNSIQuery") } + + + /** + * If no nssi,delete NSI from AAI + * @param execution + */ + void deleteNSIInstance(DelegateExecution execution){ + def currentNSSI = execution.getVariable("currentNSSI") + def nsiId = currentNSSI['nsiServiceInstanceId'] + List<String> nssiIdList = getNSSIIdList(execution, nsiId) + try + { + if(0 == nssiIdList.size()){ + AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("serviceType")).serviceInstance(nsiId)) + getAAIClient().delete(serviceInstanceUri) + } + } catch (Exception ex) { + LOGGER.debug( "Failed to delete NSI instance.") + exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Failed to delete NSI instance.") + } + + } } |