summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-lib
diff options
context:
space:
mode:
authorshiria <shiri.amichai@amdocs.com>2018-09-20 12:51:32 +0300
committerOren Kleks <orenkle@amdocs.com>2018-10-08 12:04:27 +0000
commit48528e9da9e241c59f1628ffda9020a981f939f6 (patch)
tree16644ddacf5b4be4dc56c1e8639f2934a5503d3b /openecomp-be/lib/openecomp-tosca-lib
parent90943911394d3672e714d2b743c143a2dd4408cc (diff)
Add support of interface in TOSCA datatypes
Move all interface functionality from DataModelUtil class to TOSCA datatype relevant class Change-Id: Ifea22b60e9a71fe024e87f9987a749e9d56aad82 Issue-ID: SDC-1781 Signed-off-by: shiria <shiri.amichai@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-lib')
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java303
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java253
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/ToscaModelTest.java118
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java267
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/ServiceTemplateInterfaceInheritanceTest.yaml107
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithInterface.yaml4
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithInterfaceAndOperation.yaml4
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithNodeTemplateInterface.yaml4
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithNodeTypeInterface.yaml4
9 files changed, 518 insertions, 546 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java
index 64b0006acd..9b9cd80385 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java
@@ -16,28 +16,54 @@
package org.openecomp.sdc.tosca.services;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.NotSerializableException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
-import org.onap.sdc.tosca.datatypes.model.*;
+import org.onap.sdc.tosca.datatypes.model.AttributeDefinition;
+import org.onap.sdc.tosca.datatypes.model.CapabilityAssignment;
+import org.onap.sdc.tosca.datatypes.model.CapabilityDefinition;
+import org.onap.sdc.tosca.datatypes.model.Constraint;
+import org.onap.sdc.tosca.datatypes.model.EntrySchema;
+import org.onap.sdc.tosca.datatypes.model.GroupDefinition;
+import org.onap.sdc.tosca.datatypes.model.Import;
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
+import org.onap.sdc.tosca.datatypes.model.NodeType;
+import org.onap.sdc.tosca.datatypes.model.ParameterDefinition;
+import org.onap.sdc.tosca.datatypes.model.PolicyDefinition;
+import org.onap.sdc.tosca.datatypes.model.PropertyDefinition;
+import org.onap.sdc.tosca.datatypes.model.RelationshipTemplate;
+import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
+import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
+import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.onap.sdc.tosca.datatypes.model.SubstitutionMapping;
+import org.onap.sdc.tosca.datatypes.model.TopologyTemplate;
import org.onap.sdc.tosca.datatypes.model.heatextend.ParameterDefinitionExt;
import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
import org.onap.sdc.tosca.services.YamlUtil;
import org.openecomp.core.utilities.CommonMethods;
import org.openecomp.sdc.common.errors.CoreException;
-import org.openecomp.sdc.common.utils.CommonUtil;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
-import org.openecomp.sdc.tosca.errors.*;
+import org.openecomp.sdc.tosca.errors.InvalidAddActionNullEntityErrorBuilder;
+import org.openecomp.sdc.tosca.errors.InvalidRequirementAssignmentErrorBuilder;
import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl;
-import java.io.*;
-import java.util.*;
-
/**
* The type Data model util.
*/
@@ -46,7 +72,6 @@ public class DataModelUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(DataModelUtil.class);
private static final String SERVICE_TEMPLATE = "Service Template";
private static final String NODE_TYPE = "Node Type";
- private static final String OPERATIONS = "operations";
private DataModelUtil() {
// prevent instantiation
@@ -59,7 +84,7 @@ public class DataModelUtil {
* @param substitutionMapping the substitution mapping
*/
public static void addSubstitutionMapping(ServiceTemplate serviceTemplate,
- SubstitutionMapping substitutionMapping) {
+ SubstitutionMapping substitutionMapping) {
if (serviceTemplate == null) {
throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping", SERVICE_TEMPLATE)
.build());
@@ -92,11 +117,11 @@ public class DataModelUtil {
* @param substitutionMappingRequirementList the substitution mapping requirement list
*/
public static void addSubstitutionMappingReq(ServiceTemplate serviceTemplate,
- String substitutionMappingRequirementId,
- List<String> substitutionMappingRequirementList) {
+ String substitutionMappingRequirementId, List<String> substitutionMappingRequirementList) {
if (serviceTemplate == null) {
- throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping Requirements",
- SERVICE_TEMPLATE).build());
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping Requirements", SERVICE_TEMPLATE)
+ .build());
}
if (serviceTemplate.getTopology_template() == null) {
@@ -121,8 +146,7 @@ public class DataModelUtil {
* @param substitutionMappingCapabilityList the substitution mapping capability list
*/
public static void addSubstitutionMappingCapability(ServiceTemplate serviceTemplate,
- String substitutionMappingCapabilityId,
- List<String> substitutionMappingCapabilityList) {
+ String substitutionMappingCapabilityId, List<String> substitutionMappingCapabilityList) {
if (serviceTemplate == null) {
throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping Capabilities",
SERVICE_TEMPLATE).build());
@@ -180,10 +204,10 @@ public class DataModelUtil {
* @param nodeTemplate the node template
*/
public static void addNodeTemplate(ServiceTemplate serviceTemplate, String nodeTemplateId,
- NodeTemplate nodeTemplate) {
+ NodeTemplate nodeTemplate) {
if (serviceTemplate == null) {
- throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Node Template", SERVICE_TEMPLATE)
- .build());
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Node Template", SERVICE_TEMPLATE).build());
}
TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
if (Objects.isNull(topologyTemplate)) {
@@ -208,8 +232,8 @@ public class DataModelUtil {
}
if (nodeType == null) {
- throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Capability Definition", NODE_TYPE)
- .build());
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Capability Definition", NODE_TYPE).build());
}
if (MapUtils.isEmpty(nodeType.getCapabilities())) {
@@ -256,10 +280,10 @@ public class DataModelUtil {
* @param policyDefinition the policy definition
*/
public static void addPolicyDefinition(ServiceTemplate serviceTemplate, String policyId,
- PolicyDefinition policyDefinition) {
+ PolicyDefinition policyDefinition) {
if (serviceTemplate == null) {
- throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Policy Definition", SERVICE_TEMPLATE)
- .build());
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Policy Definition", SERVICE_TEMPLATE).build());
}
TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
if (Objects.isNull(topologyTemplate)) {
@@ -297,10 +321,10 @@ public class DataModelUtil {
* @param relationshipTemplate the relationship template
*/
public static void addRelationshipTemplate(ServiceTemplate serviceTemplate, String relationshipTemplateId,
- RelationshipTemplate relationshipTemplate) {
+ RelationshipTemplate relationshipTemplate) {
if (serviceTemplate == null) {
- throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Relationship Template",
- SERVICE_TEMPLATE).build());
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Relationship Template", SERVICE_TEMPLATE).build());
}
if (serviceTemplate.getTopology_template() == null) {
serviceTemplate.setTopology_template(new TopologyTemplate());
@@ -320,10 +344,11 @@ public class DataModelUtil {
* @param requirementAssignment the requirement assignment
*/
public static void addRequirementAssignment(NodeTemplate nodeTemplate, String requirementId,
- RequirementAssignment requirementAssignment) {
+ RequirementAssignment requirementAssignment) {
if (nodeTemplate == null) {
- throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Requirement Assignment",
- "Node Template").build());
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Requirement Assignment",
+ "Node Template").build());
}
if (requirementAssignment.getNode() == null) {
throw new CoreException(new InvalidRequirementAssignmentErrorBuilder(requirementId).build());
@@ -401,8 +426,8 @@ public class DataModelUtil {
* @param requirementsDefinitionList requirement definition list
* @param requirementKey requirement key
*/
- public static Optional<RequirementDefinition> getRequirementDefinition(List<Map<String, RequirementDefinition>> requirementsDefinitionList,
- String requirementKey) {
+ public static Optional<RequirementDefinition> getRequirementDefinition(
+ List<Map<String, RequirementDefinition>> requirementsDefinitionList, String requirementKey) {
if (CollectionUtils.isEmpty(requirementsDefinitionList)) {
return Optional.empty();
}
@@ -427,7 +452,7 @@ public class DataModelUtil {
* @return the capability definition
*/
public static Optional<CapabilityDefinition> getCapabilityDefinition(NodeType nodeType,
- String capabilityDefinitionId) {
+ String capabilityDefinitionId) {
if (nodeType == null || nodeType.getCapabilities() == null || capabilityDefinitionId == null) {
return Optional.empty();
}
@@ -442,10 +467,10 @@ public class DataModelUtil {
* @param group the group
*/
public static void addGroupDefinitionToTopologyTemplate(ServiceTemplate serviceTemplate, String groupName,
- GroupDefinition group) {
+ GroupDefinition group) {
if (serviceTemplate == null) {
- throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Group Definition", SERVICE_TEMPLATE)
- .build());
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Group Definition", SERVICE_TEMPLATE).build());
}
TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
@@ -500,8 +525,7 @@ public class DataModelUtil {
* @return the property definition
*/
public static ParameterDefinition createParameterDefinition(String type, String description, boolean required,
- List<Constraint> constraints,
- EntrySchema entrySchema, Object defaultVal) {
+ List<Constraint> constraints, EntrySchema entrySchema, Object defaultVal) {
ParameterDefinition paramDef = new ParameterDefinition();
paramDef.setType(type);
paramDef.setDescription(description);
@@ -522,7 +546,7 @@ public class DataModelUtil {
* @return the requirement definition
*/
public static RequirementDefinition createRequirement(String capability, String node, String relationship,
- Object[] occurrences) {
+ Object[] occurrences) {
RequirementDefinition requirementDefinition = new RequirementDefinition();
requirementDefinition.setCapability(capability);
requirementDefinition.setNode(node);
@@ -562,7 +586,7 @@ public class DataModelUtil {
* @return the map
*/
public static Map createGetInputPropertyValueFromListParameter(String inputPropertyListName, int indexInTheList,
- String... nestedPropertyName) {
+ String... nestedPropertyName) {
List<Object> propertyList = new ArrayList<>();
propertyList.add(inputPropertyListName);
propertyList.add(indexInTheList);
@@ -607,7 +631,7 @@ public class DataModelUtil {
* @return the parameter definition ext
*/
public static ParameterDefinitionExt convertAttributeDefToParameterDef(AttributeDefinition attributeDefinition,
- Map<String, List> outputValue) {
+ Map<String, List> outputValue) {
if (attributeDefinition == null) {
return null;
}
@@ -630,11 +654,11 @@ public class DataModelUtil {
* @param parameterDefinition the parameter definition
*/
public static void addInputParameterToTopologyTemplate(ServiceTemplate serviceTemplate,
- String parameterDefinitionId,
- ParameterDefinition parameterDefinition) {
+ String parameterDefinitionId, ParameterDefinition parameterDefinition) {
if (Objects.isNull(serviceTemplate)) {
- throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Topology Template Input Parameter",
- SERVICE_TEMPLATE).build());
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Topology Template Input Parameter", SERVICE_TEMPLATE)
+ .build());
}
TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
if (Objects.isNull(topologyTemplate)) {
@@ -655,11 +679,11 @@ public class DataModelUtil {
* @param parameterDefinition the parameter definition
*/
public static void addOutputParameterToTopologyTemplate(ServiceTemplate serviceTemplate,
- String parameterDefinitionId,
- ParameterDefinition parameterDefinition) {
+ String parameterDefinitionId, ParameterDefinition parameterDefinition) {
if (Objects.isNull(serviceTemplate)) {
- throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Topology Template Output Parameter",
- SERVICE_TEMPLATE).build());
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Topology Template Output Parameter", SERVICE_TEMPLATE)
+ .build());
}
TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
if (Objects.isNull(topologyTemplate)) {
@@ -679,7 +703,7 @@ public class DataModelUtil {
* @param requirementDef added requirement def
*/
public static void addRequirementToList(List<Map<String, RequirementDefinition>> requirementList,
- Map<String, RequirementDefinition> requirementDef) {
+ Map<String, RequirementDefinition> requirementDef) {
if (requirementDef == null) {
return;
}
@@ -710,9 +734,8 @@ public class DataModelUtil {
ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
for (Map<String, RequirementAssignment> requirementAssignmentMap : templateRequirements) {
for (Map.Entry<String, RequirementAssignment> requirementEntry : requirementAssignmentMap.entrySet()) {
- RequirementAssignment requirementAssignment =
- (toscaExtensionYamlUtil.yamlToObject(toscaExtensionYamlUtil.objectToYaml(requirementEntry.getValue()),
- RequirementAssignment.class));
+ RequirementAssignment requirementAssignment = (toscaExtensionYamlUtil.yamlToObject(
+ toscaExtensionYamlUtil.objectToYaml(requirementEntry.getValue()), RequirementAssignment.class));
nodeTemplateRequirementsAssignment.put(requirementEntry.getKey(), requirementAssignment);
}
}
@@ -757,8 +780,8 @@ public class DataModelUtil {
* @param requirementsAssignmentList requirement definition list
* @param requirementKey requirement key
*/
- public static Optional<List<RequirementAssignment>> getRequirementAssignment(List<Map<String, RequirementAssignment>> requirementsAssignmentList,
- String requirementKey) {
+ public static Optional<List<RequirementAssignment>> getRequirementAssignment(
+ List<Map<String, RequirementAssignment>> requirementsAssignmentList, String requirementKey) {
if (CollectionUtils.isEmpty(requirementsAssignmentList)) {
return Optional.empty();
}
@@ -786,7 +809,7 @@ public class DataModelUtil {
* @param requirementKey requirement key
*/
public static void removeRequirementsDefinition(List<Map<String, RequirementDefinition>> requirementsDefinitionList,
- String requirementKey) {
+ String requirementKey) {
if (requirementsDefinitionList == null) {
return;
}
@@ -810,7 +833,7 @@ public class DataModelUtil {
* @param requirementKey requirement key
*/
public static void removeRequirementsAssignment(List<Map<String, RequirementAssignment>> requirementsAssignmentList,
- String requirementKey) {
+ String requirementKey) {
if (requirementsAssignmentList == null) {
return;
}
@@ -836,7 +859,7 @@ public class DataModelUtil {
* @param requirementAssignmentToBeDeleted the requirement assignment to be deleted
*/
public static void removeRequirementAssignment(NodeTemplate nodeTemplate, String requirementKey,
- RequirementAssignment requirementAssignmentToBeDeleted) {
+ RequirementAssignment requirementAssignmentToBeDeleted) {
ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
List<Map<String, RequirementAssignment>> nodeTemplateRequirements = nodeTemplate.getRequirements();
if (nodeTemplateRequirements == null) {
@@ -960,7 +983,7 @@ public class DataModelUtil {
* @return node template properties
*/
public static Map<String, Object> getNodeTemplateProperties(ServiceTemplate serviceTemplate,
- String nodeTemplateId) {
+ String nodeTemplateId) {
if (serviceTemplate == null || serviceTemplate.getTopology_template() == null
|| serviceTemplate.getTopology_template().getNode_templates() == null
|| serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId) == null) {
@@ -1097,8 +1120,7 @@ public class DataModelUtil {
* @return the substitution mapping
*/
public static SubstitutionMapping createSubstitutionTemplateSubMapping(String nodeTypeKey,
- NodeType substitutionNodeType,
- Map<String, Map<String, List<String>>> mapping) {
+ NodeType substitutionNodeType, Map<String, Map<String, List<String>>> mapping) {
SubstitutionMapping substitutionMapping = new SubstitutionMapping();
substitutionMapping.setNode_type(nodeTypeKey);
substitutionMapping.setCapabilities(manageCapabilityMapping(substitutionNodeType.getCapabilities(),
@@ -1117,8 +1139,7 @@ public class DataModelUtil {
* @param capabilityAttributes the capability attributes
*/
public static void addNodeTemplateCapability(NodeTemplate nodeTemplate, String capabilityId,
- Map<String, Object> capabilityProperties,
- Map<String, Object> capabilityAttributes) {
+ Map<String, Object> capabilityProperties, Map<String, Object> capabilityAttributes) {
Map<String, CapabilityAssignment> capabilities = nodeTemplate.getCapabilities();
if (Objects.isNull(capabilities)) {
capabilities = new HashMap<>();
@@ -1130,8 +1151,9 @@ public class DataModelUtil {
nodeTemplate.setCapabilities(capabilities);
}
- private static Map<String, List<String>> manageRequirementMapping(List<Map<String, RequirementDefinition>> requirementList,
- Map<String, List<String>> requirementSubstitutionMapping) {
+ private static Map<String, List<String>> manageRequirementMapping(
+ List<Map<String, RequirementDefinition>> requirementList,
+ Map<String, List<String>> requirementSubstitutionMapping) {
if (requirementList == null) {
return null;
}
@@ -1149,7 +1171,7 @@ public class DataModelUtil {
}
private static Map<String, List<String>> manageCapabilityMapping(Map<String, CapabilityDefinition> capabilities,
- Map<String, List<String>> capabilitySubstitutionMapping) {
+ Map<String, List<String>> capabilitySubstitutionMapping) {
if (capabilities == null) {
return null;
}
@@ -1165,153 +1187,8 @@ public class DataModelUtil {
return capabilityMapping;
}
- /**
- * Add interface operation.
- *
- * @param serviceTemplate the service template
- * @param interfaceId the interface id
- * @param operationId the operation id
- * @param operationDefinition the operation definition
- */
- public static void addInterfaceOperation(ServiceTemplate serviceTemplate, String interfaceId, String operationId,
- OperationDefinition operationDefinition) {
- Map<String, Object> interfaceTypes = serviceTemplate.getInterface_types();
- if (MapUtils.isEmpty(interfaceTypes) || Objects.isNull(interfaceTypes.get(interfaceId))) {
- return;
- }
-
- Object interfaceObject = interfaceTypes.get(interfaceId);
- Map<String, Object> interfaceAsMap = CommonUtil.getObjectAsMap(interfaceObject);
- interfaceAsMap.put(operationId, operationDefinition);
- }
-
- public static Map<String, InterfaceType> getInterfaceTypes(ServiceTemplate serviceTemplate) {
- Map<String, Object> interfaceTypes = serviceTemplate.getInterface_types();
-
- if (MapUtils.isEmpty(interfaceTypes)) {
- return new HashMap<>();
- }
-
- Map<String, InterfaceType> convertedInterfaceTypes = new HashMap<>();
- for (Map.Entry<String, Object> interfaceEntry : interfaceTypes.entrySet()) {
- try {
- Optional<InterfaceType> interfaceType =
- convertObjToInterfaceType(interfaceEntry.getKey(), interfaceEntry.getValue());
- interfaceType.ifPresent(
- interfaceValue -> convertedInterfaceTypes.put(interfaceEntry.getKey(), interfaceValue));
- } catch (Exception e) {
- LOGGER.error("Cannot create interface object", e);
- throw new CoreException(new ToscaInvalidInterfaceValueErrorBuilder(e.getMessage()).build());
- }
- }
-
- return convertedInterfaceTypes;
- }
-
- public static <T extends InterfaceDefinition> Optional<T> convertObjToInterfaceDefinition(String interfaceId,
- Object interfaceObj,
- Class<T> interfaceClass) {
- try {
- Optional<T> interfaceDefinition = CommonUtil.createObjectUsingSetters(interfaceObj, interfaceClass);
- interfaceDefinition.ifPresent(interfaceDefinitionType1 -> updateInterfaceDefinitionOperations(
- CommonUtil.getObjectAsMap(interfaceObj), interfaceDefinitionType1));
- return interfaceDefinition;
- } catch (Exception ex) {
- LOGGER.error("Could not create {} from {}", InterfaceDefinitionType.class.getName(), interfaceId, ex);
- throw new CoreException(new CreateInterfaceObjectErrorBuilder(InterfaceDefinitionType.class.getName(),
- interfaceId, ex.getMessage()).build());
- }
-
- }
-
-
- public static Optional<InterfaceType> convertObjToInterfaceType(String interfaceId, Object interfaceObj) {
- try {
- Optional<InterfaceType> interfaceType =
- CommonUtil.createObjectUsingSetters(interfaceObj, InterfaceType.class);
- interfaceType.ifPresent(
- interfaceType1 -> updateInterfaceTypeOperations(CommonUtil.getObjectAsMap(interfaceObj),
- interfaceType1));
- return interfaceType;
- } catch (Exception ex) {
- LOGGER.error("Could not create {} from {}", InterfaceType.class.getName(), interfaceId, ex);
- throw new CoreException(new CreateInterfaceObjectErrorBuilder(InterfaceType.class.getName(), interfaceId,
- ex.getMessage()).build());
- }
- }
-
- public static Optional<Object> convertInterfaceTypeToObj(InterfaceType interfaceType) {
- return converInterfaceToToscaInterfaceObj(interfaceType);
- }
-
- public static Optional<Object> convertInterfaceDefinitionTypeToObj(InterfaceDefinitionType interfaceDefinitionType) {
- return converInterfaceToToscaInterfaceObj(interfaceDefinitionType);
- }
-
- private static Optional<Object> converInterfaceToToscaInterfaceObj(Object interfaceEntity) {
- if (Objects.isNull(interfaceEntity)) {
- return Optional.empty();
- }
-
- Map<String, Object> interfaceAsMap = CommonUtil.getObjectAsMap(interfaceEntity);
- Map<String, Object> operations = (Map<String, Object>) interfaceAsMap.get(OPERATIONS);
- if (MapUtils.isNotEmpty(operations)) {
- interfaceAsMap.remove(OPERATIONS);
- interfaceAsMap.putAll(operations);
- }
-
- ObjectMapper objectMapper = new ObjectMapper();
- objectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
- return Optional.of(objectMapper.convertValue(interfaceAsMap, Object.class));
- }
-
- private static void updateInterfaceTypeOperations(Map<String, Object> interfaceAsMap, InterfaceType interfaceType) {
-
- Set<String> fieldNames = CommonUtil.getClassFieldNames(InterfaceType.class);
-
- for (Map.Entry<String, Object> entry : interfaceAsMap.entrySet()) {
- Optional<? extends OperationDefinition> operationDefinition =
- createOperation(entry.getKey(), entry.getValue(), fieldNames, OperationDefinitionType.class);
- operationDefinition.ifPresent(operation -> interfaceType.addOperation(entry.getKey(), operation));
- }
- }
-
- private static Optional<? extends OperationDefinition> createOperation(String propertyName,
- Object operationCandidate,
- Set<String> fieldNames,
- Class<? extends OperationDefinition> operationClass) {
- if (!fieldNames.contains(propertyName)) {
- try {
- return CommonUtil.createObjectUsingSetters(operationCandidate, operationClass);
- } catch (Exception ex) {
- LOGGER.error("Could not create Operation from {}", propertyName, ex);
- throw new CoreException(new CreateInterfaceOperationObjectErrorBuilder(propertyName, ex.getMessage())
- .build());
- }
- }
-
- return Optional.empty();
- }
-
- private static <T extends OperationDefinition> void updateInterfaceDefinitionOperations(Map<String, Object> interfaceAsMap,
- InterfaceDefinition interfaceDefinition) {
-
- Set<String> fieldNames = CommonUtil.getClassFieldNames(InterfaceDefinitionType.class);
- Optional<? extends OperationDefinition> operationDefinition;
-
- for (Map.Entry<String, Object> entry : interfaceAsMap.entrySet()) {
- operationDefinition = createOperation(entry.getKey(), entry.getValue(), fieldNames,
- interfaceDefinition instanceof InterfaceDefinitionType ? OperationDefinitionType.class :
- OperationDefinitionTemplate.class);
- operationDefinition.ifPresent(operation -> interfaceDefinition.addOperation(entry.getKey(), operation));
- }
-
- }
-
-
public static void addSubstitutionNodeTypeRequirements(NodeType substitutionNodeType,
- List<Map<String, RequirementDefinition>> requirementsList,
- String templateName) {
+ List<Map<String, RequirementDefinition>> requirementsList, String templateName) {
if (CollectionUtils.isEmpty(requirementsList)) {
return;
}
@@ -1341,7 +1218,7 @@ public class DataModelUtil {
* @return the relationship template
*/
public static Optional<RelationshipTemplate> getRelationshipTemplate(ServiceTemplate serviceTemplate,
- String relationshipId) {
+ String relationshipId) {
if (serviceTemplate == null || serviceTemplate.getTopology_template() == null
|| serviceTemplate.getTopology_template().getRelationship_templates() == null
|| serviceTemplate.getTopology_template().getRelationship_templates().get(relationshipId) == null) {
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java
index 2d0d3fb59c..b254671dc7 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java
@@ -16,10 +16,35 @@
package org.openecomp.sdc.tosca.services.impl;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
-import org.onap.sdc.tosca.datatypes.model.*;
+import org.onap.sdc.tosca.datatypes.model.AttributeDefinition;
+import org.onap.sdc.tosca.datatypes.model.CapabilityDefinition;
+import org.onap.sdc.tosca.datatypes.model.CapabilityType;
+import org.onap.sdc.tosca.datatypes.model.DataType;
+import org.onap.sdc.tosca.datatypes.model.DefinitionOfDataType;
+import org.onap.sdc.tosca.datatypes.model.Import;
+import org.onap.sdc.tosca.datatypes.model.InterfaceDefinitionType;
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
+import org.onap.sdc.tosca.datatypes.model.NodeType;
+import org.onap.sdc.tosca.datatypes.model.ParameterDefinition;
+import org.onap.sdc.tosca.datatypes.model.PropertyDefinition;
+import org.onap.sdc.tosca.datatypes.model.PropertyType;
+import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
+import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
+import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
import org.openecomp.core.utilities.CommonMethods;
import org.openecomp.sdc.common.errors.CoreException;
@@ -27,29 +52,31 @@ import org.openecomp.sdc.common.errors.SdcRuntimeException;
import org.openecomp.sdc.tosca.datatypes.ToscaElementTypes;
import org.openecomp.sdc.tosca.datatypes.ToscaFlatData;
import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
-import org.openecomp.sdc.tosca.errors.*;
+import org.openecomp.sdc.tosca.errors.ToscaElementTypeNotFoundErrorBuilder;
+import org.openecomp.sdc.tosca.errors.ToscaFileNotFoundErrorBuilder;
+import org.openecomp.sdc.tosca.errors.ToscaInvalidEntryNotFoundErrorBuilder;
+import org.openecomp.sdc.tosca.errors.ToscaInvalidSubstituteNodeTemplatePropertiesErrorBuilder;
+import org.openecomp.sdc.tosca.errors.ToscaInvalidSubstitutionServiceTemplateErrorBuilder;
import org.openecomp.sdc.tosca.services.DataModelUtil;
import org.openecomp.sdc.tosca.services.ToscaAnalyzerService;
import org.openecomp.sdc.tosca.services.ToscaConstants;
import org.openecomp.sdc.tosca.services.ToscaUtil;
-import java.lang.reflect.InvocationTargetException;
-import java.util.*;
-
public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
private static final String GET_NODE_TYPE_METHOD_NAME = "getNode_types";
private static final String GET_DERIVED_FROM_METHOD_NAME = "getDerived_from";
private static final String GET_TYPE_METHOD_NAME = "getType";
private static final String GET_DATA_TYPE_METHOD_NAME = "getData_types";
- private static final String GET_INTERFACE_TYPE_METHOD_NAME = "getInterface_types";
+ private static final String GET_INTERFACE_TYPE_METHOD_NAME = "getNormalizeInterfaceTypes";
private static final String GET_CAPABILITY_TYPE_METHOD_NAME = "getCapability_types";
private static final String TOSCA_DOT = "tosca.";
private static final String DOT_ROOT = ".Root";
@Override
- public List<Map<String, RequirementDefinition>> calculateExposedRequirements(List<Map<String, RequirementDefinition>> nodeTypeRequirementsDefinitionList,
- Map<String, RequirementAssignment> nodeTemplateRequirementsAssignment) {
+ public List<Map<String, RequirementDefinition>> calculateExposedRequirements(
+ List<Map<String, RequirementDefinition>> nodeTypeRequirementsDefinitionList,
+ Map<String, RequirementAssignment> nodeTemplateRequirementsAssignment) {
if (nodeTypeRequirementsDefinitionList == null) {
return Collections.emptyList();
@@ -73,19 +100,19 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
private void updateMinMaxOccurencesForNodeTypeRequirement(Map.Entry<String, RequirementAssignment> entry,
- Map<String, RequirementDefinition> nodeTypeRequirementsMap) {
+ Map<String, RequirementDefinition> nodeTypeRequirementsMap) {
Object max = nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences() != null
- && nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences().length > 0 ?
- nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences()[1] : 1;
+ && nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences().length > 0
+ ? nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences()[1] : 1;
Object min = nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences() != null
- && nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences().length > 0 ?
- nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences()[0] : 1;
+ && nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences().length > 0
+ ? nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences()[0] : 1;
nodeTypeRequirementsMap.get(entry.getKey()).setOccurrences(new Object[] {min, max});
}
- private void updateRequirementDefinition(List<Map<String, RequirementDefinition>> nodeTypeRequirementsDefinitionList,
- Map.Entry<String, RequirementAssignment> entry,
- RequirementDefinition cloneRequirementDefinition) {
+ private void updateRequirementDefinition(
+ List<Map<String, RequirementDefinition>> nodeTypeRequirementsDefinitionList,
+ Map.Entry<String, RequirementAssignment> entry, RequirementDefinition cloneRequirementDefinition) {
if (!evaluateRequirementFulfillment(cloneRequirementDefinition)) {
CommonMethods
.mergeEntryInList(entry.getKey(), cloneRequirementDefinition, nodeTypeRequirementsDefinitionList);
@@ -112,8 +139,9 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
@Override
- public Map<String, CapabilityDefinition> calculateExposedCapabilities(Map<String, CapabilityDefinition> nodeTypeCapabilitiesDefinition,
- Map<String, Map<String, RequirementAssignment>> fullFilledRequirementsDefinitionMap) {
+ public Map<String, CapabilityDefinition> calculateExposedCapabilities(
+ Map<String, CapabilityDefinition> nodeTypeCapabilitiesDefinition,
+ Map<String, Map<String, RequirementAssignment>> fullFilledRequirementsDefinitionMap) {
String capabilityKey;
String capability;
@@ -122,6 +150,7 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
.entrySet()) {
for (Map.Entry<String, RequirementAssignment> fullFilledEntry : entry.getValue().entrySet()) {
+
capability = fullFilledEntry.getValue().getCapability();
node = fullFilledEntry.getValue().getNode();
capabilityKey = capability + "_" + node;
@@ -143,8 +172,7 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
private void updateNodeTypeCapabilitiesDefinition(Map<String, CapabilityDefinition> nodeTypeCapabilitiesDefinition,
- String capabilityKey,
- CapabilityDefinition clonedCapabilityDefinition) {
+ String capabilityKey, CapabilityDefinition clonedCapabilityDefinition) {
if (evaluateCapabilityFulfillment(clonedCapabilityDefinition)) {
nodeTypeCapabilitiesDefinition.remove(capabilityKey);
} else {
@@ -175,13 +203,13 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
*/
@Override
public Map<String, NodeTemplate> getNodeTemplatesByType(ServiceTemplate serviceTemplate, String nodeType,
- ToscaServiceModel toscaServiceModel) {
+ ToscaServiceModel toscaServiceModel) {
Map<String, NodeTemplate> nodeTemplates = new HashMap<>();
if (Objects.nonNull(serviceTemplate.getTopology_template()) && MapUtils.isNotEmpty(
serviceTemplate.getTopology_template().getNode_templates())) {
for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : serviceTemplate.getTopology_template()
- .getNode_templates().entrySet()) {
+ .getNode_templates().entrySet()) {
if (isTypeOf(nodeTemplateEntry.getValue(), nodeType, serviceTemplate, toscaServiceModel)) {
nodeTemplates.put(nodeTemplateEntry.getKey(), nodeTemplateEntry.getValue());
}
@@ -194,21 +222,38 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
@Override
public Optional<NodeType> fetchNodeType(String nodeTypeKey, Collection<ServiceTemplate> serviceTemplates) {
Optional<Map<String, NodeType>> nodeTypeMap = serviceTemplates.stream().map(ServiceTemplate::getNode_types)
- .filter(nodeTypes -> Objects.nonNull(nodeTypes)
- && nodeTypes
- .containsKey(
- nodeTypeKey))
- .findFirst();
+ .filter(nodeTypes -> Objects.nonNull(nodeTypes)
+ && nodeTypes.containsKey(nodeTypeKey)).findFirst();
return nodeTypeMap.map(stringNodeTypeMap -> stringNodeTypeMap.get(nodeTypeKey));
}
@Override
public boolean isTypeOf(NodeTemplate nodeTemplate, String nodeType, ServiceTemplate serviceTemplate,
- ToscaServiceModel toscaServiceModel) {
+ ToscaServiceModel toscaServiceModel) {
return isTypeOf(nodeTemplate, nodeType, GET_NODE_TYPE_METHOD_NAME, serviceTemplate, toscaServiceModel);
}
@Override
+ public boolean isTypeOf(InterfaceDefinitionType interfaceDefinition, String interfaceType,
+ ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel) {
+ return isTypeOf(interfaceDefinition, interfaceType, GET_INTERFACE_TYPE_METHOD_NAME, serviceTemplate,
+ toscaServiceModel);
+ }
+
+ @Override
+ public boolean isTypeOf(DefinitionOfDataType parameterDefinition, String dataType, ServiceTemplate serviceTemplate,
+ ToscaServiceModel toscaServiceModel) {
+ return isTypeOf(parameterDefinition, dataType, GET_DATA_TYPE_METHOD_NAME, serviceTemplate, toscaServiceModel);
+ }
+
+ @Override
+ public boolean isTypeOf(CapabilityDefinition capabilityDefinition, String capabilityType,
+ ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel) {
+ return isTypeOf(capabilityDefinition, capabilityType, GET_CAPABILITY_TYPE_METHOD_NAME, serviceTemplate,
+ toscaServiceModel);
+ }
+
+ @Override
public List<RequirementAssignment> getRequirements(NodeTemplate nodeTemplate, String requirementId) {
List<RequirementAssignment> requirements = new ArrayList<>();
List<Map<String, RequirementAssignment>> requirementList = nodeTemplate.getRequirements();
@@ -225,9 +270,9 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
@Override
public Optional<NodeTemplate> getNodeTemplateById(ServiceTemplate serviceTemplate, String nodeTemplateId) {
- if ((serviceTemplate.getTopology_template() != null) && (serviceTemplate.getTopology_template()
- .getNode_templates() != null)
- && (serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId) != null)) {
+ if ((serviceTemplate.getTopology_template() != null) && (
+ serviceTemplate.getTopology_template().getNode_templates() != null) && (
+ serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId) != null)) {
return Optional.of(serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId));
}
return Optional.empty();
@@ -235,14 +280,14 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
@Override
public Optional<String> getSubstituteServiceTemplateName(String substituteNodeTemplateId,
- NodeTemplate substitutableNodeTemplate) {
+ NodeTemplate substitutableNodeTemplate) {
if (!isSubstitutableNodeTemplate(substitutableNodeTemplate)) {
return Optional.empty();
}
- if (substitutableNodeTemplate.getProperties() != null &&
- substitutableNodeTemplate.getProperties().get(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME)
- != null) {
+ if (substitutableNodeTemplate.getProperties() != null
+ && substitutableNodeTemplate.getProperties().get(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME)
+ != null) {
Object serviceTemplateFilter =
substitutableNodeTemplate.getProperties().get(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME);
if (serviceTemplateFilter instanceof Map) {
@@ -252,14 +297,14 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
return Optional.of(substituteServiceTemplate.toString());
}
}
- throw new CoreException(new ToscaInvalidSubstituteNodeTemplatePropertiesErrorBuilder(substituteNodeTemplateId)
- .build());
+ throw new CoreException(
+ new ToscaInvalidSubstituteNodeTemplatePropertiesErrorBuilder(substituteNodeTemplateId).build());
}
private void handleNoSubstituteServiceTemplate(String substituteNodeTemplateId, Object substituteServiceTemplate) {
if (substituteServiceTemplate == null) {
- throw new CoreException(new ToscaInvalidSubstituteNodeTemplatePropertiesErrorBuilder(substituteNodeTemplateId)
- .build());
+ throw new CoreException(
+ new ToscaInvalidSubstituteNodeTemplatePropertiesErrorBuilder(substituteNodeTemplateId).build());
}
}
@@ -285,9 +330,8 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
@Override
- public Optional<Map.Entry<String, NodeTemplate>> getSubstitutionMappedNodeTemplateByExposedReq(String substituteServiceTemplateFileName,
- ServiceTemplate substituteServiceTemplate,
- String requirementId) {
+ public Optional<Map.Entry<String, NodeTemplate>> getSubstitutionMappedNodeTemplateByExposedReq(
+ String substituteServiceTemplateFileName, ServiceTemplate substituteServiceTemplate, String requirementId) {
if (isSubstitutionServiceTemplate(substituteServiceTemplateFileName, substituteServiceTemplate)) {
Map<String, List<String>> substitutionMappingRequirements =
substituteServiceTemplate.getTopology_template().getSubstitution_mappings().getRequirements();
@@ -297,10 +341,8 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
String mappedNodeTemplateId = requirementMapping.get(0);
Optional<NodeTemplate> mappedNodeTemplate =
getNodeTemplateById(substituteServiceTemplate, mappedNodeTemplateId);
- mappedNodeTemplate.orElseThrow(
- () -> new CoreException(new ToscaInvalidEntryNotFoundErrorBuilder("Node Template",
- mappedNodeTemplateId)
- .build()));
+ mappedNodeTemplate.orElseThrow(() -> new CoreException(
+ new ToscaInvalidEntryNotFoundErrorBuilder("Node Template", mappedNodeTemplateId).build()));
Map.Entry<String, NodeTemplate> mappedNodeTemplateEntry = new Map.Entry<String, NodeTemplate>() {
@Override
public String getKey() {
@@ -329,7 +371,7 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
*/
@Override
public boolean isDesiredRequirementAssignment(RequirementAssignment requirementAssignment, String capability,
- String node, String relationship) {
+ String node, String relationship) {
if (isSameCapability(requirementAssignment, capability)) {
return false;
}
@@ -347,14 +389,14 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
private boolean isSameRelationship(RequirementAssignment requirementAssignment, String relationship) {
- return relationship != null && (requirementAssignment.getRelationship() == null || !requirementAssignment
- .getRelationship()
- .equals(relationship));
+ return relationship != null
+ && (requirementAssignment.getRelationship() == null
+ || !requirementAssignment.getRelationship().equals(relationship));
}
private boolean isSameRequirement(RequirementAssignment requirementAssignment, String node) {
return node != null && (requirementAssignment.getNode() == null || !requirementAssignment.getNode()
- .equals(node));
+ .equals(node));
}
private boolean isSameCapability(RequirementAssignment requirementAssignment, String capability) {
@@ -365,7 +407,7 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
@Override
public ToscaFlatData getFlatEntity(ToscaElementTypes elementType, String typeId, ServiceTemplate serviceTemplate,
- ToscaServiceModel toscaModel) {
+ ToscaServiceModel toscaModel) {
ToscaFlatData flatData = new ToscaFlatData();
flatData.setElementType(elementType);
@@ -380,7 +422,7 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
flatData.setFlatEntity(new DataType());
break;
default:
- throw new RuntimeException("Entity[" + elementType + "] id[" + typeId + "] flat not supported");
+ throw new SdcRuntimeException("Entity[" + elementType + "] id[" + typeId + "] flat not supported");
}
boolean isEntityFound =
@@ -399,10 +441,8 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
private <T> Optional<Boolean> isTypeExistInServiceTemplateHierarchy(String typeToMatch, String typeToSearch,
- String getTypesMethodName,
- ServiceTemplate serviceTemplate,
- ToscaServiceModel toscaServiceModel,
- Set<String> analyzedImportFiles)
+ String getTypesMethodName, ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel,
+ Set<String> analyzedImportFiles)
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Map<String, T> searchableTypes =
(Map<String, T>) serviceTemplate.getClass().getMethod(getTypesMethodName).invoke(serviceTemplate);
@@ -430,8 +470,7 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
private Optional<Boolean> isTypeExistInImports(String typeToMatch, String typeToSearch, String getTypesMethodName,
- ServiceTemplate serviceTemplate,
- ToscaServiceModel toscaServiceModel, Set<String> filesScanned)
+ ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel, Set<String> filesScanned)
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
List<Map<String, Import>> imports = serviceTemplate.getImports();
if (CollectionUtils.isEmpty(imports)) {
@@ -469,7 +508,7 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
private void handleImportWithNoFileEntry(Import anImport) {
if (Objects.isNull(anImport) || Objects.isNull(anImport.getFile())) {
- throw new RuntimeException("import without file entry");
+ throw new SdcRuntimeException("import without file entry");
}
}
@@ -486,12 +525,13 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
private boolean isSubstitutionServiceTemplate(String substituteServiceTemplateFileName,
- ServiceTemplate substituteServiceTemplate) {
+ ServiceTemplate substituteServiceTemplate) {
if (substituteServiceTemplate != null && substituteServiceTemplate.getTopology_template() != null
&& substituteServiceTemplate.getTopology_template().getSubstitution_mappings() != null) {
if (substituteServiceTemplate.getTopology_template().getSubstitution_mappings().getNode_type() == null) {
- throw new CoreException(new ToscaInvalidSubstitutionServiceTemplateErrorBuilder(substituteServiceTemplateFileName)
- .build());
+ throw new CoreException(
+ new ToscaInvalidSubstitutionServiceTemplateErrorBuilder(substituteServiceTemplateFileName)
+ .build());
}
return true;
}
@@ -500,8 +540,8 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
private boolean scanAnFlatEntity(ToscaElementTypes elementType, String typeId, ToscaFlatData flatData,
- ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel,
- List<String> filesScanned, int rootScanStartInx) {
+ ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel, List<String> filesScanned,
+ int rootScanStartInx) {
boolean entityFound =
@@ -526,8 +566,7 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
private boolean isFlatEntity(Map<String, Import> importMap, ToscaFlatData flatData, ServiceTemplate serviceTemplate,
- List<String> filesScanned, ToscaServiceModel toscaModel,
- ToscaElementTypes elementType, String typeId) {
+ List<String> filesScanned, ToscaServiceModel toscaModel, ToscaElementTypes elementType, String typeId) {
boolean found = false;
ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
for (Object importObject : importMap.values()) {
@@ -564,10 +603,8 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
private boolean enrichEntityFromCurrentServiceTemplate(ToscaElementTypes elementType, String typeId,
- ToscaFlatData flatData,
- ServiceTemplate serviceTemplate,
- ToscaServiceModel toscaModel,
- List<String> filesScanned, int rootScanStartInx) {
+ ToscaFlatData flatData, ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel,
+ List<String> filesScanned, int rootScanStartInx) {
switch (elementType) {
case CAPABILITY_TYPE:
if (enrichCapabilityType(elementType, typeId, flatData, serviceTemplate, toscaModel, filesScanned,
@@ -588,7 +625,7 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
break;
default:
- throw new RuntimeException("Entity[" + elementType + "] id[" + typeId + "] flat not supported");
+ throw new SdcRuntimeException("Entity[" + elementType + "] id[" + typeId + "] flat not supported");
}
return true;
@@ -597,8 +634,8 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
private boolean enrichNodeTypeInfo(ToscaElementTypes elementType, String typeId, ToscaFlatData flatData,
- ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel,
- List<String> filesScanned, int rootScanStartInx) {
+ ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel, List<String> filesScanned,
+ int rootScanStartInx) {
String derivedFrom;
if (serviceTemplate.getNode_types() != null && serviceTemplate.getNode_types().containsKey(typeId)) {
@@ -623,8 +660,8 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
private boolean enrichDataTypeInfo(ToscaElementTypes elementType, String typeId, ToscaFlatData flatData,
- ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel,
- List<String> filesScanned, int rootScanStartInx) {
+ ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel, List<String> filesScanned,
+ int rootScanStartInx) {
String derivedFrom;
if (serviceTemplate.getData_types() != null && serviceTemplate.getData_types().containsKey(typeId)) {
@@ -655,11 +692,11 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
private boolean enrichCapabilityType(ToscaElementTypes elementType, String typeId, ToscaFlatData flatData,
- ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel,
- List<String> filesScanned, int rootScanStartInx) {
+ ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel, List<String> filesScanned,
+ int rootScanStartInx) {
String derivedFrom;
if (serviceTemplate.getCapability_types() != null && serviceTemplate.getCapability_types()
- .containsKey(typeId)) {
+ .containsKey(typeId)) {
filesScanned.clear();
flatData.addInheritanceHierarchyType(typeId);
@@ -699,16 +736,6 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
- private InterfaceDefinitionType getInterfaceDefinitionType(String interfaceName, Object interfaceDefTypeObj) {
- Optional<InterfaceDefinitionType> interfaceDefinitionType = DataModelUtil.convertObjToInterfaceDefinition(
- interfaceName, interfaceDefTypeObj, InterfaceDefinitionType.class);
- if (!interfaceDefinitionType.isPresent()) {
- throw new CoreException(new CreateInterfaceObjectErrorBuilder("InterfaceDefinitionType", interfaceName,
- "Invalid interface object").build());
- }
- return interfaceDefinitionType.get();
- }
-
private void combineNodeTypeInterfaceInfo(NodeType sourceNodeType, NodeType targetNodeType) {
Optional<Map<String, Object>> interfaceNoMerge = combineInterfaceNoMerge(sourceNodeType, targetNodeType);
if (interfaceNoMerge.isPresent()) {
@@ -723,9 +750,9 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
for (Map.Entry<String, Object> sourceInterfaceDefEntry : sourceNodeType.getInterfaces().entrySet()) {
String interfaceName = sourceInterfaceDefEntry.getKey();
if (!MapUtils.isEmpty(targetNodeType.getInterfaces()) && targetNodeType.getInterfaces()
- .containsKey(interfaceName)) {
+ .containsKey(interfaceName)) {
combineInterfaces.put(interfaceName,
- combineInterfaceDefinition(interfaceName, sourceInterfaceDefEntry.getValue(),
+ combineInterfaceDefinition(sourceInterfaceDefEntry.getValue(),
targetNodeType.getInterfaces().get(interfaceName)));
} else {
combineInterfaces.put(sourceInterfaceDefEntry.getKey(), sourceInterfaceDefEntry.getValue());
@@ -758,18 +785,17 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
- private Object combineInterfaceDefinition(String interfaceName, Object sourceInterfaceDefType,
- Object targetInterfaceDefType) {
- InterfaceDefinitionType sourceInterface = getInterfaceDefinitionType(interfaceName, sourceInterfaceDefType);
- InterfaceDefinitionType targetInterface = getInterfaceDefinitionType(interfaceName, targetInterfaceDefType);
+ private Object combineInterfaceDefinition(Object sourceInterfaceDefType, Object targetInterfaceDefType) {
+ InterfaceDefinitionType sourceInterface = new InterfaceDefinitionType(sourceInterfaceDefType);
+ InterfaceDefinitionType targetInterface = new InterfaceDefinitionType(targetInterfaceDefType);
InterfaceDefinitionType combineInterface = new InterfaceDefinitionType();
combineInterface.setType(sourceInterface.getType());
combineInterface.setInputs(CommonMethods.mergeMaps(targetInterface.getInputs(), sourceInterface.getInputs()));
combineInterface.setOperations(
CommonMethods.mergeMaps(targetInterface.getOperations(), sourceInterface.getOperations()));
- Optional<Object> interfaceDefObject = DataModelUtil.convertInterfaceDefinitionTypeToObj(combineInterface);
- if( !interfaceDefObject.isPresent()){
+ Optional<Object> interfaceDefObject = combineInterface.convertInterfaceDefinitionTypeToToscaObj();
+ if (!interfaceDefObject.isPresent()) {
throw new SdcRuntimeException("Illegal Statement");
}
return interfaceDefObject.get();
@@ -785,7 +811,6 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
CommonMethods.mergeLists(targetDataType.getConstraints(), sourceDataType.getConstraints()));
}
-
private void combineCapabilityTypeInfo(CapabilityType sourceCapabilityType, CapabilityType targetCapabilityType) {
targetCapabilityType.setAttributes(
@@ -820,7 +845,7 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
*/
@Override
public NodeType createInitSubstitutionNodeType(ServiceTemplate substitutionServiceTemplate,
- String nodeTypeDerivedFromValue) {
+ String nodeTypeDerivedFromValue) {
NodeType substitutionNodeType = new NodeType();
substitutionNodeType.setDerived_from(nodeTypeDerivedFromValue);
substitutionNodeType.setDescription(substitutionServiceTemplate.getDescription());
@@ -830,7 +855,8 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
@Override
- public Map<String, PropertyDefinition> manageSubstitutionNodeTypeProperties(ServiceTemplate substitutionServiceTemplate) {
+ public Map<String, PropertyDefinition> manageSubstitutionNodeTypeProperties(
+ ServiceTemplate substitutionServiceTemplate) {
Map<String, PropertyDefinition> substitutionNodeTypeProperties = new HashMap<>();
Map<String, ParameterDefinition> properties = substitutionServiceTemplate.getTopology_template().getInputs();
if (properties == null) {
@@ -866,7 +892,8 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
- private Map<String, AttributeDefinition> manageSubstitutionNodeTypeAttributes(ServiceTemplate substitutionServiceTemplate) {
+ private Map<String, AttributeDefinition> manageSubstitutionNodeTypeAttributes(
+ ServiceTemplate substitutionServiceTemplate) {
Map<String, AttributeDefinition> substitutionNodeTypeAttributes = new HashMap<>();
Map<String, ParameterDefinition> attributes = substitutionServiceTemplate.getTopology_template().getOutputs();
if (attributes == null) {
@@ -906,35 +933,15 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
*/
@Override
public boolean isRequirementExistInNodeTemplate(NodeTemplate nodeTemplate, String requirementId,
- RequirementAssignment requirementAssignment) {
+ RequirementAssignment requirementAssignment) {
List<Map<String, RequirementAssignment>> nodeTemplateRequirements = nodeTemplate.getRequirements();
return nodeTemplateRequirements != null && nodeTemplateRequirements.stream().anyMatch(
requirement -> requirement.containsKey(requirementId) && DataModelUtil.compareRequirementAssignment(
requirementAssignment, requirement.get(requirementId)));
}
- @Override
- public boolean isTypeOf(InterfaceDefinitionType interfaceDefinition, String interfaceType,
- ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel) {
- return isTypeOf(interfaceDefinition, interfaceType, GET_INTERFACE_TYPE_METHOD_NAME, serviceTemplate,
- toscaServiceModel);
- }
-
- @Override
- public boolean isTypeOf(DefinitionOfDataType parameterDefinition, String dataType, ServiceTemplate serviceTemplate,
- ToscaServiceModel toscaServiceModel) {
- return isTypeOf(parameterDefinition, dataType, GET_DATA_TYPE_METHOD_NAME, serviceTemplate, toscaServiceModel);
- }
-
- @Override
- public boolean isTypeOf(CapabilityDefinition capabilityDefinition, String capabilityType,
- ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel) {
- return isTypeOf(capabilityDefinition, capabilityType, GET_CAPABILITY_TYPE_METHOD_NAME, serviceTemplate, toscaServiceModel);
- }
-
-
private <T> boolean isTypeOf(T object, String type, String getTypesMethodName, ServiceTemplate serviceTemplate,
- ToscaServiceModel toscaServiceModel) {
+ ToscaServiceModel toscaServiceModel) {
if (object == null) {
return false;
}
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/ToscaModelTest.java b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/ToscaModelTest.java
index 2833cc456d..88e8461299 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/ToscaModelTest.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/ToscaModelTest.java
@@ -25,9 +25,35 @@ import java.util.Map;
import java.util.Optional;
import org.junit.Assert;
import org.junit.Test;
-import org.onap.sdc.tosca.datatypes.model.*;
+import org.onap.sdc.tosca.datatypes.model.ArtifactType;
+import org.onap.sdc.tosca.datatypes.model.AttributeDefinition;
+import org.onap.sdc.tosca.datatypes.model.CapabilityAssignment;
+import org.onap.sdc.tosca.datatypes.model.CapabilityDefinition;
+import org.onap.sdc.tosca.datatypes.model.CapabilityFilter;
+import org.onap.sdc.tosca.datatypes.model.Constraint;
+import org.onap.sdc.tosca.datatypes.model.Directive;
+import org.onap.sdc.tosca.datatypes.model.Implementation;
+import org.onap.sdc.tosca.datatypes.model.Import;
+import org.onap.sdc.tosca.datatypes.model.InterfaceDefinitionTemplate;
+import org.onap.sdc.tosca.datatypes.model.InterfaceDefinitionType;
+import org.onap.sdc.tosca.datatypes.model.InterfaceType;
+import org.onap.sdc.tosca.datatypes.model.NodeFilter;
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
+import org.onap.sdc.tosca.datatypes.model.NodeType;
+import org.onap.sdc.tosca.datatypes.model.OperationDefinition;
+import org.onap.sdc.tosca.datatypes.model.OperationDefinitionTemplate;
+import org.onap.sdc.tosca.datatypes.model.OperationDefinitionType;
+import org.onap.sdc.tosca.datatypes.model.ParameterDefinition;
+import org.onap.sdc.tosca.datatypes.model.PropertyDefinition;
+import org.onap.sdc.tosca.datatypes.model.PropertyType;
import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
-import org.onap.sdc.tosca.datatypes.model.extension.*;
+import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
+import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.onap.sdc.tosca.datatypes.model.SubstitutionMapping;
+import org.onap.sdc.tosca.datatypes.model.TopologyTemplate;
+import org.onap.sdc.tosca.datatypes.model.extension.RequirementAssignmentExt;
+import org.onap.sdc.tosca.datatypes.model.extension.SubstitutionFilter;
+import org.onap.sdc.tosca.datatypes.model.extension.SubstitutionMappingExt;
import org.onap.sdc.tosca.datatypes.model.heatextend.ParameterDefinitionExt;
import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
import org.onap.sdc.tosca.services.YamlUtil;
@@ -72,6 +98,7 @@ public class ToscaModelTest {
metadata.put("Template_author", "OPENECOMP");
metadata.put(ToscaConstants.ST_METADATA_TEMPLATE_NAME, "Test");
metadata.put("Template_version", "1.0.0");
+ serviceTemplate.setMetadata(metadata);
serviceTemplate.setTosca_definitions_version("tosca_simple_yaml_1_0_0");
serviceTemplate.setDescription("testing desc tosca service template");
@@ -156,13 +183,13 @@ public class ToscaModelTest {
nodeType.setRequirements(reqList);
- Map<String, CapabilityDefinition> capsDef = new HashMap<>();
CapabilityDefinition capdef = new CapabilityDefinition();
capdef.setType("tosca.cap");
List<String> vvSource = new ArrayList<>();
vvSource.add("node1");
vvSource.add("node2");
capdef.setValid_source_types(vvSource);
+ Map<String, CapabilityDefinition> capsDef = new HashMap<>();
capsDef.put("cap1", capdef);
nodeType.setCapabilities(capsDef);
@@ -172,7 +199,6 @@ public class ToscaModelTest {
TopologyTemplate topologyTemplate = new TopologyTemplate();
topologyTemplate.setDescription("topologi template descroption");
- Map<String, ParameterDefinition> inputs = new HashMap<>();
ParameterDefinition paramDef = new ParameterDefinition();
paramDef.setType(PropertyType.STRING.getDisplayName());
paramDef.setDescription("desc");
@@ -187,10 +213,10 @@ public class ToscaModelTest {
paramConstraint.add(paramConst1);
paramConstraint.add(paramConst2);
paramDef.setConstraints(paramConstraint);
+ Map<String, ParameterDefinition> inputs = new HashMap<>();
inputs.put("inParam1", paramDef);
topologyTemplate.setInputs(inputs);
- Map<String, NodeTemplate> nodeTemplates = new HashMap<>();
NodeTemplate nodeTemplate = new NodeTemplate();
nodeTemplate.setType("nodeTypeRef");
List<String> directives = new ArrayList<>();
@@ -204,6 +230,7 @@ public class ToscaModelTest {
Map<String, Object> nodeTemplateAtts = new HashMap<>();
nodeTemplateAtts.put("att1", "att1Val");
nodeTemplateAtts.put("att2", "{ get_input: my_mysql_rootpw }");
+ Map<String, NodeTemplate> nodeTemplates = new HashMap<>();
nodeTemplate.setAttributes(nodeTemplateAtts);
@@ -215,7 +242,6 @@ public class ToscaModelTest {
reqAssOccurrences[0] = 1;
reqAssOccurrences[1] = 2;
reqAssignment1.setOccurrences(reqAssOccurrences);
- NodeFilter reqNodeFilter = new NodeFilter();
List<Constraint> propConstraint1 = new ArrayList<>();
Constraint propConst1 = new Constraint();
propConst1.setGreater_or_equal(9);
@@ -232,6 +258,7 @@ public class ToscaModelTest {
propsMap.put("propName1", propConstraint1);
propsMap.put("propName2", propConstraint2);
nodeFilterProp.add(propsMap);
+ NodeFilter reqNodeFilter = new NodeFilter();
reqNodeFilter.setProperties(nodeFilterProp);
reqAssignment1.setNode_filter(reqNodeFilter);
@@ -247,7 +274,6 @@ public class ToscaModelTest {
nodeTemplate.getRequirements().add(nodeTemplateRequirement1);
nodeTemplate.getRequirements().add(nodeTemplateRequirement2);
- Map<String, CapabilityAssignment> nodeTemplateCapability = new HashMap<>();
CapabilityAssignment capAss = new CapabilityAssignment();
Map<String, Object> capProps = new HashMap<>();
capProps.put("num_cpus", "{ get_input: cpus }");
@@ -255,10 +281,10 @@ public class ToscaModelTest {
Map<String, Object> capAtts = new HashMap<>();
capAtts.put("num_cpus", "66");
capAss.setAttributes(capAtts);
+ Map<String, CapabilityAssignment> nodeTemplateCapability = new HashMap<>();
nodeTemplateCapability.put("cap1", capAss);
nodeTemplate.setCapabilities(nodeTemplateCapability);
- NodeFilter nodeTemplateNodeFilter = new NodeFilter();
List<Map<String, List<Constraint>>> nodeFilterProp2 = new ArrayList<>();
Map<String, List<Constraint>> propsMap2 = new HashMap<>();
Constraint c1 = new Constraint();
@@ -267,6 +293,7 @@ public class ToscaModelTest {
consList.add(c1);
propsMap2.put("test1", consList);
nodeFilterProp2.add(propsMap2);
+ NodeFilter nodeTemplateNodeFilter = new NodeFilter();
nodeTemplateNodeFilter.setProperties(nodeFilterProp2);
nodeTemplate.setNode_filter(nodeTemplateNodeFilter);
nodeTemplates.put("firatNodeTemplate", nodeTemplate);
@@ -275,10 +302,10 @@ public class ToscaModelTest {
SubstitutionMapping subMap = new SubstitutionMapping();
subMap.setNode_type("myNodeType.node");
Map<String, List<String>> mapCapabilities = new HashMap<>();
- List<String> NodeCap = new ArrayList<>();
- NodeCap.add("database");
- NodeCap.add("database_endpoint");
- mapCapabilities.put("database_endpoint", NodeCap);
+ List<String> nodeCap = new ArrayList<>();
+ nodeCap.add("database");
+ nodeCap.add("database_endpoint");
+ mapCapabilities.put("database_endpoint", nodeCap);
subMap.setCapabilities(mapCapabilities);
topologyTemplate.setSubstitution_mappings(subMap);
serviceTemplate.setTopology_template(topologyTemplate);
@@ -291,8 +318,7 @@ public class ToscaModelTest {
@Test
public void testYamlToServiceTemplateObj() throws IOException {
- ServiceTemplate serviceTemplateFromYaml =
- getServiceTemplate(BASE_DIR + ST);
+ ServiceTemplate serviceTemplateFromYaml = getServiceTemplate(BASE_DIR + ST);
Assert.assertNotNull(serviceTemplateFromYaml);
}
@@ -303,7 +329,7 @@ public class ToscaModelTest {
InterfaceType expectedInterfaceType = createInterfaceType();
- Map<String, InterfaceType> interfaceTypes = DataModelUtil.getInterfaceTypes(serviceTemplateWithOperation);
+ Map<String, InterfaceType> interfaceTypes = serviceTemplateWithOperation.getNormalizeInterfaceTypes();
Assert.assertEquals(1, interfaceTypes.size());
InterfaceType actualInterfaceType = interfaceTypes.get(INTERFACE_ID);
Assert.assertEquals(expectedInterfaceType, actualInterfaceType);
@@ -316,9 +342,10 @@ public class ToscaModelTest {
ServiceTemplate serviceTemplateWithOperation = getServiceTemplate(BASE_DIR + ST_WITH_OPERATIONS);
OperationDefinition operationDefinition = createOperationDefinition();
-
- DataModelUtil.addInterfaceOperation(serviceTemplateWithInterface, INTERFACE_ID, OPERATION_START,
- operationDefinition);
+ InterfaceType normalizeInterfaceType =
+ serviceTemplateWithInterface.getNormalizeInterfaceTypes().get(INTERFACE_ID);
+ normalizeInterfaceType.addOperation(OPERATION_START, operationDefinition);
+ serviceTemplateWithInterface.addInterfaceType(INTERFACE_ID, normalizeInterfaceType);
String expectedServiceTemplate = yamlUtil.objectToYaml(serviceTemplateWithOperation);
String actualServiceTemplate = yamlUtil.objectToYaml(serviceTemplateWithInterface);
Assert.assertEquals(expectedServiceTemplate, actualServiceTemplate);
@@ -330,7 +357,7 @@ public class ToscaModelTest {
ServiceTemplate serviceTemplateWithOperation = getServiceTemplate(BASE_DIR + ST_WITH_OPERATIONS);
InterfaceType interfaceType = createInterfaceType();
- Optional<Object> interfaceAsObj = DataModelUtil.convertInterfaceTypeToObj(interfaceType);
+ Optional<Object> interfaceAsObj = interfaceType.convertInterfaceTypeToToscaObj();
Assert.assertTrue(interfaceAsObj.isPresent());
Map<String, Object> interfaceTypes = new HashMap<>();
@@ -345,14 +372,10 @@ public class ToscaModelTest {
@Test
public void testObjToInterfaceTypeConversion() throws IOException, ReflectiveOperationException {
ServiceTemplate serviceTemplateWithOperation = getServiceTemplate(BASE_DIR + ST_WITH_OPERATIONS);
- Map<String, Object> interfaceTypes = serviceTemplateWithOperation.getInterface_types();
- Object interfaceObj = interfaceTypes.get(INTERFACE_ID);
- Optional<InterfaceType> actualInterfaceType =
- DataModelUtil.convertObjToInterfaceType(INTERFACE_ID, interfaceObj);
-
- Assert.assertTrue(actualInterfaceType.isPresent());
+ Map<String, InterfaceType> interfaceTypes = serviceTemplateWithOperation.getNormalizeInterfaceTypes();
+ InterfaceType actualInterfaceType = interfaceTypes.get(INTERFACE_ID);
InterfaceType expectedInterfaceType = createInterfaceType();
- Assert.assertEquals(expectedInterfaceType, actualInterfaceType.get());
+ Assert.assertEquals(expectedInterfaceType, actualInterfaceType);
}
@Test
@@ -362,33 +385,22 @@ public class ToscaModelTest {
Map<String, Object> interfaces = nodeTypeWithInterface.getInterfaces();
Object interfaceObj = interfaces.get(INTERFACE_ID);
- Optional<? extends InterfaceDefinition> actualInterfaceDefinition = DataModelUtil
- .convertObjToInterfaceDefinition(
- INTERFACE_ID, interfaceObj,
- InterfaceDefinitionType.class);
-
- Assert.assertTrue(actualInterfaceDefinition.isPresent());
-
+ InterfaceDefinitionType actualInterfaceDefinition = new InterfaceDefinitionType(interfaceObj);
InterfaceDefinitionType expectedInterfaceDefinitionType = createInterfaceDefinitionType();
- Assert.assertEquals(expectedInterfaceDefinitionType, actualInterfaceDefinition.get());
+ Assert.assertEquals(expectedInterfaceDefinitionType, actualInterfaceDefinition);
}
@Test
- public void testObjToInterfaceDefinitionTemplateConversion() throws IOException, ReflectiveOperationException {
+ public void testObjToInterfaceDefinitionTemplateConversion() throws IOException {
ServiceTemplate serviceTemplateWithInterfaceDef = getServiceTemplate(BASE_DIR + ST_WITH_INTERFACE_DEF);
NodeTemplate nodeTemplateWithInterface =
DataModelUtil.getNodeTemplate(serviceTemplateWithInterfaceDef, NODE_TEMPLATE_ID);
Map<String, Object> interfaces = nodeTemplateWithInterface.getInterfaces();
Object interfaceObj = interfaces.get(INTERFACE_ID);
- Optional<? extends InterfaceDefinition> actualInterfaceDefinition = DataModelUtil
- .convertObjToInterfaceDefinition(
- INTERFACE_ID, interfaceObj,
- InterfaceDefinitionTemplate.class);
-
- Assert.assertTrue(actualInterfaceDefinition.isPresent());
+ InterfaceDefinitionTemplate actualInterfaceDefinition = new InterfaceDefinitionTemplate(interfaceObj);
InterfaceDefinitionTemplate expectedInterfaceDefinitionTemplate = createInterfaceDefinitionTemplate();
- Assert.assertEquals(expectedInterfaceDefinitionTemplate, actualInterfaceDefinition.get());
+ Assert.assertEquals(expectedInterfaceDefinitionTemplate, actualInterfaceDefinition);
}
@Test
@@ -416,19 +428,17 @@ public class ToscaModelTest {
DataModelUtil.getNodeTemplateRequirements(firstNodeTemplate);
Object req1 = nodeTemplateRequirements.get(REQ1);
- Assert.assertEquals(true, req1 instanceof org.onap.sdc.tosca.datatypes.model.extension.RequirementAssignment);
- Assert.assertNotNull(((org.onap.sdc.tosca.datatypes.model.extension.RequirementAssignment)req1).getService_filter());
+ Assert.assertTrue(req1 instanceof RequirementAssignmentExt);
+ Assert.assertNotNull(((RequirementAssignmentExt) req1).getService_filter());
List<Map<String, List<Constraint>>> properties =
- ((org.onap.sdc.tosca.datatypes.model.extension.RequirementAssignment) req1).getService_filter()
- .getProperties();
+ ((RequirementAssignmentExt) req1).getService_filter().getProperties();
Assert.assertNotNull(properties);
List<Constraint> vmdNameConstrain = properties.get(0).get(VMD_NAME);
Assert.assertNotNull(vmdNameConstrain);
Assert.assertNotNull(vmdNameConstrain.get(0).getEqual());
List<Map<String, CapabilityFilter>> capabilities =
- ((org.onap.sdc.tosca.datatypes.model.extension.RequirementAssignment) req1).getService_filter()
- .getCapabilities();
+ ((RequirementAssignmentExt) req1).getService_filter().getCapabilities();
Assert.assertNotNull(capabilities);
CapabilityFilter capabilityFilter = capabilities.get(0).get(DIRECTOR);
Assert.assertNotNull(capabilityFilter);
@@ -436,13 +446,11 @@ public class ToscaModelTest {
Object req2 = nodeTemplateRequirements.get(REQ2);
- Assert.assertEquals(true, req2 instanceof org.onap.sdc.tosca.datatypes.model.extension.RequirementAssignment);
- Assert.assertNotNull(((org.onap.sdc.tosca.datatypes.model.extension.RequirementAssignment)req2).getService_filter());
- Object tosca_id =
- ((org.onap.sdc.tosca.datatypes.model.extension.RequirementAssignment) req2).getService_filter()
- .getTosca_id();
- Assert.assertNotNull(tosca_id);
- Assert.assertEquals(SERVICE_FILTER_TOSCA_ID, tosca_id.toString());
+ Assert.assertTrue(req2 instanceof RequirementAssignmentExt);
+ Assert.assertNotNull(((RequirementAssignmentExt) req2).getService_filter());
+ Object toscaId = ((RequirementAssignmentExt) req2).getService_filter().getTosca_id();
+ Assert.assertNotNull(toscaId);
+ Assert.assertEquals(SERVICE_FILTER_TOSCA_ID, toscaId.toString());
String serviceTemplateYaml = toscaExtensionYamlUtil.objectToYaml(serviceTemplateWithServiceFilter);
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java
index 0f79ed05d6..269f44b28f 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java
@@ -16,13 +16,46 @@
package org.openecomp.sdc.tosca.services.impl;
-import org.junit.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.runners.MockitoJUnitRunner;
-import org.onap.sdc.tosca.datatypes.model.*;
+import org.onap.sdc.tosca.datatypes.model.CapabilityDefinition;
+import org.onap.sdc.tosca.datatypes.model.CapabilityType;
+import org.onap.sdc.tosca.datatypes.model.DataType;
+import org.onap.sdc.tosca.datatypes.model.DefinitionOfDataType;
+import org.onap.sdc.tosca.datatypes.model.Import;
+import org.onap.sdc.tosca.datatypes.model.InterfaceDefinitionType;
+import org.onap.sdc.tosca.datatypes.model.InterfaceType;
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
+import org.onap.sdc.tosca.datatypes.model.NodeType;
+import org.onap.sdc.tosca.datatypes.model.OperationDefinitionType;
+import org.onap.sdc.tosca.datatypes.model.ParameterDefinition;
+import org.onap.sdc.tosca.datatypes.model.PropertyDefinition;
+import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
+import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
+import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.onap.sdc.tosca.datatypes.model.SubstitutionMapping;
+import org.onap.sdc.tosca.datatypes.model.TopologyTemplate;
import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.tosca.TestUtil;
@@ -30,24 +63,22 @@ import org.openecomp.sdc.tosca.datatypes.ToscaElementTypes;
import org.openecomp.sdc.tosca.datatypes.ToscaFlatData;
import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
-import org.openecomp.sdc.tosca.services.DataModelUtil;
import org.openecomp.sdc.tosca.services.ToscaAnalyzerService;
import org.openecomp.sdc.tosca.services.ToscaConstants;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.*;
-
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.when;
-
@RunWith(MockitoJUnitRunner.class)
public class ToscaAnalyzerServiceImplTest {
- public static final String CAPABILITY_TYPE_A = "capabilityTypeA";
- public static final String CAPABILITY_TYPE_B = "capabilityTypeB";
- public static final String TOSCA_CAPABILITIES_ROOT = "tosca.capabilities.Root";
+ private static final String CAPABILITY_TYPE_A = "capabilityTypeA";
+ private static final String CAPABILITY_TYPE_B = "capabilityTypeB";
+ private static final String TOSCA_CAPABILITIES_ROOT = "tosca.capabilities.Root";
+ private static final String CMAUI_IMAGE_EXTEND = "org.openecomp.resource.vfc.nodes.heat.cmaui_image_extend";
+ private static final String STANDARD_INTERFACE_KEY = "Standard";
+ private static final String TOSCA_LIFECYCLE_STANDARD = "tosca.interfaces.node.lifecycle.Standard";
+ private static final String CMAUI_INTERFACE_TEST =
+ "org.openecomp.resource.vfc.nodes.heat.cmaui_image_interfaceTest";
+ private static final String CMAUI_IMAGE_EXTEND2 = "org.openecomp.resource.vfc.nodes.heat.cmaui_image_extend2";
/*
Dictionary:
@@ -88,7 +119,8 @@ public class ToscaAnalyzerServiceImplTest {
public void testGetFlatEntityNotFound() throws Exception {
thrown.expect(CoreException.class);
thrown.expectMessage(
- "Entity Type 'org.openecomp.resource.vfc.notFound' or one of its derivedFrom type hierarchy, is not defined in tosca service model");
+ "Entity Type 'org.openecomp.resource.vfc.notFound' or one of its derivedFrom type "
+ + "hierarchy, is not defined in tosca service model");
ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
try (InputStream yamlFile = toscaExtensionYamlUtil.loadYamlFileIs(
"/mock/analyzerService/NestedServiceTemplateReqTest.yaml")) {
@@ -141,12 +173,10 @@ public class ToscaAnalyzerServiceImplTest {
List<String> inheritanceHierarchyType = flatData.getInheritanceHierarchyType();
Assert.assertNotNull(inheritanceHierarchyType);
Assert.assertEquals(4, inheritanceHierarchyType.size());
- Assert.assertEquals(true,
- inheritanceHierarchyType.contains("org.openecomp.resource.vfc.nodes.heat.cmaui_image"));
- Assert.assertEquals(true,
- inheritanceHierarchyType.contains("org.openecomp.resource.vfc.nodes.heat.nova.Server"));
- Assert.assertEquals(true, inheritanceHierarchyType.contains("tosca.nodes.Compute"));
- Assert.assertEquals(true, inheritanceHierarchyType.contains("tosca.nodes.Root"));
+ Assert.assertTrue(inheritanceHierarchyType.contains("org.openecomp.resource.vfc.nodes.heat.cmaui_image"));
+ Assert.assertTrue(inheritanceHierarchyType.contains("org.openecomp.resource.vfc.nodes.heat.nova.Server"));
+ Assert.assertTrue(inheritanceHierarchyType.contains("tosca.nodes.Compute"));
+ Assert.assertTrue(inheritanceHierarchyType.contains("tosca.nodes.Root"));
}
private void checkNodeTypeFlatEntity(ToscaFlatData flatData) {
@@ -168,25 +198,20 @@ public class ToscaAnalyzerServiceImplTest {
ServiceTemplate serviceTemplateFromYaml =
toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
- ToscaFlatData flatData = toscaAnalyzerService.getFlatEntity(ToscaElementTypes.NODE_TYPE,
- "org.openecomp.resource.vfc.nodes.heat.cmaui_image_extend", serviceTemplateFromYaml,
- toscaServiceModel);
+ ToscaFlatData flatData = toscaAnalyzerService.getFlatEntity(ToscaElementTypes.NODE_TYPE, CMAUI_IMAGE_EXTEND,
+ serviceTemplateFromYaml, toscaServiceModel);
Assert.assertNotNull(flatData);
Assert.assertNotNull(flatData.getFlatEntity());
NodeType flatEntity = (NodeType) flatData.getFlatEntity();
Assert.assertNotNull(flatEntity.getInterfaces());
- Object standardInterfaceObj = flatEntity.getInterfaces().get("Standard");
+ Object standardInterfaceObj = flatEntity.getInterfaces().get(STANDARD_INTERFACE_KEY);
Assert.assertNotNull(standardInterfaceObj);
- Optional<InterfaceDefinitionType> standardInterface = DataModelUtil
- .convertObjToInterfaceDefinition("Standard",
- standardInterfaceObj,
- InterfaceDefinitionType.class);
- Assert.assertEquals(true, standardInterface.isPresent());
- Assert.assertEquals(2, standardInterface.get().getInputs().size());
- Assert.assertEquals(3, standardInterface.get().getOperations().size());
+ InterfaceDefinitionType standardInterface = new InterfaceDefinitionType(standardInterfaceObj);
+ Assert.assertEquals(2, standardInterface.getInputs().size());
+ Assert.assertEquals(3, standardInterface.getOperations().size());
OperationDefinitionType createOperation = toscaExtensionYamlUtil.yamlToObject(
- toscaExtensionYamlUtil.objectToYaml(standardInterface.get().getOperations().get("create")),
+ toscaExtensionYamlUtil.objectToYaml(standardInterface.getOperations().get("create")),
OperationDefinitionType.class);
Assert.assertEquals(2, createOperation.getInputs().size());
@@ -261,11 +286,11 @@ public class ToscaAnalyzerServiceImplTest {
Object[] occurences = new Object[] {0, "UNBOUNDED"};
rd.setOccurrences(occurences);
- RequirementDefinition rd1 = new RequirementDefinition();
rd.setCapability("tosca.capabilities.network.Bindable");
rd.setNode(null);
rd.setRelationship("tosca.relationships.network.BindsTo");
Object[] occurences1 = new Object[] {1, 1};
+ RequirementDefinition rd1 = new RequirementDefinition();
rd1.setOccurrences(occurences1);
Map<String, RequirementDefinition> nodeTypeRequirementDefinition = new HashMap<>();
@@ -285,8 +310,8 @@ public class ToscaAnalyzerServiceImplTest {
List<Map<String, RequirementDefinition>> exposedRequirements = toscaAnalyzerService
.calculateExposedRequirements(
- nodeTypeRequirementsDefinition,
- nodeTemplateRequirementsAssignment);
+ nodeTypeRequirementsDefinition,
+ nodeTemplateRequirementsAssignment);
Assert.assertEquals(1, exposedRequirements.size());
}
@@ -299,11 +324,11 @@ public class ToscaAnalyzerServiceImplTest {
Object[] occurences = new Object[] {0, "UNBOUNDED"};
rd.setOccurrences(occurences);
- RequirementDefinition rd1 = new RequirementDefinition();
rd.setCapability("tosca.capabilities.network.Bindable");
rd.setNode(null);
rd.setRelationship("tosca.relationships.network.BindsTo");
Object[] occurences1 = new Object[] {1, 1};
+ RequirementDefinition rd1 = new RequirementDefinition();
rd1.setOccurrences(occurences1);
Map<String, RequirementDefinition> nodeTypeRequirementDefinition = new HashMap<>();
@@ -323,8 +348,8 @@ public class ToscaAnalyzerServiceImplTest {
List<Map<String, RequirementDefinition>> exposedRequirements = toscaAnalyzerService
.calculateExposedRequirements(
- nodeTypeRequirementsDefinition,
- nodeTemplateRequirementsAssignment);
+ nodeTypeRequirementsDefinition,
+ nodeTemplateRequirementsAssignment);
Assert.assertEquals(1, exposedRequirements.size());
}
@@ -334,11 +359,11 @@ public class ToscaAnalyzerServiceImplTest {
CapabilityDefinition cd = new CapabilityDefinition();
cd.setType("tosca.capabilities.Scalable");
nodeTypeCapabilitiesDefinition.put("tosca.capabilities.network.Bindable_pd_server", cd);
- Map<String, RequirementAssignment> nodeTemplateRequirementsAssignment = new HashMap<>();
RequirementAssignment ra = new RequirementAssignment();
ra.setCapability("tosca.capabilities.network.Bindable");
ra.setNode("pd_server");
ra.setRelationship("tosca.relationships.network.BindsTo");
+ Map<String, RequirementAssignment> nodeTemplateRequirementsAssignment = new HashMap<>();
nodeTemplateRequirementsAssignment.put("binding", ra);
Map<String, Map<String, RequirementAssignment>> fullFilledRequirementsDefinition = new HashMap<>();
fullFilledRequirementsDefinition.put("pd_server", nodeTemplateRequirementsAssignment);
@@ -366,17 +391,17 @@ public class ToscaAnalyzerServiceImplTest {
NodeTemplate port0 = serviceTemplateFromYaml.getTopology_template().getNode_templates().get("cmaui_port_0");
//Test With Empty requirementId
- Assert.assertEquals(false, toscaAnalyzerService.isRequirementExistInNodeTemplate(port0, "", ra));
+ Assert.assertFalse(toscaAnalyzerService.isRequirementExistInNodeTemplate(port0, "", ra));
//Test With valid requirementId
- Assert.assertEquals(true, toscaAnalyzerService.isRequirementExistInNodeTemplate(port0, "binding", ra));
+ Assert.assertTrue(toscaAnalyzerService.isRequirementExistInNodeTemplate(port0, "binding", ra));
//Test With invalid requirement assignment
RequirementAssignment ra1 = new RequirementAssignment();
ra1.setCapability("tosca.capabilities.network.Bindable1");
ra1.setNode("server_cmaui1");
ra1.setRelationship("tosca.relationships.network.BindsTo1");
- Assert.assertEquals(false, toscaAnalyzerService.isRequirementExistInNodeTemplate(port0, "binding", ra1));
+ Assert.assertFalse(toscaAnalyzerService.isRequirementExistInNodeTemplate(port0, "binding", ra1));
}
}
@@ -411,22 +436,23 @@ public class ToscaAnalyzerServiceImplTest {
ServiceTemplate emptyServiceTemplate = new ServiceTemplate();
Optional<NodeTemplate> nodeTemplate =
toscaAnalyzerService.getNodeTemplateById(emptyServiceTemplate, "test_net222");
- assertEquals(false, nodeTemplate.isPresent());
+ assertFalse(nodeTemplate.isPresent());
ServiceTemplate mainServiceTemplate =
toscaServiceModel.getServiceTemplates().get(toscaServiceModel.getEntryDefinitionServiceTemplate());
nodeTemplate = toscaAnalyzerService.getNodeTemplateById(mainServiceTemplate, "test_net");
- assertEquals(true, nodeTemplate.isPresent());
+ assertTrue(nodeTemplate.isPresent());
nodeTemplate = toscaAnalyzerService.getNodeTemplateById(mainServiceTemplate, "test_net222");
- assertEquals(false, nodeTemplate.isPresent());
+ assertFalse(nodeTemplate.isPresent());
}
@Test
public void testGetSubstituteServiceTemplateName() throws Exception {
thrown.expect(CoreException.class);
thrown.expectMessage(
- "Invalid Substitute Node Template invalid2, mandatory map property service_template_filter with mandatory key substitute_service_template must be defined.");
+ "Invalid Substitute Node Template invalid2, mandatory map property service_template_filter "
+ + "with mandatory key substitute_service_template must be defined.");
Optional<String> substituteServiceTemplateName;
@@ -434,28 +460,28 @@ public class ToscaAnalyzerServiceImplTest {
toscaServiceModel.getServiceTemplates().get(toscaServiceModel.getEntryDefinitionServiceTemplate());
Optional<NodeTemplate> notSubstitutableNodeTemplate =
toscaAnalyzerService.getNodeTemplateById(mainServiceTemplate, "test_net");
- assertEquals(true, notSubstitutableNodeTemplate.isPresent());
+ assertTrue(notSubstitutableNodeTemplate.isPresent());
if (notSubstitutableNodeTemplate.isPresent()) {
substituteServiceTemplateName = toscaAnalyzerService.getSubstituteServiceTemplateName("test_net",
notSubstitutableNodeTemplate.get());
- assertEquals(false, substituteServiceTemplateName.isPresent());
+ assertFalse(substituteServiceTemplateName.isPresent());
}
Optional<NodeTemplate> substitutableNodeTemplate =
toscaAnalyzerService.getNodeTemplateById(mainServiceTemplate, "test_nested");
- assertEquals(true, substitutableNodeTemplate.isPresent());
+ assertTrue(substitutableNodeTemplate.isPresent());
if (substitutableNodeTemplate.isPresent()) {
substituteServiceTemplateName = toscaAnalyzerService.getSubstituteServiceTemplateName("test_nested",
substitutableNodeTemplate.get());
- assertEquals(true, substituteServiceTemplateName.isPresent());
+ assertTrue(substituteServiceTemplateName.isPresent());
assertEquals("nestedServiceTemplate.yaml", substituteServiceTemplateName.get());
}
NodeTemplate invalidSubstitutableNodeTemplate1 = new NodeTemplate();
substituteServiceTemplateName =
toscaAnalyzerService.getSubstituteServiceTemplateName("invalid1", invalidSubstitutableNodeTemplate1);
- assertEquals(false, substituteServiceTemplateName.isPresent());
+ assertFalse(substituteServiceTemplateName.isPresent());
substitutableNodeTemplate.ifPresent(nodeTemplate -> {
Object serviceTemplateFilter =
@@ -508,12 +534,13 @@ public class ToscaAnalyzerServiceImplTest {
ServiceTemplate nestedServiceTemplateFromYaml =
toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
- Optional<Map.Entry<String, NodeTemplate>> mappedNodeTemplate = toscaAnalyzerService
- .getSubstitutionMappedNodeTemplateByExposedReq(
- "NestedServiceTemplateSubstituteTest.yaml",
- nestedServiceTemplateFromYaml,
- "local_storage_server_cmaui");
- assertEquals(true, mappedNodeTemplate.isPresent());
+ Optional<Map.Entry<String, NodeTemplate>> mappedNodeTemplate =
+ toscaAnalyzerService.getSubstitutionMappedNodeTemplateByExposedReq(
+ "NestedServiceTemplateSubstituteTest.yaml",
+ nestedServiceTemplateFromYaml,
+ "local_storage_server_cmaui");
+
+ assertTrue(mappedNodeTemplate.isPresent());
mappedNodeTemplate.ifPresent(stringNodeTemplateEntry -> {
assertEquals("server_cmaui", stringNodeTemplateEntry.getKey());
assertNotNull(stringNodeTemplateEntry.getValue());
@@ -522,7 +549,7 @@ public class ToscaAnalyzerServiceImplTest {
mappedNodeTemplate = toscaAnalyzerService.getSubstitutionMappedNodeTemplateByExposedReq(
"NestedServiceTemplateSubstituteTest.yaml", nestedServiceTemplateFromYaml,
"link_cmaui_port_invalid");
- assertEquals(true, mappedNodeTemplate.isPresent());
+ assertTrue(mappedNodeTemplate.isPresent());
mappedNodeTemplate.ifPresent(stringNodeTemplateEntry -> {
assertEquals("server_cmaui", stringNodeTemplateEntry.getKey());
assertNotNull(stringNodeTemplateEntry.getValue());
@@ -533,7 +560,7 @@ public class ToscaAnalyzerServiceImplTest {
mappedNodeTemplate = toscaAnalyzerService.getSubstitutionMappedNodeTemplateByExposedReq(
toscaServiceModel.getEntryDefinitionServiceTemplate(), mainServiceTemplate,
"local_storage_server_cmaui");
- assertEquals(false, mappedNodeTemplate.isPresent());
+ assertFalse(mappedNodeTemplate.isPresent());
}
}
@@ -541,7 +568,8 @@ public class ToscaAnalyzerServiceImplTest {
public void invalidSubstitutableMapping() throws Exception {
thrown.expect(CoreException.class);
thrown.expectMessage(
- "Invalid Substitution Service Template invalidMappingServiceTemplate.yaml, missing mandatory file 'Node type' in substitution mapping.");
+ "Invalid Substitution Service Template invalidMappingServiceTemplate.yaml, "
+ + "missing mandatory file 'Node type' in substitution mapping.");
ServiceTemplate invalidMappingServiceTemplate = new ServiceTemplate();
invalidMappingServiceTemplate.setTopology_template(new TopologyTemplate());
invalidMappingServiceTemplate.getTopology_template().setSubstitution_mappings(new SubstitutionMapping());
@@ -557,13 +585,11 @@ public class ToscaAnalyzerServiceImplTest {
emptyReqMapping.getTopology_template().getSubstitution_mappings().setNode_type("temp");
ServiceTemplate mainServiceTemplate =
toscaServiceModel.getServiceTemplates().get(toscaServiceModel.getEntryDefinitionServiceTemplate());
- Optional<Map.Entry<String, NodeTemplate>> mappedNodeTemplate = toscaAnalyzerService
- .getSubstitutionMappedNodeTemplateByExposedReq(
- toscaServiceModel
- .getEntryDefinitionServiceTemplate(),
- mainServiceTemplate,
- "local_storage_server_cmaui");
- assertEquals(false, mappedNodeTemplate.isPresent());
+ Optional<Map.Entry<String, NodeTemplate>> mappedNodeTemplate =
+ toscaAnalyzerService.getSubstitutionMappedNodeTemplateByExposedReq(
+ toscaServiceModel.getEntryDefinitionServiceTemplate(),mainServiceTemplate,
+ "local_storage_server_cmaui");
+ assertFalse(mappedNodeTemplate.isPresent());
}
@Test
@@ -594,20 +620,17 @@ public class ToscaAnalyzerServiceImplTest {
requirementAssignment.setNode(node);
requirementAssignment.setRelationship(relationship);
- assertEquals(true, toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, capability, node,
- relationship));
- assertEquals(true,
+ assertTrue(toscaAnalyzerService
+ .isDesiredRequirementAssignment(requirementAssignment, capability, node, relationship));
+ assertTrue(
toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, null, node, relationship));
- assertEquals(true, toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, capability, null,
- relationship));
- assertEquals(true,
- toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, capability, node, null));
- assertEquals(true,
+ assertTrue(toscaAnalyzerService
+ .isDesiredRequirementAssignment(requirementAssignment, capability, null, relationship));
+ assertTrue(toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, capability, node, null));
+ assertTrue(
toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, null, null, relationship));
- assertEquals(true,
- toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, capability, null, null));
- assertEquals(true,
- toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, null, node, null));
+ assertTrue(toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, capability, null, null));
+ assertTrue(toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, null, node, null));
}
@@ -622,22 +645,17 @@ public class ToscaAnalyzerServiceImplTest {
requirementAssignment.setNode(node);
requirementAssignment.setRelationship(relationship);
- assertEquals(false,
+ assertFalse(
toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, "no", node, relationship));
- assertEquals(false,
+ assertFalse(
toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, "no", "no", relationship));
- assertEquals(false,
- toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, "no", "no", "no"));
- assertEquals(false, toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, capability, "no",
- relationship));
- assertEquals(false,
- toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, capability, node, "no"));
- assertEquals(false,
- toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, capability, "no", "no"));
- assertEquals(false,
- toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, "no", null, null));
- assertEquals(false,
- toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, null, null, null));
+ assertFalse(toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, "no", "no", "no"));
+ assertFalse(toscaAnalyzerService
+ .isDesiredRequirementAssignment(requirementAssignment, capability, "no", relationship));
+ assertFalse(toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, capability, node, "no"));
+ assertFalse(toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, capability, "no", "no"));
+ assertFalse(toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, "no", null, null));
+ assertFalse(toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, null, null, null));
}
@@ -677,6 +695,42 @@ public class ToscaAnalyzerServiceImplTest {
}
@Test
+ public void interfaceInheritanceNoOperIsTypeTrue() throws IOException {
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
+ try (InputStream yamlFile = toscaExtensionYamlUtil.loadYamlFileIs(
+ "/mock/analyzerService/ServiceTemplateInterfaceInheritanceTest.yaml")) {
+ interfaceIsTypeTest(toscaExtensionYamlUtil, CMAUI_IMAGE_EXTEND, yamlFile);
+ }
+ }
+
+ private void interfaceIsTypeTest(ToscaExtensionYamlUtil toscaExtensionYamlUtil, String nodeTypeKey,
+ InputStream yamlFile) {
+ ServiceTemplate serviceTemplateFromYaml = toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
+
+ ToscaFlatData flatData = toscaAnalyzerService.getFlatEntity(ToscaElementTypes.NODE_TYPE, nodeTypeKey,
+ serviceTemplateFromYaml, toscaServiceModel);
+
+ Assert.assertNotNull(flatData);
+ Object standardInterfaceDefinition =
+ ((NodeType) flatData.getFlatEntity()).getInterfaces().get(STANDARD_INTERFACE_KEY);
+ InterfaceDefinitionType standardInterfaceDefinitionType =
+ new InterfaceDefinitionType(standardInterfaceDefinition);
+ assertTrue(toscaAnalyzerService
+ .isTypeOf(standardInterfaceDefinitionType, TOSCA_LIFECYCLE_STANDARD, serviceTemplateFromYaml,
+ toscaServiceModel));
+ }
+
+ @Test
+ public void interfaceInheritanceWithOperIsTypeTrue() throws IOException {
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
+ try (InputStream yamlFile = toscaExtensionYamlUtil.loadYamlFileIs(
+ "/mock/analyzerService/ServiceTemplateInterfaceInheritanceTest.yaml")) {
+ interfaceIsTypeTest(toscaExtensionYamlUtil, CMAUI_INTERFACE_TEST, yamlFile);
+ }
+ }
+
+
+ @Test
public void shouldReturnTrueIfNdTmpTypeIsFoundInSrvTmpNdTyAndNdTyDerivedFromRequestedType() {
String typeToMatch = ToscaNodeType.CINDER_VOLUME;
when(nodeTemplateMock.getType()).thenReturn(typeToMatch);
@@ -765,7 +819,8 @@ public class ToscaAnalyzerServiceImplTest {
}
@Test
- public void shouldReturnTrueIfNdTmpTypeIsFoundInSrvTmpNdTyAndNotDerivedFromRequestedTypeBut2ndLevelDerivedFromMatch() {
+ public void
+ shouldReturnTrueIfNdTmpTypeIsFoundInSrvTmpNdTyAndNotDerivedFromRequestedTypeBut2ndLevelDerivedFromMatch() {
String typeToMatch = "A";
when(nodeTemplateMock.getType()).thenReturn(typeToMatch);
Map<String, NodeType> stNodeTypes = new HashMap<>();
@@ -814,8 +869,8 @@ public class ToscaAnalyzerServiceImplTest {
anImport.setFile("mainImport");
importMap.put("bla bla", anImport);
imports.add(importMap);
- ServiceTemplate mainST = new ServiceTemplate();
- mainST.setImports(imports);
+ ServiceTemplate mainSt = new ServiceTemplate();
+ mainSt.setImports(imports);
//create searchable service template
Map<String, NodeType> stNodeTypes = new HashMap<>();
@@ -827,11 +882,11 @@ public class ToscaAnalyzerServiceImplTest {
// add service templates to tosca service model
Map<String, ServiceTemplate> serviceTemplates = toscaServiceModelMock.getServiceTemplates();
- serviceTemplates.put("testMainServiceTemplate", mainST);
+ serviceTemplates.put("testMainServiceTemplate", mainSt);
serviceTemplates.put("mainImport", serviceTemplate);
when(toscaServiceModelMock.getServiceTemplates()).thenReturn(serviceTemplates);
- assertTrue(toscaAnalyzerService.isTypeOf(nodeTemplateMock, ToscaNodeType.NATIVE_BLOCK_STORAGE, mainST,
+ assertTrue(toscaAnalyzerService.isTypeOf(nodeTemplateMock, ToscaNodeType.NATIVE_BLOCK_STORAGE, mainSt,
toscaServiceModelMock));
}
@@ -845,8 +900,8 @@ public class ToscaAnalyzerServiceImplTest {
anImport.setFile("refToMainImport");
importMap.put("bla bla", anImport);
imports.add(importMap);
- ServiceTemplate mainST = new ServiceTemplate();
- mainST.setImports(imports);
+ ServiceTemplate mainSt = new ServiceTemplate();
+ mainSt.setImports(imports);
//create searchable service template
Map<String, NodeType> stNodeTypes = new HashMap<>();
@@ -863,17 +918,17 @@ public class ToscaAnalyzerServiceImplTest {
firstLevelImport.setFile("mainImport");
firstLevelImportsMap.put("bla bla 2", firstLevelImport);
firstLevelImports.add(firstLevelImportsMap);
- ServiceTemplate firstLevelST = new ServiceTemplate();
- firstLevelST.setImports(firstLevelImports);
+ ServiceTemplate firstLevelSt = new ServiceTemplate();
+ firstLevelSt.setImports(firstLevelImports);
// add service templates to tosca service model
Map<String, ServiceTemplate> serviceTemplates = toscaServiceModelMock.getServiceTemplates();
- serviceTemplates.put("testMainServiceTemplate", mainST);
- serviceTemplates.put("refToMainImport", firstLevelST);
+ serviceTemplates.put("testMainServiceTemplate", mainSt);
+ serviceTemplates.put("refToMainImport", firstLevelSt);
serviceTemplates.put("mainImport", serviceTemplate);
when(toscaServiceModelMock.getServiceTemplates()).thenReturn(serviceTemplates);
- assertTrue(toscaAnalyzerService.isTypeOf(nodeTemplateMock, ToscaNodeType.NATIVE_BLOCK_STORAGE, mainST,
+ assertTrue(toscaAnalyzerService.isTypeOf(nodeTemplateMock, ToscaNodeType.NATIVE_BLOCK_STORAGE, mainSt,
toscaServiceModelMock));
}
@@ -913,5 +968,5 @@ public class ToscaAnalyzerServiceImplTest {
assertTrue(toscaAnalyzerService
.isTypeOf(capabilityDefinition, CAPABILITY_TYPE_B, serviceTemplate, toscaServiceModelMock));
}
-
}
+
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/ServiceTemplateInterfaceInheritanceTest.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/ServiceTemplateInterfaceInheritanceTest.yaml
index 4abc7ca681..17cfe33592 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/ServiceTemplateInterfaceInheritanceTest.yaml
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/ServiceTemplateInterfaceInheritanceTest.yaml
@@ -39,11 +39,11 @@ node_types:
derived_from: org.openecomp.resource.vfc.nodes.heat.cmaui_image
interfaces:
Standard:
+ type: amdocs.interfaces.interfaceNoOper
inputs:
url_path:
type: string
required: false
- type: tosca.interfaces.node.lifecycle.Standard
create:
inputs:
peeringSessions:
@@ -55,6 +55,21 @@ node_types:
time:
type: string
+
+ org.openecomp.resource.vfc.nodes.heat.cmaui_image_interfaceTest:
+ derived_from: org.openecomp.resource.vfc.nodes.heat.cmaui_image
+ interfaces:
+ Standard:
+ type: amdocs.interfaces.interfaceInheritance
+ inputs:
+ url_path:
+ type: string
+ required: false
+ newOper:
+ inputs:
+ name:
+ type: string
+
data_types:
org.openecomp.datatypes.heat.network.MyAddressPair:
derived_from: org.openecomp.datatypes.heat.network.AddressPair
@@ -81,6 +96,16 @@ data_types:
status: SUPPORTED
required: true
default: overridden default value
+interface_types:
+ amdocs.interfaces.interfaceNoOper:
+ derived_from: tosca.interfaces.node.lifecycle.Standard
+
+ amdocs.interfaces.interfaceInheritance:
+ derived_from: tosca.interfaces.node.lifecycle.Standard
+ newOper:
+ description: new operation
+
+
topology_template:
inputs:
cmaui_names:
@@ -148,48 +173,48 @@ topology_template:
node: server_cmaui
relationship: tosca.relationships.network.BindsTo
cmaui1_port_1:
- type: org.openecomp.resource.cp.nodes.heat.network.neutron.Port
- properties:
- replacement_policy: AUTO
- security_groups:
- - get_input: security_group_name
- fixed_ips:
- - subnet: subnetNameVal
- ip_address:
- get_input:
- - cmaui_oam_ips
- - 1
- - subnet: subnetNameVal2
- ip_address:
- get_input:
- - cmaui_oam_ips
- - 1
- network: jsa_net
- requirements:
- - link:
- capability: tosca.capabilities.network.Linkable
- node: jsa_net1
- relationship: tosca.relationships.network.LinksTo
- - link:
- capability: tosca.capabilities.network.Linkable
- node: jsa_net2
- relationship: tosca.relationships.network.LinksTo
- - binding:
- capability: tosca.capabilities.network.Bindable
- node: server_cmaui
- relationship: tosca.relationships.network.BindsTo
+ type: org.openecomp.resource.cp.nodes.heat.network.neutron.Port
+ properties:
+ replacement_policy: AUTO
+ security_groups:
+ - get_input: security_group_name
+ fixed_ips:
+ - subnet: subnetNameVal
+ ip_address:
+ get_input:
+ - cmaui_oam_ips
+ - 1
+ - subnet: subnetNameVal2
+ ip_address:
+ get_input:
+ - cmaui_oam_ips
+ - 1
+ network: jsa_net
+ requirements:
+ - link:
+ capability: tosca.capabilities.network.Linkable
+ node: jsa_net1
+ relationship: tosca.relationships.network.LinksTo
+ - link:
+ capability: tosca.capabilities.network.Linkable
+ node: jsa_net2
+ relationship: tosca.relationships.network.LinksTo
+ - binding:
+ capability: tosca.capabilities.network.Bindable
+ node: server_cmaui
+ relationship: tosca.relationships.network.BindsTo
jsa_net1:
- type: org.openecomp.resource.vl.nodes.heat.network.neutron.Net
- properties:
- shared: true
- network_name:
- get_input: jsa_net_name
+ type: org.openecomp.resource.vl.nodes.heat.network.neutron.Net
+ properties:
+ shared: true
+ network_name:
+ get_input: jsa_net_name
jsa_net2:
- type: org.openecomp.resource.vl.nodes.heat.network.neutron.Net
- properties:
- shared: true
- network_name:
- get_input: jsa_net_name
+ type: org.openecomp.resource.vl.nodes.heat.network.neutron.Net
+ properties:
+ shared: true
+ network_name:
+ get_input: jsa_net_name
groups:
nested:
type: org.openecomp.groups.heat.HeatStack
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithInterface.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithInterface.yaml
index 46d61079a2..5e3c7ed2e0 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithInterface.yaml
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithInterface.yaml
@@ -89,9 +89,9 @@ topology_template:
relationship: relationB
node_filter:
properties:
- propName1:
+ - propName1:
- greater_or_equal: 9
- propName2:
+ - propName2:
- min_length: 1
- max_length: 2
occurrences:
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithInterfaceAndOperation.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithInterfaceAndOperation.yaml
index 9da35df8a2..d00248741c 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithInterfaceAndOperation.yaml
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithInterfaceAndOperation.yaml
@@ -91,9 +91,9 @@ topology_template:
relationship: relationB
node_filter:
properties:
- propName1:
+ - propName1:
- greater_or_equal: 9
- propName2:
+ - propName2:
- min_length: 1
- max_length: 2
occurrences:
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithNodeTemplateInterface.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithNodeTemplateInterface.yaml
index 29ce7c9eac..1131b4777f 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithNodeTemplateInterface.yaml
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithNodeTemplateInterface.yaml
@@ -86,9 +86,9 @@ topology_template:
relationship: relationB
node_filter:
properties:
- propName1:
+ - propName1:
- greater_or_equal: 9
- propName2:
+ - propName2:
- min_length: 1
- max_length: 2
occurrences:
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithNodeTypeInterface.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithNodeTypeInterface.yaml
index 4cbb5163e9..59c00c9ec3 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithNodeTypeInterface.yaml
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithNodeTypeInterface.yaml
@@ -97,9 +97,9 @@ topology_template:
relationship: relationB
node_filter:
properties:
- propName1:
+ - propName1:
- greater_or_equal: 9
- propName2:
+ - propName2:
- min_length: 1
- max_length: 2
occurrences: