diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src')
29 files changed, 1536 insertions, 163 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/AbstractPnfdTransformationEngine.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/AbstractPnfdTransformationEngine.java new file mode 100644 index 0000000000..2391ed6ecc --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/AbstractPnfdTransformationEngine.java @@ -0,0 +1,86 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.openecomp.core.converter.impl.pnfd; + +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Map; +import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.core.converter.ServiceTemplateReaderService; +import org.openecomp.core.converter.pnfd.PnfdTransformationEngine; +import org.openecomp.core.converter.pnfd.model.Transformation; +import org.openecomp.core.converter.pnfd.model.TransformationBlock; +import org.openecomp.core.converter.pnfd.model.TransformationDescription; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; + +/** + * Engine that manages the PNF Descriptor transformation process. + */ +public abstract class AbstractPnfdTransformationEngine implements PnfdTransformationEngine { + + private static final Logger LOGGER = LoggerFactory.getLogger(AbstractPnfdTransformationEngine.class); + + protected final ServiceTemplate templateTo; + protected final ServiceTemplateReaderService templateFrom; + private final PnfdTransformationDescriptorReader pnfdTransformationDescriptorReader = + new PnfdTransformationDescriptorReader(); + protected TransformationDescription transformationDescription; + protected Map<TransformationBlock, List<Transformation>> transformationGroupByBlockMap; + private final String descriptorResourcePath; + + public AbstractPnfdTransformationEngine(final ServiceTemplateReaderService templateFrom, + final ServiceTemplate templateTo) { + this(templateFrom, templateTo, "pnfdTransformationTemplate/model-driven-conversion.yaml"); + } + + //used for tests purposes + AbstractPnfdTransformationEngine(final ServiceTemplateReaderService templateFrom, + final ServiceTemplate templateTo, + final String descriptorResourcePath) { + this.templateFrom = templateFrom; + this.templateTo = templateTo; + this.descriptorResourcePath = descriptorResourcePath; + } + + /** + * Gets and Reads the transformation description yaml file. + */ + protected void readDefinition() { + try (final InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream(descriptorResourcePath)) { + if (resourceAsStream == null) { + if (LOGGER.isErrorEnabled()) { + LOGGER.error("Could not find resource '{}'", descriptorResourcePath); + } + return; + } + transformationDescription = pnfdTransformationDescriptorReader.parse(resourceAsStream); + } catch (final IOException e) { + LOGGER.error("Could not find resource '{}'", descriptorResourcePath, e); + } + } + + /** + * Executes all transformations specified in the descriptor. + */ + protected abstract void executeTransformations(); + +} diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdTransformationEngine.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdNodeTemplateTransformationEngine.java index a2365b4f8a..b2038a00dd 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdTransformationEngine.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdNodeTemplateTransformationEngine.java @@ -19,7 +19,6 @@ package org.openecomp.core.converter.impl.pnfd; -import java.io.InputStream; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -35,35 +34,22 @@ import org.openecomp.core.converter.impl.pnfd.factory.PnfdBlockParserFactory; import org.openecomp.core.converter.impl.pnfd.parser.ConversionQueryYamlParser; import org.openecomp.core.converter.pnfd.model.Transformation; import org.openecomp.core.converter.pnfd.model.TransformationBlock; -import org.openecomp.core.converter.pnfd.model.TransformationDescription; -import org.openecomp.sdc.logging.api.Logger; -import org.openecomp.sdc.logging.api.LoggerFactory; /** - * Engine that manages the PNF Descriptor transformation process. + * Engine that manages the PNF Descriptor transformation process for the NodeTemplate block. */ -public class PnfdTransformationEngine { +public class PnfdNodeTemplateTransformationEngine extends AbstractPnfdTransformationEngine { - private static final Logger LOGGER = LoggerFactory.getLogger(PnfdTransformationEngine.class); - - private final ServiceTemplate templateTo; - private final ServiceTemplateReaderService templateFrom; - private final PnfdTransformationDescriptorReader pnfdTransformationDescriptorReader = - new PnfdTransformationDescriptorReader(); - private TransformationDescription transformationDescription; - private Map<TransformationBlock, List<Transformation>> transformationGroupByBlockMap; - private final String descriptorResourcePath; - - public PnfdTransformationEngine(final ServiceTemplateReaderService templateFrom, final ServiceTemplate templateTo) { - this(templateFrom, templateTo, "pnfdTransformationTemplate/model-driven-conversion.yaml"); + public PnfdNodeTemplateTransformationEngine(final ServiceTemplateReaderService templateFrom, + final ServiceTemplate templateTo) { + super(templateFrom, templateTo); } //used for tests purposes - PnfdTransformationEngine(final ServiceTemplateReaderService templateFrom, final ServiceTemplate templateTo, - final String descriptorResourcePath) { - this.templateFrom = templateFrom; - this.templateTo = templateTo; - this.descriptorResourcePath = descriptorResourcePath; + PnfdNodeTemplateTransformationEngine(final ServiceTemplateReaderService templateFrom, + final ServiceTemplate templateTo, + final String descriptorResourcePath) { + super(templateFrom, templateTo, descriptorResourcePath); } /** @@ -89,17 +75,12 @@ public class PnfdTransformationEngine { } } - /** - * Reads the transformation description yaml file. - */ - private void readDefinition() { - transformationDescription = pnfdTransformationDescriptorReader.parse(getDefinitionFileInputStream()); - } /** * Execute all transformations specified in the descriptor. */ - private void executeTransformations() { + @Override + protected void executeTransformations() { final Set<Transformation> transformationSet = transformationDescription.getTransformationSet(); if (CollectionUtils.isEmpty(transformationSet)) { return; @@ -107,6 +88,7 @@ public class PnfdTransformationEngine { transformationGroupByBlockMap = transformationSet.stream() .filter(Transformation::isValid) .collect(Collectors.groupingBy(Transformation::getBlock)); + executeCustomTypeTransformations(); final Map<String, String> inputsToConvertMap = executeNodeTemplateTransformations(); executeGetInputFunctionTransformations(inputsToConvertMap); } @@ -158,7 +140,9 @@ public class PnfdTransformationEngine { if (transformation != null) { final Map<String, Object> conversionQueryMap = new HashMap<>(); conversionQueryMap.put(inputName, null); - transformation.setConversionQuery(ConversionQueryYamlParser.parse(conversionQueryMap)); + transformation.setConversionQuery( + ConversionQueryYamlParser.parse(conversionQueryMap).orElse(null) + ); PnfdBlockParserFactory.getInstance().get(transformation) .ifPresent(pnfParser -> pnfParser.parse(templateFrom, templateTo)); } @@ -167,17 +151,17 @@ public class PnfdTransformationEngine { } /** - * Gets the transformation definition yaml file path. - * @return The transformation definition yaml path. + * Parses a Customized Node Type that extend from a valid ONAP NodeType. */ - private InputStream getDefinitionFileInputStream() { - final InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream(descriptorResourcePath); - if (resourceAsStream == null) { - if (LOGGER.isErrorEnabled()) { - LOGGER.error(String.format("Could not find resource '%s'", descriptorResourcePath)); - } - return null; + private void executeCustomTypeTransformations() { + final List<Transformation> transformationList = transformationGroupByBlockMap + .get((TransformationBlock.CUSTOM_NODE_TYPE)); + if (CollectionUtils.isEmpty(transformationList)) { + return; } - return resourceAsStream; + transformationList.forEach(transformation -> + PnfdBlockParserFactory.getInstance().get(transformation).ifPresent(pnfdBlockParser -> + pnfdBlockParser.parse(templateFrom, templateTo))); } + } diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdNodeTypeTransformationEngine.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdNodeTypeTransformationEngine.java new file mode 100644 index 0000000000..48d06b67a4 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdNodeTypeTransformationEngine.java @@ -0,0 +1,72 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.openecomp.core.converter.impl.pnfd; + +import java.util.Set; +import java.util.stream.Collectors; +import org.apache.commons.collections.CollectionUtils; +import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.core.converter.ServiceTemplateReaderService; +import org.openecomp.core.converter.impl.pnfd.factory.PnfdBlockParserFactory; +import org.openecomp.core.converter.pnfd.model.Transformation; +import org.openecomp.core.converter.pnfd.model.TransformationBlock; + +/** + * Engine that manages the PNF Descriptor transformation process for the NodeType block. + */ +public class PnfdNodeTypeTransformationEngine extends AbstractPnfdTransformationEngine { + + public PnfdNodeTypeTransformationEngine(final ServiceTemplateReaderService templateFrom, + final ServiceTemplate templateTo) { + super(templateFrom, templateTo); + } + + /** + * Runs the transformation process. + */ + @Override + public void transform() { + readDefinition(); + executeTransformations(); + } + + /** + * Execute all transformations specified in the descriptor. + */ + @Override + protected void executeTransformations() { + final Set<Transformation> transformationSet = transformationDescription.getTransformationSet(); + if (CollectionUtils.isEmpty(transformationSet)) { + return; + } + final Set<Transformation> validNodeTypeTransformationSet = transformationSet.stream() + .filter(transformation -> transformation.getBlock() == TransformationBlock.NODE_TYPE) + .filter(Transformation::isValid) + .collect(Collectors.toSet()); + + if (CollectionUtils.isEmpty(validNodeTypeTransformationSet)) { + return; + } + validNodeTypeTransformationSet.forEach(transformation -> + PnfdBlockParserFactory.getInstance().get(transformation).ifPresent(pnfdBlockParser -> + pnfdBlockParser.parse(templateFrom, templateTo))); + } + +} diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdTransformationDescriptorReader.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdTransformationDescriptorReader.java index 6ef5caf21b..d040c93d09 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdTransformationDescriptorReader.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdTransformationDescriptorReader.java @@ -25,6 +25,7 @@ import java.io.InputStream; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; import org.apache.commons.collections.CollectionUtils; @@ -82,7 +83,8 @@ public class PnfdTransformationDescriptorReader { } return transformationYamlList.stream() - .map(conversionMap -> TransformationYamlParser.parse((Map<String, Object>) conversionMap)) + .map(conversionMap -> TransformationYamlParser.parse((Map<String, Object>) conversionMap).orElse(null)) + .filter(Objects::nonNull) .collect(Collectors.toSet()); } diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/factory/PnfdBlockParserFactory.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/factory/PnfdBlockParserFactory.java index 512fdb5ca7..12dd790c9d 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/factory/PnfdBlockParserFactory.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/factory/PnfdBlockParserFactory.java @@ -20,9 +20,11 @@ package org.openecomp.core.converter.impl.pnfd.factory; import java.util.Optional; -import org.openecomp.core.converter.pnfd.model.Transformation; import org.openecomp.core.converter.impl.pnfd.parser.PnfdInputBlockParser; import org.openecomp.core.converter.impl.pnfd.parser.PnfdNodeTemplateBlockParser; +import org.openecomp.core.converter.impl.pnfd.parser.PnfdCustomNodeTypeBlockParser; +import org.openecomp.core.converter.impl.pnfd.parser.PnfdNodeTypeBlockParser; +import org.openecomp.core.converter.pnfd.model.Transformation; import org.openecomp.core.converter.pnfd.parser.PnfdBlockParser; /** @@ -46,6 +48,10 @@ public class PnfdBlockParserFactory { switch (transformation.getBlock()) { case NODE_TEMPLATE: return Optional.of(new PnfdNodeTemplateBlockParser(transformation)); + case NODE_TYPE: + return Optional.of(new PnfdNodeTypeBlockParser(transformation)); + case CUSTOM_NODE_TYPE: + return Optional.of(new PnfdCustomNodeTypeBlockParser(transformation)); case INPUT: case GET_INPUT_FUNCTION: return Optional.of(new PnfdInputBlockParser(transformation)); diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/AbstractPnfdBlockParser.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/AbstractPnfdBlockParser.java new file mode 100644 index 0000000000..056d07aed0 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/AbstractPnfdBlockParser.java @@ -0,0 +1,226 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.openecomp.core.converter.impl.pnfd.parser; + +import com.google.common.collect.ImmutableMap; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import org.apache.commons.collections.MapUtils; +import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.core.converter.ServiceTemplateReaderService; +import org.openecomp.core.converter.impl.pnfd.PnfdQueryExecutor; +import org.openecomp.core.converter.pnfd.model.ConversionDefinition; +import org.openecomp.core.converter.pnfd.model.ConversionQuery; +import org.openecomp.core.converter.pnfd.model.PnfTransformationToken; +import org.openecomp.core.converter.pnfd.model.Transformation; +import org.openecomp.core.converter.pnfd.parser.PnfdBlockParser; + +public abstract class AbstractPnfdBlockParser implements PnfdBlockParser { + + protected final Transformation transformation; + protected ServiceTemplateReaderService templateFrom; + protected ServiceTemplate templateTo; + protected Object attributeValueToBeConverted = ""; + + public AbstractPnfdBlockParser(final Transformation transformation) { + this.transformation = transformation; + } + + /** + * Parses a PNFD block based on the {@link Transformation} provided during the {@link PnfdBlockParser} + * instantiation. + * + * @param templateFrom the original PNFD template + * @param templateTo the resulting PNFD template + */ + public void parse(final ServiceTemplateReaderService templateFrom, final ServiceTemplate templateTo) { + this.templateFrom = templateFrom; + this.templateTo = templateTo; + final Set<Map<String, Object>> blockToParseSet = findBlocksToParse(); + if (!blockToParseSet.isEmpty()) { + blockToParseSet.forEach(this::parse); + } + } + + /** + * Applies all specified conversions in {@link Transformation#getConversionDefinitionList()} for the given + * blockYamlObject. + * + * @param blockYamlObject the block content as a YAML object + */ + protected void parse(final Map<String, Object> blockYamlObject) { + if (MapUtils.isEmpty(blockYamlObject)) { + return; + } + final List<ConversionDefinition> conversionDefinitionList = transformation.getConversionDefinitionList(); + final Map<String, Object> parsedBlockYamlObject = new HashMap<>(); + final String blockName = blockYamlObject.keySet().iterator().next(); + conversionDefinitionList.stream() + .filter(conversionDefinition -> conversionDefinition.getConversionQuery().isValidAttributeQuery()) + .forEach(conversionDefinition -> { + final Map<String, Object> query = + (Map<String, Object>) conversionDefinition.getConversionQuery().getQuery(); + final Map<String, Object> blockAttributeMap = (Map<String, Object>) blockYamlObject.get(blockName); + final Optional<Map<String, Object>> parsedBlockAttributeMap = buildParsedBlock(query, blockAttributeMap + , conversionDefinition); + parsedBlockAttributeMap.ifPresent(convertedNodeTemplateAttributeMap1 -> + mergeYamlObjects(parsedBlockYamlObject, convertedNodeTemplateAttributeMap1) + ); + }); + + write(blockName, parsedBlockYamlObject); + } + + /** + * Writes the block in the resulting {@link ServiceTemplate} {@link #templateTo}. + * + * @param blockName the name of the block + * @param parsedBlockYamlObject the block content as a YAML object + */ + protected abstract void write(final String blockName, final Map<String, Object> parsedBlockYamlObject); + + /** + * Uses the provided attribute query to find a attribute in the original YAML object and apply the provided + * conversion. + * + * @param attributeQuery the attribute query + * @param fromNodeTemplateAttributeMap the original YAML object + * @param conversionDefinition the conversion + * @return the rebuilt original YAML object with the converted attribute + */ + protected abstract Optional<Map<String, Object>> buildParsedBlock(final Map<String, Object> attributeQuery, + final Map<String, Object> fromNodeTemplateAttributeMap, + final ConversionDefinition conversionDefinition); + + /** + * Merges two YAML objects. + * + * @param originalMap original YAML object + * @param toBeMergedMap YAML object to be merged + * @return the new YAML object representing the merge result. + */ + protected Map<String, Object> mergeYamlObjects(final Map<String, Object> originalMap, + final Map<String, Object> toBeMergedMap) { + toBeMergedMap.forEach( + (key, value) -> originalMap.merge(key, value, + (toBeMergedValue, originalValue) -> { + if (originalValue instanceof Map) { + return mergeYamlObjects((Map) originalValue, (Map) toBeMergedValue); + } + return originalValue; + }) + ); + + return originalMap; + } + + /** + * Executes the provided {@link #transformation getConversionQuery} YAML query to find the blocks to be parsed in + * {@link #templateFrom}. + * + * @return The YAML blocks found + */ + protected abstract Set<Map<String, Object>> findBlocksToParse(); + + /** + * Checks if the YAML object is a TOSCA get_input call + * + * @param yamlObject the YAML object + * @return {@code true} if the YAML object is a TOSCA get_input call, {@code false} otherwise + */ + protected boolean isGetInputFunction(final Object yamlObject) { + if (yamlObject instanceof Map) { + final Map<String, Object> yamlMap = (Map<String, Object>) yamlObject; + return yamlMap.containsKey(PnfTransformationToken.GET_INPUT.getName()); + } + + return false; + } + + /** + * Extracts the value from an YAML Object. + * @param yamlObject + * @return The Object value from the yamlObject parameter. + */ + protected String extractObjectValue(final Object yamlObject) { + if (yamlObject instanceof Map) { + final Map<String, Object> yamlMap = (Map<String, Object>) yamlObject; + return (String) yamlMap.values().stream().findFirst().orElse(null); + } + + return null; + } + + /** + * Gets the stored input names called with TOSCA get_input function and its transformation configured in {@link + * ConversionDefinition#getToGetInput()} + */ + public Optional<Map<String, String>> getInputAndTransformationNameMap() { + return Optional.empty(); + } + + /** + * Finds all the derived node types from the provided node types. + * + * @param rootNodeTypeMap a map with the root node types to find the derived ones + * @param derivedNodeTypeMap a map that will be filled with the derived node types + */ + private void findAllDerivedNodeType(final Map<String, Object> rootNodeTypeMap, + final Map<String, Object> derivedNodeTypeMap) { + templateFrom.getNodeTypes().entrySet().stream() + .filter(nodeEntry -> rootNodeTypeMap.containsKey(extractObjectValue(nodeEntry.getValue()))) + .forEach(nodeEntry -> { + if (!derivedNodeTypeMap.containsKey(nodeEntry.getKey())) { + derivedNodeTypeMap.put(nodeEntry.getKey(), nodeEntry.getValue()); + final ImmutableMap<String, Object> newRootNodeTypeMap = ImmutableMap + .of(nodeEntry.getKey(), nodeEntry.getValue()); + findAllDerivedNodeType(newRootNodeTypeMap, derivedNodeTypeMap); + } + }); + } + + /** + * Fetches all Custom NodeTypes based on the query result. + * @return a map with all custom Node Types that matches with the query result. + */ + protected Map<String, Object> fetchCustomNodeType() { + final Map<String, Object> nodeTypesMap = templateFrom.getNodeTypes(); + if (MapUtils.isEmpty(nodeTypesMap)) { + return Collections.emptyMap(); + } + final ConversionQuery conversionQuery = transformation.getConversionQuery(); + final Map<String, Object> customNodeTypesMap = new HashMap<>(); + nodeTypesMap.entrySet().stream() + .filter(nodeEntry -> PnfdQueryExecutor.find(conversionQuery, nodeEntry.getValue())) + .forEach(customNode -> { + attributeValueToBeConverted = extractObjectValue(customNode.getValue()); + customNodeTypesMap.put(customNode.getKey(), customNode.getValue()); + }); + final Map<String, Object> childNodeTypeMap = new HashMap<>(); + findAllDerivedNodeType(customNodeTypesMap, childNodeTypeMap); + customNodeTypesMap.putAll(childNodeTypeMap); + return customNodeTypesMap; + } + +} diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionDefinitionYamlParser.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionDefinitionYamlParser.java index 143185210e..2ea9f2dc93 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionDefinitionYamlParser.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionDefinitionYamlParser.java @@ -20,16 +20,21 @@ package org.openecomp.core.converter.impl.pnfd.parser; import java.util.Map; +import java.util.Optional; import org.openecomp.core.converter.pnfd.model.ConversionDefinition; import org.openecomp.core.converter.pnfd.model.ConversionQuery; import org.openecomp.core.converter.pnfd.model.PnfTransformationToken; import org.openecomp.core.converter.pnfd.strategy.PnfdConversionStrategy; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; /** * Handles YAML from/to {@link ConversionDefinition} conversions */ public class ConversionDefinitionYamlParser { + private static final Logger LOGGER = LoggerFactory.getLogger(ConversionDefinitionYamlParser.class); + private ConversionDefinitionYamlParser() { } @@ -40,16 +45,20 @@ public class ConversionDefinitionYamlParser { * @return * A new instance of {@link ConversionDefinition}. */ - public static ConversionDefinition parse(final Map<String, Object> conversionYaml) { + public static Optional<ConversionDefinition> parse(final Map<String, Object> conversionYaml) { final ConversionQuery conversionQuery = ConversionQueryYamlParser - .parse(conversionYaml.get(PnfTransformationToken.QUERY.getName())); + .parse(conversionYaml.get(PnfTransformationToken.QUERY.getName())).orElse(null); + if (conversionQuery == null) { + LOGGER.warn("Invalid '{}' for '{}'", PnfTransformationToken.QUERY.getName(), conversionYaml.toString()); + return Optional.empty(); + } final String toName = (String) conversionYaml.get(PnfTransformationToken.TO_NAME.getName()); final PnfdConversionStrategy toValue = PnfdConversionStrategyYamlParser .parse((Map<String, Object>) conversionYaml.get(PnfTransformationToken.TO_VALUE.getName())) .orElse(null); final String toGetInput = (String) conversionYaml.get(PnfTransformationToken.TO_GET_INPUT.getName()); - return new ConversionDefinition(conversionQuery, toName, toValue, toGetInput); + return Optional.of(new ConversionDefinition(conversionQuery, toName, toValue, toGetInput)); } } diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionQueryYamlParser.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionQueryYamlParser.java index 417262c61c..374bf3702f 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionQueryYamlParser.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionQueryYamlParser.java @@ -19,6 +19,7 @@ package org.openecomp.core.converter.impl.pnfd.parser; +import java.util.Optional; import org.openecomp.core.converter.pnfd.model.ConversionQuery; /** @@ -36,7 +37,11 @@ public class ConversionQueryYamlParser { * @return * A new instance of {@link ConversionQuery}. */ - public static ConversionQuery parse(final Object conversionYaml) { - return new ConversionQuery(conversionYaml); + public static Optional<ConversionQuery> parse(final Object conversionYaml) { + if (conversionYaml == null) { + return Optional.empty(); + } + + return Optional.of(new ConversionQuery(conversionYaml)); } } diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/NodeTypeYamlParser.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/NodeTypeYamlParser.java new file mode 100644 index 0000000000..b0b52e0c40 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/NodeTypeYamlParser.java @@ -0,0 +1,67 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.openecomp.core.converter.impl.pnfd.parser; + +import java.util.List; +import java.util.Map; +import org.onap.sdc.tosca.datatypes.model.ArtifactDefinition; +import org.onap.sdc.tosca.datatypes.model.AttributeDefinition; +import org.onap.sdc.tosca.datatypes.model.CapabilityDefinition; +import org.onap.sdc.tosca.datatypes.model.NodeType; +import org.onap.sdc.tosca.datatypes.model.PropertyDefinition; +import org.onap.sdc.tosca.datatypes.model.RequirementDefinition; +import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum; + +/** + * Handles YAML from/to {@link NodeType} conversions + */ +public class NodeTypeYamlParser { + + private NodeTypeYamlParser() { + } + + /** + * Parses the given a YAML object to a {@link NodeType} instance. + * @param nodeTypeYaml the YAML object representing a TOSCA Node Type + * @return A new instance of {@link NodeType}. + */ + @SuppressWarnings("unchecked") + public static NodeType parse(final Map<String, Object> nodeTypeYaml) { + final NodeType nodeType = new NodeType(); + nodeType.setDerived_from((String) nodeTypeYaml.get(ToscaTagNamesEnum.DERIVED_FROM.getElementName())); + nodeType.setDescription((String) nodeTypeYaml.get(ToscaTagNamesEnum.DESCRIPTION.getElementName())); + nodeType.setVersion((String) nodeTypeYaml.get("version")); + nodeType.setProperties( + (Map<String, PropertyDefinition>) nodeTypeYaml.get(ToscaTagNamesEnum.PROPERTIES.getElementName())); + nodeType.setArtifacts((Map<String, ArtifactDefinition>) nodeTypeYaml.get("artifacts")); + nodeType.setMetadata((Map<String, String>) nodeTypeYaml.get("metadata")); + nodeType.setInterfaces( + (Map<String, Object>) nodeTypeYaml.get(ToscaTagNamesEnum.INTERFACES.getElementName())); + nodeType.setRequirements( + (List<Map<String, RequirementDefinition>>) nodeTypeYaml.get(ToscaTagNamesEnum.REQUIREMENTS.getElementName())); + nodeType.setCapabilities( + (Map<String, CapabilityDefinition>) nodeTypeYaml.get(ToscaTagNamesEnum.CAPABILITIES.getElementName())); + nodeType.setAttributes( + (Map<String, AttributeDefinition>) nodeTypeYaml.get(ToscaTagNamesEnum.ATTRIBUTES.getElementName())); + + return nodeType; + } + +} diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdCustomNodeTypeBlockParser.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdCustomNodeTypeBlockParser.java new file mode 100644 index 0000000000..3efde199b4 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdCustomNodeTypeBlockParser.java @@ -0,0 +1,88 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.openecomp.core.converter.impl.pnfd.parser; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; +import org.apache.commons.collections.MapUtils; +import org.onap.sdc.tosca.datatypes.model.NodeTemplate; +import org.openecomp.core.converter.pnfd.model.ConversionDefinition; +import org.openecomp.core.converter.pnfd.model.Transformation; +import org.openecomp.core.converter.pnfd.strategy.PnfdConversionStrategy; +import org.openecomp.sdc.tosca.services.DataModelUtil; + +public class PnfdCustomNodeTypeBlockParser extends AbstractPnfdBlockParser { + + public PnfdCustomNodeTypeBlockParser(final Transformation transformation) { + super(transformation); + } + + @Override + protected Set<Map<String, Object>> findBlocksToParse() { + final Map<String, Object> nodeTemplateMap = templateFrom.getNodeTemplates(); + final Map<String, Object> customNodeTypeMap = fetchCustomNodeType(); + if (customNodeTypeMap.isEmpty() || MapUtils.isEmpty(nodeTemplateMap)) { + return Collections.emptySet(); + } + return customNodeTypeMap.entrySet().stream() + .map(customNode -> { + final Map<String, Object> map = new HashMap<>(); + nodeTemplateMap.entrySet().stream() + .filter(nodeTemplate -> + extractObjectValue(nodeTemplate.getValue()).equalsIgnoreCase(customNode.getKey())) + .forEach(nodeType -> map.put(nodeType.getKey(), nodeType.getValue())); + return map; + }).collect(Collectors.toSet()); + } + + @Override + protected Optional<Map<String, Object>> buildParsedBlock(final Map<String, Object> attributeQuery, + final Map<String, Object> fromNodeTemplateAttributeMap, + final ConversionDefinition conversionDefinition) { + //cannot query for more than one attribute + if (attributeQuery.keySet().size() > 1) { + return Optional.empty(); + } + final String attribute = attributeQuery.keySet().iterator().next(); + final Object queryValue = attributeQuery.get(attribute); + final Map<String, Object> parsedNodeTemplate = new HashMap<>(); + if (queryValue == null) { + final PnfdConversionStrategy pnfdConversionStrategy = conversionDefinition.getPnfdConversionStrategy(); + final Optional convertedAttribute = pnfdConversionStrategy.convert(attributeValueToBeConverted); + if (convertedAttribute.isPresent()) { + parsedNodeTemplate.put(conversionDefinition.getToAttributeName(), convertedAttribute.get()); + } + } + return parsedNodeTemplate.isEmpty() ? Optional.empty() : Optional.of(parsedNodeTemplate); + } + + @Override + protected void write(final String nodeTemplateName, final Map<String, Object> parsedTemplateMap) { + if (!parsedTemplateMap.isEmpty()) { + final NodeTemplate parsedNodeTemplate = NodeTemplateYamlParser.parse(parsedTemplateMap); + DataModelUtil.addNodeTemplate(templateTo, nodeTemplateName, parsedNodeTemplate); + } + } + +} diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdInputBlockParser.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdInputBlockParser.java index 4aec8c8ac3..4ce7b2e1c7 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdInputBlockParser.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdInputBlockParser.java @@ -28,7 +28,6 @@ import java.util.Set; import java.util.stream.Collectors; import org.apache.commons.collections.MapUtils; import org.onap.sdc.tosca.datatypes.model.ParameterDefinition; -import org.openecomp.core.converter.pnfd.parser.AbstractPnfdBlockParser; import org.openecomp.core.converter.impl.pnfd.PnfdQueryExecutor; import org.openecomp.core.converter.pnfd.model.ConversionDefinition; import org.openecomp.core.converter.pnfd.model.ConversionQuery; diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdNodeTemplateBlockParser.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdNodeTemplateBlockParser.java index 5539840561..5d7a6049cd 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdNodeTemplateBlockParser.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdNodeTemplateBlockParser.java @@ -27,12 +27,11 @@ import java.util.Set; import java.util.stream.Collectors; import org.apache.commons.collections.MapUtils; import org.onap.sdc.tosca.datatypes.model.NodeTemplate; -import org.openecomp.core.converter.pnfd.parser.AbstractPnfdBlockParser; import org.openecomp.core.converter.impl.pnfd.PnfdQueryExecutor; +import org.openecomp.core.converter.impl.pnfd.strategy.CopyConversionStrategy; import org.openecomp.core.converter.pnfd.model.ConversionDefinition; import org.openecomp.core.converter.pnfd.model.ConversionQuery; import org.openecomp.core.converter.pnfd.model.Transformation; -import org.openecomp.core.converter.impl.pnfd.strategy.CopyConversionStrategy; import org.openecomp.core.converter.pnfd.strategy.PnfdConversionStrategy; import org.openecomp.sdc.tosca.services.DataModelUtil; @@ -44,7 +43,25 @@ public class PnfdNodeTemplateBlockParser extends AbstractPnfdBlockParser { super(transformation); } - public Optional<Map<String, Object>> buildParsedBlock(final Map<String, Object> attributeQuery, + @Override + protected Set<Map<String, Object>> findBlocksToParse() { + final ConversionQuery conversionQuery = transformation.getConversionQuery(); + final Map<String, Object> nodeTemplateMap = templateFrom.getNodeTemplates(); + if (MapUtils.isEmpty(nodeTemplateMap)) { + return Collections.emptySet(); + } + + return nodeTemplateMap.entrySet().stream() + .filter(mapEntry -> PnfdQueryExecutor.find(conversionQuery, mapEntry.getValue())) + .map(stringObjectEntry -> { + final Map<String, Object> map = new HashMap<>(); + map.put(stringObjectEntry.getKey(), stringObjectEntry.getValue()); + return map; + }).collect(Collectors.toSet()); + } + + @Override + protected Optional<Map<String, Object>> buildParsedBlock(final Map<String, Object> attributeQuery, final Map<String, Object> fromNodeTemplateAttributeMap, final ConversionDefinition conversionDefinition) { //cannot query for more than one attribute @@ -57,7 +74,7 @@ public class PnfdNodeTemplateBlockParser extends AbstractPnfdBlockParser { if (queryValue == null) { PnfdConversionStrategy pnfdConversionStrategy = conversionDefinition.getPnfdConversionStrategy(); if (isGetInputFunction(attributeValueToConvert)) { - inputNameToConvertMap.put(extractGetInputFunctionValue(attributeValueToConvert) + inputNameToConvertMap.put(extractObjectValue(attributeValueToConvert) , conversionDefinition.getToGetInput() ); pnfdConversionStrategy = new CopyConversionStrategy(); @@ -83,24 +100,8 @@ public class PnfdNodeTemplateBlockParser extends AbstractPnfdBlockParser { } } - protected Set<Map<String, Object>> findBlocksToParse() { - final ConversionQuery conversionQuery = transformation.getConversionQuery(); - final Map<String, Object> nodeTemplateMap = templateFrom.getNodeTemplates(); - if (MapUtils.isEmpty(nodeTemplateMap)) { - return Collections.emptySet(); - } - - return nodeTemplateMap.entrySet().stream() - .filter(mapEntry -> PnfdQueryExecutor.find(conversionQuery, mapEntry.getValue())) - .map(stringObjectEntry -> { - final Map<String, Object> map = new HashMap<>(); - map.put(stringObjectEntry.getKey(), stringObjectEntry.getValue()); - return map; - }).collect(Collectors.toSet()); - } - @Override - public void write(final String nodeTemplateName, final Map<String, Object> parsedNodeTemplateMap) { + protected void write(final String nodeTemplateName, final Map<String, Object> parsedNodeTemplateMap) { if (!parsedNodeTemplateMap.isEmpty()) { final NodeTemplate parsedNodeTemplate = NodeTemplateYamlParser.parse(parsedNodeTemplateMap); DataModelUtil.addNodeTemplate(templateTo, nodeTemplateName, parsedNodeTemplate); diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdNodeTypeBlockParser.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdNodeTypeBlockParser.java new file mode 100644 index 0000000000..386bbfb558 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdNodeTypeBlockParser.java @@ -0,0 +1,94 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.openecomp.core.converter.impl.pnfd.parser; + +import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.DERIVED_FROM; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; +import org.onap.sdc.tosca.datatypes.model.NodeType; +import org.openecomp.core.converter.pnfd.model.ConversionDefinition; +import org.openecomp.core.converter.pnfd.model.Transformation; +import org.openecomp.core.converter.pnfd.model.TransformationPropertyType; +import org.openecomp.core.converter.pnfd.strategy.PnfdConversionStrategy; +import org.openecomp.sdc.tosca.services.DataModelUtil; + +public class PnfdNodeTypeBlockParser extends AbstractPnfdBlockParser { + + public PnfdNodeTypeBlockParser(final Transformation transformation) { + super(transformation); + } + + @Override + protected Set<Map<String, Object>> findBlocksToParse() { + final Map<String, Object> customNodeTypeMap = fetchCustomNodeType(); + if (customNodeTypeMap.isEmpty()) { + return Collections.emptySet(); + } + + final String nodeNamePrefix = + transformation.getPropertyValue(TransformationPropertyType.NODE_NAME_PREFIX, String.class) + .orElse(""); + + return customNodeTypeMap.entrySet().parallelStream() + .map(nodeEntry -> { + final Map<String, Object> map = new HashMap<>(); + map.put(nodeNamePrefix.concat(nodeEntry.getKey()), nodeEntry.getValue()); + return map; + }).collect(Collectors.toSet()); + } + + @Override + protected Optional<Map<String, Object>> buildParsedBlock(final Map<String, Object> attributeQuery, + final Map<String, Object> fromNodeTemplateAttributeMap, + final ConversionDefinition conversionDefinition) { + //cannot query for more than one attribute + if (attributeQuery.keySet().size() > 1) { + return Optional.empty(); + } + final String attribute = attributeQuery.keySet().iterator().next(); + final Object queryValue = attributeQuery.get(attribute); + final Object attributeValueToConvert = fromNodeTemplateAttributeMap.get(attribute); + final Map<String, Object> parsedNodeTemplate = new HashMap<>(); + if (queryValue == null) { + PnfdConversionStrategy pnfdConversionStrategy = conversionDefinition.getPnfdConversionStrategy(); + final Optional convertedAttribute = pnfdConversionStrategy + .convert(DERIVED_FROM.getElementName() + .equalsIgnoreCase(attribute) ? attributeValueToBeConverted : attributeValueToConvert); + if (convertedAttribute.isPresent()) { + parsedNodeTemplate.put(conversionDefinition.getToAttributeName(), convertedAttribute.get()); + } + } + return parsedNodeTemplate.isEmpty() ? Optional.empty() : Optional.of(parsedNodeTemplate); + } + + @Override + protected void write(final String blockName, final Map<String, Object> parsedBlockYamlObject) { + if (!parsedBlockYamlObject.isEmpty()) { + final NodeType nodeTypeYamlParser = NodeTypeYamlParser.parse(parsedBlockYamlObject); + DataModelUtil.addNodeType(templateTo, blockName, nodeTypeYamlParser); + } + } + +} diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/TransformationYamlParser.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/TransformationYamlParser.java index 16d06704b3..6ad04b0f7a 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/TransformationYamlParser.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/TransformationYamlParser.java @@ -21,24 +21,43 @@ package org.openecomp.core.converter.impl.pnfd.parser; import static org.openecomp.core.converter.pnfd.model.PnfTransformationToken.CONVERSIONS; import static org.openecomp.core.converter.pnfd.model.PnfTransformationToken.DESCRIPTION; +import static org.openecomp.core.converter.pnfd.model.PnfTransformationToken.FROM; import static org.openecomp.core.converter.pnfd.model.PnfTransformationToken.NAME; +import static org.openecomp.core.converter.pnfd.model.PnfTransformationToken.PROPERTIES; import static org.openecomp.core.converter.pnfd.model.PnfTransformationToken.QUERY; +import static org.openecomp.core.converter.pnfd.model.PnfTransformationToken.TO; import static org.openecomp.core.converter.pnfd.model.PnfTransformationToken.TRANSFORMATION_FOR; +import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; +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.stream.Collectors; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.MapUtils; +import org.openecomp.core.converter.impl.pnfd.strategy.ReplaceConversionStrategy; import org.openecomp.core.converter.pnfd.model.ConversionDefinition; +import org.openecomp.core.converter.pnfd.model.ConversionQuery; import org.openecomp.core.converter.pnfd.model.Transformation; import org.openecomp.core.converter.pnfd.model.TransformationBlock; +import org.openecomp.core.converter.pnfd.model.TransformationProperty; +import org.openecomp.core.converter.pnfd.model.TransformationPropertyType; +import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; /** * Handles YAML from/to {@link Transformation} conversions */ public class TransformationYamlParser { + private static final Logger LOGGER = LoggerFactory.getLogger(TransformationYamlParser.class); + private TransformationYamlParser() { } @@ -49,20 +68,101 @@ public class TransformationYamlParser { * @return * A new instance of {@link Transformation}. */ - public static Transformation parse(final Map<String, Object> transformationYaml) { + public static Optional<Transformation> parse(final Map<String, Object> transformationYaml) { final Transformation transformation = new Transformation(); - transformation.setName((String) transformationYaml.get(NAME.getName())); - transformation.setDescription((String) transformationYaml.get(DESCRIPTION.getName())); + final Optional<String> name = parseStringAttribute(NAME.getName(), transformationYaml); + if (!name.isPresent()) { + LOGGER.warn("Invalid '{}' value in transformation '{}'", NAME.getName(), transformationYaml.toString()); + } + transformation.setName(name.orElse(null)); + transformation.setDescription(parseStringAttribute(DESCRIPTION.getName(), transformationYaml).orElse(null)); + transformation.setPropertySet(readProperties(transformationYaml)); + + final String block = parseStringAttribute(TRANSFORMATION_FOR.getName(), transformationYaml).orElse(null); + final Optional<TransformationBlock> transformationBlockOptional = TransformationBlock.parse(block); + if (transformationBlockOptional.isPresent()) { + final TransformationBlock transformationBlock = transformationBlockOptional.get(); + transformation.setBlock(transformationBlock); + parseTransformationBlock(transformationBlock, transformation, transformationYaml); + } else { + LOGGER.warn("Invalid '{}' value in transformation '{}'", TRANSFORMATION_FOR.getName(), + transformationYaml.toString()); + } + + if (transformation.isValid()) { + return Optional.of(transformation); + } + + return Optional.empty(); + } + + private static Set<TransformationProperty> readProperties(final Map<String, Object> transformationYaml) { + final Map<String, Object> propertyMap = (Map<String, Object>) transformationYaml.get(PROPERTIES.getName()); + if (MapUtils.isEmpty(propertyMap)) { + return Collections.emptySet(); + } + + final Set<TransformationProperty> propertySet = new HashSet<>(); + + propertyMap.forEach((key, value) -> { + final TransformationPropertyType transformationPropertyType = TransformationPropertyType.parse(key) + .orElse(null); + + if(transformationPropertyType != null) { + if (value instanceof String) { + propertySet.add(new TransformationProperty<>(transformationPropertyType, (String) value)); + } else if (value instanceof Boolean) { + propertySet.add(new TransformationProperty<>(transformationPropertyType, (Boolean) value)); + } else if (value instanceof Integer) { + propertySet.add(new TransformationProperty<>(transformationPropertyType, (Integer) value)); + } else { + propertySet.add(new TransformationProperty<>(transformationPropertyType, value)); + } + } + }); - final String block = (String) transformationYaml.get(TRANSFORMATION_FOR.getName()); - transformation.setBlock(TransformationBlock.parse(block).orElse(null)); + return propertySet; + } + + private static void parseTransformationBlock(final TransformationBlock transformationBlock, + final Transformation transformationReference, + final Map<String, Object> transformationYaml) { + if (transformationBlock == TransformationBlock.CUSTOM_NODE_TYPE) { + parseCustomNodeTypeBlock(transformationReference, transformationYaml); + return; + } - transformation.setConversionQuery( - ConversionQueryYamlParser.parse(transformationYaml.get(QUERY.getName())) - ); - transformation.setConversionDefinitionList(parseConversions(transformationYaml)); + ConversionQueryYamlParser.parse(transformationYaml.get(QUERY.getName())) + .ifPresent(transformationReference::setConversionQuery); - return transformation; + transformationReference.setConversionDefinitionList(parseConversions(transformationYaml)); + } + + private static void parseCustomNodeTypeBlock(final Transformation transformationReference, + final Map<String, Object> transformationYaml) { + final Object fromAttribute = transformationYaml.get(FROM.getName()); + if (!(fromAttribute instanceof String)) { + return; + } + final String from = parseStringAttribute(FROM.getName(), transformationYaml).orElse(null); + + final Object toAttribute = transformationYaml.get(TO.getName()); + if (!(toAttribute instanceof String)) { + return; + } + final String to = parseStringAttribute(TO.getName(), transformationYaml).orElse(null); + + final HashMap<String, String> transformationQuery = new HashMap<>(); + transformationQuery.put(ToscaTagNamesEnum.DERIVED_FROM.getElementName(), from); + transformationReference.setConversionQuery(new ConversionQuery(transformationQuery)); + + final List<ConversionDefinition> conversionDefinitionList = new ArrayList<>(); + final HashMap<String, String> conversionDefinitionQuery = new HashMap<>(); + conversionDefinitionQuery.put(ToscaTagNamesEnum.TYPE.getElementName(), null); + ConversionDefinition conversionDefinition = new ConversionDefinition(new ConversionQuery(conversionDefinitionQuery) + , ToscaTagNamesEnum.TYPE.getElementName(), new ReplaceConversionStrategy(from, to)); + conversionDefinitionList.add(conversionDefinition); + transformationReference.setConversionDefinitionList(conversionDefinitionList); } private static List<ConversionDefinition> parseConversions(final Map<String, Object> conversionYaml) { @@ -73,8 +173,18 @@ public class TransformationYamlParser { } return conversionList.stream() - .map(conversion -> ConversionDefinitionYamlParser.parse((Map<String, Object>) conversion)) + .map(conversion -> ConversionDefinitionYamlParser.parse((Map<String, Object>) conversion).orElse(null)) + .filter(Objects::nonNull) .collect(Collectors.toList()); } + private static Optional<String> parseStringAttribute(final String attribute, final Map<String, Object> transformationYaml) { + try { + return Optional.of((String) transformationYaml.get(attribute)); + } catch (final Exception ignore) { + LOGGER.warn("Could not parse the String '{}' in transformation '{}'", attribute, transformationYaml.toString()); + return Optional.empty(); + } + } + } diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java index fa1de6751c..b7ba56ee5a 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java @@ -212,7 +212,7 @@ public abstract class AbstractToscaConverter implements ToscaConverter { serviceTemplate.setMetadata(finalMetadata); } - private void convertNodeTypes(ServiceTemplate serviceTemplate, ServiceTemplateReaderService readerService) { + protected void convertNodeTypes(ServiceTemplate serviceTemplate, ServiceTemplateReaderService readerService) { Map<String, Object> nodeTypes = readerService.getNodeTypes(); if (MapUtils.isEmpty(nodeTypes)) { return; diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolModelDrivenConverterPnf.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolModelDrivenConverterPnf.java index ee2c4060e5..b861980f24 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolModelDrivenConverterPnf.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolModelDrivenConverterPnf.java @@ -21,7 +21,9 @@ package org.openecomp.core.impl; import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; import org.openecomp.core.converter.ServiceTemplateReaderService; -import org.openecomp.core.converter.impl.pnfd.PnfdTransformationEngine; +import org.openecomp.core.converter.impl.pnfd.PnfdNodeTemplateTransformationEngine; +import org.openecomp.core.converter.impl.pnfd.PnfdNodeTypeTransformationEngine; +import org.openecomp.core.converter.pnfd.PnfdTransformationEngine; public class ToscaSolModelDrivenConverterPnf extends AbstractToscaSolConverter { @@ -31,9 +33,18 @@ public class ToscaSolModelDrivenConverterPnf extends AbstractToscaSolConverter { * @param readerService */ @Override - public void convertTopologyTemplate(final ServiceTemplate serviceTemplate, final ServiceTemplateReaderService readerService) { - final PnfdTransformationEngine pnfdTransformationEngine = new PnfdTransformationEngine(readerService, serviceTemplate); + public void convertTopologyTemplate(final ServiceTemplate serviceTemplate, + final ServiceTemplateReaderService readerService) { + final PnfdTransformationEngine pnfdTransformationEngine = + new PnfdNodeTemplateTransformationEngine(readerService, serviceTemplate); pnfdTransformationEngine.transform(); } + @Override + protected void convertNodeTypes(final ServiceTemplate serviceTemplate, + final ServiceTemplateReaderService readerService) { + final PnfdTransformationEngine pnfdTransformationEngine = + new PnfdNodeTypeTransformationEngine(readerService, serviceTemplate); + pnfdTransformationEngine.transform(); + } }
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/resources/pnfdTransformationTemplate/model-driven-conversion.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/resources/pnfdTransformationTemplate/model-driven-conversion.yaml index c58a23b8a2..9d2a899bd4 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/resources/pnfdTransformationTemplate/model-driven-conversion.yaml +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/resources/pnfdTransformationTemplate/model-driven-conversion.yaml @@ -1,3 +1,68 @@ +- transformation-for: nodeType # Transforms all Node Types that extend from a valid ONAP NodeType. + name: Node Type transformation + description: converts any node type that has/extends from the type tosca.nodes.nfv.PnfExtCp + properties: + nodeNamePrefix: "org.openecomp.resource.abstract." + query: + derived_from: tosca.nodes.nfv.PnfExtCp + conversions: + - query: + derived_from: + to-name: derived_from + to-value: + strategy: replace + from: tosca.nodes.nfv.PnfExtCp + to: org.openecomp.resource.cp.v2.extCP + - query: + version: + to-name: version + to-value: + strategy: copy + - query: + metadata: + to-name: metadata + to-value: + strategy: copy + - query: + description: + to-name: description + to-value: + strategy: copy + - query: + attributes: + to-name: attributes + to-value: + strategy: copy + - query: + properties: + to-name: properties + to-value: + strategy: copy + - query: + requirements: + to-name: requirements + to-value: + strategy: copy + - query: + capabilities: + to-name: capabilities + to-value: + strategy: copy + - query: + interfaces: + to-name: interfaces + to-value: + strategy: copy + - query: + artifacts: + to-name: artifacts + to-value: + strategy: copy +- transformation-for: customNodeType # Transforms all Customized Node Types that extend from a valid ONAP NodeType. + name: Custom Node Type transformation + description: converts any node type that has/extends from the type tosca.nodes.nfv.PnfExtCp + from: tosca.nodes.nfv.PnfExtCp + to: org.openecomp.resource.cp.v2.extCP - transformation-for: nodeTemplate #block name: PnfExtCp transformation #transformation name description: converts any node template that has a type tosca.nodes.nfv.PnfExtCp #transformation description diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfTransformationEngineParameterizedTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfTransformationEngineParameterizedTest.java index e2cbc147ac..a343e1aec0 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfTransformationEngineParameterizedTest.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfTransformationEngineParameterizedTest.java @@ -23,6 +23,7 @@ import static org.junit.Assert.assertEquals; import java.io.IOException; import java.io.InputStream; +import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -40,6 +41,7 @@ import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil; import org.onap.sdc.tosca.services.YamlUtil; import org.openecomp.core.converter.ServiceTemplateReaderService; +import org.openecomp.core.converter.pnfd.PnfdTransformationEngine; import org.openecomp.core.impl.services.ServiceTemplateReaderServiceImpl; @RunWith(Parameterized.class) @@ -72,7 +74,7 @@ public class PnfTransformationEngineParameterizedTest { @Parameterized.Parameters(name = "{index}: input: {0}, descriptor: {4}, output: {2}") - public static Collection input() throws IOException { + public static Collection input() throws IOException, URISyntaxException { return Files.list(getPathFromClasspath(TEST_CASES_PATH)).map(path -> { try { return buildTestCase(path); @@ -90,7 +92,6 @@ public class PnfTransformationEngineParameterizedTest { if (inputFilePath == null) { return Collections.emptyList(); } - ; final List<Path> transformationDescriptorList; try (final Stream<Path> files = Files.walk(testCasePath.resolve(TRANSFORMATION_DESCRIPTOR_FOLDER))) { transformationDescriptorList = files.filter(path -> Files.isRegularFile(path)) @@ -130,8 +131,8 @@ public class PnfTransformationEngineParameterizedTest { final ServiceTemplateReaderService serviceTemplateReaderService = new ServiceTemplateReaderServiceImpl(descriptor); final ServiceTemplate serviceTemplate = new ServiceTemplate(); - final PnfdTransformationEngine pnfdTransformationEngine = new PnfdTransformationEngine(serviceTemplateReaderService, serviceTemplate - , transformationDescriptorFilePath.toString()); + final PnfdTransformationEngine pnfdTransformationEngine = new PnfdNodeTemplateTransformationEngine( + serviceTemplateReaderService, serviceTemplate, transformationDescriptorFilePath.toString()); pnfdTransformationEngine.transform(); final String result = yamlUtil.objectToYaml(serviceTemplate); @@ -146,7 +147,7 @@ public class PnfTransformationEngineParameterizedTest { } } - private static Path getPathFromClasspath(final String location) { - return Paths.get(Thread.currentThread().getContextClassLoader().getResource(location).getPath()); + private static Path getPathFromClasspath(final String location) throws URISyntaxException { + return Paths.get(PnfTransformationEngineParameterizedTest.class.getClassLoader().getResource(location).toURI()); } }
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfTransformationEngineTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfTransformationEngineTest.java index 280d14888d..be13d775e3 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfTransformationEngineTest.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfTransformationEngineTest.java @@ -37,6 +37,7 @@ import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil; import org.onap.sdc.tosca.services.YamlUtil; import org.openecomp.core.converter.ServiceTemplateReaderService; +import org.openecomp.core.converter.pnfd.PnfdTransformationEngine; import org.openecomp.core.impl.services.ServiceTemplateReaderServiceImpl; @RunWith(Parameterized.class) @@ -66,11 +67,14 @@ public class PnfTransformationEngineTest { final ServiceTemplateReaderService serviceTemplateReaderService = new ServiceTemplateReaderServiceImpl(descriptor); final ServiceTemplate serviceTemplate = new ServiceTemplate(); - final PnfdTransformationEngine pnfdTransformationEngine = new PnfdTransformationEngine( + PnfdTransformationEngine pnfdTransformationEngine = new PnfdNodeTypeTransformationEngine( serviceTemplateReaderService, serviceTemplate); pnfdTransformationEngine.transform(); + pnfdTransformationEngine = new PnfdNodeTemplateTransformationEngine(serviceTemplateReaderService, serviceTemplate); + pnfdTransformationEngine.transform(); - final String result = yamlUtil.objectToYaml(serviceTemplate); + final String yamlContent = yamlUtil.objectToYaml(serviceTemplate); + final String result = yamlUtil.objectToYaml(yamlUtil.yamlToObject(yamlContent, ServiceTemplate.class)); final String expectedResult = getExpectedResultFor(inputFilename); assertEquals(expectedResult, result); } diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionDefinitionYamlParserTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionDefinitionYamlParserTest.java index 967081ba0f..2326318657 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionDefinitionYamlParserTest.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionDefinitionYamlParserTest.java @@ -47,7 +47,7 @@ public class ConversionDefinitionYamlParserTest { fail(String.format("Could not load %s", definitionYamlFilePath)); return; } - final ConversionDefinition conversionDefinition = ConversionDefinitionYamlParser.parse(definitionYaml); + final ConversionDefinition conversionDefinition = ConversionDefinitionYamlParser.parse(definitionYaml).orElse(null); assertConversionDefinition(definitionYaml, conversionDefinition); } diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/model-driven-conversion.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/model-driven-conversion.yaml deleted file mode 100644 index 4d1500169e..0000000000 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/model-driven-conversion.yaml +++ /dev/null @@ -1,69 +0,0 @@ -- transformation-for: nodeTemplate #or "region: nodeTemplate"; or "object: nodeTemplate" - name: PnfExtCp transformation - description: converts any node template that has a type tosca.nodes.nfv.PnfExtCp - query: #or "find:" - #currently we only support a single attribute and value search. Can be hierarchical like "properties: layer_protocols:". - #must have the same structure in the original node_template declaration, otherwise the attribute will not be found. - type: tosca.nodes.nfv.PnfExtCp - conversions: - - query: #attribute query - #must have the same structure in the original node_template declaration, otherwise the attribute will not be found. - #the value does not matter as we are going to convert it. - type: - to-name: type #new attribute name. We could have a default strategy to copy the original name (in the query) if this entry is not provided. - to-value: - strategy: replace - from: tosca.nodes.nfv.PnfExtCp #could be ignored - to: org.openecomp.resource.cp.v2.extCP - - query: - properties: - layer_protocols: - to-name: ip_requirements - to-value: - strategy: replaceInList - list: - - from: ipv4 - to: - assingment_method: dhcp - ip_version: 4 - - from: ipv6 - to: - assingment_method: dhcp - ip_version: 6 - to-get-input: ipRequirements -- transformation-for: getInputFunction - name: ipRequirements - description: converts IpRequirements inputs when called by a get_input TOSCA function - conversions: - - query: - type: - to-name: type - to-value: - strategy: copy - - query: - description: - to-name: description - to-value: - strategy: copy - - query: - entry_schema: - type: - to-name: type - to-value: - strategy: replace - from: string - to: org.openecomp.datatypes.network.IpRequirements - - query: - default: - to-name: default - to-value: - strategy: replaceInList - list: - - from: ipv4 - to: - assingment_method: dhcp - ip_version: 4 - - from: ipv6 - to: - assingment_method: dhcp - ip_version: 6
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withCustomType.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withCustomType.yaml new file mode 100644 index 0000000000..8fc43390dc --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withCustomType.yaml @@ -0,0 +1,95 @@ +tosca_definitions_version: tosca_simple_yaml_1_1 + +description: the service template of a PNFD + +imports: + - etsi_nfv_sol001_pnfd_2_5_1_types.yaml + +node_types: + myCustomizedNodeType_A: + derived_from: tosca.nodes.nfv.PnfExtCp + myCustomizedNodeType_B: + derived_from: myCustomizedNodeType_A + myCustomizedNodeType_C: + derived_from: AnotherCustomizedNodeType + myCustomizedNodeType_D: + derived_from: myCustomizedNodeType_C + myCustomizedNodeType_E: + derived_from: myCustomizedNodeType_D + properties: + descriptor_id: + type: string + constraints: [ valid_values: [ b1bb0ce7-ebca-4fa7-95ed-4840d70a2233 ] ] + default: b1bb0ce7-ebca-4fa7-95ed-4840d70a2233 + function_description: + type: string + default: an example PNF + provider: + type: string + constraints: [ valid_values: [ MyCompany] ] + default: MyCompany + version: + type: string + constraints: [ valid_values: [ '1.0' ] ] + default: '1.0' + descriptor_invariant_id: + type: string + constraints: [ valid_values: [ 1111-2222-ccaa-bbdd ] ] + default: 1111-2222-ccaa-bbdd + name: + type: string + constraints: [ valid_values: [ExamplePnf] ] + default: ExamplePnf + requirements: + - virtual_link: + capability: tosca.capabilities.nfv.VirtualLinkable + +topology_template: + inputs: + anyOtherInput: + type: string + description: this is input1 + default: defaultValue + protocols: + type: list + description: IP protocols + entry_schema: + type: string + default: [ ipv4, ipv6 ] + + substitution_mappings: + node_type: myCustomizedNodeType_B + requirements: + virtual_link: [ pnfExtCp_1, external_virtual_link ] + + node_templates: + pnf_mainPart: + type: myCustomizedNodeType_B + properties: + descriptor_id: b1bb0ce7-ebca-4fa7-95ed-4840d70a2233 + function_description: an example PNF + provider: Mycompany + version: 1.0 + descriptor_invariant_id: 1111-2222-ccaa-bbdd + name: ExamplePnf + + pnfExtCp_1: + type: tosca.nodes.nfv.PnfExtCp + properties: + protocol: [ associated_layer_protocol: ipv4 ] + trunk_mode: false + layer_protocols: [ ipv4 ] + role: leaf + description: External connection point to access this pnf + requirements: + - dependency: pnf_mainPart + + pnfExtCp_2: + type: tosca.nodes.nfv.PnfExtCp + properties: + trunk_mode: false + layer_protocols: { get_input: protocols } + role: leaf + description: External connection point to access Acme myPnf + requirements: + - dependency: myPnf
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withCustomTypeDerivedFromMultiple.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withCustomTypeDerivedFromMultiple.yaml new file mode 100644 index 0000000000..b3f4ce0f53 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withCustomTypeDerivedFromMultiple.yaml @@ -0,0 +1,95 @@ +tosca_definitions_version: tosca_simple_yaml_1_1 + +description: the service template of a PNFD + +imports: + - etsi_nfv_sol001_pnfd_2_5_1_types.yaml + +node_types: + myCustomizedNodeType_C: + derived_from: myCustomizedNodeType_B + myCustomizedNodeType_A: + derived_from: tosca.nodes.nfv.PnfExtCp + myCustomizedNodeType_D: + derived_from: myCustomizedNodeType_C + myCustomizedNodeType_E: + derived_from: myCustomizedNodeType_XXXXXX + myCustomizedNodeType_B: + derived_from: myCustomizedNodeType_A + properties: + descriptor_id: + type: string + constraints: [ valid_values: [ b1bb0ce7-ebca-4fa7-95ed-4840d70a2233 ] ] + default: b1bb0ce7-ebca-4fa7-95ed-4840d70a2233 + function_description: + type: string + default: an example PNF + provider: + type: string + constraints: [ valid_values: [ MyCompany] ] + default: MyCompany + version: + type: string + constraints: [ valid_values: [ '1.0' ] ] + default: '1.0' + descriptor_invariant_id: + type: string + constraints: [ valid_values: [ 1111-2222-ccaa-bbdd ] ] + default: 1111-2222-ccaa-bbdd + name: + type: string + constraints: [ valid_values: [ExamplePnf] ] + default: ExamplePnf + requirements: + - virtual_link: + capability: tosca.capabilities.nfv.VirtualLinkable + +topology_template: + inputs: + anyOtherInput: + type: string + description: this is input1 + default: defaultValue + protocols: + type: list + description: IP protocols + entry_schema: + type: string + default: [ ipv4, ipv6 ] + + substitution_mappings: + node_type: myCustomizedNodeType_C + requirements: + virtual_link: [ pnfExtCp_1, external_virtual_link ] + + node_templates: + pnf_mainPart: + type: myCustomizedNodeType_C + properties: + descriptor_id: b1bb0ce7-ebca-4fa7-95ed-4840d70a2233 + function_description: an example PNF + provider: Mycompany + version: 1.0 + descriptor_invariant_id: 1111-2222-ccaa-bbdd + name: ExamplePnf + + pnfExtCp_1: + type: tosca.nodes.nfv.PnfExtCp + properties: + protocol: [ associated_layer_protocol: ipv4 ] + trunk_mode: false + layer_protocols: [ ipv4 ] + role: leaf + description: External connection point to access this pnf + requirements: + - dependency: pnf_mainPart + + pnfExtCp_2: + type: tosca.nodes.nfv.PnfExtCp + properties: + trunk_mode: false + layer_protocols: { get_input: protocols } + role: leaf + description: External connection point to access Acme myPnf + requirements: + - dependency: myPnf
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_with_Invalid_CustomType.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_with_Invalid_CustomType.yaml new file mode 100644 index 0000000000..d27fbfd70a --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_with_Invalid_CustomType.yaml @@ -0,0 +1,95 @@ +tosca_definitions_version: tosca_simple_yaml_1_1 + +description: the service template of a PNFD + +imports: + - etsi_nfv_sol001_pnfd_2_5_1_types.yaml + +node_types: + myCustomizedNodeType_A: + derived_from: tosca.nodes.nfv.INVALID + myCustomizedNodeType_B: + derived_from: myCustomizedNodeType_A + myCustomizedNodeType_C: + derived_from: myCustomizedNodeType_B + myCustomizedNodeType_D: + derived_from: myCustomizedNodeType_C + myCustomizedNodeType_E: + derived_from: myCustomizedNodeType_D + properties: + descriptor_id: + type: string + constraints: [ valid_values: [ b1bb0ce7-ebca-4fa7-95ed-4840d70a2233 ] ] + default: b1bb0ce7-ebca-4fa7-95ed-4840d70a2233 + function_description: + type: string + default: an example PNF + provider: + type: string + constraints: [ valid_values: [ MyCompany] ] + default: MyCompany + version: + type: string + constraints: [ valid_values: [ '1.0' ] ] + default: '1.0' + descriptor_invariant_id: + type: string + constraints: [ valid_values: [ 1111-2222-ccaa-bbdd ] ] + default: 1111-2222-ccaa-bbdd + name: + type: string + constraints: [ valid_values: [ExamplePnf] ] + default: ExamplePnf + requirements: + - virtual_link: + capability: tosca.capabilities.nfv.VirtualLinkable + +topology_template: + inputs: + anyOtherInput: + type: string + description: this is input1 + default: defaultValue + protocols: + type: list + description: IP protocols + entry_schema: + type: string + default: [ ipv4, ipv6 ] + + substitution_mappings: + node_type: 00_Another_NodeTypeMyCompany.examplePnf.1_0 + requirements: + virtual_link: [ pnfExtCp_1, external_virtual_link ] + + node_templates: + pnf_mainPart: + type: wrong_nodeType_Not_Derived_from_any_valid_Node + properties: + descriptor_id: b1bb0ce7-ebca-4fa7-95ed-4840d70a2233 + function_description: an example PNF + provider: Mycompany + version: 1.0 + descriptor_invariant_id: 1111-2222-ccaa-bbdd + name: ExamplePnf + + pnfExtCp_1: + type: tosca.nodes.nfv.PnfExtCp + properties: + protocol: [ associated_layer_protocol: ipv4 ] + trunk_mode: false + layer_protocols: [ ipv4 ] + role: leaf + description: External connection point to access this pnf + requirements: + - dependency: pnf_mainPart + + pnfExtCp_2: + type: tosca.nodes.nfv.PnfExtCp + properties: + trunk_mode: false + layer_protocols: { get_input: protocols } + role: leaf + description: External connection point to access Acme myPnf + requirements: + - dependency: myPnf
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_with_Multiple_CustomType.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_with_Multiple_CustomType.yaml new file mode 100644 index 0000000000..7a886c4917 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_with_Multiple_CustomType.yaml @@ -0,0 +1,105 @@ +tosca_definitions_version: tosca_simple_yaml_1_1 + +description: the service template of a PNFD + +imports: + - etsi_nfv_sol001_pnfd_2_5_1_types.yaml + +node_types: + myCustomizedNodeType_B: + derived_from: myCustomizedNodeType_A + myCustomizedNodeType_A: + derived_from: tosca.nodes.nfv.PnfExtCp + myCustomizedNodeType_C: + derived_from: myCustomizedNodeType_D + myCustomizedNodeType_D: + derived_from: tosca.nodes.nfv.PnfExtCp + myCustomizedNodeType_E: + derived_from: myCustomizedNodeType_D + properties: + descriptor_id: + type: string + constraints: [ valid_values: [ b1bb0ce7-ebca-4fa7-95ed-4840d70a2233 ] ] + default: b1bb0ce7-ebca-4fa7-95ed-4840d70a2233 + function_description: + type: string + default: an example PNF + provider: + type: string + constraints: [ valid_values: [ MyCompany] ] + default: MyCompany + version: + type: string + constraints: [ valid_values: [ '1.0' ] ] + default: '1.0' + descriptor_invariant_id: + type: string + constraints: [ valid_values: [ 1111-2222-ccaa-bbdd ] ] + default: 1111-2222-ccaa-bbdd + name: + type: string + constraints: [ valid_values: [ExamplePnf] ] + default: ExamplePnf + requirements: + - virtual_link: + capability: tosca.capabilities.nfv.VirtualLinkable + +topology_template: + inputs: + anyOtherInput: + type: string + description: this is input1 + default: defaultValue + protocols: + type: list + description: IP protocols + entry_schema: + type: string + default: [ ipv4, ipv6 ] + + substitution_mappings: + node_type: myCustomizedNodeType_B + requirements: + virtual_link: [ pnfExtCp_1, external_virtual_link ] + + node_templates: + pnf_mainPart: + type: myCustomizedNodeType_B + properties: + descriptor_id: b1bb0ce7-ebca-4fa7-95ed-4840d70a2233 + function_description: an example PNF + provider: Mycompany + version: 1.0 + descriptor_invariant_id: 1111-2222-ccaa-bbdd + name: ExamplePnf + + pnfExtCp_1: + type: tosca.nodes.nfv.PnfExtCp + properties: + protocol: [ associated_layer_protocol: ipv4 ] + trunk_mode: false + layer_protocols: [ ipv4 ] + role: leaf + description: External connection point to access this pnf + requirements: + - dependency: pnf_mainPart + + pnfExtCp_2: + type: tosca.nodes.nfv.PnfExtCp + properties: + trunk_mode: false + layer_protocols: { get_input: protocols } + role: leaf + description: External connection point to access Acme myPnf + requirements: + - dependency: myPnf + + pnfExtCp_3: + type: myCustomizedNodeType_C + properties: + trunk_mode: false + layer_protocols: { get_input: protocols } + role: leaf + description: External connection point to access Acme myPnf + requirements: + - dependency: myPnf
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withCustomType.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withCustomType.yaml new file mode 100644 index 0000000000..0013ae08dc --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withCustomType.yaml @@ -0,0 +1,31 @@ +node_types: + org.openecomp.resource.abstract.myCustomizedNodeType_B: + derived_from: org.openecomp.resource.cp.v2.extCP + org.openecomp.resource.abstract.myCustomizedNodeType_A: + derived_from: org.openecomp.resource.cp.v2.extCP +topology_template: + inputs: + protocols: + type: list + description: IP protocols + default: + - assingment_method: dhcp + ip_version: 4 + - assingment_method: dhcp + ip_version: 6 + entry_schema: + type: org.openecomp.datatypes.network.IpRequirements + node_templates: + pnf_mainPart: + type: org.openecomp.resource.cp.v2.extCP + pnfExtCp_2: + type: org.openecomp.resource.cp.v2.extCP + properties: + ip_requirements: + get_input: protocols + pnfExtCp_1: + type: org.openecomp.resource.cp.v2.extCP + properties: + ip_requirements: + - assingment_method: dhcp + ip_version: 4 diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withCustomTypeDerivedFromMultiple.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withCustomTypeDerivedFromMultiple.yaml new file mode 100644 index 0000000000..6092097c31 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withCustomTypeDerivedFromMultiple.yaml @@ -0,0 +1,84 @@ +node_types: + org.openecomp.resource.abstract.myCustomizedNodeType_B: + derived_from: org.openecomp.resource.cp.v2.extCP + properties: + descriptor_id: + type: string + required: true + default: b1bb0ce7-ebca-4fa7-95ed-4840d70a2233 + status: supported + constraints: + - valid_values: + - b1bb0ce7-ebca-4fa7-95ed-4840d70a2233 + function_description: + type: string + required: true + default: an example PNF + status: supported + provider: + type: string + required: true + default: MyCompany + status: supported + constraints: + - valid_values: + - MyCompany + version: + type: string + required: true + default: '1.0' + status: supported + constraints: + - valid_values: + - '1.0' + descriptor_invariant_id: + type: string + required: true + default: 1111-2222-ccaa-bbdd + status: supported + constraints: + - valid_values: + - 1111-2222-ccaa-bbdd + name: + type: string + required: true + default: ExamplePnf + status: supported + constraints: + - valid_values: + - ExamplePnf + requirements: + - virtual_link: + capability: tosca.capabilities.nfv.VirtualLinkable + org.openecomp.resource.abstract.myCustomizedNodeType_C: + derived_from: org.openecomp.resource.cp.v2.extCP + org.openecomp.resource.abstract.myCustomizedNodeType_A: + derived_from: org.openecomp.resource.cp.v2.extCP + org.openecomp.resource.abstract.myCustomizedNodeType_D: + derived_from: org.openecomp.resource.cp.v2.extCP +topology_template: + inputs: + protocols: + type: list + description: IP protocols + default: + - assingment_method: dhcp + ip_version: 4 + - assingment_method: dhcp + ip_version: 6 + entry_schema: + type: org.openecomp.datatypes.network.IpRequirements + node_templates: + pnf_mainPart: + type: org.openecomp.resource.cp.v2.extCP + pnfExtCp_2: + type: org.openecomp.resource.cp.v2.extCP + properties: + ip_requirements: + get_input: protocols + pnfExtCp_1: + type: org.openecomp.resource.cp.v2.extCP + properties: + ip_requirements: + - assingment_method: dhcp + ip_version: 4 diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_with_Invalid_CustomType.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_with_Invalid_CustomType.yaml new file mode 100644 index 0000000000..3292a94a58 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_with_Invalid_CustomType.yaml @@ -0,0 +1,19 @@ +topology_template: + inputs: + protocols: + type: list + description: IP protocols + entry_schema: + type: org.openecomp.datatypes.network.IpRequirements + default: [{assingment_method: dhcp, ip_version: 4}, {assingment_method: dhcp, ip_version: 6}] + node_templates: + pnfExtCp_2: + type: org.openecomp.resource.cp.v2.extCP + properties: + ip_requirements: { get_input: protocols } + pnfExtCp_1: + type: org.openecomp.resource.cp.v2.extCP + properties: + ip_requirements: + - assingment_method: dhcp + ip_version: 4 diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_with_Multiple_CustomType.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_with_Multiple_CustomType.yaml new file mode 100644 index 0000000000..3fd846bbef --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_with_Multiple_CustomType.yaml @@ -0,0 +1,88 @@ +node_types: + org.openecomp.resource.abstract.myCustomizedNodeType_B: + derived_from: org.openecomp.resource.cp.v2.extCP + org.openecomp.resource.abstract.myCustomizedNodeType_C: + derived_from: org.openecomp.resource.cp.v2.extCP + org.openecomp.resource.abstract.myCustomizedNodeType_A: + derived_from: org.openecomp.resource.cp.v2.extCP + org.openecomp.resource.abstract.myCustomizedNodeType_D: + derived_from: org.openecomp.resource.cp.v2.extCP + org.openecomp.resource.abstract.myCustomizedNodeType_E: + derived_from: org.openecomp.resource.cp.v2.extCP + properties: + descriptor_id: + type: string + required: true + default: b1bb0ce7-ebca-4fa7-95ed-4840d70a2233 + status: supported + constraints: + - valid_values: + - b1bb0ce7-ebca-4fa7-95ed-4840d70a2233 + function_description: + type: string + required: true + default: an example PNF + status: supported + provider: + type: string + required: true + default: MyCompany + status: supported + constraints: + - valid_values: + - MyCompany + version: + type: string + required: true + default: '1.0' + status: supported + constraints: + - valid_values: + - '1.0' + descriptor_invariant_id: + type: string + required: true + default: 1111-2222-ccaa-bbdd + status: supported + constraints: + - valid_values: + - 1111-2222-ccaa-bbdd + name: + type: string + required: true + default: ExamplePnf + status: supported + constraints: + - valid_values: + - ExamplePnf + requirements: + - virtual_link: + capability: tosca.capabilities.nfv.VirtualLinkable +topology_template: + inputs: + protocols: + type: list + description: IP protocols + default: + - assingment_method: dhcp + ip_version: 4 + - assingment_method: dhcp + ip_version: 6 + entry_schema: + type: org.openecomp.datatypes.network.IpRequirements + node_templates: + pnf_mainPart: + type: org.openecomp.resource.cp.v2.extCP + pnfExtCp_3: + type: org.openecomp.resource.cp.v2.extCP + pnfExtCp_2: + type: org.openecomp.resource.cp.v2.extCP + properties: + ip_requirements: + get_input: protocols + pnfExtCp_1: + type: org.openecomp.resource.cp.v2.extCP + properties: + ip_requirements: + - assingment_method: dhcp + ip_version: 4 |