diff options
Diffstat (limited to 'catalog-be/src/main/java')
3 files changed, 114 insertions, 2 deletions
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<String, UploadNodeFilterInfo> instNodeFilter) { + for (Entry<String, UploadNodeFilterInfo> filter : instNodeFilter.entrySet()) { + String componentInstanceId = filter.getKey(); + CINodeFilterDataDefinition ciNodeFilterDataDefinition = new CINodeFilterUtils() + .getNodeFilterDataDefinition(filter.getValue(), componentInstanceId); + Either<CINodeFilterDataDefinition, StorageOperationStatus> 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<RequirementNodeFilterPropertyDataDefinition> properties = ciNodeFilterDataDefinition.getProperties() + .getListToscaDataDefinition(); + if (!properties.isEmpty()) { + properties.forEach(property -> { + RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition = + getRequirementNodeFilterPropertyDataDefinition(property); + Either<CINodeFilterDataDefinition, StorageOperationStatus> 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<RequirementNodeFilterCapabilityDataDefinition> capabilities = ciNodeFilterDataDefinition.getCapabilities() + .getListToscaDataDefinition(); + if (!capabilities.isEmpty()) { + capabilities.forEach(capability -> { + RequirementNodeFilterCapabilityDataDefinition requirementNodeFilterCapabilityDataDefinition = + new RequirementNodeFilterCapabilityDataDefinition(); + requirementNodeFilterCapabilityDataDefinition.setName(capability.getName()); + requirementNodeFilterCapabilityDataDefinition.setProperties(getProperties(capability.getProperties())); + Either<CINodeFilterDataDefinition, StorageOperationStatus> 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<String> getNodeFilterConstraints(String name, List<String> value) { + List<String> constraints = new ArrayList<>(); + String values = value.get(0).split("\n")[0]; + constraints.add(name + ": {" + values + "}"); + return constraints; + } + + private ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> getProperties(ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> properties) { + ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> 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<String, Resource> originCompMap = new HashMap<>(); List<RequirementCapabilityRelDef> relations = new ArrayList<>(); Map<String, List<ComponentInstanceInput>> instInputs = new HashMap<>(); + Map<String, UploadNodeFilterInfo> 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<String, Resource> originCompMap = new HashMap<>(); List<RequirementCapabilityRelDef> relations = new ArrayList<>(); Map<String, List<ComponentInstanceInput>> instInputs = new HashMap<>(); + Map<String, UploadNodeFilterInfo> 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<String, Map<String, ArtifactDefinition>> instArtifacts, Map<String, List<AttributeDefinition>> instAttributes, Map<String, Resource> originCompMap, Map<String, List<ComponentInstanceInput>> instInputs, + Map<String, UploadNodeFilterInfo> instNodeFilter, UploadComponentInstanceInfo uploadComponentInstanceInfo) { log.debug("enter ServiceImportBusinessLogic processComponentInstance"); Optional<ComponentInstance> 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<Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>>, ResponseFormat> findNodeTypesArtifactsToHandle( Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo, Service oldResource) { @@ -2127,6 +2132,17 @@ public class ServiceImportParseLogic { } } + public void associateCINodeFilterToComponent(String yamlName, Service service, Map<String, UploadNodeFilterInfo> 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<String, List<ComponentInstanceProperty>> instProperties) { Either<Map<String, List<ComponentInstanceProperty>>, StorageOperationStatus> addPropToInst = toscaOperationFacade |