From 97b5fa431d5924d90e97adedf76f3ce5648cd938 Mon Sep 17 00:00:00 2001 From: MichaelMorris Date: Fri, 19 Aug 2022 09:36:41 +0100 Subject: Support updated data types in service import Signed-off-by: MichaelMorris Issue-ID: SDC-4140 Change-Id: Ib66d47a0f566b648722ce86cfc4e208880551a29 --- .../sdc/be/components/impl/CommonImportManager.java | 8 ++++++++ .../be/components/impl/DataTypeImportManager.java | 5 ++++- .../components/impl/ServiceImportBusinessLogic.java | 12 ++++++++++++ .../impl/ServiceImportBusinessLogicTest.java | 19 +++++++++++++++++-- .../resources/csars/service-Ser09080002-csar.csar | Bin 65020 -> 64137 bytes 5 files changed, 41 insertions(+), 3 deletions(-) (limited to 'catalog-be') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java index f1582eecb1..6bbeed0dd0 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java @@ -538,9 +538,17 @@ public class CommonImportManager { public void addTypesToDefaultImports(final ElementTypeEnum elementTypeEnum, final String typesYaml, final String modelName) { modelOperation.addTypesToDefaultImports(elementTypeEnum, typesYaml, modelName); } + + public void updateTypesInAdditionalTypesImport(final ElementTypeEnum elementTypeEnum, final String dataTypeYml, final String modelName) { + modelOperation.updateTypesInAdditionalTypesImport(elementTypeEnum, dataTypeYml, modelName); + } public interface ICreateElementType { T3 createElement(T1 firstArg, T2 secondArg); } + + + + } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeImportManager.java index 943edb1b95..d488c65b22 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeImportManager.java @@ -65,12 +65,15 @@ public class DataTypeImportManager { public Either>, ResponseFormat> createDataTypes(final String dataTypeYml, final String modelName, final boolean includeToModelDefaultImports) { - final var elementTypes = commonImportManager.createElementTypes( + final Either>, ResponseFormat> elementTypes = commonImportManager.createElementTypes( dataTypeYml, dataTypesFromYml -> createDataTypesFromYml(dataTypeYml, modelName), this::createDataTypesByDao, ElementTypeEnum.DATA_TYPE); if (includeToModelDefaultImports && StringUtils.isNotEmpty(modelName)) { commonImportManager.addTypesToDefaultImports(ElementTypeEnum.DATA_TYPE, dataTypeYml, modelName); } + if (!includeToModelDefaultImports && StringUtils.isNotEmpty(modelName) && elementTypes.isLeft()) { + commonImportManager.updateTypesInAdditionalTypesImport(ElementTypeEnum.DATA_TYPE, dataTypeYml, modelName); + } return elementTypes; } 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 a3e3a6ba58..b4079ac0d2 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 @@ -250,6 +250,9 @@ public class ServiceImportBusinessLogic { final Map dataTypesToCreate = getDatatypesToCreate(service.getModel(), csarInfo); if (MapUtils.isNotEmpty(dataTypesToCreate)) { dataTypeBusinessLogic.createDataTypeFromYaml(new Yaml().dump(dataTypesToCreate), service.getModel(), true); + dataTypesToCreate.entrySet().stream().forEach(createdOrUpdatedDataType -> { + applicationDataTypeCache.reload(service.getModel(), UniqueIdBuilder.buildDataTypeUid(service.getModel(), createdOrUpdatedDataType.getKey())); + }); } final List nodeTypesToCreate = getNodeTypesToCreate(service.getModel(), csarInfo); if (CollectionUtils.isNotEmpty(nodeTypesToCreate)) { @@ -283,9 +286,18 @@ public class ServiceImportBusinessLogic { dataTypesToCreate.put(dataTypeEntry.getKey(), dataTypeEntry.getValue()); log.info("Deploying unknown type " + dataTypeEntry.getKey() + " to model " + model + " from package " + csarInfo.getCsarUUID()); } + if (hasNewProperties(result, (Map>) dataTypeEntry.getValue())) { + dataTypesToCreate.put(dataTypeEntry.getKey(), dataTypeEntry.getValue()); + log.info("Deploying new version of type " + dataTypeEntry.getKey() + " to model " + model + " from package " + csarInfo.getCsarUUID()); + } } return dataTypesToCreate; } + + private boolean hasNewProperties(final Either result, final Map> dataType) { + return result.isLeft() && dataType.containsKey("properties") && result.left().value().getProperties() != null + && result.left().value().getProperties().size() != dataType.get("properties").size(); + } private void createNodeTypes(List nodeTypesToCreate, ServiceCsarInfo csarInfo) { NodeTypesMetadataList nodeTypesMetadataList = new NodeTypesMetadataList(); 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 07593a0cd7..3f8f9c382c 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 @@ -218,7 +218,21 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest when(toscaOperationFacade.updateInputsToComponent(anyList(), eq(newService.getUniqueId()))).thenReturn(Either.left(new ArrayList<>())); when(applicationDataTypeCache.get(any(), contains("tosca.datatypes.test_"))).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)); - when(applicationDataTypeCache.get(any(), matches("^((?!tosca.datatypes.test_).)*$"))).thenReturn(Either.left(new DataTypeDefinition())); + DataTypeDefinition typeToBeUpdated = new DataTypeDefinition(); + List properties = new ArrayList<>(); + PropertyDefinition nameProperty = new PropertyDefinition(); + nameProperty.setName("name"); + nameProperty.setType("string"); + properties.add(nameProperty); + PropertyDefinition versionProperty = new PropertyDefinition(); + versionProperty.setName("version"); + versionProperty.setType("string"); + 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(toscaOperationFacade.getLatestByToscaResourceName(contains("org.openecomp.resource"), isNull())).thenReturn(Either.left(null)); when(toscaOperationFacade.getLatestByToscaResourceName(contains("tosca.nodes."), isNull())).thenReturn(Either.left(null)); @@ -240,9 +254,10 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest ArgumentCaptor yaml = ArgumentCaptor.forClass(String.class); verify(dataTypeBusinessLogic).createDataTypeFromYaml(yaml.capture(), isNull(), anyBoolean()); Map yamlMap = new Yaml().load(yaml.getValue()); - assertEquals(2, yamlMap.size()); + assertEquals(3, yamlMap.size()); assertNotNull(yamlMap.get("tosca.datatypes.test_a")); assertNotNull(yamlMap.get("tosca.datatypes.test_b")); + assertNotNull(yamlMap.get("onap.datatypes.ToscaConceptIdentifier")); } @Test diff --git a/catalog-be/src/test/resources/csars/service-Ser09080002-csar.csar b/catalog-be/src/test/resources/csars/service-Ser09080002-csar.csar index a65850469d..00a6981272 100644 Binary files a/catalog-be/src/test/resources/csars/service-Ser09080002-csar.csar and b/catalog-be/src/test/resources/csars/service-Ser09080002-csar.csar differ -- cgit 1.2.3-korg