diff options
Diffstat (limited to 'bpmn/MSOCommonBPMN')
8 files changed, 446 insertions, 98 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/GenericVnf.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/GenericVnf.java index ebf722ef74..0bce305f1d 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/GenericVnf.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/GenericVnf.java @@ -144,6 +144,8 @@ public class GenericVnf implements Serializable, ShallowCopy<GenericVnf> { private String blueprintName; @JsonProperty("CDS_BLUEPRINT_VERSION") private String blueprintVersion; + @JsonProperty("application-id") + private String applicationId; public String getBlueprintName() { @@ -530,6 +532,15 @@ public class GenericVnf implements Serializable, ShallowCopy<GenericVnf> { this.callHoming = callHoming; } + + public String getApplicationId() { + return applicationId; + } + + public void setApplicationId(String applicationId) { + this.applicationId = applicationId; + } + @Override public boolean equals(final Object other) { if (!(other instanceof GenericVnf)) { diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/generalobjects/RequestContext.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/generalobjects/RequestContext.java index 632e61b85c..0193469d93 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/generalobjects/RequestContext.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/generalobjects/RequestContext.java @@ -55,6 +55,8 @@ public class RequestContext implements Serializable { private RequestParameters requestParameters; @JsonProperty("configurationParameters") private List<Map<String, String>> configurationParameters = new ArrayList<>(); + @JsonProperty("application-id") + private String applicationId; public String getServiceURI() { return serviceURI; @@ -143,4 +145,12 @@ public class RequestContext implements Serializable { public void setConfigurationParameters(List<Map<String, String>> configurationParameters) { this.configurationParameters = configurationParameters; } + + public String getApplicationId() { + return applicationId; + } + + public void setApplicationId(String applicationId) { + this.applicationId = applicationId; + } } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java index 3f664cb821..88c36bec3a 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java @@ -62,6 +62,7 @@ import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds; import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext; import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.NoServiceInstanceFoundException; +import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.ServiceModelNotFoundException; import org.onap.so.client.aai.AAICommonObjectMapperProvider; import org.onap.so.client.aai.AAIObjectType; import org.onap.so.client.aai.entities.AAIResultWrapper; @@ -116,6 +117,7 @@ public class BBInputSetup implements JavaDelegate { private static final String VNF = "Vnf"; private static final String NETWORK_COLLECTION = "NetworkCollection"; private static final String PREPROV = "PREPROV"; + private static final String CREATEVOLUME = "CreateVolume"; @Autowired private BBInputSetupUtils bbInputSetupUtils; @@ -253,41 +255,46 @@ public class BBInputSetup implements JavaDelegate { String bbName = executeBB.getBuildingBlock().getBpmnFlowName(); String serviceInstanceId = lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID); org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance = null; - if (serviceInstanceId != null) { - aaiServiceInstance = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId); - } Service service = null; boolean isReplace = false; - if (aaiServiceInstance != null) { - if (requestAction.equalsIgnoreCase("replaceInstance")) { - RelatedInstanceList[] relatedInstanceList = requestDetails.getRelatedInstanceList(); - if (relatedInstanceList != null) { - for (RelatedInstanceList relatedInstList : relatedInstanceList) { - RelatedInstance relatedInstance = relatedInstList.getRelatedInstance(); - if (relatedInstance.getModelInfo().getModelType().equals(ModelType.service)) { - service = bbInputSetupUtils - .getCatalogServiceByModelUUID(relatedInstance.getModelInfo().getModelVersionId()); - isReplace = true; + if (serviceInstanceId != null) { + aaiServiceInstance = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId); + if (aaiServiceInstance != null) { + if (requestAction.equalsIgnoreCase("replaceInstance")) { + RelatedInstanceList[] relatedInstanceList = requestDetails.getRelatedInstanceList(); + if (relatedInstanceList != null) { + for (RelatedInstanceList relatedInstList : relatedInstanceList) { + RelatedInstance relatedInstance = relatedInstList.getRelatedInstance(); + if (relatedInstance.getModelInfo().getModelType().equals(ModelType.service)) { + service = bbInputSetupUtils.getCatalogServiceByModelUUID( + relatedInstance.getModelInfo().getModelVersionId()); + isReplace = true; + } } } + } else { + service = bbInputSetupUtils.getCatalogServiceByModelUUID(aaiServiceInstance.getModelVersionId()); + } + if (service == null) { + String message = String.format( + "Related service instance model not found in MSO CatalogDB: model-version-id=%s", + aaiServiceInstance.getModelVersionId()); + throw new ServiceModelNotFoundException(message); } } else { - service = bbInputSetupUtils.getCatalogServiceByModelUUID(aaiServiceInstance.getModelVersionId()); + String message = String.format("Related service instance from AAI not found: service-instance-id=%s", + serviceInstanceId); + throw new NoServiceInstanceFoundException(message); } } - if (aaiServiceInstance != null && service != null) { - ServiceInstance serviceInstance = this.getExistingServiceInstance(aaiServiceInstance); - serviceInstance.setModelInfoServiceInstance(this.mapperLayer.mapCatalogServiceIntoServiceInstance(service)); - this.populateObjectsOnAssignAndCreateFlows(executeBB.getRequestId(), requestDetails, service, bbName, - serviceInstance, lookupKeyMap, resourceId, vnfType, executeBB.getBuildingBlock().getKey(), - executeBB.getConfigurationResourceKeys(), isReplace); - return this.populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, executeBB, requestAction, - null); - } else { - logger.debug("Related Service Instance from AAI: {}", aaiServiceInstance); - logger.debug("Related Service Instance Model Info from AAI: {}", service); - throw new Exception("Could not find relevant information for related Service Instance"); - } + + ServiceInstance serviceInstance = this.getExistingServiceInstance(aaiServiceInstance); + serviceInstance.setModelInfoServiceInstance(this.mapperLayer.mapCatalogServiceIntoServiceInstance(service)); + this.populateObjectsOnAssignAndCreateFlows(executeBB.getRequestId(), requestDetails, service, bbName, + serviceInstance, lookupKeyMap, resourceId, vnfType, executeBB.getBuildingBlock().getKey(), + executeBB.getConfigurationResourceKeys(), isReplace); + return this.populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, executeBB, requestAction, null); + } protected GeneralBuildingBlock getGBBCM(ExecuteBuildingBlock executeBB, RequestDetails requestDetails, @@ -361,6 +368,10 @@ public class BBInputSetup implements JavaDelegate { org.onap.so.serviceinstancebeans.Platform platform = requestDetails.getPlatform(); org.onap.so.serviceinstancebeans.LineOfBusiness lineOfBusiness = requestDetails.getLineOfBusiness(); + String applicationId = ""; + if (requestDetails.getRequestInfo().getApplicationId() != null) { + applicationId = requestDetails.getRequestInfo().getApplicationId(); + } if (modelType.equals(ModelType.network)) { lookupKeyMap.put(ResourceKey.NETWORK_ID, resourceId); @@ -369,8 +380,10 @@ public class BBInputSetup implements JavaDelegate { } else if (modelType.equals(ModelType.vnf)) { lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, resourceId); this.populateGenericVnf(requestId, modelInfo, instanceName, platform, lineOfBusiness, service, bbName, - serviceInstance, lookupKeyMap, relatedInstanceList, resourceId, vnfType, null, productFamilyId); - } else if (modelType.equals(ModelType.volumeGroup)) { + serviceInstance, lookupKeyMap, relatedInstanceList, resourceId, vnfType, null, productFamilyId, + applicationId); + } else if (modelType.equals(ModelType.volumeGroup) || (modelType.equals(ModelType.vfModule) + && (bbName.equalsIgnoreCase(AssignFlows.VOLUME_GROUP.toString()) || bbName.startsWith(CREATEVOLUME)))) { lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, resourceId); this.populateVolumeGroup(requestId, modelInfo, service, bbName, serviceInstance, lookupKeyMap, resourceId, relatedInstanceList, instanceName, vnfType, null); @@ -594,6 +607,7 @@ public class BBInputSetup implements JavaDelegate { bbInputSetupUtils.getAAIVolumeGroup(cloudOwner, cloudRegionId, volumeGroup.getVolumeGroupId()) .getModelCustomizationId(); if (modelInfo.getModelCustomizationId().equalsIgnoreCase(volumeGroupCustId)) { + logger.debug("Found volume group for vfModule: " + volumeGroup.getVolumeGroupId()); return Optional.of(volumeGroup.getVolumeGroupId()); } } @@ -748,7 +762,7 @@ public class BBInputSetup implements JavaDelegate { org.onap.so.serviceinstancebeans.LineOfBusiness lineOfBusiness, Service service, String bbName, ServiceInstance serviceInstance, Map<ResourceKey, String> lookupKeyMap, RelatedInstanceList[] relatedInstanceList, String resourceId, String vnfType, - List<Map<String, String>> instanceParams, String productFamilyId) { + List<Map<String, String>> instanceParams, String productFamilyId, String applicationId) { GenericVnf vnf = null; ModelInfo instanceGroupModelInfo = null; String instanceGroupId = null; @@ -777,7 +791,7 @@ public class BBInputSetup implements JavaDelegate { } if (vnf == null && bbName.equalsIgnoreCase(AssignFlows.VNF.toString())) { vnf = createGenericVnf(lookupKeyMap, instanceName, platform, lineOfBusiness, resourceId, generatedVnfType, - instanceParams, productFamilyId); + instanceParams, productFamilyId, applicationId); serviceInstance.getVnfs().add(vnf); mapVnfcCollectionInstanceGroup(vnf, modelInfo, service); } @@ -831,7 +845,7 @@ public class BBInputSetup implements JavaDelegate { protected GenericVnf createGenericVnf(Map<ResourceKey, String> lookupKeyMap, String instanceName, org.onap.so.serviceinstancebeans.Platform platform, org.onap.so.serviceinstancebeans.LineOfBusiness lineOfBusiness, String vnfId, String vnfType, - List<Map<String, String>> instanceParams, String productFamilyId) { + List<Map<String, String>> instanceParams, String productFamilyId, String applicationId) { lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, vnfId); GenericVnf genericVnf = new GenericVnf(); genericVnf.setVnfId(vnfId); @@ -840,6 +854,7 @@ public class BBInputSetup implements JavaDelegate { genericVnf.setVnfType(vnfType); genericVnf.setProvStatus(PREPROV); genericVnf.setServiceId(productFamilyId); + genericVnf.setApplicationId(applicationId); if (platform != null) { genericVnf.setPlatform(this.mapperLayer.mapRequestPlatform(platform)); } @@ -1279,24 +1294,30 @@ public class BBInputSetup implements JavaDelegate { String serviceInstanceId = lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID); RequestDetails requestDetails = executeBB.getRequestDetails(); GeneralBuildingBlock gBB = null; + Service service = null; if (serviceInstanceId != null) { aaiServiceInstance = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId); + if (aaiServiceInstance != null) { + service = bbInputSetupUtils.getCatalogServiceByModelUUID(aaiServiceInstance.getModelVersionId()); + if (service == null) { + String message = String.format( + "Related service instance model not found in MSO CatalogDB: model-version-id=%s", + aaiServiceInstance.getModelVersionId()); + throw new ServiceModelNotFoundException(message); + } + } else { + String message = String.format("Related service instance from AAI not found: service-instance-id=%s", + serviceInstanceId); + throw new NoServiceInstanceFoundException(message); + } } - Service service = null; - if (aaiServiceInstance != null) { - service = bbInputSetupUtils.getCatalogServiceByModelUUID(aaiServiceInstance.getModelVersionId()); - } - if (aaiServiceInstance != null && service != null) { - ServiceInstance serviceInstance = this.getExistingServiceInstance(aaiServiceInstance); - serviceInstance.setModelInfoServiceInstance(this.mapperLayer.mapCatalogServiceIntoServiceInstance(service)); - updateInstanceName(executeBB.getRequestId(), ModelType.service, serviceInstance.getServiceInstanceName()); - gBB = populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, executeBB, requestAction, null); - } else { - logger.debug("Related Service Instance from AAI: {}", aaiServiceInstance); - logger.debug("Related Service Instance Model Info from AAI: {}", service); - throw new Exception("Could not find relevant information for related Service Instance"); - } - ServiceInstance serviceInstance = gBB.getServiceInstance(); + + ServiceInstance serviceInstance = this.getExistingServiceInstance(aaiServiceInstance); + serviceInstance.setModelInfoServiceInstance(this.mapperLayer.mapCatalogServiceIntoServiceInstance(service)); + updateInstanceName(executeBB.getRequestId(), ModelType.service, serviceInstance.getServiceInstanceName()); + gBB = populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, executeBB, requestAction, null); + + serviceInstance = gBB.getServiceInstance(); CloudRegion cloudRegion = null; if (cloudConfiguration == null) { Optional<CloudRegion> cloudRegionOp = cloudInfoFromAAI.getCloudInfoFromAAI(serviceInstance); @@ -1431,9 +1452,10 @@ public class BBInputSetup implements JavaDelegate { this.bbInputSetupUtils.updateInfraActiveRequestVnfId(request, vnfId); } String productFamilyId = requestDetails.getRequestInfo().getProductFamilyId(); + String applicationId = ""; this.populateGenericVnf(executeBB.getRequestId(), vnfs.getModelInfo(), vnfs.getInstanceName(), vnfs.getPlatform(), vnfs.getLineOfBusiness(), service, bbName, serviceInstance, lookupKeyMap, null, - vnfId, vnfType, vnfs.getInstanceParams(), productFamilyId); + vnfId, vnfType, vnfs.getInstanceParams(), productFamilyId, applicationId); } else if (bbName.contains(VF_MODULE) || bbName.contains(VOLUME_GROUP)) { Pair<Vnfs, VfModules> vnfsAndVfModules = getVfModulesAndItsVnfsByKey(key, resources); if (vnfsAndVfModules != null) { diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtils.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtils.java index fcac86b251..994abda083 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtils.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtils.java @@ -359,7 +359,7 @@ public class BBInputSetupUtils { } public Optional<ServiceInstance> getAAIServiceInstanceByName(String globalCustomerId, String serviceType, - String serviceInstanceName) throws Exception { + String serviceInstanceName) throws MultipleObjectsFoundException { ServiceInstance aaiServiceInstance = null; ServiceInstances aaiServiceInstances = null; aaiServiceInstances = getAAIServiceInstancesByName(globalCustomerId, serviceType, serviceInstanceName); @@ -367,7 +367,10 @@ public class BBInputSetupUtils { if (aaiServiceInstances == null) { return Optional.empty(); } else if (aaiServiceInstances.getServiceInstance().size() > 1) { - throw new Exception("Multiple Service Instances Returned"); + String message = String.format( + "Multiple service instances found for customer-id: %s, service-type: %s and service-instance-name: %s.", + globalCustomerId, serviceType, serviceInstanceName); + throw new MultipleObjectsFoundException(message); } else { aaiServiceInstance = aaiServiceInstances.getServiceInstance().get(0); } @@ -472,7 +475,9 @@ public class BBInputSetupUtils { if (serviceInstances.get().getServiceInstance().isEmpty()) { throw new NoServiceInstanceFoundException("No ServiceInstances Returned"); } else if (serviceInstances.get().getServiceInstance().size() > 1) { - throw new MultipleObjectsFoundException("Multiple ServiceInstances Returned"); + String message = String.format("Mulitple service instances were found for instance-group-id: %s.", + instanceGroupId); + throw new MultipleObjectsFoundException(message); } else { serviceInstance = serviceInstances.get().getServiceInstance().get(0); } @@ -481,7 +486,7 @@ public class BBInputSetupUtils { } public Optional<L3Network> getRelatedNetworkByNameFromServiceInstance(String serviceInstanceId, String networkName) - throws Exception { + throws MultipleObjectsFoundException { AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId); uri.relatedTo(AAIObjectPlurals.L3_NETWORK).queryParam("network-name", networkName); Optional<L3Networks> networks = injectionHelper.getAaiClient().get(L3Networks.class, uri); @@ -491,7 +496,10 @@ public class BBInputSetupUtils { return Optional.empty(); } else { if (networks.get().getL3Network().size() > 1) { - throw new Exception("Multiple Networks Returned"); + String message = + String.format("Multiple networks found for service-instance-id: %s and network-name: %s.", + serviceInstanceId, networkName); + throw new MultipleObjectsFoundException(message); } else { network = networks.get().getL3Network().get(0); } @@ -500,7 +508,7 @@ public class BBInputSetupUtils { } public Optional<GenericVnf> getRelatedVnfByNameFromServiceInstance(String serviceInstanceId, String vnfName) - throws Exception { + throws MultipleObjectsFoundException { AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId); uri.relatedTo(AAIObjectPlurals.GENERIC_VNF).queryParam("vnf-name", vnfName); Optional<GenericVnfs> vnfs = injectionHelper.getAaiClient().get(GenericVnfs.class, uri); @@ -510,7 +518,9 @@ public class BBInputSetupUtils { return Optional.empty(); } else { if (vnfs.get().getGenericVnf().size() > 1) { - throw new Exception("Multiple Vnfs Returned"); + String message = String.format("Multiple vnfs found for service-instance-id: %s and vnf-name: %s.", + serviceInstanceId, vnfName); + throw new MultipleObjectsFoundException(message); } else { vnf = vnfs.get().getGenericVnf().get(0); } @@ -519,7 +529,7 @@ public class BBInputSetupUtils { } public Optional<VolumeGroup> getRelatedVolumeGroupByNameFromVnf(String vnfId, String volumeGroupName) - throws Exception { + throws MultipleObjectsFoundException { AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId); uri.relatedTo(AAIObjectPlurals.VOLUME_GROUP).queryParam("volume-group-name", volumeGroupName); Optional<VolumeGroups> volumeGroups = injectionHelper.getAaiClient().get(VolumeGroups.class, uri); @@ -529,7 +539,9 @@ public class BBInputSetupUtils { return Optional.empty(); } else { if (volumeGroups.get().getVolumeGroup().size() > 1) { - throw new Exception("Multiple VolumeGroups Returned"); + String message = String.format("Multiple volume-groups found for vnf-id: %s and volume-group-name: %s.", + vnfId, volumeGroupName); + throw new MultipleObjectsFoundException(message); } else { volumeGroup = volumeGroups.get().getVolumeGroup().get(0); } @@ -538,7 +550,7 @@ public class BBInputSetupUtils { } public Optional<VolumeGroup> getRelatedVolumeGroupByNameFromVfModule(String vnfId, String vfModuleId, - String volumeGroupName) throws Exception { + String volumeGroupName) throws MultipleObjectsFoundException { AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId); uri.relatedTo(AAIObjectPlurals.VOLUME_GROUP).queryParam("volume-group-name", volumeGroupName); Optional<VolumeGroups> volumeGroups = injectionHelper.getAaiClient().get(VolumeGroups.class, uri); @@ -548,6 +560,27 @@ public class BBInputSetupUtils { return Optional.empty(); } else { if (volumeGroups.get().getVolumeGroup().size() > 1) { + String message = String.format( + "Multiple voulme-groups found for vnf-id: %s, vf-module-id: %s and volume-group-name: %s.", + vnfId, vfModuleId, volumeGroupName); + throw new MultipleObjectsFoundException(message); + } else { + volumeGroup = volumeGroups.get().getVolumeGroup().get(0); + } + return Optional.of(volumeGroup); + } + } + + public Optional<VolumeGroup> getRelatedVolumeGroupFromVfModule(String vnfId, String vfModuleId) throws Exception { + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId); + uri.relatedTo(AAIObjectPlurals.VOLUME_GROUP); + Optional<VolumeGroups> volumeGroups = injectionHelper.getAaiClient().get(VolumeGroups.class, uri); + VolumeGroup volumeGroup = null; + if (!volumeGroups.isPresent()) { + logger.debug("VfModule does not have a volume group attached"); + return Optional.empty(); + } else { + if (volumeGroups.get().getVolumeGroup().size() > 1) { throw new Exception("Multiple VolumeGroups Returned"); } else { volumeGroup = volumeGroups.get().getVolumeGroup().get(0); @@ -587,6 +620,24 @@ public class BBInputSetupUtils { return aaiRC.exists(l3networkUri); } + public boolean existsAAIVfModuleGloballyByName(String vfModuleName) { + AAIResourceUri vfModuleUri = + AAIUriFactory.createNodesUri(AAIObjectPlurals.VF_MODULE).queryParam("vf-module-name", vfModuleName); + return injectionHelper.getAaiClient().exists(vfModuleUri); + } + + public boolean existsAAIConfigurationGloballyByName(String configurationName) { + AAIResourceUri configUri = AAIUriFactory.createResourceUri(AAIObjectPlurals.CONFIGURATION) + .queryParam("configuration-name", configurationName); + return injectionHelper.getAaiClient().exists(configUri); + } + + public boolean existsAAIVolumeGroupGloballyByName(String volumeGroupName) { + AAIResourceUri volumeGroupUri = AAIUriFactory.createNodesUri(AAIObjectPlurals.VOLUME_GROUP) + .queryParam("volume-group-name", volumeGroupName); + return injectionHelper.getAaiClient().exists(volumeGroupUri); + } + public GenericVnfs getAAIVnfsGloballyByName(String vnfName) { return injectionHelper.getAaiClient() @@ -599,7 +650,7 @@ public class BBInputSetupUtils { } public Optional<Configuration> getRelatedConfigurationByNameFromServiceInstance(String serviceInstanceId, - String configurationName) throws Exception { + String configurationName) throws MultipleObjectsFoundException { AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId); uri.relatedTo(AAIObjectPlurals.CONFIGURATION).queryParam("configuration-name", configurationName); Optional<Configurations> configurations = injectionHelper.getAaiClient().get(Configurations.class, uri); @@ -609,7 +660,10 @@ public class BBInputSetupUtils { return Optional.empty(); } else { if (configurations.get().getConfiguration().size() > 1) { - throw new Exception("Multiple Configurations Returned"); + String message = String.format( + "Multiple configurations found for service-instance-d: %s and configuration-name: %s.", + serviceInstanceId, configurationName); + throw new MultipleObjectsFoundException(message); } else { configuration = configurations.get().getConfiguration().get(0); } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/exceptions/ServiceModelNotFoundException.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/exceptions/ServiceModelNotFoundException.java new file mode 100644 index 0000000000..b9daad6626 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/exceptions/ServiceModelNotFoundException.java @@ -0,0 +1,15 @@ +package org.onap.so.bpmn.servicedecomposition.tasks.exceptions; + +public class ServiceModelNotFoundException extends Exception { + + private static final long serialVersionUID = -5551887892983898061L; + + public ServiceModelNotFoundException() { + super(); + } + + public ServiceModelNotFoundException(String message) { + super(message); + } + +} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java index 955cf94618..483b626f95 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java @@ -46,7 +46,9 @@ import java.util.Optional; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.junit.Assert; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; @@ -87,6 +89,8 @@ import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoNetwork; import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance; import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceProxy; import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule; +import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.NoServiceInstanceFoundException; +import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.ServiceModelNotFoundException; import org.onap.so.client.aai.AAICommonObjectMapperProvider; import org.onap.so.client.aai.AAIObjectType; import org.onap.so.client.aai.entities.AAIResultWrapper; @@ -149,6 +153,9 @@ public class BBInputSetupTest { @Mock private RequestsDbClient requestsDbClient; + @Rule + public ExpectedException expectedException = ExpectedException.none(); + @Before public void setup() { SPY_bbInputSetup.setBbInputSetupUtils(SPY_bbInputSetupUtils); @@ -462,19 +469,50 @@ public class BBInputSetupTest { assertThat(actual, sameBeanAs(expected)); } - @Test(expected = Exception.class) + @Test public void testGetGBBALaCarteNonServiceWithoutServiceModelInfo() throws Exception { ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), ExecuteBuildingBlock.class); RequestDetails requestDetails = mapper.readValue( new File(RESOURCE_PATH + "RequestDetailsInput_withRelatedInstanceList.json"), RequestDetails.class); Map<ResourceKey, String> lookupKeyMap = new HashMap<>(); + lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, "si123"); + String requestAction = "createInstance"; + org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance = new org.onap.aai.domain.yang.ServiceInstance(); + aaiServiceInstance.setModelVersionId("modelVersionId"); + String resourceId = "123"; + String vnfType = "vnfType"; + + doReturn(aaiServiceInstance).when(SPY_bbInputSetupUtils).getAAIServiceInstanceById("si123"); + doReturn(null).when(SPY_bbInputSetupUtils).getCatalogServiceByModelUUID(aaiServiceInstance.getModelVersionId()); + + expectedException.expect(ServiceModelNotFoundException.class); + expectedException.expectMessage( + "Related service instance model not found in MSO CatalogDB: model-version-id=modelVersionId"); + + SPY_bbInputSetup.getGBBALaCarteNonService(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, + vnfType); + } + + @Test + public void testGetGBBALaCarteNonServiceServiceInstanceNotFoundInAAI() throws Exception { + ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), + ExecuteBuildingBlock.class); + RequestDetails requestDetails = mapper.readValue( + new File(RESOURCE_PATH + "RequestDetailsInput_withRelatedInstanceList.json"), RequestDetails.class); + Map<ResourceKey, String> lookupKeyMap = new HashMap<>(); + lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, "si123"); String requestAction = "createInstance"; org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance = new org.onap.aai.domain.yang.ServiceInstance(); aaiServiceInstance.setModelVersionId("modelVersionId"); String resourceId = "123"; String vnfType = "vnfType"; + doReturn(null).when(SPY_bbInputSetupUtils).getAAIServiceInstanceById("si123"); + + expectedException.expect(NoServiceInstanceFoundException.class); + expectedException.expectMessage("Related service instance from AAI not found: service-instance-id=si123"); + SPY_bbInputSetup.getGBBALaCarteNonService(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); } @@ -780,6 +818,7 @@ public class BBInputSetupTest { String vnfType = "vnfType"; String resourceId = "networkId"; String productFamilyId = "productFamilyId"; + String applicationId = "applicationId"; Service service = Mockito.mock(Service.class); ServiceInstance serviceInstance = Mockito.mock(ServiceInstance.class); RequestDetails requestDetails = Mockito.mock(RequestDetails.class); @@ -803,6 +842,7 @@ public class BBInputSetupTest { doReturn(lineOfBusiness).when(requestDetails).getLineOfBusiness(); doReturn(relatedInstanceList).when(requestDetails).getRelatedInstanceList(); doReturn(cloudConfiguration).when(requestDetails).getCloudConfiguration(); + doReturn(applicationId).when(requestInfo).getApplicationId(); doReturn(ModelType.network).when(modelInfo).getModelType(); SPY_bbInputSetup.populateObjectsOnAssignAndCreateFlows(REQUEST_ID, requestDetails, service, bbName, @@ -814,14 +854,16 @@ public class BBInputSetupTest { doReturn(ModelType.vnf).when(modelInfo).getModelType(); resourceId = "vnfId"; + doNothing().when(SPY_bbInputSetup).populateGenericVnf(REQUEST_ID, modelInfo, instanceName, platform, lineOfBusiness, service, bbName, serviceInstance, lookupKeyMap, relatedInstanceList, resourceId, - vnfType, null, productFamilyId); + vnfType, null, productFamilyId, applicationId); + SPY_bbInputSetup.populateObjectsOnAssignAndCreateFlows(REQUEST_ID, requestDetails, service, bbName, serviceInstance, lookupKeyMap, resourceId, vnfType, null, null, false); verify(SPY_bbInputSetup, times(1)).populateGenericVnf(REQUEST_ID, modelInfo, instanceName, platform, lineOfBusiness, service, bbName, serviceInstance, lookupKeyMap, relatedInstanceList, resourceId, - vnfType, null, productFamilyId); + vnfType, null, productFamilyId, applicationId); assertEquals("VnfId populated", true, lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID).equalsIgnoreCase(resourceId)); @@ -846,6 +888,18 @@ public class BBInputSetupTest { lookupKeyMap, resourceId, relatedInstanceList, instanceName, null, cloudConfiguration, false); assertEquals("VfModuleId populated", true, lookupKeyMap.get(ResourceKey.VF_MODULE_ID).equalsIgnoreCase(resourceId)); + + String bbNameAssignVolume = AssignFlows.VOLUME_GROUP.toString(); + doReturn(ModelType.vfModule).when(modelInfo).getModelType(); + resourceId = "vfModuleId"; + doNothing().when(SPY_bbInputSetup).populateVolumeGroup(REQUEST_ID, modelInfo, service, bbNameAssignVolume, + serviceInstance, lookupKeyMap, resourceId, relatedInstanceList, instanceName, vnfType, null); + SPY_bbInputSetup.populateObjectsOnAssignAndCreateFlows(REQUEST_ID, requestDetails, service, bbNameAssignVolume, + serviceInstance, lookupKeyMap, resourceId, vnfType, null, null, false); + verify(SPY_bbInputSetup, times(1)).populateVolumeGroup(REQUEST_ID, modelInfo, service, bbNameAssignVolume, + serviceInstance, lookupKeyMap, resourceId, relatedInstanceList, instanceName, vnfType, null); + assertEquals("VolumeGroupId populated", true, + lookupKeyMap.get(ResourceKey.VOLUME_GROUP_ID).equalsIgnoreCase(resourceId)); } @Test @@ -1354,6 +1408,7 @@ public class BBInputSetupTest { vnf.setVnfName("vnfName"); serviceInstance.getVnfs().add(vnf); String vnfType = "vnfType"; + String applicationId = "applicationId"; RequestDetails requestDetails = mapper.readValue(new File(RESOURCE_PATH + "RequestDetails_CreateVnf.json"), RequestDetails.class); @@ -1380,20 +1435,20 @@ public class BBInputSetupTest { SPY_bbInputSetup.populateGenericVnf(REQUEST_ID, modelInfo, instanceName, platform, lineOfBusiness, service, bbName, serviceInstance, lookupKeyMap, requestDetails.getRelatedInstanceList(), resourceId, vnfType, - null, requestDetails.getRequestInfo().getProductFamilyId()); + null, requestDetails.getRequestInfo().getProductFamilyId(), applicationId); lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, null); SPY_bbInputSetup.populateGenericVnf(REQUEST_ID, modelInfo, instanceName, platform, lineOfBusiness, service, bbName, serviceInstance, lookupKeyMap, requestDetails.getRelatedInstanceList(), resourceId, vnfType, - null, requestDetails.getRequestInfo().getProductFamilyId()); + null, requestDetails.getRequestInfo().getProductFamilyId(), applicationId); verify(SPY_bbInputSetup, times(1)).mapCatalogVnf(vnf, modelInfo, service); instanceName = "vnfName2"; GenericVnf vnf2 = SPY_bbInputSetup.createGenericVnf(lookupKeyMap, instanceName, platform, lineOfBusiness, - resourceId, vnfType, null, requestDetails.getRequestInfo().getProductFamilyId()); + resourceId, vnfType, null, requestDetails.getRequestInfo().getProductFamilyId(), applicationId); doReturn(vnf2).when(SPY_bbInputSetup).createGenericVnf(lookupKeyMap, instanceName, platform, lineOfBusiness, - resourceId, vnfType, null, requestDetails.getRequestInfo().getProductFamilyId()); + resourceId, vnfType, null, requestDetails.getRequestInfo().getProductFamilyId(), applicationId); doNothing().when(SPY_bbInputSetup).mapNetworkCollectionInstanceGroup(vnf2, "{instanceGroupId}"); doNothing().when(SPY_bbInputSetup).mapVnfcCollectionInstanceGroup(vnf2, modelInfo, service); @@ -1401,7 +1456,7 @@ public class BBInputSetupTest { SPY_bbInputSetup.populateGenericVnf(REQUEST_ID, modelInfo, instanceName, platform, lineOfBusiness, service, bbName, serviceInstance, lookupKeyMap, requestDetails.getRelatedInstanceList(), resourceId, vnfType, - null, requestDetails.getRequestInfo().getProductFamilyId()); + null, requestDetails.getRequestInfo().getProductFamilyId(), applicationId); verify(SPY_bbInputSetup, times(2)).mapCatalogVnf(vnf2, modelInfo, service); verify(SPY_bbInputSetup, times(2)).mapNetworkCollectionInstanceGroup(vnf2, "{instanceGroupId}"); verify(SPY_bbInputSetup, times(2)).mapVnfcCollectionInstanceGroup(vnf2, modelInfo, service); @@ -1463,6 +1518,7 @@ public class BBInputSetupTest { Platform expectedPlatform = new Platform(); LineOfBusiness expectedLineOfBusiness = new LineOfBusiness(); String resourceId = "123"; + String applicationId = "applicationId"; doReturn(expectedPlatform).when(bbInputSetupMapperLayer).mapRequestPlatform(platform); doReturn(expectedLineOfBusiness).when(bbInputSetupMapperLayer).mapRequestLineOfBusiness(lineOfBusiness); org.onap.aai.domain.yang.GenericVnf vnfAAI = new org.onap.aai.domain.yang.GenericVnf(); @@ -1477,18 +1533,18 @@ public class BBInputSetupTest { SPY_bbInputSetup.populateGenericVnf(REQUEST_ID, modelInfo, instanceName, platform, lineOfBusiness, service, bbName, serviceInstance, lookupKeyMap, requestDetails.getRelatedInstanceList(), resourceId, vnfType, - null, requestDetails.getRequestInfo().getProductFamilyId()); + null, requestDetails.getRequestInfo().getProductFamilyId(), applicationId); lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, null); SPY_bbInputSetup.populateGenericVnf(REQUEST_ID, modelInfo, instanceName, platform, lineOfBusiness, service, bbName, serviceInstance, lookupKeyMap, requestDetails.getRelatedInstanceList(), resourceId, vnfType, - null, requestDetails.getRequestInfo().getProductFamilyId()); + null, requestDetails.getRequestInfo().getProductFamilyId(), applicationId); verify(SPY_bbInputSetup, times(1)).mapCatalogVnf(vnf, modelInfo, service); instanceName = "vnfName2"; GenericVnf vnf2 = SPY_bbInputSetup.createGenericVnf(lookupKeyMap, instanceName, platform, lineOfBusiness, - resourceId, vnfType, null, requestDetails.getRequestInfo().getProductFamilyId()); + resourceId, vnfType, null, requestDetails.getRequestInfo().getProductFamilyId(), applicationId); org.onap.aai.domain.yang.GenericVnf vnf2AAI = new org.onap.aai.domain.yang.GenericVnf(); vnfAAI.setModelCustomizationId("modelCustId2"); @@ -1497,7 +1553,7 @@ public class BBInputSetupTest { doNothing().when(SPY_bbInputSetup).mapNetworkCollectionInstanceGroup(vnf2, "{instanceGroupId}"); SPY_bbInputSetup.populateGenericVnf(REQUEST_ID, modelInfo, instanceName, platform, lineOfBusiness, service, bbName, serviceInstance, lookupKeyMap, requestDetails.getRelatedInstanceList(), resourceId, vnfType, - null, requestDetails.getRequestInfo().getProductFamilyId()); + null, requestDetails.getRequestInfo().getProductFamilyId(), applicationId); verify(SPY_bbInputSetup, times(2)).mapCatalogVnf(vnf2, modelInfo, service); verify(SPY_bbInputSetup, times(2)).mapNetworkCollectionInstanceGroup(vnf2, "{instanceGroupId}"); verify(SPY_bbInputSetup, times(1)).mapVnfcCollectionInstanceGroup(vnf2, modelInfo, service); @@ -1933,7 +1989,6 @@ public class BBInputSetupTest { configResourceKeys.setVfModuleCustomizationUUID("vfModuleCustomizationUUID"); configResourceKeys.setVnfResourceCustomizationUUID("vnfResourceCustomizationUUID"); executeBB.setConfigurationResourceKeys(configResourceKeys); - executeBB.setRequestDetails(requestDetails); doReturn(gBB).when(SPY_bbInputSetup).getGBBALaCarteService(executeBB, requestDetails, lookupKeyMap, requestAction, lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID)); @@ -1959,7 +2014,7 @@ public class BBInputSetupTest { any(String.class), isA(org.onap.so.serviceinstancebeans.Platform.class), isA(org.onap.so.serviceinstancebeans.LineOfBusiness.class), isA(Service.class), any(String.class), isA(ServiceInstance.class), any(), any(), any(String.class), any(String.class), any(), - any(String.class)); + any(String.class), any(String.class)); lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, null); executeBB.getBuildingBlock().setBpmnFlowName(AssignFlows.VF_MODULE.toString()); @@ -2218,7 +2273,6 @@ public class BBInputSetupTest { Service service = Mockito.mock(Service.class); String requestAction = "createInstance"; - executeBB.setRequestDetails(requestDetails); doReturn(gBB).when(SPY_bbInputSetup).getGBBALaCarteService(executeBB, requestDetails, lookupKeyMap, requestAction, lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID)); @@ -2243,7 +2297,7 @@ public class BBInputSetupTest { any(String.class), isA(org.onap.so.serviceinstancebeans.Platform.class), isA(org.onap.so.serviceinstancebeans.LineOfBusiness.class), isA(Service.class), any(String.class), isA(ServiceInstance.class), any(), ArgumentMatchers.isNull(), any(String.class), - ArgumentMatchers.isNull(), any(), any(String.class)); + ArgumentMatchers.isNull(), any(), any(String.class), any()); lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, null); executeBB.getBuildingBlock().setBpmnFlowName(AssignFlows.VF_MODULE.toString()); @@ -2308,7 +2362,7 @@ public class BBInputSetupTest { any(String.class), isA(org.onap.so.serviceinstancebeans.Platform.class), isA(org.onap.so.serviceinstancebeans.LineOfBusiness.class), isA(Service.class), any(String.class), isA(ServiceInstance.class), any(), any(), any(String.class), any(String.class), any(), - any(String.class)); + any(String.class), any(String.class)); lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, null); executeBB.getBuildingBlock().setBpmnFlowName(AssignFlows.VF_MODULE.toString()); @@ -2668,6 +2722,48 @@ public class BBInputSetupTest { } @Test + public void testGetGBBMacroExistingServiceServiceinstancenotFoundInAai() throws Exception { + ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), + ExecuteBuildingBlock.class); + Map<ResourceKey, String> lookupKeyMap = new HashMap<>(); + lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, "si123"); + + CloudConfiguration cloudConfiguration = new CloudConfiguration(); + cloudConfiguration.setLcpCloudRegionId("cloudRegionId"); + + doReturn(null).when(SPY_bbInputSetupUtils).getAAIServiceInstanceById("si123"); + + expectedException.expect(NoServiceInstanceFoundException.class); + expectedException.expectMessage("Related service instance from AAI not found: service-instance-id=si123"); + + SPY_bbInputSetup.getGBBMacroExistingService(executeBB, lookupKeyMap, "AssignVnfBB", "assign", + cloudConfiguration); + } + + @Test + public void testGetGBBMacroExistingServiceServiceModelNotFound() throws Exception { + ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), + ExecuteBuildingBlock.class); + Map<ResourceKey, String> lookupKeyMap = new HashMap<>(); + lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, "si123"); + org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance = new org.onap.aai.domain.yang.ServiceInstance(); + aaiServiceInstance.setModelVersionId("modelVersionId"); + + CloudConfiguration cloudConfiguration = new CloudConfiguration(); + cloudConfiguration.setLcpCloudRegionId("cloudRegionId"); + + doReturn(aaiServiceInstance).when(SPY_bbInputSetupUtils).getAAIServiceInstanceById("si123"); + doReturn(null).when(SPY_bbInputSetupUtils).getCatalogServiceByModelUUID(aaiServiceInstance.getModelVersionId()); + + expectedException.expect(ServiceModelNotFoundException.class); + expectedException.expectMessage( + "Related service instance model not found in MSO CatalogDB: model-version-id=modelVersionId"); + + SPY_bbInputSetup.getGBBMacroExistingService(executeBB, lookupKeyMap, "AssignVnfBB", "assign", + cloudConfiguration); + } + + @Test public void testGetVnfId() { String expected = "vnfId"; ExecuteBuildingBlock executeBB = new ExecuteBuildingBlock(); @@ -2767,6 +2863,7 @@ public class BBInputSetupTest { String platformName = "platformName"; String lineOfBusinessName = "lineOfBusinessName"; String productFamilyId = "productFamilyId"; + String applicationId = "applicationId"; Platform platform = new Platform(); platform.setPlatformName(platformName); LineOfBusiness lineOfBusiness = new LineOfBusiness(); @@ -2783,6 +2880,7 @@ public class BBInputSetupTest { expected.setLineOfBusiness(lineOfBusiness); expected.setProvStatus("PREPROV"); expected.setServiceId(productFamilyId); + expected.setApplicationId(applicationId); Map<ResourceKey, String> lookupKeyMap = new HashMap<>(); List<Map<String, String>> instanceParams = new ArrayList<>(); instanceParams.add(cloudParams); @@ -2796,14 +2894,14 @@ public class BBInputSetupTest { doReturn(lineOfBusiness).when(bbInputSetupMapperLayer).mapRequestLineOfBusiness(requestLineOfBusiness); GenericVnf actual = SPY_bbInputSetup.createGenericVnf(lookupKeyMap, instanceName, requestPlatform, - requestLineOfBusiness, vnfId, vnfType, instanceParams, productFamilyId); + requestLineOfBusiness, vnfId, vnfType, instanceParams, productFamilyId, applicationId); assertThat(actual, sameBeanAs(expected)); assertEquals("LookupKeyMap is populated", vnfId, lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID)); expected.getCloudParams().clear(); actual = SPY_bbInputSetup.createGenericVnf(lookupKeyMap, instanceName, requestPlatform, requestLineOfBusiness, - vnfId, vnfType, null, productFamilyId); + vnfId, vnfType, null, productFamilyId, applicationId); assertThat(actual, sameBeanAs(expected)); } diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtilsTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtilsTest.java index 7780837714..3fdbf39756 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtilsTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtilsTest.java @@ -22,6 +22,7 @@ package org.onap.so.bpmn.servicedecomposition.tasks; import static com.shazam.shazamcrest.MatcherAssert.assertThat; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.hamcrest.CoreMatchers.containsString; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.mockito.ArgumentMatchers.any; @@ -480,7 +481,9 @@ public class BBInputSetupUtilsTest { @Test public void testGetOptionalAAIServiceInstanceByNameException() throws Exception { - expectedException.expect(Exception.class); + expectedException.expect(MultipleObjectsFoundException.class); + expectedException.expectMessage(containsString( + "Multiple service instances found for customer-id: globalCustomerId, service-type: serviceType and service-instance-name: serviceInstanceId.")); String globalCustomerId = "globalCustomerId"; String serviceType = "serviceType"; @@ -628,7 +631,9 @@ public class BBInputSetupUtilsTest { @Test public void getRelatedNetworkByNameFromServiceInstanceMultipleNetworksExceptionTest() throws Exception { - expectedException.expect(Exception.class); + expectedException.expect(MultipleObjectsFoundException.class); + expectedException.expectMessage(containsString( + "Multiple networks found for service-instance-id: serviceInstanceId and network-name: networkName.")); String serviceInstanceId = "serviceInstanceId"; String networkName = "networkName"; @@ -637,11 +642,12 @@ public class BBInputSetupUtilsTest { network.setNetworkId("id123"); network.setNetworkName("name123"); - L3Networks expected = new L3Networks(); - expected.getL3Network().add(network); - expected.getL3Network().add(network); + L3Networks l3Networks = new L3Networks(); + l3Networks.getL3Network().add(network); + l3Networks.getL3Network().add(network); + Optional<L3Networks> optNetworks = Optional.of(l3Networks); - doReturn(expected).when(MOCK_aaiResourcesClient).get(eq(L3Networks.class), any(AAIResourceUri.class)); + doReturn(optNetworks).when(MOCK_aaiResourcesClient).get(eq(L3Networks.class), any(AAIResourceUri.class)); bbInputSetupUtils.getRelatedNetworkByNameFromServiceInstance(serviceInstanceId, networkName); } @@ -711,7 +717,9 @@ public class BBInputSetupUtilsTest { @Test public void getRelatedVnfByNameFromServiceInstanceMultipleVnfsExceptionTest() throws Exception { - expectedException.expect(Exception.class); + expectedException.expect(MultipleObjectsFoundException.class); + expectedException.expectMessage(containsString( + "Multiple vnfs found for service-instance-id: serviceInstanceId and vnf-name: vnfName.")); String serviceInstanceId = "serviceInstanceId"; String vnfName = "vnfName"; @@ -720,11 +728,13 @@ public class BBInputSetupUtilsTest { vnf.setVnfId("id123"); vnf.setVnfName("name123"); - GenericVnfs expectedVnf = new GenericVnfs(); - expectedVnf.getGenericVnf().add(vnf); - expectedVnf.getGenericVnf().add(vnf); + GenericVnfs vnfs = new GenericVnfs(); + vnfs.getGenericVnf().add(vnf); + vnfs.getGenericVnf().add(vnf); + + Optional<GenericVnfs> optVnfs = Optional.of(vnfs); - doReturn(expectedVnf).when(MOCK_aaiResourcesClient).get(eq(GenericVnfs.class), any(AAIResourceUri.class)); + doReturn(optVnfs).when(MOCK_aaiResourcesClient).get(eq(GenericVnfs.class), any(AAIResourceUri.class)); bbInputSetupUtils.getRelatedVnfByNameFromServiceInstance(serviceInstanceId, vnfName); } @@ -756,7 +766,10 @@ public class BBInputSetupUtilsTest { @Test public void getRelatedVolumeGroupByNameFromVnfMultipleVolumeGroupsExceptionTest() throws Exception { - expectedException.expect(Exception.class); + expectedException.expect(MultipleObjectsFoundException.class); + expectedException.expectMessage(containsString( + "Multiple volume-groups found for vnf-id: vnfId and volume-group-name: volumeGroupName.")); + String vnfId = "vnfId"; String volumeGroupName = "volumeGroupName"; @@ -765,12 +778,12 @@ public class BBInputSetupUtilsTest { volumeGroup.setVolumeGroupId("id123"); volumeGroup.setVolumeGroupName("name123"); - VolumeGroups expectedVolumeGroup = new VolumeGroups(); - expectedVolumeGroup.getVolumeGroup().add(volumeGroup); - expectedVolumeGroup.getVolumeGroup().add(volumeGroup); + VolumeGroups volumeGroups = new VolumeGroups(); + volumeGroups.getVolumeGroup().add(volumeGroup); + volumeGroups.getVolumeGroup().add(volumeGroup); + Optional<VolumeGroups> optVolumeGroups = Optional.of(volumeGroups); - doReturn(expectedVolumeGroup).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class), - any(AAIResourceUri.class)); + doReturn(optVolumeGroups).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class), any(AAIResourceUri.class)); bbInputSetupUtils.getRelatedVolumeGroupByNameFromVnf(vnfId, volumeGroupName); } @@ -802,12 +815,11 @@ public class BBInputSetupUtilsTest { } @Test - public void getRelatedVolumeGroupByNameFromVfModuleMultipleVolumeGroupsExceptionTest() throws Exception { + public void getRelatedVolumeGroupFromVfModuleMultipleVolumeGroupsExceptionTest() throws Exception { expectedException.expect(Exception.class); String vnfId = "vnfId"; String volumeGroupId = "volumeGroupId"; - String volumeGroupName = "volumeGroupName"; VolumeGroup volumeGroup = new VolumeGroup(); volumeGroup.setVolumeGroupId("id123"); @@ -820,6 +832,54 @@ public class BBInputSetupUtilsTest { doReturn(expectedVolumeGroup).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class), any(AAIResourceUri.class)); + bbInputSetupUtils.getRelatedVolumeGroupFromVfModule(vnfId, volumeGroupId); + } + + @Test + public void getRelatedVolumeGroupFromVfModuleNotFoundTest() throws Exception { + String vnfId = "vnfId"; + String volumeGroupId = "volumeGroupId"; + + doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class), any(AAIResourceUri.class)); + + Optional<VolumeGroup> actualVolumeGroup = + bbInputSetupUtils.getRelatedVolumeGroupFromVfModule(vnfId, volumeGroupId); + + assertEquals(actualVolumeGroup, Optional.empty()); + } + + @Test + public void getRelatedVolumeGroupFromVfModuleTest() throws Exception { + Optional<VolumeGroups> expected = Optional.of(new VolumeGroups()); + VolumeGroup volumeGroup = new VolumeGroup(); + volumeGroup.setVolumeGroupId("id123"); + expected.get().getVolumeGroup().add(volumeGroup); + doReturn(expected).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class), any(AAIResourceUri.class)); + Optional<VolumeGroup> actual = this.bbInputSetupUtils.getRelatedVolumeGroupFromVfModule("id123", "id123"); + assertEquals(actual.get().getVolumeGroupId(), expected.get().getVolumeGroup().get(0).getVolumeGroupId()); + } + + @Test + public void getRelatedVolumeGroupByNameFromVfModuleMultipleVolumeGroupsExceptionTest() throws Exception { + expectedException.expect(MultipleObjectsFoundException.class); + expectedException.expectMessage(containsString( + "Multiple voulme-groups found for vnf-id: vnfId, vf-module-id: volumeGroupId and volume-group-name: volumeGroupName.")); + String vnfId = "vnfId"; + String volumeGroupId = "volumeGroupId"; + String volumeGroupName = "volumeGroupName"; + + VolumeGroup volumeGroup = new VolumeGroup(); + volumeGroup.setVolumeGroupId("id123"); + volumeGroup.setVolumeGroupName("name123"); + + VolumeGroups volumeGroups = new VolumeGroups(); + volumeGroups.getVolumeGroup().add(volumeGroup); + volumeGroups.getVolumeGroup().add(volumeGroup); + + Optional<VolumeGroups> optVolumeGroups = Optional.of(volumeGroups); + + doReturn(optVolumeGroups).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class), any(AAIResourceUri.class)); + bbInputSetupUtils.getRelatedVolumeGroupByNameFromVfModule(vnfId, volumeGroupId, volumeGroupName); } @@ -837,6 +897,7 @@ public class BBInputSetupUtilsTest { assertEquals(actualVolumeGroup, Optional.empty()); } + @Test public void loadOriginalFlowExecutionPathTest() throws Exception { @@ -867,6 +928,33 @@ public class BBInputSetupUtilsTest { } @Test + public void getRelatedConfigurationByNameFromServiceInstanceExceptionTest() throws Exception { + Configuration configuration = new Configuration(); + configuration.setConfigurationId("id123"); + + Configurations configurations = new Configurations(); + configurations.getConfiguration().add(configuration); + configurations.getConfiguration().add(configuration); + + Optional<Configurations> optConfigurations = Optional.of(configurations); + + doReturn(optConfigurations).when(MOCK_aaiResourcesClient).get(eq(Configurations.class), + any(AAIResourceUri.class)); + + expectedException.expect(MultipleObjectsFoundException.class); + this.bbInputSetupUtils.getRelatedConfigurationByNameFromServiceInstance("id123", "name123"); + } + + @Test + public void getRelatedConfigurationByNameFromServiceInstanceNotFoundTest() throws Exception { + doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(eq(Configurations.class), + any(AAIResourceUri.class)); + Optional<Configuration> actualConfiguration = + bbInputSetupUtils.getRelatedConfigurationByNameFromServiceInstance("id123", "name123"); + assertEquals(actualConfiguration, Optional.empty()); + } + + @Test public void getRelatedConfigurationByNameFromServiceInstanceTest() throws Exception { Optional<Configurations> expected = Optional.of(new Configurations()); Configuration configuration = new Configuration(); @@ -878,4 +966,35 @@ public class BBInputSetupUtilsTest { assertEquals(actual.get().getConfigurationId(), expected.get().getConfiguration().get(0).getConfigurationId()); } + @Test + public void existsAAIVfModuleGloballyByNameTest() throws Exception { + AAIResourceUri expectedUri = + AAIUriFactory.createNodesUri(AAIObjectPlurals.VF_MODULE).queryParam("vf-module-name", "testVfModule"); + bbInputSetupUtils.existsAAIVfModuleGloballyByName("testVfModule"); + verify(MOCK_aaiResourcesClient, times(1)).exists(expectedUri); + } + + @Test + public void existsAAIConfigurationGloballyByNameTest() throws Exception { + AAIResourceUri expectedUri = AAIUriFactory.createResourceUri(AAIObjectPlurals.CONFIGURATION) + .queryParam("configuration-name", "testConfig"); + bbInputSetupUtils.existsAAIConfigurationGloballyByName("testConfig"); + verify(MOCK_aaiResourcesClient, times(1)).exists(expectedUri); + } + + @Test + public void existsAAINetworksGloballyByNameTest() throws Exception { + AAIResourceUri expectedUri = + AAIUriFactory.createResourceUri(AAIObjectPlurals.L3_NETWORK).queryParam("network-name", "testNetwork"); + bbInputSetupUtils.existsAAINetworksGloballyByName("testNetwork"); + verify(MOCK_aaiResourcesClient, times(1)).exists(expectedUri); + } + + @Test + public void existsAAIVolumeGroupGloballyByNameTest() throws Exception { + AAIResourceUri expectedUri = AAIUriFactory.createNodesUri(AAIObjectPlurals.VOLUME_GROUP) + .queryParam("volume-group-name", "testVoumeGroup"); + bbInputSetupUtils.existsAAIVolumeGroupGloballyByName("testVoumeGroup"); + verify(MOCK_aaiResourcesClient, times(1)).exists(expectedUri); + } } diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/exceptions/ServiceModelNotFoundExceptionTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/exceptions/ServiceModelNotFoundExceptionTest.java new file mode 100644 index 0000000000..1ab1d7aa9a --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/exceptions/ServiceModelNotFoundExceptionTest.java @@ -0,0 +1,19 @@ +package org.onap.so.bpmn.servicedecomposition.tasks.exceptions; + +import org.junit.Assert; +import org.junit.Test; + + +public class ServiceModelNotFoundExceptionTest { + + @Test + public void testRequestValidationException() { + + ServiceModelNotFoundException serviceModelNotFoundException = new ServiceModelNotFoundException(); + Assert.assertNull(serviceModelNotFoundException.getMessage()); + + serviceModelNotFoundException = new ServiceModelNotFoundException("test message"); + Assert.assertEquals("test message", serviceModelNotFoundException.getMessage()); + + } +} |