summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/parser
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/pnfd/parser')
-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
8 files changed, 571 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/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());
+ }
+
+}