aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2021-02-02 19:18:22 +0000
committerChristophe Closset <christophe.closset@intl.att.com>2021-02-25 12:20:17 +0000
commit0aa493c70aebd63244beeddf0ef22147196c5489 (patch)
tree6557463275234f84d05d40c89c1bcfc7134298fc /catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
parent70f93dfdd2b3a7c682b341223b6f63af43feb280 (diff)
Improve import and export VFC TOSCA attributes
Improve the import and export VFC TOSCA attributes, addressing the following concerns: - brings the import and export logic very close to the properties logic, as they are very similar structures - fix import/export default values for complex types and list of simple or complex types - fix export of unnecessary/empty attribute entries - creation of attributes during the initialization (base types) - inheritance of parent attributes Change-Id: Ic733e3455fc256595b5c2b1f48e19a13be27b5cc Issue-ID: SDC-3466 Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java72
1 files changed, 47 insertions, 25 deletions
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 0459b5d1c6..1f0270fee9 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
@@ -28,9 +28,7 @@ import static org.openecomp.sdc.tosca.datatypes.ToscaFunctions.GET_ATTRIBUTE;
import static org.openecomp.sdc.tosca.datatypes.ToscaFunctions.GET_INPUT;
import static org.openecomp.sdc.tosca.datatypes.ToscaFunctions.GET_PROPERTY;
-import com.fasterxml.jackson.databind.ObjectMapper;
import fj.data.Either;
-import java.beans.IntrospectionException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -102,9 +100,11 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
import org.openecomp.sdc.be.tosca.PropertyConvertor.PropertyType;
import org.openecomp.sdc.be.tosca.builder.ToscaRelationshipBuilder;
+import org.openecomp.sdc.be.tosca.exception.ToscaConversionException;
import org.openecomp.sdc.be.tosca.model.CapabilityFilter;
import org.openecomp.sdc.be.tosca.model.NodeFilter;
import org.openecomp.sdc.be.tosca.model.SubstitutionMapping;
+import org.openecomp.sdc.be.tosca.model.ToscaAttribute;
import org.openecomp.sdc.be.tosca.model.ToscaCapability;
import org.openecomp.sdc.be.tosca.model.ToscaDataType;
import org.openecomp.sdc.be.tosca.model.ToscaGroupTemplate;
@@ -122,6 +122,7 @@ import org.openecomp.sdc.be.tosca.model.ToscaTopolgyTemplate;
import org.openecomp.sdc.be.tosca.utils.ForwardingPathToscaUtil;
import org.openecomp.sdc.be.tosca.utils.InputConverter;
import org.openecomp.sdc.be.tosca.utils.OutputConverter;
+import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.yaml.snakeyaml.DumperOptions;
@@ -324,7 +325,15 @@ public class ToscaExportHandler {
topologyTemplate.setInputs(inputs);
}
- final Map<String, ToscaProperty> outputs = outputConverter.convert(component.getOutputs(), dataTypes);
+ final Map<String, ToscaProperty> outputs;
+ try {
+ outputs = outputConverter.convert(component.getOutputs(), dataTypes);
+ } catch (final ToscaConversionException e) {
+ log.error(EcompLoggerErrorCode.SCHEMA_ERROR, ToscaExportHandler.class.getName(),
+ "Could not parse component '{}' outputs. Component unique id '{}'.",
+ new Object[]{component.getName(), component.getUniqueId(), e});
+ return Either.right(ToscaError.GENERAL_ERROR);
+ }
if (!outputs.isEmpty()) {
topologyTemplate.setOutputs(outputs);
}
@@ -748,6 +757,18 @@ public class ToscaExportHandler {
.addInterfaceDefinitionElement(component, toscaNodeType, dataTypes, isAssociatedComponent);
addInputsToProperties(dataTypes, inputDef, mergedProperties);
+ final Map<String, ToscaAttribute> toscaAttributeMap;
+ try {
+ toscaAttributeMap = convertToToscaAttributes(component.getAttributes(), dataTypes);
+ } catch (final ToscaConversionException e) {
+ log.error(EcompLoggerErrorCode.SCHEMA_ERROR, ToscaExportHandler.class.getName(),
+ "Could not parse component '{}' attributes. Component unique id '{}'.",
+ new Object[]{component.getName(), component.getUniqueId(), e});
+ return Either.right(ToscaError.GENERAL_ERROR);
+ }
+ if (!toscaAttributeMap.isEmpty()) {
+ toscaNodeType.setAttributes(toscaAttributeMap);
+ }
if (CollectionUtils.isNotEmpty(component.getProperties())) {
List<PropertyDefinition> properties = component.getProperties();
Map<String, ToscaProperty> convertedProperties = properties.stream()
@@ -790,6 +811,19 @@ public class ToscaExportHandler {
return convertReqCapAndTypeName(componentsCache, component, toscaNode, nodeTypes, toscaNodeType, dataTypes);
}
+ private Map<String, ToscaAttribute> convertToToscaAttributes(final List<AttributeDefinition> attributeList,
+ final Map<String, DataTypeDefinition> dataTypes) throws ToscaConversionException {
+ if (CollectionUtils.isEmpty(attributeList)) {
+ return Collections.emptyMap();
+ }
+ final AttributeConverter attributeConverter = new AttributeConverter(dataTypes);
+ final Map<String, ToscaAttribute> toscaAttributeMap = new HashMap<>();
+ for (final AttributeDefinition attributeDefinition : attributeList) {
+ toscaAttributeMap.put(attributeDefinition.getName(), attributeConverter.convert(attributeDefinition));
+ }
+ return toscaAttributeMap;
+ }
+
private Either<ToscaTemplate, ToscaError> convertReqCapAndTypeName(Map<String, Component> componentsCache,
Component component, ToscaTemplate toscaNode,
Map<String, ToscaNodeType> nodeTypes,
@@ -1050,31 +1084,9 @@ public class ToscaExportHandler {
: NATIVE_ROOT;
toscaNodeType.setDerived_from(derivedFrom);
}
- if (component instanceof Resource) {
- final List<AttributeDefinition> attributes = ((Resource) component).getAttributes();
- if (CollectionUtils.isNotEmpty(attributes)) {
- final Map<String, Object> attributeDataDefinitionMap = new HashMap<>();
- attributes.forEach(attributeDataDefinition ->
- buildAttributeData(attributeDataDefinition, attributeDataDefinitionMap));
-
- toscaNodeType.setAttributes(attributeDataDefinitionMap);
- }
- }
return toscaNodeType;
}
- private void buildAttributeData(final AttributeDefinition originalAttributeDefinition,
- final Map<String, Object> attributeDataDefinitionMap) {
-
- attributeDataDefinitionMap.put(originalAttributeDefinition.getName(),
- new ObjectMapper().convertValue(new org.onap.sdc.tosca.datatypes.model.AttributeDefinition(
- originalAttributeDefinition.getType(),
- originalAttributeDefinition.getDescription(),
- originalAttributeDefinition.get_default(),
- originalAttributeDefinition.getStatus(),
- originalAttributeDefinition.getEntry_schema()), Object.class));
- }
-
private Either<Map<String, Object>, ToscaError> createProxyInterfaceTypes(Component container) {
Map<String, Object> proxyInterfaceTypes = new HashMap<>();
@@ -1679,12 +1691,22 @@ public class ToscaExportHandler {
CustomRepresenter() {
super();
this.representers.put(ToscaPropertyAssignment.class, new RepresentToscaPropertyAssignment());
+ this.representers.put(ToscaAttribute.class, new RepresentToscaAttribute());
// null representer is exceptional and it is stored as an instance
// variable.
this.nullRepresenter = new RepresentNull();
}
+ private class RepresentToscaAttribute implements Represent {
+
+ @Override
+ public Node representData(Object data) {
+ final ToscaAttribute toscaAttribute = (ToscaAttribute) data;
+ return represent(toscaAttribute.asToscaMap());
+ }
+ }
+
private class RepresentToscaPropertyAssignment implements Represent {
public Node representData(Object data) {