From 12d11c2c6fe356d00dfb8a324f4e6ef8726a1aca Mon Sep 17 00:00:00 2001 From: sanket12345 Date: Thu, 29 Jul 2021 14:59:01 +0530 Subject: Fix Relationship update b/w core NSSI and its Sliceprofile Code changes to fix issues observed during testing for: - Core Allocate - Core Activate Issue-ID: SO-3605 Signed-off-by: sanket12345 Change-Id: I88f22f115c119d713f42f0a800aeb8320d7c9ade --- .../scripts/DoActivateCoreNSSI.groovy | 76 ++++++++++------------ .../scripts/DoAllocateCoreNonSharedSlice.groovy | 26 ++------ .../scripts/DoActivateCoreNSSITest.groovy | 12 ---- 3 files changed, 41 insertions(+), 73 deletions(-) (limited to 'bpmn/so-bpmn-infrastructure-common/src') diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoActivateCoreNSSI.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoActivateCoreNSSI.groovy index 2d18108acd..ad9dfa3425 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoActivateCoreNSSI.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoActivateCoreNSSI.groovy @@ -90,7 +90,7 @@ class DoActivateCoreNSSI extends AbstractServiceTaskProcessor { execution.setVariable("sNssai", sNssai) String serviceType = execution.getVariable("subscriptionServiceType") execution.setVariable("serviceType", serviceType) - logger.debug("operationType: {} , sNssai: {}, serviceType: {}.",operationType, sNssai, serviceType) + logger.debug("operationType: {} , sNssai: {}, serviceType: {}.",operationType, sNssai, serviceType) logger.debug(Prefix +" **** Exit DoActivateCoreNSSI ::: preProcessRequest ****") } @@ -106,52 +106,42 @@ class DoActivateCoreNSSI extends AbstractServiceTaskProcessor { if(nsi.isPresent()) { List relationshipList = nsi.get().getRelationshipList()?.getRelationship() List spiWithsNssaiAndOrchStatusList = new ArrayList<>() + for (Relationship relationship : relationshipList) { String relatedTo = relationship.getRelatedTo() - if (("service-instance").equals(relatedTo)) { + if ("service-instance".equals(relatedTo)) { List relationshipDataList = relationship.getRelationshipData() List relatedToPropertyList = relationship.getRelatedToProperty() for (RelationshipData relationshipData : relationshipDataList) { - if (("service-instance.service-instance-id").equals(relationshipData.getRelationshipKey())) { - execution.setVariable("networkServiceInstanceId", relationshipData.getRelationshipValue()) - } - } - for (RelatedToProperty relatedToProperty : relatedToPropertyList) { - if (("service-instance.service-instance-name").equals(relatedToProperty.getPropertyKey())) { - execution.setVariable("networkServiceInstanceName", relatedToProperty.getPropertyValue()) - } - } - } - - //If related to is allotted-Resource - if (("allotted-resource").equals(relatedTo)) { - //get slice Profile Instance Id from allotted resource in list by nssi - List sliceProfileInstanceIdList = new ArrayList<>() - List relationshipDataList = relationship.getRelationshipData() - for (RelationshipData relationshipData : relationshipDataList) { - if (relationshipData.getRelationshipKey().equals("service-instance.service-instance-id")) { - sliceProfileInstanceIdList.add(relationshipData.getRelationshipValue()) - } - } - for (String sliceProfileServiceInstanceId : sliceProfileInstanceIdList) { - String errorSliceProfileMsg = "Slice Profile Service Instance was not found in aai" - - //Query Slice Profile Service Instance From AAI by sliceProfileServiceInstanceId - AAIResultWrapper sliceProfileInstanceWrapper = queryAAI(execution, Types.SERVICE_INSTANCE, sliceProfileServiceInstanceId, errorSliceProfileMsg) - Optional sliceProfileServiceInstance = sliceProfileInstanceWrapper.asBean(ServiceInstance.class) - if (sliceProfileServiceInstance.isPresent()) { - String orchestrationStatus= sliceProfileServiceInstance.get().getOrchestrationStatus() - String sNssai = sliceProfileServiceInstance.get().getEnvironmentContext() - String sNssaiValueFromRequest = execution.getVariable("sNssai") - if(sNssai.equals(sNssaiValueFromRequest)) { - orchestrationStatus = execution.getVariable("oStatus") - //Slice Profile Service Instance to be updated in AAI - execution.setVariable("sliceProfileServiceInstance", sliceProfileServiceInstance.get()) + if ("service-instance.service-instance-id".equals(relationshipData.getRelationshipKey())) { + //Query Every related Service Instance From AAI by service Instance ID + AAIResultWrapper instanceWrapper = queryAAI(execution, Types.SERVICE_INSTANCE, relationshipData.getRelationshipValue(), "No Instance Present") + Optional relatedServiceInstance = instanceWrapper.asBean(ServiceInstance.class) + if (relatedServiceInstance.isPresent()) { + ServiceInstance relatedServiceInstanceObj = relatedServiceInstance.get() + String role = relatedServiceInstanceObj.getServiceRole(); + + if(role == null || role.isEmpty()) { + networkServiceInstanceId = relatedServiceInstanceObj.getServiceInstanceId() + networkServiceInstanceName = relatedServiceInstanceObj.getServiceInstanceName() + logger.debug("networkServiceInstanceId: {} networkServiceInstanceName: {} ",networkServiceInstanceId, networkServiceInstanceName) + execution.setVariable("networkServiceInstanceId", networkServiceInstanceId) + execution.setVariable("networkServiceInstanceName", networkServiceInstanceName) + } else if("slice-profile-instance".equals(role)) { + String orchestrationStatus= relatedServiceInstanceObj.getOrchestrationStatus() + String sNssai = relatedServiceInstanceObj.getEnvironmentContext() + if(sNssai.equals(execution.getVariable("sNssai"))) { + orchestrationStatus = execution.getVariable("oStatus") + //Slice Profile Service Instance to be updated in AAI + execution.setVariable("sliceProfileServiceInstance", relatedServiceInstanceObj) + } + Map spiWithsNssaiAndOrchStatus = new LinkedHashMap<>() + spiWithsNssaiAndOrchStatus.put("snssai", sNssai) + spiWithsNssaiAndOrchStatus.put("status", orchestrationStatus) + spiWithsNssaiAndOrchStatusList.add(spiWithsNssaiAndOrchStatus) + logger.debug("service Profile's NSSAI And Orchestration Status: "+spiWithsNssaiAndOrchStatus) + } } - Map spiWithsNssaiAndOrchStatus = new LinkedHashMap<>() - spiWithsNssaiAndOrchStatus.put("snssai", sNssai) - spiWithsNssaiAndOrchStatus.put("status", orchestrationStatus) - spiWithsNssaiAndOrchStatusList.add(spiWithsNssaiAndOrchStatus) } } } @@ -620,6 +610,10 @@ class DoActivateCoreNSSI extends AbstractServiceTaskProcessor { ServiceInstance si = execution.getVariable("sliceProfileServiceInstance") String sliceProfileInstanceId = si.getServiceInstanceId() + + if(sliceProfileInstanceId==null) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Slice Profile Instance Update failed") + } si.setOrchestrationStatus(oStatus) AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalCustId).serviceSubscription(serviceType).serviceInstance(sliceProfileInstanceId)) diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateCoreNonSharedSlice.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateCoreNonSharedSlice.groovy index 2801c11e47..bf3dda6832 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateCoreNonSharedSlice.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateCoreNonSharedSlice.groovy @@ -112,33 +112,19 @@ class DoAllocateCoreNonSharedSlice extends AbstractServiceTaskProcessor { try { String serviceType = execution.getVariable("subscriptionServiceType") String oStatus = execution.getVariable("orchestrationStatus") - //Get workload context and environment context from DB - String environmentContext = "" - String workloadContext ="" + String environmentContext = execution.getVariable("networkType") + String workloadContext = "CN" String modelInvariantUuid = execution.getVariable("modelInvariantUuid") - try{ - String json = catalogDbUtils.getServiceResourcesByServiceModelInvariantUuidString(execution,modelInvariantUuid ) - logger.debug("JSON Response from DB: "+json) - environmentContext = jsonUtil.getJsonValue(json, "serviceResources.environmentContext") ?: "" - workloadContext = jsonUtil.getJsonValue(json, "serviceResources.workloadContext") ?: "" - logger.debug("Env Context is: "+ environmentContext) - logger.debug("Workload Context is: "+ workloadContext) - } catch(BpmnError e){ - throw e - } catch (Exception ex){ - msg = "Exception in createNSSIinAAI ::: DoAllocateCoreNonSharedSlice " + ex.getMessage() - logger.debug(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) - } + String nssiServiceType = execution.getVariable("sst") //set shared or non shared value from sliceProfile object in request String additionalParams = execution.getVariable("sliceParams") //Get resourceSharingLevel from sliceProfile String serviceFunction = jsonUtil.getJsonValue(additionalParams, "sliceProfile.resourceSharingLevel") - String serviceInstanceName = "nssi_"+execution.getVariable("nsstName") + String serviceInstanceName = execution.getVariable("servicename") ServiceInstance si = new ServiceInstance() si.setServiceInstanceId(execution.getVariable("nssiServiceInstanceId")) si.setServiceInstanceName(serviceInstanceName) - si.setServiceType(serviceType) + si.setServiceType(nssiServiceType) si.setServiceRole("nssi") si.setOrchestrationStatus(oStatus) si.setModelInvariantId(modelInvariantUuid) @@ -378,7 +364,7 @@ class DoAllocateCoreNonSharedSlice extends AbstractServiceTaskProcessor { //Update NSSI orchestration status nssiServiceInstance ServiceInstance si = execution.getVariable("nssiServiceInstance") logger.debug("nssiServiceInstance "+si) - si.setOrchestrationStatus("activated") + si.setOrchestrationStatus("deactivated") AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalCustId).serviceSubscription(serviceType).serviceInstance(nssiId)) logger.debug("uri to call: "+uri) diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoActivateCoreNSSITest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoActivateCoreNSSITest.groovy index e4c6fe5f60..b32b96b123 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoActivateCoreNSSITest.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoActivateCoreNSSITest.groovy @@ -136,18 +136,6 @@ class DoActivateCoreNSSITest extends MsoGroovyTest { Mockito.verify(mockExecution, times(1)).setVariable(eq("vnfId"), captor.capture()) assertEquals("eeb66c6f-36bd-47ad-8294-48f46b1aa912", captor.getValue()) - Mockito.verify(mockExecution, times(1)).setVariable(eq("snssaiAndOrchStatusList"), captor.capture()) - List> snssaiList = new ArrayList<>() - Map snssaiMap = new LinkedHashMap<>() - snssaiMap.put("snssai", "01-5C83F071") - snssaiMap.put("status", "activated") - snssaiList.add(snssaiMap) - Map snssaiMap1 = new LinkedHashMap<>() - snssaiMap1.put("snssai", "01-5B179BD4") - snssaiMap1.put("status", "activated") - snssaiList.add(snssaiMap1) - assertEquals(snssaiList, captor.getValue()) - //Verify Project Mockito.verify(mockExecution, times(1)).setVariable(eq("projectName"), captor.capture()) assertEquals("Project-generic", captor.getValue()) -- cgit 1.2.3-korg