From: vasraz Date: Fri, 18 Aug 2023 18:40:44 +0000 (+0100) Subject: Fix 'Fail to import service with CP'-bug X-Git-Tag: 1.13.4~23 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=sdc.git;a=commitdiff_plain;h=fda41360dcb7e68c8e3003c73fdb98db2514bf5f Fix 'Fail to import service with CP'-bug Signed-off-by: Vasyl Razinkov Change-Id: I7261b03eb7e796aaa66ac3dbd0116bc62d2d6e71 Issue-ID: SDC-4599 --- diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java index 1ba74a1594..bf27d030b5 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java @@ -539,7 +539,8 @@ public class ServiceImportBusinessLogic { && result.left().value().getProperties().size() != dataType.get("properties").size(); } - private void createNodeTypes(List nodeTypesToCreate, Map instancesFromCsar, String model, User user) { + private void createNodeTypes(List nodeTypesToCreate, Map instancesFromCsar, String model, + User user) { NodeTypesMetadataList nodeTypesMetadataList = new NodeTypesMetadataList(); List nodeTypeMetadataList = new ArrayList<>(); final Map allTypesToCreate = new HashMap<>(); @@ -611,7 +612,7 @@ public class ServiceImportBusinessLogic { private void combineInterfacesIntoToscaTemplate(Map> newInterfaces, Map> existingInterfaces, Map combinedMappedToscaTemplate) { - Map> combinedInterfaces = combineAdditionalInterfaces(existingInterfaces, newInterfaces); + Map> combinedInterfaces = combineAdditionalInterfaces(newInterfaces, existingInterfaces); if ((MapUtils.isEmpty(existingInterfaces) && MapUtils.isNotEmpty(combinedInterfaces)) || (MapUtils.isNotEmpty(existingInterfaces) && !existingInterfaces.equals(combinedInterfaces))) { combinedMappedToscaTemplate.put("interfaces", combinedInterfaces); @@ -654,8 +655,11 @@ public class ServiceImportBusinessLogic { } } - private Map> combineAdditionalInterfaces(Map> existingInterfaces, - Map> newInterfaces) { + private Map> combineAdditionalInterfaces(Map> newInterfaces, + Map> existingInterfaces) { + if (MapUtils.isNotEmpty(newInterfaces) && MapUtils.isNotEmpty(existingInterfaces) && newInterfaces.equals(existingInterfaces)) { + return new HashMap<>(existingInterfaces); + } if (MapUtils.isEmpty(newInterfaces)) { newInterfaces = new HashMap<>(); } @@ -676,6 +680,9 @@ public class ServiceImportBusinessLogic { private List> combineAdditionalRequirements(List> newReqs, List> existingResourceReqs) { + if (CollectionUtils.isNotEmpty(newReqs) && CollectionUtils.isNotEmpty(existingResourceReqs) && newReqs.equals(existingResourceReqs)) { + return new ArrayList<>(existingResourceReqs); + } if (CollectionUtils.isEmpty(existingResourceReqs)) { existingResourceReqs = new ArrayList<>(); } @@ -690,6 +697,9 @@ public class ServiceImportBusinessLogic { } private Map combineEntries(Map newMap, Map existingMap) { + if (MapUtils.isNotEmpty(newMap) && MapUtils.isNotEmpty(existingMap) && newMap.equals(existingMap)) { + return new HashMap<>(existingMap); + } if (MapUtils.isEmpty(newMap)) { newMap = new HashMap<>(); } @@ -861,7 +871,8 @@ public class ServiceImportBusinessLogic { } } if (CollectionUtils.isNotEmpty(propertyMissingNames)) { - throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.MISSING_PROPERTIES_ERROR, propertyMissingNames.toString())); + throw new ComponentException( + componentsUtils.getResponseFormat(ActionStatus.MISSING_PROPERTIES_ERROR, propertyMissingNames.toString())); } Either, StorageOperationStatus> either = toscaOperationFacade.updateInputsToComponent(inputs, componentUniqueId); if (either.isRight()) { @@ -927,8 +938,8 @@ public class ServiceImportBusinessLogic { } private String associateInputToServiceProperty(final String userId, - final InputDefinition input, final Service component, - final Map> substitutionMappingProperties) { + final InputDefinition input, final Service component, + final Map> substitutionMappingProperties) { final List properties = component.getProperties(); if (CollectionUtils.isNotEmpty(properties) && MapUtils.isNotEmpty(substitutionMappingProperties)) { AtomicReference propertyNameFromInput = new AtomicReference<>(" "); @@ -2388,7 +2399,8 @@ public class ServiceImportBusinessLogic { Map operations = uploadInterfaceInfo.getOperations(); for (Map.Entry operation : operations.entrySet()) { OperationDataDefinition instanceOperation = operation.getValue(); - OperationDataDefinition templateOperation = currentInterfaceDef.getOperationsMap().getOrDefault(operation.getKey(), new Operation(instanceOperation)); + OperationDataDefinition templateOperation = currentInterfaceDef.getOperationsMap() + .getOrDefault(operation.getKey(), new Operation(instanceOperation)); //Inputs ListDataDefinition instanceInputs = instanceOperation.getInputs(); if (null != instanceInputs) { diff --git a/catalog-ui/src/app/utils/service-csar-reader.ts b/catalog-ui/src/app/utils/service-csar-reader.ts index 20dfe6ca6b..4c9b0cd0ca 100644 --- a/catalog-ui/src/app/utils/service-csar-reader.ts +++ b/catalog-ui/src/app/utils/service-csar-reader.ts @@ -82,7 +82,10 @@ export class ServiceCsarReader { } private readSubstitutionNodeFromMainTemplateFile(entryDefinitionFileContent) { - this.serviceCsar.substitutionNodeType = load(entryDefinitionFileContent).topology_template.substitution_mappings.node_type; + const loadEntryDefinitionFileContent = load(entryDefinitionFileContent); + if (loadEntryDefinitionFileContent.topology_template && loadEntryDefinitionFileContent.topology_template.substitution_mappings) { + this.serviceCsar.substitutionNodeType = loadEntryDefinitionFileContent.topology_template.substitution_mappings.node_type; + } } private setMetadata = (metadata:object) : void => { @@ -147,4 +150,4 @@ export class ServiceCsarReader { }); this.serviceCsar.extraServiceMetadata = extraServiceMetadata; } -} \ No newline at end of file +}