Transform custom types for PNFD. 22/96322/5
authoraribeiro <anderson.ribeiro@est.tech>
Wed, 11 Sep 2019 12:50:46 +0000 (13:50 +0100)
committerOfir Sonsino <ofir.sonsino@intl.att.com>
Mon, 4 Nov 2019 13:33:00 +0000 (13:33 +0000)
Transformation of customized Node Types for PNFD.

Issue-ID: SDC-2561
Change-Id: Id3e07edff0e5a8cb134aa12c07878e14c33d1512
Signed-off-by: aribeiro <anderson.ribeiro@est.tech>
36 files changed:
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/PnfdTransformationEngine.java [new file with mode: 0644]
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/ConversionDefinition.java
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/PnfTransformationToken.java
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/Transformation.java
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/TransformationBlock.java
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/TransformationProperty.java [new file with mode: 0644]
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/TransformationPropertyType.java [new file with mode: 0644]
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/AbstractPnfdTransformationEngine.java [new file with mode: 0644]
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdNodeTemplateTransformationEngine.java [moved from openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdTransformationEngine.java with 72% similarity]
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdNodeTypeTransformationEngine.java [new file with mode: 0644]
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdTransformationDescriptorReader.java
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/factory/PnfdBlockParserFactory.java
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/AbstractPnfdBlockParser.java [moved from openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/parser/AbstractPnfdBlockParser.java with 69% similarity]
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionDefinitionYamlParser.java
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionQueryYamlParser.java
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 with mode: 0644]
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 with mode: 0644]
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdInputBlockParser.java
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdNodeTemplateBlockParser.java
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 with mode: 0644]
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/TransformationYamlParser.java
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolModelDrivenConverterPnf.java
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/resources/pnfdTransformationTemplate/model-driven-conversion.yaml
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfTransformationEngineParameterizedTest.java
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfTransformationEngineTest.java
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionDefinitionYamlParserTest.java
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/model-driven-conversion.yaml [deleted file]
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withCustomType.yaml [new file with mode: 0644]
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withCustomTypeDerivedFromMultiple.yaml [new file with mode: 0644]
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_with_Invalid_CustomType.yaml [new file with mode: 0644]
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_with_Multiple_CustomType.yaml [new file with mode: 0644]
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withCustomType.yaml [new file with mode: 0644]
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withCustomTypeDerivedFromMultiple.yaml [new file with mode: 0644]
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_with_Invalid_CustomType.yaml [new file with mode: 0644]
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_with_Multiple_CustomType.yaml [new file with mode: 0644]

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 (file)
index 0000000..12949f2
--- /dev/null
@@ -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();
+
+}
index 0406393..fa06ab8 100644 (file)
@@ -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;
+    }
 }
index fab5b44..8866147 100644 (file)
@@ -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;
 
index fa4a933..a3f7ca0 100644 (file)
@@ -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<TransformationProperty> propertySet;
     private ConversionQuery conversionQuery;
     private List<ConversionDefinition> 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 <T> Optional<T> getPropertyValue(final TransformationPropertyType type, Class<T> clazz) {
+        if (CollectionUtils.isEmpty(propertySet)) {
+            return Optional.empty();
+        }
+
+        final Optional<TransformationProperty> 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();
+    }
 }
index 4c897c4..f8a5aee 100644 (file)
 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 (file)
index 0000000..c42917d
--- /dev/null
@@ -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 <T> the type of the property value
+ */
+@Getter
+@AllArgsConstructor
+@EqualsAndHashCode
+public class TransformationProperty<T> {
+
+    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 (file)
index 0000000..eed2519
--- /dev/null
@@ -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<TransformationPropertyType> 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-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 (file)
index 0000000..2391ed6
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation
+ *  ================================================================================
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *  SPDX-License-Identifier: Apache-2.0
+ *  ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.core.converter.impl.pnfd;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Map;
+import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.core.converter.ServiceTemplateReaderService;
+import org.openecomp.core.converter.pnfd.PnfdTransformationEngine;
+import org.openecomp.core.converter.pnfd.model.Transformation;
+import org.openecomp.core.converter.pnfd.model.TransformationBlock;
+import org.openecomp.core.converter.pnfd.model.TransformationDescription;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+
+/**
+ * Engine that manages the PNF Descriptor transformation process.
+ */
+public abstract class AbstractPnfdTransformationEngine implements PnfdTransformationEngine {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(AbstractPnfdTransformationEngine.class);
+
+    protected final ServiceTemplate templateTo;
+    protected final ServiceTemplateReaderService templateFrom;
+    private final PnfdTransformationDescriptorReader pnfdTransformationDescriptorReader =
+        new PnfdTransformationDescriptorReader();
+    protected TransformationDescription transformationDescription;
+    protected Map<TransformationBlock, List<Transformation>> transformationGroupByBlockMap;
+    private final String descriptorResourcePath;
+
+    public AbstractPnfdTransformationEngine(final ServiceTemplateReaderService templateFrom,
+                                            final ServiceTemplate templateTo) {
+        this(templateFrom, templateTo, "pnfdTransformationTemplate/model-driven-conversion.yaml");
+    }
+
+    //used for tests purposes
+    AbstractPnfdTransformationEngine(final ServiceTemplateReaderService templateFrom,
+                                     final ServiceTemplate templateTo,
+                                     final String descriptorResourcePath) {
+        this.templateFrom = templateFrom;
+        this.templateTo = templateTo;
+        this.descriptorResourcePath = descriptorResourcePath;
+    }
+
+    /**
+     * Gets and Reads the transformation description yaml file.
+     */
+    protected void readDefinition() {
+        try (final InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream(descriptorResourcePath)) {
+            if (resourceAsStream  == null) {
+                if (LOGGER.isErrorEnabled()) {
+                    LOGGER.error("Could not find resource '{}'", descriptorResourcePath);
+                }
+                return;
+            }
+            transformationDescription = pnfdTransformationDescriptorReader.parse(resourceAsStream);
+        } catch (final IOException e) {
+            LOGGER.error("Could not find resource '{}'", descriptorResourcePath, e);
+        }
+    }
+
+    /**
+     * Executes all transformations specified in the descriptor.
+     */
+    protected abstract void executeTransformations();
+
+}
@@ -19,7 +19,6 @@
 
 package org.openecomp.core.converter.impl.pnfd;
 
-import java.io.InputStream;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -35,35 +34,22 @@ import org.openecomp.core.converter.impl.pnfd.factory.PnfdBlockParserFactory;
 import org.openecomp.core.converter.impl.pnfd.parser.ConversionQueryYamlParser;
 import org.openecomp.core.converter.pnfd.model.Transformation;
 import org.openecomp.core.converter.pnfd.model.TransformationBlock;
-import org.openecomp.core.converter.pnfd.model.TransformationDescription;
-import org.openecomp.sdc.logging.api.Logger;
-import org.openecomp.sdc.logging.api.LoggerFactory;
 
 /**
- * Engine that manages the PNF Descriptor transformation process.
+ * Engine that manages the PNF Descriptor transformation process for the NodeTemplate block.
  */
-public class PnfdTransformationEngine {
+public class PnfdNodeTemplateTransformationEngine extends AbstractPnfdTransformationEngine {
 
-    private static final Logger LOGGER = LoggerFactory.getLogger(PnfdTransformationEngine.class);
-
-    private final ServiceTemplate templateTo;
-    private final ServiceTemplateReaderService templateFrom;
-    private final PnfdTransformationDescriptorReader pnfdTransformationDescriptorReader =
-        new PnfdTransformationDescriptorReader();
-    private TransformationDescription transformationDescription;
-    private Map<TransformationBlock, List<Transformation>> transformationGroupByBlockMap;
-    private final String descriptorResourcePath;
-
-    public PnfdTransformationEngine(final ServiceTemplateReaderService templateFrom, final ServiceTemplate templateTo) {
-        this(templateFrom, templateTo, "pnfdTransformationTemplate/model-driven-conversion.yaml");
+    public PnfdNodeTemplateTransformationEngine(final ServiceTemplateReaderService templateFrom,
+                                                final ServiceTemplate templateTo) {
+        super(templateFrom, templateTo);
     }
 
     //used for tests purposes
-    PnfdTransformationEngine(final ServiceTemplateReaderService templateFrom, final ServiceTemplate templateTo,
-            final String descriptorResourcePath) {
-        this.templateFrom = templateFrom;
-        this.templateTo = templateTo;
-        this.descriptorResourcePath = descriptorResourcePath;
+    PnfdNodeTemplateTransformationEngine(final ServiceTemplateReaderService templateFrom,
+                                                final ServiceTemplate templateTo,
+                                                final String descriptorResourcePath) {
+        super(templateFrom, templateTo, descriptorResourcePath);
     }
 
     /**
@@ -89,17 +75,12 @@ public class PnfdTransformationEngine {
         }
     }
 
-    /**
-     * Reads the transformation description yaml file.
-     */
-    private void readDefinition() {
-        transformationDescription = pnfdTransformationDescriptorReader.parse(getDefinitionFileInputStream());
-    }
 
     /**
      * Execute all transformations specified in the descriptor.
      */
-    private void executeTransformations() {
+    @Override
+    protected void executeTransformations() {
         final Set<Transformation> transformationSet = transformationDescription.getTransformationSet();
         if (CollectionUtils.isEmpty(transformationSet)) {
             return;
@@ -107,6 +88,7 @@ public class PnfdTransformationEngine {
         transformationGroupByBlockMap = transformationSet.stream()
             .filter(Transformation::isValid)
             .collect(Collectors.groupingBy(Transformation::getBlock));
+        executeCustomTypeTransformations();
         final Map<String, String> inputsToConvertMap = executeNodeTemplateTransformations();
         executeGetInputFunctionTransformations(inputsToConvertMap);
     }
@@ -158,7 +140,9 @@ public class PnfdTransformationEngine {
                 if (transformation != null) {
                     final Map<String, Object> conversionQueryMap = new HashMap<>();
                     conversionQueryMap.put(inputName, null);
-                    transformation.setConversionQuery(ConversionQueryYamlParser.parse(conversionQueryMap));
+                    transformation.setConversionQuery(
+                        ConversionQueryYamlParser.parse(conversionQueryMap).orElse(null)
+                    );
                     PnfdBlockParserFactory.getInstance().get(transformation)
                         .ifPresent(pnfParser -> pnfParser.parse(templateFrom, templateTo));
                 }
@@ -167,17 +151,17 @@ public class PnfdTransformationEngine {
     }
 
     /**
-     * Gets the transformation definition yaml file path.
-     * @return The transformation definition yaml path.
+     * Parses a Customized Node Type that extend from a valid ONAP NodeType.
      */
-    private InputStream getDefinitionFileInputStream() {
-        final InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream(descriptorResourcePath);
-        if (resourceAsStream  == null) {
-            if (LOGGER.isErrorEnabled()) {
-                LOGGER.error(String.format("Could not find resource '%s'", descriptorResourcePath));
-            }
-            return null;
+    private void executeCustomTypeTransformations() {
+        final List<Transformation> transformationList =  transformationGroupByBlockMap
+            .get((TransformationBlock.CUSTOM_NODE_TYPE));
+        if (CollectionUtils.isEmpty(transformationList)) {
+            return;
         }
-        return resourceAsStream;
+        transformationList.forEach(transformation ->
+            PnfdBlockParserFactory.getInstance().get(transformation).ifPresent(pnfdBlockParser ->
+                pnfdBlockParser.parse(templateFrom, templateTo)));
     }
+
 }
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdNodeTypeTransformationEngine.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdNodeTypeTransformationEngine.java
new file mode 100644 (file)
index 0000000..48d06b6
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation
+ *  ================================================================================
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *  SPDX-License-Identifier: Apache-2.0
+ *  ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.core.converter.impl.pnfd;
+
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.commons.collections.CollectionUtils;
+import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.core.converter.ServiceTemplateReaderService;
+import org.openecomp.core.converter.impl.pnfd.factory.PnfdBlockParserFactory;
+import org.openecomp.core.converter.pnfd.model.Transformation;
+import org.openecomp.core.converter.pnfd.model.TransformationBlock;
+
+/**
+ * Engine that manages the PNF Descriptor transformation process for the NodeType block.
+ */
+public class PnfdNodeTypeTransformationEngine extends AbstractPnfdTransformationEngine {
+
+    public PnfdNodeTypeTransformationEngine(final ServiceTemplateReaderService templateFrom,
+                                            final ServiceTemplate templateTo) {
+        super(templateFrom, templateTo);
+    }
+
+    /**
+     * Runs the transformation process.
+     */
+    @Override
+    public void transform() {
+        readDefinition();
+        executeTransformations();
+    }
+
+    /**
+     * Execute all transformations specified in the descriptor.
+     */
+    @Override
+    protected void executeTransformations() {
+        final Set<Transformation> transformationSet = transformationDescription.getTransformationSet();
+        if (CollectionUtils.isEmpty(transformationSet)) {
+            return;
+        }
+        final Set<Transformation> validNodeTypeTransformationSet = transformationSet.stream()
+            .filter(transformation -> transformation.getBlock() == TransformationBlock.NODE_TYPE)
+            .filter(Transformation::isValid)
+            .collect(Collectors.toSet());
+
+        if (CollectionUtils.isEmpty(validNodeTypeTransformationSet)) {
+            return;
+        }
+        validNodeTypeTransformationSet.forEach(transformation ->
+            PnfdBlockParserFactory.getInstance().get(transformation).ifPresent(pnfdBlockParser ->
+                pnfdBlockParser.parse(templateFrom, templateTo)));
+    }
+
+}
index 6ef5caf..d040c93 100644 (file)
@@ -25,6 +25,7 @@ import java.io.InputStream;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 import java.util.stream.Collectors;
 import org.apache.commons.collections.CollectionUtils;
@@ -82,7 +83,8 @@ public class PnfdTransformationDescriptorReader {
         }
 
         return transformationYamlList.stream()
-            .map(conversionMap -> TransformationYamlParser.parse((Map<String, Object>) conversionMap))
+            .map(conversionMap -> TransformationYamlParser.parse((Map<String, Object>) conversionMap).orElse(null))
+            .filter(Objects::nonNull)
             .collect(Collectors.toSet());
     }
 
index 512fdb5..12dd790 100644 (file)
 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));
  *  ============LICENSE_END=========================================================
  */
 
-package org.openecomp.core.converter.pnfd.parser;
+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;
@@ -27,15 +29,19 @@ 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;
@@ -104,8 +110,8 @@ public abstract class AbstractPnfdBlockParser implements PnfdBlockParser {
      * @return the rebuilt original YAML object with the converted attribute
      */
     protected abstract Optional<Map<String, Object>> buildParsedBlock(final Map<String, Object> attributeQuery,
-        final Map<String, Object> fromNodeTemplateAttributeMap,
-        final ConversionDefinition conversionDefinition);
+                                                                      final Map<String, Object> fromNodeTemplateAttributeMap,
+                                                                      final ConversionDefinition conversionDefinition);
 
     /**
      * Merges two YAML objects.
@@ -153,12 +159,11 @@ public abstract class AbstractPnfdBlockParser implements PnfdBlockParser {
     }
 
     /**
-     * Gets the value (input name) of a YAML object representing a TOSCA get_input call: "get_input: <i>value</i>".
-     *
-     * @param yamlObject the YAML object
-     * @return The get_input function value, that represents the input name
+     * Extracts the value from an YAML Object.
+     * @param yamlObject
+     * @return The Object value from the yamlObject parameter.
      */
-    protected String extractGetInputFunctionValue(final Object yamlObject) {
+    protected String extractObjectValue(final Object yamlObject) {
         if (yamlObject instanceof Map) {
             final Map<String, Object> yamlMap = (Map<String, Object>) yamlObject;
             return (String) yamlMap.values().stream().findFirst().orElse(null);
@@ -175,4 +180,47 @@ public abstract class AbstractPnfdBlockParser implements PnfdBlockParser {
         return Optional.empty();
     }
 
+    /**
+     * Finds all the derived node types from the provided node types.
+     *
+     * @param rootNodeTypeMap a map with the root node types to find the derived ones
+     * @param derivedNodeTypeMap a map that will be filled with the derived node types
+     */
+    private void findAllDerivedNodeType(final Map<String, Object> rootNodeTypeMap,
+                                          final Map<String, Object> derivedNodeTypeMap) {
+        templateFrom.getNodeTypes().entrySet().stream()
+            .filter(nodeEntry -> rootNodeTypeMap.containsKey(extractObjectValue(nodeEntry.getValue())))
+            .forEach(nodeEntry -> {
+                if (!derivedNodeTypeMap.containsKey(nodeEntry.getKey())) {
+                    derivedNodeTypeMap.put(nodeEntry.getKey(), nodeEntry.getValue());
+                    final ImmutableMap<String, Object> newRootNodeTypeMap = ImmutableMap
+                        .of(nodeEntry.getKey(), nodeEntry.getValue());
+                    findAllDerivedNodeType(newRootNodeTypeMap, derivedNodeTypeMap);
+                }
+            });
+    }
+
+    /**
+     * Fetches all Custom NodeTypes based on the query result.
+     * @return a map with all custom Node Types that matches with the query result.
+     */
+    protected Map<String, Object> fetchCustomNodeType() {
+        final Map<String, Object> nodeTypesMap = templateFrom.getNodeTypes();
+        if (MapUtils.isEmpty(nodeTypesMap)) {
+            return Collections.emptyMap();
+        }
+        final ConversionQuery conversionQuery = transformation.getConversionQuery();
+        final Map<String, Object> customNodeTypesMap = new HashMap<>();
+        nodeTypesMap.entrySet().stream()
+            .filter(nodeEntry -> PnfdQueryExecutor.find(conversionQuery, nodeEntry.getValue()))
+            .forEach(customNode -> {
+                attributeValueToBeConverted = extractObjectValue(customNode.getValue());
+                customNodeTypesMap.put(customNode.getKey(), customNode.getValue());
+            });
+        final Map<String, Object> childNodeTypeMap = new HashMap<>();
+        findAllDerivedNodeType(customNodeTypesMap, childNodeTypeMap);
+        customNodeTypesMap.putAll(childNodeTypeMap);
+        return customNodeTypesMap;
+    }
+
 }
index 1431852..2ea9f2d 100644 (file)
 package org.openecomp.core.converter.impl.pnfd.parser;
 
 import java.util.Map;
+import java.util.Optional;
 import org.openecomp.core.converter.pnfd.model.ConversionDefinition;
 import org.openecomp.core.converter.pnfd.model.ConversionQuery;
 import org.openecomp.core.converter.pnfd.model.PnfTransformationToken;
 import org.openecomp.core.converter.pnfd.strategy.PnfdConversionStrategy;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
 
 /**
  * Handles YAML from/to {@link ConversionDefinition} conversions
  */
 public class ConversionDefinitionYamlParser {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(ConversionDefinitionYamlParser.class);
+
     private ConversionDefinitionYamlParser() {
 
     }
@@ -40,16 +45,20 @@ public class ConversionDefinitionYamlParser {
      * @return
      *  A new instance of {@link ConversionDefinition}.
      */
-    public static ConversionDefinition parse(final Map<String, Object> conversionYaml) {
+    public static Optional<ConversionDefinition> parse(final Map<String, Object> conversionYaml) {
         final ConversionQuery conversionQuery = ConversionQueryYamlParser
-            .parse(conversionYaml.get(PnfTransformationToken.QUERY.getName()));
+            .parse(conversionYaml.get(PnfTransformationToken.QUERY.getName())).orElse(null);
+        if (conversionQuery == null) {
+            LOGGER.warn("Invalid '{}' for '{}'", PnfTransformationToken.QUERY.getName(), conversionYaml.toString());
+            return Optional.empty();
+        }
         final String toName = (String) conversionYaml.get(PnfTransformationToken.TO_NAME.getName());
         final PnfdConversionStrategy toValue = PnfdConversionStrategyYamlParser
             .parse((Map<String, Object>) conversionYaml.get(PnfTransformationToken.TO_VALUE.getName()))
             .orElse(null);
         final String toGetInput = (String) conversionYaml.get(PnfTransformationToken.TO_GET_INPUT.getName());
 
-        return new ConversionDefinition(conversionQuery, toName, toValue, toGetInput);
+        return Optional.of(new ConversionDefinition(conversionQuery, toName, toValue, toGetInput));
     }
 
 }
index 417262c..374bf37 100644 (file)
@@ -19,6 +19,7 @@
 
 package org.openecomp.core.converter.impl.pnfd.parser;
 
+import java.util.Optional;
 import org.openecomp.core.converter.pnfd.model.ConversionQuery;
 
 /**
@@ -36,7 +37,11 @@ public class ConversionQueryYamlParser {
      * @return
      *  A new instance of {@link ConversionQuery}.
      */
-    public static ConversionQuery parse(final Object conversionYaml) {
-        return new ConversionQuery(conversionYaml);
+    public static Optional<ConversionQuery> parse(final Object conversionYaml) {
+        if (conversionYaml == null) {
+            return Optional.empty();
+        }
+
+        return Optional.of(new ConversionQuery(conversionYaml));
     }
 }
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/NodeTypeYamlParser.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/NodeTypeYamlParser.java
new file mode 100644 (file)
index 0000000..b0b52e0
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation
+ *  ================================================================================
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *  SPDX-License-Identifier: Apache-2.0
+ *  ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.core.converter.impl.pnfd.parser;
+
+import java.util.List;
+import java.util.Map;
+import org.onap.sdc.tosca.datatypes.model.ArtifactDefinition;
+import org.onap.sdc.tosca.datatypes.model.AttributeDefinition;
+import org.onap.sdc.tosca.datatypes.model.CapabilityDefinition;
+import org.onap.sdc.tosca.datatypes.model.NodeType;
+import org.onap.sdc.tosca.datatypes.model.PropertyDefinition;
+import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
+import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum;
+
+/**
+ * Handles YAML from/to {@link NodeType} conversions
+ */
+public class NodeTypeYamlParser {
+
+    private NodeTypeYamlParser() {
+    }
+
+    /**
+     * Parses the given a YAML object to a {@link NodeType} instance.
+     * @param nodeTypeYaml the YAML object representing a TOSCA Node Type
+     * @return A new instance of {@link NodeType}.
+     */
+    @SuppressWarnings("unchecked")
+    public static NodeType parse(final Map<String, Object> nodeTypeYaml) {
+        final NodeType nodeType = new NodeType();
+        nodeType.setDerived_from((String) nodeTypeYaml.get(ToscaTagNamesEnum.DERIVED_FROM.getElementName()));
+        nodeType.setDescription((String) nodeTypeYaml.get(ToscaTagNamesEnum.DESCRIPTION.getElementName()));
+        nodeType.setVersion((String) nodeTypeYaml.get("version"));
+        nodeType.setProperties(
+            (Map<String, PropertyDefinition>) nodeTypeYaml.get(ToscaTagNamesEnum.PROPERTIES.getElementName()));
+        nodeType.setArtifacts((Map<String, ArtifactDefinition>) nodeTypeYaml.get("artifacts"));
+        nodeType.setMetadata((Map<String, String>) nodeTypeYaml.get("metadata"));
+        nodeType.setInterfaces(
+            (Map<String, Object>) nodeTypeYaml.get(ToscaTagNamesEnum.INTERFACES.getElementName()));
+        nodeType.setRequirements(
+            (List<Map<String, RequirementDefinition>>) nodeTypeYaml.get(ToscaTagNamesEnum.REQUIREMENTS.getElementName()));
+        nodeType.setCapabilities(
+            (Map<String, CapabilityDefinition>) nodeTypeYaml.get(ToscaTagNamesEnum.CAPABILITIES.getElementName()));
+        nodeType.setAttributes(
+            (Map<String, AttributeDefinition>) nodeTypeYaml.get(ToscaTagNamesEnum.ATTRIBUTES.getElementName()));
+
+        return nodeType;
+    }
+
+}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdCustomNodeTypeBlockParser.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdCustomNodeTypeBlockParser.java
new file mode 100644 (file)
index 0000000..3efde19
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation
+ *  ================================================================================
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *  SPDX-License-Identifier: Apache-2.0
+ *  ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.core.converter.impl.pnfd.parser;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.commons.collections.MapUtils;
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
+import org.openecomp.core.converter.pnfd.model.ConversionDefinition;
+import org.openecomp.core.converter.pnfd.model.Transformation;
+import org.openecomp.core.converter.pnfd.strategy.PnfdConversionStrategy;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+
+public class PnfdCustomNodeTypeBlockParser extends AbstractPnfdBlockParser {
+
+    public PnfdCustomNodeTypeBlockParser(final Transformation transformation) {
+        super(transformation);
+    }
+
+    @Override
+    protected Set<Map<String, Object>> findBlocksToParse() {
+        final Map<String, Object> nodeTemplateMap = templateFrom.getNodeTemplates();
+        final Map<String, Object> customNodeTypeMap = fetchCustomNodeType();
+        if (customNodeTypeMap.isEmpty() || MapUtils.isEmpty(nodeTemplateMap)) {
+            return Collections.emptySet();
+        }
+        return customNodeTypeMap.entrySet().stream()
+            .map(customNode -> {
+                final Map<String, Object> map = new HashMap<>();
+                nodeTemplateMap.entrySet().stream()
+                    .filter(nodeTemplate ->
+                        extractObjectValue(nodeTemplate.getValue()).equalsIgnoreCase(customNode.getKey()))
+                    .forEach(nodeType -> map.put(nodeType.getKey(), nodeType.getValue()));
+                return map;
+            }).collect(Collectors.toSet());
+    }
+
+    @Override
+    protected Optional<Map<String, Object>> buildParsedBlock(final Map<String, Object> attributeQuery,
+        final Map<String, Object> fromNodeTemplateAttributeMap,
+        final ConversionDefinition conversionDefinition) {
+        //cannot query for more than one attribute
+        if (attributeQuery.keySet().size() > 1) {
+            return Optional.empty();
+        }
+        final String attribute = attributeQuery.keySet().iterator().next();
+        final Object queryValue = attributeQuery.get(attribute);
+        final Map<String, Object> parsedNodeTemplate = new HashMap<>();
+        if (queryValue == null) {
+            final PnfdConversionStrategy pnfdConversionStrategy = conversionDefinition.getPnfdConversionStrategy();
+            final Optional convertedAttribute = pnfdConversionStrategy.convert(attributeValueToBeConverted);
+            if (convertedAttribute.isPresent()) {
+                parsedNodeTemplate.put(conversionDefinition.getToAttributeName(), convertedAttribute.get());
+            }
+        }
+        return parsedNodeTemplate.isEmpty() ? Optional.empty() : Optional.of(parsedNodeTemplate);
+    }
+
+    @Override
+    protected void write(final String nodeTemplateName, final Map<String, Object> parsedTemplateMap) {
+        if (!parsedTemplateMap.isEmpty()) {
+            final NodeTemplate parsedNodeTemplate = NodeTemplateYamlParser.parse(parsedTemplateMap);
+            DataModelUtil.addNodeTemplate(templateTo, nodeTemplateName, parsedNodeTemplate);
+        }
+    }
+
+}
index 4aec8c8..4ce7b2e 100644 (file)
@@ -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;
index 5539840..5d7a604 100644 (file)
@@ -27,12 +27,11 @@ import java.util.Set;
 import java.util.stream.Collectors;
 import org.apache.commons.collections.MapUtils;
 import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
-import org.openecomp.core.converter.pnfd.parser.AbstractPnfdBlockParser;
 import org.openecomp.core.converter.impl.pnfd.PnfdQueryExecutor;
+import org.openecomp.core.converter.impl.pnfd.strategy.CopyConversionStrategy;
 import org.openecomp.core.converter.pnfd.model.ConversionDefinition;
 import org.openecomp.core.converter.pnfd.model.ConversionQuery;
 import org.openecomp.core.converter.pnfd.model.Transformation;
-import org.openecomp.core.converter.impl.pnfd.strategy.CopyConversionStrategy;
 import org.openecomp.core.converter.pnfd.strategy.PnfdConversionStrategy;
 import org.openecomp.sdc.tosca.services.DataModelUtil;
 
@@ -44,7 +43,25 @@ public class PnfdNodeTemplateBlockParser extends AbstractPnfdBlockParser {
         super(transformation);
     }
 
-    public Optional<Map<String, Object>> buildParsedBlock(final Map<String, Object> attributeQuery,
+    @Override
+    protected Set<Map<String, Object>> findBlocksToParse() {
+        final ConversionQuery conversionQuery = transformation.getConversionQuery();
+        final Map<String, Object> nodeTemplateMap = templateFrom.getNodeTemplates();
+        if (MapUtils.isEmpty(nodeTemplateMap)) {
+            return Collections.emptySet();
+        }
+
+        return nodeTemplateMap.entrySet().stream()
+            .filter(mapEntry -> PnfdQueryExecutor.find(conversionQuery, mapEntry.getValue()))
+            .map(stringObjectEntry -> {
+                final Map<String, Object> map = new HashMap<>();
+                map.put(stringObjectEntry.getKey(), stringObjectEntry.getValue());
+                return map;
+            }).collect(Collectors.toSet());
+    }
+
+    @Override
+    protected Optional<Map<String, Object>> buildParsedBlock(final Map<String, Object> attributeQuery,
         final Map<String, Object> fromNodeTemplateAttributeMap,
         final ConversionDefinition conversionDefinition) {
         //cannot query for more than one attribute
@@ -57,7 +74,7 @@ public class PnfdNodeTemplateBlockParser extends AbstractPnfdBlockParser {
         if (queryValue == null) {
             PnfdConversionStrategy pnfdConversionStrategy = conversionDefinition.getPnfdConversionStrategy();
             if (isGetInputFunction(attributeValueToConvert)) {
-                inputNameToConvertMap.put(extractGetInputFunctionValue(attributeValueToConvert)
+                inputNameToConvertMap.put(extractObjectValue(attributeValueToConvert)
                     , conversionDefinition.getToGetInput()
                 );
                 pnfdConversionStrategy = new CopyConversionStrategy();
@@ -83,24 +100,8 @@ public class PnfdNodeTemplateBlockParser extends AbstractPnfdBlockParser {
         }
     }
 
-    protected Set<Map<String, Object>> findBlocksToParse() {
-        final ConversionQuery conversionQuery = transformation.getConversionQuery();
-        final Map<String, Object> nodeTemplateMap = templateFrom.getNodeTemplates();
-        if (MapUtils.isEmpty(nodeTemplateMap)) {
-            return Collections.emptySet();
-        }
-
-        return nodeTemplateMap.entrySet().stream()
-            .filter(mapEntry -> PnfdQueryExecutor.find(conversionQuery, mapEntry.getValue()))
-            .map(stringObjectEntry -> {
-                final Map<String, Object> map = new HashMap<>();
-                map.put(stringObjectEntry.getKey(), stringObjectEntry.getValue());
-                return map;
-            }).collect(Collectors.toSet());
-    }
-
     @Override
-    public void write(final String nodeTemplateName, final Map<String, Object> parsedNodeTemplateMap) {
+    protected void write(final String nodeTemplateName, final Map<String, Object> parsedNodeTemplateMap) {
         if (!parsedNodeTemplateMap.isEmpty()) {
             final NodeTemplate parsedNodeTemplate = NodeTemplateYamlParser.parse(parsedNodeTemplateMap);
             DataModelUtil.addNodeTemplate(templateTo, nodeTemplateName, parsedNodeTemplate);
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdNodeTypeBlockParser.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdNodeTypeBlockParser.java
new file mode 100644 (file)
index 0000000..386bbfb
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation
+ *  ================================================================================
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *  SPDX-License-Identifier: Apache-2.0
+ *  ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.core.converter.impl.pnfd.parser;
+
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.DERIVED_FROM;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.onap.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.core.converter.pnfd.model.ConversionDefinition;
+import org.openecomp.core.converter.pnfd.model.Transformation;
+import org.openecomp.core.converter.pnfd.model.TransformationPropertyType;
+import org.openecomp.core.converter.pnfd.strategy.PnfdConversionStrategy;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+
+public class PnfdNodeTypeBlockParser extends AbstractPnfdBlockParser {
+
+    public PnfdNodeTypeBlockParser(final Transformation transformation) {
+        super(transformation);
+    }
+
+    @Override
+    protected Set<Map<String, Object>> findBlocksToParse() {
+        final Map<String, Object> customNodeTypeMap = fetchCustomNodeType();
+        if (customNodeTypeMap.isEmpty()) {
+            return Collections.emptySet();
+        }
+
+        final String nodeNamePrefix =
+            transformation.getPropertyValue(TransformationPropertyType.NODE_NAME_PREFIX, String.class)
+                .orElse("");
+
+        return customNodeTypeMap.entrySet().parallelStream()
+            .map(nodeEntry -> {
+                final Map<String, Object> map = new HashMap<>();
+                map.put(nodeNamePrefix.concat(nodeEntry.getKey()), nodeEntry.getValue());
+                return map;
+            }).collect(Collectors.toSet());
+    }
+
+    @Override
+    protected Optional<Map<String, Object>> buildParsedBlock(final Map<String, Object> attributeQuery,
+                                                             final Map<String, Object> fromNodeTemplateAttributeMap,
+                                                             final ConversionDefinition conversionDefinition) {
+        //cannot query for more than one attribute
+        if (attributeQuery.keySet().size() > 1) {
+            return Optional.empty();
+        }
+        final String attribute = attributeQuery.keySet().iterator().next();
+        final Object queryValue = attributeQuery.get(attribute);
+        final Object attributeValueToConvert = fromNodeTemplateAttributeMap.get(attribute);
+        final Map<String, Object> parsedNodeTemplate = new HashMap<>();
+        if (queryValue == null) {
+            PnfdConversionStrategy pnfdConversionStrategy = conversionDefinition.getPnfdConversionStrategy();
+            final Optional convertedAttribute = pnfdConversionStrategy
+                .convert(DERIVED_FROM.getElementName()
+                    .equalsIgnoreCase(attribute) ? attributeValueToBeConverted : attributeValueToConvert);
+            if (convertedAttribute.isPresent()) {
+                parsedNodeTemplate.put(conversionDefinition.getToAttributeName(), convertedAttribute.get());
+            }
+        }
+        return parsedNodeTemplate.isEmpty() ? Optional.empty() : Optional.of(parsedNodeTemplate);
+    }
+
+    @Override
+    protected void write(final String blockName, final Map<String, Object> parsedBlockYamlObject) {
+        if (!parsedBlockYamlObject.isEmpty()) {
+            final NodeType nodeTypeYamlParser = NodeTypeYamlParser.parse(parsedBlockYamlObject);
+            DataModelUtil.addNodeType(templateTo, blockName, nodeTypeYamlParser);
+        }
+    }
+
+}
index 16d0670..6ad04b0 100644 (file)
@@ -21,24 +21,43 @@ package org.openecomp.core.converter.impl.pnfd.parser;
 
 import static org.openecomp.core.converter.pnfd.model.PnfTransformationToken.CONVERSIONS;
 import static org.openecomp.core.converter.pnfd.model.PnfTransformationToken.DESCRIPTION;
+import static org.openecomp.core.converter.pnfd.model.PnfTransformationToken.FROM;
 import static org.openecomp.core.converter.pnfd.model.PnfTransformationToken.NAME;
+import static org.openecomp.core.converter.pnfd.model.PnfTransformationToken.PROPERTIES;
 import static org.openecomp.core.converter.pnfd.model.PnfTransformationToken.QUERY;
+import static org.openecomp.core.converter.pnfd.model.PnfTransformationToken.TO;
 import static org.openecomp.core.converter.pnfd.model.PnfTransformationToken.TRANSFORMATION_FOR;
 
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
 import java.util.stream.Collectors;
 import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
+import org.openecomp.core.converter.impl.pnfd.strategy.ReplaceConversionStrategy;
 import org.openecomp.core.converter.pnfd.model.ConversionDefinition;
+import org.openecomp.core.converter.pnfd.model.ConversionQuery;
 import org.openecomp.core.converter.pnfd.model.Transformation;
 import org.openecomp.core.converter.pnfd.model.TransformationBlock;
+import org.openecomp.core.converter.pnfd.model.TransformationProperty;
+import org.openecomp.core.converter.pnfd.model.TransformationPropertyType;
+import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
 
 /**
  * Handles YAML from/to {@link Transformation} conversions
  */
 public class TransformationYamlParser {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(TransformationYamlParser.class);
+
     private TransformationYamlParser() {
 
     }
@@ -49,20 +68,101 @@ public class TransformationYamlParser {
      * @return
      *  A new instance of {@link Transformation}.
      */
-    public static Transformation parse(final Map<String, Object> transformationYaml) {
+    public static Optional<Transformation> parse(final Map<String, Object> transformationYaml) {
         final Transformation transformation = new Transformation();
-        transformation.setName((String) transformationYaml.get(NAME.getName()));
-        transformation.setDescription((String) transformationYaml.get(DESCRIPTION.getName()));
+        final Optional<String> name = parseStringAttribute(NAME.getName(), transformationYaml);
+        if (!name.isPresent()) {
+            LOGGER.warn("Invalid '{}' value in transformation '{}'", NAME.getName(), transformationYaml.toString());
+        }
+        transformation.setName(name.orElse(null));
+        transformation.setDescription(parseStringAttribute(DESCRIPTION.getName(), transformationYaml).orElse(null));
+        transformation.setPropertySet(readProperties(transformationYaml));
+
+        final String block = parseStringAttribute(TRANSFORMATION_FOR.getName(), transformationYaml).orElse(null);
+        final Optional<TransformationBlock> transformationBlockOptional = TransformationBlock.parse(block);
+        if (transformationBlockOptional.isPresent()) {
+            final TransformationBlock transformationBlock = transformationBlockOptional.get();
+            transformation.setBlock(transformationBlock);
+            parseTransformationBlock(transformationBlock, transformation, transformationYaml);
+        } else {
+            LOGGER.warn("Invalid '{}' value in transformation '{}'", TRANSFORMATION_FOR.getName(),
+                transformationYaml.toString());
+        }
+
+        if (transformation.isValid()) {
+            return Optional.of(transformation);
+        }
+
+        return Optional.empty();
+    }
+
+    private static Set<TransformationProperty> readProperties(final Map<String, Object> transformationYaml) {
+        final Map<String, Object> propertyMap = (Map<String, Object>) transformationYaml.get(PROPERTIES.getName());
+        if (MapUtils.isEmpty(propertyMap)) {
+            return Collections.emptySet();
+        }
+
+        final Set<TransformationProperty> propertySet = new HashSet<>();
+
+        propertyMap.forEach((key, value) -> {
+            final TransformationPropertyType transformationPropertyType = TransformationPropertyType.parse(key)
+                .orElse(null);
+
+            if(transformationPropertyType != null) {
+                if (value instanceof String) {
+                    propertySet.add(new TransformationProperty<>(transformationPropertyType, (String) value));
+                } else if (value instanceof Boolean) {
+                    propertySet.add(new TransformationProperty<>(transformationPropertyType, (Boolean) value));
+                } else if (value instanceof Integer) {
+                    propertySet.add(new TransformationProperty<>(transformationPropertyType, (Integer) value));
+                } else {
+                    propertySet.add(new TransformationProperty<>(transformationPropertyType, value));
+                }
+            }
+        });
 
-        final String block = (String) transformationYaml.get(TRANSFORMATION_FOR.getName());
-        transformation.setBlock(TransformationBlock.parse(block).orElse(null));
+        return propertySet;
+    }
+
+    private static void parseTransformationBlock(final TransformationBlock transformationBlock,
+                                                 final Transformation transformationReference,
+                                                 final Map<String, Object> transformationYaml) {
+        if (transformationBlock == TransformationBlock.CUSTOM_NODE_TYPE) {
+            parseCustomNodeTypeBlock(transformationReference, transformationYaml);
+            return;
+        }
 
-        transformation.setConversionQuery(
-            ConversionQueryYamlParser.parse(transformationYaml.get(QUERY.getName()))
-        );
-        transformation.setConversionDefinitionList(parseConversions(transformationYaml));
+        ConversionQueryYamlParser.parse(transformationYaml.get(QUERY.getName()))
+            .ifPresent(transformationReference::setConversionQuery);
 
-        return transformation;
+        transformationReference.setConversionDefinitionList(parseConversions(transformationYaml));
+    }
+
+    private static void parseCustomNodeTypeBlock(final Transformation transformationReference,
+                                                 final Map<String, Object> transformationYaml) {
+        final Object fromAttribute = transformationYaml.get(FROM.getName());
+        if (!(fromAttribute instanceof String)) {
+            return;
+        }
+        final String from = parseStringAttribute(FROM.getName(), transformationYaml).orElse(null);
+
+        final Object toAttribute = transformationYaml.get(TO.getName());
+        if (!(toAttribute instanceof String)) {
+            return;
+        }
+        final String to = parseStringAttribute(TO.getName(), transformationYaml).orElse(null);
+
+        final HashMap<String, String> transformationQuery = new HashMap<>();
+        transformationQuery.put(ToscaTagNamesEnum.DERIVED_FROM.getElementName(), from);
+        transformationReference.setConversionQuery(new ConversionQuery(transformationQuery));
+
+        final List<ConversionDefinition> conversionDefinitionList = new ArrayList<>();
+        final HashMap<String, String> conversionDefinitionQuery = new HashMap<>();
+        conversionDefinitionQuery.put(ToscaTagNamesEnum.TYPE.getElementName(), null);
+        ConversionDefinition conversionDefinition = new ConversionDefinition(new ConversionQuery(conversionDefinitionQuery)
+            , ToscaTagNamesEnum.TYPE.getElementName(), new ReplaceConversionStrategy(from, to));
+        conversionDefinitionList.add(conversionDefinition);
+        transformationReference.setConversionDefinitionList(conversionDefinitionList);
     }
 
     private static List<ConversionDefinition> parseConversions(final Map<String, Object> conversionYaml) {
@@ -73,8 +173,18 @@ public class TransformationYamlParser {
         }
 
         return conversionList.stream()
-            .map(conversion -> ConversionDefinitionYamlParser.parse((Map<String, Object>) conversion))
+            .map(conversion -> ConversionDefinitionYamlParser.parse((Map<String, Object>) conversion).orElse(null))
+            .filter(Objects::nonNull)
             .collect(Collectors.toList());
     }
 
+    private static Optional<String> parseStringAttribute(final String attribute, final Map<String, Object> transformationYaml) {
+        try {
+            return Optional.of((String) transformationYaml.get(attribute));
+        } catch (final Exception ignore) {
+            LOGGER.warn("Could not parse the String '{}' in transformation '{}'", attribute, transformationYaml.toString());
+            return Optional.empty();
+        }
+    }
+
 }
index fa1de67..b7ba56e 100644 (file)
@@ -212,7 +212,7 @@ public abstract class AbstractToscaConverter implements ToscaConverter {
         serviceTemplate.setMetadata(finalMetadata);
     }
 
-    private void convertNodeTypes(ServiceTemplate serviceTemplate, ServiceTemplateReaderService readerService) {
+    protected void convertNodeTypes(ServiceTemplate serviceTemplate, ServiceTemplateReaderService readerService) {
         Map<String, Object> nodeTypes = readerService.getNodeTypes();
         if (MapUtils.isEmpty(nodeTypes)) {
             return;
index ee2c406..b861980 100644 (file)
@@ -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
index c58a23b..9d2a899 100644 (file)
@@ -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
index e2cbc14..a343e1a 100644 (file)
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertEquals;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URISyntaxException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
@@ -40,6 +41,7 @@ import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
 import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
 import org.onap.sdc.tosca.services.YamlUtil;
 import org.openecomp.core.converter.ServiceTemplateReaderService;
+import org.openecomp.core.converter.pnfd.PnfdTransformationEngine;
 import org.openecomp.core.impl.services.ServiceTemplateReaderServiceImpl;
 
 @RunWith(Parameterized.class)
@@ -72,7 +74,7 @@ public class PnfTransformationEngineParameterizedTest {
 
 
     @Parameterized.Parameters(name = "{index}: input: {0}, descriptor: {4}, output: {2}")
-    public static Collection input() throws IOException {
+    public static Collection input() throws IOException, URISyntaxException {
         return Files.list(getPathFromClasspath(TEST_CASES_PATH)).map(path -> {
             try {
                 return buildTestCase(path);
@@ -90,7 +92,6 @@ public class PnfTransformationEngineParameterizedTest {
         if (inputFilePath == null) {
             return Collections.emptyList();
         }
-        ;
         final List<Path> transformationDescriptorList;
         try (final Stream<Path> files = Files.walk(testCasePath.resolve(TRANSFORMATION_DESCRIPTOR_FOLDER))) {
             transformationDescriptorList = files.filter(path -> Files.isRegularFile(path))
@@ -130,8 +131,8 @@ public class PnfTransformationEngineParameterizedTest {
         final ServiceTemplateReaderService serviceTemplateReaderService = new ServiceTemplateReaderServiceImpl(descriptor);
         final ServiceTemplate serviceTemplate = new ServiceTemplate();
 
-        final PnfdTransformationEngine pnfdTransformationEngine = new PnfdTransformationEngine(serviceTemplateReaderService, serviceTemplate
-            , transformationDescriptorFilePath.toString());
+        final PnfdTransformationEngine pnfdTransformationEngine = new PnfdNodeTemplateTransformationEngine(
+            serviceTemplateReaderService, serviceTemplate, transformationDescriptorFilePath.toString());
         pnfdTransformationEngine.transform();
 
         final String result = yamlUtil.objectToYaml(serviceTemplate);
@@ -146,7 +147,7 @@ public class PnfTransformationEngineParameterizedTest {
         }
     }
 
-    private static Path getPathFromClasspath(final String location) {
-        return Paths.get(Thread.currentThread().getContextClassLoader().getResource(location).getPath());
+    private static Path getPathFromClasspath(final String location) throws URISyntaxException {
+        return Paths.get(PnfTransformationEngineParameterizedTest.class.getClassLoader().getResource(location).toURI());
     }
 }
\ No newline at end of file
index 280d148..be13d77 100644 (file)
@@ -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);
     }
index 967081b..2326318 100644 (file)
@@ -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 (file)
index 4d15001..0000000
+++ /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 (file)
index 0000000..8fc4339
--- /dev/null
@@ -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 (file)
index 0000000..b3f4ce0
--- /dev/null
@@ -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 (file)
index 0000000..d27fbfd
--- /dev/null
@@ -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 (file)
index 0000000..7a886c4
--- /dev/null
@@ -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 (file)
index 0000000..0013ae0
--- /dev/null
@@ -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 (file)
index 0000000..6092097
--- /dev/null
@@ -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 (file)
index 0000000..3292a94
--- /dev/null
@@ -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 (file)
index 0000000..3fd846b
--- /dev/null
@@ -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