summaryrefslogtreecommitdiffstats
path: root/openecomp-be
diff options
context:
space:
mode:
authorvempo <vitaliy.emporopulo@amdocs.com>2017-10-03 20:04:37 +0300
committervempo <vitaliy.emporopulo@amdocs.com>2017-10-03 20:06:51 +0300
commit33e00cd1d7d580a2fdafad771d54e29bb455cb5d (patch)
tree15f2f1c08313eac8633aaf3935e0df1dcae9a74c /openecomp-be
parent2e4d90a7a3c76deb582df234a1b474daeb37ae30 (diff)
Update group members ids
Issue-Id: SDC-427 Change-Id: If7a476adfac7c56c97e14330e4fddcc6d9f2d293 Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'openecomp-be')
-rw-r--r--openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManager.java17
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java13
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/TranslationService.java45
-rw-r--r--openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java1
-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
6 files changed, 121 insertions, 17 deletions
diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManager.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManager.java
index 372c09cffe..df46ef048d 100644
--- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManager.java
+++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManager.java
@@ -119,22 +119,19 @@ public class HeatTreeManager {
}
- private void handleHeatContentReference(String filename, HeatStructureTree fileHeatStructureTree,
+ private void handleHeatContentReference(HeatStructureTree fileHeatStructureTree,
GlobalValidationContext globalContext) {
String fileName = fileHeatStructureTree.getFileName();
- InputStream fileContent = this.heatContentMap.getFileContent(fileName);
- if (fileContent == null) {
- return; // file exist in manifest but does not exist in zip
- }
- try {
+
+ try (InputStream fileContent = this.heatContentMap.getFileContent(fileName)) {
HeatOrchestrationTemplate hot =
new YamlUtil().yamlToObject(fileContent, HeatOrchestrationTemplate.class);
- Set<String> nestedSet = HeatTreeManagerUtil.getNestedFiles(filename, hot, globalContext);
+ Set<String> nestedSet = HeatTreeManagerUtil.getNestedFiles(fileName, hot, globalContext);
addHeatNestedFiles(fileHeatStructureTree, nestedSet);
- Set<String> artifactSet = HeatTreeManagerUtil.getArtifactFiles(filename, hot, globalContext);
+ Set<String> artifactSet = HeatTreeManagerUtil.getArtifactFiles(fileName, hot, globalContext);
addHeatArtifactFiles(fileHeatStructureTree, artifactSet);
} catch (Exception ignore) { /* invalid yaml no need to process reference */
logger.debug("",ignore);
@@ -224,7 +221,7 @@ public class HeatTreeManager {
fileHeatStructureTree.setFileName(fileName);
fileHeatStructureTree.setBase(fileData.getBase());
fileHeatStructureTree.setType(type);
- handleHeatContentReference(null, fileHeatStructureTree, null);
+ handleHeatContentReference(fileHeatStructureTree, null);
parentHeatStructureTree.addHeatToHeatList(fileHeatStructureTree);
if (fileData.getData() != null) {
scanTree(fileName, fileData.getData());
@@ -244,6 +241,7 @@ public class HeatTreeManager {
if (fileData.getData() != null) {
scanTree(fileName, fileData.getData());
}
+ handleHeatContentReference(childHeatStructureTree, null);
} else if (FileData.Type.HEAT_VOL.equals(type)) {
//parentHeatStructureTree.addVolumeFileToVolumeList(childHeatStructureTree);
@@ -251,6 +249,7 @@ public class HeatTreeManager {
if (fileData.getData() != null) {
scanTree(fileName, fileData.getData());
}
+ handleHeatContentReference(childHeatStructureTree, null);
} else if (FileData.Type.HEAT_ENV.equals(type)) {
if (parentHeatStructureTree != null && parentHeatStructureTree.getFileName() != null) {
parentHeatStructureTree.setEnv(childHeatStructureTree);
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java
index 81ef3e01ce..c1f69cf3bf 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java
@@ -86,6 +86,7 @@ import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypes
import org.openecomp.sdc.translator.services.heattotosca.helper.FunctionTranslationHelper;
import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
+import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
@@ -135,11 +136,15 @@ public class HeatToToscaUtil {
return translatorOutput;
}
- InputStream structureFile = getHeatStructureTreeFile(fileNameContentMap);
- heatToToscaTranslator.addExternalArtifacts(SdcCommon.HEAT_META, structureFile);
+ try (InputStream structureFile = getHeatStructureTreeFile(fileNameContentMap)) {
+ heatToToscaTranslator.addExternalArtifacts(SdcCommon.HEAT_META, structureFile);
- mdcDataDebugMessage.debugExitMessage(null, null);
- return heatToToscaTranslator.translate();
+ mdcDataDebugMessage.debugExitMessage(null, null);
+ return heatToToscaTranslator.translate();
+ } catch (IOException e) {
+ // rethrow as a RuntimeException to keep the signature backward compatible
+ throw new RuntimeException(e);
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/TranslationService.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/TranslationService.java
index 43079f9025..012be05257 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/TranslationService.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/TranslationService.java
@@ -20,6 +20,7 @@
package org.openecomp.sdc.translator.services.heattotosca;
+import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.openecomp.core.translator.datatypes.TranslatorOutput;
import org.openecomp.core.utilities.file.FileUtils;
@@ -48,6 +49,7 @@ import org.openecomp.sdc.tosca.datatypes.model.TopologyTemplate;
import org.openecomp.sdc.tosca.services.DataModelUtil;
import org.openecomp.sdc.tosca.services.ToscaConstants;
import org.openecomp.sdc.tosca.services.ToscaFileOutputService;
+import org.openecomp.sdc.tosca.services.ToscaUtil;
import org.openecomp.sdc.tosca.services.YamlUtil;
import org.openecomp.sdc.tosca.services.impl.ToscaFileOutputServiceCsarImpl;
import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedResourceId;
@@ -213,17 +215,54 @@ public class TranslationService {
groupDefinition.getProperties().put(Constants.DESCRIPTION_PROPERTY_NAME, hotDescription);
}
groupDefinition.setMembers(new ArrayList<>());
- Map<String, Set<String>> heatStackGroupMembers = context.getHeatStackGroupMembers();
- if (heatStackGroupMembers.get(fileName) == null) {
+ Set<String> heatStackGroupMembersIds = getHeatStackGroupMembers(fileName,
+ serviceTemplate, context);
+ if (CollectionUtils.isEmpty(heatStackGroupMembersIds)) {
return; //not creating a group when no resources are present in the heat input
}
- groupDefinition.getMembers().addAll(heatStackGroupMembers.get(fileName));
+ groupDefinition.getMembers().addAll(heatStackGroupMembersIds);
DataModelUtil
.addGroupDefinitionToTopologyTemplate(serviceTemplate, heatStackGroupId, groupDefinition);
mdcDataDebugMessage.debugExitMessage(null, null);
}
+ private Set<String> getHeatStackGroupMembers(String heatFileName,
+ ServiceTemplate serviceTemplate,
+ TranslationContext context){
+
+ Map<String, Set<String>> heatStackGroupMembers = context.getHeatStackGroupMembers();
+ Set<String> groupMembers = MapUtils.isEmpty(heatStackGroupMembers) ? new HashSet<>()
+ : heatStackGroupMembers.get(heatFileName);
+
+ if(CollectionUtils.isEmpty(groupMembers)){
+ return new HashSet<>();
+ }
+
+ Set<String> updatedMembersIds = new HashSet<>();
+
+ groupMembers.forEach(member -> {
+ if (Objects.nonNull(DataModelUtil.getNodeTemplate(serviceTemplate, member))) {
+ updatedMembersIds.add(member);
+ } else {
+ updateSubstitutableGroupMemberId(heatFileName, serviceTemplate, updatedMembersIds);
+ }
+ });
+
+ return updatedMembersIds;
+ }
+
+ private void updateSubstitutableGroupMemberId(String heatFileName,
+ ServiceTemplate serviceTemplate,
+ Set<String> updatedMembersIds) {
+ Optional<String> substitutableGroupMemberId =
+ ToscaUtil.getSubstitutableGroupMemberId(heatFileName, serviceTemplate);
+
+ if (substitutableGroupMemberId.isPresent()) {
+ updatedMembersIds.add(substitutableGroupMemberId.get());
+ }
+ }
+
private void translateInputParameters(ServiceTemplate serviceTemplate,
HeatOrchestrationTemplate heatOrchestrationTemplate,
FileData heatFileData, TranslationContext context,
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java
index c18a0cbedd..4c38bd94a7 100644
--- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java
@@ -603,6 +603,7 @@ public class CandidateServiceImpl implements CandidateService {
handleArtifactsFromTree(volume, structure);
module.setVol(volume.getFileName());
handleEnv(module, volume, true, structure);
+ addNestedToFileDataStructure(volume, structure);
}
mdcDataDebugMessage.debugExitMessage(null);
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.