From 1a6dc06b35e3d49953325a3d6c1eefee76ac8601 Mon Sep 17 00:00:00 2001 From: ojasdubey Date: Fri, 7 Jun 2019 16:36:39 +0530 Subject: Fix Service proxy node template Fixes for issues: 1. Declared properties of VFCs not appearing in proxy node template 2. Proper value resolution of proxy properties Change-Id: I4b5bedc7e2a4b4071f3adb4dfe909db80575c25a Issue-ID: SDC-2359 Signed-off-by: ojasdubey --- .../sdc/be/components/utils/PropertiesUtils.java | 38 +++++++++++++++++----- .../openecomp/sdc/be/tosca/ToscaExportHandler.java | 20 ++++++------ .../sdc/be/tosca/utils/ToscaExportUtils.java | 32 +++--------------- 3 files changed, 43 insertions(+), 47 deletions(-) (limited to 'catalog-be/src/main/java/org') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/PropertiesUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/PropertiesUtils.java index 7bea8356a7..613ced6454 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/PropertiesUtils.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/PropertiesUtils.java @@ -16,11 +16,14 @@ package org.openecomp.sdc.be.components.utils; +import static org.openecomp.sdc.be.components.property.GetInputUtils.isGetInputValueForInput; + import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.function.Function; @@ -29,6 +32,8 @@ import java.util.stream.Collectors; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; +import org.apache.commons.collections4.ListUtils; +import org.apache.commons.collections4.SetUtils; import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; @@ -39,8 +44,6 @@ import org.openecomp.sdc.be.model.InputDefinition; import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.Resource; -import static org.openecomp.sdc.be.components.property.GetInputUtils.isGetInputValueForInput; - public class PropertiesUtils { private PropertiesUtils() { @@ -53,16 +56,33 @@ public class PropertiesUtils { properties = new ArrayList<>(); } Set serviceProperties = new HashSet<>(properties); - if (service.getInputs() != null) { - Set inputs = service.getInputs().stream().map(PropertyDefinition::new) - .collect(Collectors.toSet()); - serviceProperties.addAll(inputs); - } - serviceProperties = - serviceProperties.stream().filter(distinctByKey(PropertyDefinition::getName)).collect(Collectors.toSet()); + SetUtils.emptyIfNull(serviceProperties) + .forEach(propertyDefinition -> resolvePropertyValueFromInput(propertyDefinition, + service.getInputs())); + Set inputs = ListUtils.emptyIfNull(service.getInputs()).stream() + .map(PropertyDefinition::new) + .collect(Collectors.toSet()); + serviceProperties.addAll(inputs); + serviceProperties = serviceProperties.stream() + .filter(distinctByKey(PropertyDefinition::getName)) + .collect(Collectors.toSet()); return new ArrayList<>(serviceProperties); } + public static PropertyDefinition resolvePropertyValueFromInput(PropertyDefinition propertyDefinition, + List componentInputs) { + if (Objects.isNull(propertyDefinition) || CollectionUtils.isEmpty(componentInputs)) { + return propertyDefinition; + } + Optional mappedInput = componentInputs.stream() + .filter(componentInput -> Objects.nonNull(componentInput.getPropertyId()) + && componentInput.getPropertyId().equals(propertyDefinition.getUniqueId())) + .findFirst(); + mappedInput.ifPresent(inputDefinition -> propertyDefinition.setValue(inputDefinition.getValue())); + return propertyDefinition; + } + + public static Optional isCapabilityProperty(String propertyUniqueId, Component containerComponent) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java index 1301a1c7a9..e6e69bf8de 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java @@ -75,12 +75,12 @@ import java.util.stream.Collectors; import static org.apache.commons.collections.CollectionUtils.isEmpty; import static org.apache.commons.collections.CollectionUtils.isNotEmpty; import static org.apache.commons.collections.MapUtils.isNotEmpty; +import static org.openecomp.sdc.be.components.utils.PropertiesUtils.resolvePropertyValueFromInput; import static org.openecomp.sdc.be.tosca.utils.InterfacesOperationsToscaUtil.addInterfaceDefinitionElement; import static org.openecomp.sdc.be.tosca.utils.InterfacesOperationsToscaUtil.addInterfaceTypeElement; import static org.openecomp.sdc.be.tosca.utils.ToscaExportUtils.addInputsToProperties; import static org.openecomp.sdc.be.tosca.utils.ToscaExportUtils.getProxyNodeTypeInterfaces; import static org.openecomp.sdc.be.tosca.utils.ToscaExportUtils.getProxyNodeTypeProperties; -import static org.openecomp.sdc.be.tosca.utils.ToscaExportUtils.resolvePropertyDefaultValueFromInput; @org.springframework.stereotype.Component("tosca-export-handler") public class ToscaExportHandler { @@ -563,15 +563,15 @@ public class ToscaExportHandler { if(CollectionUtils.isNotEmpty(component.getProperties())) { List properties = component.getProperties(); - Map convertedProperties = properties.stream().collect(Collectors.toMap( - PropertyDataDefinition::getName, - property -> propertyConvertor.convertProperty(dataTypes, property, - PropertyConvertor.PropertyType.PROPERTY))); + Map convertedProperties = properties.stream() + .map(propertyDefinition -> resolvePropertyValueFromInput(propertyDefinition, component.getInputs())) + .collect(Collectors.toMap(PropertyDataDefinition::getName, + property -> propertyConvertor.convertProperty(dataTypes, property, + PropertyConvertor.PropertyType.PROPERTY))); // merge component properties and inputs properties mergedProperties.putAll(convertedProperties); } if (MapUtils.isNotEmpty(mergedProperties)) { - resolvePropertyDefaultValueFromInput(inputDef, mergedProperties, dataTypes); toscaNodeType.setProperties(mergedProperties); } @@ -705,14 +705,14 @@ public class ToscaExportHandler { addPropertiesOfParentComponent(dataTypes, originalComponent, props); } - if (null != componentInstancesProperties && componentInstancesProperties.containsKey(instanceUniqueId) - && !isComponentOfTypeServiceProxy(componentInstance)) { - addPropertiesOfComponentInstance(componentInstancesProperties, dataTypes, - instanceUniqueId, props); + if (null != componentInstancesProperties && componentInstancesProperties.containsKey(instanceUniqueId)) { + addPropertiesOfComponentInstance(componentInstancesProperties, dataTypes, instanceUniqueId, + props); } if (componentInstancesInputs != null && componentInstancesInputs.containsKey(instanceUniqueId) && !isComponentOfTypeServiceProxy(componentInstance)) { + //For service proxy the inputs are already handled under instance properties above addComponentInstanceInputs(dataTypes, componentInstancesInputs, instanceUniqueId, props); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/ToscaExportUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/ToscaExportUtils.java index 20e0698276..9cce43ccd3 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/ToscaExportUtils.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/ToscaExportUtils.java @@ -16,6 +16,8 @@ package org.openecomp.sdc.be.tosca.utils; +import static org.openecomp.sdc.be.components.utils.PropertiesUtils.resolvePropertyValueFromInput; + import java.util.HashMap; import java.util.List; import java.util.Map; @@ -29,7 +31,6 @@ import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.DataTypeDefinition; import org.openecomp.sdc.be.model.InputDefinition; -import org.openecomp.sdc.be.model.tosca.ToscaFunctions; import org.openecomp.sdc.be.tosca.PropertyConvertor; import org.openecomp.sdc.be.tosca.model.ToscaProperty; @@ -58,41 +59,16 @@ public class ToscaExportUtils { addInputsToProperties(dataTypes, proxyComponent.getInputs(), proxyProperties); if (CollectionUtils.isNotEmpty(proxyComponent.getProperties())) { proxyProperties.putAll(proxyComponent.getProperties().stream() + .map(propertyDefinition -> resolvePropertyValueFromInput(propertyDefinition, + proxyComponent.getInputs())) .collect(Collectors.toMap(PropertyDataDefinition::getName, property -> PropertyConvertor.getInstance().convertProperty(dataTypes, property, PropertyConvertor.PropertyType.PROPERTY)))); } - resolvePropertyDefaultValueFromInput(proxyComponent.getInputs(), proxyProperties, dataTypes); - return MapUtils.isNotEmpty(proxyProperties) ? Optional.of(proxyProperties) : Optional.empty(); } - public static void resolvePropertyDefaultValueFromInput(List componentInputs, - Map mergedProperties, - Map dataTypes) { - if (MapUtils.isEmpty(mergedProperties) || CollectionUtils.isEmpty(componentInputs)) { - return; - } - for (Map.Entry mergedPropertyEntry : mergedProperties.entrySet()) { - ToscaProperty value = mergedPropertyEntry.getValue(); - if (Objects.nonNull(value) && value.getDefaultp() instanceof Map) { - Map valueAsMap = (Map) value.getDefaultp(); - String inputName = valueAsMap.get(ToscaFunctions.GET_INPUT.getFunctionName()); - Optional matchedInputDefinition = componentInputs.stream() - .filter(componentInput -> componentInput.getName().equals(inputName)) - .findFirst(); - if (matchedInputDefinition.isPresent()) { - InputDefinition matchedInput = matchedInputDefinition.get(); - Object resolvedDefaultValue = new PropertyConvertor().convertToToscaObject(matchedInput.getType(), - matchedInput.getDefaultValue(), matchedInput.getSchemaType(), dataTypes, false); - value.setDefaultp(resolvedDefaultValue); - mergedProperties.put(mergedPropertyEntry.getKey(), value); - } - } - } - } - public static void addInputsToProperties(Map dataTypes, List componentInputs, Map mergedProperties) { -- cgit 1.2.3-korg