summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl')
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdQueryExecutor.java113
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdTransformationDescriptorReader.java89
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdTransformationEngine.java183
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/factory/PnfdBlockParserFactory.java57
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionDefinitionYamlParser.java55
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionQueryYamlParser.java42
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/NodeTemplateYamlParser.java55
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/ParameterDefinitionYamlParser.java57
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdConversionStrategyYamlParser.java74
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdInputBlockParser.java94
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdNodeTemplateBlockParser.java114
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/TransformationYamlParser.java80
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/strategy/CopyConversionStrategy.java37
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/strategy/ReplaceConversionStrategy.java39
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/strategy/ReplaceInListConversionStrategy.java60
15 files changed, 1149 insertions, 0 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdQueryExecutor.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdQueryExecutor.java
new file mode 100644
index 0000000000..890dedb2a7
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdQueryExecutor.java
@@ -0,0 +1,113 @@
+/*
+ * ============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.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import org.apache.commons.collections.MapUtils;
+import org.openecomp.core.converter.pnfd.exception.QueryOperationNotSupportedException;
+import org.openecomp.core.converter.pnfd.model.ConversionQuery;
+
+/**
+ * Runs YAML queries
+ */
+public class PnfdQueryExecutor {
+
+ private PnfdQueryExecutor() {
+
+ }
+
+ /**
+ * Finds if a YAML object contains the provided YAML query.
+ * @param conversionQuery The query
+ * @param yamlObject The YAML object to be searched
+ * @return
+ * {@code true} if the YAML query structure was found in the YAML object, {@code false} otherwise.
+ */
+ public static boolean find(final ConversionQuery conversionQuery, final Object yamlObject) {
+ return find(conversionQuery.getQuery(), yamlObject);
+ }
+
+ /**
+ * Recursive structure combined with {@link #findMap(Map, Map)} to find if a YAML object contains the provided YAML query.
+ * Compares the objects if it's a scalar value, otherwise go further in the YAML hierarchical structure
+ * calling the {@link #findMap(Map, Map)}.
+ * @param query The current query
+ * @param yamlObject The current YAML object to be searched
+ * @return
+ * {@code true} if the YAML query structure was found in the YAML object, {@code false} otherwise.
+ */
+ private static boolean find(final Object query, final Object yamlObject) {
+ if (query == null) {
+ return true;
+ }
+
+ checkSupportedQueryType(query);
+
+ if (query instanceof String) {
+ return query.equals(yamlObject);
+ }
+ if (query instanceof Map) {
+ return findMap((Map) query, (Map) yamlObject);
+ }
+ return false;
+ }
+
+ /**
+ * Recursive structure combined with {@link #find(Object, Object)} to find if a YAML object contains the provided YAML query. *
+ * @param query The query current object
+ * @param yamlObject The YAML object to be searched
+ * @return
+ * {@code true} if the YAML query structure was found in the YAML object, {@code false} otherwise.
+ */
+ private static boolean findMap(final Map query, final Map yamlObject) {
+ if (MapUtils.isEmpty(query) || MapUtils.isEmpty(yamlObject)) {
+ return false;
+ }
+
+ if (!yamlObject.keySet().containsAll(query.keySet())) {
+ return false;
+ }
+
+ return query.entrySet().parallelStream().allMatch(queryEntryObj -> {
+ final Entry queryEntry = (Entry) queryEntryObj;
+ return find(queryEntry.getValue(), yamlObject.get(queryEntry.getKey()));
+ });
+ }
+
+ /**
+ * Checks the supported types for a query.
+ * @param query the query to check
+ */
+ private static void checkSupportedQueryType(final Object query) {
+ if (query instanceof String || query instanceof Map) {
+ return;
+ }
+ if (query instanceof List || query instanceof Set) {
+ throw new QueryOperationNotSupportedException("Yaml list query is not supported yet");
+ }
+ throw new QueryOperationNotSupportedException(
+ String.format("Yaml query operation for '%s' is not supported yet", query.getClass())
+ );
+ }
+
+}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdTransformationDescriptorReader.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdTransformationDescriptorReader.java
new file mode 100644
index 0000000000..6ef5caf21b
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdTransformationDescriptorReader.java
@@ -0,0 +1,89 @@
+/*
+ * ============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.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.commons.collections.CollectionUtils;
+import org.onap.sdc.tosca.services.YamlUtil;
+import org.openecomp.core.converter.impl.pnfd.parser.TransformationYamlParser;
+import org.openecomp.core.converter.pnfd.model.Transformation;
+import org.openecomp.core.converter.pnfd.model.TransformationDescription;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+
+/**
+ * Reads the PNF Transformation Description
+ */
+public class PnfdTransformationDescriptorReader {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(PnfdTransformationDescriptorReader.class);
+
+ /**
+ * Parse the transformation description to {@link TransformationDescription} class.
+ * @return
+ * The {@link TransformationDescription} instance.
+ */
+ public TransformationDescription parse(final InputStream transformationDescriptionInputStream) {
+ final List<Object> transformationList = readDescriptionYaml(transformationDescriptionInputStream);
+ final Set<Transformation> transformationSet = parseTransformationList(transformationList);
+
+ return new TransformationDescription(transformationSet);
+ }
+
+ /**
+ * Reads the description file that has the required YAML format.
+ * @return
+ * The yaml parsed to Object
+ */
+ private List<Object> readDescriptionYaml(final InputStream transformationDescriptionPath) {
+ try (final InputStream fileInputStream = transformationDescriptionPath) {
+ return YamlUtil.yamlToList(fileInputStream).orElse(Collections.emptyList());
+ } catch (final FileNotFoundException e) {
+ LOGGER.error("Could not find the resource on path.", e);
+ } catch (final IOException e) {
+ LOGGER.error("Could not load resource.", e);
+ }
+ return Collections.emptyList();
+ }
+
+ /**
+ * Parse the transformation list represented in a YAML object to {@link Transformation}.
+ * @param transformationYamlList the YAML object read from the transformation description file
+ * @return
+ * The set of transformations represented as {@link Transformation} class
+ */
+ private Set<Transformation> parseTransformationList(final List<Object> transformationYamlList) {
+ if (CollectionUtils.isEmpty(transformationYamlList)) {
+ return Collections.emptySet();
+ }
+
+ return transformationYamlList.stream()
+ .map(conversionMap -> TransformationYamlParser.parse((Map<String, Object>) conversionMap))
+ .collect(Collectors.toSet());
+ }
+
+}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdTransformationEngine.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdTransformationEngine.java
new file mode 100644
index 0000000000..a2365b4f8a
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/PnfdTransformationEngine.java
@@ -0,0 +1,183 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.core.converter.impl.pnfd;
+
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
+import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.onap.sdc.tosca.datatypes.model.TopologyTemplate;
+import org.openecomp.core.converter.ServiceTemplateReaderService;
+import org.openecomp.core.converter.impl.pnfd.factory.PnfdBlockParserFactory;
+import org.openecomp.core.converter.impl.pnfd.parser.ConversionQueryYamlParser;
+import org.openecomp.core.converter.pnfd.model.Transformation;
+import org.openecomp.core.converter.pnfd.model.TransformationBlock;
+import org.openecomp.core.converter.pnfd.model.TransformationDescription;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+
+/**
+ * Engine that manages the PNF Descriptor transformation process.
+ */
+public class PnfdTransformationEngine {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(PnfdTransformationEngine.class);
+
+ private final ServiceTemplate templateTo;
+ private final ServiceTemplateReaderService templateFrom;
+ private final PnfdTransformationDescriptorReader pnfdTransformationDescriptorReader =
+ new PnfdTransformationDescriptorReader();
+ private TransformationDescription transformationDescription;
+ private Map<TransformationBlock, List<Transformation>> transformationGroupByBlockMap;
+ private final String descriptorResourcePath;
+
+ public PnfdTransformationEngine(final ServiceTemplateReaderService templateFrom, final ServiceTemplate templateTo) {
+ this(templateFrom, templateTo, "pnfdTransformationTemplate/model-driven-conversion.yaml");
+ }
+
+ //used for tests purposes
+ PnfdTransformationEngine(final ServiceTemplateReaderService templateFrom, final ServiceTemplate templateTo,
+ final String descriptorResourcePath) {
+ this.templateFrom = templateFrom;
+ this.templateTo = templateTo;
+ this.descriptorResourcePath = descriptorResourcePath;
+ }
+
+ /**
+ * Runs the transformation process.
+ */
+ public void transform() {
+ readDefinition();
+ initializeTopologyTemplate();
+ executeTransformations();
+ }
+
+ /**
+ * Initializes the topology template and its node template set.
+ */
+ private void initializeTopologyTemplate() {
+ TopologyTemplate topologyTemplate = templateTo.getTopology_template();
+ if (topologyTemplate == null) {
+ topologyTemplate = new TopologyTemplate();
+ templateTo.setTopology_template(topologyTemplate);
+ }
+ if (topologyTemplate.getNode_templates() == null) {
+ topologyTemplate.setNode_templates(new HashMap<>());
+ }
+ }
+
+ /**
+ * Reads the transformation description yaml file.
+ */
+ private void readDefinition() {
+ transformationDescription = pnfdTransformationDescriptorReader.parse(getDefinitionFileInputStream());
+ }
+
+ /**
+ * Execute all transformations specified in the descriptor.
+ */
+ private void executeTransformations() {
+ final Set<Transformation> transformationSet = transformationDescription.getTransformationSet();
+ if (CollectionUtils.isEmpty(transformationSet)) {
+ return;
+ }
+ transformationGroupByBlockMap = transformationSet.stream()
+ .filter(Transformation::isValid)
+ .collect(Collectors.groupingBy(Transformation::getBlock));
+ final Map<String, String> inputsToConvertMap = executeNodeTemplateTransformations();
+ executeGetInputFunctionTransformations(inputsToConvertMap);
+ }
+
+ /**
+ * Parses all topology_template node_template.
+ * @return
+ * A map containing any input that was called with a get_input TOSCA function and its getInputFunction
+ * transformation name
+ */
+ private Map<String, String> executeNodeTemplateTransformations() {
+ final List<Transformation> transformationList = transformationGroupByBlockMap
+ .get(TransformationBlock.NODE_TEMPLATE);
+ if (CollectionUtils.isEmpty(transformationList)) {
+ return Collections.emptyMap();
+ }
+
+ final Map<String, String> inputsToConvertMap = new HashMap<>();
+ transformationList.forEach(transformation ->
+ PnfdBlockParserFactory.getInstance().get(transformation).ifPresent(pnfParser -> {
+ pnfParser.parse(templateFrom, templateTo);
+ if (pnfParser.getInputAndTransformationNameMap().isPresent()) {
+ inputsToConvertMap.putAll(pnfParser.getInputAndTransformationNameMap().get());
+ }
+ }));
+ return inputsToConvertMap;
+ }
+
+ /**
+ * Parses all topology_template inputs called with a get_input TOSCA function.
+ * @param inputsToConvertMap A map containing the topology_template input name and its conversion definition name
+ */
+ private void executeGetInputFunctionTransformations(final Map<String, String> inputsToConvertMap) {
+ final List<Transformation> transformationListOfGetInputFunction = transformationGroupByBlockMap
+ .get(TransformationBlock.GET_INPUT_FUNCTION);
+
+ if(MapUtils.isEmpty(inputsToConvertMap) || CollectionUtils.isEmpty(transformationListOfGetInputFunction)) {
+ return;
+ }
+
+ final Map<String, List<Transformation>> transformationByName = transformationListOfGetInputFunction.stream()
+ .collect(Collectors.groupingBy(Transformation::getName));
+
+ inputsToConvertMap.forEach((inputName, transformationName) -> {
+ final List<Transformation> transformationList = transformationByName.get(transformationName);
+ if (!CollectionUtils.isEmpty(transformationList)) {
+ final Transformation transformation = transformationList.stream()
+ .findFirst().orElse(null);
+ if (transformation != null) {
+ final Map<String, Object> conversionQueryMap = new HashMap<>();
+ conversionQueryMap.put(inputName, null);
+ transformation.setConversionQuery(ConversionQueryYamlParser.parse(conversionQueryMap));
+ PnfdBlockParserFactory.getInstance().get(transformation)
+ .ifPresent(pnfParser -> pnfParser.parse(templateFrom, templateTo));
+ }
+ }
+ });
+ }
+
+ /**
+ * Gets the transformation definition yaml file path.
+ * @return The transformation definition yaml path.
+ */
+ private InputStream getDefinitionFileInputStream() {
+ final InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream(descriptorResourcePath);
+ if (resourceAsStream == null) {
+ if (LOGGER.isErrorEnabled()) {
+ LOGGER.error(String.format("Could not find resource '%s'", descriptorResourcePath));
+ }
+ return null;
+ }
+ return resourceAsStream;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/factory/PnfdBlockParserFactory.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/factory/PnfdBlockParserFactory.java
new file mode 100644
index 0000000000..512fdb5ca7
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/factory/PnfdBlockParserFactory.java
@@ -0,0 +1,57 @@
+/*
+ * ============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.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.pnfd.parser.PnfdBlockParser;
+
+/**
+ * Factory for {@link PnfdBlockParser}.
+ */
+public class PnfdBlockParserFactory {
+ private static PnfdBlockParserFactory instance;
+
+ private PnfdBlockParserFactory() {
+ }
+
+ public static PnfdBlockParserFactory getInstance() {
+ if (instance == null) {
+ instance = new PnfdBlockParserFactory();
+ }
+
+ return instance;
+ }
+
+ public Optional<PnfdBlockParser> get(final Transformation transformation) {
+ switch (transformation.getBlock()) {
+ case NODE_TEMPLATE:
+ return Optional.of(new PnfdNodeTemplateBlockParser(transformation));
+ case INPUT:
+ case GET_INPUT_FUNCTION:
+ return Optional.of(new PnfdInputBlockParser(transformation));
+ default:
+ return Optional.empty();
+ }
+ }
+
+}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionDefinitionYamlParser.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionDefinitionYamlParser.java
new file mode 100644
index 0000000000..143185210e
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionDefinitionYamlParser.java
@@ -0,0 +1,55 @@
+/*
+ * ============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.Map;
+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;
+
+/**
+ * Handles YAML from/to {@link ConversionDefinition} conversions
+ */
+public class ConversionDefinitionYamlParser {
+
+ private ConversionDefinitionYamlParser() {
+
+ }
+
+ /**
+ * Parses the given a YAML object to a {@link ConversionDefinition} instance.
+ * @param conversionYaml the YAML object representing a conversion definition
+ * @return
+ * A new instance of {@link ConversionDefinition}.
+ */
+ public static ConversionDefinition parse(final Map<String, Object> conversionYaml) {
+ final ConversionQuery conversionQuery = ConversionQueryYamlParser
+ .parse(conversionYaml.get(PnfTransformationToken.QUERY.getName()));
+ 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);
+ }
+
+}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionQueryYamlParser.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionQueryYamlParser.java
new file mode 100644
index 0000000000..417262c61c
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionQueryYamlParser.java
@@ -0,0 +1,42 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.core.converter.impl.pnfd.parser;
+
+import org.openecomp.core.converter.pnfd.model.ConversionQuery;
+
+/**
+ * Handles YAML from/to {@link ConversionQuery} conversions
+ */
+public class ConversionQueryYamlParser {
+
+ private ConversionQueryYamlParser() {
+
+ }
+
+ /**
+ * Parses the given a YAML object to a {@link ConversionQuery} instance.
+ * @param conversionYaml the YAML object representing a conversion query
+ * @return
+ * A new instance of {@link ConversionQuery}.
+ */
+ public static ConversionQuery parse(final Object conversionYaml) {
+ return 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/NodeTemplateYamlParser.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/NodeTemplateYamlParser.java
new file mode 100644
index 0000000000..fdf276f37d
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/NodeTemplateYamlParser.java
@@ -0,0 +1,55 @@
+/*
+ * ============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.NodeTemplate;
+
+/**
+ * Handles YAML from/to {@link NodeTemplate} conversions
+ */
+public class NodeTemplateYamlParser {
+
+ private NodeTemplateYamlParser() {
+ }
+
+ /**
+ * Parses the given a YAML object to a {@link NodeTemplate} instance.
+ * @param nodeTemplateYaml the YAML object representing a TOSCA Node Template
+ * @return
+ * A new instance of {@link NodeTemplate}.
+ */
+ public static NodeTemplate parse(final Map<String, Object> nodeTemplateYaml) {
+ final NodeTemplate nodeTemplate = new NodeTemplate();
+ nodeTemplate.setType((String) nodeTemplateYaml.get("type"));
+ nodeTemplate.setDescription((String) nodeTemplateYaml.get("description"));
+ nodeTemplate.setCopy((String) nodeTemplateYaml.get("copy"));
+ nodeTemplate.setProperties((Map<String, Object>) nodeTemplateYaml.get("properties"));
+ nodeTemplate.setAttributes((Map<String, Object>) nodeTemplateYaml.get("attributes"));
+ nodeTemplate.setDirectives((List<String>) nodeTemplateYaml.get("directives"));
+ nodeTemplate.setMetadata((Map<String, String>) nodeTemplateYaml.get("metadata"));
+ nodeTemplate.setInterfaces((Map<String, Object>) nodeTemplateYaml.get("interfaces"));
+
+ return nodeTemplate;
+ }
+
+
+}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/ParameterDefinitionYamlParser.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/ParameterDefinitionYamlParser.java
new file mode 100644
index 0000000000..d103326c11
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/ParameterDefinitionYamlParser.java
@@ -0,0 +1,57 @@
+/*
+ * ============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.Map;
+import org.onap.sdc.tosca.datatypes.model.EntrySchema;
+import org.onap.sdc.tosca.datatypes.model.ParameterDefinition;
+import org.onap.sdc.tosca.datatypes.model.Status;
+
+/**
+ * Handles YAML from/to {@link ParameterDefinition} conversions
+ */
+public class ParameterDefinitionYamlParser {
+
+ private ParameterDefinitionYamlParser() {
+ }
+
+ /**
+ * Parses the given a YAML object to a {@link ParameterDefinition} instance.
+ * @param parameterDefinitionYaml the YAML object representing a TOSCA Parameter Definition
+ * @return
+ * A new instance of {@link ParameterDefinition}.
+ */
+ public static ParameterDefinition parse(final Map<String, Object> parameterDefinitionYaml) {
+ final ParameterDefinition parameterDefinition = new ParameterDefinition();
+ parameterDefinition.set_default(parameterDefinitionYaml.get("default"));
+ parameterDefinition.setDescription((String) parameterDefinitionYaml.get("description"));
+ final Map<String, Object> entrySchemaYaml = (Map<String, Object>) parameterDefinitionYaml.get("entry_schema");
+ if (entrySchemaYaml != null) {
+ final EntrySchema entrySchema = new EntrySchema();
+ entrySchema.setType((String) entrySchemaYaml.get("type"));
+ parameterDefinition.setEntry_schema(entrySchema);
+ }
+ parameterDefinition.setRequired((Boolean) parameterDefinitionYaml.get("required"));
+ parameterDefinition.setType((String) parameterDefinitionYaml.get("type"));
+ parameterDefinition.setStatus((Status) parameterDefinitionYaml.get("status"));
+
+ return parameterDefinition;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdConversionStrategyYamlParser.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdConversionStrategyYamlParser.java
new file mode 100644
index 0000000000..dee16749ae
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdConversionStrategyYamlParser.java
@@ -0,0 +1,74 @@
+/*
+ * ============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 java.util.Optional;
+import org.openecomp.core.converter.pnfd.model.ConversionStrategyType;
+import org.openecomp.core.converter.pnfd.model.PnfTransformationToken;
+import org.openecomp.core.converter.impl.pnfd.strategy.CopyConversionStrategy;
+import org.openecomp.core.converter.pnfd.strategy.PnfdConversionStrategy;
+import org.openecomp.core.converter.impl.pnfd.strategy.ReplaceConversionStrategy;
+import org.openecomp.core.converter.impl.pnfd.strategy.ReplaceInListConversionStrategy;
+
+
+/**
+ * Handles YAML from/to {@link PnfdConversionStrategy} conversions.
+ */
+public class PnfdConversionStrategyYamlParser {
+
+ private PnfdConversionStrategyYamlParser() {
+
+ }
+
+ /**
+ * Parses the given YAML object to a {@link PnfdConversionStrategy} instance.
+ * @param strategyYaml the YAML object representing a conversion strategy
+ * @return
+ * A new instance of {@link PnfdConversionStrategy}.
+ */
+ public static Optional<PnfdConversionStrategy> parse(final Map<String, Object> strategyYaml) {
+ final Optional<ConversionStrategyType> optionalStrategy = ConversionStrategyType.parse(
+ (String) strategyYaml.get(PnfTransformationToken.STRATEGY.getName())
+ );
+
+ if (!optionalStrategy.isPresent()) {
+ return Optional.empty();
+ }
+
+ final ConversionStrategyType strategyType = optionalStrategy.get();
+ if (strategyType == ConversionStrategyType.COPY) {
+ return Optional.of(new CopyConversionStrategy());
+ }
+ if (strategyType == ConversionStrategyType.REPLACE) {
+ final Object from = strategyYaml.get(PnfTransformationToken.FROM.getName());
+ final Object to = strategyYaml.get(PnfTransformationToken.TO.getName());
+ return Optional.of(new ReplaceConversionStrategy(from, to));
+ }
+ if (strategyType == ConversionStrategyType.REPLACE_IN_LIST) {
+ return Optional.of(new ReplaceInListConversionStrategy(
+ (List<Map<String, Object>>) strategyYaml.get(PnfTransformationToken.LIST.getName()))
+ );
+ }
+ return Optional.empty();
+ }
+
+}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdInputBlockParser.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdInputBlockParser.java
new file mode 100644
index 0000000000..4aec8c8ac3
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdInputBlockParser.java
@@ -0,0 +1,94 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.core.converter.impl.pnfd.parser;
+
+import com.google.common.collect.ImmutableMap;
+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.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;
+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 PnfdInputBlockParser extends AbstractPnfdBlockParser {
+
+ public PnfdInputBlockParser(final Transformation transformation) {
+ super(transformation);
+ }
+
+ @Override
+ protected Optional<Map<String, Object>> buildParsedBlock(final Map<String, Object> attributeQuery,
+ final Map<String, Object> originalAttributeMap, 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 Map<String, Object> parsedInput = new HashMap<>();
+ if (attributeQuery.get(attribute) == null) {
+ final PnfdConversionStrategy pnfdConversionStrategy = conversionDefinition.getPnfdConversionStrategy();
+ final Optional convertedAttribute = pnfdConversionStrategy.convert(originalAttributeMap.get(attribute));
+ convertedAttribute.ifPresent(convertedAttribute1 -> parsedInput.put(conversionDefinition.getToAttributeName(), convertedAttribute1));
+ } else {
+ final Optional<Map<String, Object>> builtInput = buildParsedBlock((Map<String, Object>) attributeQuery.get(attribute),
+ (Map<String, Object>) originalAttributeMap.get(attribute), conversionDefinition);
+ builtInput.ifPresent(builtInput1 -> parsedInput.put(attribute, builtInput1));
+ }
+
+ return parsedInput.isEmpty() ? Optional.empty() : Optional.of(parsedInput);
+ }
+
+ @Override
+ protected void write(final String blockName, final Map<String, Object> parsedBlockYamlObject) {
+ if (!parsedBlockYamlObject.isEmpty()) {
+ final ParameterDefinition parameterDefinition = ParameterDefinitionYamlParser.parse(parsedBlockYamlObject);
+ DataModelUtil.addInputParameterToTopologyTemplate(templateTo, blockName, parameterDefinition);
+ }
+ }
+
+ @Override
+ protected Set<Map<String, Object>> findBlocksToParse() {
+ final ConversionQuery conversionQuery = transformation.getConversionQuery();
+ final Map<String, Object> inputsMap = templateFrom.getInputs();
+ if (MapUtils.isEmpty(inputsMap)) {
+ return Collections.emptySet();
+ }
+
+ return inputsMap.entrySet().stream()
+ .filter(inputMapEntry -> PnfdQueryExecutor
+ .find(conversionQuery, ImmutableMap.of(inputMapEntry.getKey(), inputMapEntry.getValue()))
+ )
+ .map(inputMapEntry -> {
+ final Map<String, Object> map = new HashMap<>();
+ map.put(inputMapEntry.getKey(), inputMapEntry.getValue());
+ return map;
+ }).collect(Collectors.toSet());
+ }
+
+}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdNodeTemplateBlockParser.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdNodeTemplateBlockParser.java
new file mode 100644
index 0000000000..5539840561
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdNodeTemplateBlockParser.java
@@ -0,0 +1,114 @@
+/*
+ * ============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.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;
+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;
+
+public class PnfdNodeTemplateBlockParser extends AbstractPnfdBlockParser {
+
+ private Map<String, String> inputNameToConvertMap = new HashMap<>();
+
+ public PnfdNodeTemplateBlockParser(final Transformation transformation) {
+ super(transformation);
+ }
+
+ public 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);
+ if (queryValue == null) {
+ PnfdConversionStrategy pnfdConversionStrategy = conversionDefinition.getPnfdConversionStrategy();
+ if (isGetInputFunction(attributeValueToConvert)) {
+ inputNameToConvertMap.put(extractGetInputFunctionValue(attributeValueToConvert)
+ , conversionDefinition.getToGetInput()
+ );
+ pnfdConversionStrategy = new CopyConversionStrategy();
+ }
+ final Map<String, Object> parsedNodeTemplate = new HashMap<>();
+ final Optional convertedAttribute = pnfdConversionStrategy.convert(attributeValueToConvert);
+ if (convertedAttribute.isPresent()) {
+ parsedNodeTemplate.put(conversionDefinition.getToAttributeName(), convertedAttribute.get());
+ }
+
+ return parsedNodeTemplate.isEmpty() ? Optional.empty() : Optional.of(parsedNodeTemplate);
+ } else {
+ if (!(queryValue instanceof Map) || !(attributeValueToConvert instanceof Map)) {
+ return Optional.empty();
+ }
+ final Map<String, Object> parsedNodeTemplate = new HashMap<>();
+ final Optional<Map<String, Object>> builtNodeTemplate = buildParsedBlock(
+ (Map<String, Object>) queryValue,
+ (Map<String, Object>) attributeValueToConvert, conversionDefinition);
+ builtNodeTemplate.ifPresent(builtNodeTemplate1 -> parsedNodeTemplate.put(attribute, builtNodeTemplate1));
+
+ return parsedNodeTemplate.isEmpty() ? Optional.empty() : Optional.of(parsedNodeTemplate);
+ }
+ }
+
+ 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) {
+ if (!parsedNodeTemplateMap.isEmpty()) {
+ final NodeTemplate parsedNodeTemplate = NodeTemplateYamlParser.parse(parsedNodeTemplateMap);
+ DataModelUtil.addNodeTemplate(templateTo, nodeTemplateName, parsedNodeTemplate);
+ }
+ }
+
+ @Override
+ public Optional<Map<String, String>> getInputAndTransformationNameMap() {
+ return Optional.of(inputNameToConvertMap);
+ }
+}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/TransformationYamlParser.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/TransformationYamlParser.java
new file mode 100644
index 0000000000..16d06704b3
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser/TransformationYamlParser.java
@@ -0,0 +1,80 @@
+/*
+ * ============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.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.NAME;
+import static org.openecomp.core.converter.pnfd.model.PnfTransformationToken.QUERY;
+import static org.openecomp.core.converter.pnfd.model.PnfTransformationToken.TRANSFORMATION_FOR;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.commons.collections.CollectionUtils;
+import org.openecomp.core.converter.pnfd.model.ConversionDefinition;
+import org.openecomp.core.converter.pnfd.model.Transformation;
+import org.openecomp.core.converter.pnfd.model.TransformationBlock;
+
+/**
+ * Handles YAML from/to {@link Transformation} conversions
+ */
+public class TransformationYamlParser {
+
+ private TransformationYamlParser() {
+
+ }
+
+ /**
+ * Parses the given YAML object to a {@link Transformation} instance.
+ * @param transformationYaml the YAML object representing a transformation
+ * @return
+ * A new instance of {@link Transformation}.
+ */
+ public static 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 String block = (String) transformationYaml.get(TRANSFORMATION_FOR.getName());
+ transformation.setBlock(TransformationBlock.parse(block).orElse(null));
+
+ transformation.setConversionQuery(
+ ConversionQueryYamlParser.parse(transformationYaml.get(QUERY.getName()))
+ );
+ transformation.setConversionDefinitionList(parseConversions(transformationYaml));
+
+ return transformation;
+ }
+
+ private static List<ConversionDefinition> parseConversions(final Map<String, Object> conversionYaml) {
+ final List<Object> conversionList = (List<Object>) conversionYaml.get(CONVERSIONS.getName());
+
+ if (CollectionUtils.isEmpty(conversionList)) {
+ return Collections.emptyList();
+ }
+
+ return conversionList.stream()
+ .map(conversion -> ConversionDefinitionYamlParser.parse((Map<String, Object>) conversion))
+ .collect(Collectors.toList());
+ }
+
+}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/strategy/CopyConversionStrategy.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/strategy/CopyConversionStrategy.java
new file mode 100644
index 0000000000..c379dfa85c
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/strategy/CopyConversionStrategy.java
@@ -0,0 +1,37 @@
+/*
+ * ============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.strategy;
+
+import java.util.HashMap;
+import java.util.Optional;
+import org.openecomp.core.converter.pnfd.strategy.AbstractPnfdConversionStrategy;
+import org.openecomp.core.converter.pnfd.model.ConversionStrategyType;
+
+public class CopyConversionStrategy extends AbstractPnfdConversionStrategy<Object, Object> {
+
+ public CopyConversionStrategy() {
+ super(ConversionStrategyType.COPY, new HashMap<>());
+ }
+
+ @Override
+ public Optional<Object> convert(final Object originalValue) {
+ return Optional.ofNullable(originalValue);
+ }
+}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/strategy/ReplaceConversionStrategy.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/strategy/ReplaceConversionStrategy.java
new file mode 100644
index 0000000000..3bde6326b7
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/strategy/ReplaceConversionStrategy.java
@@ -0,0 +1,39 @@
+/*
+ * ============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.strategy;
+
+import java.util.HashMap;
+import java.util.Optional;
+import org.openecomp.core.converter.pnfd.strategy.AbstractPnfdConversionStrategy;
+import org.openecomp.core.converter.pnfd.model.ConversionStrategyType;
+
+public class ReplaceConversionStrategy extends AbstractPnfdConversionStrategy<Object, Object> {
+
+ public ReplaceConversionStrategy(final Object from, final Object to) {
+ super(ConversionStrategyType.REPLACE, new HashMap<>());
+ conversionMap.put(from, to);
+ }
+
+ @Override
+ public Optional<Object> convert(final Object originalValue) {
+ return Optional.ofNullable(conversionMap.get(originalValue));
+ }
+
+}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/strategy/ReplaceInListConversionStrategy.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/strategy/ReplaceInListConversionStrategy.java
new file mode 100644
index 0000000000..9984a8708d
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/strategy/ReplaceInListConversionStrategy.java
@@ -0,0 +1,60 @@
+/*
+ * ============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.strategy;
+
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
+import org.openecomp.core.converter.pnfd.strategy.AbstractPnfdConversionStrategy;
+import org.openecomp.core.converter.pnfd.model.ConversionStrategyType;
+import org.openecomp.core.converter.pnfd.model.PnfTransformationToken;
+
+public class ReplaceInListConversionStrategy extends AbstractPnfdConversionStrategy<List<Object>, List<Object>> {
+
+ private final Map<Object, Object> replaceInListConversionStrategyMap;
+
+ public ReplaceInListConversionStrategy(final List<Map<String, Object>> descriptorList) {
+ super(ConversionStrategyType.REPLACE_IN_LIST, new HashMap<>());
+ replaceInListConversionStrategyMap = new LinkedHashMap<>();
+ descriptorList
+ .forEach(stringObjectMap -> replaceInListConversionStrategyMap.put(stringObjectMap.get(
+ PnfTransformationToken.FROM.getName())
+ , stringObjectMap.get(PnfTransformationToken.TO.getName()))
+ );
+ }
+
+ @Override
+ public Optional<List<Object>> convert(final List<Object> originalValue) {
+ if (originalValue == null || originalValue.isEmpty()) {
+ return Optional.empty();
+ }
+
+ final List<Object> convertedList = originalValue.stream()
+ .map(replaceInListConversionStrategyMap::get)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
+
+ return convertedList.isEmpty() ? Optional.empty() : Optional.of(convertedList);
+ }
+}