aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src')
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/PnfdTransformationEngine.java30
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/ConversionDefinition.java6
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/PnfTransformationToken.java5
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/Transformation.java31
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/TransformationBlock.java16
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/TransformationProperty.java40
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/TransformationPropertyType.java42
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/parser/AbstractPnfdBlockParser.java178
8 files changed, 158 insertions, 190 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/PnfdTransformationEngine.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/PnfdTransformationEngine.java
new file mode 100644
index 0000000000..12949f2dcc
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/PnfdTransformationEngine.java
@@ -0,0 +1,30 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.core.converter.pnfd;
+
+/**
+ * Engine that manages the PNF Descriptor transformation process.
+ */
+@FunctionalInterface
+public interface PnfdTransformationEngine {
+
+ void transform();
+
+}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/ConversionDefinition.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/ConversionDefinition.java
index 040639358f..fa06ab800e 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/ConversionDefinition.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/ConversionDefinition.java
@@ -32,4 +32,10 @@ public class ConversionDefinition {
private PnfdConversionStrategy pnfdConversionStrategy;
private String toGetInput;
+ public ConversionDefinition(ConversionQuery conversionQuery, String toAttributeName,
+ PnfdConversionStrategy pnfdConversionStrategy) {
+ this.conversionQuery = conversionQuery;
+ this.toAttributeName = toAttributeName;
+ this.pnfdConversionStrategy = pnfdConversionStrategy;
+ }
}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/PnfTransformationToken.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/PnfTransformationToken.java
index fab5b44720..886614799f 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/PnfTransformationToken.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/PnfTransformationToken.java
@@ -34,7 +34,10 @@ public enum PnfTransformationToken {
TRANSFORMATION_FOR("transformation-for"),
NAME("name"),
DESCRIPTION("description"),
- GET_INPUT("get_input"), TO_GET_INPUT("to-get-input");
+ GET_INPUT("get_input"),
+ TO_GET_INPUT("to-get-input"),
+ PROPERTIES("properties"),
+ NODE_TYPE("node_types");
private final String name;
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/Transformation.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/Transformation.java
index fa4a9336e3..a3f7ca0626 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/Transformation.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/Transformation.java
@@ -21,9 +21,12 @@ package org.openecomp.core.converter.pnfd.model;
import java.util.List;
import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
/**
* Represents a transformation from the PNFD transformation descriptor.
@@ -35,6 +38,7 @@ public class Transformation {
private String name;
private String description;
private TransformationBlock block;
+ private Set<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();
+ }
}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/TransformationBlock.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/TransformationBlock.java
index 4c897c45fb..f8a5aee407 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/TransformationBlock.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/TransformationBlock.java
@@ -20,25 +20,23 @@
package org.openecomp.core.converter.pnfd.model;
import java.util.Optional;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
/**
* Represents a type of a transformation block
*/
+@AllArgsConstructor
+@Getter
public enum TransformationBlock {
INPUT("input"),
+ GET_INPUT_FUNCTION("getInputFunction"),
NODE_TEMPLATE("nodeTemplate"),
- GET_INPUT_FUNCTION("getInputFunction");
+ CUSTOM_NODE_TYPE("customNodeType"),
+ NODE_TYPE("nodeType");
private final String name;
- TransformationBlock(final String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
/**
* Parse a String to the related {@link TransformationBlock}.
* @param name the {@link TransformationBlock} name
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/TransformationProperty.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/TransformationProperty.java
new file mode 100644
index 0000000000..c42917d95d
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/TransformationProperty.java
@@ -0,0 +1,40 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.core.converter.pnfd.model;
+
+import lombok.AllArgsConstructor;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+
+/**
+ * Represents a PNFD transformation block property.
+ *
+ * @param <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
index 0000000000..eed251944f
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/model/TransformationPropertyType.java
@@ -0,0 +1,42 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.core.converter.pnfd.model;
+
+import java.util.Arrays;
+import java.util.Optional;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * Represents a valid property for a PNFD transformation block.
+ */
+@Getter
+@AllArgsConstructor
+public enum TransformationPropertyType {
+ NODE_NAME_PREFIX("nodeNamePrefix");
+
+ private final String type;
+
+ public static Optional<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-api/src/main/java/org/openecomp/core/converter/pnfd/parser/AbstractPnfdBlockParser.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/parser/AbstractPnfdBlockParser.java
deleted file mode 100644
index fe8bd428c3..0000000000
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/pnfd/parser/AbstractPnfdBlockParser.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.core.converter.pnfd.parser;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-import org.apache.commons.collections.MapUtils;
-import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
-import org.openecomp.core.converter.ServiceTemplateReaderService;
-import org.openecomp.core.converter.pnfd.model.ConversionDefinition;
-import org.openecomp.core.converter.pnfd.model.PnfTransformationToken;
-import org.openecomp.core.converter.pnfd.model.Transformation;
-
-public abstract class AbstractPnfdBlockParser implements PnfdBlockParser {
-
- protected final Transformation transformation;
- protected ServiceTemplateReaderService templateFrom;
- protected ServiceTemplate templateTo;
-
- public AbstractPnfdBlockParser(final Transformation transformation) {
- this.transformation = transformation;
- }
-
- /**
- * Parses a PNFD block based on the {@link Transformation} provided during the {@link PnfdBlockParser}
- * instantiation.
- *
- * @param templateFrom the original PNFD template
- * @param templateTo the resulting PNFD template
- */
- public void parse(final ServiceTemplateReaderService templateFrom, final ServiceTemplate templateTo) {
- this.templateFrom = templateFrom;
- this.templateTo = templateTo;
- final Set<Map<String, Object>> blockToParseSet = findBlocksToParse();
- if (!blockToParseSet.isEmpty()) {
- blockToParseSet.forEach(this::parse);
- }
- }
-
- /**
- * Applies all specified conversions in {@link Transformation#getConversionDefinitionList()} for the given
- * blockYamlObject.
- *
- * @param blockYamlObject the block content as a YAML object
- */
- protected void parse(final Map<String, Object> blockYamlObject) {
- if (MapUtils.isEmpty(blockYamlObject)) {
- return;
- }
- final List<ConversionDefinition> conversionDefinitionList = transformation.getConversionDefinitionList();
- final Map<String, Object> parsedBlockYamlObject = new HashMap<>();
- final String blockName = blockYamlObject.keySet().iterator().next();
- conversionDefinitionList.stream()
- .filter(conversionDefinition -> conversionDefinition.getConversionQuery().isValidAttributeQuery())
- .forEach(conversionDefinition -> {
- final Map<String, Object> query =
- (Map<String, Object>) conversionDefinition.getConversionQuery().getQuery();
- final Map<String, Object> blockAttributeMap = (Map<String, Object>) blockYamlObject.get(blockName);
- final Optional<Map<String, Object>> parsedBlockAttributeMap = buildParsedBlock(query, blockAttributeMap
- , conversionDefinition);
- parsedBlockAttributeMap.ifPresent(convertedNodeTemplateAttributeMap1 ->
- mergeYamlObjects(parsedBlockYamlObject, convertedNodeTemplateAttributeMap1)
- );
- });
-
- write(blockName, parsedBlockYamlObject);
- }
-
- /**
- * Writes the block in the resulting {@link ServiceTemplate} {@link #templateTo}.
- *
- * @param blockName the name of the block
- * @param parsedBlockYamlObject the block content as a YAML object
- */
- protected abstract void write(final String blockName, final Map<String, Object> parsedBlockYamlObject);
-
- /**
- * Uses the provided attribute query to find a attribute in the original YAML object and apply the provided
- * conversion.
- *
- * @param attributeQuery the attribute query
- * @param fromNodeTemplateAttributeMap the original YAML object
- * @param conversionDefinition the conversion
- * @return the rebuilt original YAML object with the converted attribute
- */
- protected abstract Optional<Map<String, Object>> buildParsedBlock(final Map<String, Object> attributeQuery,
- final Map<String, Object> fromNodeTemplateAttributeMap,
- final ConversionDefinition conversionDefinition);
-
- /**
- * Merges two YAML objects.
- *
- * @param originalMap original YAML object
- * @param toBeMergedMap YAML object to be merged
- * @return the new YAML object representing the merge result.
- */
- protected Map<String, Object> mergeYamlObjects(final Map<String, Object> originalMap,
- final Map<String, Object> toBeMergedMap) {
- toBeMergedMap.forEach(
- (key, value) -> originalMap.merge(key, value,
- (toBeMergedValue, originalValue) -> {
- if (originalValue instanceof Map) {
- return mergeYamlObjects((Map) originalValue, (Map) toBeMergedValue);
- }
- return originalValue;
- })
- );
-
- return originalMap;
- }
-
- /**
- * Executes the provided {@link #transformation getConversionQuery} YAML query to find the blocks to be parsed in
- * {@link #templateFrom}.
- *
- * @return The YAML blocks found
- */
- protected abstract Set<Map<String, Object>> findBlocksToParse();
-
- /**
- * Checks if the YAML object is a TOSCA get_input call
- *
- * @param yamlObject the YAML object
- * @return {@code true} if the YAML object is a TOSCA get_input call, {@code false} otherwise
- */
- protected boolean isGetInputFunction(final Object yamlObject) {
- if (yamlObject instanceof Map) {
- final Map<String, Object> yamlMap = (Map<String, Object>) yamlObject;
- return yamlMap.containsKey(PnfTransformationToken.GET_INPUT.getName());
- }
-
- return false;
- }
-
- /**
- * 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
- */
- protected String extractGetInputFunctionValue(final Object yamlObject) {
- if (yamlObject instanceof Map) {
- final Map<String, Object> yamlMap = (Map<String, Object>) yamlObject;
- return (String) yamlMap.values().stream().findFirst().orElse(null);
- }
-
- return null;
- }
-
- /**
- * Gets the stored input names called with TOSCA get_input function and its transformation configured in {@link
- * ConversionDefinition#getToGetInput()}
- */
- public Optional<Map<String, String>> getInputAndTransformationNameMap() {
- return Optional.empty();
- }
-
-}