aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java
diff options
context:
space:
mode:
authorMichaelMorris <michael.morris@est.tech>2023-03-21 16:31:56 +0000
committerFrancisco Javier Paradela Vila <javier.paradela.vila@est.tech>2023-04-03 12:46:35 +0000
commit18b6345a65843bcea872125cd0888ced7c521588 (patch)
treeb959d0bdcb9cfc101e33770023457a498ba3f855 /catalog-be/src/main/java
parent7565f810f9fa50c8140843b2f81e8fb428815154 (diff)
Add robustness to type creation on service import
Change-Id: I2c6bf2a13f8972c3c336ee032d4d0fda22f90938 Issue-ID: SDC-4355 Signed-off-by: MichaelMorris <michael.morris@est.tech>
Diffstat (limited to 'catalog-be/src/main/java')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java7
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfo.java67
2 files changed, 51 insertions, 23 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java
index 0df8555b47..36c16bed9e 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java
@@ -50,6 +50,7 @@ import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.CsarOperation;
import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
+import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
import org.openecomp.sdc.common.log.wrappers.Logger;
@@ -64,15 +65,17 @@ public class CsarBusinessLogic extends BaseBusinessLogic {
private static final String FAILED = " failed";
private final YamlTemplateParsingHandler yamlHandler;
private CsarOperation csarOperation;
+ private ModelOperation modelOperation;
@Autowired
public CsarBusinessLogic(IElementOperation elementDao, IGroupOperation groupOperation, IGroupInstanceOperation groupInstanceOperation,
IGroupTypeOperation groupTypeOperation, InterfaceOperation interfaceOperation,
InterfaceLifecycleOperation interfaceLifecycleTypeOperation, YamlTemplateParsingHandler yamlHandler,
- ArtifactsOperations artifactToscaOperation) {
+ ArtifactsOperations artifactToscaOperation, ModelOperation modelOperation) {
super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, interfaceOperation, interfaceLifecycleTypeOperation,
artifactToscaOperation);
this.yamlHandler = yamlHandler;
+ this.modelOperation = modelOperation;
}
@Autowired
@@ -160,7 +163,7 @@ public class CsarBusinessLogic extends BaseBusinessLogic {
oldResource.getComponentMetadataDefinition().getMetadataDataDefinition().setImportedToscaChecksum(checksum);
}
return new ServiceCsarInfo(user, csarUUID, csar, service.getName(), service.getModel(), toscaYamlCsarStatus.getKey(),
- toscaYamlCsarStatus.getValue(), true);
+ toscaYamlCsarStatus.getValue(), true, modelOperation);
}
public ParsedToscaYamlInfo getParsedToscaYamlInfo(String topologyTemplateYaml, String yamlName, Map<String, NodeTypeInfo> nodeTypesInfo,
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfo.java
index dc77c6044f..cd73f70cc5 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfo.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfo.java
@@ -35,13 +35,13 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.openecomp.sdc.be.components.impl.ImportUtils;
import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
import org.openecomp.sdc.be.components.impl.ImportUtils.ToscaElementTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
-import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.NodeTypeDefinition;
import org.openecomp.sdc.be.model.NodeTypeInfo;
import org.openecomp.sdc.be.model.NodeTypeMetadata;
@@ -49,8 +49,10 @@ import org.openecomp.sdc.be.model.NullNodeTypeMetadata;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
+import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
import org.openecomp.sdc.be.utils.TypeUtils;
import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum;
+import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.yaml.snakeyaml.Yaml;
@@ -63,12 +65,14 @@ public class ServiceCsarInfo extends CsarInfo {
private final Map<String, Map<String, Object>> mainTemplateImports;
private List<NodeTypeDefinition> nodeTypeDefinitions;
private final String model;
+ private final ModelOperation modelOperation;
public ServiceCsarInfo(final User modifier, final String csarUUID, final Map<String, byte[]> csar,
final String vfResourceName, final String model,
- final String mainTemplateName, final String mainTemplateContent, final boolean isUpdate) {
+ final String mainTemplateName, final String mainTemplateContent, final boolean isUpdate, final ModelOperation modelOperation) {
super(modifier, csarUUID, csar, vfResourceName, mainTemplateName, mainTemplateContent, isUpdate);
this.model = model;
+ this.modelOperation = modelOperation;
final Path mainTemplateDir = Paths.get(getMainTemplateName().substring(0, getMainTemplateName().lastIndexOf('/') + 1));
final Collection<Path> filesHandled = new HashSet<>();
filesHandled.add(Paths.get(mainTemplateName));
@@ -190,7 +194,7 @@ public class ServiceCsarInfo extends CsarInfo {
if (nodeTypeDefinitions == null) {
nodeTypeDefinitions = new ArrayList<>();
final Set<String> nodeTypesUsed = getNodeTypesUsedInToscaTemplate(getMappedToscaMainTemplate());
- nodeTypeDefinitions.addAll(getNodeTypeDefinitions(nodeTypesUsed));
+ nodeTypeDefinitions.addAll(getNodeTypeDefinitions(nodeTypesUsed).values());
}
nodeTypeDefinitions = sortNodeTypesByDependencyOrder(nodeTypeDefinitions);
return nodeTypeDefinitions;
@@ -226,11 +230,11 @@ public class ServiceCsarInfo extends CsarInfo {
return dependencies;
}
- private Set<NodeTypeDefinition> getNodeTypeDefinitions(final Set<String> nodeTypesToGet) {
- final Set<NodeTypeDefinition> foundNodeTypes = getTypes(nodeTypesToGet);
- final Set<NodeTypeDefinition> nodeTypesToReturn = new HashSet<>(foundNodeTypes);
+ private Map<String, NodeTypeDefinition> getNodeTypeDefinitions(final Set<String> nodeTypesToGet) {
+ final Map<String, NodeTypeDefinition> foundNodeTypes = getTypes(nodeTypesToGet);
+ final Map<String, NodeTypeDefinition> nodeTypesToReturn = new HashMap<>(foundNodeTypes);
final Set<String> recursiveNodeTypesToGet = new HashSet<>();
- foundNodeTypes.forEach(nodeTypeDef -> {
+ foundNodeTypes.values().forEach(nodeTypeDef -> {
Either<Object, ResultStatusEnum> derivedFromTypeEither =
findToscaElement((Map<String, Object>) nodeTypeDef.getMappedNodeType().getValue(), TypeUtils.ToscaTagNamesEnum.DERIVED_FROM,
ToscaElementTypeEnum.STRING);
@@ -240,25 +244,46 @@ public class ServiceCsarInfo extends CsarInfo {
});
recursiveNodeTypesToGet.removeAll(nodeTypesToGet);
if (CollectionUtils.isNotEmpty(recursiveNodeTypesToGet)) {
- nodeTypesToReturn.addAll(getNodeTypeDefinitions(recursiveNodeTypesToGet));
+ nodeTypesToReturn.putAll(getNodeTypeDefinitions(recursiveNodeTypesToGet));
}
return nodeTypesToReturn;
}
- private Set<NodeTypeDefinition> getTypes(final Set<String> nodeTypes) {
- Set<NodeTypeDefinition> nodeTypeDefinitionsLocal = new HashSet<>();
- mainTemplateImports.values().forEach(template -> {
- final Map<String, Object> types = getTypesFromTemplate(template, ToscaTagNamesEnum.NODE_TYPES, nodeTypes);
- if (MapUtils.isNotEmpty(types)) {
- types.entrySet().forEach(typesEntry -> {
- final NodeTypeMetadata metadata =
- getMetaDataFromTemplate(template, typesEntry.getKey());
- nodeTypeDefinitionsLocal.add(new NodeTypeDefinition(typesEntry, metadata));
- });
- }
- });
- return nodeTypeDefinitionsLocal;
+ private Map<String, NodeTypeDefinition> getTypes(final Set<String> nodeTypes) {
+ final Map<String, NodeTypeDefinition> nodeTypeDefinitionsMap = new HashMap<>();
+ final Set<String> lowerPrecedenceImports = new HashSet<>();
+
+ if (model != null && !model.equals(Constants.DEFAULT_MODEL_NAME)) {
+ final Set<String> modelImports = new HashSet<>();
+ modelOperation.findAllModelImports(model, true).forEach(modelImport -> modelImports.add("Definitions/" + modelImport.getFullPath()));
+
+ lowerPrecedenceImports.add("Definitions/" + ModelOperation.ADDITIONAL_TYPE_DEFINITIONS_PATH);
+ lowerPrecedenceImports.addAll(modelImports);
+
+ mainTemplateImports.entrySet().stream().filter(entry -> modelImports.contains(entry.getKey()))
+ .forEach(template -> addTypesFromTemplate(nodeTypeDefinitionsMap, template.getValue(), nodeTypes));
+
+ mainTemplateImports.entrySet().stream().filter(entry -> entry.getKey().equals(ModelOperation.ADDITIONAL_TYPE_DEFINITIONS_PATH.toString()))
+ .forEach(template -> addTypesFromTemplate(nodeTypeDefinitionsMap, template.getValue(), nodeTypes));
+ }
+
+ mainTemplateImports.entrySet().stream().filter(entry -> !lowerPrecedenceImports.contains(entry.getKey()))
+ .forEach(template -> addTypesFromTemplate(nodeTypeDefinitionsMap, template.getValue(), nodeTypes));
+
+ return nodeTypeDefinitionsMap;
+ }
+
+
+ private void addTypesFromTemplate(final Map<String, NodeTypeDefinition> nodeTypeDefinitionsMap, final Map<String, Object> mappedTemplate,
+ final Set<String> nodeTypes) {
+ final Map<String, Object> types = getTypesFromTemplate(mappedTemplate, ToscaTagNamesEnum.NODE_TYPES, nodeTypes);
+ if (MapUtils.isNotEmpty(types)) {
+ types.entrySet().forEach(typesEntry -> {
+ final NodeTypeMetadata metadata = getMetaDataFromTemplate(mappedTemplate, typesEntry.getKey());
+ nodeTypeDefinitionsMap.put(typesEntry.getKey(), new NodeTypeDefinition(typesEntry, metadata));
+ });
+ }
}
@SuppressWarnings("unchecked")