diff options
Diffstat (limited to 'bpmn')
8 files changed, 171 insertions, 16 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VfModuleCDSRequestProvider.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VfModuleCDSRequestProvider.java index c2874fe23d..478b65c349 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VfModuleCDSRequestProvider.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VfModuleCDSRequestProvider.java @@ -104,9 +104,10 @@ public class VfModuleCDSRequestProvider implements CDSRequestProvider { final GeneralBuildingBlock buildingBlock = execution.getGeneralBuildingBlock(); List<Map<String, Object>> userParamsFromRequest = buildingBlock.getRequestContext().getRequestParameters().getUserParams(); - - configureInstanceParamsForVfModule.populateInstanceParams(vfModuleObject, userParamsFromRequest, - modelCustomizationUuidForVnf, modelCustomizationUuidForVfModule); + if (userParamsFromRequest != null && userParamsFromRequest.size() != 0) { + configureInstanceParamsForVfModule.populateInstanceParams(vfModuleObject, userParamsFromRequest, + modelCustomizationUuidForVnf, modelCustomizationUuidForVfModule); + } } catch (Exception e) { throw new PayloadGenerationException("Failed to buildPropertyObject for VF-Module", e); } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VnfCDSRequestProvider.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VnfCDSRequestProvider.java index 7425d09721..6251eb6fad 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VnfCDSRequestProvider.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VnfCDSRequestProvider.java @@ -93,9 +93,10 @@ public class VnfCDSRequestProvider implements CDSRequestProvider { final GeneralBuildingBlock buildingBlock = execution.getGeneralBuildingBlock(); List<Map<String, Object>> userParamsFromRequest = buildingBlock.getRequestContext().getRequestParameters().getUserParams(); - - configureInstanceParamsForVnf.populateInstanceParams(vnfObject, userParamsFromRequest, - modelCustomizationUuid); + if (userParamsFromRequest != null && userParamsFromRequest.size() != 0) { + configureInstanceParamsForVnf.populateInstanceParams(vnfObject, userParamsFromRequest, + modelCustomizationUuid); + } } catch (Exception e) { throw new PayloadGenerationException("Failed to buildPropertyObjectForVnf", e); } diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractVnfCDSRequestProviderTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractVnfCDSRequestProviderTest.java index 9c3ce60400..06defaa84c 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractVnfCDSRequestProviderTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractVnfCDSRequestProviderTest.java @@ -44,6 +44,7 @@ import org.onap.so.serviceinstancebeans.*; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.LinkedList; import java.util.Map; @RunWith(MockitoJUnitRunner.Silent.class) @@ -202,4 +203,10 @@ public abstract class AbstractVnfCDSRequestProviderTest { executeBuildingBlock.setBuildingBlock(buildingBlock); buildingBlockExecution.setVariable(BUILDING_BLOCK, executeBuildingBlock); } + + protected void setScopeAndActionWithoutUserParams(String scope, String action) { + buildingBlockExecution.getGeneralBuildingBlock().getRequestContext().getRequestParameters() + .setUserParams(new LinkedList<>()); + setScopeAndAction(scope, action); + } } diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VfModuleCDSRequestProviderTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VfModuleCDSRequestProviderTest.java index 2ca09d9ab3..f224ebf21e 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VfModuleCDSRequestProviderTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VfModuleCDSRequestProviderTest.java @@ -25,8 +25,14 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Spy; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.client.exception.PayloadGenerationException; +import org.onap.so.serviceinstancebeans.Service; +import org.springframework.beans.factory.annotation.Autowired; +import java.util.List; +import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -34,11 +40,19 @@ import static org.mockito.Mockito.*; public class VfModuleCDSRequestProviderTest extends AbstractVnfCDSRequestProviderTest { + @Autowired + private ObjectMapper objectMapper; + + @Spy + protected ExtractServiceFromUserParameters extractServiceFromUserParameters; + + @Spy + @InjectMocks + protected ConfigureInstanceParamsForVfModule configureInstanceParamsForVfModule; + @InjectMocks private VfModuleCDSRequestProvider vfModuleCDSRequestProvider; - @Mock - protected ConfigureInstanceParamsForVfModule configureInstanceParamsForVfModule; @Test public void testRequestPayloadForConfigDeployVfModule() throws Exception { @@ -52,7 +66,8 @@ public class VfModuleCDSRequestProviderTest extends AbstractVnfCDSRequestProvide ResourceKey.GENERIC_VNF_ID); doReturn(createVfModule()).when(extractPojosForBB).extractByKey(buildingBlockExecution, ResourceKey.VF_MODULE_ID); - doNothing().when(configureInstanceParamsForVfModule).populateInstanceParams(any(), any(), anyString(), + doReturn(getUserParams()).when(extractServiceFromUserParameters).getServiceFromRequestUserParams(anyList()); + doCallRealMethod().when(configureInstanceParamsForVfModule).populateInstanceParams(any(), any(), anyString(), anyString()); // when @@ -76,5 +91,39 @@ public class VfModuleCDSRequestProviderTest extends AbstractVnfCDSRequestProvide assertThat(propertiesNode.get("vnf-id").asText()).isEqualTo(GENERIC_VNF_ID); } + @Test + public void testRequestPayloadForConfigDeployVfModuleWithoutUserParams() throws Exception { + // given + setScopeAndActionWithoutUserParams(VF_SCOPE, DEPLOY_ACTION); + ServiceInstance serviceInstance = createServiceInstance(); + + doReturn(serviceInstance).when(extractPojosForBB).extractByKey(buildingBlockExecution, + ResourceKey.SERVICE_INSTANCE_ID); + doReturn(createGenericVnf()).when(extractPojosForBB).extractByKey(buildingBlockExecution, + ResourceKey.GENERIC_VNF_ID); + doReturn(createVfModule()).when(extractPojosForBB).extractByKey(buildingBlockExecution, + ResourceKey.VF_MODULE_ID); + doReturn(getUserParams()).when(extractServiceFromUserParameters).getServiceFromRequestUserParams(anyList()); + doCallRealMethod().when(configureInstanceParamsForVfModule).populateInstanceParams(any(), any(), anyString(), + anyString()); + + vfModuleCDSRequestProvider.setExecutionObject(buildingBlockExecution); + String payload = vfModuleCDSRequestProvider.buildRequestPayload(DEPLOY_ACTION).get(); + // verify + ObjectMapper mapper = new ObjectMapper(); + JsonNode payloadJson = mapper.readTree(payload); + JsonNode requestNode = payloadJson.findValue("configDeploy-request"); + JsonNode propertiesNode = payloadJson.findValue("configDeploy-properties"); + + assertNotNull(payload); + assertTrue(verfiyJsonFromString(payload)); + assertThat(requestNode.get("resolution-key").asText()).isEqualTo(VF_MODULE_NAME); + assertThat(propertiesNode.get("service-instance-id").asText()).isEqualTo(SERVICE_INSTANCE_ID); + assertThat(propertiesNode.get("vf-module-id").asText()).isEqualTo(VF_MODULE_ID); + assertThat(propertiesNode.get("vf-module-name").asText()).isEqualTo(VF_MODULE_NAME); + assertThat(propertiesNode.get("vf-module-customization-uuid").asText()).isEqualTo(VF_MODULE_CUSTOMIZATION_UUID); + assertThat(propertiesNode.get("service-model-uuid").asText()).isEqualTo(SERVICE_MODEL_UUID); + assertThat(propertiesNode.get("vnf-id").asText()).isEqualTo(GENERIC_VNF_ID); + } } diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateCommunicationService.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateCommunicationService.groovy index 89c3ab7c8b..12cd0dde0b 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateCommunicationService.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateCommunicationService.groovy @@ -293,11 +293,11 @@ class CreateCommunicationService extends AbstractServiceTaskProcessor { //2. profile info - Integer expDataRateDL = jsonUtil.getJsonIntValue(uuiRequest, "service.parameters.requestInputs.expDataRateDL") - Integer expDataRateUL = jsonUtil.getJsonIntValue(uuiRequest, "service.parameters.requestInputs.expDataRateUL") - Integer latency = jsonUtil.getJsonIntValue(uuiRequest, "service.parameters.requestInputs.latency") - Integer maxNumberOfUEs = jsonUtil.getJsonIntValue(uuiRequest, "service.parameters.requestInputs.maxNumberofUEs") - String uEMobilityLevel = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.uemobilityLevel") + Integer expDataRateDL = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.expDataRateDL") as Integer + Integer expDataRateUL = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.expDataRateUL") as Integer + Integer latency = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.latency") as Integer + Integer maxNumberOfUEs = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.maxNumberofUEs") as Integer + String uEMobilityLevel = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.uEMobilityLevel") String resourceSharingLevel = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.resourceSharingLevel") String coverageArea = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.coverageAreaList") diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java index b8562ba6b5..7184bba377 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java @@ -22,6 +22,9 @@ package org.onap.so.client.orchestration; import com.google.common.base.Strings; import java.util.Optional; +import org.onap.aai.domain.yang.RelatedToProperty; +import org.onap.aai.domain.yang.Relationship; +import org.onap.aai.domain.yang.RelationshipData; import org.onap.so.bpmn.common.InjectionHelper; import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; @@ -68,8 +71,15 @@ public class AAIPnfResources { public void checkIfPnfExistsInAaiAndCanBeUsed(String pnfName) throws Exception { Optional<org.onap.aai.domain.yang.Pnf> pnfFromAai = injectionHelper.getAaiClient() .get(org.onap.aai.domain.yang.Pnf.class, AAIUriFactory.createResourceUri(AAIObjectType.PNF, pnfName)); - if (pnfFromAai.isPresent() && isOrchestrationStatusSet(pnfFromAai.get())) { - checkOrchestrationStatusOfExistingPnf(pnfFromAai.get()); + if (pnfFromAai.isPresent()) { + checkIfPnfCanBeUsed(pnfFromAai.get()); + } + } + + private void checkIfPnfCanBeUsed(org.onap.aai.domain.yang.Pnf pnfFromAai) throws Exception { + isRelatedToService(pnfFromAai); + if (isOrchestrationStatusSet(pnfFromAai)) { + checkOrchestrationStatusOfExistingPnf(pnfFromAai); } } @@ -92,7 +102,39 @@ public class AAIPnfResources { pnfFromAai.getPnfName(), pnfFromAai.getOrchestrationStatus()); logger.error(errorMessage); throw new Exception(errorMessage); + } + } + private void isRelatedToService(org.onap.aai.domain.yang.Pnf pnfFromAai) throws Exception { + if (pnfFromAai.getRelationshipList() != null) { + for (Relationship relationship : pnfFromAai.getRelationshipList().getRelationship()) { + if (relationship.getRelatedTo().equals("service-instance")) { + String errorMessage = prepareRelationErrorMessage(pnfFromAai, relationship); + logger.error(errorMessage); + throw new Exception(errorMessage); + } + } + } + } + + private String prepareRelationErrorMessage(org.onap.aai.domain.yang.Pnf pnfFromAai, Relationship relationship) { + String serviceInstanceName = ""; + String serviceInstanceId = ""; + + for (RelationshipData relationshipData : relationship.getRelationshipData()) { + if (relationshipData.getRelationshipKey().equals("service-instance.service-instance-id")) { + serviceInstanceId = relationshipData.getRelationshipValue(); + break; + } + } + for (RelatedToProperty relatedToProperty : relationship.getRelatedToProperty()) { + if (relatedToProperty.getPropertyKey().equals("service-instance.service-instance-name")) { + serviceInstanceName = relatedToProperty.getPropertyValue(); + break; + } } + return String.format( + "Pnf with name %s exist with orchestration status %s and is related to %s service with certain service-instance-id: %s", + pnfFromAai.getPnfName(), pnfFromAai.getOrchestrationStatus(), serviceInstanceName, serviceInstanceId); } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java index 15c4b48d66..5e9b4c7592 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java @@ -29,7 +29,10 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.io.File; +import java.io.IOException; import java.util.Optional; +import com.fasterxml.jackson.databind.ObjectMapper; import joptsimple.internal.Strings; import org.junit.Before; import org.junit.Test; @@ -151,6 +154,27 @@ public class AAIPnfResourcesTest extends TestDataSetup { } } + @Test + public void existingPnfInAaiIsRelatedToService() throws IOException { + // given + final String relatedTo = "service-instance"; + final String serviceInstanceId = "service-instance-id"; + final String path = "src/test/resources/__files/BuildingBlocks/aaiPnf.json"; + org.onap.aai.domain.yang.Pnf pnfFromAai = + new ObjectMapper().readValue(new File(path), org.onap.aai.domain.yang.Pnf.class); + when(injectionHelperMock.getAaiClient().get(org.onap.aai.domain.yang.Pnf.class, + AAIUriFactory.createResourceUri(AAIObjectType.PNF, PNF_NAME))).thenReturn(Optional.of(pnfFromAai)); + // when + try { + testedObject.checkIfPnfExistsInAaiAndCanBeUsed(PNF_NAME); + } catch (Exception e) { + // then + assertThat(e.getMessage()).isEqualTo(String.format( + "Pnf with name %s exist with orchestration status %s and is related to %s service with certain service-instance-id: %s", + PNF_NAME, OrchestrationStatus.ACTIVE, relatedTo, serviceInstanceId)); + } + } + private org.onap.aai.domain.yang.Pnf createPnf(String orchestrationStatus) { org.onap.aai.domain.yang.Pnf pnfFromAai = new org.onap.aai.domain.yang.Pnf(); pnfFromAai.setPnfName(PNF_NAME); diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/aaiPnf.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/aaiPnf.json new file mode 100644 index 0000000000..c4600d94a0 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/aaiPnf.json @@ -0,0 +1,31 @@ +{ + "pnfName": "pnfTest", + "pnfId": "pnfId", + "orchestrationStatus": "Active", + "resourceVersion": "resourceVersion", + "relationshipList": { + "relationship": [ + { + "relatedTo": "service-instance", + "relationshipLabel": "org.onap.relationships.inventory.ComposedOf", + "relatedLink": "relatedLink", + "relationshipData": [ + { + "relationshipKey": "relationshipKey", + "relationshipValue": "relationshipValue" + }, + { + "relationshipKey": "service-instance.service-instance-id", + "relationshipValue": "service-instance-id" + } + ], + "relatedToProperty": [ + { + "propertyKey": "service-instance.service-instance-name", + "propertyValue": "service-instance" + } + ] + } + ] + } +} |