From a7dd2ece847fa88dda4912994f2e5220bd4adb7b Mon Sep 17 00:00:00 2001 From: KrupaNagabhushan Date: Wed, 3 Nov 2021 20:43:16 +0000 Subject: Update import service to import node filter Issue-ID: SDC-3775 Signed-off-by: KrupaNagabhushan Change-Id: Ide75c9319ad321d796a1ead34cbf425ad8de5504 --- .../impl/ComponentNodeFilterBusinessLogic.java | 86 ++++++++++++++++++++++ .../impl/ServiceImportBusinessLogic.java | 14 +++- .../components/impl/ServiceImportParseLogic.java | 16 ++++ 3 files changed, 114 insertions(+), 2 deletions(-) (limited to 'catalog-be/src/main/java/org') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogic.java index 43187a59d6..729538c640 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogic.java @@ -21,11 +21,17 @@ package org.openecomp.sdc.be.components.impl; import static org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR; import fj.data.Either; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import java.util.Optional; import org.apache.commons.lang3.StringUtils; import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException; +import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.utils.CINodeFilterUtils; import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction; import org.openecomp.sdc.be.components.validation.NodeFilterValidator; import org.openecomp.sdc.be.dao.api.ActionStatus; @@ -38,6 +44,7 @@ import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.NodeFilterConstraintType; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.ComponentInstance; +import org.openecomp.sdc.be.model.UploadNodeFilterInfo; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.InterfaceOperation; @@ -318,4 +325,83 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic { new ConstraintConvertor().convert(uiConstraint), true, componentTypeEnum, nodeFilterConstraintType, StringUtils.isEmpty(uiConstraint.getCapabilityName()) ? "" : uiConstraint.getCapabilityName()); } + + public StorageOperationStatus associateNodeFilterToComponentInstance(final String componentId, + final Map instNodeFilter) { + for (Entry filter : instNodeFilter.entrySet()) { + String componentInstanceId = filter.getKey(); + CINodeFilterDataDefinition ciNodeFilterDataDefinition = new CINodeFilterUtils() + .getNodeFilterDataDefinition(filter.getValue(), componentInstanceId); + Either nodeFilter = nodeFilterOperation.createNodeFilter(componentId, + componentInstanceId); + if (nodeFilter.isRight()) { + LOGGER.error(BUSINESS_PROCESS_ERROR, "Failed to Create Node filter on component instance with id {}", + filter.getKey()); + return nodeFilter.right().value(); + } + + //associate node filter properties to component instance + List properties = ciNodeFilterDataDefinition.getProperties() + .getListToscaDataDefinition(); + if (!properties.isEmpty()) { + properties.forEach(property -> { + RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition = + getRequirementNodeFilterPropertyDataDefinition(property); + Either nodeFilterProperty = nodeFilterOperation + .addNewProperty(componentId, componentInstanceId, nodeFilter.left().value(), requirementNodeFilterPropertyDataDefinition); + if (nodeFilterProperty.isRight()) { + throw new ComponentException( + componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(nodeFilterProperty.right().value()), + componentInstanceId)); + } + }); + } + + //associate node filter capabilities to component instance + List capabilities = ciNodeFilterDataDefinition.getCapabilities() + .getListToscaDataDefinition(); + if (!capabilities.isEmpty()) { + capabilities.forEach(capability -> { + RequirementNodeFilterCapabilityDataDefinition requirementNodeFilterCapabilityDataDefinition = + new RequirementNodeFilterCapabilityDataDefinition(); + requirementNodeFilterCapabilityDataDefinition.setName(capability.getName()); + requirementNodeFilterCapabilityDataDefinition.setProperties(getProperties(capability.getProperties())); + Either nodeFilterCapability = nodeFilterOperation + .addNewCapabilities(componentId, componentInstanceId, nodeFilter.left().value(), + requirementNodeFilterCapabilityDataDefinition); + if (nodeFilterCapability.isRight()) { + throw new ComponentException( + componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(nodeFilterCapability.right().value()), + componentInstanceId)); + } + }); + } + } + return StorageOperationStatus.OK; + } + + private List getNodeFilterConstraints(String name, List value) { + List constraints = new ArrayList<>(); + String values = value.get(0).split("\n")[0]; + constraints.add(name + ": {" + values + "}"); + return constraints; + } + + private ListDataDefinition getProperties(ListDataDefinition properties) { + ListDataDefinition updatedProperties = new ListDataDefinition<>(); + properties.getListToscaDataDefinition().forEach(property -> { + RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition = getRequirementNodeFilterPropertyDataDefinition( + property); + updatedProperties.add(requirementNodeFilterPropertyDataDefinition); + }); + return updatedProperties; + } + + private RequirementNodeFilterPropertyDataDefinition getRequirementNodeFilterPropertyDataDefinition( + RequirementNodeFilterPropertyDataDefinition property) { + RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition = new RequirementNodeFilterPropertyDataDefinition(); + requirementNodeFilterPropertyDataDefinition.setName(property.getName()); + requirementNodeFilterPropertyDataDefinition.setConstraints(getNodeFilterConstraints(property.getName(), property.getConstraints())); + return requirementNodeFilterPropertyDataDefinition; + } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java index d3e7085e4f..2fa20ea3a9 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java @@ -68,6 +68,7 @@ import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datamodel.utils.ArtifactUtils; import org.openecomp.sdc.be.datamodel.utils.UiComponentDataConverter; +import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition; import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition; @@ -171,6 +172,8 @@ public class ServiceImportBusinessLogic { private ResourceDataMergeBusinessLogic resourceDataMergeBusinessLogic; @Autowired private ServiceImportParseLogic serviceImportParseLogic; + @Autowired + private ComponentNodeFilterBusinessLogic componentNodeFilterBusinessLogic; @Autowired public ServiceImportBusinessLogic(IElementOperation elementDao, IGroupOperation groupOperation, IGroupInstanceOperation groupInstanceOperation, @@ -971,6 +974,7 @@ public class ServiceImportBusinessLogic { Map originCompMap = new HashMap<>(); List relations = new ArrayList<>(); Map> instInputs = new HashMap<>(); + Map instNodeFilter = new HashMap<>(); log.debug("enter ServiceImportBusinessLogic createResourceInstancesRelations#createResourceInstancesRelations - Before get all datatypes. "); final ApplicationDataTypeCache applicationDataTypeCache = serviceBusinessLogic.applicationDataTypeCache; @@ -979,7 +983,7 @@ public class ServiceImportBusinessLogic { uploadResInstancesMap.values().forEach( i -> processComponentInstance(yamlName, finalResource, componentInstancesList, componentsUtils.getAllDataTypes(applicationDataTypeCache, finalResource.getModel()), instProperties, instCapabilities, - instRequirements, instDeploymentArtifacts, instArtifacts, instAttributes, originCompMap, instInputs, i)); + instRequirements, instDeploymentArtifacts, instArtifacts, instAttributes, originCompMap, instInputs, instNodeFilter, i)); } serviceImportParseLogic.associateComponentInstancePropertiesToComponent(yamlName, resource, instProperties); serviceImportParseLogic.associateComponentInstanceInputsToComponent(yamlName, resource, instInputs); @@ -1334,6 +1338,7 @@ public class ServiceImportBusinessLogic { Map originCompMap = new HashMap<>(); List relations = new ArrayList<>(); Map> instInputs = new HashMap<>(); + Map instNodeFilter = new HashMap<>(); log.debug("enter ServiceImportBusinessLogic createServiceInstancesRelations#createResourceInstancesRelations - Before get all datatypes. "); final ApplicationDataTypeCache applicationDataTypeCache = serviceBusinessLogic.applicationDataTypeCache; if (applicationDataTypeCache != null) { @@ -1341,10 +1346,11 @@ public class ServiceImportBusinessLogic { uploadResInstancesMap.values().forEach( i -> processComponentInstance(yamlName, finalResource, componentInstancesList, componentsUtils.getAllDataTypes(applicationDataTypeCache, finalResource.getModel()), instProperties, - instCapabilities, instRequirements, instDeploymentArtifacts, instArtifacts, instAttributes, originCompMap, instInputs, i)); + instCapabilities, instRequirements, instDeploymentArtifacts, instArtifacts, instAttributes, originCompMap, instInputs, instNodeFilter, i)); } serviceImportParseLogic.associateComponentInstancePropertiesToComponent(yamlName, service, instProperties); serviceImportParseLogic.associateComponentInstanceInputsToComponent(yamlName, service, instInputs); + serviceImportParseLogic.associateCINodeFilterToComponent(yamlName, service, instNodeFilter); serviceImportParseLogic.associateDeploymentArtifactsToInstances(user, yamlName, service, instDeploymentArtifacts); serviceImportParseLogic.associateArtifactsToInstances(yamlName, service, instArtifacts); serviceImportParseLogic.associateOrAddCalculatedCapReq(yamlName, service, instCapabilities, instRequirements); @@ -1379,6 +1385,7 @@ public class ServiceImportBusinessLogic { Map> instArtifacts, Map> instAttributes, Map originCompMap, Map> instInputs, + Map instNodeFilter, UploadComponentInstanceInfo uploadComponentInstanceInfo) { log.debug("enter ServiceImportBusinessLogic processComponentInstance"); Optional currentCompInstanceOpt = componentInstancesList.stream() @@ -1409,6 +1416,9 @@ public class ServiceImportBusinessLogic { if (originResource.getAttributes() != null && !originResource.getAttributes().isEmpty()) { instAttributes.put(resourceInstanceId, originResource.getAttributes()); } + if (uploadComponentInstanceInfo.getUploadNodeFilterInfo() != null) { + instNodeFilter.put(resourceInstanceId, uploadComponentInstanceInfo.getUploadNodeFilterInfo()); + } if (originResource.getResourceType() != ResourceTypeEnum.VF) { ResponseFormat addPropertiesValueToRiRes = addPropertyValuesToRi(uploadComponentInstanceInfo, component, originResource, currentCompInstance, instProperties, allDataTypes); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java index 196fc679ad..d9f5e1a5b9 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java @@ -23,6 +23,7 @@ import static org.apache.commons.collections.CollectionUtils.isNotEmpty; import fj.data.Either; import java.util.ArrayList; +import java.util.Collections; import java.util.EnumMap; import java.util.HashMap; import java.util.HashSet; @@ -49,6 +50,7 @@ import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition; import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition; import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition; @@ -87,6 +89,7 @@ import org.openecomp.sdc.be.model.Service; import org.openecomp.sdc.be.model.UploadCapInfo; import org.openecomp.sdc.be.model.UploadComponentInstanceInfo; import org.openecomp.sdc.be.model.UploadInfo; +import org.openecomp.sdc.be.model.UploadNodeFilterInfo; import org.openecomp.sdc.be.model.UploadPropInfo; import org.openecomp.sdc.be.model.UploadReqInfo; import org.openecomp.sdc.be.model.UploadResourceInfo; @@ -147,6 +150,8 @@ public class ServiceImportParseLogic { private IInterfaceLifecycleOperation interfaceTypeOperation = null; @Autowired private ICapabilityTypeOperation capabilityTypeOperation = null; + @Autowired + private ComponentNodeFilterBusinessLogic componentNodeFilterBusinessLogic; public Either>>, ResponseFormat> findNodeTypesArtifactsToHandle( Map nodeTypesInfo, CsarInfo csarInfo, Service oldResource) { @@ -2127,6 +2132,17 @@ public class ServiceImportParseLogic { } } + public void associateCINodeFilterToComponent(String yamlName, Service service, Map nodeFilter) { + log.trace("************* Going to associate all resource node filters {}", yamlName); + if (MapUtils.isNotEmpty(nodeFilter)) { + StorageOperationStatus status = componentNodeFilterBusinessLogic.associateNodeFilterToComponentInstance(service.getUniqueId(), nodeFilter); + if (status != StorageOperationStatus.OK) { + throw new ComponentException( + componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status), yamlName)); + } + } + } + public void associateComponentInstancePropertiesToComponent(String yamlName, Service service, Map> instProperties) { Either>, StorageOperationStatus> addPropToInst = toscaOperationFacade -- cgit 1.2.3-korg