summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-lib/src
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-lib/src')
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java10
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaUtil.java52
2 files changed, 61 insertions, 1 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 26596b994f..7c1dfdcafd 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
@@ -198,6 +198,16 @@ public class DataModelUtil {
mdcDataDebugMessage.debugExitMessage(null, null);
}
+ public static Map<String, NodeTemplate> getNodeTemplates(ServiceTemplate serviceTemplate){
+ if (Objects.isNull(serviceTemplate)
+ || Objects.isNull(serviceTemplate.getTopology_template())
+ || MapUtils.isEmpty(serviceTemplate.getTopology_template().getNode_templates())){
+ return new HashMap<>();
+ }
+
+ return serviceTemplate.getTopology_template().getNode_templates();
+ }
+
/**
* Add node template.
*
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaUtil.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaUtil.java
index f3bf3280dc..3b7db49fee 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaUtil.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaUtil.java
@@ -20,10 +20,16 @@
package org.openecomp.sdc.tosca.services;
+import org.apache.commons.collections4.MapUtils;
+import org.openecomp.core.utilities.file.FileUtils;
+import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
import java.util.UUID;
/**
@@ -50,7 +56,7 @@ public class ToscaUtil {
/**
* Gets service template file name.
*
- * @param metaData the file name
+ * @param metadata the file name
* @return the service template file name
*/
public static String getServiceTemplateFileName(Map<String, String> metadata) {
@@ -63,6 +69,50 @@ public class ToscaUtil {
}
+ public static Optional<String> getSubstitutableGroupMemberId(String heatFileName,
+ ServiceTemplate serviceTemplate){
+
+ Map<String, NodeTemplate> nodeTemplates =
+ DataModelUtil.getNodeTemplates(serviceTemplate);
+
+ if(MapUtils.isEmpty(nodeTemplates)){
+ return Optional.empty();
+ }
+
+ String heatFileNameWithoutExt = FileUtils.getFileWithoutExtention(heatFileName);
+
+ for(Map.Entry<String, NodeTemplate> nodeTemplateEntry : nodeTemplates.entrySet()){
+ String subServiceTemplateName =
+ getSubstitutionServiceTemplateNameFromProperties(nodeTemplateEntry);
+
+ if(Objects.nonNull(subServiceTemplateName)
+ && isGroupMemberIdSubstitutable(heatFileNameWithoutExt, subServiceTemplateName)){
+ return Optional.of(nodeTemplateEntry.getKey());
+ }
+ }
+
+ return Optional.empty();
+ }
+
+ private static boolean isGroupMemberIdSubstitutable(String heatFileNameWithoutExt,
+ String subServiceTemplateName) {
+ return subServiceTemplateName.startsWith(heatFileNameWithoutExt);
+ }
+
+ private static String getSubstitutionServiceTemplateNameFromProperties(
+ Map.Entry<String, NodeTemplate> nodeTemplateEntry) {
+ Map<String, Object> properties =
+ nodeTemplateEntry.getValue().getProperties() == null ? Collections.emptyMap() :
+ nodeTemplateEntry.getValue().getProperties();
+
+ Map<String, Object> serviceTemplateFilter =
+ properties.containsKey(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME)?
+ (Map<String, Object>) properties.get(ToscaConstants
+ .SERVICE_TEMPLATE_FILTER_PROPERTY_NAME) : Collections.emptyMap();
+
+ return (String) serviceTemplateFilter.get(ToscaConstants.SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME);
+ }
+
/**
* Add service template to map with key file name.