From edd8f30798d42f26ca6f23d7883f88f2c246760b Mon Sep 17 00:00:00 2001 From: Marcin Rzepecki Date: Mon, 29 Mar 2021 15:24:42 +0200 Subject: SO refactor - extract Workflow type Service Issue-ID: SO-3581 Signed-off-by: Marcin Rzepecki Change-Id: I5bbe63371045333213542c275e763ac7305369a1 --- .../workflow/tasks/UserParamsServiceTraversal.java | 274 ------------ .../workflow/tasks/VrfValidation.java | 163 ------- .../workflow/tasks/WorkflowAction.java | 431 +----------------- .../workflow/tasks/WorkflowActionConstants.java | 10 +- .../tasks/ebb/loader/ServiceEBBLoader.java | 485 +++++++++++++++++++++ .../ebb/loader/UserParamsServiceTraversal.java | 276 ++++++++++++ .../workflow/tasks/ebb/loader/VrfValidation.java | 164 +++++++ .../tasks/UserParamsServiceTraversalTest.java | 219 ---------- .../workflow/tasks/VrfValidationTest.java | 219 ---------- .../workflow/tasks/WorkflowActionTest.java | 30 +- .../ebb/loader/UserParamsServiceTraversalTest.java | 221 ++++++++++ .../tasks/ebb/loader/VrfValidationTest.java | 220 ++++++++++ 12 files changed, 1398 insertions(+), 1314 deletions(-) delete mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/UserParamsServiceTraversal.java delete mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/VrfValidation.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoader.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/UserParamsServiceTraversal.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VrfValidation.java delete mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/UserParamsServiceTraversalTest.java delete mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/VrfValidationTest.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/UserParamsServiceTraversalTest.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VrfValidationTest.java diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/UserParamsServiceTraversal.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/UserParamsServiceTraversal.java deleted file mode 100644 index 3a7dd5772f..0000000000 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/UserParamsServiceTraversal.java +++ /dev/null @@ -1,274 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Modifications Copyright (c) 2019 Samsung - * ================================================================================ - * Modifications Copyright (c) 2020 Nokia - * ================================================================================ - * Modifications Copyright (c) 2020 Tech Mahindra - * ================================================================================ - * 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.bpmn.infrastructure.workflow.tasks; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.camunda.bpm.engine.delegate.DelegateExecution; -import org.onap.so.client.exception.ExceptionBuilder; -import org.onap.so.db.catalog.beans.CollectionResourceCustomization; -import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization; -import org.onap.so.db.catalog.beans.CvnfcCustomization; -import org.onap.so.db.catalog.beans.VfModuleCustomization; -import org.onap.so.db.catalog.client.CatalogDbClient; -import org.onap.so.serviceinstancebeans.Networks; -import org.onap.so.serviceinstancebeans.Pnfs; -import org.onap.so.serviceinstancebeans.Service; -import org.onap.so.serviceinstancebeans.VfModules; -import org.onap.so.serviceinstancebeans.Vnfs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.CREATE_INSTANCE; -import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.FABRIC_CONFIGURATION; -import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.USER_PARAM_SERVICE; -import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.WORKFLOW_ACTION_ERROR_MESSAGE; - -@Component -public class UserParamsServiceTraversal { - - private static final Logger logger = LoggerFactory.getLogger(UserParamsServiceTraversal.class); - - private final CatalogDbClient catalogDbClient; - private final ExceptionBuilder exceptionBuilder; - private boolean foundVfModuleOrVG; - private String vnfCustomizationUUID; - private String vfModuleCustomizationUUID; - - UserParamsServiceTraversal(CatalogDbClient catalogDbClient, ExceptionBuilder exceptionBuilder) { - this.catalogDbClient = catalogDbClient; - this.exceptionBuilder = exceptionBuilder; - } - - protected List getResourceListFromUserParams(DelegateExecution execution, - List> userParams, String serviceModelVersionId, String requestAction) - throws IOException { - if (userParams != null) { - for (Map params : userParams) { - if (params.containsKey(USER_PARAM_SERVICE)) { - ObjectMapper obj = new ObjectMapper(); - String input = obj.writeValueAsString(params.get(USER_PARAM_SERVICE)); - Service validate = obj.readValue(input, Service.class); - return getResourceList(execution, serviceModelVersionId, requestAction, validate); - } - } - } - return Collections.emptyList(); - } - - private List getResourceList(DelegateExecution execution, String serviceModelVersionId, - String requestAction, Service validate) { - List resourceList = new ArrayList<>(); - resourceList.add(new Resource(WorkflowType.SERVICE, validate.getModelInfo().getModelVersionId(), false)); - if (validate.getResources().getVnfs() != null) { - setResourceListForVnfs(execution, resourceList, validate); - } - if (validate.getResources().getPnfs() != null) { - setResourceListForPnfs(resourceList, validate); - } - if (validate.getResources().getNetworks() != null) { - setResourceListForNetworks(execution, serviceModelVersionId, requestAction, resourceList, validate); - } - return resourceList; - } - - private void setResourceListForVnfs(DelegateExecution execution, List resourceList, Service validate) { - for (Vnfs vnf : validate.getResources().getVnfs()) { - setVnfCustomizationUUID(vnf); - resourceList.add(new Resource(WorkflowType.VNF, vnf.getModelInfo().getModelCustomizationId(), false)); - setResourceListForVfModules(execution, resourceList, validate, vnf); - } - } - - private void setResourceListForVfModules(DelegateExecution execution, List resourceList, Service validate, - Vnfs vnf) { - if (vnf.getVfModules() != null) { - for (VfModules vfModule : vnf.getVfModules()) { - setVfModuleCustomizationUUID(vfModule); - VfModuleCustomization vfModuleCustomization = - catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID(vfModuleCustomizationUUID); - if (vfModuleCustomization != null && vfModuleCustomization.getVfModule() != null) { - setVolumeGroupWorkFlowTypeToResourceList(resourceList, vfModuleCustomization); - setVfModuleAndConfigurationWorkFlowTypeToResourceList(resourceList, validate, vnf, vfModule, - vfModuleCustomization); - if (!foundVfModuleOrVG) { - buildAndThrowException(execution, - "Could not determine if vfModule was a vfModule or volume group. Heat template and Heat env are null"); - } - } - } - } - } - - private void setVolumeGroupWorkFlowTypeToResourceList(List resourceList, - VfModuleCustomization vfModuleCustomization) { - if (vfModuleCustomization.getVfModule().getVolumeHeatTemplate() != null - && vfModuleCustomization.getVolumeHeatEnv() != null) { - foundVfModuleOrVG = true; - resourceList.add( - new Resource(WorkflowType.VOLUMEGROUP, vfModuleCustomization.getModelCustomizationUUID(), false)); - } - } - - private void setVfModuleAndConfigurationWorkFlowTypeToResourceList(List resourceList, Service validate, - Vnfs vnf, VfModules vfModule, VfModuleCustomization vfModuleCustomization) { - if ((vfModuleCustomization.getVfModule().getModuleHeatTemplate() != null - && vfModuleCustomization.getHeatEnvironment() != null) - || (vfModuleCustomization.getVfModule().getModelName() != null - && vfModuleCustomization.getVfModule().getModelName().contains("helm"))) { - foundVfModuleOrVG = true; - Resource resource = setVfModuleWorkFlowTypeToResourceList(resourceList, vfModuleCustomization); - setConfigurationWorkFlowTypeToResourceList(resourceList, validate, vnf, vfModule, resource); - } - } - - private Resource setVfModuleWorkFlowTypeToResourceList(List resourceList, - VfModuleCustomization vfModuleCustomization) { - Resource resource = - new Resource(WorkflowType.VFMODULE, vfModuleCustomization.getModelCustomizationUUID(), false); - resource.setBaseVfModule(vfModuleCustomization.getVfModule().getIsBase() != null - && vfModuleCustomization.getVfModule().getIsBase()); - resourceList.add(resource); - return resource; - } - - private void setConfigurationWorkFlowTypeToResourceList(List resourceList, Service validate, Vnfs vnf, - VfModules vfModule, Resource resource) { - if (!vnfCustomizationUUID.isEmpty() && !vfModuleCustomizationUUID.isEmpty()) { - List configs = - traverseCatalogDbForConfiguration(validate.getModelInfo().getModelVersionId()); - for (CvnfcConfigurationCustomization config : configs) { - Resource configResource = new Resource(WorkflowType.CONFIGURATION, - config.getConfigurationResource().getModelUUID(), false); - resource.setVnfCustomizationId(vnf.getModelInfo().getModelCustomizationId()); - resource.setVfModuleCustomizationId(vfModule.getModelInfo().getModelCustomizationId()); - resourceList.add(configResource); - } - } - } - - private void setVfModuleCustomizationUUID(VfModules vfModule) { - if (vfModule.getModelInfo() != null && vfModule.getModelInfo().getModelCustomizationUuid() != null) { - vfModuleCustomizationUUID = vfModule.getModelInfo().getModelCustomizationUuid(); - } else { - vfModuleCustomizationUUID = ""; - } - } - - private void setVnfCustomizationUUID(Vnfs vnf) { - if (vnf.getModelInfo() != null && vnf.getModelInfo().getModelCustomizationUuid() != null) { - vnfCustomizationUUID = vnf.getModelInfo().getModelCustomizationUuid(); - } else { - vnfCustomizationUUID = ""; - } - } - - private void setResourceListForPnfs(List resourceList, Service validate) { - for (Pnfs pnf : validate.getResources().getPnfs()) { - resourceList.add(new Resource(WorkflowType.PNF, pnf.getModelInfo().getModelCustomizationId(), false)); - } - } - - private void setResourceListForNetworks(DelegateExecution execution, String serviceModelVersionId, - String requestAction, List resourceList, Service validate) { - for (Networks network : validate.getResources().getNetworks()) { - resourceList - .add(new Resource(WorkflowType.NETWORK, network.getModelInfo().getModelCustomizationId(), false)); - } - if (requestAction.equals(CREATE_INSTANCE)) { - String networkColCustId = queryCatalogDbForNetworkCollection(execution, serviceModelVersionId); - if (networkColCustId != null) { - resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, networkColCustId, false)); - } - } - } - - - private List traverseCatalogDbForConfiguration(String serviceModelUUID) { - try { - List cvnfcCustomizations = catalogDbClient.getCvnfcCustomization(serviceModelUUID, - vnfCustomizationUUID, vfModuleCustomizationUUID); - return getCvnfcConfigurationCustomizations(cvnfcCustomizations); - } catch (Exception ex) { - logger.error("Error in finding configurations", ex); - return Collections.emptyList(); - } - } - - private List getCvnfcConfigurationCustomizations( - List cvnfcCustomizations) { - List configurations = new ArrayList<>(); - for (CvnfcCustomization cvnfc : cvnfcCustomizations) { - for (CvnfcConfigurationCustomization customization : cvnfc.getCvnfcConfigurationCustomization()) { - if (customization.getConfigurationResource().getToscaNodeType().contains(FABRIC_CONFIGURATION)) { - configurations.add(customization); - } - } - } - logger.debug("found {} fabric configuration(s)", configurations.size()); - return configurations; - } - - private String queryCatalogDbForNetworkCollection(DelegateExecution execution, String serviceModelVersionId) { - org.onap.so.db.catalog.beans.Service service = catalogDbClient.getServiceByID(serviceModelVersionId); - if (service != null) { - CollectionResourceCustomization networkCollection = this.findCatalogNetworkCollection(execution, service); - if (networkCollection != null) { - return networkCollection.getModelCustomizationUUID(); - } - } - return null; - } - - private CollectionResourceCustomization findCatalogNetworkCollection(DelegateExecution execution, - org.onap.so.db.catalog.beans.Service service) { - CollectionResourceCustomization networkCollection = null; - int count = 0; - for (CollectionResourceCustomization collectionCustom : service.getCollectionResourceCustomizations()) { - if (catalogDbClient.getNetworkCollectionResourceCustomizationByID( - collectionCustom.getModelCustomizationUUID()) != null) { - networkCollection = collectionCustom; - count++; - } - } - if (count > 1) { - buildAndThrowException(execution, - "Found multiple Network Collections in the Service model, only one per Service is supported."); - } - return networkCollection; - } - - private void buildAndThrowException(DelegateExecution execution, String msg) { - logger.error(msg); - execution.setVariable(WORKFLOW_ACTION_ERROR_MESSAGE, msg); - exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg); - } -} 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 deleted file mode 100644 index 304cb9f4b4..0000000000 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/VrfValidation.java +++ /dev/null @@ -1,163 +0,0 @@ -/*- - * ============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.bpmn.infrastructure.workflow.tasks; - -import java.util.List; -import java.util.Optional; -import org.onap.aai.domain.yang.L3Network; -import org.onap.aaiclient.client.aai.entities.AAIResultWrapper; -import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; -import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; -import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; -import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization; -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(String relatedVpnId, org.onap.aai.domain.yang.VpnBinding aaiVpnBinding) - throws VrfBondingServiceException { - if (aaiVpnBinding == null) { - throw new VrfBondingServiceException("The infrastructure vpn " + relatedVpnId + " does not exist in A&AI."); - } else if (aaiVpnBinding.getVpnType() != null - && !aaiVpnBinding.getVpnType().equalsIgnoreCase("SERVICE-INFRASTRUCTURE")) { - throw new VrfBondingServiceException( - "VpnBinding: " + relatedVpnId + " does not have a vpn type of SERVICE-INFRASTRUCTURE."); - } - } - - 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 aaiNetworkValidation(String relatedNetworkid, org.onap.aai.domain.yang.L3Network aaiLocalNetwork) - throws VrfBondingServiceException { - if (aaiLocalNetwork == null) { - throw new VrfBondingServiceException("The local network " + relatedNetworkid + " does not exist in A&AI."); - } - } - - 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 vpnBindingUris = - networkWrapper.getRelationships().get().getRelatedUris(Types.VPN_BINDING); - if (!vpnBindingUris.isEmpty()) { - Optional 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 bc8f8cc822..29206a6aa9 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 @@ -30,11 +30,9 @@ import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConst import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.CONTROLLER; import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.CREATE_INSTANCE; import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.FABRIC_CONFIGURATION; -import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.NETWORKCOLLECTION; import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.REPLACEINSTANCE; import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.REPLACEINSTANCERETAINASSIGNMENTS; import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.SERVICE; -import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.USER_PARAM_SERVICE; import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.WORKFLOW_ACTION_ERROR_MESSAGE; import java.io.IOException; import java.util.ArrayList; @@ -50,12 +48,8 @@ import java.util.stream.Collectors; import org.apache.commons.lang3.SerializationUtils; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.javatuples.Pair; -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.aaiclient.client.aai.AAICommonObjectMapperProvider; import org.onap.aaiclient.client.aai.AAIObjectName; import org.onap.aaiclient.client.aai.entities.AAIResultWrapper; import org.onap.aaiclient.client.aai.entities.Relationships; @@ -64,22 +58,16 @@ import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; import org.onap.so.bpmn.common.BBConstants; +import org.onap.so.bpmn.infrastructure.workflow.tasks.ebb.loader.ServiceEBBLoader; import org.onap.so.bpmn.infrastructure.workflow.tasks.ebb.loader.VnfEBBLoader; import org.onap.so.bpmn.infrastructure.workflow.tasks.excpetion.VnfcMultipleRelationshipException; import org.onap.so.bpmn.infrastructure.workflow.tasks.utils.WorkflowResourceIdsUtils; -import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; -import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds; import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup; import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; import org.onap.so.client.exception.ExceptionBuilder; -import org.onap.so.client.orchestration.AAIConfigurationResources; import org.onap.so.client.orchestration.AAIEntityNotFoundException; -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.InstanceGroup; import org.onap.so.db.catalog.beans.VfModuleCustomization; import org.onap.so.db.catalog.beans.macro.NorthBoundRequest; import org.onap.so.db.catalog.beans.macro.OrchestrationFlow; @@ -97,7 +85,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @Component @@ -131,21 +118,15 @@ public class WorkflowAction { @Autowired private CatalogDbClient catalogDbClient; @Autowired - private AAIConfigurationResources aaiConfigurationResources; - @Autowired - private WorkflowActionExtractResourcesAAI workflowActionUtils; - @Autowired - private VrfValidation vrfValidation; - @Autowired private Environment environment; @Autowired - private UserParamsServiceTraversal userParamsServiceTraversal; - @Autowired private AaiResourceIdValidator aaiResourceIdValidator; @Autowired private ExecuteBuildingBlockBuilder executeBuildingBlockBuilder; @Autowired private VnfEBBLoader vnfEBBLoader; + @Autowired + private ServiceEBBLoader serviceEBBLoader; public void setBbInputSetupUtils(BBInputSetupUtils bbInputSetupUtils) { this.bbInputSetupUtils = bbInputSetupUtils; @@ -295,52 +276,12 @@ public class WorkflowAction { String cloudOwner, String serviceType, String requestId, String apiVersion, String vnfType, RequestDetails requestDetails) throws IOException, VrfBondingServiceException { List flowsToExecute; - boolean containsService = false; List resourceList = new ArrayList<>(); List> aaiResourceIds = new ArrayList<>(); - List> userParams = sIRequest.getRequestDetails().getRequestParameters().getUserParams(); - if (resourceType == WorkflowType.SERVICE && requestAction.equalsIgnoreCase(ASSIGNINSTANCE)) { - // SERVICE-MACRO-ASSIGN will always get user params with a - // service. - - if (userParams != null) { - containsService = isContainsService(sIRequest); - if (containsService) { - resourceList = userParamsServiceTraversal.getResourceListFromUserParams(execution, userParams, - serviceInstanceId, requestAction); - } - } else { - buildAndThrowException(execution, - "Service-Macro-Assign request details must contain user params with a service"); - } - } else if (resourceType == WorkflowType.SERVICE && requestAction.equalsIgnoreCase(CREATE_INSTANCE)) { - // SERVICE-MACRO-CREATE will get user params with a service, - // a service with a network, a service with a - // network collection, OR an empty service. - // If user params is just a service or null and macro - // queries the SI and finds a VNF, macro fails. - - if (userParams != null) { - containsService = isContainsService(sIRequest); - } - if (containsService) { - resourceList = userParamsServiceTraversal.getResourceListFromUserParams(execution, userParams, - serviceInstanceId, requestAction); - } - if (!foundRelated(resourceList)) { - traverseCatalogDbService(execution, sIRequest, resourceList, aaiResourceIds); - } - } else if (resourceType == WorkflowType.SERVICE && ("activateInstance".equalsIgnoreCase(requestAction) - || "unassignInstance".equalsIgnoreCase(requestAction) - || "deleteInstance".equalsIgnoreCase(requestAction) - || requestAction.equalsIgnoreCase("activate" + FABRIC_CONFIGURATION))) { - // SERVICE-MACRO-ACTIVATE, SERVICE-MACRO-UNASSIGN, and - // SERVICE-MACRO-DELETE - // Will never get user params with service, macro will have - // to query the SI in AAI to find related instances. - traverseAAIService(execution, resourceList, resourceId, aaiResourceIds); - } else if (resourceType == WorkflowType.SERVICE && "deactivateInstance".equalsIgnoreCase(requestAction)) { - resourceList.add(new Resource(WorkflowType.SERVICE, "", false)); + + if (resourceType == WorkflowType.SERVICE) { + resourceList = serviceEBBLoader.getResourceListForService(sIRequest, requestAction, execution, + serviceInstanceId, resourceId, aaiResourceIds); } else if (resourceType == WorkflowType.VNF && (REPLACEINSTANCE.equalsIgnoreCase(requestAction) || ("recreateInstance".equalsIgnoreCase(requestAction)))) { vnfEBBLoader.traverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(), @@ -370,7 +311,7 @@ public class WorkflowAction { } flowsToExecute = executeBuildingBlockBuilder.buildExecuteBuildingBlockList(orchFlows, resourceList, requestId, apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, vnfReplace); - if (isNetworkCollectionInTheResourceList(resourceList)) { + if (serviceEBBLoader.isNetworkCollectionInTheResourceList(resourceList)) { logger.info("Sorting for Vlan Tagging"); flowsToExecute = sortExecutionPathByObjectForVlanTagging(flowsToExecute, requestAction); } @@ -400,13 +341,6 @@ public class WorkflowAction { execution.setVariable("isRollbackComplete", false); } - private boolean isContainsService(ServiceInstancesRequest sIRequest) { - boolean containsService; - List> userParams = sIRequest.getRequestDetails().getRequestParameters().getUserParams(); - containsService = userParams.stream().anyMatch(param -> param.containsKey(USER_PARAM_SERVICE)); - return containsService; - } - private List loadExecuteBuildingBlocks(DelegateExecution execution, String requestId, String errorMessage) { List flowsToExecute; @@ -699,8 +633,6 @@ public class WorkflowAction { return orchFlows; } - - private void updateResourceIdsFromAAITraversal(List flowsToExecute, List resourceList, List> aaiResourceIds, String serviceInstanceId) { for (Pair pair : aaiResourceIds) { @@ -759,342 +691,6 @@ public class WorkflowAction { } } - protected CollectionResourceCustomization findCatalogNetworkCollection(DelegateExecution execution, - org.onap.so.db.catalog.beans.Service service) { - CollectionResourceCustomization networkCollection = null; - int count = 0; - for (CollectionResourceCustomization collectionCust : service.getCollectionResourceCustomizations()) { - if (catalogDbClient.getNetworkCollectionResourceCustomizationByID( - collectionCust.getModelCustomizationUUID()) != null) { - networkCollection = collectionCust; - count++; - } - } - if (count == 0) { - return null; - } else if (count > 1) { - buildAndThrowException(execution, - "Found multiple Network Collections in the Service model, only one per Service is supported."); - } - return networkCollection; - } - - protected void traverseCatalogDbService(DelegateExecution execution, ServiceInstancesRequest sIRequest, - List resourceList, List> aaiResourceIds) - throws JsonProcessingException, VrfBondingServiceException { - 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 { - resourceList.add(new Resource(WorkflowType.SERVICE, service.getModelUUID(), false)); - RelatedInstance relatedVpnBinding = - bbInputSetupUtils.getRelatedInstanceByType(sIRequest.getRequestDetails(), ModelType.vpnBinding); - RelatedInstance relatedLocalNetwork = - bbInputSetupUtils.getRelatedInstanceByType(sIRequest.getRequestDetails(), ModelType.network); - - if (relatedVpnBinding != null && relatedLocalNetwork != null) { - traverseVrfConfiguration(aaiResourceIds, resourceList, service, relatedVpnBinding, relatedLocalNetwork); - } else { - traverseNetworkCollection(execution, resourceList, service); - } - } - } - - protected void traverseVrfConfiguration(List> aaiResourceIds, - List resourceList, org.onap.so.db.catalog.beans.Service service, - RelatedInstance relatedVpnBinding, RelatedInstance relatedLocalNetwork) - throws VrfBondingServiceException, JsonProcessingException { - org.onap.aai.domain.yang.L3Network aaiLocalNetwork = - bbInputSetupUtils.getAAIL3Network(relatedLocalNetwork.getInstanceId()); - vrfValidation.vrfServiceValidation(service); - vrfValidation.vrfCatalogDbChecks(service); - vrfValidation.aaiVpnBindingValidation(relatedVpnBinding.getInstanceId(), - bbInputSetupUtils.getAAIVpnBinding(relatedVpnBinding.getInstanceId())); - vrfValidation.aaiNetworkValidation(relatedLocalNetwork.getInstanceId(), aaiLocalNetwork); - vrfValidation.aaiSubnetValidation(aaiLocalNetwork); - vrfValidation.aaiAggregateRouteValidation(aaiLocalNetwork); - vrfValidation.aaiRouteTargetValidation(aaiLocalNetwork); - String existingAAIVrfConfiguration = getExistingAAIVrfConfiguration(relatedVpnBinding, aaiLocalNetwork); - if (existingAAIVrfConfiguration != null) { - aaiResourceIds.add(new Pair<>(WorkflowType.CONFIGURATION, existingAAIVrfConfiguration)); - } - resourceList.add(new Resource(WorkflowType.CONFIGURATION, - service.getConfigurationCustomizations().get(0).getModelCustomizationUUID(), false)); - - } - - protected String getExistingAAIVrfConfiguration(RelatedInstance relatedVpnBinding, - org.onap.aai.domain.yang.L3Network aaiLocalNetwork) - throws JsonProcessingException, VrfBondingServiceException { - Optional relationshipsOp = new AAIResultWrapper( - new AAICommonObjectMapperProvider().getMapper().writeValueAsString(aaiLocalNetwork)).getRelationships(); - if (relationshipsOp.isPresent()) { - List configurationsRelatedToLocalNetwork = - relationshipsOp.get().getByType(Types.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 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 ("VRF-ENTRY".equalsIgnoreCase(vrfConfiguration.getConfigurationType())) { - Optional relationshipsConfigOp = configWrapper.getRelationships(); - if (relationshipsConfigOp.isPresent()) { - Optional 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 resourceList, - org.onap.so.db.catalog.beans.Service service) { - if (isVnfCustomizationsInTheService(service)) { - 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"); - } - if (isPnfCustomizationsInTheService(service)) { - buildAndThrowException(execution, - "Cannot orchestrate Service-Macro-Create without user params with a pnf. Please update ASDC model for new macro orchestration support or add service_recipe records to route to old macro flows"); - } - List customizations = service.getCollectionResourceCustomizations(); - if (customizations.isEmpty()) { - logger.debug("No Collections found. CollectionResourceCustomization list is empty."); - } else { - CollectionResourceCustomization collectionResourceCustomization = - findCatalogNetworkCollection(execution, service); - traverseNetworkCollectionResourceCustomization(resourceList, collectionResourceCustomization); - } - traverseNetworkCollectionCustomization(resourceList, service); - } - - private void traverseNetworkCollectionResourceCustomization(List resourceList, - CollectionResourceCustomization collectionResourceCustomization) { - if (collectionResourceCustomizationShouldNotBeProcessed(resourceList, collectionResourceCustomization)) - return; - 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 (interfaceNetworkQuantityIsAvailableInCollection(collectionInstCust)) { - minNetworks = collectionInstCust.getSubInterfaceNetworkQuantity(); - } - } - logger.debug("minNetworks: {}", minNetworks); - CollectionNetworkResourceCustomization collectionNetworkResourceCust = - getCollectionNetworkResourceCustomization(collectionResourceCustomization, instanceGroup); - for (int i = 0; i < minNetworks; i++) { - if (collectionNetworkResourceCust != null) { - Resource resource = new Resource(WorkflowType.VIRTUAL_LINK, - collectionNetworkResourceCust.getModelCustomizationUUID(), false); - resource.setVirtualLinkKey(Integer.toString(i)); - resourceList.add(resource); - } - } - } - - private CollectionNetworkResourceCustomization getCollectionNetworkResourceCustomization( - CollectionResourceCustomization collectionResourceCustomization, InstanceGroup instanceGroup) { - CollectionNetworkResourceCustomization collectionNetworkResourceCust = null; - for (CollectionNetworkResourceCustomization collectionNetworkTemp : instanceGroup - .getCollectionNetworkResourceCustomizations()) { - if (collectionNetworkTemp.getNetworkResourceCustomization().getModelCustomizationUUID() - .equalsIgnoreCase(collectionResourceCustomization.getModelCustomizationUUID())) { - collectionNetworkResourceCust = collectionNetworkTemp; - break; - } - } - return collectionNetworkResourceCust; - } - - private boolean collectionResourceCustomizationShouldNotBeProcessed(List resourceList, - CollectionResourceCustomization collectionResourceCustomization) { - if (collectionResourceCustomization == null) { - logger.debug("No Network Collection Customization found"); - return true; - } - resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, - collectionResourceCustomization.getModelCustomizationUUID(), false)); - logger.debug("Found a network collection"); - if (collectionResourceCustomization.getCollectionResource() == null) { - logger.debug("No Network Collection found. collectionResource is null"); - return true; - } - if (collectionResourceCustomization.getCollectionResource().getInstanceGroup() == null) { - logger.debug("No Instance Group found for network collection."); - return true; - } - String toscaNodeType = - collectionResourceCustomization.getCollectionResource().getInstanceGroup().getToscaNodeType(); - if (!toscaNodeTypeHasNetworkCollection(toscaNodeType)) { - logger.debug("Instance Group tosca node type does not contain NetworkCollection: {}", toscaNodeType); - return true; - } - return false; - } - - private boolean interfaceNetworkQuantityIsAvailableInCollection( - CollectionResourceInstanceGroupCustomization collectionInstCust) { - return collectionInstCust != null && collectionInstCust.getSubInterfaceNetworkQuantity() != null; - } - - private boolean toscaNodeTypeHasNetworkCollection(String toscaNodeType) { - return toscaNodeType != null && toscaNodeType.contains(NETWORKCOLLECTION); - } - - private void traverseNetworkCollectionCustomization(List resourceList, - org.onap.so.db.catalog.beans.Service service) { - if (isNetworkCollectionInTheResourceList(resourceList)) { - return; - } - if (service.getNetworkCustomizations() == null) { - logger.debug("No networks were found on this service model"); - return; - } - for (int i = 0; i < service.getNetworkCustomizations().size(); i++) { - resourceList.add(new Resource(WorkflowType.NETWORK, - service.getNetworkCustomizations().get(i).getModelCustomizationUUID(), false)); - } - } - - private boolean isNetworkCollectionInTheResourceList(List resourceList) { - return resourceList.stream().anyMatch(x -> WorkflowType.NETWORKCOLLECTION == x.getResourceType()); - } - - private boolean isVnfCustomizationsInTheService(org.onap.so.db.catalog.beans.Service service) { - return !(service.getVnfCustomizations() == null || service.getVnfCustomizations().isEmpty()); - } - - private boolean isPnfCustomizationsInTheService(org.onap.so.db.catalog.beans.Service service) { - return !(service.getPnfCustomizations() == null || service.getPnfCustomizations().isEmpty()); - } - - protected void traverseAAIService(DelegateExecution execution, List resourceList, String resourceId, - List> aaiResourceIds) { - try { - ServiceInstance serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceById(resourceId); - org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO = - bbInputSetup.getExistingServiceInstance(serviceInstanceAAI); - resourceList.add(new Resource(WorkflowType.SERVICE, serviceInstanceMSO.getServiceInstanceId(), false)); - traverseServiceInstanceMSOVnfs(resourceList, aaiResourceIds, serviceInstanceMSO); - traverseServiceInstanceMSOPnfs(resourceList, aaiResourceIds, serviceInstanceMSO); - if (serviceInstanceMSO.getNetworks() != null) { - for (org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network network : serviceInstanceMSO - .getNetworks()) { - aaiResourceIds.add(new Pair<>(WorkflowType.NETWORK, network.getNetworkId())); - resourceList.add(new Resource(WorkflowType.NETWORK, network.getNetworkId(), false)); - } - } - if (serviceInstanceMSO.getCollection() != null) { - logger.debug("found networkcollection"); - aaiResourceIds - .add(new Pair<>(WorkflowType.NETWORKCOLLECTION, serviceInstanceMSO.getCollection().getId())); - resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, - serviceInstanceMSO.getCollection().getId(), false)); - } - if (serviceInstanceMSO.getConfigurations() != null) { - for (Configuration config : serviceInstanceMSO.getConfigurations()) { - Optional aaiConfig = - aaiConfigurationResources.getConfiguration(config.getConfigurationId()); - if (aaiConfig.isPresent() && aaiConfig.get().getRelationshipList() != null) { - for (Relationship relationship : aaiConfig.get().getRelationshipList().getRelationship()) { - if (relationship.getRelatedTo().contains("vnfc") - || relationship.getRelatedTo().contains("vpn-binding")) { - aaiResourceIds.add(new Pair<>(WorkflowType.CONFIGURATION, config.getConfigurationId())); - resourceList.add( - new Resource(WorkflowType.CONFIGURATION, config.getConfigurationId(), false)); - break; - } - } - } - } - } - } catch (Exception ex) { - logger.error("Exception in traverseAAIService", ex); - buildAndThrowException(execution, - "Could not find existing Service Instance or related Instances to execute the request on."); - } - } - - private void traverseServiceInstanceMSOVnfs(List resourceList, - List> aaiResourceIds, - org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO) { - if (serviceInstanceMSO.getVnfs() == null) { - return; - } - for (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf vnf : serviceInstanceMSO.getVnfs()) { - aaiResourceIds.add(new Pair<>(WorkflowType.VNF, vnf.getVnfId())); - resourceList.add(new Resource(WorkflowType.VNF, vnf.getVnfId(), false)); - traverseVnfModules(resourceList, aaiResourceIds, vnf); - if (vnf.getVolumeGroups() != null) { - for (org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup volumeGroup : vnf.getVolumeGroups()) { - aaiResourceIds.add(new Pair<>(WorkflowType.VOLUMEGROUP, volumeGroup.getVolumeGroupId())); - resourceList.add(new Resource(WorkflowType.VOLUMEGROUP, volumeGroup.getVolumeGroupId(), false)); - } - } - } - } - - private void traverseServiceInstanceMSOPnfs(List resourceList, - List> aaiResourceIds, - org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO) { - if (serviceInstanceMSO.getPnfs() == null) { - return; - } - for (org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf pnf : serviceInstanceMSO.getPnfs()) { - aaiResourceIds.add(new Pair<>(WorkflowType.PNF, pnf.getPnfId())); - resourceList.add(new Resource(WorkflowType.PNF, pnf.getPnfId(), false)); - } - } - - private void traverseVnfModules(List resourceList, List> aaiResourceIds, - org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf vnf) { - if (vnf.getVfModules() == null) { - return; - } - for (VfModule vfModule : vnf.getVfModules()) { - aaiResourceIds.add(new Pair<>(WorkflowType.VFMODULE, vfModule.getVfModuleId())); - Resource resource = new Resource(WorkflowType.VFMODULE, vfModule.getVfModuleId(), false); - resource.setBaseVfModule(vfModule.getModelInfoVfModule().getIsBaseBoolean()); - resourceList.add(resource); - } - } - - - protected WorkflowResourceIds populateResourceIdsFromApiHandler(DelegateExecution execution) { return WorkflowResourceIdsUtils.getWorkflowResourceIdsFromExecution(execution); } @@ -1296,17 +892,6 @@ public class WorkflowAction { && (bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId) != null)); } - protected boolean foundRelated(List resourceList) { - return (containsWorkflowType(resourceList, WorkflowType.VNF) - || containsWorkflowType(resourceList, WorkflowType.PNF) - || containsWorkflowType(resourceList, WorkflowType.NETWORK) - || containsWorkflowType(resourceList, WorkflowType.NETWORKCOLLECTION)); - } - - protected boolean containsWorkflowType(List resourceList, WorkflowType workflowType) { - return resourceList.stream().anyMatch(resource -> resource.getResourceType().equals(workflowType)); - } - private void fillExecutionDefault(DelegateExecution execution) { execution.setVariable("sentSyncResponse", false); execution.setVariable(HOMING, false); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java index 9128e9e3e1..b2cc89545b 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java @@ -32,15 +32,15 @@ public final class WorkflowActionConstants { throw new IllegalStateException("Utility class"); } - static final String USER_PARAM_SERVICE = "service"; - static final String CREATE_INSTANCE = "createInstance"; - static final String FABRIC_CONFIGURATION = "FabricConfiguration"; + public static final String USER_PARAM_SERVICE = "service"; + public static final String CREATE_INSTANCE = "createInstance"; + public static final String FABRIC_CONFIGURATION = "FabricConfiguration"; public static final String WORKFLOW_ACTION_ERROR_MESSAGE = "WorkflowActionErrorMessage"; static final String SERVICE = "Service"; static final String CONTROLLER = "Controller"; - static final String NETWORKCOLLECTION = "NetworkCollection"; + public static final String NETWORKCOLLECTION = "NetworkCollection"; static final String CONFIGURATION = "Configuration"; - static final String ASSIGNINSTANCE = "assignInstance"; + public static final String ASSIGNINSTANCE = "assignInstance"; static final String REPLACEINSTANCE = "replaceInstance"; static final String VOLUMEGROUP = "VolumeGroup"; static final String REPLACEINSTANCERETAINASSIGNMENTS = "replaceInstanceRetainAssignments"; diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoader.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoader.java new file mode 100644 index 0000000000..55a92b0b81 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoader.java @@ -0,0 +1,485 @@ +package org.onap.so.bpmn.infrastructure.workflow.tasks.ebb.loader; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.javatuples.Pair; +import org.onap.aai.domain.yang.Relationship; +import org.onap.aai.domain.yang.ServiceInstance; +import org.onap.aai.domain.yang.VpnBinding; +import org.onap.aaiclient.client.aai.AAICommonObjectMapperProvider; +import org.onap.aaiclient.client.aai.entities.AAIResultWrapper; +import org.onap.aaiclient.client.aai.entities.Relationships; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; +import org.onap.so.bpmn.infrastructure.workflow.tasks.Resource; +import org.onap.so.bpmn.infrastructure.workflow.tasks.VrfBondingServiceException; +import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionExtractResourcesAAI; +import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowType; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; +import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup; +import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; +import org.onap.so.client.exception.ExceptionBuilder; +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.InstanceGroup; +import org.onap.so.db.catalog.client.CatalogDbClient; +import org.onap.so.serviceinstancebeans.ModelType; +import org.onap.so.serviceinstancebeans.RelatedInstance; +import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.WORKFLOW_ACTION_ERROR_MESSAGE; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.CREATE_INSTANCE; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.FABRIC_CONFIGURATION; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.NETWORKCOLLECTION; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.USER_PARAM_SERVICE; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.ASSIGNINSTANCE; + + +@Component +public class ServiceEBBLoader { + + private static final Logger logger = LoggerFactory.getLogger(ServiceEBBLoader.class); + + private final UserParamsServiceTraversal userParamsServiceTraversal; + private final CatalogDbClient catalogDbClient; + private final VrfValidation vrfValidation; + private final AAIConfigurationResources aaiConfigurationResources; + private final WorkflowActionExtractResourcesAAI workflowActionUtils; + private final BBInputSetupUtils bbInputSetupUtils; + private final BBInputSetup bbInputSetup; + private final ExceptionBuilder exceptionBuilder; + + public ServiceEBBLoader(UserParamsServiceTraversal userParamsServiceTraversal, CatalogDbClient catalogDbClient, + VrfValidation vrfValidation, AAIConfigurationResources aaiConfigurationResources, + WorkflowActionExtractResourcesAAI workflowActionUtils, BBInputSetupUtils bbInputSetupUtils, + BBInputSetup bbInputSetup, ExceptionBuilder exceptionBuilder) { + this.userParamsServiceTraversal = userParamsServiceTraversal; + this.catalogDbClient = catalogDbClient; + this.vrfValidation = vrfValidation; + this.aaiConfigurationResources = aaiConfigurationResources; + this.workflowActionUtils = workflowActionUtils; + this.bbInputSetupUtils = bbInputSetupUtils; + this.bbInputSetup = bbInputSetup; + this.exceptionBuilder = exceptionBuilder; + } + + public List getResourceListForService(ServiceInstancesRequest sIRequest, String requestAction, + DelegateExecution execution, String serviceInstanceId, String resourceId, + List> aaiResourceIds) throws IOException, VrfBondingServiceException { + boolean containsService = false; + List resourceList = new ArrayList<>(); + List> userParams = sIRequest.getRequestDetails().getRequestParameters().getUserParams(); + if (requestAction.equalsIgnoreCase(ASSIGNINSTANCE)) { + // SERVICE-MACRO-ASSIGN will always get user params with a + // service. + + if (userParams != null) { + containsService = isContainsService(sIRequest); + if (containsService) { + resourceList = userParamsServiceTraversal.getResourceListFromUserParams(execution, userParams, + serviceInstanceId, requestAction); + } + } else { + buildAndThrowException(execution, + "Service-Macro-Assign request details must contain user params with a service"); + } + } else if (requestAction.equalsIgnoreCase(CREATE_INSTANCE)) { + // SERVICE-MACRO-CREATE will get user params with a service, + // a service with a network, a service with a + // network collection, OR an empty service. + // If user params is just a service or null and macro + // queries the SI and finds a VNF, macro fails. + + if (userParams != null) { + containsService = isContainsService(sIRequest); + } + if (containsService) { + resourceList = userParamsServiceTraversal.getResourceListFromUserParams(execution, userParams, + serviceInstanceId, requestAction); + } + if (!foundRelated(resourceList)) { + traverseCatalogDbService(execution, sIRequest, resourceList, aaiResourceIds); + } + } else if (("activateInstance".equalsIgnoreCase(requestAction) + || "unassignInstance".equalsIgnoreCase(requestAction) + || "deleteInstance".equalsIgnoreCase(requestAction) + || requestAction.equalsIgnoreCase("activate" + FABRIC_CONFIGURATION))) { + // SERVICE-MACRO-ACTIVATE, SERVICE-MACRO-UNASSIGN, and + // SERVICE-MACRO-DELETE + // Will never get user params with service, macro will have + // to query the SI in AAI to find related instances. + traverseAAIService(execution, resourceList, resourceId, aaiResourceIds); + } else if ("deactivateInstance".equalsIgnoreCase(requestAction)) { + resourceList.add(new Resource(WorkflowType.SERVICE, "", false)); + } + return resourceList; + } + + private boolean isContainsService(ServiceInstancesRequest sIRequest) { + boolean containsService; + List> userParams = sIRequest.getRequestDetails().getRequestParameters().getUserParams(); + containsService = userParams.stream().anyMatch(param -> param.containsKey(USER_PARAM_SERVICE)); + return containsService; + } + + public void traverseCatalogDbService(DelegateExecution execution, ServiceInstancesRequest sIRequest, + List resourceList, List> aaiResourceIds) + throws JsonProcessingException, VrfBondingServiceException { + 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 { + resourceList.add(new Resource(WorkflowType.SERVICE, service.getModelUUID(), false)); + RelatedInstance relatedVpnBinding = + bbInputSetupUtils.getRelatedInstanceByType(sIRequest.getRequestDetails(), ModelType.vpnBinding); + RelatedInstance relatedLocalNetwork = + bbInputSetupUtils.getRelatedInstanceByType(sIRequest.getRequestDetails(), ModelType.network); + + if (relatedVpnBinding != null && relatedLocalNetwork != null) { + traverseVrfConfiguration(aaiResourceIds, resourceList, service, relatedVpnBinding, relatedLocalNetwork); + } else { + traverseNetworkCollection(execution, resourceList, service); + } + } + } + + public boolean foundRelated(List resourceList) { + return (containsWorkflowType(resourceList, WorkflowType.VNF) + || containsWorkflowType(resourceList, WorkflowType.PNF) + || containsWorkflowType(resourceList, WorkflowType.NETWORK) + || containsWorkflowType(resourceList, WorkflowType.NETWORKCOLLECTION)); + } + + public void traverseAAIService(DelegateExecution execution, List resourceList, String resourceId, + List> aaiResourceIds) { + try { + ServiceInstance serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceById(resourceId); + org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO = + bbInputSetup.getExistingServiceInstance(serviceInstanceAAI); + resourceList.add(new Resource(WorkflowType.SERVICE, serviceInstanceMSO.getServiceInstanceId(), false)); + traverseServiceInstanceMSOVnfs(resourceList, aaiResourceIds, serviceInstanceMSO); + traverseServiceInstanceMSOPnfs(resourceList, aaiResourceIds, serviceInstanceMSO); + if (serviceInstanceMSO.getNetworks() != null) { + for (org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network network : serviceInstanceMSO + .getNetworks()) { + aaiResourceIds.add(new Pair<>(WorkflowType.NETWORK, network.getNetworkId())); + resourceList.add(new Resource(WorkflowType.NETWORK, network.getNetworkId(), false)); + } + } + if (serviceInstanceMSO.getCollection() != null) { + logger.debug("found networkcollection"); + aaiResourceIds + .add(new Pair<>(WorkflowType.NETWORKCOLLECTION, serviceInstanceMSO.getCollection().getId())); + resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, + serviceInstanceMSO.getCollection().getId(), false)); + } + if (serviceInstanceMSO.getConfigurations() != null) { + for (Configuration config : serviceInstanceMSO.getConfigurations()) { + Optional aaiConfig = + aaiConfigurationResources.getConfiguration(config.getConfigurationId()); + if (aaiConfig.isPresent() && aaiConfig.get().getRelationshipList() != null) { + for (Relationship relationship : aaiConfig.get().getRelationshipList().getRelationship()) { + if (relationship.getRelatedTo().contains("vnfc") + || relationship.getRelatedTo().contains("vpn-binding")) { + aaiResourceIds.add(new Pair<>(WorkflowType.CONFIGURATION, config.getConfigurationId())); + resourceList.add( + new Resource(WorkflowType.CONFIGURATION, config.getConfigurationId(), false)); + break; + } + } + } + } + } + } catch (Exception ex) { + logger.error("Exception in traverseAAIService", ex); + buildAndThrowException(execution, + "Could not find existing Service Instance or related Instances to execute the request on."); + } + } + + private void traverseServiceInstanceMSOVnfs(List resourceList, + List> aaiResourceIds, + org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO) { + if (serviceInstanceMSO.getVnfs() == null) { + return; + } + for (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf vnf : serviceInstanceMSO.getVnfs()) { + aaiResourceIds.add(new Pair<>(WorkflowType.VNF, vnf.getVnfId())); + resourceList.add(new Resource(WorkflowType.VNF, vnf.getVnfId(), false)); + traverseVnfModules(resourceList, aaiResourceIds, vnf); + if (vnf.getVolumeGroups() != null) { + for (org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup volumeGroup : vnf.getVolumeGroups()) { + aaiResourceIds.add(new Pair<>(WorkflowType.VOLUMEGROUP, volumeGroup.getVolumeGroupId())); + resourceList.add(new Resource(WorkflowType.VOLUMEGROUP, volumeGroup.getVolumeGroupId(), false)); + } + } + } + } + + private void traverseServiceInstanceMSOPnfs(List resourceList, + List> aaiResourceIds, + org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO) { + if (serviceInstanceMSO.getPnfs() == null) { + return; + } + for (org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf pnf : serviceInstanceMSO.getPnfs()) { + aaiResourceIds.add(new Pair<>(WorkflowType.PNF, pnf.getPnfId())); + resourceList.add(new Resource(WorkflowType.PNF, pnf.getPnfId(), false)); + } + } + + protected void traverseVrfConfiguration(List> aaiResourceIds, + List resourceList, org.onap.so.db.catalog.beans.Service service, + RelatedInstance relatedVpnBinding, RelatedInstance relatedLocalNetwork) + throws VrfBondingServiceException, JsonProcessingException { + org.onap.aai.domain.yang.L3Network aaiLocalNetwork = + bbInputSetupUtils.getAAIL3Network(relatedLocalNetwork.getInstanceId()); + vrfValidation.vrfServiceValidation(service); + vrfValidation.vrfCatalogDbChecks(service); + vrfValidation.aaiVpnBindingValidation(relatedVpnBinding.getInstanceId(), + bbInputSetupUtils.getAAIVpnBinding(relatedVpnBinding.getInstanceId())); + vrfValidation.aaiNetworkValidation(relatedLocalNetwork.getInstanceId(), aaiLocalNetwork); + vrfValidation.aaiSubnetValidation(aaiLocalNetwork); + vrfValidation.aaiAggregateRouteValidation(aaiLocalNetwork); + vrfValidation.aaiRouteTargetValidation(aaiLocalNetwork); + String existingAAIVrfConfiguration = getExistingAAIVrfConfiguration(relatedVpnBinding, aaiLocalNetwork); + if (existingAAIVrfConfiguration != null) { + aaiResourceIds.add(new Pair<>(WorkflowType.CONFIGURATION, existingAAIVrfConfiguration)); + } + resourceList.add(new Resource(WorkflowType.CONFIGURATION, + service.getConfigurationCustomizations().get(0).getModelCustomizationUUID(), false)); + + } + + protected void traverseNetworkCollection(DelegateExecution execution, List resourceList, + org.onap.so.db.catalog.beans.Service service) { + if (isVnfCustomizationsInTheService(service)) { + 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"); + } + if (isPnfCustomizationsInTheService(service)) { + buildAndThrowException(execution, + "Cannot orchestrate Service-Macro-Create without user params with a pnf. Please update ASDC model for new macro orchestration support or add service_recipe records to route to old macro flows"); + } + List customizations = service.getCollectionResourceCustomizations(); + if (customizations.isEmpty()) { + logger.debug("No Collections found. CollectionResourceCustomization list is empty."); + } else { + CollectionResourceCustomization collectionResourceCustomization = + findCatalogNetworkCollection(execution, service); + traverseNetworkCollectionResourceCustomization(resourceList, collectionResourceCustomization); + } + traverseNetworkCollectionCustomization(resourceList, service); + } + + private void traverseNetworkCollectionResourceCustomization(List resourceList, + CollectionResourceCustomization collectionResourceCustomization) { + if (collectionResourceCustomizationShouldNotBeProcessed(resourceList, collectionResourceCustomization)) + return; + 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 (interfaceNetworkQuantityIsAvailableInCollection(collectionInstCust)) { + minNetworks = collectionInstCust.getSubInterfaceNetworkQuantity(); + } + } + logger.debug("minNetworks: {}", minNetworks); + CollectionNetworkResourceCustomization collectionNetworkResourceCust = + getCollectionNetworkResourceCustomization(collectionResourceCustomization, instanceGroup); + for (int i = 0; i < minNetworks; i++) { + if (collectionNetworkResourceCust != null) { + Resource resource = new Resource(WorkflowType.VIRTUAL_LINK, + collectionNetworkResourceCust.getModelCustomizationUUID(), false); + resource.setVirtualLinkKey(Integer.toString(i)); + resourceList.add(resource); + } + } + } + + private CollectionNetworkResourceCustomization getCollectionNetworkResourceCustomization( + CollectionResourceCustomization collectionResourceCustomization, InstanceGroup instanceGroup) { + CollectionNetworkResourceCustomization collectionNetworkResourceCust = null; + for (CollectionNetworkResourceCustomization collectionNetworkTemp : instanceGroup + .getCollectionNetworkResourceCustomizations()) { + if (collectionNetworkTemp.getNetworkResourceCustomization().getModelCustomizationUUID() + .equalsIgnoreCase(collectionResourceCustomization.getModelCustomizationUUID())) { + collectionNetworkResourceCust = collectionNetworkTemp; + break; + } + } + return collectionNetworkResourceCust; + } + + private boolean collectionResourceCustomizationShouldNotBeProcessed(List resourceList, + CollectionResourceCustomization collectionResourceCustomization) { + if (collectionResourceCustomization == null) { + logger.debug("No Network Collection Customization found"); + return true; + } + resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, + collectionResourceCustomization.getModelCustomizationUUID(), false)); + logger.debug("Found a network collection"); + if (collectionResourceCustomization.getCollectionResource() == null) { + logger.debug("No Network Collection found. collectionResource is null"); + return true; + } + if (collectionResourceCustomization.getCollectionResource().getInstanceGroup() == null) { + logger.debug("No Instance Group found for network collection."); + return true; + } + String toscaNodeType = + collectionResourceCustomization.getCollectionResource().getInstanceGroup().getToscaNodeType(); + if (!toscaNodeTypeHasNetworkCollection(toscaNodeType)) { + logger.debug("Instance Group tosca node type does not contain NetworkCollection: {}", toscaNodeType); + return true; + } + return false; + } + + private boolean interfaceNetworkQuantityIsAvailableInCollection( + CollectionResourceInstanceGroupCustomization collectionInstCust) { + return collectionInstCust != null && collectionInstCust.getSubInterfaceNetworkQuantity() != null; + } + + private boolean toscaNodeTypeHasNetworkCollection(String toscaNodeType) { + return toscaNodeType != null && toscaNodeType.contains(NETWORKCOLLECTION); + } + + private void traverseNetworkCollectionCustomization(List resourceList, + org.onap.so.db.catalog.beans.Service service) { + if (isNetworkCollectionInTheResourceList(resourceList)) { + return; + } + if (service.getNetworkCustomizations() == null) { + logger.debug("No networks were found on this service model"); + return; + } + for (int i = 0; i < service.getNetworkCustomizations().size(); i++) { + resourceList.add(new Resource(WorkflowType.NETWORK, + service.getNetworkCustomizations().get(i).getModelCustomizationUUID(), false)); + } + } + + private boolean isVnfCustomizationsInTheService(org.onap.so.db.catalog.beans.Service service) { + return !(service.getVnfCustomizations() == null || service.getVnfCustomizations().isEmpty()); + } + + private boolean isPnfCustomizationsInTheService(org.onap.so.db.catalog.beans.Service service) { + return !(service.getPnfCustomizations() == null || service.getPnfCustomizations().isEmpty()); + } + + private void traverseVnfModules(List resourceList, List> aaiResourceIds, + org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf vnf) { + if (vnf.getVfModules() == null) { + return; + } + for (VfModule vfModule : vnf.getVfModules()) { + aaiResourceIds.add(new Pair<>(WorkflowType.VFMODULE, vfModule.getVfModuleId())); + Resource resource = new Resource(WorkflowType.VFMODULE, vfModule.getVfModuleId(), false); + resource.setBaseVfModule(vfModule.getModelInfoVfModule().getIsBaseBoolean()); + resourceList.add(resource); + } + } + + + protected String getExistingAAIVrfConfiguration(RelatedInstance relatedVpnBinding, + org.onap.aai.domain.yang.L3Network aaiLocalNetwork) + throws JsonProcessingException, VrfBondingServiceException { + Optional relationshipsOp = new AAIResultWrapper( + new AAICommonObjectMapperProvider().getMapper().writeValueAsString(aaiLocalNetwork)).getRelationships(); + if (relationshipsOp.isPresent()) { + List configurationsRelatedToLocalNetwork = + relationshipsOp.get().getByType(AAIFluentTypeBuilder.Types.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 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 ("VRF-ENTRY".equalsIgnoreCase(vrfConfiguration.getConfigurationType())) { + Optional relationshipsConfigOp = configWrapper.getRelationships(); + if (relationshipsConfigOp.isPresent()) { + Optional 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; + } + + public boolean containsWorkflowType(List resourceList, WorkflowType workflowType) { + return resourceList.stream().anyMatch(resource -> resource.getResourceType().equals(workflowType)); + } + + public boolean isNetworkCollectionInTheResourceList(List resourceList) { + return resourceList.stream().anyMatch(x -> WorkflowType.NETWORKCOLLECTION == x.getResourceType()); + } + + public CollectionResourceCustomization findCatalogNetworkCollection(DelegateExecution execution, + org.onap.so.db.catalog.beans.Service service) { + CollectionResourceCustomization networkCollection = null; + int count = 0; + for (CollectionResourceCustomization collectionCust : service.getCollectionResourceCustomizations()) { + if (catalogDbClient.getNetworkCollectionResourceCustomizationByID( + collectionCust.getModelCustomizationUUID()) != null) { + networkCollection = collectionCust; + count++; + } + } + if (count == 0) { + return null; + } else if (count > 1) { + buildAndThrowException(execution, + "Found multiple Network Collections in the Service model, only one per Service is supported."); + } + return networkCollection; + } + + protected void buildAndThrowException(DelegateExecution execution, String msg) { + logger.error(msg); + execution.setVariable(WORKFLOW_ACTION_ERROR_MESSAGE, msg); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg); + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/UserParamsServiceTraversal.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/UserParamsServiceTraversal.java new file mode 100644 index 0000000000..4b1fdd8da1 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/UserParamsServiceTraversal.java @@ -0,0 +1,276 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ + * Modifications Copyright (c) 2020 Nokia + * ================================================================================ + * Modifications Copyright (c) 2020 Tech Mahindra + * ================================================================================ + * 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.bpmn.infrastructure.workflow.tasks.ebb.loader; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.onap.so.bpmn.infrastructure.workflow.tasks.Resource; +import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowType; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.db.catalog.beans.CollectionResourceCustomization; +import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization; +import org.onap.so.db.catalog.beans.CvnfcCustomization; +import org.onap.so.db.catalog.beans.VfModuleCustomization; +import org.onap.so.db.catalog.client.CatalogDbClient; +import org.onap.so.serviceinstancebeans.Networks; +import org.onap.so.serviceinstancebeans.Pnfs; +import org.onap.so.serviceinstancebeans.Service; +import org.onap.so.serviceinstancebeans.VfModules; +import org.onap.so.serviceinstancebeans.Vnfs; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.CREATE_INSTANCE; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.FABRIC_CONFIGURATION; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.USER_PARAM_SERVICE; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.WORKFLOW_ACTION_ERROR_MESSAGE; + +@Component +public class UserParamsServiceTraversal { + + private static final Logger logger = LoggerFactory.getLogger(UserParamsServiceTraversal.class); + + private final CatalogDbClient catalogDbClient; + private final ExceptionBuilder exceptionBuilder; + private boolean foundVfModuleOrVG; + private String vnfCustomizationUUID; + private String vfModuleCustomizationUUID; + + UserParamsServiceTraversal(CatalogDbClient catalogDbClient, ExceptionBuilder exceptionBuilder) { + this.catalogDbClient = catalogDbClient; + this.exceptionBuilder = exceptionBuilder; + } + + public List getResourceListFromUserParams(DelegateExecution execution, + List> userParams, String serviceModelVersionId, String requestAction) + throws IOException { + if (userParams != null) { + for (Map params : userParams) { + if (params.containsKey(USER_PARAM_SERVICE)) { + ObjectMapper obj = new ObjectMapper(); + String input = obj.writeValueAsString(params.get(USER_PARAM_SERVICE)); + Service validate = obj.readValue(input, Service.class); + return getResourceList(execution, serviceModelVersionId, requestAction, validate); + } + } + } + return Collections.emptyList(); + } + + private List getResourceList(DelegateExecution execution, String serviceModelVersionId, + String requestAction, Service validate) { + List resourceList = new ArrayList<>(); + resourceList.add(new Resource(WorkflowType.SERVICE, validate.getModelInfo().getModelVersionId(), false)); + if (validate.getResources().getVnfs() != null) { + setResourceListForVnfs(execution, resourceList, validate); + } + if (validate.getResources().getPnfs() != null) { + setResourceListForPnfs(resourceList, validate); + } + if (validate.getResources().getNetworks() != null) { + setResourceListForNetworks(execution, serviceModelVersionId, requestAction, resourceList, validate); + } + return resourceList; + } + + private void setResourceListForVnfs(DelegateExecution execution, List resourceList, Service validate) { + for (Vnfs vnf : validate.getResources().getVnfs()) { + setVnfCustomizationUUID(vnf); + resourceList.add(new Resource(WorkflowType.VNF, vnf.getModelInfo().getModelCustomizationId(), false)); + setResourceListForVfModules(execution, resourceList, validate, vnf); + } + } + + private void setResourceListForVfModules(DelegateExecution execution, List resourceList, Service validate, + Vnfs vnf) { + if (vnf.getVfModules() != null) { + for (VfModules vfModule : vnf.getVfModules()) { + setVfModuleCustomizationUUID(vfModule); + VfModuleCustomization vfModuleCustomization = + catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID(vfModuleCustomizationUUID); + if (vfModuleCustomization != null && vfModuleCustomization.getVfModule() != null) { + setVolumeGroupWorkFlowTypeToResourceList(resourceList, vfModuleCustomization); + setVfModuleAndConfigurationWorkFlowTypeToResourceList(resourceList, validate, vnf, vfModule, + vfModuleCustomization); + if (!foundVfModuleOrVG) { + buildAndThrowException(execution, + "Could not determine if vfModule was a vfModule or volume group. Heat template and Heat env are null"); + } + } + } + } + } + + private void setVolumeGroupWorkFlowTypeToResourceList(List resourceList, + VfModuleCustomization vfModuleCustomization) { + if (vfModuleCustomization.getVfModule().getVolumeHeatTemplate() != null + && vfModuleCustomization.getVolumeHeatEnv() != null) { + foundVfModuleOrVG = true; + resourceList.add( + new Resource(WorkflowType.VOLUMEGROUP, vfModuleCustomization.getModelCustomizationUUID(), false)); + } + } + + private void setVfModuleAndConfigurationWorkFlowTypeToResourceList(List resourceList, Service validate, + Vnfs vnf, VfModules vfModule, VfModuleCustomization vfModuleCustomization) { + if ((vfModuleCustomization.getVfModule().getModuleHeatTemplate() != null + && vfModuleCustomization.getHeatEnvironment() != null) + || (vfModuleCustomization.getVfModule().getModelName() != null + && vfModuleCustomization.getVfModule().getModelName().contains("helm"))) { + foundVfModuleOrVG = true; + Resource resource = setVfModuleWorkFlowTypeToResourceList(resourceList, vfModuleCustomization); + setConfigurationWorkFlowTypeToResourceList(resourceList, validate, vnf, vfModule, resource); + } + } + + private Resource setVfModuleWorkFlowTypeToResourceList(List resourceList, + VfModuleCustomization vfModuleCustomization) { + Resource resource = + new Resource(WorkflowType.VFMODULE, vfModuleCustomization.getModelCustomizationUUID(), false); + resource.setBaseVfModule(vfModuleCustomization.getVfModule().getIsBase() != null + && vfModuleCustomization.getVfModule().getIsBase()); + resourceList.add(resource); + return resource; + } + + private void setConfigurationWorkFlowTypeToResourceList(List resourceList, Service validate, Vnfs vnf, + VfModules vfModule, Resource resource) { + if (!vnfCustomizationUUID.isEmpty() && !vfModuleCustomizationUUID.isEmpty()) { + List configs = + traverseCatalogDbForConfiguration(validate.getModelInfo().getModelVersionId()); + for (CvnfcConfigurationCustomization config : configs) { + Resource configResource = new Resource(WorkflowType.CONFIGURATION, + config.getConfigurationResource().getModelUUID(), false); + resource.setVnfCustomizationId(vnf.getModelInfo().getModelCustomizationId()); + resource.setVfModuleCustomizationId(vfModule.getModelInfo().getModelCustomizationId()); + resourceList.add(configResource); + } + } + } + + private void setVfModuleCustomizationUUID(VfModules vfModule) { + if (vfModule.getModelInfo() != null && vfModule.getModelInfo().getModelCustomizationUuid() != null) { + vfModuleCustomizationUUID = vfModule.getModelInfo().getModelCustomizationUuid(); + } else { + vfModuleCustomizationUUID = ""; + } + } + + private void setVnfCustomizationUUID(Vnfs vnf) { + if (vnf.getModelInfo() != null && vnf.getModelInfo().getModelCustomizationUuid() != null) { + vnfCustomizationUUID = vnf.getModelInfo().getModelCustomizationUuid(); + } else { + vnfCustomizationUUID = ""; + } + } + + private void setResourceListForPnfs(List resourceList, Service validate) { + for (Pnfs pnf : validate.getResources().getPnfs()) { + resourceList.add(new Resource(WorkflowType.PNF, pnf.getModelInfo().getModelCustomizationId(), false)); + } + } + + private void setResourceListForNetworks(DelegateExecution execution, String serviceModelVersionId, + String requestAction, List resourceList, Service validate) { + for (Networks network : validate.getResources().getNetworks()) { + resourceList + .add(new Resource(WorkflowType.NETWORK, network.getModelInfo().getModelCustomizationId(), false)); + } + if (requestAction.equals(CREATE_INSTANCE)) { + String networkColCustId = queryCatalogDbForNetworkCollection(execution, serviceModelVersionId); + if (networkColCustId != null) { + resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, networkColCustId, false)); + } + } + } + + + private List traverseCatalogDbForConfiguration(String serviceModelUUID) { + try { + List cvnfcCustomizations = catalogDbClient.getCvnfcCustomization(serviceModelUUID, + vnfCustomizationUUID, vfModuleCustomizationUUID); + return getCvnfcConfigurationCustomizations(cvnfcCustomizations); + } catch (Exception ex) { + logger.error("Error in finding configurations", ex); + return Collections.emptyList(); + } + } + + private List getCvnfcConfigurationCustomizations( + List cvnfcCustomizations) { + List configurations = new ArrayList<>(); + for (CvnfcCustomization cvnfc : cvnfcCustomizations) { + for (CvnfcConfigurationCustomization customization : cvnfc.getCvnfcConfigurationCustomization()) { + if (customization.getConfigurationResource().getToscaNodeType().contains(FABRIC_CONFIGURATION)) { + configurations.add(customization); + } + } + } + logger.debug("found {} fabric configuration(s)", configurations.size()); + return configurations; + } + + private String queryCatalogDbForNetworkCollection(DelegateExecution execution, String serviceModelVersionId) { + org.onap.so.db.catalog.beans.Service service = catalogDbClient.getServiceByID(serviceModelVersionId); + if (service != null) { + CollectionResourceCustomization networkCollection = this.findCatalogNetworkCollection(execution, service); + if (networkCollection != null) { + return networkCollection.getModelCustomizationUUID(); + } + } + return null; + } + + private CollectionResourceCustomization findCatalogNetworkCollection(DelegateExecution execution, + org.onap.so.db.catalog.beans.Service service) { + CollectionResourceCustomization networkCollection = null; + int count = 0; + for (CollectionResourceCustomization collectionCustom : service.getCollectionResourceCustomizations()) { + if (catalogDbClient.getNetworkCollectionResourceCustomizationByID( + collectionCustom.getModelCustomizationUUID()) != null) { + networkCollection = collectionCustom; + count++; + } + } + if (count > 1) { + buildAndThrowException(execution, + "Found multiple Network Collections in the Service model, only one per Service is supported."); + } + return networkCollection; + } + + private void buildAndThrowException(DelegateExecution execution, String msg) { + logger.error(msg); + execution.setVariable(WORKFLOW_ACTION_ERROR_MESSAGE, msg); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg); + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VrfValidation.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VrfValidation.java new file mode 100644 index 0000000000..3b54645b35 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VrfValidation.java @@ -0,0 +1,164 @@ +/*- + * ============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.bpmn.infrastructure.workflow.tasks.ebb.loader; + +import java.util.List; +import java.util.Optional; +import org.onap.aai.domain.yang.L3Network; +import org.onap.aaiclient.client.aai.entities.AAIResultWrapper; +import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; +import org.onap.so.bpmn.infrastructure.workflow.tasks.VrfBondingServiceException; +import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; +import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization; +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(String relatedVpnId, org.onap.aai.domain.yang.VpnBinding aaiVpnBinding) + throws VrfBondingServiceException { + if (aaiVpnBinding == null) { + throw new VrfBondingServiceException("The infrastructure vpn " + relatedVpnId + " does not exist in A&AI."); + } else if (aaiVpnBinding.getVpnType() != null + && !aaiVpnBinding.getVpnType().equalsIgnoreCase("SERVICE-INFRASTRUCTURE")) { + throw new VrfBondingServiceException( + "VpnBinding: " + relatedVpnId + " does not have a vpn type of SERVICE-INFRASTRUCTURE."); + } + } + + 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 aaiNetworkValidation(String relatedNetworkid, org.onap.aai.domain.yang.L3Network aaiLocalNetwork) + throws VrfBondingServiceException { + if (aaiLocalNetwork == null) { + throw new VrfBondingServiceException("The local network " + relatedNetworkid + " does not exist in A&AI."); + } + } + + 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 vpnBindingUris = + networkWrapper.getRelationships().get().getRelatedUris(Types.VPN_BINDING); + if (!vpnBindingUris.isEmpty()) { + Optional 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/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/UserParamsServiceTraversalTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/UserParamsServiceTraversalTest.java deleted file mode 100644 index 99f17a3628..0000000000 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/UserParamsServiceTraversalTest.java +++ /dev/null @@ -1,219 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Modifications Copyright (c) 2020 Nokia - * ================================================================================ - * 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.bpmn.infrastructure.workflow.tasks; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.camunda.bpm.engine.delegate.DelegateExecution; -import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; -import org.onap.so.bpmn.BaseTaskTest; -import org.onap.so.bpmn.common.BBConstants; -import org.onap.so.client.exception.ExceptionBuilder; -import org.onap.so.db.catalog.beans.ConfigurationResource; -import org.onap.so.db.catalog.beans.CvnfcCustomization; -import org.onap.so.db.catalog.beans.HeatTemplate; -import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization; -import org.onap.so.db.catalog.beans.VfModuleCustomization; -import org.onap.so.db.catalog.beans.Service; -import org.onap.so.db.catalog.beans.VfModule; -import org.onap.so.db.catalog.beans.CollectionResourceCustomization; -import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization; -import org.onap.so.db.catalog.beans.HeatEnvironment; -import org.onap.so.db.catalog.client.CatalogDbClient; -import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.mock; - -public class UserParamsServiceTraversalTest extends BaseTaskTest { - - private static final String MACRO_ASSIGN_JSON = "Macro/ServiceMacroAssign.json"; - private static final String MACRO_ASSIGN_PNF_JSON = "Macro/ServiceMacroAssignPnf.json"; - private static final String NETWORK_COLLECTION_JSON = "Macro/CreateNetworkCollection.json"; - private static final String serviceInstanceId = "123"; - private DelegateExecution execution; - private CatalogDbClient mockCatalogDbClient; - private UserParamsServiceTraversal userParamsServiceTraversal; - private String requestAction; - - @Before - public void before() throws Exception { - execution = new DelegateExecutionFake(); - mockCatalogDbClient = mock(CatalogDbClient.class); - userParamsServiceTraversal = new UserParamsServiceTraversal(mockCatalogDbClient, mock(ExceptionBuilder.class)); - requestAction = "assignInstance"; - } - - @Test - public void getResourceListFromUserParamsForVnfs() throws Exception { - initExecution(requestAction, readBpmnRequestFromFile(MACRO_ASSIGN_JSON), false); - Mockito.doReturn(getVfModuleCustomization()).when(mockCatalogDbClient) - .getVfModuleCustomizationByModelCuztomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); - Mockito.doReturn(getCvnfcCustomizations()).when(mockCatalogDbClient).getCvnfcCustomization(anyString(), - anyString(), anyString()); - - List resourceListFromUserParams = userParamsServiceTraversal.getResourceListFromUserParams(execution, - getUserParams(), serviceInstanceId, requestAction); - List expected = List.of(WorkflowType.SERVICE, WorkflowType.VNF, WorkflowType.VOLUMEGROUP, - WorkflowType.VFMODULE, WorkflowType.CONFIGURATION); - List result = - resourceListFromUserParams.stream().map(Resource::getResourceType).collect(Collectors.toList()); - - assertEquals(5, resourceListFromUserParams.size()); - assertThat(expected, is(result)); - } - - @Test - public void getResourceListFromUserParamsForPnfs() throws Exception { - initExecution(requestAction, readBpmnRequestFromFile(MACRO_ASSIGN_PNF_JSON), false); - Mockito.doReturn(getVfModuleCustomization()).when(mockCatalogDbClient) - .getVfModuleCustomizationByModelCuztomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); - Mockito.doReturn(getCvnfcCustomizations()).when(mockCatalogDbClient).getCvnfcCustomization(anyString(), - anyString(), anyString()); - - List resourceListFromUserParams = userParamsServiceTraversal.getResourceListFromUserParams(execution, - getUserParams(), serviceInstanceId, requestAction); - List expected = List.of(WorkflowType.SERVICE, WorkflowType.PNF); - List result = - resourceListFromUserParams.stream().map(Resource::getResourceType).collect(Collectors.toList()); - - assertEquals(2, resourceListFromUserParams.size()); - assertThat(expected, is(result)); - } - - @Test - public void getResourceListFromUserParamsForNetworks() throws Exception { - requestAction = "createInstance"; - initExecution(requestAction, readBpmnRequestFromFile(NETWORK_COLLECTION_JSON), false); - Mockito.doReturn(getVfModuleCustomization()).when(mockCatalogDbClient) - .getVfModuleCustomizationByModelCuztomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); - Mockito.doReturn(getCvnfcCustomizations()).when(mockCatalogDbClient).getCvnfcCustomization(anyString(), - anyString(), anyString()); - Mockito.doReturn(getService()).when(mockCatalogDbClient).getServiceByID(anyString()); - Mockito.doReturn(new NetworkCollectionResourceCustomization()).when(mockCatalogDbClient) - .getNetworkCollectionResourceCustomizationByID(anyString()); - - List resourceListFromUserParams = userParamsServiceTraversal.getResourceListFromUserParams(execution, - getUserParams(), serviceInstanceId, requestAction); - List expected = List.of(WorkflowType.SERVICE, WorkflowType.NETWORK, WorkflowType.NETWORK, - WorkflowType.NETWORKCOLLECTION); - List result = - resourceListFromUserParams.stream().map(Resource::getResourceType).collect(Collectors.toList()); - - assertEquals(4, resourceListFromUserParams.size()); - assertThat(expected, is(result)); - } - - @Test - public void getResourceListFromUserParamsBuildAndThrowExceptionWhenVfModuleAreEmpty() throws Exception { - initExecution(requestAction, readBpmnRequestFromFile(MACRO_ASSIGN_JSON), false); - VfModuleCustomization vfModuleCustomization = new VfModuleCustomization(); - vfModuleCustomization.setVfModule(null); - Mockito.doReturn(vfModuleCustomization).when(mockCatalogDbClient) - .getVfModuleCustomizationByModelCuztomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); - - List resourceListFromUserParams = userParamsServiceTraversal.getResourceListFromUserParams(execution, - getUserParams(), serviceInstanceId, requestAction); - List expected = List.of(WorkflowType.SERVICE, WorkflowType.VNF); - List result = - resourceListFromUserParams.stream().map(Resource::getResourceType).collect(Collectors.toList()); - - assertEquals(2, resourceListFromUserParams.size()); - assertThat(expected, is(result)); - } - - private List> getUserParams() throws IOException { - String bpmnRequest = (String) execution.getVariable(BBConstants.G_BPMN_REQUEST); - ServiceInstancesRequest sIRequest = new ObjectMapper().readValue(bpmnRequest, ServiceInstancesRequest.class); - return sIRequest.getRequestDetails().getRequestParameters().getUserParams(); - } - - @Test - public void getResourceListFromUserParamsWhenUserParamsAreNull() throws Exception { - List expectedResourceList = new ArrayList<>(); - List resultResourceList = userParamsServiceTraversal.getResourceListFromUserParams(execution, null, - serviceInstanceId, requestAction); - - assertEquals(expectedResourceList, resultResourceList); - } - - private String readBpmnRequestFromFile(String fileName) throws IOException { - return new String(Files.readAllBytes(Paths.get("src/test/resources/__files/" + fileName))); - } - - private void initExecution(String gAction, String bpmnRequest, boolean isAlaCarte) { - execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); - execution.setVariable("requestAction", gAction); - execution.setVariable("bpmnRequest", bpmnRequest); - execution.setVariable("aLaCarte", isAlaCarte); - execution.setVariable("apiVersion", "7"); - } - - private Service getService() { - Service service = new Service(); - List collectionResourceCustomizations = new ArrayList<>(); - CollectionResourceCustomization collectionResourceCustomization = new CollectionResourceCustomization(); - collectionResourceCustomization.setModelCustomizationUUID("123"); - collectionResourceCustomizations.add(collectionResourceCustomization); - service.setCollectionResourceCustomizations(collectionResourceCustomizations); - return service; - } - - private VfModuleCustomization getVfModuleCustomization() { - VfModuleCustomization vfModuleCustomization = new VfModuleCustomization(); - vfModuleCustomization.setVolumeHeatEnv(new HeatEnvironment()); - vfModuleCustomization.setModelCustomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); - VfModule vfModule = new VfModule(); - vfModule.setVolumeHeatTemplate(new HeatTemplate()); - vfModule.setModelName("helm"); - vfModule.setModuleHeatTemplate(new HeatTemplate()); - vfModuleCustomization.setVfModule(vfModule); - return vfModuleCustomization; - } - - private List getCvnfcCustomizations() { - ConfigurationResource configurationResource = new ConfigurationResource(); - configurationResource.setToscaNodeType("FabricConfiguration"); - - CvnfcConfigurationCustomization cvnfcConfigurationCustomization = new CvnfcConfigurationCustomization(); - cvnfcConfigurationCustomization.setConfigurationResource(configurationResource); - CvnfcCustomization cvnfcCustomization = new CvnfcCustomization(); - - List cvnfcConfigurationCustomizations = new ArrayList<>(); - cvnfcConfigurationCustomizations.add(cvnfcConfigurationCustomization); - cvnfcCustomization.setCvnfcConfigurationCustomization(cvnfcConfigurationCustomizations); - - List cvnfcCustomizations = new ArrayList<>(); - cvnfcCustomizations.add(cvnfcCustomization); - return cvnfcCustomizations; - } -} 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 deleted file mode 100644 index 7f9f0417ea..0000000000 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/VrfValidationTest.java +++ /dev/null @@ -1,219 +0,0 @@ -/*- - * ============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.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.aaiclient.client.aai.entities.AAIResultWrapper; -import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; -import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; -import org.onap.so.bpmn.BaseTaskTest; -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("test-vpn", aaiVpnBinding); - } - - @Test - public void testAaiVpnBindingValidationVpnBindingIsNull() throws VrfBondingServiceException { - exceptionRule.expect(VrfBondingServiceException.class); - exceptionRule.expectMessage("The infrastructure vpn test-vpn does not exist in A&AI."); - vrfValidation.aaiVpnBindingValidation("test-vpn", null); - } - - @Test - public void testAaiNetworkValidation() throws VrfBondingServiceException { - org.onap.aai.domain.yang.L3Network aaiLocalNetwork = new org.onap.aai.domain.yang.L3Network(); - aaiLocalNetwork.setNetworkId("test-network"); - ExpectedException.none(); - vrfValidation.aaiNetworkValidation("test-network", aaiLocalNetwork); - } - - @Test - public void testAaiNetworkValidationNetworkIsNull() throws VrfBondingServiceException { - exceptionRule.expect(VrfBondingServiceException.class); - exceptionRule.expectMessage("The local network test-network does not exist in A&AI."); - vrfValidation.aaiNetworkValidation("test-network", null); - } - - @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 vpnBindingUris = - networkWrapper.getRelationships().get().getRelatedUris(Types.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 55529b5bf0..31f37f4ac3 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 @@ -78,6 +78,8 @@ import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.infrastructure.workflow.tasks.ebb.loader.ServiceEBBLoader; +import org.onap.so.bpmn.infrastructure.workflow.tasks.ebb.loader.UserParamsServiceTraversal; import org.onap.so.bpmn.infrastructure.workflow.tasks.ebb.loader.VnfEBBLoader; import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection; import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; @@ -141,6 +143,10 @@ public class WorkflowActionTest extends BaseTaskTest { @Spy protected VnfEBBLoader vnfEBBLoaderSpy; + @InjectMocks + @Spy + protected ServiceEBBLoader serviceEBBLoader; + @Rule public ExpectedException thrown = ExpectedException.none(); @@ -2094,7 +2100,7 @@ public class WorkflowActionTest extends BaseTaskTest { List resourceCounter = new ArrayList<>(); thrown.expect(BpmnError.class); List> aaiResourceIds = new ArrayList<>(); - workflowAction.traverseCatalogDbService(execution, sIRequest, resourceCounter, aaiResourceIds); + serviceEBBLoader.traverseCatalogDbService(execution, sIRequest, resourceCounter, aaiResourceIds); } @@ -2106,7 +2112,8 @@ public class WorkflowActionTest extends BaseTaskTest { networkCustomization.setModelCustomizationUUID("123"); service.getCollectionResourceCustomizations().add(networkCustomization); doReturn(networkCustomization).when(catalogDbClient).getNetworkCollectionResourceCustomizationByID("123"); - CollectionResourceCustomization customization = workflowAction.findCatalogNetworkCollection(execution, service); + CollectionResourceCustomization customization = + serviceEBBLoader.findCatalogNetworkCollection(execution, service); assertNotNull(customization); } @@ -2116,7 +2123,8 @@ public class WorkflowActionTest extends BaseTaskTest { NetworkCollectionResourceCustomization networkCustomization = new NetworkCollectionResourceCustomization(); networkCustomization.setModelCustomizationUUID("123"); service.getCollectionResourceCustomizations().add(networkCustomization); - CollectionResourceCustomization customization = workflowAction.findCatalogNetworkCollection(execution, service); + CollectionResourceCustomization customization = + serviceEBBLoader.findCatalogNetworkCollection(execution, service); assertNull(customization); } @@ -2131,7 +2139,7 @@ public class WorkflowActionTest extends BaseTaskTest { service.getCollectionResourceCustomizations().add(networkCustomization2); doReturn(networkCustomization1).when(catalogDbClient).getNetworkCollectionResourceCustomizationByID("123"); doReturn(networkCustomization2).when(catalogDbClient).getNetworkCollectionResourceCustomizationByID("321"); - workflowAction.findCatalogNetworkCollection(execution, service); + serviceEBBLoader.findCatalogNetworkCollection(execution, service); assertEquals("Found multiple Network Collections in the Service model, only one per Service is supported.", execution.getVariable("WorkflowActionErrorMessage")); } @@ -2183,7 +2191,7 @@ public class WorkflowActionTest extends BaseTaskTest { .getConfiguration("testConfigurationId"); doReturn(Optional.of(aaiConfiguration2)).when(aaiConfigurationResources) .getConfiguration("testConfigurationId2"); - workflowAction.traverseAAIService(execution, resourceCounter, resourceId, aaiResourceIds); + serviceEBBLoader.traverseAAIService(execution, resourceCounter, resourceId, aaiResourceIds); assertEquals(8, resourceCounter.size()); assertTrue(resourceCounter.get(2).isBaseVfModule()); assertThat(aaiResourceIds, sameBeanAs(getExpectedResourceIds())); @@ -2200,7 +2208,7 @@ public class WorkflowActionTest extends BaseTaskTest { resourceList.add(new Resource(WorkflowType.NETWORK, "model customization id", false)); resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, "model customization id", false)); - assertEquals(workflowAction.foundRelated(resourceList), true); + assertEquals(serviceEBBLoader.foundRelated(resourceList), true); } @Test @@ -2211,11 +2219,11 @@ public class WorkflowActionTest extends BaseTaskTest { resourceList.add(new Resource(WorkflowType.NETWORK, "model customization id", false)); resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, "model customization id", false)); - assertEquals(workflowAction.containsWorkflowType(resourceList, WorkflowType.PNF), true); - assertEquals(workflowAction.containsWorkflowType(resourceList, WorkflowType.VNF), true); - assertEquals(workflowAction.containsWorkflowType(resourceList, WorkflowType.NETWORK), true); - assertEquals(workflowAction.containsWorkflowType(resourceList, WorkflowType.NETWORKCOLLECTION), true); - assertEquals(workflowAction.containsWorkflowType(resourceList, WorkflowType.CONFIGURATION), false); + assertEquals(serviceEBBLoader.containsWorkflowType(resourceList, WorkflowType.PNF), true); + assertEquals(serviceEBBLoader.containsWorkflowType(resourceList, WorkflowType.VNF), true); + assertEquals(serviceEBBLoader.containsWorkflowType(resourceList, WorkflowType.NETWORK), true); + assertEquals(serviceEBBLoader.containsWorkflowType(resourceList, WorkflowType.NETWORKCOLLECTION), true); + assertEquals(serviceEBBLoader.containsWorkflowType(resourceList, WorkflowType.CONFIGURATION), false); } private List> getExpectedResourceIds() { diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/UserParamsServiceTraversalTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/UserParamsServiceTraversalTest.java new file mode 100644 index 0000000000..75514b15d7 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/UserParamsServiceTraversalTest.java @@ -0,0 +1,221 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Modifications Copyright (c) 2020 Nokia + * ================================================================================ + * 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.bpmn.infrastructure.workflow.tasks.ebb.loader; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.common.BBConstants; +import org.onap.so.bpmn.infrastructure.workflow.tasks.Resource; +import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowType; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.db.catalog.beans.ConfigurationResource; +import org.onap.so.db.catalog.beans.CvnfcCustomization; +import org.onap.so.db.catalog.beans.HeatTemplate; +import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization; +import org.onap.so.db.catalog.beans.VfModuleCustomization; +import org.onap.so.db.catalog.beans.Service; +import org.onap.so.db.catalog.beans.VfModule; +import org.onap.so.db.catalog.beans.CollectionResourceCustomization; +import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization; +import org.onap.so.db.catalog.beans.HeatEnvironment; +import org.onap.so.db.catalog.client.CatalogDbClient; +import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; + +public class UserParamsServiceTraversalTest extends BaseTaskTest { + + private static final String MACRO_ASSIGN_JSON = "Macro/ServiceMacroAssign.json"; + private static final String MACRO_ASSIGN_PNF_JSON = "Macro/ServiceMacroAssignPnf.json"; + private static final String NETWORK_COLLECTION_JSON = "Macro/CreateNetworkCollection.json"; + private static final String serviceInstanceId = "123"; + private DelegateExecution execution; + private CatalogDbClient mockCatalogDbClient; + private UserParamsServiceTraversal userParamsServiceTraversal; + private String requestAction; + + @Before + public void before() throws Exception { + execution = new DelegateExecutionFake(); + mockCatalogDbClient = mock(CatalogDbClient.class); + userParamsServiceTraversal = new UserParamsServiceTraversal(mockCatalogDbClient, mock(ExceptionBuilder.class)); + requestAction = "assignInstance"; + } + + @Test + public void getResourceListFromUserParamsForVnfs() throws Exception { + initExecution(requestAction, readBpmnRequestFromFile(MACRO_ASSIGN_JSON), false); + Mockito.doReturn(getVfModuleCustomization()).when(mockCatalogDbClient) + .getVfModuleCustomizationByModelCuztomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); + Mockito.doReturn(getCvnfcCustomizations()).when(mockCatalogDbClient).getCvnfcCustomization(anyString(), + anyString(), anyString()); + + List resourceListFromUserParams = userParamsServiceTraversal.getResourceListFromUserParams(execution, + getUserParams(), serviceInstanceId, requestAction); + List expected = List.of(WorkflowType.SERVICE, WorkflowType.VNF, WorkflowType.VOLUMEGROUP, + WorkflowType.VFMODULE, WorkflowType.CONFIGURATION); + List result = + resourceListFromUserParams.stream().map(Resource::getResourceType).collect(Collectors.toList()); + + assertEquals(5, resourceListFromUserParams.size()); + assertThat(expected, is(result)); + } + + @Test + public void getResourceListFromUserParamsForPnfs() throws Exception { + initExecution(requestAction, readBpmnRequestFromFile(MACRO_ASSIGN_PNF_JSON), false); + Mockito.doReturn(getVfModuleCustomization()).when(mockCatalogDbClient) + .getVfModuleCustomizationByModelCuztomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); + Mockito.doReturn(getCvnfcCustomizations()).when(mockCatalogDbClient).getCvnfcCustomization(anyString(), + anyString(), anyString()); + + List resourceListFromUserParams = userParamsServiceTraversal.getResourceListFromUserParams(execution, + getUserParams(), serviceInstanceId, requestAction); + List expected = List.of(WorkflowType.SERVICE, WorkflowType.PNF); + List result = + resourceListFromUserParams.stream().map(Resource::getResourceType).collect(Collectors.toList()); + + assertEquals(2, resourceListFromUserParams.size()); + assertThat(expected, is(result)); + } + + @Test + public void getResourceListFromUserParamsForNetworks() throws Exception { + requestAction = "createInstance"; + initExecution(requestAction, readBpmnRequestFromFile(NETWORK_COLLECTION_JSON), false); + Mockito.doReturn(getVfModuleCustomization()).when(mockCatalogDbClient) + .getVfModuleCustomizationByModelCuztomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); + Mockito.doReturn(getCvnfcCustomizations()).when(mockCatalogDbClient).getCvnfcCustomization(anyString(), + anyString(), anyString()); + Mockito.doReturn(getService()).when(mockCatalogDbClient).getServiceByID(anyString()); + Mockito.doReturn(new NetworkCollectionResourceCustomization()).when(mockCatalogDbClient) + .getNetworkCollectionResourceCustomizationByID(anyString()); + + List resourceListFromUserParams = userParamsServiceTraversal.getResourceListFromUserParams(execution, + getUserParams(), serviceInstanceId, requestAction); + List expected = List.of(WorkflowType.SERVICE, WorkflowType.NETWORK, WorkflowType.NETWORK, + WorkflowType.NETWORKCOLLECTION); + List result = + resourceListFromUserParams.stream().map(Resource::getResourceType).collect(Collectors.toList()); + + assertEquals(4, resourceListFromUserParams.size()); + assertThat(expected, is(result)); + } + + @Test + public void getResourceListFromUserParamsBuildAndThrowExceptionWhenVfModuleAreEmpty() throws Exception { + initExecution(requestAction, readBpmnRequestFromFile(MACRO_ASSIGN_JSON), false); + VfModuleCustomization vfModuleCustomization = new VfModuleCustomization(); + vfModuleCustomization.setVfModule(null); + Mockito.doReturn(vfModuleCustomization).when(mockCatalogDbClient) + .getVfModuleCustomizationByModelCuztomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); + + List resourceListFromUserParams = userParamsServiceTraversal.getResourceListFromUserParams(execution, + getUserParams(), serviceInstanceId, requestAction); + List expected = List.of(WorkflowType.SERVICE, WorkflowType.VNF); + List result = + resourceListFromUserParams.stream().map(Resource::getResourceType).collect(Collectors.toList()); + + assertEquals(2, resourceListFromUserParams.size()); + assertThat(expected, is(result)); + } + + private List> getUserParams() throws IOException { + String bpmnRequest = (String) execution.getVariable(BBConstants.G_BPMN_REQUEST); + ServiceInstancesRequest sIRequest = new ObjectMapper().readValue(bpmnRequest, ServiceInstancesRequest.class); + return sIRequest.getRequestDetails().getRequestParameters().getUserParams(); + } + + @Test + public void getResourceListFromUserParamsWhenUserParamsAreNull() throws Exception { + List expectedResourceList = new ArrayList<>(); + List resultResourceList = userParamsServiceTraversal.getResourceListFromUserParams(execution, null, + serviceInstanceId, requestAction); + + assertEquals(expectedResourceList, resultResourceList); + } + + private String readBpmnRequestFromFile(String fileName) throws IOException { + return new String(Files.readAllBytes(Paths.get("src/test/resources/__files/" + fileName))); + } + + private void initExecution(String gAction, String bpmnRequest, boolean isAlaCarte) { + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + execution.setVariable("requestAction", gAction); + execution.setVariable("bpmnRequest", bpmnRequest); + execution.setVariable("aLaCarte", isAlaCarte); + execution.setVariable("apiVersion", "7"); + } + + private Service getService() { + Service service = new Service(); + List collectionResourceCustomizations = new ArrayList<>(); + CollectionResourceCustomization collectionResourceCustomization = new CollectionResourceCustomization(); + collectionResourceCustomization.setModelCustomizationUUID("123"); + collectionResourceCustomizations.add(collectionResourceCustomization); + service.setCollectionResourceCustomizations(collectionResourceCustomizations); + return service; + } + + private VfModuleCustomization getVfModuleCustomization() { + VfModuleCustomization vfModuleCustomization = new VfModuleCustomization(); + vfModuleCustomization.setVolumeHeatEnv(new HeatEnvironment()); + vfModuleCustomization.setModelCustomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); + VfModule vfModule = new VfModule(); + vfModule.setVolumeHeatTemplate(new HeatTemplate()); + vfModule.setModelName("helm"); + vfModule.setModuleHeatTemplate(new HeatTemplate()); + vfModuleCustomization.setVfModule(vfModule); + return vfModuleCustomization; + } + + private List getCvnfcCustomizations() { + ConfigurationResource configurationResource = new ConfigurationResource(); + configurationResource.setToscaNodeType("FabricConfiguration"); + + CvnfcConfigurationCustomization cvnfcConfigurationCustomization = new CvnfcConfigurationCustomization(); + cvnfcConfigurationCustomization.setConfigurationResource(configurationResource); + CvnfcCustomization cvnfcCustomization = new CvnfcCustomization(); + + List cvnfcConfigurationCustomizations = new ArrayList<>(); + cvnfcConfigurationCustomizations.add(cvnfcConfigurationCustomization); + cvnfcCustomization.setCvnfcConfigurationCustomization(cvnfcConfigurationCustomizations); + + List cvnfcCustomizations = new ArrayList<>(); + cvnfcCustomizations.add(cvnfcCustomization); + return cvnfcCustomizations; + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VrfValidationTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VrfValidationTest.java new file mode 100644 index 0000000000..dcccb74f58 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VrfValidationTest.java @@ -0,0 +1,220 @@ +/*- + * ============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.bpmn.infrastructure.workflow.tasks.ebb.loader; + +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.aaiclient.client.aai.entities.AAIResultWrapper; +import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.infrastructure.workflow.tasks.VrfBondingServiceException; +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("test-vpn", aaiVpnBinding); + } + + @Test + public void testAaiVpnBindingValidationVpnBindingIsNull() throws VrfBondingServiceException { + exceptionRule.expect(VrfBondingServiceException.class); + exceptionRule.expectMessage("The infrastructure vpn test-vpn does not exist in A&AI."); + vrfValidation.aaiVpnBindingValidation("test-vpn", null); + } + + @Test + public void testAaiNetworkValidation() throws VrfBondingServiceException { + org.onap.aai.domain.yang.L3Network aaiLocalNetwork = new org.onap.aai.domain.yang.L3Network(); + aaiLocalNetwork.setNetworkId("test-network"); + ExpectedException.none(); + vrfValidation.aaiNetworkValidation("test-network", aaiLocalNetwork); + } + + @Test + public void testAaiNetworkValidationNetworkIsNull() throws VrfBondingServiceException { + exceptionRule.expect(VrfBondingServiceException.class); + exceptionRule.expectMessage("The local network test-network does not exist in A&AI."); + vrfValidation.aaiNetworkValidation("test-network", null); + } + + @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 vpnBindingUris = + networkWrapper.getRelationships().get().getRelatedUris(Types.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); + } + } +} -- cgit 1.2.3-korg