From 01d865e89f94af25b477659608b7311b3ddadc1e Mon Sep 17 00:00:00 2001 From: zm330 Date: Thu, 7 Jan 2021 20:14:45 +0800 Subject: Fix some deallocate issues Issue-ID: SO-3411 Signed-off-by: zm330 Change-Id: Ie61983b9e9567bd21e5cd12cda4d76ec422c5dee --- .../nssmf/manager/impl/ExternalNssmfManager.java | 2 +- .../scripts/DeleteCommunicationService.groovy | 7 ++- .../scripts/DoDeleteSliceService.groovy | 66 ++++++++++++++++------ .../resources/subprocess/DoDeleteSliceService.bpmn | 27 +++++++-- .../java/org/onap/so/beans/nsmf/NssmfRequest.java | 4 +- 5 files changed, 77 insertions(+), 29 deletions(-) diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/ExternalNssmfManager.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/ExternalNssmfManager.java index 96f2956b93..7c4bd50852 100644 --- a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/ExternalNssmfManager.java +++ b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/ExternalNssmfManager.java @@ -100,7 +100,7 @@ public abstract class ExternalNssmfManager extends BaseNssmfManager { restUtil.createServiceInstance(nssiInstance, serviceInfo); } else if (ActionType.DEALLOCATE.equals(jobOperType)) { // TODO - // restUtil.deleteServiceInstance(serviceInfo); + restUtil.deleteServiceInstance(serviceInfo); } } } 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 DoDeleteSliceService.bpmn process. * @@ -193,13 +191,27 @@ class DoDeleteSliceService extends AbstractServiceTaskProcessor { { LOGGER.trace(" *****${PREFIX} Start getNSIFromAAI *****") String nsiId = execution.getVariable("nsiId") + List 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 getNSSIIdList(DelegateExecution execution, String nsiId){ + List 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 si =wrapper.asBean(ServiceInstance.class) - List nssiIdList = [] - String msg = "nsiId:${nsiId},nssiIdList:" + Optional si = wrapper.asBean(ServiceInstance.class) if(si.isPresent()) { List 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 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.") + } + + } } diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoDeleteSliceService.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoDeleteSliceService.bpmn index 9edb6127f0..f1534a0360 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoDeleteSliceService.bpmn +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoDeleteSliceService.bpmn @@ -34,9 +34,9 @@ ddss.getNSSIListFromAAI(execution) SequenceFlow_0926ghe - SequenceFlow_1c4fjbv + SequenceFlow_1odnvjl - + #{(execution.getVariable("isAllNSSIFinished" ) == true)} @@ -96,6 +96,14 @@ dss.terminateNSIQuery(execution) + + + SequenceFlow_1c4fjbv + SequenceFlow_1odnvjl + import org.onap.so.bpmn.infrastructure.scripts.* +def ddss= new DoDeleteSliceService() +ddss.deleteNSIInstance(execution) + @@ -138,9 +146,9 @@ dss.terminateNSIQuery(execution) - + - + @@ -177,9 +185,9 @@ dss.terminateNSIQuery(execution) - + - + @@ -200,6 +208,13 @@ dss.terminateNSIQuery(execution) + + + + + + + diff --git a/common/src/main/java/org/onap/so/beans/nsmf/NssmfRequest.java b/common/src/main/java/org/onap/so/beans/nsmf/NssmfRequest.java index 3292730f29..356c1cb4de 100644 --- a/common/src/main/java/org/onap/so/beans/nsmf/NssmfRequest.java +++ b/common/src/main/java/org/onap/so/beans/nsmf/NssmfRequest.java @@ -37,7 +37,7 @@ public class NssmfRequest implements Serializable { private String globalSubscriberId; - private String serviceInstanceId; + private String serviceInstanceID; private String subscriptionServiceType; @@ -54,7 +54,7 @@ public class NssmfRequest implements Serializable { this.subscriptionServiceType = serviceInfo.getSubscriptionServiceType(); this.networkType = networkType; this.additionalProperties = additionalProperties; - this.serviceInstanceId = serviceInfo.getNssiId(); + this.serviceInstanceID = serviceInfo.getNssiId(); this.name = serviceInfo.getNssiName(); } -- cgit 1.2.3-korg