From a5a46f26d043b70cd9a44fed05b0e8ba184318fb Mon Sep 17 00:00:00 2001 From: KrupaNagabhushan Date: Thu, 17 Sep 2020 15:11:30 +0100 Subject: Fix for substitution filter properties Issue-ID: SDC-3325 Change-Id: If26bf895a0a2f914fb9c2b36e53466df9b7999fe Signed-off-by: KrupaNagabhushan --- .../java/org/openecomp/sdc/be/model/Component.java | 1 + .../openecomp/sdc/be/model/ComponentInstance.java | 1 - .../sdc/be/model/ComponentParametersView.java | 14 ---- .../operations/SubstitutionFilterOperation.java | 77 ++++++++++------------ .../model/jsonjanusgraph/utils/ModelConverter.java | 12 +--- 5 files changed, 37 insertions(+), 68 deletions(-) (limited to 'catalog-model/src/main/java') diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java index ba73e77e05..8f58a3c4d2 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java @@ -87,6 +87,7 @@ public abstract class Component implements PropertiesOwner { private Map substitutionFilterComponents; private Map interfaces; private List dataTypes; + private SubstitutionFilterDataDefinition substitutionFilter; public Component(ComponentMetadataDefinition componentMetadataDefinition) { this.componentMetadataDefinition = componentMetadataDefinition; diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstance.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstance.java index 5b99f99bd2..fd4feeb035 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstance.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstance.java @@ -47,7 +47,6 @@ public class ComponentInstance extends ComponentInstanceDataDefinition implement private Map interfaces; private List properties; private CINodeFilterDataDefinition nodeFilter; - private SubstitutionFilterDataDefinition substitutionFilter; private List inputs; public ComponentInstance() { diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java index f1785c76f8..505b8e6c7c 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java @@ -50,7 +50,6 @@ public class ComponentParametersView { private boolean ignoreServicePath = true; private boolean ignorePolicies = false; private boolean ignoreNodeFilterRequirements = false; - private boolean ignoreSubstitutionFilterRequirements = false; private boolean ignoreNodeFilter = false; private boolean ignoreSubstitutionFilter = false; private boolean ignoreDataType = false; @@ -157,7 +156,6 @@ public class ComponentParametersView { this.setIgnoreNodeFilter(false); break; case SUBSTITUTION_FILTER: - this.setIgnoreSubstitutionFilterRequirements(false); this.setIgnoreSubstitutionFilter(false); break; case COMPONENT_INSTANCES_INTERFACES: @@ -223,9 +221,6 @@ public class ComponentParametersView { if (ignoreNodeFilterRequirements){ component.setNodeFilterComponents(null); } - if (ignoreSubstitutionFilterRequirements){ - component.setSubstitutionFilterComponents(null); - } if (ignoreInterfaces && ignoreInterfaceInstances && componentType == ComponentTypeEnum.RESOURCE) { component.setInterfaces(null); @@ -268,14 +263,6 @@ public class ComponentParametersView { this.ignoreNodeFilterRequirements = ignoreNodeFilter; } - public boolean isIgnoreSubstitutionFilterRequirements() { - return ignoreSubstitutionFilterRequirements; - } - - public void setIgnoreSubstitutionFilterRequirements(boolean ignoreSubstitutionFilterRequirements) { - this.ignoreSubstitutionFilterRequirements = ignoreSubstitutionFilterRequirements; - } - public void disableAll() { ignoreUsers = true; ignoreGroups = true; @@ -299,7 +286,6 @@ public class ComponentParametersView { ignoreCapabiltyProperties = true; ignoreServicePath = true; ignoreNodeFilterRequirements = true; - ignoreSubstitutionFilterRequirements = true; ignoreNodeFilter = true; ignoreSubstitutionFilter = true; ignoreDataType = true; diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/SubstitutionFilterOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/SubstitutionFilterOperation.java index 9007e20998..0062e2eaa7 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/SubstitutionFilterOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/SubstitutionFilterOperation.java @@ -22,6 +22,7 @@ package org.openecomp.sdc.be.model.jsonjanusgraph.operations; import com.google.common.collect.ImmutableList; import fj.data.Either; import java.util.List; +import java.util.Objects; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; @@ -44,78 +45,70 @@ public class SubstitutionFilterOperation extends BaseOperation { private static final Logger LOGGER = Logger.getLogger(SubstitutionFilterOperation.class); public Either createSubstitutionFilter( - final String componentId, final String componentInstanceId) { + final String componentId) { - return addOrUpdateSubstitutionFilter(false, componentId, componentInstanceId, - new SubstitutionFilterDataDefinition()); + return addOrUpdateSubstitutionFilter(false, componentId, new SubstitutionFilterDataDefinition()); } public Either deleteConstraint( - final String serviceId, final String componentInstanceId, - final SubstitutionFilterDataDefinition substitutionFilterDataDefinition, final int propertyIndex) { + final String serviceId, final SubstitutionFilterDataDefinition substitutionFilterDataDefinition, + final int propertyIndex) { final ListDataDefinition properties = - substitutionFilterDataDefinition.getProperties(); + substitutionFilterDataDefinition.getProperties(); properties.getListToscaDataDefinition().remove(propertyIndex); substitutionFilterDataDefinition.setProperties(properties); - return addOrUpdateSubstitutionFilter(true, serviceId, componentInstanceId, substitutionFilterDataDefinition); + + return addOrUpdateSubstitutionFilter(true, serviceId, substitutionFilterDataDefinition); } - public Either addNewProperty( - final String componentId, final String componentInstanceId, - final SubstitutionFilterDataDefinition substitutionFilterDataDefinition, - final RequirementSubstitutionFilterPropertyDataDefinition requirementSubstitutionFilterPropertyDataDefinition) { + public Either addPropertyFilter( + final String componentId, final SubstitutionFilterDataDefinition substitutionFilterDataDefinition, + final RequirementSubstitutionFilterPropertyDataDefinition substitutionFilterPropertyDataDefinition) { - ListDataDefinition properties = - substitutionFilterDataDefinition.getProperties(); - if (properties == null) { - properties = new ListDataDefinition<>(); - substitutionFilterDataDefinition.setProperties(properties); - } - properties.getListToscaDataDefinition().add(requirementSubstitutionFilterPropertyDataDefinition); - substitutionFilterDataDefinition.setProperties(properties); - return addOrUpdateSubstitutionFilter(true, componentId, componentInstanceId, substitutionFilterDataDefinition); + final SubstitutionFilterDataDefinition substitutionFilterDataDefinition1 = + Objects.requireNonNullElseGet(substitutionFilterDataDefinition, SubstitutionFilterDataDefinition::new); + final ListDataDefinition properties = + Objects.requireNonNullElseGet(substitutionFilterDataDefinition1.getProperties(), ListDataDefinition::new); + properties.getListToscaDataDefinition().add(substitutionFilterPropertyDataDefinition); + substitutionFilterDataDefinition1.setProperties(properties); + return addOrUpdateSubstitutionFilter(true, componentId, substitutionFilterDataDefinition1); } - public Either updateSubstitutionFilter( - final String serviceId, final String componentInstanceId, - final SubstitutionFilterDataDefinition substitutionFilterDataDefinition, - final List requirementSubstitutionFilterPropertyDataDefinitions) { + public Either updateProperties( + final String componentId, final SubstitutionFilterDataDefinition substitutionFilterDataDefinition, + final List requirementSubstitutionFilterPropertyDataDefinition) { final ListDataDefinition properties = substitutionFilterDataDefinition.getProperties(); properties.getListToscaDataDefinition().clear(); - properties.getListToscaDataDefinition().addAll(requirementSubstitutionFilterPropertyDataDefinitions); + properties.getListToscaDataDefinition().addAll(requirementSubstitutionFilterPropertyDataDefinition); substitutionFilterDataDefinition.setProperties(properties); - return addOrUpdateSubstitutionFilter(true, serviceId, componentInstanceId, - substitutionFilterDataDefinition); + return addOrUpdateSubstitutionFilter(true, componentId, substitutionFilterDataDefinition); } private Either addOrUpdateSubstitutionFilter( - final boolean isUpdateAction, final String componentId, final String componentInstanceId, + final boolean isUpdateAction, final String componentId, final SubstitutionFilterDataDefinition substitutionFilterDataDefinition) { - StorageOperationStatus statusRes; - Either getToscaElementRes; - - getToscaElementRes = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse); - if (getToscaElementRes.isRight()) { - final JanusGraphOperationStatus status = getToscaElementRes.right().value(); + final Either toscaElementEither = + janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse); + if (toscaElementEither.isRight()) { + final JanusGraphOperationStatus status = toscaElementEither.right().value(); CommonUtility.addRecordToLog(LOGGER, CommonUtility.LogLevelEnum.DEBUG, "Failed to get tosca element {} upon adding the properties. Status is {}. ", componentId, status); - statusRes = DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status); - return Either.right(statusRes); + return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } - final GraphVertex serviceVertex = getToscaElementRes.left().value(); - substitutionFilterDataDefinition.setID(componentInstanceId); - statusRes = performUpdateToscaAction(isUpdateAction, serviceVertex, + final GraphVertex serviceVertex = toscaElementEither.left().value(); + substitutionFilterDataDefinition.setID(componentId); + final StorageOperationStatus operationStatus = performUpdateToscaAction(isUpdateAction, serviceVertex, ImmutableList.of(substitutionFilterDataDefinition)); - if (!statusRes.equals(StorageOperationStatus.OK)) { + if (!StorageOperationStatus.OK.equals(operationStatus)) { janusGraphDao.rollback(); LOGGER.error(EcompErrorSeverity.ERROR, EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR, " Failed to perform tosca update for substitution filter in service {} , component instance {}. status is {}", - componentId, componentInstanceId, statusRes); - return Either.right(statusRes); + componentId, "componentInstanceId", operationStatus); + return Either.right(operationStatus); } janusGraphDao.commit(); return Either.left(substitutionFilterDataDefinition); diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java index 839ae27a19..4d2480f6af 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java @@ -909,14 +909,9 @@ public class ModelConverter { final Component component) { final Map filters = topologyTemplate .getSubstitutionFilterDataDefinitionMap(); - final Map copy; if (MapUtils.isNotEmpty(filters)) { - copy = filters.entrySet().stream() - .collect(Collectors.toMap(Map.Entry::getKey, e -> new SubstitutionFilterDataDefinition(e.getValue()))); - } else { - copy = new HashMap<>(); + component.setSubstitutionFilter(filters.get(component.getUniqueId())); } - component.setSubstitutionFilterComponents(copy); } private static void convertServiceApiArtifacts(TopologyTemplate topologyTemplate, Service service) { @@ -1361,8 +1356,6 @@ public class ModelConverter { List componentInstances = new ArrayList<>(); ComponentInstance currComponentInstance; Map nodeFilterComponents = topologyTemplate.getNodeFilterComponents(); - Map substitutionFilterDataDefinitionMap = topologyTemplate - .getSubstitutionFilterDataDefinitionMap(); for (Map.Entry entry : topologyTemplate.getComponentInstances().entrySet()) { String key = entry.getKey(); @@ -1375,9 +1368,6 @@ public class ModelConverter { if(MapUtils.isNotEmpty(nodeFilterComponents) && nodeFilterComponents.containsKey(key)){ currComponentInstance.setNodeFilter(nodeFilterComponents.get(key)); } - if(MapUtils.isNotEmpty(substitutionFilterDataDefinitionMap) && substitutionFilterDataDefinitionMap.containsKey(key)) { - currComponentInstance.setSubstitutionFilter(substitutionFilterDataDefinitionMap.get(key)); - } if(topologyTemplate.getInstProperties() != null && topologyTemplate.getInstProperties().containsKey(key) && topologyTemplate.getInstProperties().get(key) != null ){ List instanceProps = topologyTemplate.getInstProperties().get(key).getMapToscaDataDefinition().entrySet().stream().map(e -> new PropertyDefinition(e.getValue())).collect(Collectors.toList()); currComponentInstance.setProperties(instanceProps); -- cgit 1.2.3-korg