From 5775dd13964a56a60dfbe8fc72e5977672d5acb8 Mon Sep 17 00:00:00 2001 From: aribeiro Date: Wed, 11 Sep 2019 13:50:46 +0100 Subject: Transform custom types for PNFD. Transformation of customized Node Types for PNFD. Issue-ID: SDC-2561 Change-Id: Id3e07edff0e5a8cb134aa12c07878e14c33d1512 Signed-off-by: aribeiro --- .../converter/pnfd/PnfdTransformationEngine.java | 30 +++ .../converter/pnfd/model/ConversionDefinition.java | 6 + .../pnfd/model/PnfTransformationToken.java | 5 +- .../core/converter/pnfd/model/Transformation.java | 31 ++- .../converter/pnfd/model/TransformationBlock.java | 16 +- .../pnfd/model/TransformationProperty.java | 40 ++++ .../pnfd/model/TransformationPropertyType.java | 42 ++++ .../pnfd/parser/AbstractPnfdBlockParser.java | 178 ---------------- .../pnfd/AbstractPnfdTransformationEngine.java | 86 ++++++++ .../pnfd/PnfdNodeTemplateTransformationEngine.java | 167 +++++++++++++++ .../pnfd/PnfdNodeTypeTransformationEngine.java | 72 +++++++ .../pnfd/PnfdTransformationDescriptorReader.java | 4 +- .../impl/pnfd/PnfdTransformationEngine.java | 183 ----------------- .../impl/pnfd/factory/PnfdBlockParserFactory.java | 8 +- .../impl/pnfd/parser/AbstractPnfdBlockParser.java | 226 +++++++++++++++++++++ .../parser/ConversionDefinitionYamlParser.java | 15 +- .../pnfd/parser/ConversionQueryYamlParser.java | 9 +- .../impl/pnfd/parser/NodeTypeYamlParser.java | 67 ++++++ .../pnfd/parser/PnfdCustomNodeTypeBlockParser.java | 88 ++++++++ .../impl/pnfd/parser/PnfdInputBlockParser.java | 1 - .../pnfd/parser/PnfdNodeTemplateBlockParser.java | 43 ++-- .../impl/pnfd/parser/PnfdNodeTypeBlockParser.java | 94 +++++++++ .../impl/pnfd/parser/TransformationYamlParser.java | 132 +++++++++++- .../core/impl/AbstractToscaConverter.java | 2 +- .../core/impl/ToscaSolModelDrivenConverterPnf.java | 17 +- .../model-driven-conversion.yaml | 65 ++++++ .../PnfTransformationEngineParameterizedTest.java | 13 +- .../impl/pnfd/PnfTransformationEngineTest.java | 8 +- .../parser/ConversionDefinitionYamlParserTest.java | 2 +- .../test/resources/model-driven-conversion.yaml | 69 ------- .../in/pnfDescriptor_withCustomType.yaml | 95 +++++++++ ...scriptor_withCustomTypeDerivedFromMultiple.yaml | 95 +++++++++ .../in/pnfDescriptor_with_Invalid_CustomType.yaml | 95 +++++++++ .../in/pnfDescriptor_with_Multiple_CustomType.yaml | 105 ++++++++++ .../out/topologyTemplate_withCustomType.yaml | 31 +++ ...Template_withCustomTypeDerivedFromMultiple.yaml | 84 ++++++++ .../topologyTemplate_with_Invalid_CustomType.yaml | 19 ++ .../topologyTemplate_with_Multiple_CustomType.yaml | 88 ++++++++ 38 files changed, 1836 insertions(+), 495 deletions(-) create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/PnfdTransformationEngine.java create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/TransformationProperty.java create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/TransformationPropertyType.java delete mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/parser/AbstractPnfdBlockParser.java create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/AbstractPnfdTransformationEngine.java create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdNodeTemplateTransformationEngine.java create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdNodeTypeTransformationEngine.java delete mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdTransformationEngine.java create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/AbstractPnfdBlockParser.java create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/NodeTypeYamlParser.java create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdCustomNodeTypeBlockParser.java create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdNodeTypeBlockParser.java delete mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/model-driven-conversion.yaml create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withCustomType.yaml create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withCustomTypeDerivedFromMultiple.yaml create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_with_Invalid_CustomType.yaml create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_with_Multiple_CustomType.yaml create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withCustomType.yaml create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withCustomTypeDerivedFromMultiple.yaml create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_with_Invalid_CustomType.yaml create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_with_Multiple_CustomType.yaml (limited to 'openecomp-be/lib') diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/PnfdTransformationEngine.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/PnfdTransformationEngine.java new file mode 100644 index 0000000000..12949f2dcc --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/PnfdTransformationEngine.java @@ -0,0 +1,30 @@ +/* + * ============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.pnfd; + +/** + * Engine that manages the PNF Descriptor transformation process. + */ +@FunctionalInterface +public interface PnfdTransformationEngine { + + void transform(); + +} diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/ConversionDefinition.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/ConversionDefinition.java index 040639358f..fa06ab800e 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/ConversionDefinition.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/ConversionDefinition.java @@ -32,4 +32,10 @@ public class ConversionDefinition { private PnfdConversionStrategy pnfdConversionStrategy; private String toGetInput; + public ConversionDefinition(ConversionQuery conversionQuery, String toAttributeName, + PnfdConversionStrategy pnfdConversionStrategy) { + this.conversionQuery = conversionQuery; + this.toAttributeName = toAttributeName; + this.pnfdConversionStrategy = pnfdConversionStrategy; + } } diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/PnfTransformationToken.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/PnfTransformationToken.java index fab5b44720..886614799f 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/PnfTransformationToken.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/PnfTransformationToken.java @@ -34,7 +34,10 @@ public enum PnfTransformationToken { TRANSFORMATION_FOR("transformation-for"), NAME("name"), DESCRIPTION("description"), - GET_INPUT("get_input"), TO_GET_INPUT("to-get-input"); + GET_INPUT("get_input"), + TO_GET_INPUT("to-get-input"), + PROPERTIES("properties"), + NODE_TYPE("node_types"); private final String name; diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/Transformation.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/Transformation.java index fa4a9336e3..a3f7ca0626 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/Transformation.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/Transformation.java @@ -21,9 +21,12 @@ package org.openecomp.core.converter.pnfd.model; import java.util.List; import java.util.Objects; +import java.util.Optional; +import java.util.Set; import lombok.Getter; import lombok.Setter; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; /** * Represents a transformation from the PNFD transformation descriptor. @@ -35,6 +38,7 @@ public class Transformation { private String name; private String description; private TransformationBlock block; + private Set propertySet; private ConversionQuery conversionQuery; private List conversionDefinitionList; @@ -44,6 +48,9 @@ public class Transformation { * @return {code true} if the instance is valid, {code false} otherwise */ public boolean isValid() { + if (block == TransformationBlock.GET_INPUT_FUNCTION) { + return !StringUtils.isEmpty(name) && !CollectionUtils.isEmpty(conversionDefinitionList); + } return block != null && conversionQuery != null && !CollectionUtils.isEmpty(conversionDefinitionList); } @@ -55,9 +62,9 @@ public class Transformation { if (o == null || getClass() != o.getClass()) { return false; } - Transformation that = (Transformation) o; + final Transformation that = (Transformation) o; //if there is no query, compares by block and name. - if (conversionQuery != null && conversionQuery.getQuery() == null && that.conversionQuery.getQuery() == null) { + if (conversionQuery == null && that.conversionQuery == null) { return block == that.block && Objects.equals(name, that.name); } @@ -70,4 +77,24 @@ public class Transformation { public int hashCode() { return Objects.hash(block, conversionQuery); } + + public Optional getPropertyValue(final TransformationPropertyType type, Class clazz) { + if (CollectionUtils.isEmpty(propertySet)) { + return Optional.empty(); + } + + final Optional transformationProperty = propertySet.stream() + .filter(transformationProperty1 -> transformationProperty1.getType() == type) + .findFirst(); + if (transformationProperty.isPresent()) { + try { + T value = clazz.cast(transformationProperty.get().getValue()); + return Optional.of(value); + } catch (final ClassCastException ignored) { + return Optional.empty(); + } + } + + return Optional.empty(); + } } diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/TransformationBlock.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/TransformationBlock.java index 4c897c45fb..f8a5aee407 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/TransformationBlock.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/TransformationBlock.java @@ -20,25 +20,23 @@ package org.openecomp.core.converter.pnfd.model; import java.util.Optional; +import lombok.AllArgsConstructor; +import lombok.Getter; /** * Represents a type of a transformation block */ +@AllArgsConstructor +@Getter public enum TransformationBlock { INPUT("input"), + GET_INPUT_FUNCTION("getInputFunction"), NODE_TEMPLATE("nodeTemplate"), - GET_INPUT_FUNCTION("getInputFunction"); + CUSTOM_NODE_TYPE("customNodeType"), + NODE_TYPE("nodeType"); private final String name; - TransformationBlock(final String name) { - this.name = name; - } - - public String getName() { - return name; - } - /** * Parse a String to the related {@link TransformationBlock}. * @param name the {@link TransformationBlock} name diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/TransformationProperty.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/TransformationProperty.java new file mode 100644 index 0000000000..c42917d95d --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/TransformationProperty.java @@ -0,0 +1,40 @@ +/* + * ============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.pnfd.model; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; + +/** + * Represents a PNFD transformation block property. + * + * @param the type of the property value + */ +@Getter +@AllArgsConstructor +@EqualsAndHashCode +public class TransformationProperty { + + private TransformationPropertyType type; + + @EqualsAndHashCode.Exclude + private T value; +} diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/TransformationPropertyType.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/TransformationPropertyType.java new file mode 100644 index 0000000000..eed251944f --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/TransformationPropertyType.java @@ -0,0 +1,42 @@ +/* + * ============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.pnfd.model; + +import java.util.Arrays; +import java.util.Optional; +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * Represents a valid property for a PNFD transformation block. + */ +@Getter +@AllArgsConstructor +public enum TransformationPropertyType { + NODE_NAME_PREFIX("nodeNamePrefix"); + + private final String type; + + public static Optional parse(final String type) { + return Arrays.stream(values()) + .filter(transformationPropertyType -> transformationPropertyType.getType().equals(type)) + .findFirst(); + } +} diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/parser/AbstractPnfdBlockParser.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/parser/AbstractPnfdBlockParser.java deleted file mode 100644 index fe8bd428c3..0000000000 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/parser/AbstractPnfdBlockParser.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * ============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.pnfd.parser; - -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.pnfd.model.ConversionDefinition; -import org.openecomp.core.converter.pnfd.model.PnfTransformationToken; -import org.openecomp.core.converter.pnfd.model.Transformation; - -public abstract class AbstractPnfdBlockParser implements PnfdBlockParser { - - protected final Transformation transformation; - protected ServiceTemplateReaderService templateFrom; - protected ServiceTemplate templateTo; - - 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> 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 blockYamlObject) { - if (MapUtils.isEmpty(blockYamlObject)) { - return; - } - final List conversionDefinitionList = transformation.getConversionDefinitionList(); - final Map parsedBlockYamlObject = new HashMap<>(); - final String blockName = blockYamlObject.keySet().iterator().next(); - conversionDefinitionList.stream() - .filter(conversionDefinition -> conversionDefinition.getConversionQuery().isValidAttributeQuery()) - .forEach(conversionDefinition -> { - final Map query = - (Map) conversionDefinition.getConversionQuery().getQuery(); - final Map blockAttributeMap = (Map) blockYamlObject.get(blockName); - final Optional> 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 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> buildParsedBlock(final Map attributeQuery, - final Map 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 mergeYamlObjects(final Map originalMap, - final Map 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> 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 yamlMap = (Map) yamlObject; - return yamlMap.containsKey(PnfTransformationToken.GET_INPUT.getName()); - } - - return false; - } - - /** - * Gets the value (input name) of a YAML object representing a TOSCA get_input call: "get_input: value". - * - * @param yamlObject the YAML object - * @return The get_input function value, that represents the input name - */ - protected String extractGetInputFunctionValue(final Object yamlObject) { - if (yamlObject instanceof Map) { - final Map yamlMap = (Map) 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> getInputAndTransformationNameMap() { - return Optional.empty(); - } - -} 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> 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/PnfdNodeTemplateTransformationEngine.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdNodeTemplateTransformationEngine.java new file mode 100644 index 0000000000..b2038a00dd --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdNodeTemplateTransformationEngine.java @@ -0,0 +1,167 @@ +/* + * ============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.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.MapUtils; +import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; +import org.onap.sdc.tosca.datatypes.model.TopologyTemplate; +import org.openecomp.core.converter.ServiceTemplateReaderService; +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; + +/** + * Engine that manages the PNF Descriptor transformation process for the NodeTemplate block. + */ +public class PnfdNodeTemplateTransformationEngine extends AbstractPnfdTransformationEngine { + + public PnfdNodeTemplateTransformationEngine(final ServiceTemplateReaderService templateFrom, + final ServiceTemplate templateTo) { + super(templateFrom, templateTo); + } + + //used for tests purposes + PnfdNodeTemplateTransformationEngine(final ServiceTemplateReaderService templateFrom, + final ServiceTemplate templateTo, + final String descriptorResourcePath) { + super(templateFrom, templateTo, descriptorResourcePath); + } + + /** + * Runs the transformation process. + */ + public void transform() { + readDefinition(); + initializeTopologyTemplate(); + executeTransformations(); + } + + /** + * Initializes the topology template and its node template set. + */ + private void initializeTopologyTemplate() { + TopologyTemplate topologyTemplate = templateTo.getTopology_template(); + if (topologyTemplate == null) { + topologyTemplate = new TopologyTemplate(); + templateTo.setTopology_template(topologyTemplate); + } + if (topologyTemplate.getNode_templates() == null) { + topologyTemplate.setNode_templates(new HashMap<>()); + } + } + + + /** + * Execute all transformations specified in the descriptor. + */ + @Override + protected void executeTransformations() { + final Set transformationSet = transformationDescription.getTransformationSet(); + if (CollectionUtils.isEmpty(transformationSet)) { + return; + } + transformationGroupByBlockMap = transformationSet.stream() + .filter(Transformation::isValid) + .collect(Collectors.groupingBy(Transformation::getBlock)); + executeCustomTypeTransformations(); + final Map inputsToConvertMap = executeNodeTemplateTransformations(); + executeGetInputFunctionTransformations(inputsToConvertMap); + } + + /** + * Parses all topology_template node_template. + * @return + * A map containing any input that was called with a get_input TOSCA function and its getInputFunction + * transformation name + */ + private Map executeNodeTemplateTransformations() { + final List transformationList = transformationGroupByBlockMap + .get(TransformationBlock.NODE_TEMPLATE); + if (CollectionUtils.isEmpty(transformationList)) { + return Collections.emptyMap(); + } + + final Map inputsToConvertMap = new HashMap<>(); + transformationList.forEach(transformation -> + PnfdBlockParserFactory.getInstance().get(transformation).ifPresent(pnfParser -> { + pnfParser.parse(templateFrom, templateTo); + if (pnfParser.getInputAndTransformationNameMap().isPresent()) { + inputsToConvertMap.putAll(pnfParser.getInputAndTransformationNameMap().get()); + } + })); + return inputsToConvertMap; + } + + /** + * Parses all topology_template inputs called with a get_input TOSCA function. + * @param inputsToConvertMap A map containing the topology_template input name and its conversion definition name + */ + private void executeGetInputFunctionTransformations(final Map inputsToConvertMap) { + final List transformationListOfGetInputFunction = transformationGroupByBlockMap + .get(TransformationBlock.GET_INPUT_FUNCTION); + + if(MapUtils.isEmpty(inputsToConvertMap) || CollectionUtils.isEmpty(transformationListOfGetInputFunction)) { + return; + } + + final Map> transformationByName = transformationListOfGetInputFunction.stream() + .collect(Collectors.groupingBy(Transformation::getName)); + + inputsToConvertMap.forEach((inputName, transformationName) -> { + final List transformationList = transformationByName.get(transformationName); + if (!CollectionUtils.isEmpty(transformationList)) { + final Transformation transformation = transformationList.stream() + .findFirst().orElse(null); + if (transformation != null) { + final Map conversionQueryMap = new HashMap<>(); + conversionQueryMap.put(inputName, null); + transformation.setConversionQuery( + ConversionQueryYamlParser.parse(conversionQueryMap).orElse(null) + ); + PnfdBlockParserFactory.getInstance().get(transformation) + .ifPresent(pnfParser -> pnfParser.parse(templateFrom, templateTo)); + } + } + }); + } + + /** + * Parses a Customized Node Type that extend from a valid ONAP NodeType. + */ + private void executeCustomTypeTransformations() { + final List transformationList = transformationGroupByBlockMap + .get((TransformationBlock.CUSTOM_NODE_TYPE)); + if (CollectionUtils.isEmpty(transformationList)) { + return; + } + 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 transformationSet = transformationDescription.getTransformationSet(); + if (CollectionUtils.isEmpty(transformationSet)) { + return; + } + final Set 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) conversionMap)) + .map(conversionMap -> TransformationYamlParser.parse((Map) 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/PnfdTransformationEngine.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdTransformationEngine.java deleted file mode 100644 index a2365b4f8a..0000000000 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdTransformationEngine.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * ============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.InputStream; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.collections.MapUtils; -import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; -import org.onap.sdc.tosca.datatypes.model.TopologyTemplate; -import org.openecomp.core.converter.ServiceTemplateReaderService; -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. - */ -public class PnfdTransformationEngine { - - 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> transformationGroupByBlockMap; - private final String descriptorResourcePath; - - public PnfdTransformationEngine(final ServiceTemplateReaderService templateFrom, final ServiceTemplate templateTo) { - this(templateFrom, templateTo, "pnfdTransformationTemplate/model-driven-conversion.yaml"); - } - - //used for tests purposes - PnfdTransformationEngine(final ServiceTemplateReaderService templateFrom, final ServiceTemplate templateTo, - final String descriptorResourcePath) { - this.templateFrom = templateFrom; - this.templateTo = templateTo; - this.descriptorResourcePath = descriptorResourcePath; - } - - /** - * Runs the transformation process. - */ - public void transform() { - readDefinition(); - initializeTopologyTemplate(); - executeTransformations(); - } - - /** - * Initializes the topology template and its node template set. - */ - private void initializeTopologyTemplate() { - TopologyTemplate topologyTemplate = templateTo.getTopology_template(); - if (topologyTemplate == null) { - topologyTemplate = new TopologyTemplate(); - templateTo.setTopology_template(topologyTemplate); - } - if (topologyTemplate.getNode_templates() == null) { - topologyTemplate.setNode_templates(new HashMap<>()); - } - } - - /** - * Reads the transformation description yaml file. - */ - private void readDefinition() { - transformationDescription = pnfdTransformationDescriptorReader.parse(getDefinitionFileInputStream()); - } - - /** - * Execute all transformations specified in the descriptor. - */ - private void executeTransformations() { - final Set transformationSet = transformationDescription.getTransformationSet(); - if (CollectionUtils.isEmpty(transformationSet)) { - return; - } - transformationGroupByBlockMap = transformationSet.stream() - .filter(Transformation::isValid) - .collect(Collectors.groupingBy(Transformation::getBlock)); - final Map inputsToConvertMap = executeNodeTemplateTransformations(); - executeGetInputFunctionTransformations(inputsToConvertMap); - } - - /** - * Parses all topology_template node_template. - * @return - * A map containing any input that was called with a get_input TOSCA function and its getInputFunction - * transformation name - */ - private Map executeNodeTemplateTransformations() { - final List transformationList = transformationGroupByBlockMap - .get(TransformationBlock.NODE_TEMPLATE); - if (CollectionUtils.isEmpty(transformationList)) { - return Collections.emptyMap(); - } - - final Map inputsToConvertMap = new HashMap<>(); - transformationList.forEach(transformation -> - PnfdBlockParserFactory.getInstance().get(transformation).ifPresent(pnfParser -> { - pnfParser.parse(templateFrom, templateTo); - if (pnfParser.getInputAndTransformationNameMap().isPresent()) { - inputsToConvertMap.putAll(pnfParser.getInputAndTransformationNameMap().get()); - } - })); - return inputsToConvertMap; - } - - /** - * Parses all topology_template inputs called with a get_input TOSCA function. - * @param inputsToConvertMap A map containing the topology_template input name and its conversion definition name - */ - private void executeGetInputFunctionTransformations(final Map inputsToConvertMap) { - final List transformationListOfGetInputFunction = transformationGroupByBlockMap - .get(TransformationBlock.GET_INPUT_FUNCTION); - - if(MapUtils.isEmpty(inputsToConvertMap) || CollectionUtils.isEmpty(transformationListOfGetInputFunction)) { - return; - } - - final Map> transformationByName = transformationListOfGetInputFunction.stream() - .collect(Collectors.groupingBy(Transformation::getName)); - - inputsToConvertMap.forEach((inputName, transformationName) -> { - final List transformationList = transformationByName.get(transformationName); - if (!CollectionUtils.isEmpty(transformationList)) { - final Transformation transformation = transformationList.stream() - .findFirst().orElse(null); - if (transformation != null) { - final Map conversionQueryMap = new HashMap<>(); - conversionQueryMap.put(inputName, null); - transformation.setConversionQuery(ConversionQueryYamlParser.parse(conversionQueryMap)); - PnfdBlockParserFactory.getInstance().get(transformation) - .ifPresent(pnfParser -> pnfParser.parse(templateFrom, templateTo)); - } - } - }); - } - - /** - * Gets the transformation definition yaml file path. - * @return The transformation definition yaml path. - */ - 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; - } - return resourceAsStream; - } -} 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> 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 blockYamlObject) { + if (MapUtils.isEmpty(blockYamlObject)) { + return; + } + final List conversionDefinitionList = transformation.getConversionDefinitionList(); + final Map parsedBlockYamlObject = new HashMap<>(); + final String blockName = blockYamlObject.keySet().iterator().next(); + conversionDefinitionList.stream() + .filter(conversionDefinition -> conversionDefinition.getConversionQuery().isValidAttributeQuery()) + .forEach(conversionDefinition -> { + final Map query = + (Map) conversionDefinition.getConversionQuery().getQuery(); + final Map blockAttributeMap = (Map) blockYamlObject.get(blockName); + final Optional> 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 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> buildParsedBlock(final Map attributeQuery, + final Map 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 mergeYamlObjects(final Map originalMap, + final Map 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> 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 yamlMap = (Map) 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 yamlMap = (Map) 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> 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 rootNodeTypeMap, + final Map 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 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 fetchCustomNodeType() { + final Map nodeTypesMap = templateFrom.getNodeTypes(); + if (MapUtils.isEmpty(nodeTypesMap)) { + return Collections.emptyMap(); + } + final ConversionQuery conversionQuery = transformation.getConversionQuery(); + final Map 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 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 conversionYaml) { + public static Optional parse(final Map 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) 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 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 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) nodeTypeYaml.get(ToscaTagNamesEnum.PROPERTIES.getElementName())); + nodeType.setArtifacts((Map) nodeTypeYaml.get("artifacts")); + nodeType.setMetadata((Map) nodeTypeYaml.get("metadata")); + nodeType.setInterfaces( + (Map) nodeTypeYaml.get(ToscaTagNamesEnum.INTERFACES.getElementName())); + nodeType.setRequirements( + (List>) nodeTypeYaml.get(ToscaTagNamesEnum.REQUIREMENTS.getElementName())); + nodeType.setCapabilities( + (Map) nodeTypeYaml.get(ToscaTagNamesEnum.CAPABILITIES.getElementName())); + nodeType.setAttributes( + (Map) 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> findBlocksToParse() { + final Map nodeTemplateMap = templateFrom.getNodeTemplates(); + final Map customNodeTypeMap = fetchCustomNodeType(); + if (customNodeTypeMap.isEmpty() || MapUtils.isEmpty(nodeTemplateMap)) { + return Collections.emptySet(); + } + return customNodeTypeMap.entrySet().stream() + .map(customNode -> { + final Map 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> buildParsedBlock(final Map attributeQuery, + final Map 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 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 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> buildParsedBlock(final Map attributeQuery, + @Override + protected Set> findBlocksToParse() { + final ConversionQuery conversionQuery = transformation.getConversionQuery(); + final Map 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 map = new HashMap<>(); + map.put(stringObjectEntry.getKey(), stringObjectEntry.getValue()); + return map; + }).collect(Collectors.toSet()); + } + + @Override + protected Optional> buildParsedBlock(final Map attributeQuery, final Map 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> findBlocksToParse() { - final ConversionQuery conversionQuery = transformation.getConversionQuery(); - final Map 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 map = new HashMap<>(); - map.put(stringObjectEntry.getKey(), stringObjectEntry.getValue()); - return map; - }).collect(Collectors.toSet()); - } - @Override - public void write(final String nodeTemplateName, final Map parsedNodeTemplateMap) { + protected void write(final String nodeTemplateName, final Map 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> findBlocksToParse() { + final Map 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 map = new HashMap<>(); + map.put(nodeNamePrefix.concat(nodeEntry.getKey()), nodeEntry.getValue()); + return map; + }).collect(Collectors.toSet()); + } + + @Override + protected Optional> buildParsedBlock(final Map attributeQuery, + final Map 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 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 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 transformationYaml) { + public static Optional parse(final Map transformationYaml) { final Transformation transformation = new Transformation(); - transformation.setName((String) transformationYaml.get(NAME.getName())); - transformation.setDescription((String) transformationYaml.get(DESCRIPTION.getName())); + final Optional 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 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 readProperties(final Map transformationYaml) { + final Map propertyMap = (Map) transformationYaml.get(PROPERTIES.getName()); + if (MapUtils.isEmpty(propertyMap)) { + return Collections.emptySet(); + } + + final Set 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 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 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 transformationQuery = new HashMap<>(); + transformationQuery.put(ToscaTagNamesEnum.DERIVED_FROM.getElementName(), from); + transformationReference.setConversionQuery(new ConversionQuery(transformationQuery)); + + final List conversionDefinitionList = new ArrayList<>(); + final HashMap 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 parseConversions(final Map conversionYaml) { @@ -73,8 +173,18 @@ public class TransformationYamlParser { } return conversionList.stream() - .map(conversion -> ConversionDefinitionYamlParser.parse((Map) conversion)) + .map(conversion -> ConversionDefinitionYamlParser.parse((Map) conversion).orElse(null)) + .filter(Objects::nonNull) .collect(Collectors.toList()); } + private static Optional parseStringAttribute(final String attribute, final Map 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 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 transformationDescriptorList; try (final Stream 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 -- cgit 1.2.3-korg