aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-tosca-generator-lib
diff options
context:
space:
mode:
authorshiria <shiri.amichai@amdocs.com>2018-06-04 11:07:29 +0300
committerAvi Gaffa <avi.gaffa@amdocs.com>2018-06-05 14:31:34 +0000
commit09c6320df7f768e42edeaedd7ba69e6fb13d433d (patch)
tree92883e0297c3d47ab039685ca91f2f47a1dbcd46 /openecomp-be/lib/openecomp-sdc-tosca-generator-lib
parentd9cae980e80021dfad0bc9366d32d2cf996cfa90 (diff)
fix get flat node type
update node type interface update return value to object which include the type hierarchy Change-Id: I97623c7bbad0223a174370d13aabf4c3efe9c21e Issue-ID: SDC-1394 Signed-off-by: shiria <shiri.amichai@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-tosca-generator-lib')
-rw-r--r--openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-core/src/main/java/org/openecomp/sdc/generator/core/utils/GeneratorUtils.java361
1 files changed, 177 insertions, 184 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-core/src/main/java/org/openecomp/sdc/generator/core/utils/GeneratorUtils.java b/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-core/src/main/java/org/openecomp/sdc/generator/core/utils/GeneratorUtils.java
index 9ea8ba752a..1501fa1c9f 100644
--- a/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-core/src/main/java/org/openecomp/sdc/generator/core/utils/GeneratorUtils.java
+++ b/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-core/src/main/java/org/openecomp/sdc/generator/core/utils/GeneratorUtils.java
@@ -29,198 +29,191 @@ import static org.openecomp.sdc.tosca.services.DataModelUtil.addSubstitutionNode
*/
public class GeneratorUtils {
- private GeneratorUtils() {
- // prevent instantiation
- }
-
- //TODO : Read from configuration
- private static final List<String> SUPPORTED_CAPABILITIES = Arrays.asList("host", "os", "endpoint", "scalable");
- private static final List<String> SUPPORTED_REQUIREMENTS = Collections.singletonList("link");
-
- /**
- * Add service template to tosca service model.
- *
- * @param toscaServiceModel the tosca service model
- * @param serviceTemplate the service template
- */
- public static void addServiceTemplateToToscaServiceModel(ToscaServiceModel toscaServiceModel,
- ServiceTemplate serviceTemplate) {
-
- String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
- Map<String, ServiceTemplate> serviceTemplates = toscaServiceModel.getServiceTemplates();
- if (!serviceTemplates.containsKey(serviceTemplateFileName)) {
- ToscaUtil.addServiceTemplateToMapWithKeyFileName(serviceTemplates, serviceTemplate);
- }
- toscaServiceModel.setServiceTemplates(serviceTemplates);
- }
-
- /**
- * Gets substitution node type exposed connection points.
- *
- * @param substitutionNodeType the substitution node type
- * @param substitutionServiceTemplate the substitution service template
- * @param toscaServiceModel the tosca service model
- * @return the substitution node type exposed connection points
- */
- public static Map<String, Map<String, List<String>>>
- getSubstitutionNodeTypeExposedConnectionPoints(NodeType substitutionNodeType,
- ServiceTemplate substitutionServiceTemplate,
- ToscaServiceModel toscaServiceModel) {
-
- Map<String, NodeTemplate> nodeTemplates =
- substitutionServiceTemplate.getTopology_template().getNode_templates();
- String nodeTemplateId;
- NodeTemplate nodeTemplate;
- String nodeType;
- Map<String, Map<String, List<String>>> substitutionMapping = new HashMap<>();
- if (nodeTemplates == null) {
- return substitutionMapping;
+ private GeneratorUtils() {
+ // prevent instantiation
}
- try {
- Map<String, List<String>> capabilitySubstitutionMapping = new HashMap<>();
- Map<String, List<String>> requirementSubstitutionMapping = new HashMap<>();
- substitutionMapping.put("capability", capabilitySubstitutionMapping);
- substitutionMapping.put("requirement", requirementSubstitutionMapping);
- List<Map<String, RequirementDefinition>> nodeTypeRequirementsDefinition;
- Map<String, RequirementAssignment> nodeTemplateRequirementsAssignment;
- List<Map<String, RequirementDefinition>> exposedRequirementsDefinition;
- Map<String, Map<String, RequirementAssignment>> fullFilledRequirementsDefinition =
- new HashMap<>();
- Map<String, CapabilityDefinition> nodeTypeCapabilitiesDefinition = new HashMap<>();
- Map<String, CapabilityDefinition> exposedCapabilitiesDefinition;
-
- ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
- for (Map.Entry<String, NodeTemplate> entry : nodeTemplates.entrySet()) {
- nodeTemplateId = entry.getKey();
- nodeTemplate = entry.getValue();
- nodeType = nodeTemplate.getType();
- NodeType flatNodeType = (NodeType) toscaAnalyzerService
- .getFlatEntity(ToscaElementTypes.NODE_TYPE, nodeType, substitutionServiceTemplate,
- toscaServiceModel);
- // get requirements
- nodeTypeRequirementsDefinition =
- getNodeTypeRequirements(flatNodeType, nodeTemplateId, substitutionServiceTemplate,
- requirementSubstitutionMapping);
- nodeTemplateRequirementsAssignment =
- DataModelUtil.getNodeTemplateRequirements(nodeTemplate);
- fullFilledRequirementsDefinition.put(nodeTemplateId, nodeTemplateRequirementsAssignment);
- //set substitution node type requirements
- exposedRequirementsDefinition =
- toscaAnalyzerService.calculateExposedRequirements(nodeTypeRequirementsDefinition,
- nodeTemplateRequirementsAssignment);
-
-
- //Filter unsupported requirements
- Iterator<Map<String, RequirementDefinition>> iterator =
- exposedRequirementsDefinition.iterator();
- while (iterator.hasNext()) {
- Map<String, RequirementDefinition> requirementDefinitionMap = iterator.next();
- for (Map.Entry<String, RequirementDefinition> requirementDefinitionEntry :
- requirementDefinitionMap.entrySet()) {
- String requirementKey = requirementDefinitionEntry.getKey();
- if (!SUPPORTED_REQUIREMENTS.contains(requirementKey)) {
- iterator.remove();
- }
- }
+ //TODO : Read from configuration
+ private static final List<String> SUPPORTED_CAPABILITIES = Arrays.asList("host", "os", "endpoint", "scalable");
+ private static final List<String> SUPPORTED_REQUIREMENTS = Collections.singletonList("link");
+
+ /**
+ * Add service template to tosca service model.
+ *
+ * @param toscaServiceModel the tosca service model
+ * @param serviceTemplate the service template
+ */
+ public static void addServiceTemplateToToscaServiceModel(ToscaServiceModel toscaServiceModel,
+ ServiceTemplate serviceTemplate) {
+
+ String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
+ Map<String, ServiceTemplate> serviceTemplates = toscaServiceModel.getServiceTemplates();
+ if (!serviceTemplates.containsKey(serviceTemplateFileName)) {
+ ToscaUtil.addServiceTemplateToMapWithKeyFileName(serviceTemplates, serviceTemplate);
}
- addSubstitutionNodeTypeRequirements(substitutionNodeType, exposedRequirementsDefinition,
- nodeTemplateId);
- //get capabilities
- addNodeTypeCapabilitiesToSubMapping(nodeTypeCapabilitiesDefinition,
- capabilitySubstitutionMapping, nodeType,
- nodeTemplateId, substitutionServiceTemplate, toscaServiceModel);
- }
-
- exposedCapabilitiesDefinition =
- toscaAnalyzerService.calculateExposedCapabilities(nodeTypeCapabilitiesDefinition,
- fullFilledRequirementsDefinition);
-
- //Filter unsupported capabilities
- Iterator<Map.Entry<String, CapabilityDefinition>> iterator = exposedCapabilitiesDefinition
- .entrySet().iterator();
- while (iterator.hasNext()) {
- Map.Entry<String, CapabilityDefinition> capabilityDefinitionEntry = iterator.next();
- //Expected Capability is of the format <capabilityId>_<componentName>
- String capabilityKey = capabilityDefinitionEntry.getKey().split("_")[0];
- if (!SUPPORTED_CAPABILITIES.contains(capabilityKey)) {
- iterator.remove();
+ toscaServiceModel.setServiceTemplates(serviceTemplates);
+ }
+
+ /**
+ * Gets substitution node type exposed connection points.
+ *
+ * @param substitutionNodeType the substitution node type
+ * @param substitutionServiceTemplate the substitution service template
+ * @param toscaServiceModel the tosca service model
+ * @return the substitution node type exposed connection points
+ */
+ public static Map<String, Map<String, List<String>>> getSubstitutionNodeTypeExposedConnectionPoints(NodeType substitutionNodeType,
+ ServiceTemplate substitutionServiceTemplate,
+ ToscaServiceModel toscaServiceModel) {
+
+ Map<String, NodeTemplate> nodeTemplates =
+ substitutionServiceTemplate.getTopology_template().getNode_templates();
+ String nodeTemplateId;
+ NodeTemplate nodeTemplate;
+ String nodeType;
+ Map<String, Map<String, List<String>>> substitutionMapping = new HashMap<>();
+ if (nodeTemplates == null) {
+ return substitutionMapping;
}
- }
- DataModelUtil.addNodeTypeCapabilitiesDef(substitutionNodeType, exposedCapabilitiesDefinition);
- } catch (Exception ex) {
- return null;
+ try {
+ Map<String, List<String>> capabilitySubstitutionMapping = new HashMap<>();
+ Map<String, List<String>> requirementSubstitutionMapping = new HashMap<>();
+ substitutionMapping.put("capability", capabilitySubstitutionMapping);
+ substitutionMapping.put("requirement", requirementSubstitutionMapping);
+ List<Map<String, RequirementDefinition>> nodeTypeRequirementsDefinition;
+ Map<String, RequirementAssignment> nodeTemplateRequirementsAssignment;
+ List<Map<String, RequirementDefinition>> exposedRequirementsDefinition;
+ Map<String, Map<String, RequirementAssignment>> fullFilledRequirementsDefinition = new HashMap<>();
+ Map<String, CapabilityDefinition> nodeTypeCapabilitiesDefinition = new HashMap<>();
+ Map<String, CapabilityDefinition> exposedCapabilitiesDefinition;
+
+ ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
+ for (Map.Entry<String, NodeTemplate> entry : nodeTemplates.entrySet()) {
+ nodeTemplateId = entry.getKey();
+ nodeTemplate = entry.getValue();
+ nodeType = nodeTemplate.getType();
+ NodeType flatNodeType = (NodeType) toscaAnalyzerService
+ .getFlatEntity(ToscaElementTypes.NODE_TYPE, nodeType,
+ substitutionServiceTemplate, toscaServiceModel)
+ .getFlatEntity();
+ // get requirements
+ nodeTypeRequirementsDefinition =
+ getNodeTypeRequirements(flatNodeType, nodeTemplateId, substitutionServiceTemplate,
+ requirementSubstitutionMapping);
+ nodeTemplateRequirementsAssignment = DataModelUtil.getNodeTemplateRequirements(nodeTemplate);
+ fullFilledRequirementsDefinition.put(nodeTemplateId, nodeTemplateRequirementsAssignment);
+ //set substitution node type requirements
+ exposedRequirementsDefinition = toscaAnalyzerService
+ .calculateExposedRequirements(nodeTypeRequirementsDefinition,
+ nodeTemplateRequirementsAssignment);
+
+
+ //Filter unsupported requirements
+ Iterator<Map<String, RequirementDefinition>> iterator = exposedRequirementsDefinition.iterator();
+ while (iterator.hasNext()) {
+ Map<String, RequirementDefinition> requirementDefinitionMap = iterator.next();
+ for (Map.Entry<String, RequirementDefinition> requirementDefinitionEntry : requirementDefinitionMap
+ .entrySet()) {
+ String requirementKey = requirementDefinitionEntry.getKey();
+ if (!SUPPORTED_REQUIREMENTS.contains(requirementKey)) {
+ iterator.remove();
+ }
+ }
+ }
+ addSubstitutionNodeTypeRequirements(substitutionNodeType, exposedRequirementsDefinition,
+ nodeTemplateId);
+ //get capabilities
+ addNodeTypeCapabilitiesToSubMapping(nodeTypeCapabilitiesDefinition, capabilitySubstitutionMapping,
+ nodeType, nodeTemplateId, substitutionServiceTemplate, toscaServiceModel);
+ }
+
+ exposedCapabilitiesDefinition = toscaAnalyzerService
+ .calculateExposedCapabilities(nodeTypeCapabilitiesDefinition,
+ fullFilledRequirementsDefinition);
+
+ //Filter unsupported capabilities
+ Iterator<Map.Entry<String, CapabilityDefinition>> iterator =
+ exposedCapabilitiesDefinition.entrySet().iterator();
+ while (iterator.hasNext()) {
+ Map.Entry<String, CapabilityDefinition> capabilityDefinitionEntry = iterator.next();
+ //Expected Capability is of the format <capabilityId>_<componentName>
+ String capabilityKey = capabilityDefinitionEntry.getKey().split("_")[0];
+ if (!SUPPORTED_CAPABILITIES.contains(capabilityKey)) {
+ iterator.remove();
+ }
+ }
+
+ DataModelUtil.addNodeTypeCapabilitiesDef(substitutionNodeType, exposedCapabilitiesDefinition);
+ } catch (Exception ex) {
+ return null;
+ }
+ return substitutionMapping;
}
- return substitutionMapping;
- }
-
- /**
- * Gets node type requirements.
- *
- * @param flatNodeType the flat node type
- * @param templateName the template name
- * @param serviceTemplate the service template
- * @param requirementSubstitutionMapping the requirement substitution mapping
- * @return the node type requirements
- */
- public static List<Map<String, RequirementDefinition>> getNodeTypeRequirements(
- NodeType flatNodeType,
- String templateName,
- ServiceTemplate serviceTemplate,
- Map<String, List<String>> requirementSubstitutionMapping) {
- List<Map<String, RequirementDefinition>> requirementList = new ArrayList<>();
- List<String> requirementMapping;
- if (flatNodeType.getRequirements() != null) {
- for (Map<String, RequirementDefinition> requirementMap : flatNodeType.getRequirements()) {
- for (Map.Entry<String, RequirementDefinition> requirementNodeEntry : requirementMap
- .entrySet()) {
- ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
- RequirementDefinition requirementNodeEntryValue = toscaExtensionYamlUtil
- .yamlToObject(toscaExtensionYamlUtil.objectToYaml(requirementNodeEntry.getValue()),
- RequirementDefinition.class);
- if (requirementNodeEntryValue.getOccurrences() == null) {
- requirementNodeEntryValue.setOccurrences(new Object[]{1, 1});
- }
- Map<String, RequirementDefinition> requirementDef = new HashMap<>();
- requirementDef.put(requirementNodeEntry.getKey(), requirementNodeEntryValue);
- DataModelUtil.addRequirementToList(requirementList, requirementDef);
- requirementMapping = new ArrayList<>();
- requirementMapping.add(templateName);
- requirementMapping.add(requirementNodeEntry.getKey());
- requirementSubstitutionMapping
- .put(requirementNodeEntry.getKey() + "_" + templateName, requirementMapping);
- if (requirementNodeEntryValue.getNode() == null) {
- requirementNodeEntryValue.setOccurrences(new Object[]{1, 1});
- }
+
+ /**
+ * Gets node type requirements.
+ *
+ * @param flatNodeType the flat node type
+ * @param templateName the template name
+ * @param serviceTemplate the service template
+ * @param requirementSubstitutionMapping the requirement substitution mapping
+ * @return the node type requirements
+ */
+ public static List<Map<String, RequirementDefinition>> getNodeTypeRequirements(NodeType flatNodeType,
+ String templateName,
+ ServiceTemplate serviceTemplate,
+ Map<String, List<String>> requirementSubstitutionMapping) {
+ List<Map<String, RequirementDefinition>> requirementList = new ArrayList<>();
+ List<String> requirementMapping;
+ if (flatNodeType.getRequirements() != null) {
+ for (Map<String, RequirementDefinition> requirementMap : flatNodeType.getRequirements()) {
+ for (Map.Entry<String, RequirementDefinition> requirementNodeEntry : requirementMap.entrySet()) {
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
+ RequirementDefinition requirementNodeEntryValue = toscaExtensionYamlUtil.yamlToObject(
+ toscaExtensionYamlUtil.objectToYaml(requirementNodeEntry.getValue()),
+ RequirementDefinition.class);
+ if (requirementNodeEntryValue.getOccurrences() == null) {
+ requirementNodeEntryValue.setOccurrences(new Object[] {1, 1});
+ }
+ Map<String, RequirementDefinition> requirementDef = new HashMap<>();
+ requirementDef.put(requirementNodeEntry.getKey(), requirementNodeEntryValue);
+ DataModelUtil.addRequirementToList(requirementList, requirementDef);
+ requirementMapping = new ArrayList<>();
+ requirementMapping.add(templateName);
+ requirementMapping.add(requirementNodeEntry.getKey());
+ requirementSubstitutionMapping
+ .put(requirementNodeEntry.getKey() + "_" + templateName, requirementMapping);
+ if (requirementNodeEntryValue.getNode() == null) {
+ requirementNodeEntryValue.setOccurrences(new Object[] {1, 1});
+ }
+ }
+ }
}
- }
+ return requirementList;
}
- return requirementList;
- }
-
- private static void addNodeTypeCapabilitiesToSubMapping(
- Map<String, CapabilityDefinition> nodeTypeCapabilitiesDefinition,
- Map<String, List<String>> capabilitySubstitutionMapping, String type, String templateName,
- ServiceTemplate substitutionServiceTemplate, ToscaServiceModel toscaServiceModel) {
- ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
- NodeType flatNodeType = (NodeType) toscaAnalyzerService
- .getFlatEntity(ToscaElementTypes.NODE_TYPE, type, substitutionServiceTemplate,
- toscaServiceModel);
- String capabilityKey;
- List<String> capabilityMapping;
- if (flatNodeType.getCapabilities() != null) {
- for (Map.Entry<String, CapabilityDefinition> capabilityNodeEntry : flatNodeType
- .getCapabilities()
- .entrySet()) {
- capabilityKey = capabilityNodeEntry.getKey() + "_" + templateName;
- nodeTypeCapabilitiesDefinition.put(capabilityKey, capabilityNodeEntry.getValue().clone());
- capabilityMapping = new ArrayList<>();
- capabilityMapping.add(templateName);
- capabilityMapping.add(capabilityNodeEntry.getKey());
- capabilitySubstitutionMapping.put(capabilityKey, capabilityMapping);
- }
+
+ private static void addNodeTypeCapabilitiesToSubMapping(Map<String, CapabilityDefinition> nodeTypeCapabilitiesDefinition,
+ Map<String, List<String>> capabilitySubstitutionMapping,
+ String type, String templateName,
+ ServiceTemplate substitutionServiceTemplate,
+ ToscaServiceModel toscaServiceModel) {
+ ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
+ NodeType flatNodeType = (NodeType) toscaAnalyzerService.getFlatEntity(ToscaElementTypes.NODE_TYPE, type,
+ substitutionServiceTemplate, toscaServiceModel).getFlatEntity();
+ String capabilityKey;
+ List<String> capabilityMapping;
+ if (flatNodeType.getCapabilities() != null) {
+ for (Map.Entry<String, CapabilityDefinition> capabilityNodeEntry : flatNodeType.getCapabilities()
+ .entrySet()) {
+ capabilityKey = capabilityNodeEntry.getKey() + "_" + templateName;
+ nodeTypeCapabilitiesDefinition.put(capabilityKey, capabilityNodeEntry.getValue().clone());
+ capabilityMapping = new ArrayList<>();
+ capabilityMapping.add(templateName);
+ capabilityMapping.add(capabilityNodeEntry.getKey());
+ capabilitySubstitutionMapping.put(capabilityKey, capabilityMapping);
+ }
+ }
}
- }
}