From c7504e2be5ec250abc188d01a3de523d8f01e091 Mon Sep 17 00:00:00 2001 From: hyu2010 Date: Thu, 22 Apr 2021 10:43:23 -0400 Subject: Fixes exceptions found in modifying transport slices This update fixes the exceptions found in the integration tests of transport slicing in Istanbul release Issue-ID: SO-3631 Signed-off-by: hyu2010 Change-Id: Ib085742f09f6c31bc6d238d1b9f4c12b3e16d04e Signed-off-by: hyu2010 --- .../scripts/DoCreateTnNssiInstance.groovy | 2 +- .../infrastructure/scripts/DoModifyTnNssi.groovy | 73 +++++++++++++--------- .../infrastructure/scripts/TnNssmfUtils.groovy | 70 ++++++++++++++++++--- 3 files changed, 106 insertions(+), 39 deletions(-) (limited to 'bpmn/so-bpmn-infrastructure-common') diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateTnNssiInstance.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateTnNssiInstance.groovy index 9221067cce..dd168519e5 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateTnNssiInstance.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateTnNssiInstance.groovy @@ -297,7 +297,7 @@ class DoCreateTnNssiInstance extends AbstractServiceTaskProcessor { List linkStrList = jsonUtil.StringArrayToList(linkArrayStr) for (String linkStr : linkStrList) { - String linkId = jsonUtil.getJsonValue(linkStr, "id") + String linkId = jsonUtil.getJsonValue(linkStr, "name") if (isBlank(linkId)) { linkId = "tn-nssmf-" + UUID.randomUUID().toString() } diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyTnNssi.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyTnNssi.groovy index 9440b42124..25cb2f57f6 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyTnNssi.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyTnNssi.groovy @@ -24,7 +24,11 @@ import com.fasterxml.jackson.databind.ObjectMapper import groovy.json.JsonSlurper import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.delegate.DelegateExecution -import org.onap.aai.domain.yang.* +import org.onap.aai.domain.yang.AllottedResource +import org.onap.aai.domain.yang.AllottedResources +import org.onap.aai.domain.yang.NetworkPolicy +import org.onap.aai.domain.yang.ServiceInstance +import org.onap.aai.domain.yang.SliceProfile import org.onap.aaiclient.client.aai.AAIResourcesClient import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory @@ -38,7 +42,9 @@ import org.onap.so.db.request.beans.ResourceOperationStatus import org.slf4j.Logger import org.slf4j.LoggerFactory -import static org.apache.commons.lang3.StringUtils.* +import static org.apache.commons.lang3.StringUtils.isBlank +import static org.apache.commons.lang3.StringUtils.isEmpty +import static org.apache.commons.lang3.StringUtils.isNotBlank public class DoModifyTnNssi extends AbstractServiceTaskProcessor { String Prefix = "TNMOD_" @@ -150,26 +156,31 @@ public class DoModifyTnNssi extends AbstractServiceTaskProcessor { AAIResourceUri ssServiceuri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(serviceInstanceId)) try { - if (resourceClient.exists(ssServiceuri)) { - ServiceInstance ss = resourceClient.get(ServiceInstance.class, ssServiceuri) - - AllottedResources ars = ss.getAllottedResources() - List arList = ars.getAllottedResource() - List arIdList = new ArrayList<>() - Map policyMap = new HashMap<>() - Map> logicalLinksMap = new HashMap<>() - for (AllottedResource ar : arList) { - String arId = ar.getId() - arIdList.add(arId) - String policyId = tnNssmfUtils.getPolicyIdFromAr(execution, serviceInstanceId, arId, true) - policyMap.put(arId, policyId) - List logicalLinkList = tnNssmfUtils.getLogicalLinkNamesFromAr(execution, - serviceInstanceId, arId, true) - logicalLinksMap.put(arId, logicalLinkList) + Optional ssOpt = resourceClient.get(ServiceInstance.class, ssServiceuri) + if (ssOpt.isPresent()) { + ServiceInstance ss = ssOpt.get() + AllottedResources ars = tnNssmfUtils.getAllottedResourcesFromAai(execution, serviceInstanceId, true) + if (ars != null) { + List arList = ars.getAllottedResource() + List arIdList = new ArrayList<>() + Map policyMap = new HashMap<>() + Map> logicalLinksMap = new HashMap<>() + for (AllottedResource ar : arList) { + String arId = ar.getId() + arIdList.add(arId) + String policyId = tnNssmfUtils.getPolicyIdFromAr(execution, serviceInstanceId, arId, true) + policyMap.put(arId, policyId) + List logicalLinkList = tnNssmfUtils.getLogicalLinkNamesFromAr(execution, + serviceInstanceId, arId, true) + logicalLinksMap.put(arId, logicalLinkList) + } + execution.setVariable("arIdList", arIdList) + execution.setVariable("arPolicyMap", policyMap) + execution.setVariable("arLogicalLinkMap", logicalLinksMap) + } else { + logger.error("ERROR: getExistingServiceInstance: getAllottedResources() returned null. ss=" + ss + .toString()) } - execution.setVariable("arIdList", arIdList) - execution.setVariable("arPolicyMap", policyMap) - execution.setVariable("arLogicalLinkMap", logicalLinksMap) } else { exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service instance was not found in aai to " + "associate allotted resource for service :" + serviceInstanceId) @@ -177,7 +188,7 @@ public class DoModifyTnNssi extends AbstractServiceTaskProcessor { } catch (BpmnError e) { throw e; } catch (Exception ex) { - String msg = "Exception in getServiceInstance. " + ex.getMessage() + String msg = "Exception in getExistingServiceInstance. " + ex.getMessage() logger.debug(msg) exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) } @@ -195,6 +206,7 @@ public class DoModifyTnNssi extends AbstractServiceTaskProcessor { //ss.setServiceInstanceId(ssInstanceId) String serviceStatus = "modified" ss.setOrchestrationStatus(serviceStatus) + ss.setEnvironmentContext("tn") AAIResourcesClient client = getAAIClient() AAIResourceUri uri = AAIUriFactory.createResourceUri( AAIFluentTypeBuilder.business() @@ -279,14 +291,15 @@ public class DoModifyTnNssi extends AbstractServiceTaskProcessor { void updateLogicalLinksInNetwork(DelegateExecution execution, String networkJsonStr) { try { - String arId = getValidArId(jsonUtil.getJsonValue(networkJsonStr, "id")) + String arId = getValidArId(execution, jsonUtil.getJsonValue(networkJsonStr, "id")) String linkArrayStr = jsonUtil.getJsonValue(networkJsonStr, "connectionLinks") updateLogicalLinksInAr(execution, arId, linkArrayStr) } catch (BpmnError e) { throw e } catch (Exception ex) { - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, - "Exception in updateLogicalLinksInNetwork" + ex.getMessage()) + String msg = String.format("ERROR: updateLogicalLinksInNetwork: exception: %s", ex.getMessage()) + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg); } } @@ -351,7 +364,7 @@ public class DoModifyTnNssi extends AbstractServiceTaskProcessor { try { int maxBw = getMaxBw(execution) - String arId = getValidArId(jsonUtil.getJsonValue(networkJsonStr, "id")) + String arId = getValidArId(execution, jsonUtil.getJsonValue(networkJsonStr, "id")) Map policyMap = execution.getVariable("arPolicyMap") String policyId = policyMap.get(arId) if (isBlank(policyId)) { @@ -365,8 +378,9 @@ public class DoModifyTnNssi extends AbstractServiceTaskProcessor { } catch (BpmnError e) { throw e } catch (Exception ex) { - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, - "Exception in updateNetworkPolicy" + ex.getMessage()) + String msg = String.format("ERROR: updateNetworkPolicy: exception: %s", ex.getMessage()) + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg); } } @@ -428,7 +442,7 @@ public class DoModifyTnNssi extends AbstractServiceTaskProcessor { try { String serviceInstanceId = execution.getVariable("sliceServiceInstanceId") - String sdncRequest = tnNssmfUtils.buildSDNCRequest(execution, serviceInstanceId, "modify") + String sdncRequest = tnNssmfUtils.buildSDNCRequest(execution, serviceInstanceId, "update") execution.setVariable("TNNSSMF_SDNCRequest", sdncRequest) logger.debug("Outgoing SDNCRequest is: \n" + sdncRequest) @@ -483,6 +497,7 @@ public class DoModifyTnNssi extends AbstractServiceTaskProcessor { ResourceOperationStatus roStatus = tnNssmfUtils.buildRoStatus(modelUuid, ssInstanceId, jobId, nsiId, operType, status, progress, statusDescription) + logger.debug("prepareUpdateJobStatus: roStatus={}", roStatus) requestDBUtil.prepareUpdateResourceOperationStatus(execution, roStatus) } diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/TnNssmfUtils.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/TnNssmfUtils.groovy index 4624cdafe9..fc21ed4a5e 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/TnNssmfUtils.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/TnNssmfUtils.groovy @@ -22,17 +22,19 @@ package org.onap.so.bpmn.infrastructure.scripts import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.delegate.DelegateExecution +import org.onap.aai.domain.yang.AllottedResources import org.onap.aai.domain.yang.LogicalLink import org.onap.aai.domain.yang.NetworkPolicy import org.onap.aai.domain.yang.Relationship import org.onap.aai.domain.yang.ServiceInstance import org.onap.aaiclient.client.aai.AAIResourcesClient +import org.onap.aaiclient.client.aai.AAIVersion import org.onap.aaiclient.client.aai.entities.AAIResultWrapper import org.onap.aaiclient.client.aai.entities.Relationships +import org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri 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.Activities import org.onap.so.bpmn.common.scripts.ExceptionUtil import org.onap.so.bpmn.common.scripts.MsoUtils import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils @@ -47,7 +49,7 @@ import org.slf4j.LoggerFactory import static org.apache.commons.lang3.StringUtils.isBlank class TnNssmfUtils { - static final String AAI_VERSION = "v23" + static final String AAI_VERSION = AAIVersion.LATEST private static final Logger logger = LoggerFactory.getLogger(TnNssmfUtils.class); @@ -91,6 +93,9 @@ class TnNssmfUtils { case "deactivate": reqAction = "DeactivateTransportSliceInstance" break + case "update": + reqAction = "ModifyTransportSliceInstance" + break default: reqAction = svcAction } @@ -433,7 +438,7 @@ class TnNssmfUtils { return null } - return si.modelVersionId() + return si.getModelVersionId() } AAIResourceUri buildNetworkPolicyUri(String networkPolicyId) { @@ -456,6 +461,52 @@ class TnNssmfUtils { return allottedResourceUri } + AAIPluralResourceUri buildAllottedResourcesUri(DelegateExecution execution, String serviceInstanceId) { + + AAIPluralResourceUri arsUri = + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business() + .customer(execution.getVariable("globalSubscriberId")) + .serviceSubscription(execution.getVariable("subscriptionServiceType")) + .serviceInstance(serviceInstanceId) + .allottedResources()) + + return arsUri + } + + AllottedResources getAllottedResourcesFromAai(DelegateExecution execution, String serviceInstanceId, boolean exceptionOnErr) { + AllottedResources res + try { + AAIResourcesClient client = new AAIResourcesClient() + + AAIPluralResourceUri arsUri = buildAllottedResourcesUri(execution, serviceInstanceId) + + //AAIResultWrapper wrapperAllotted = client.get(arsUri, NotFoundException.class) + //Optional allAllotted = wrapperAllotted.asBean(AllottedResources.class) + //AllottedResources allottedResources = allAllotted.get() + + Optional arsOpt = client.get(AllottedResources.class, arsUri) + if (arsOpt.isPresent()) { + res = arsOpt.get() + return res + } else { + String msg = String.format("ERROR: getAllottedResourcesFromAai: ars not found. nssiId=%s", serviceInstanceId) + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) + } + } catch (BpmnError e) { + if (exceptionOnErr) { + throw e; + } + } catch (Exception ex) { + if (exceptionOnErr) { + String msg = String.format("ERROR: getAllottedResourcesFromAai: %s", ex.getMessage()) + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) + } + } + + return res + } String getPolicyIdFromAr(DelegateExecution execution, String serviceInstanceId, String arId, boolean exceptionOnErr) { @@ -464,15 +515,15 @@ class TnNssmfUtils { AAIResourcesClient client = new AAIResourcesClient() AAIResourceUri arUri = buildAllottedResourceUri(execution, serviceInstanceId, arId) - List logicalLinkUriList = getRelationshipUriListInAai(execution, arUri, + List policyUriList = getRelationshipUriListInAai(execution, arUri, AAIFluentTypeBuilder.Types.NETWORK_POLICY, exceptionOnErr) - for (AAIResourceUri logicalLinkUri : logicalLinkUriList) { - Optional policyOpt = client.get(NetworkPolicy.class, logicalLinkUri) + for (AAIResourceUri policyUri : policyUriList) { + Optional policyOpt = client.get(NetworkPolicy.class, policyUri) if (policyOpt.isPresent()) { NetworkPolicy policy = policyOpt.get() return policy.getNetworkPolicyId() } else { - String msg = String.format("ERROR: getLogicalLinkNamesFromAr: logicalLinkUri=%s", logicalLinkUri) + String msg = String.format("ERROR: getPolicyIdFromAr: arUri=%s", policyUri) logger.error(msg) exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) } @@ -483,7 +534,7 @@ class TnNssmfUtils { } } catch (Exception ex) { if (exceptionOnErr) { - String msg = String.format("ERROR: getLogicalLinkNamesFromAr: %s", ex.getMessage()) + String msg = String.format("ERROR: getPolicyIdFromAr: %s", ex.getMessage()) logger.error(msg) exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) } @@ -494,7 +545,8 @@ class TnNssmfUtils { List getRelationshipUriListInAai(DelegateExecution execution, - AAIResourceUri uri, Activities.Info info, + AAIResourceUri uri, + Object info, boolean exceptionOnErr) { AAIResourcesClient client = new AAIResourcesClient() AAIResultWrapper wrapper = client.get(uri); -- cgit 1.2.3-korg