diff options
author | vasraz <vasyl.razinkov@est.tech> | 2023-09-22 14:51:31 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2023-09-25 11:03:32 +0000 |
commit | f4668df71072c8ecd4b9d05423006265b36a6ef7 (patch) | |
tree | 91c147e039b45b91e65eecea174f94a3b96ad27d | |
parent | ceaf83e0f29c10e4521321abcd6dd17080d2db60 (diff) |
Fix 'Substitution Node not updated during import'-bug
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Change-Id: I3b99e4c60a5971916ed593b8d4161da58ddab6d6
Issue-ID: SDC-4633
6 files changed, 62 insertions, 39 deletions
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 7837588178..8352a8d628 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 @@ -22,6 +22,7 @@ package org.openecomp.sdc.be.components.csar; import static org.openecomp.sdc.be.components.impl.ImportUtils.Constants.DEFAULT_ICON; +import static org.openecomp.sdc.be.components.impl.ImportUtils.findFirstToscaStringElement; import static org.openecomp.sdc.be.components.impl.ImportUtils.findToscaElement; import fj.data.Either; @@ -282,16 +283,18 @@ public class ServiceCsarInfo extends CsarInfo { } @SuppressWarnings("unchecked") - private Set<String> getNodeTypesUsedInToscaTemplate(Map<String, Object> mappedToscaTemplate) { - final Either<Object, ResultStatusEnum> nodeTemplatesEither = findToscaElement(mappedToscaTemplate, - TypeUtils.ToscaTagNamesEnum.NODE_TEMPLATES, ToscaElementTypeEnum.MAP); - final Set<String> nodeTypesUsedInNodeTemplates = new HashSet<>(); + private Set<String> getNodeTypesUsedInToscaTemplate(final Map<String, Object> mappedToscaTemplate) { + final var nodeTemplatesEither = findToscaElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.NODE_TEMPLATES, ToscaElementTypeEnum.MAP); + final Set<String> nodeTypesUsedInToscaTemplate = new HashSet<>(); if (nodeTemplatesEither.isLeft()) { - final Map<String, Map<String, Object>> nodeTemplates = - (Map<String, Map<String, Object>>) nodeTemplatesEither.left().value(); - nodeTypesUsedInNodeTemplates.addAll(findNodeTypesUsedInNodeTemplates(nodeTemplates)); + final var nodeTemplates = (Map<String, Map<String, Object>>) nodeTemplatesEither.left().value(); + nodeTypesUsedInToscaTemplate.addAll(findNodeTypesUsedInNodeTemplates(nodeTemplates)); } - return nodeTypesUsedInNodeTemplates; + final var substitutionMappingsNodeType = findFirstToscaStringElement(mappedToscaTemplate, ToscaTagNamesEnum.NODE_TYPE); + if (substitutionMappingsNodeType.isLeft()){ + nodeTypesUsedInToscaTemplate.add(substitutionMappingsNodeType.left().value()); + } + return nodeTypesUsedInToscaTemplate; } private NodeTypeMetadata getMetaDataFromTemplate(Map<String, Object> mappedResourceTemplate, String nodeTemplateType) { @@ -320,7 +323,6 @@ public class ServiceCsarInfo extends CsarInfo { category.setName((String) metadata.get("category")); category.setNormalizedName(((String) metadata.get("category")).toLowerCase()); category.setIcons(List.of(DEFAULT_ICON)); - category.setNormalizedName(((String) metadata.get("category")).toLowerCase()); category.addSubCategory(subCategory); List<CategoryDefinition> categories = new ArrayList<>(); categories.add(category); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java index 3b0d19f03c..2d29f80017 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java @@ -109,7 +109,6 @@ import org.openecomp.sdc.be.datatypes.elements.SubPropertyToscaFunction; import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterPropertyDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ToscaFunction; import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition; -import org.openecomp.sdc.be.datatypes.enums.ConstraintType; import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionType; import org.openecomp.sdc.be.datatypes.enums.ConstraintType; import org.openecomp.sdc.be.datatypes.enums.FilterValueType; @@ -201,14 +200,12 @@ public class YamlTemplateParsingHandler { if (substitutionMappings != null) { if (component.isService()) { if (interfaceTemplateYaml.isEmpty()) { - Resource resource = serviceBusinessLogic.fetchDerivedFromGenericType(component, null); - List<PropertyDefinition> properties = resource.getProperties(); + List<PropertyDefinition> properties = serviceBusinessLogic.fetchDerivedFromGenericType(component, null).getProperties(); parsedToscaYamlInfo.setProperties(properties.stream().collect(Collectors.toMap(PropertyDefinition::getName, prop -> prop))); - parsedToscaYamlInfo.setSubstitutionFilterProperties(getSubstitutionFilterProperties(mappedToscaTemplate)); } else { parsedToscaYamlInfo.setProperties(getProperties(loadYamlAsStrictMap(interfaceTemplateYaml))); - parsedToscaYamlInfo.setSubstitutionFilterProperties(getSubstitutionFilterProperties(mappedToscaTemplate)); } + parsedToscaYamlInfo.setSubstitutionFilterProperties(getSubstitutionFilterProperties(mappedToscaTemplate)); } if (substitutionMappings.get("properties") != null) { parsedToscaYamlInfo.setSubstitutionMappingProperties((Map<String, List<String>>) substitutionMappings.get("properties")); @@ -1442,7 +1439,7 @@ public class YamlTemplateParsingHandler { for (Object objValue : propValueList) { if (objValue instanceof Map) { Map<String, Object> objMap = (Map<String, Object>) objValue; - Map<String, Object> propValueMap = new HashMap<String, Object>(); + Map<String, Object> propValueMap = new HashMap<>(); propValueMap.put(String.valueOf(index), objValue); final Collection<SubPropertyToscaFunction> subPropertyToscaFunctions = buildSubPropertyToscaFunctions(propValueMap, new ArrayList<>()); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CommonCsarGenerator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CommonCsarGenerator.java index 633dd6e483..3fa8745f01 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CommonCsarGenerator.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CommonCsarGenerator.java @@ -643,7 +643,7 @@ public class CommonCsarGenerator { final List<ToscaImportByModel> modelDefaultImportList = modelOperation.findAllModelImports(modelName, true); final Set<Path> writtenEntryPathList = new HashSet<>(); final var defsPath = Path.of(definitionsPath); - Map<Path, byte[]> contentToMerge = new HashMap(); + Map<Path, byte[]> contentToMerge = new HashMap<>(); for (final ToscaImportByModel toscaImportByModel : modelDefaultImportList) { var importPath = Path.of(toscaImportByModel.getFullPath()); if (!isSingleImportsFile) { @@ -675,15 +675,15 @@ public class CommonCsarGenerator { } if (!isSingleImportsFile) { byte[] mergingContent = new byte[0]; - for (Map.Entry entry : contentToMerge.entrySet()) { + for (Map.Entry<Path, byte[]> entry : contentToMerge.entrySet()) { if (ADDITIONAL_TYPE_DEFINITIONS.equals(Paths.get(String.valueOf(entry.getKey())).normalize().toString())) { - mergingContent = (byte[]) entry.getValue(); + mergingContent = Bytes.concat(mergingContent, entry.getValue()); } else { final var zipEntry = new ZipEntry(entry.getKey().toString()); zipOutputStream.putNextEntry(zipEntry); - writtenEntryPathList.add((Path) entry.getKey()); - zipOutputStream.write(Bytes.concat(mergingContent, (byte[]) entry.getValue()), 0, - ((byte[]) entry.getValue()).length); + writtenEntryPathList.add(entry.getKey()); + final var concat = Bytes.concat(mergingContent, entry.getValue()); + zipOutputStream.write(concat, 0, concat.length); zipOutputStream.closeEntry(); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java index 0d6922e3f2..d64aaf8cd0 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java @@ -477,7 +477,7 @@ class ResourceImportManagerTest { NodeTypesMetadataList nodeTypesMetadataList = new NodeTypesMetadataList(); List<NodeTypeMetadata> nodeTypeMetadataList = new ArrayList<>(); Map<String, Object> allTypesToCreate = new HashMap<>(); - ServiceCsarInfo csarInfo= getCsarInfo(); + ServiceCsarInfo csarInfo = getCsarInfo(); List<NodeTypeDefinition> nodeTypesToCreate = csarInfo.getNodeTypesUsed(); nodeTypesToCreate.stream().forEach(nodeType -> { allTypesToCreate.put(nodeType.getMappedNodeType().getKey(), nodeType.getMappedNodeType().getValue()); @@ -487,15 +487,26 @@ class ResourceImportManagerTest { when(toscaOperationFacade.getLatestByName(any(), any())).thenReturn(Either.left(null)).thenReturn(Either.left(null)); when(toscaOperationFacade.getLatestByToscaResourceName("org.openecomp.resource.VFC-root", "ETSI SOL001 v2.5.1")) - .thenReturn(Either.left(null)); - when(resourceBusinessLogic - .createOrUpdateResourceByImport(any(Resource.class), any(User.class), eq(true), eq(true), eq(false), eq(null), eq(null), eq(false))) - .thenReturn(new ImmutablePair<>(new Resource(), ActionStatus.OK)).thenReturn(new ImmutablePair<>(new Resource(), ActionStatus.OK)); + .thenReturn(Either.left(null)); + when(toscaOperationFacade.getLatestByToscaResourceName("tosca.nodes.nfv.NS", "")) + .thenReturn(Either.left(createResourceNS())); + when(toscaOperationFacade.getLatestByToscaResourceName("org.openecomp.service.Etsiwithchild", "")) + .thenReturn(Either.right(null)); + when(resourceBusinessLogic.createOrUpdateResourceByImport(any(Resource.class), any(User.class), eq(true), eq(true), eq(false), eq(null), + eq(null), eq(false))).thenReturn(new ImmutablePair<>(new Resource(), ActionStatus.OK)) + .thenReturn(new ImmutablePair<>(new Resource(), ActionStatus.OK)); + when(responseFormatManager.getResponseFormat(ActionStatus.GENERAL_ERROR)).thenReturn(mock(ResponseFormat.class)); importManager.importAllNormativeResource(allTypesToCreate, nodeTypesMetadataList, null, user, "", false, false); verify(janusGraphDao).commit(); } + private Resource createResourceNS() { + Resource ns = new Resource(); + ns.setName("tosca.nodes.nfv.NS"); + return ns; + } + private void setResourceBusinessLogicMock() { when(resourceBusinessLogic.getUserAdmin()).thenReturn(userAdmin); when(resourceBusinessLogic.createOrUpdateResourceByImport(any(Resource.class), any(User.class), anyBoolean(), anyBoolean(), anyBoolean(), @@ -768,7 +779,8 @@ class ResourceImportManagerTest { assertNotNull(mainTemplateService); final String mainTemplateContent = new String(mainTemplateService); - return new ServiceCsarInfo(user, csarUuid, csar, vfReousrceName, null, mainTemplateName, mainTemplateContent, false, mock(ModelOperation.class)); + return new ServiceCsarInfo(user, csarUuid, csar, vfReousrceName, null, mainTemplateName, mainTemplateContent, false, + mock(ModelOperation.class)); } catch (URISyntaxException | ZipException e) { fail(e); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java index fc709ceaea..c6ba0ba9ac 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java @@ -212,11 +212,13 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest when(csarBusinessLogic.getCsarInfo(any(Service.class), any(), any(User.class), any(Map.class), anyString(), any())).thenReturn(csarInfo); when(serviceImportParseLogic.findNodeTypesArtifactsToHandle(any(Map.class), any(CsarInfo.class), any(Service.class))) .thenReturn(Either.left(new HashMap<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>>())); - doReturn(getParsedToscaYamlInfo()).when(csarBusinessLogic).getParsedToscaYamlInfo(anyString(), anyString(), any(), any(CsarInfo.class), any(), any(Service.class)); + doReturn(getParsedToscaYamlInfo()).when(csarBusinessLogic) + .getParsedToscaYamlInfo(anyString(), anyString(), any(), any(CsarInfo.class), any(), any(Service.class)); doReturn(getParsedToscaYamlInfo()).when(csarBusinessLogic).getParsedToscaYamlInfo(any(ServiceCsarInfo.class), any(Service.class)); when(serviceBusinessLogic.lockComponentByName(newService.getSystemName(), oldService, CREATE_RESOURCE)).thenReturn(Either.left(true)); when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString())).thenReturn(Either.left(createOldResource())); - when(serviceImportParseLogic.createServiceTransaction(oldService, csarInfo.getModifier(), false, AuditingActionEnum.CREATE_RESOURCE)).thenReturn(newService); + when(serviceImportParseLogic.createServiceTransaction(oldService, csarInfo.getModifier(), false, + AuditingActionEnum.CREATE_RESOURCE)).thenReturn(newService); when(serviceImportParseLogic.createInputsOnService(eq(oldService), anyMap())).thenReturn(newService); Assertions.assertDoesNotThrow(() -> { when(serviceImportParseLogic.createSubstitutionFilterOnService(eq(oldService), any())).thenReturn(newService); @@ -258,14 +260,16 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest properties.add(versionProperty); typeToBeUpdated.setProperties(properties); when(applicationDataTypeCache.get(any(), eq("onap.datatypes.ToscaConceptIdentifier.datatype"))).thenReturn(Either.left(typeToBeUpdated)); - when(applicationDataTypeCache.get(any(), matches("^((?!(tosca.datatypes.test_|onap.datatypes.ToscaConceptIdentifier)).)*$"))).thenReturn(Either.left(new DataTypeDefinition())); + when(applicationDataTypeCache.get(any(), matches("^((?!(tosca.datatypes.test_|onap.datatypes.ToscaConceptIdentifier)).)*$"))).thenReturn( + Either.left(new DataTypeDefinition())); - when(artifactTypeOperation.getArtifactTypeByUid(contains("tosca.testartifacts.Name"))).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); + when(artifactTypeOperation.getArtifactTypeByUid(contains("tosca.testartifacts.Name"))).thenReturn( + Either.right(StorageOperationStatus.NOT_FOUND)); when(artifactTypeOperation.getArtifactTypeByUid(contains("tosca.artifacts"))).thenReturn(Either.left(null)); when(interfaceLifecycleTypeOperation.getInterface(contains("tosca.interfaces"))).thenReturn(Either.left(new InterfaceDefinition())); - when(interfaceLifecycleTypeOperation.getInterface(contains("tosca.interfaces.test"))).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); - + when(interfaceLifecycleTypeOperation.getInterface(contains("tosca.interfaces.test"))).thenReturn( + Either.right(StorageOperationStatus.NOT_FOUND)); when(capabilityTypeOperation.getCapabilityType(anyString())) .thenReturn(Either.left(new CapabilityTypeDefinition())); @@ -273,12 +277,15 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); when(toscaOperationFacade.getLatestByToscaResourceName(contains("org.openecomp.resource"), isNull())) - .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); + .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); when(toscaOperationFacade.getLatestByToscaResourceName(contains("tosca.nodes."), isNull())) - .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); + .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); when(toscaOperationFacade.getLatestByToscaResourceName(updatedNodeType, null)).thenReturn(Either.left(resource)); - when(artifactsBusinessLogic.handleDownloadRequestById(resourceUniqueId, artifactUniqueId, user.getUserId(), ComponentTypeEnum.RESOURCE, null, null)) - .thenReturn(resourceTemplate); + when(toscaOperationFacade.getLatestByToscaResourceName(contains("org.openecomp.service."), isNull())) + .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); + when(artifactsBusinessLogic.handleDownloadRequestById(resourceUniqueId, artifactUniqueId, user.getUserId(), ComponentTypeEnum.RESOURCE, null, + null)) + .thenReturn(resourceTemplate); when(toscaOperationFacade.updatePropertyOfComponent(eq(oldService), any(PropertyDefinition.class))).thenReturn(Either.left(null)); when(toscaOperationFacade.updateComponentInstancePropsToComponent(anyMap(), anyString())).thenReturn(Either.left(null)); when(groupTypeOperation.getGroupTypeByUid(anyString())).thenReturn(Either.left(new GroupTypeDefinition())); @@ -304,7 +311,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest assertNotNull(yamlMap.get("onap.datatypes.ToscaConceptIdentifier")); ArgumentCaptor<String> artifactTypes = ArgumentCaptor.forClass(String.class); - verify(artifactTypeImportManager).createArtifactTypes(artifactTypes.capture(),isNull(), anyBoolean()); + verify(artifactTypeImportManager).createArtifactTypes(artifactTypes.capture(), isNull(), anyBoolean()); Map<String, Object> artifactTypesMap = new Yaml().load(artifactTypes.getValue()); assertEquals(1, artifactTypesMap.size()); assertNotNull(artifactTypesMap.get("tosca.testartifacts.Name")); @@ -320,7 +327,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest ArgumentCaptor<Map<String, Object>> nodeTypes = ArgumentCaptor.forClass(Map.class); verify(resourceImportManager).importAllNormativeResource(nodeTypes.capture(), any(), any(), any(), any(), - anyBoolean(), anyBoolean()); + anyBoolean(), anyBoolean()); Map<String, Object> nodeTypesMap = nodeTypes.getValue(); Map<String, Object> newUpdatedNodeType = (Map<String, Object>) nodeTypesMap.get(updatedNodeType); assertEquals(8, ((Map<String, Object>) newUpdatedNodeType.get("properties")).size()); diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java index a253d815ad..f8665b7845 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java @@ -1329,6 +1329,11 @@ public class TopologyTemplateOperation extends ToscaElementOperation { log.debug("Failed to disassociate capabilities for {} error {}", toscaElementVertex.getUniqueId(), status); return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } + status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.SUBSTITUTION_FILTER_TEMPLATE); + if (status != JanusGraphOperationStatus.OK) { + log.debug("Failed to disassociate substitution filter template for {} error {}", toscaElementVertex.getUniqueId(), status); + return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); + } toscaElementVertex.getVertex().remove(); log.trace("Tosca element vertex for {} was removed", toscaElementVertex.getUniqueId()); |