diff options
author | Steve Smokowski <ss835w@att.com> | 2019-06-07 17:38:13 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-06-07 17:38:13 +0000 |
commit | 18029185dc1f6c79fc2927dcb92a9a4b618f9366 (patch) | |
tree | 6fbdcf652784be141c869259f2c2919d2a7ce378 /bpmn/so-bpmn-tasks/src | |
parent | d784f833d7268357912bd63b1e6787a2f30d5329 (diff) | |
parent | 62b2e47808fe1adcbac31dbcdf992617b7f0bd4d (diff) |
Merge "Accommodate WAN Networking"
Diffstat (limited to 'bpmn/so-bpmn-tasks/src')
32 files changed, 1369 insertions, 99 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java index 7c1ddc9923..e5df3d3f35 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java @@ -181,7 +181,6 @@ public class SniroHomingV2 { logger.trace("Started Sniro Homing Process Solution"); try { // TODO improve handling multiple solutions but is dependent on sniro enhancing api + work with sniro - // conductor to improve "inventoryType" representation validateSolution(asyncResponse); ServiceInstance serviceInstance = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription() .getServiceInstances().get(0); @@ -404,13 +403,14 @@ public class SniroHomingV2 { } /** - * Adds required, excluded, and existing candidates to a demand + * Adds required, excluded, and existing candidates as well as filtering attributes to a demand * */ private void addCandidates(SolutionCandidates candidates, Demand demand) { List<Candidate> required = candidates.getRequiredCandidates(); List<Candidate> excluded = candidates.getExcludedCandidates(); List<Candidate> existing = candidates.getExistingCandidates(); + List<Candidate> filtering = candidates.getFilteringAttributes(); List<org.onap.so.client.sniro.beans.Candidate> candidateList = getCandidates(required); if (!candidateList.isEmpty()) { @@ -424,6 +424,11 @@ public class SniroHomingV2 { if (!candidateList.isEmpty()) { demand.setExistingCandidates(candidateList); } + + candidateList = getCandidates(filtering); + if (!candidateList.isEmpty()) { + demand.setFilteringAttributes(candidateList); + } } private List<org.onap.so.client.sniro.beans.Candidate> getCandidates(List<Candidate> candidates) { diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceCreateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceCreateTasks.java index d248ad5443..df22cfdc26 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceCreateTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceCreateTasks.java @@ -21,11 +21,28 @@ package org.onap.so.bpmn.infrastructure.namingservice.tasks; +import java.util.List; +import java.util.Optional; +import org.onap.aai.domain.yang.Zone; import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.InjectionHelper; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; +import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBinding; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.aai.AAIObjectType; +import org.onap.so.client.aai.entities.AAIResultWrapper; +import org.onap.so.client.aai.entities.Relationships; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.onap.so.client.aai.entities.uri.AAIUriFactory; import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.client.namingservice.NamingRequestObject; +import org.onap.so.client.namingservice.NamingServiceConstants; import org.onap.so.client.orchestration.NamingServiceResources; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -40,6 +57,14 @@ public class NamingServiceCreateTasks { @Autowired private NamingServiceResources namingServiceResources; + @Autowired + protected InjectionHelper injectionHelper; + @Autowired + protected BBInputSetupUtils bbInputSetupUtils; + + public void setBbInputSetupUtils(BBInputSetupUtils bbInputSetupUtils) { + this.bbInputSetupUtils = bbInputSetupUtils; + } public void createInstanceGroupName(BuildingBlockExecution execution) throws Exception { InstanceGroup instanceGroup = extractPojosForBB.extractByKey(execution, ResourceKey.INSTANCE_GROUP_ID); @@ -54,4 +79,87 @@ public class NamingServiceCreateTasks { } instanceGroup.setInstanceGroupName(generatedInstanceGroupName); } + + public void createWanTransportServiceName(BuildingBlockExecution execution) throws Exception { + ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); + NamingRequestObject namingRequestObject = new NamingRequestObject(); + namingRequestObject.setExternalKeyValue(serviceInstance.getServiceInstanceId()); + namingRequestObject.setNamingTypeValue(NamingServiceConstants.NAMING_TYPE_SERVICE); + namingRequestObject.setResourceNameValue(NamingServiceConstants.RESOURCE_NAME_SERVICE_INSTANCE_NAME); + namingRequestObject.setPolicyInstanceNameValue(serviceInstance.getModelInfoServiceInstance().getNamingPolicy()); + namingRequestObject.setServiceModelNameValue(serviceInstance.getModelInfoServiceInstance().getModelName()); + namingRequestObject.setModelVersionValue(serviceInstance.getModelInfoServiceInstance().getModelVersion()); + namingRequestObject.setZoneIdValue(this.getRelatedZoneId(execution)); + + String generatedWanTransportServiceName = ""; + try { + generatedWanTransportServiceName = namingServiceResources.generateServiceInstanceName(namingRequestObject); + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + serviceInstance.setServiceInstanceName(generatedWanTransportServiceName); + } + + public void createVpnBondingServiceName(BuildingBlockExecution execution) throws Exception { + ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); + L3Network network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID); + VpnBinding vpnBinding = extractPojosForBB.extractByKey(execution, ResourceKey.VPN_ID); + NamingRequestObject namingRequestObject = new NamingRequestObject(); + namingRequestObject.setExternalKeyValue(serviceInstance.getServiceInstanceId()); + namingRequestObject.setPolicyInstanceNameValue(serviceInstance.getModelInfoServiceInstance().getNamingPolicy()); + namingRequestObject.setNamingTypeValue(NamingServiceConstants.NAMING_TYPE_SERVICE); + namingRequestObject.setServiceModelNameValue(serviceInstance.getModelInfoServiceInstance().getModelName()); + namingRequestObject.setModelVersionValue(serviceInstance.getModelInfoServiceInstance().getModelVersion()); + namingRequestObject.setNetworkNameValue(execution.getVariable(network.getNetworkName())); + namingRequestObject.setVpnNameValue(vpnBinding.getVpnName()); + namingRequestObject.setResourceNameValue(NamingServiceConstants.RESOURCE_NAME_SERVICE_INSTANCE_NAME); + + String generatedVpnBondingServiceName = ""; + try { + generatedVpnBondingServiceName = namingServiceResources.generateServiceInstanceName(namingRequestObject); + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + serviceInstance.setServiceInstanceName(generatedVpnBondingServiceName); + } + + protected String getRelatedZoneId(BuildingBlockExecution execution) { + GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock(); + String cloudRegionId = gBBInput.getCloudRegion().getLcpCloudRegionId(); + String cloudOwner = gBBInput.getCloudRegion().getCloudOwner(); + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, cloudOwner, cloudRegionId); + AAIResultWrapper vnfcResultsWrapper = bbInputSetupUtils.getAAIResourceDepthOne(uri); + Optional<Relationships> relationshipsOp = this.getRelationshipsFromWrapper(vnfcResultsWrapper); + Zone aaiZone = getRelatedZone(relationshipsOp); + if (aaiZone == null) { + String errMsg = "No relationships for Cloud Region in AAI to extract zone id"; + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, errMsg); + } + return aaiZone.getZoneId(); + } + + protected Optional<Relationships> getRelationshipsFromWrapper(AAIResultWrapper wrapper) { + Optional<Relationships> relationshipsOp; + relationshipsOp = wrapper.getRelationships(); + if (relationshipsOp.isPresent()) { + return relationshipsOp; + } + return Optional.empty(); + } + + protected org.onap.aai.domain.yang.Zone getRelatedZone(Optional<Relationships> relationshipsOp) { + Zone aaiZone = null; + if (relationshipsOp.isPresent()) { + Relationships relationships = relationshipsOp.get(); + if (!relationships.getAll().isEmpty()) { + List<AAIResultWrapper> zones = relationships.getByType(AAIObjectType.ZONE); + AAIResultWrapper zoneWrapper = zones.get(0); + Optional<Zone> aaiZoneOp = zoneWrapper.asBean(Zone.class); + if (aaiZoneOp.isPresent()) { + aaiZone = aaiZoneOp.get(); + } + } + } + return aaiZone; + } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceDeleteTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceDeleteTasks.java index 9a8c9df8b5..507e14e42a 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceDeleteTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceDeleteTasks.java @@ -23,9 +23,11 @@ package org.onap.so.bpmn.infrastructure.namingservice.tasks; import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.client.namingservice.NamingRequestObject; import org.onap.so.client.orchestration.NamingServiceResources; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -50,4 +52,16 @@ public class NamingServiceDeleteTasks { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); } } + + public void deleteServiceInstanceName(BuildingBlockExecution execution) throws Exception { + ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); + NamingRequestObject namingRequestObject = new NamingRequestObject(); + namingRequestObject.setExternalKeyValue(serviceInstance.getServiceInstanceId()); + try { + namingServiceResources.deleteServiceInstanceName(namingRequestObject); + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/VrfBondingServiceException.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/VrfBondingServiceException.java new file mode 100644 index 0000000000..2f99b46d10 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/VrfBondingServiceException.java @@ -0,0 +1,12 @@ +package org.onap.so.bpmn.infrastructure.workflow.tasks; + +public class VrfBondingServiceException extends Exception { + /** + * + */ + private static final long serialVersionUID = -4277883464681291740L; + + public VrfBondingServiceException(String errorMessage) { + super(errorMessage); + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/VrfValidation.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/VrfValidation.java new file mode 100644 index 0000000000..6e410e9880 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/VrfValidation.java @@ -0,0 +1,134 @@ +package org.onap.so.bpmn.infrastructure.workflow.tasks; + +import java.util.List; +import java.util.Optional; +import org.onap.aai.domain.yang.L3Network; +import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; +import org.onap.so.client.aai.AAIObjectType; +import org.onap.so.client.aai.entities.AAIResultWrapper; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization; +import org.onap.so.db.catalog.beans.ServiceProxyResourceCustomization; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class VrfValidation { + + @Autowired + protected BBInputSetupUtils bbInputSetupUtils; + + public void setBbInputSetupUtils(BBInputSetupUtils bbInputSetupUtils) { + this.bbInputSetupUtils = bbInputSetupUtils; + } + + protected void vrfServiceValidation(org.onap.so.db.catalog.beans.Service service) + throws VrfBondingServiceException { + if (!"BONDING".equalsIgnoreCase(service.getServiceType()) + || !"INFRASTRUCTURE-VPN".equalsIgnoreCase(service.getServiceRole())) { + throw new VrfBondingServiceException("Service: " + service.getModelName() + + " does not have service type of BONDING and does not have service role of INFRASTRUCTURE-VPN"); + } + } + + protected void vrfCatalogDbChecks(org.onap.so.db.catalog.beans.Service service) throws VrfBondingServiceException { + ConfigurationResourceCustomization configuration = getVrfConfiguration(service); + if (configuration == null || configuration.getServiceProxyResourceCustomization() == null + || configuration.getServiceProxyResourceCustomization().getSourceService() == null + || !configuration.getServiceProxyResourceCustomization().getSourceService().getServiceType() + .equalsIgnoreCase("TRANSPORT")) { + throw new VrfBondingServiceException("Service: " + service.getModelName() + + " does not have a configuration of type VRF-ENTRY and role INFRASTRUCTURE-CLOUD-VPN" + + ", and serviceProxy that does not have source service that has a serviceType of TRANSPORT)"); + } + } + + protected ConfigurationResourceCustomization getVrfConfiguration(org.onap.so.db.catalog.beans.Service service) { + for (ConfigurationResourceCustomization configuration : service.getConfigurationCustomizations()) { + if (configuration.getType() != null && configuration.getType().equalsIgnoreCase("VRF-ENTRY") + && configuration.getRole() != null + && configuration.getRole().equalsIgnoreCase("INFRASTRUCTURE-CLOUD-VPN")) { + return configuration; + } + } + return null; + } + + protected void aaiVpnBindingValidation(org.onap.aai.domain.yang.VpnBinding aaiVpnBinding) + throws VrfBondingServiceException { + if (aaiVpnBinding == null || !aaiVpnBinding.getVpnType().equalsIgnoreCase("SERVICE-INFRASTRUCTURE")) { + throw new VrfBondingServiceException("VpnBinding: " + aaiVpnBinding.getVpnId() + + " does not have service type of BONDING and doesn not have service role of INFRASTRUCTURE-VPN"); + } + } + + protected void aaiAggregateRouteValidation(org.onap.aai.domain.yang.L3Network aaiLocalNetwork) + throws VrfBondingServiceException { + if (aaiLocalNetwork.getAggregateRoutes() == null + || aaiLocalNetwork.getAggregateRoutes().getAggregateRoute() == null) { + return; + } + if (aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().size() == 1 && !aaiLocalNetwork + .getAggregateRoutes().getAggregateRoute().get(0).getIpVersion().equalsIgnoreCase("4")) { + throw new VrfBondingServiceException("LocalNetwork: " + aaiLocalNetwork.getNetworkId() + + " has 1 aggregate route but the Ip version of aggregate route is : " + + aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().get(0).getIpVersion() + " and is not 4"); + } else if (aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().size() == 2 + && !ipVersionValidation(aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().get(0).getIpVersion(), + aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().get(1).getIpVersion())) { + throw new VrfBondingServiceException("LocalNetwork: " + aaiLocalNetwork.getNetworkId() + + " has 2 aggregate routes but the combination of the Ip versions for the aggregate routes did not match the ip version of one of them to be 4 and one to be 6"); + } else if (aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().size() > 2) { + throw new VrfBondingServiceException( + "LocalNetwork: " + aaiLocalNetwork.getNetworkId() + " either has more than 2 aggregate routes"); + } + } + + protected void aaiSubnetValidation(org.onap.aai.domain.yang.L3Network aaiLocalNetwork) + throws VrfBondingServiceException { + if (aaiLocalNetwork.getSubnets() == null || aaiLocalNetwork.getSubnets().getSubnet() == null) { + throw new VrfBondingServiceException("LocalNetwork: " + aaiLocalNetwork.getNetworkId() + " has no subnets"); + } else if (aaiLocalNetwork.getSubnets().getSubnet().size() == 1 + && !aaiLocalNetwork.getSubnets().getSubnet().get(0).getIpVersion().equalsIgnoreCase("4")) { + throw new VrfBondingServiceException("LocalNetwork: " + aaiLocalNetwork.getNetworkId() + + " has 1 subnet but the Ip version of subnet is : " + + aaiLocalNetwork.getSubnets().getSubnet().get(0).getIpVersion() + " and is not 4"); + } else if (aaiLocalNetwork.getSubnets().getSubnet().size() == 2 + && !ipVersionValidation(aaiLocalNetwork.getSubnets().getSubnet().get(0).getIpVersion(), + aaiLocalNetwork.getSubnets().getSubnet().get(1).getIpVersion())) { + throw new VrfBondingServiceException("LocalNetwork: " + aaiLocalNetwork.getNetworkId() + + " has 2 subnets but the combination of the Ip versions for the subnets did not match the ip version of one of them to be 4 and one to be 6"); + } else if (aaiLocalNetwork.getSubnets().getSubnet().isEmpty() + || aaiLocalNetwork.getSubnets().getSubnet().size() > 2) { + throw new VrfBondingServiceException("LocalNetwork: " + aaiLocalNetwork.getNetworkId() + + " either has no subnets or more than 2 subnets"); + } + } + + protected boolean ipVersionValidation(String ipVersion1, String ipVersion2) { + return (ipVersion1.equalsIgnoreCase("4") && ipVersion2.equalsIgnoreCase("6")) + || (ipVersion1.equalsIgnoreCase("6") && ipVersion2.equalsIgnoreCase("4")); + } + + protected void aaiRouteTargetValidation(L3Network aaiLocalNetwork) throws VrfBondingServiceException { + AAIResultWrapper networkWrapper = new AAIResultWrapper(aaiLocalNetwork); + if (networkWrapper.getRelationships().isPresent()) { + List<AAIResourceUri> vpnBindingUris = + networkWrapper.getRelationships().get().getRelatedUris(AAIObjectType.VPN_BINDING); + if (!vpnBindingUris.isEmpty()) { + Optional<org.onap.aai.domain.yang.VpnBinding> vpnBindingOp = + bbInputSetupUtils.getAAIResourceDepthOne(vpnBindingUris.get(0)) + .asBean(org.onap.aai.domain.yang.VpnBinding.class); + if (vpnBindingOp.isPresent()) { + org.onap.aai.domain.yang.VpnBinding vpnBinding = vpnBindingOp.get(); + if (vpnBinding.getRouteTargets() != null + && !vpnBinding.getRouteTargets().getRouteTarget().isEmpty()) { + return; + } + } + } + } + throw new VrfBondingServiceException("The Local Network: " + aaiLocalNetwork.getNetworkId() + + " does not have vpn binding and/or RT information"); + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java index 70726f2014..73b0b5483e 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java @@ -35,13 +35,13 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.javatuples.Pair; -import org.slf4j.LoggerFactory; import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.L3Network; import org.onap.aai.domain.yang.Relationship; import org.onap.aai.domain.yang.ServiceInstance; import org.onap.aai.domain.yang.Vnfc; import org.onap.aai.domain.yang.VolumeGroup; +import org.onap.aai.domain.yang.VpnBinding; import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; @@ -61,9 +61,11 @@ import org.onap.so.client.orchestration.AAIConfigurationResources; import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization; import org.onap.so.db.catalog.beans.CollectionResourceCustomization; import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization; +import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization; +import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization; import org.onap.so.db.catalog.beans.CvnfcCustomization; +import org.onap.so.db.catalog.beans.ServiceProxyResourceCustomization; import org.onap.so.db.catalog.beans.VfModuleCustomization; -import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization; import org.onap.so.db.catalog.beans.macro.NorthBoundRequest; import org.onap.so.db.catalog.beans.macro.OrchestrationFlow; import org.onap.so.db.catalog.client.CatalogDbClient; @@ -78,9 +80,11 @@ import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; import org.onap.so.serviceinstancebeans.VfModules; import org.onap.so.serviceinstancebeans.Vnfs; import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @Component @@ -117,6 +121,7 @@ public class WorkflowAction { private static final String FABRIC_CONFIGURATION = "FabricConfiguration"; private static final String G_SERVICE_TYPE = "serviceType"; private static final String SERVICE_TYPE_TRANSPORT = "TRANSPORT"; + private static final String SERVICE_TYPE_BONDING = "BONDING"; private static final Logger logger = LoggerFactory.getLogger(WorkflowAction.class); @Autowired @@ -131,6 +136,8 @@ public class WorkflowAction { private AAIConfigurationResources aaiConfigurationResources; @Autowired private WorkflowActionExtractResourcesAAI workflowActionUtils; + @Autowired + private VrfValidation vrfValidation; @Autowired private Environment environment; @@ -270,7 +277,7 @@ public class WorkflowAction { foundRelated = traverseUserParamsService(execution, resourceCounter, sIRequest, requestAction); } if (!foundRelated) { - traverseCatalogDbService(execution, sIRequest, resourceCounter); + traverseCatalogDbService(execution, sIRequest, resourceCounter, aaiResourceIds); } } else if (resourceType == WorkflowType.SERVICE && (requestAction.equalsIgnoreCase("activateInstance") || requestAction.equalsIgnoreCase("unassignInstance") @@ -616,97 +623,181 @@ public class WorkflowAction { } protected void traverseCatalogDbService(DelegateExecution execution, ServiceInstancesRequest sIRequest, - List<Resource> resourceCounter) { + List<Resource> resourceCounter, List<Pair<WorkflowType, String>> aaiResourceIds) { String modelUUID = sIRequest.getRequestDetails().getModelInfo().getModelVersionId(); org.onap.so.db.catalog.beans.Service service = catalogDbClient.getServiceByID(modelUUID); if (service == null) { buildAndThrowException(execution, "Could not find the service model in catalog db."); } else { resourceCounter.add(new Resource(WorkflowType.SERVICE, service.getModelUUID(), false)); - if (service.getVnfCustomizations() == null || service.getVnfCustomizations().isEmpty()) { - List<CollectionResourceCustomization> customizations = service.getCollectionResourceCustomizations(); - if (customizations.isEmpty()) { - logger.debug("No Collections found. CollectionResourceCustomization list is empty."); - } else { - CollectionResourceCustomization collectionResourceCustomization = - findCatalogNetworkCollection(execution, service); - if (collectionResourceCustomization != null) { - resourceCounter.add(new Resource(WorkflowType.NETWORKCOLLECTION, - collectionResourceCustomization.getModelCustomizationUUID(), false)); - logger.debug("Found a network collection"); - if (collectionResourceCustomization.getCollectionResource() != null) { - if (collectionResourceCustomization.getCollectionResource().getInstanceGroup() != null) { - String toscaNodeType = collectionResourceCustomization.getCollectionResource() - .getInstanceGroup().getToscaNodeType(); - if (toscaNodeType != null && toscaNodeType.contains("NetworkCollection")) { - int minNetworks = 0; - org.onap.so.db.catalog.beans.InstanceGroup instanceGroup = - collectionResourceCustomization.getCollectionResource().getInstanceGroup(); - CollectionResourceInstanceGroupCustomization collectionInstCust = null; - if (!instanceGroup.getCollectionInstanceGroupCustomizations().isEmpty()) { - for (CollectionResourceInstanceGroupCustomization collectionInstanceGroupTemp : instanceGroup - .getCollectionInstanceGroupCustomizations()) { - if (collectionInstanceGroupTemp.getModelCustomizationUUID() - .equalsIgnoreCase(collectionResourceCustomization - .getModelCustomizationUUID())) { - collectionInstCust = collectionInstanceGroupTemp; - break; - } - } - if (collectionInstCust != null - && collectionInstCust.getSubInterfaceNetworkQuantity() != null) { - minNetworks = collectionInstCust.getSubInterfaceNetworkQuantity(); - } - } - logger.debug("minNetworks: {}", minNetworks); - CollectionNetworkResourceCustomization collectionNetworkResourceCust = null; - for (CollectionNetworkResourceCustomization collectionNetworkTemp : instanceGroup - .getCollectionNetworkResourceCustomizations()) { - if (collectionNetworkTemp.getNetworkResourceCustomization() - .getModelCustomizationUUID().equalsIgnoreCase( - collectionResourceCustomization.getModelCustomizationUUID())) { - collectionNetworkResourceCust = collectionNetworkTemp; + RelatedInstance relatedVpnBinding = + bbInputSetupUtils.getRelatedInstanceByType(sIRequest.getRequestDetails(), ModelType.vpnBinding); + RelatedInstance relatedLocalNetwork = + bbInputSetupUtils.getRelatedInstanceByType(sIRequest.getRequestDetails(), ModelType.network); + if (relatedVpnBinding != null && relatedLocalNetwork != null) { + traverseVrfConfiguration(execution, aaiResourceIds, resourceCounter, service, relatedVpnBinding, + relatedLocalNetwork); + } else { + traverseNetworkCollection(execution, resourceCounter, service); + } + } + } + + protected void traverseVrfConfiguration(DelegateExecution execution, + List<Pair<WorkflowType, String>> aaiResourceIds, List<Resource> resourceCounter, + org.onap.so.db.catalog.beans.Service service, RelatedInstance relatedVpnBinding, + RelatedInstance relatedLocalNetwork) { + try { + org.onap.aai.domain.yang.L3Network aaiLocalNetwork = + bbInputSetupUtils.getAAIL3Network(relatedLocalNetwork.getInstanceId()); + vrfValidation.vrfServiceValidation(service); + vrfValidation.vrfCatalogDbChecks(service); + vrfValidation + .aaiVpnBindingValidation(bbInputSetupUtils.getAAIVpnBinding(relatedVpnBinding.getInstanceId())); + vrfValidation.aaiSubnetValidation(aaiLocalNetwork); + vrfValidation.aaiAggregateRouteValidation(aaiLocalNetwork); + vrfValidation.aaiRouteTargetValidation(aaiLocalNetwork); + String existingAAIVrfConfiguration = getExistingAAIVrfConfiguration(relatedVpnBinding, aaiLocalNetwork); + if (existingAAIVrfConfiguration != null) { + aaiResourceIds + .add(new Pair<WorkflowType, String>(WorkflowType.CONFIGURATION, existingAAIVrfConfiguration)); + } + resourceCounter.add(new Resource(WorkflowType.CONFIGURATION, + service.getConfigurationCustomizations().get(0).getModelCustomizationUUID(), false)); + } catch (VrfBondingServiceException | JsonProcessingException e) { + buildAndThrowException(execution, e.getMessage()); + } + } + + protected String getExistingAAIVrfConfiguration(RelatedInstance relatedVpnBinding, + org.onap.aai.domain.yang.L3Network aaiLocalNetwork) + throws JsonProcessingException, VrfBondingServiceException { + Optional<Relationships> relationshipsOp = new AAIResultWrapper( + new AAICommonObjectMapperProvider().getMapper().writeValueAsString(aaiLocalNetwork)).getRelationships(); + if (relationshipsOp.isPresent()) { + List<AAIResultWrapper> configurationsRelatedToLocalNetwork = + relationshipsOp.get().getByType(AAIObjectType.CONFIGURATION); + if (configurationsRelatedToLocalNetwork.size() > 1) { + throw new VrfBondingServiceException( + "Network: " + aaiLocalNetwork.getNetworkId() + " has more than 1 configuration related to it"); + } + if (configurationsRelatedToLocalNetwork.size() == 1) { + AAIResultWrapper configWrapper = configurationsRelatedToLocalNetwork.get(0); + Optional<Configuration> relatedConfiguration = configWrapper.asBean(Configuration.class); + if (relatedConfiguration.isPresent() && vrfConfigurationAlreadyExists(relatedVpnBinding, + relatedConfiguration.get(), configWrapper)) { + return relatedConfiguration.get().getConfigurationId(); + } + } + } + return null; + } + + protected boolean vrfConfigurationAlreadyExists(RelatedInstance relatedVpnBinding, Configuration vrfConfiguration, + AAIResultWrapper configWrapper) throws VrfBondingServiceException { + if (vrfConfiguration.getConfigurationType().equalsIgnoreCase("VRF-ENTRY")) { + Optional<Relationships> relationshipsConfigOp = configWrapper.getRelationships(); + if (relationshipsConfigOp.isPresent()) { + Optional<VpnBinding> relatedInfraVpnBindingOp = + workflowActionUtils.extractRelationshipsVpnBinding(relationshipsConfigOp.get()); + if (relatedInfraVpnBindingOp.isPresent()) { + VpnBinding relatedInfraVpnBinding = relatedInfraVpnBindingOp.get(); + if (!relatedInfraVpnBinding.getVpnId().equalsIgnoreCase(relatedVpnBinding.getInstanceId())) { + throw new VrfBondingServiceException("Configuration: " + vrfConfiguration.getConfigurationId() + + " is not connected to the same vpn binding id provided in request: " + + relatedVpnBinding.getInstanceId()); + } else { + return true; + } + } + } + } + return false; + } + + protected void traverseNetworkCollection(DelegateExecution execution, List<Resource> resourceCounter, + org.onap.so.db.catalog.beans.Service service) { + if (service.getVnfCustomizations() == null || service.getVnfCustomizations().isEmpty()) { + List<CollectionResourceCustomization> customizations = service.getCollectionResourceCustomizations(); + if (customizations.isEmpty()) { + logger.debug("No Collections found. CollectionResourceCustomization list is empty."); + } else { + CollectionResourceCustomization collectionResourceCustomization = + findCatalogNetworkCollection(execution, service); + if (collectionResourceCustomization != null) { + resourceCounter.add(new Resource(WorkflowType.NETWORKCOLLECTION, + collectionResourceCustomization.getModelCustomizationUUID(), false)); + logger.debug("Found a network collection"); + if (collectionResourceCustomization.getCollectionResource() != null) { + if (collectionResourceCustomization.getCollectionResource().getInstanceGroup() != null) { + String toscaNodeType = collectionResourceCustomization.getCollectionResource() + .getInstanceGroup().getToscaNodeType(); + if (toscaNodeType != null && toscaNodeType.contains("NetworkCollection")) { + int minNetworks = 0; + org.onap.so.db.catalog.beans.InstanceGroup instanceGroup = + collectionResourceCustomization.getCollectionResource().getInstanceGroup(); + CollectionResourceInstanceGroupCustomization collectionInstCust = null; + if (!instanceGroup.getCollectionInstanceGroupCustomizations().isEmpty()) { + for (CollectionResourceInstanceGroupCustomization collectionInstanceGroupTemp : instanceGroup + .getCollectionInstanceGroupCustomizations()) { + if (collectionInstanceGroupTemp.getModelCustomizationUUID().equalsIgnoreCase( + collectionResourceCustomization.getModelCustomizationUUID())) { + collectionInstCust = collectionInstanceGroupTemp; break; } } - for (int i = 0; i < minNetworks; i++) { - if (collectionNetworkResourceCust != null && collectionInstCust != null) { - Resource resource = new Resource(WorkflowType.VIRTUAL_LINK, - collectionNetworkResourceCust.getModelCustomizationUUID(), false); - resource.setVirtualLinkKey(Integer.toString(i)); - resourceCounter.add(resource); - } + if (collectionInstCust != null + && collectionInstCust.getSubInterfaceNetworkQuantity() != null) { + minNetworks = collectionInstCust.getSubInterfaceNetworkQuantity(); + } + } + logger.debug("minNetworks: {}", minNetworks); + CollectionNetworkResourceCustomization collectionNetworkResourceCust = null; + for (CollectionNetworkResourceCustomization collectionNetworkTemp : instanceGroup + .getCollectionNetworkResourceCustomizations()) { + if (collectionNetworkTemp.getNetworkResourceCustomization() + .getModelCustomizationUUID().equalsIgnoreCase( + collectionResourceCustomization.getModelCustomizationUUID())) { + collectionNetworkResourceCust = collectionNetworkTemp; + break; + } + } + for (int i = 0; i < minNetworks; i++) { + if (collectionNetworkResourceCust != null && collectionInstCust != null) { + Resource resource = new Resource(WorkflowType.VIRTUAL_LINK, + collectionNetworkResourceCust.getModelCustomizationUUID(), false); + resource.setVirtualLinkKey(Integer.toString(i)); + resourceCounter.add(resource); } - } else { - logger.debug( - "Instance Group tosca node type does not contain NetworkCollection: {}", - toscaNodeType); } } else { - logger.debug("No Instance Group found for network collection."); + logger.debug("Instance Group tosca node type does not contain NetworkCollection: {}", + toscaNodeType); } } else { - logger.debug("No Network Collection found. collectionResource is null"); + logger.debug("No Instance Group found for network collection."); } } else { - logger.debug("No Network Collection Customization found"); + logger.debug("No Network Collection found. collectionResource is null"); } + } else { + logger.debug("No Network Collection Customization found"); } - if (resourceCounter.stream().filter(x -> WorkflowType.NETWORKCOLLECTION == x.getResourceType()) - .collect(Collectors.toList()).isEmpty()) { - if (service.getNetworkCustomizations() == null) { - logger.debug("No networks were found on this service model"); - } else { - for (int i = 0; i < service.getNetworkCustomizations().size(); i++) { - resourceCounter.add(new Resource(WorkflowType.NETWORK, - service.getNetworkCustomizations().get(i).getModelCustomizationUUID(), false)); - } + } + if (resourceCounter.stream().filter(x -> WorkflowType.NETWORKCOLLECTION == x.getResourceType()) + .collect(Collectors.toList()).isEmpty()) { + if (service.getNetworkCustomizations() == null) { + logger.debug("No networks were found on this service model"); + } else { + for (int i = 0; i < service.getNetworkCustomizations().size(); i++) { + resourceCounter.add(new Resource(WorkflowType.NETWORK, + service.getNetworkCustomizations().get(i).getModelCustomizationUUID(), false)); } } - } else { - buildAndThrowException(execution, - "Cannot orchestrate Service-Macro-Create without user params with a vnf. Please update ASDC model for new macro orchestration support or add service_recipe records to route to old macro flows"); } + } else { + buildAndThrowException(execution, + "Cannot orchestrate Service-Macro-Create without user params with a vnf. Please update ASDC model for new macro orchestration support or add service_recipe records to route to old macro flows"); } } @@ -759,7 +850,8 @@ public class WorkflowAction { aaiConfigurationResources.getConfiguration(config.getConfigurationId()); if (aaiConfig.isPresent() && aaiConfig.get().getRelationshipList() != null) { for (Relationship relationship : aaiConfig.get().getRelationshipList().getRelationship()) { - if (relationship.getRelatedTo().contains("vnfc")) { + if (relationship.getRelatedTo().contains("vnfc") + || relationship.getRelatedTo().contains("vpn-binding")) { aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.CONFIGURATION, config.getConfigurationId())); resourceCounter.add( @@ -1315,7 +1407,8 @@ public class WorkflowAction { WorkflowType resourceName, boolean aLaCarte, String cloudOwner, String serviceType) { List<OrchestrationFlow> listToExecute = new ArrayList<>(); NorthBoundRequest northBoundRequest = null; - if (serviceType.equalsIgnoreCase(SERVICE_TYPE_TRANSPORT)) { + if (serviceType.equalsIgnoreCase(SERVICE_TYPE_TRANSPORT) + || serviceType.equalsIgnoreCase(SERVICE_TYPE_BONDING)) { northBoundRequest = catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwnerAndServiceType( requestAction, resourceName.toString(), aLaCarte, cloudOwner, serviceType); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionExtractResourcesAAI.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionExtractResourcesAAI.java index 99ae2e7495..f672aa4b59 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionExtractResourcesAAI.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionExtractResourcesAAI.java @@ -22,18 +22,25 @@ package org.onap.so.bpmn.infrastructure.workflow.tasks; import java.util.List; import java.util.Optional; +import org.onap.aai.domain.yang.VpnBinding; import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; +import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; import org.onap.so.client.aai.AAIObjectType; import org.onap.so.client.aai.entities.AAIResultWrapper; import org.onap.so.client.aai.entities.Relationships; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component public class WorkflowActionExtractResourcesAAI { private static final Logger logger = LoggerFactory.getLogger(WorkflowActionExtractResourcesAAI.class); + @Autowired + protected BBInputSetupUtils bbInputSetupUtils; + public Optional<Configuration> extractRelationshipsConfiguration(Relationships relationships) { List<AAIResultWrapper> configurations = relationships.getByType(AAIObjectType.CONFIGURATION); for (AAIResultWrapper configWrapper : configurations) { @@ -45,6 +52,18 @@ public class WorkflowActionExtractResourcesAAI { return Optional.empty(); } + public Optional<VpnBinding> extractRelationshipsVpnBinding(Relationships relationships) { + List<AAIResourceUri> configurations = relationships.getRelatedUris(AAIObjectType.VPN_BINDING); + for (AAIResourceUri vpnBindingUri : configurations) { + AAIResultWrapper vpnBindingWrapper = bbInputSetupUtils.getAAIResourceDepthOne(vpnBindingUri); + Optional<VpnBinding> vpnBinding = vpnBindingWrapper.asBean(VpnBinding.class); + if (vpnBinding.isPresent()) { + return vpnBinding; + } + } + return Optional.empty(); + } + public Optional<Relationships> extractRelationshipsVnfc(Relationships relationships) { List<AAIResultWrapper> vnfcs = relationships.getByType(AAIObjectType.VNFC); for (AAIResultWrapper vnfcWrapper : vnfcs) { diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingClientResponseValidator.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingClientResponseValidator.java index 5bf531753e..214c0ac8fb 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingClientResponseValidator.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingClientResponseValidator.java @@ -44,6 +44,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; public class NamingClientResponseValidator { private static final Logger logger = LoggerFactory.getLogger(NamingClientResponseValidator.class); private static final String INSTANCE_GROUP_NAME = "instance-group-name"; + private static final String SERVICE_INSTANCE_NAME = "Service-Instance-Name"; private static final String NO_RESPONSE_FROM_NAMING_SERVICE = "Error did not receive a response from Naming Service."; private static final String NULL_RESPONSE_FROM_NAMING_SERVICE = @@ -80,6 +81,9 @@ public class NamingClientResponseValidator { if (INSTANCE_GROUP_NAME.equals(resourceName)) { generatedName = respElement.getResourceValue(); break; + } else if (SERVICE_INSTANCE_NAME.equals(resourceName)) { + generatedName = respElement.getResourceValue(); + break; } } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingRequestObject.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingRequestObject.java new file mode 100644 index 0000000000..14af6890f3 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingRequestObject.java @@ -0,0 +1,93 @@ +package org.onap.so.client.namingservice; + +import java.util.HashMap; + +public class NamingRequestObject { + + private HashMap<String, String> namingRequestMap = new HashMap<String, String>(); + + public HashMap<String, String> getNamingRequestObjectMap() { + return this.namingRequestMap; + } + + public String getExternalKeyValue() { + return namingRequestMap.get(NamingServiceConstants.NS_EXTERNAL_KEY); + } + + public void setExternalKeyValue(String externalKey) { + this.namingRequestMap.put(NamingServiceConstants.NS_EXTERNAL_KEY, externalKey); + } + + public String getPolicyInstanceNameValue() { + return this.namingRequestMap.get(NamingServiceConstants.NS_POLICY_INSTANCE_NAME); + } + + public void setPolicyInstanceNameValue(String policyInstanceName) { + this.namingRequestMap.put(NamingServiceConstants.NS_POLICY_INSTANCE_NAME, policyInstanceName); + } + + public String getNamingTypeValue() { + return namingRequestMap.get(NamingServiceConstants.NS_NAMING_TYPE); + } + + public void setNamingTypeValue(String namingType) { + this.namingRequestMap.put(NamingServiceConstants.NS_NAMING_TYPE, namingType); + } + + public String getResourceNameValue() { + return this.namingRequestMap.get(NamingServiceConstants.NS_RESOURCE_NAME); + } + + public void setResourceNameValue(String resourceName) { + namingRequestMap.put(NamingServiceConstants.NS_RESOURCE_NAME, resourceName); + } + + public String getNfNamingCodeValue() { + return this.namingRequestMap.get(NamingServiceConstants.NS_NF_NAMING_CODE); + } + + public void setNfNamingCodeValue(String nfNamingCode) { + this.namingRequestMap.put(NamingServiceConstants.NS_NF_NAMING_CODE, nfNamingCode); + } + + public String getServiceModelNameValue() { + return this.namingRequestMap.get(NamingServiceConstants.NS_SERVICE_MODEL_NAME); + } + + public void setServiceModelNameValue(String serviceModelName) { + this.namingRequestMap.put(NamingServiceConstants.NS_SERVICE_MODEL_NAME, serviceModelName); + } + + public String getModelVersionValue() { + return this.namingRequestMap.get(NamingServiceConstants.NS_MODEL_VERSION); + } + + public void setModelVersionValue(String modelVersion) { + this.namingRequestMap.put(NamingServiceConstants.NS_MODEL_VERSION, modelVersion); + } + + public String getNetworkNameValue() { + return this.namingRequestMap.get(NamingServiceConstants.NS_NETWORK_NAME); + } + + public void setNetworkNameValue(String networkName) { + this.namingRequestMap.put(NamingServiceConstants.NS_NETWORK_NAME, networkName); + } + + public String getVpnNameValue() { + return this.namingRequestMap.get(NamingServiceConstants.NS_VPN_NAME); + } + + public void setVpnNameValue(String vpnName) { + this.namingRequestMap.put(NamingServiceConstants.NS_VPN_NAME, vpnName); + } + + public String getZoneIdValue() { + return this.namingRequestMap.get(NamingServiceConstants.NS_ZONE_ID); + } + + public void setZoneIdValue(String zoneId) { + this.namingRequestMap.put(NamingServiceConstants.NS_ZONE_ID, zoneId); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingServiceConstants.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingServiceConstants.java new file mode 100644 index 0000000000..da9e449ee7 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingServiceConstants.java @@ -0,0 +1,21 @@ +package org.onap.so.client.namingservice; + +public class NamingServiceConstants { + public static final String NS_EXTERNAL_KEY = "external-key"; + public static final String NS_POLICY_INSTANCE_NAME = "policy-instance-name"; + public static final String NS_NAMING_TYPE = "naming-type"; + public static final String NS_RESOURCE_NAME = "resource-name"; + public static final String NS_NF_NAMING_CODE = "nf-naming-code"; + public static final String NS_SERVICE_MODEL_NAME = "service-model-name"; + public static final String NS_MODEL_VERSION = "model-version"; + public static final String NS_NETWORK_NAME = "network-name"; + public static final String NS_VPN_NAME = "vpn-name"; + public static final String NS_ZONE_ID = "zone-id"; + public static final String NS_RESOURCE_VALUE = "resource-value"; + + public static final String NAMING_TYPE_SERVICE = "SERVICE"; + public static final String RESOURCE_NAME_SERVICE_INSTANCE_NAME = "Service-Instance-Name"; + public static final String RESOURCE_NAME_SERVICEINSTANCE = "ServiceInstance"; + + private NamingServiceConstants() {} +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingServiceUtils.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingServiceUtils.java new file mode 100644 index 0000000000..771309abc4 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingServiceUtils.java @@ -0,0 +1,67 @@ +package org.onap.so.client.namingservice; + +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.exception.ExceptionBuilder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class NamingServiceUtils { + + private static String errorMessages = "Policy name is not present, or Onap name was not generated! "; + + @Autowired + private ExceptionBuilder exceptionUtil; + @Autowired + private ExtractPojosForBB extractPojosForBB; + + public void checkVpnBondingService(BuildingBlockExecution execution) { + execution.setVariable("isVpnBondingService", false); + boolean isNamingPolicyAndOnapGeneratedNaming = false; + checkBondingAndInfrastureVpn(execution); + boolean isBondingAndInsfrastructureVpn = execution.getVariable("isBondingAndInsfrastructureVpn"); + if (isBondingAndInsfrastructureVpn) { + checkNamingPolicyAndOnapGeneratedNaming(execution); + isNamingPolicyAndOnapGeneratedNaming = execution.getVariable("isNamingPolicyAndOnapGeneratedNaming"); + } + if (isBondingAndInsfrastructureVpn && isNamingPolicyAndOnapGeneratedNaming) { + execution.setVariable("isVpnBondingService", true); + } + } + + public void checkBondingAndInfrastureVpn(BuildingBlockExecution execution) { + execution.setVariable("isBondingAndInsfrastructureVpn", false); + try { + ServiceInstance serviceInstance = + extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); + if ("bonding".equalsIgnoreCase(serviceInstance.getModelInfoServiceInstance().getServiceType()) + && "infrastructure-vpn" + .equalsIgnoreCase(serviceInstance.getModelInfoServiceInstance().getServiceRole())) { + execution.setVariable("isBondingAndInsfrastructureVpn", true); + } + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + + public void checkNamingPolicyAndOnapGeneratedNaming(BuildingBlockExecution execution) { + execution.setVariable("isNamingPolicyAndOnapGeneratedNaming", false); + try { + ServiceInstance serviceInstance = + extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); + if (serviceInstance.getModelInfoServiceInstance().getNamingPolicy() != null + && !serviceInstance.getModelInfoServiceInstance().getNamingPolicy().isEmpty() + && serviceInstance.getModelInfoServiceInstance().getOnapGeneratedNaming() != null + && serviceInstance.getModelInfoServiceInstance().getOnapGeneratedNaming() == true) { + execution.setVariable("isNamingPolicyAndOnapGeneratedNaming", true); + } else { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, errorMessages); + } + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIConfigurationResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIConfigurationResources.java index 1453e40653..9eee0e607d 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIConfigurationResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIConfigurationResources.java @@ -79,7 +79,7 @@ public class AAIConfigurationResources { /** * A&AI call to disconnect configuration relation with service instance - * + * * @param configurationId * @param serviceInstanceId */ @@ -211,7 +211,7 @@ public class AAIConfigurationResources { /** * Get Configuration from AAI using related Link - * + * * @param relatedLink related link - URI * @return AAI Configuration object */ @@ -228,4 +228,13 @@ public class AAIConfigurationResources { org.onap.aai.domain.yang.Configuration aaiConfiguration = aaiObjectMapper.mapConfiguration(configuration); injectionHelper.getAaiClient().update(aaiResourceUri, aaiConfiguration); } + + public void updateConfigurationOrchestrationStatus(Configuration configuration, + OrchestrationStatus orchestrationStatus) { + AAIResourceUri aaiResourceUri = + AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, configuration.getConfigurationId()); + org.onap.aai.domain.yang.Configuration aaiConfiguration = new org.onap.aai.domain.yang.Configuration(); + aaiConfiguration.setOrchestrationStatus(orchestrationStatus.name()); + injectionHelper.getAaiClient().update(aaiResourceUri, aaiConfiguration); + } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/NamingServiceResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/NamingServiceResources.java index 06535bb765..5513122560 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/NamingServiceResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/NamingServiceResources.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP - SO * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Modifications Copyright (c) 2019 Samsung * ================================================================================ @@ -24,12 +24,14 @@ package org.onap.so.client.orchestration; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import org.onap.namingservice.model.Element; import org.onap.namingservice.model.Deleteelement; import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; import org.onap.so.client.exception.BadResponseException; import org.onap.so.client.namingservice.NamingClient; +import org.onap.so.client.namingservice.NamingRequestObject; import org.onap.so.client.namingservice.NamingRequestObjectBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -63,4 +65,25 @@ public class NamingServiceResources { return (namingClient .deleteNameGenRequest(namingRequestObjectBuilder.nameGenDeleteRequestMapper(deleteElements))); } + + public String generateServiceInstanceName(NamingRequestObject namingRequestObject) + throws BadResponseException, IOException { + HashMap<String, String> nsRequestObject = namingRequestObject.getNamingRequestObjectMap(); + Element element = new Element(); + nsRequestObject.forEach((k, v) -> element.put(k, v)); + List<Element> elements = new ArrayList<Element>(); + elements.add(element); + return (namingClient.postNameGenRequest(namingRequestObjectBuilder.nameGenRequestMapper(elements))); + } + + public String deleteServiceInstanceName(NamingRequestObject namingRequestObject) + throws BadResponseException, IOException { + HashMap<String, String> nsRequestObject = namingRequestObject.getNamingRequestObjectMap(); + Deleteelement delElement = new Deleteelement(); + nsRequestObject.forEach((k, v) -> delElement.setExternalKey(v)); + List<Deleteelement> delElements = new ArrayList<Deleteelement>(); + delElements.add(delElement); + return (namingClient.deleteNameGenRequest(namingRequestObjectBuilder.nameGenDeleteRequestMapper(delElements))); + } + } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/beans/Candidate.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/beans/Candidate.java index cded23aad2..3127275b24 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/beans/Candidate.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/beans/Candidate.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -36,6 +36,13 @@ public class Candidate implements Serializable { @JsonProperty("cloudOwner") private String cloudOwner; + public Candidate() {} + + public Candidate(CandidateType identifierType, List<String> identifiers, String cloudOwner) { + this.identifierType = identifierType; + this.identifiers = identifiers; + this.cloudOwner = cloudOwner; + } public CandidateType getIdentifierType() { return identifierType; diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/beans/Demand.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/beans/Demand.java index fe2b63ff92..0cc993560d 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/beans/Demand.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/beans/Demand.java @@ -40,6 +40,8 @@ public class Demand implements Serializable { private List<Candidate> excludedCandidates; @JsonProperty("existingCandidates") private List<Candidate> existingCandidates; + @JsonProperty("filteringAttributes") + private List<Candidate> filteringAttributes; public List<Candidate> getRequiredCandidates() { @@ -90,4 +92,12 @@ public class Demand implements Serializable { this.existingCandidates = existingCandidates; } + public List<Candidate> getFilteringAttributes() { + return filteringAttributes; + } + + public void setFilteringAttributes(List<Candidate> filteringAttributes) { + this.filteringAttributes = filteringAttributes; + } + } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java index b40e43b959..39efa6dc76 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java @@ -35,6 +35,7 @@ import org.onap.so.client.aai.mapper.AAIObjectMapper; import org.onap.so.client.adapter.network.mapper.NetworkAdapterObjectMapper; import org.onap.so.client.appc.ApplicationControllerAction; import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.client.namingservice.NamingRequestObject; import org.onap.so.client.orchestration.AAICollectionResources; import org.onap.so.client.orchestration.AAIConfigurationResources; import org.onap.so.client.orchestration.AAIInstanceGroupResources; @@ -150,4 +151,8 @@ public abstract class BaseTaskTest extends TestDataSetup { @Mock protected Environment env; + + @Mock + protected NamingRequestObject namingRequestObject; + } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2IT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2IT.java index b5a8318ce9..7b6ba6b8fd 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2IT.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2IT.java @@ -110,13 +110,13 @@ public class SniroHomingV2IT extends BaseIntegrationTest { public void beforeServiceProxy() { ServiceProxy sp = setServiceProxy("1", "infrastructure"); - Candidate requiredCandidate = new Candidate(); - requiredCandidate.setIdentifierType(CandidateType.CLOUD_REGION_ID); + Candidate filteringAttributes = new Candidate(); + filteringAttributes.setIdentifierType(CandidateType.CLOUD_REGION_ID); List<String> c = new ArrayList<String>(); c.add("testCloudRegionId"); - requiredCandidate.setCloudOwner("att"); - requiredCandidate.setIdentifiers(c); - sp.addRequiredCandidates(requiredCandidate); + filteringAttributes.setCloudOwner("att"); + filteringAttributes.setIdentifiers(c); + sp.getFilteringAttributes().add(filteringAttributes); serviceInstance.getServiceProxies().add(sp); } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceCreateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceCreateTasksTest.java index f5785f94fd..3f62a61518 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceCreateTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceCreateTasksTest.java @@ -22,31 +22,50 @@ package org.onap.so.bpmn.infrastructure.namingservice.tasks; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.util.Optional; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.aai.domain.yang.Zone; import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; +import org.onap.so.client.aai.AAICommonObjectMapperProvider; +import org.onap.so.client.aai.entities.AAIResultWrapper; +import org.onap.so.client.aai.entities.Relationships; import org.onap.so.client.exception.BBObjectNotFoundException; public class NamingServiceCreateTasksTest extends BaseTaskTest { @InjectMocks - private NamingServiceCreateTasks namingServiceCreateTasks = new NamingServiceCreateTasks(); + private NamingServiceCreateTasks namingServiceCreateTasks; + + @Mock + private BBInputSetupUtils MOCK_bbInputSetupUtils; private InstanceGroup instanceGroup; + private ServiceInstance serviceInstance; @Before public void before() throws BBObjectNotFoundException { instanceGroup = setInstanceGroup(); when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.INSTANCE_GROUP_ID))) .thenReturn(instanceGroup); + serviceInstance = setServiceInstance(); + when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID))) + .thenReturn(serviceInstance); } @Test @@ -80,7 +99,62 @@ public class NamingServiceCreateTasksTest extends BaseTaskTest { namingServiceCreateTasks.createInstanceGroupName(execution); verify(namingServiceResources, times(1)).generateInstanceGroupName(instanceGroup, policyInstanceName, nfNamingCode); + } + @Test + public void createWanTransportServiceNameTest() throws Exception { + String generatedName = "generatedWanTransportServiceName"; + doReturn(generatedName).when(namingServiceResources).generateServiceInstanceName(any()); + NamingServiceCreateTasks spy = Mockito.spy(namingServiceCreateTasks); + doReturn("testZoneId").when(spy).getRelatedZoneId(any()); + spy.createWanTransportServiceName(execution); + verify(namingServiceResources, times(1)).generateServiceInstanceName(any()); + assertEquals(generatedName, serviceInstance.getServiceInstanceName()); } + @Test + public void createVpnBondingServiceNameTest() throws Exception { + when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.NETWORK_ID))) + .thenReturn(buildL3Network()); + when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VPN_ID))) + .thenReturn(buildVpnBinding()); + String generatedName = "generatedWanTransportServiceName"; + doReturn(generatedName).when(namingServiceResources).generateServiceInstanceName(any()); + namingServiceCreateTasks.createVpnBondingServiceName(execution); + verify(namingServiceResources, times(1)).generateServiceInstanceName(any()); + assertEquals(generatedName, serviceInstance.getServiceInstanceName()); + } + + @Test + public void getRelatedZoneIdTest() throws Exception { + + String zoneId = "zoneId"; + Zone zone = new Zone(); + zone.setZoneId(zoneId); + + CloudRegion cloudRegion = new CloudRegion(); + cloudRegion.setCloudOwner("testCloudOwner"); + cloudRegion.setLcpCloudRegionId("testLcpCloudRegionId"); + GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock(); + gBBInput.setCloudRegion(cloudRegion); + + AAIResultWrapper cloudRegionWrapper = + new AAIResultWrapper(new AAICommonObjectMapperProvider().getMapper().writeValueAsString(cloudRegion)); + + Relationships relationships = Mockito.mock(Relationships.class); + relationships.getAll().add(cloudRegionWrapper); + Optional<Relationships> relationshipsOp = Optional.of(relationships); + + doReturn(cloudRegionWrapper).when(MOCK_bbInputSetupUtils).getAAIResourceDepthOne(any()); + + NamingServiceCreateTasks spy = Mockito.spy(namingServiceCreateTasks); + + doReturn(relationshipsOp).when(spy).getRelationshipsFromWrapper(isA(AAIResultWrapper.class)); + doReturn(zone).when(spy).getRelatedZone(any()); + spy.setBbInputSetupUtils(MOCK_bbInputSetupUtils); + + String returnedZoneId = spy.getRelatedZoneId(execution); + + assertEquals(zoneId, returnedZoneId); + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceDeleteTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceDeleteTasksTest.java index 758b8f4ffd..32550a5467 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceDeleteTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceDeleteTasksTest.java @@ -21,6 +21,7 @@ package org.onap.so.bpmn.infrastructure.namingservice.tasks; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.times; @@ -32,14 +33,17 @@ import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.client.exception.BBObjectNotFoundException; +import org.onap.so.client.namingservice.NamingRequestObject; public class NamingServiceDeleteTasksTest extends BaseTaskTest { @InjectMocks private NamingServiceDeleteTasks namingServiceDeleteTasks = new NamingServiceDeleteTasks(); private InstanceGroup instanceGroup; + private ServiceInstance serviceInstance; @Before public void before() throws BBObjectNotFoundException { @@ -68,4 +72,15 @@ public class NamingServiceDeleteTasksTest extends BaseTaskTest { verify(namingServiceResources, times(1)).deleteInstanceGroupName(instanceGroup); } + @Test + public void deleteServiceInstanceNameTest() throws Exception { + serviceInstance = setServiceInstance(); + when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID))) + .thenReturn(serviceInstance); + doNothing().when(namingRequestObject).setExternalKeyValue(serviceInstance.getServiceInstanceId()); + doReturn("").when(namingServiceResources).deleteServiceInstanceName(namingRequestObject); + namingServiceDeleteTasks.deleteServiceInstanceName(execution); + verify(namingServiceResources, times(1)).deleteServiceInstanceName(any(NamingRequestObject.class)); + } + } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/VrfValidationTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/VrfValidationTest.java new file mode 100644 index 0000000000..526ebe8581 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/VrfValidationTest.java @@ -0,0 +1,177 @@ +package org.onap.so.bpmn.infrastructure.workflow.tasks; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doReturn; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.InjectMocks; +import org.mockito.Mockito; +import org.onap.aai.domain.yang.AggregateRoute; +import org.onap.aai.domain.yang.AggregateRoutes; +import org.onap.aai.domain.yang.L3Network; +import org.onap.aai.domain.yang.RouteTarget; +import org.onap.aai.domain.yang.RouteTargets; +import org.onap.aai.domain.yang.Subnet; +import org.onap.aai.domain.yang.Subnets; +import org.onap.aai.domain.yang.VpnBinding; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.client.aai.AAIObjectType; +import org.onap.so.client.aai.entities.AAIResultWrapper; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization; +import org.onap.so.db.catalog.beans.Service; +import org.onap.so.db.catalog.beans.ServiceProxyResourceCustomization; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class VrfValidationTest extends BaseTaskTest { + + protected ObjectMapper mapper = new ObjectMapper(); + + @InjectMocks + protected VrfValidation vrfValidation; + + @Rule + public ExpectedException exceptionRule = ExpectedException.none(); + + @Before + public void before() throws Exception { + vrfValidation.setBbInputSetupUtils(bbSetupUtils); + } + + @Test + public void testVrfServiceValidation() throws VrfBondingServiceException { + Service service = new Service(); + service.setModelName("modelName"); + service.setServiceType("BONDING"); + service.setServiceRole("VPN"); + exceptionRule.expect(VrfBondingServiceException.class); + exceptionRule.expectMessage( + "Service: modelName does not have service type of BONDING and does not have service role of INFRASTRUCTURE-VPN"); + vrfValidation.vrfServiceValidation(service); + + service.setServiceType("BOND"); + service.setServiceRole("INFRASTRUCTURE-VPN"); + exceptionRule.expect(VrfBondingServiceException.class); + exceptionRule.expectMessage( + "Service: modelName does not have service type of BONDING and does not have service role of INFRASTRUCTURE-VPN"); + vrfValidation.vrfServiceValidation(service); + + service.setServiceType("BONDING"); + service.setServiceRole("INFRASTRUCTURE-VPN"); + ExpectedException.none(); + vrfValidation.vrfServiceValidation(service); + } + + @Test + public void testVrfCatalogDbChecks() throws VrfBondingServiceException { + Service service = new Service(); + service.setModelName("modelName"); + ConfigurationResourceCustomization configuration = new ConfigurationResourceCustomization(); + service.setConfigurationCustomizations(new ArrayList<>()); + service.getConfigurationCustomizations().add(configuration); + ServiceProxyResourceCustomization serviceProxy = new ServiceProxyResourceCustomization(); + configuration.setServiceProxyResourceCustomization(serviceProxy); + service.setServiceProxyCustomizations(new ArrayList<>()); + service.getServiceProxyCustomizations().add(serviceProxy); + Service sourceService = new Service(); + sourceService.setServiceType("TRANSPORT"); + serviceProxy.setSourceService(sourceService); + configuration.setType("VRF-ENTRY"); + configuration.setRole("INFRASTRUCTURE-CLOUD-VPN"); + ExpectedException.none(); + vrfValidation.vrfCatalogDbChecks(service); + } + + @Test + public void testAaiVpnBindingValidation() throws VrfBondingServiceException { + org.onap.aai.domain.yang.VpnBinding aaiVpnBinding = new org.onap.aai.domain.yang.VpnBinding(); + aaiVpnBinding.setVpnType("SERVICE-INFRASTRUCTURE"); + ExpectedException.none(); + vrfValidation.aaiVpnBindingValidation(aaiVpnBinding); + } + + @Test + public void testAaiAggregateRouteValidation() throws VrfBondingServiceException { + org.onap.aai.domain.yang.L3Network aaiLocalNetwork = new org.onap.aai.domain.yang.L3Network(); + aaiLocalNetwork.setAggregateRoutes(new AggregateRoutes()); + aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().add(new AggregateRoute()); + aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().get(0).setIpVersion("4"); + ExpectedException.none(); + vrfValidation.aaiAggregateRouteValidation(aaiLocalNetwork); + + aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().add(new AggregateRoute()); + aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().get(1).setIpVersion("6"); + ExpectedException.none(); + vrfValidation.aaiAggregateRouteValidation(aaiLocalNetwork); + + aaiLocalNetwork.setAggregateRoutes(null); + ExpectedException.none(); + vrfValidation.aaiAggregateRouteValidation(aaiLocalNetwork); + } + + @Test + public void testAaiSubnetValidation() throws VrfBondingServiceException { + org.onap.aai.domain.yang.L3Network aaiLocalNetwork = new org.onap.aai.domain.yang.L3Network(); + aaiLocalNetwork.setNetworkId("myNetworkID"); + aaiLocalNetwork.setSubnets(new Subnets()); + aaiLocalNetwork.getSubnets().getSubnet().add(new Subnet()); + aaiLocalNetwork.getSubnets().getSubnet().get(0).setIpVersion("4"); + ExpectedException.none(); + vrfValidation.aaiSubnetValidation(aaiLocalNetwork); + + aaiLocalNetwork.getSubnets().getSubnet().add(new Subnet()); + aaiLocalNetwork.getSubnets().getSubnet().get(1).setIpVersion("6"); + ExpectedException.none(); + vrfValidation.aaiSubnetValidation(aaiLocalNetwork); + + aaiLocalNetwork.setSubnets(null); + exceptionRule.expect(VrfBondingServiceException.class); + exceptionRule.expectMessage("LocalNetwork: myNetworkID has no subnets"); + vrfValidation.aaiSubnetValidation(aaiLocalNetwork); + } + + @Test + public void testIpVersionValidation() { + String ipVersion1 = "4"; + String ipVersion2 = "6"; + boolean validation = vrfValidation.ipVersionValidation(ipVersion1, ipVersion2); + assertEquals("Validation is correct", true, validation); + + + validation = vrfValidation.ipVersionValidation(ipVersion2, ipVersion1); + assertEquals("Validation is correct", true, validation); + + ipVersion1 = "6"; + validation = vrfValidation.ipVersionValidation(ipVersion1, ipVersion2); + assertEquals("Validation is correct", false, validation); + } + + @Test + public void testAaiRouteTargetValidation() + throws VrfBondingServiceException, JsonParseException, JsonMappingException, IOException { + L3Network l3Network = mapper.readValue( + new File("src/test/resources/__files/BuildingBlocks/aaiNetworkWrapper.json"), L3Network.class); + AAIResultWrapper networkWrapper = new AAIResultWrapper(l3Network); + if (networkWrapper.getRelationships().isPresent()) { + List<AAIResourceUri> vpnBindingUris = + networkWrapper.getRelationships().get().getRelatedUris(AAIObjectType.VPN_BINDING); + VpnBinding vpnBinding = new VpnBinding(); + vpnBinding.setRouteTargets(new RouteTargets()); + vpnBinding.getRouteTargets().getRouteTarget().add(new RouteTarget()); + AAIResultWrapper wrapper = Mockito.mock(AAIResultWrapper.class); + doReturn(wrapper).when(bbSetupUtils).getAAIResourceDepthOne(vpnBindingUris.get(0)); + doReturn(Optional.of(vpnBinding)).when(wrapper).asBean(VpnBinding.class); + ExpectedException.none(); + vrfValidation.aaiRouteTargetValidation(l3Network); + } + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java index ad1238b86f..10d36f9527 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java @@ -22,6 +22,7 @@ package org.onap.so.bpmn.infrastructure.workflow.tasks; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.*; @@ -45,6 +46,7 @@ import java.util.UUID; import org.camunda.bpm.engine.delegate.BpmnError; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.javatuples.Pair; import org.junit.Before; import org.junit.Ignore; import org.junit.Rule; @@ -1584,7 +1586,8 @@ public class WorkflowActionTest extends BaseTaskTest { ServiceInstancesRequest sIRequest = mapper.readValue(bpmnRequest, ServiceInstancesRequest.class); List<Resource> resourceCounter = new ArrayList<>(); thrown.expect(BpmnError.class); - workflowAction.traverseCatalogDbService(execution, sIRequest, resourceCounter); + List<Pair<WorkflowType, String>> aaiResourceIds = new ArrayList<>(); + workflowAction.traverseCatalogDbService(execution, sIRequest, resourceCounter, aaiResourceIds); } @Test @@ -1672,6 +1675,72 @@ public class WorkflowActionTest extends BaseTaskTest { assertNotNull(result); } + @Test + public void traverseAAIServiceTest() { + List<Resource> resourceCounter = new ArrayList<>(); + String resourceId = "si0"; + List<Pair<WorkflowType, String>> aaiResourceIds = new ArrayList<>(); + + ServiceInstance serviceInstanceAAI = new ServiceInstance(); + serviceInstanceAAI.setServiceInstanceId(resourceId); + + org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstance = setServiceInstance(); + setGenericVnf(); + setVfModule(true); + setVolumeGroup(); + setL3Network(); + setCollection(); + setConfiguration(); + + Configuration config = new Configuration(); + config.setConfigurationId("testConfigurationId2"); + serviceInstance.getConfigurations().add(config); + + Relationship relationship1 = new Relationship(); + relationship1.setRelatedTo("vnfc"); + RelationshipList relationshipList1 = new RelationshipList(); + relationshipList1.getRelationship().add(relationship1); + + Relationship relationship2 = new Relationship(); + relationship2.setRelatedTo("vpn-binding"); + RelationshipList relationshipList2 = new RelationshipList(); + relationshipList2.getRelationship().add(relationship2); + + org.onap.aai.domain.yang.Configuration aaiConfiguration1 = new org.onap.aai.domain.yang.Configuration(); + aaiConfiguration1.setConfigurationId("testConfigurationId"); + aaiConfiguration1.setRelationshipList(relationshipList1); + + org.onap.aai.domain.yang.Configuration aaiConfiguration2 = new org.onap.aai.domain.yang.Configuration(); + aaiConfiguration2.setConfigurationId("testConfigurationId2"); + aaiConfiguration2.setRelationshipList(relationshipList1); + + try { + doReturn(serviceInstanceAAI).when(bbSetupUtils).getAAIServiceInstanceById(resourceId); + doReturn(serviceInstance).when(bbInputSetup).getExistingServiceInstance(serviceInstanceAAI); + doReturn(Optional.of(aaiConfiguration1)).when(aaiConfigurationResources) + .getConfiguration("testConfigurationId"); + doReturn(Optional.of(aaiConfiguration2)).when(aaiConfigurationResources) + .getConfiguration("testConfigurationId2"); + workflowAction.traverseAAIService(execution, resourceCounter, resourceId, aaiResourceIds); + assertEquals(8, resourceCounter.size()); + assertThat(aaiResourceIds, sameBeanAs(getExpectedResourceIds())); + } catch (Exception e) { + fail("Unexpected exception was thrown."); + } + } + + private List<Pair<WorkflowType, String>> getExpectedResourceIds() { + List<Pair<WorkflowType, String>> resourceIds = new ArrayList<>(); + resourceIds.add(new Pair<WorkflowType, String>(WorkflowType.VNF, "testVnfId1")); + resourceIds.add(new Pair<WorkflowType, String>(WorkflowType.VFMODULE, "testVfModuleId1")); + resourceIds.add(new Pair<WorkflowType, String>(WorkflowType.VOLUMEGROUP, "testVolumeGroupId1")); + resourceIds.add(new Pair<WorkflowType, String>(WorkflowType.NETWORK, "testNetworkId1")); + resourceIds.add(new Pair<WorkflowType, String>(WorkflowType.NETWORKCOLLECTION, "testId")); + resourceIds.add(new Pair<WorkflowType, String>(WorkflowType.CONFIGURATION, "testConfigurationId")); + resourceIds.add(new Pair<WorkflowType, String>(WorkflowType.CONFIGURATION, "testConfigurationId2")); + return resourceIds; + } + private List<OrchestrationFlow> createFlowList(String... flowNames) { List<OrchestrationFlow> result = new ArrayList<>(); for (String flowName : flowNames) { diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingClientResponseValidatorTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingClientResponseValidatorTest.java index f50916c0be..f7fd00a673 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingClientResponseValidatorTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingClientResponseValidatorTest.java @@ -36,6 +36,7 @@ public class NamingClientResponseValidatorTest extends TestDataSetup { private NamingClientResponseValidator responseValidator = new NamingClientResponseValidator(); private String instanceGroupName = "generatedInstanceGroupName"; + private String serviceInstanceName = "generatedServiceInstanceName"; @Test public void validateNameGenResponseSuccessTest() throws BadResponseException { @@ -54,6 +55,22 @@ public class NamingClientResponseValidatorTest extends TestDataSetup { } @Test + public void validateServiceInstanceNameGenResponseSuccessTest() throws BadResponseException { + NameGenResponse name = new NameGenResponse(); + Respelement respElement = new Respelement(); + respElement.setResourceName("Service-Instance-Name"); + respElement.setResourceValue(serviceInstanceName); + List<Respelement> respList = new ArrayList<Respelement>(); + respList.add(respElement); + name.setElements(respList); + ResponseEntity<NameGenResponse> resp = new ResponseEntity<>(name, null, HttpStatus.OK); + + String actual = responseValidator.validateNameGenResponse(resp); + + assertEquals(actual, "generatedServiceInstanceName"); + } + + @Test public void validateNameGenResponseNoNameGeneratedTest() throws BadResponseException { NameGenResponse name = new NameGenResponse(); Respelement respElement = new Respelement(); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingRequestObjectTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingRequestObjectTest.java new file mode 100644 index 0000000000..49f858d2ce --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingRequestObjectTest.java @@ -0,0 +1,85 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.namingservice; + +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.junit.Assert.assertThat; +import java.util.HashMap; +import org.junit.Test; +import org.onap.namingservice.model.Element; + +public class NamingRequestObjectTest { + + private String externalKey = "95cbbe59-1017-4c13-b4e8-d824e54def3e"; + private String policyInstanceName = "MSO_Policy.Config_MS_VNFInstanceGroup"; + private String namingType = "Service"; + private String nfNamingCode = "NamingCode"; + private String resourceName = "resourceName"; + private String serviceModelName = "serviceModelName"; + private String modelVersion = "modelVersion"; + private String zoneId = "zoneId"; + + @Test + public void namingRequestObjectTest() { + + Element expected = new Element(); + expected.put(NamingServiceConstants.NS_EXTERNAL_KEY, externalKey); + expected.put(NamingServiceConstants.NS_POLICY_INSTANCE_NAME, policyInstanceName); + expected.put(NamingServiceConstants.NS_NAMING_TYPE, namingType); + expected.put(NamingServiceConstants.NS_RESOURCE_NAME, resourceName); + expected.put(NamingServiceConstants.NS_NF_NAMING_CODE, nfNamingCode); + + NamingRequestObject namingRequestObject = new NamingRequestObject(); + namingRequestObject.setExternalKeyValue(externalKey); + namingRequestObject.setPolicyInstanceNameValue(policyInstanceName); + namingRequestObject.setNamingTypeValue(namingType); + namingRequestObject.setNfNamingCodeValue(nfNamingCode); + namingRequestObject.setResourceNameValue(resourceName); + + HashMap<String, String> actual = namingRequestObject.getNamingRequestObjectMap(); + assertThat(actual, sameBeanAs(expected)); + } + + @Test + public void namingWanTransportRequestObjectTest() { + + Element expected = new Element(); + expected.put(NamingServiceConstants.NS_EXTERNAL_KEY, externalKey); + expected.put(NamingServiceConstants.NS_POLICY_INSTANCE_NAME, policyInstanceName); + expected.put(NamingServiceConstants.NS_NAMING_TYPE, namingType); + expected.put(NamingServiceConstants.NS_RESOURCE_NAME, resourceName); + expected.put(NamingServiceConstants.NS_SERVICE_MODEL_NAME, serviceModelName); + expected.put(NamingServiceConstants.NS_MODEL_VERSION, modelVersion); + expected.put(NamingServiceConstants.NS_ZONE_ID, zoneId); + + NamingRequestObject namingRequestObject = new NamingRequestObject(); + namingRequestObject.setExternalKeyValue(externalKey); + namingRequestObject.setPolicyInstanceNameValue(policyInstanceName); + namingRequestObject.setNamingTypeValue(namingType); + namingRequestObject.setResourceNameValue(resourceName); + namingRequestObject.setModelVersionValue(modelVersion); + namingRequestObject.setServiceModelNameValue(serviceModelName); + namingRequestObject.setZoneIdValue(zoneId); + + HashMap<String, String> actual = namingRequestObject.getNamingRequestObjectMap(); + assertThat(actual, sameBeanAs(expected)); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingRequestUtilsTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingRequestUtilsTest.java new file mode 100644 index 0000000000..5fdb790405 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingRequestUtilsTest.java @@ -0,0 +1,136 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.namingservice; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.when; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentMatchers; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance; +import org.onap.so.client.exception.BBObjectNotFoundException; + +public class NamingRequestUtilsTest extends BaseTaskTest { + + @Mock + private ServiceInstance serviceInstanceMock; + + @Mock + ModelInfoServiceInstance modelInfoServiceInstanceMock; + + @InjectMocks + private NamingServiceUtils namingServiceUtils = new NamingServiceUtils(); + + @Before + public void before() throws BBObjectNotFoundException { + when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID))) + .thenReturn(serviceInstanceMock); + doReturn(modelInfoServiceInstanceMock).when(serviceInstanceMock).getModelInfoServiceInstance(); + } + + @Test + public void checkVpnBondingServiceTest() { + doReturn("bonding").when(modelInfoServiceInstanceMock).getServiceType(); + doReturn("infrastructure-vpn").when(modelInfoServiceInstanceMock).getServiceRole(); + doReturn("testNaminPolicy").when(modelInfoServiceInstanceMock).getNamingPolicy(); + doReturn(true).when(modelInfoServiceInstanceMock).getOnapGeneratedNaming(); + namingServiceUtils.checkVpnBondingService(execution); + assertTrue(execution.getVariable("isVpnBondingService")); + + doReturn("bonding-false").when(modelInfoServiceInstanceMock).getServiceType(); + doReturn("infrastructure-vpn").when(modelInfoServiceInstanceMock).getServiceRole(); + namingServiceUtils.checkVpnBondingService(execution); + assertFalse(execution.getVariable("isVpnBondingService")); + } + + @Test + public void checkBondingAndInfrastureVpnTrueTest() { + doReturn("bonding").when(modelInfoServiceInstanceMock).getServiceType(); + doReturn("infrastructure-vpn").when(modelInfoServiceInstanceMock).getServiceRole(); + namingServiceUtils.checkBondingAndInfrastureVpn(execution); + assertTrue(execution.getVariable("isBondingAndInsfrastructureVpn")); + } + + @Test + public void checkBondingAndInfrastureVpnFalse1Test() { + doReturn("falseBonding").when(modelInfoServiceInstanceMock).getServiceType(); + doReturn("infrastructure-vpn").when(modelInfoServiceInstanceMock).getServiceRole(); + namingServiceUtils.checkBondingAndInfrastureVpn(execution); + assertFalse(execution.getVariable("isBondingAndInsfrastructureVpn")); + } + + @Test + public void checkBondingAndInfrastureVpnFalse2Test() { + doReturn("bonding").when(modelInfoServiceInstanceMock).getServiceType(); + doReturn("false-infrastructure-vpn").when(modelInfoServiceInstanceMock).getServiceRole(); + namingServiceUtils.checkBondingAndInfrastureVpn(execution); + assertFalse(execution.getVariable("isBondingAndInsfrastructureVpn")); + } + + @Test + public void checkNamingPolicyAndAndEcompGeneratedNaming_TrueTest() { + doReturn("testNaminPolicy").when(modelInfoServiceInstanceMock).getNamingPolicy(); + doReturn(true).when(modelInfoServiceInstanceMock).getOnapGeneratedNaming(); + namingServiceUtils.checkNamingPolicyAndOnapGeneratedNaming(execution); + assertTrue(execution.getVariable("isNamingPolicyAndOnapGeneratedNaming")); + } + + @Test + public void checkNamingPolicyAndAndEcompGeneratedNamingFalse1Test() throws BBObjectNotFoundException { + doReturn(null).when(modelInfoServiceInstanceMock).getNamingPolicy(); + doReturn(true).when(modelInfoServiceInstanceMock).getOnapGeneratedNaming(); + namingServiceUtils.checkNamingPolicyAndOnapGeneratedNaming(execution); + assertFalse(execution.getVariable("isNamingPolicyAndOnapGeneratedNaming")); + } + + @Test + public void checkNamingPolicyAndAndEcompGeneratedNamingFalse2Test() throws BBObjectNotFoundException { + doReturn("testNaminPolicy").when(modelInfoServiceInstanceMock).getNamingPolicy(); + doReturn(false).when(modelInfoServiceInstanceMock).getOnapGeneratedNaming(); + namingServiceUtils.checkNamingPolicyAndOnapGeneratedNaming(execution); + assertFalse(execution.getVariable("isNamingPolicyAndOnapGeneratedNaming")); + } + + @Test + public void checkNamingPolicyAndAndEcompGeneratedNamingFalse3Test() throws BBObjectNotFoundException { + doReturn("").when(modelInfoServiceInstanceMock).getNamingPolicy(); + doReturn(false).when(modelInfoServiceInstanceMock).getOnapGeneratedNaming(); + namingServiceUtils.checkNamingPolicyAndOnapGeneratedNaming(execution); + assertFalse(execution.getVariable("isNamingPolicyAndOnapGeneratedNaming")); + } + + @Test + public void checkNamingPolicyAndAndEcompGeneratedNamingFalse4Test() throws BBObjectNotFoundException { + doReturn("bonding").when(modelInfoServiceInstanceMock).getNamingPolicy(); + doReturn(null).when(modelInfoServiceInstanceMock).getOnapGeneratedNaming(); + namingServiceUtils.checkNamingPolicyAndOnapGeneratedNaming(execution); + assertFalse(execution.getVariable("isNamingPolicyAndOnapGeneratedNaming")); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIConfigurationResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIConfigurationResourcesTest.java index be58ccb046..91d9070c0f 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIConfigurationResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIConfigurationResourcesTest.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -231,4 +231,13 @@ public class AAIConfigurationResourcesTest extends TestDataSetup { verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class), ArgumentMatchers.isNull()); assertEquals(OrchestrationStatus.ACTIVE, configuration.getOrchestrationStatus()); } + + @Test + public void updateConfigurationOrchestrationStatusTest() throws Exception { + doNothing().when(MOCK_aaiResourcesClient).update(isA(AAIResourceUri.class), + isA(org.onap.aai.domain.yang.Configuration.class)); + aaiConfigurationResources.updateConfigurationOrchestrationStatus(configuration, OrchestrationStatus.ACTIVE); + verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class), + any(org.onap.aai.domain.yang.Configuration.class)); + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/NamingServiceResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/NamingServiceResourcesTest.java index 195c89a651..1f5b42b94e 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/NamingServiceResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/NamingServiceResourcesTest.java @@ -42,7 +42,9 @@ import org.onap.namingservice.model.NameGenRequest; import org.onap.namingservice.model.NameGenResponse; import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; import org.onap.so.client.namingservice.NamingClient; +import org.onap.so.client.namingservice.NamingRequestObject; import org.onap.so.client.namingservice.NamingRequestObjectBuilder; +import org.onap.so.client.namingservice.NamingServiceConstants; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -100,5 +102,25 @@ public class NamingServiceResourcesTest extends TestDataSetup { } + @Test + public void generateServiceInstanceNameTest() throws Exception { + + NameGenRequest req = new NameGenRequest(); + doReturn("generatedServiceInstanceName").when(MOCK_namingClient).postNameGenRequest(isA(NameGenRequest.class)); + doReturn(req).when(MOCK_namingRequestObjectBuilder).nameGenRequestMapper(isA(List.class)); + NamingRequestObject nrObject = new NamingRequestObject(); + nrObject.setExternalKeyValue("testExternalKey"); + nrObject.setNamingTypeValue(NamingServiceConstants.NAMING_TYPE_SERVICE); + nrObject.setResourceNameValue(NamingServiceConstants.RESOURCE_NAME_SERVICE_INSTANCE_NAME); + nrObject.setPolicyInstanceNameValue(execution.getVariable("policyInstanceName")); + nrObject.setServiceModelNameValue("testServiceInstanceModelName"); + nrObject.setModelVersionValue("testServiceInstanceModelVersion"); + nrObject.setZoneIdValue(execution.getVariable("zoneId")); + + String generatedName = namingServiceResources.generateServiceInstanceName(nrObject); + + verify(MOCK_namingClient, times(1)).postNameGenRequest(any(NameGenRequest.class)); + assertEquals("generatedServiceInstanceName", generatedName); + } } diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest1SP.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest1SP.json index 27463350ab..31e6fd5f53 100644 --- a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest1SP.json +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest1SP.json @@ -32,7 +32,7 @@ "modelVersion" : "testProxyModelVersion1", "modelInvariantId" : "testProxyModelInvariantUuid1" }, - "requiredCandidates" : [ { + "filteringAttributes" : [ { "identifierType" : "cloudRegionId", "identifiers" : [ "testCloudRegionId" ], "cloudOwner" : "att" diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/aaiNetworkWrapper.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/aaiNetworkWrapper.json new file mode 100644 index 0000000000..aaa2c4ba35 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/aaiNetworkWrapper.json @@ -0,0 +1,42 @@ +{ + "networkId": "0384d743-f69b-4cc8-9aa8-c3ae66662c44", + "networkName": "Dev_Bindings_1802_020118", + "networkType": "CONTRAIL30_BASIC", + "networkRole": "GN_EVPN_direct", + "networkTechnology": "contrail", + "neutronNetworkId": "1112b912-0e00-4d6d-9392-014e106399ee", + "isBoundToVpn": true, + "serviceId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", + "networkRoleInstance": 0, + "resourceVersion": "1517496965485", + "orchestrationStatus": "Active", + "heatStackId": "Dev_Bindings_1802_020118/06c2445f-1ca1-4ad8-be08-454c4de443bb", + "contrailNetworkFqdn": "default-domain:ECOMP_MSO_DND:Dev_Bindings_1802_020118", + "physicalNetworkName": "tbd", + "isProviderNetwork": false, + "isSharedNetwork": true, + "isExternalNetwork": false, + "relationshipList": { + "relationship": [ + { + "relatedTo": "vpn-binding", + "relatedLink": "/aai/v11/network/vpn-bindings/vpn-binding/9a7b327d9-287aa00-82c4b0-100001", + "relationshipData": [ + { + "relationshipKey": "vpn-binding.vpn-id", + "relationshipValue": "9a7b327d9-287aa00-82c4b0-100001" + } + ], + "relatedToProperty": [ + { + "propertyKey": "vpn-binding.vpn-name", + "propertyValue": "MSO_VPN_TEST" + }, + { + "propertyKey": "vpn-binding.vpn-type" + } + ] + } + ] + } +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/CreateNetworkCollection.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/CreateNetworkCollection.json index 579075f502..692ecfdf75 100644 --- a/bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/CreateNetworkCollection.json +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/CreateNetworkCollection.json @@ -4,7 +4,7 @@ "modelType": "service", "modelInvariantId": "5d48acb5-097d-4982-aeb2-f4a3bd87d31b", "modelVersionId": "3c40d244-808e-42ca-b09a-256d83d19d0a", - "modelName": "MOW AVPN vMX BV vPE 1 Service", + "modelName": "Sample Service Model", "modelVersion": "10" }, "cloudConfiguration": { @@ -35,7 +35,7 @@ { "service": { "modelInfo": { - "modelName": "MOW AVPN vMX BV vPE 1 Service", + "modelName": "Sample Service Model", "modelVersionId": "3c40d244-808e-42ca-b09a-256d83d19d0a" }, "instanceParams": [], diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/ServiceMacroActivateDeleteUnassign.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/ServiceMacroActivateDeleteUnassign.json index 26838024da..5753f69d3f 100644 --- a/bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/ServiceMacroActivateDeleteUnassign.json +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/ServiceMacroActivateDeleteUnassign.json @@ -4,7 +4,7 @@ "modelType": "service", "modelInvariantId": "5d48acb5-097d-4982-aeb2-f4a3bd87d31b", "modelVersionId": "3c40d244-808e-42ca-b09a-256d83d19d0a", - "modelName": "MOW AVPN vMX BV vPE 1 Service", + "modelName": "Sample Service Model", "modelVersion": "10.0" }, "cloudConfiguration": { diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/ServiceMacroAssign.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/ServiceMacroAssign.json index ddb118ea49..39e87f19f1 100644 --- a/bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/ServiceMacroAssign.json +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/ServiceMacroAssign.json @@ -4,7 +4,7 @@ "modelType": "service", "modelInvariantId": "5d48acb5-097d-4982-aeb2-f4a3bd87d31b", "modelVersionId": "3c40d244-808e-42ca-b09a-256d83d19d0a", - "modelName": "MOW AVPN vMX BV vPE 1 Service", + "modelName": "Sample Service Model", "modelVersion": "10.0" }, "cloudConfiguration": { @@ -34,7 +34,7 @@ "service": { "modelInfo": { "modelType": "service", - "modelName": "MOW AVPN vMX BV vPE 1 Service", + "modelName": "Sample Service Model", "modelVersionId": "3c40d244-808e-42ca-b09a-256d83d19d0a" }, "instanceParams": [], diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/ServiceMacroAssignNoCloud.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/ServiceMacroAssignNoCloud.json index 51caddd48a..b86a2a28f6 100644 --- a/bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/ServiceMacroAssignNoCloud.json +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/ServiceMacroAssignNoCloud.json @@ -4,7 +4,7 @@ "modelType": "service", "modelInvariantId": "5d48acb5-097d-4982-aeb2-f4a3bd87d31b", "modelVersionId": "3c40d244-808e-42ca-b09a-256d83d19d0a", - "modelName": "MOW AVPN vMX BV vPE 1 Service", + "modelName": "Sample Service Model", "modelVersion": "10.0" }, "owningEntity": { @@ -31,7 +31,7 @@ "service": { "modelInfo": { "modelType": "service", - "modelName": "MOW AVPN vMX BV vPE 1 Service", + "modelName": "Sample Service Model", "modelVersionId": "3c40d244-808e-42ca-b09a-256d83d19d0a" }, "instanceParams": [], |