From 6fa01940a1dec7a323f87f7a141dbef04d8af3d3 Mon Sep 17 00:00:00 2001 From: KrupaNagabhushan Date: Wed, 21 Sep 2022 13:21:40 +0100 Subject: Service import - Import unknown interface types Issue-ID: SDC-4186 Signed-off-by: KrupaNagabhushan Change-Id: Idfbce90e795136ef2ea1a96f65e458db9206339f --- .../openecomp/sdc/be/components/csar/CsarInfo.java | 7 +++++ .../sdc/be/components/csar/OnboardedCsarInfo.java | 7 ++++- .../sdc/be/components/csar/ServiceCsarInfo.java | 6 +++++ .../impl/ServiceImportBusinessLogic.java | 30 +++++++++++++++++++-- .../be/components/csar/ServiceCsarInfoTest.java | 14 +++++++++- .../impl/ServiceImportBusinessLogicTest.java | 14 ++++++++++ .../resources/csars/service-Ser09080002-csar.csar | Bin 63922 -> 63966 bytes .../csars/serviceWithUnknownDataTypes.csar | Bin 56980 -> 0 bytes .../resources/csars/serviceWithUnknownTypes.csar | Bin 0 -> 57080 bytes 9 files changed, 74 insertions(+), 4 deletions(-) delete mode 100644 catalog-be/src/test/resources/csars/serviceWithUnknownDataTypes.csar create mode 100644 catalog-be/src/test/resources/csars/serviceWithUnknownTypes.csar (limited to 'catalog-be') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java index f92c1d10d2..c401660e27 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java @@ -183,6 +183,13 @@ public abstract class CsarInfo { public abstract Map getArtifactTypes(); + /** + * Get the interface types defined in the CSAR + * + * @return map with the interface type name as key and representation of the interface type definition as value + */ + public abstract Map getInterfaceTypes(); + public Map getPolicyTypes() { if (policytypeDefinitions == null) { policytypeDefinitions = new HashMap<>(); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/OnboardedCsarInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/OnboardedCsarInfo.java index 9ab767876d..7cb11806e4 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/OnboardedCsarInfo.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/OnboardedCsarInfo.java @@ -24,6 +24,7 @@ package org.openecomp.sdc.be.components.csar; import static org.openecomp.sdc.be.components.impl.ImportUtils.findToscaElement; import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.DATA_TYPES; import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.GROUP_TYPES; +import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.INTERFACE_TYPES; import fj.data.Either; import java.util.ArrayList; @@ -216,6 +217,11 @@ public class OnboardedCsarInfo extends CsarInfo { return getTypes(GROUP_TYPES); } + @Override + public Map getInterfaceTypes() { + return getTypes(INTERFACE_TYPES); + } + @Override public Map getCapabilityTypes() { return getTypes(ToscaTagNamesEnum.CAPABILITY_TYPES); @@ -230,5 +236,4 @@ public class OnboardedCsarInfo extends CsarInfo { types.putAll(getTypesFromTemplate(mappedToscaMainTemplate, toscaTag)); return types; } - } 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 54cd29868b..3e0ea35713 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 @@ -41,6 +41,7 @@ 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; @@ -174,6 +175,11 @@ public class ServiceCsarInfo extends CsarInfo { return artifactsTypes; } + @Override + public Map getInterfaceTypes() { + return getTypes(ToscaTagNamesEnum.INTERFACE_TYPES); + } + public List getNodeTypesUsed() { if (nodeTypeDefinitions == null) { nodeTypeDefinitions = new ArrayList<>(); 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 151717f9cd..04798ec40a 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 @@ -144,6 +144,7 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.ArtifactTypeOperation; import org.openecomp.sdc.be.model.operations.impl.CapabilityTypeOperation; import org.openecomp.sdc.be.model.operations.impl.GroupTypeOperation; +import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation; import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder; import org.openecomp.sdc.be.model.tosca.ToscaPropertyType; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; @@ -203,6 +204,8 @@ public class ServiceImportBusinessLogic { private final GroupTypeImportManager groupTypeImportManager; private final GroupTypeOperation groupTypeOperation; + private InterfaceLifecycleOperation interfaceLifecycleTypeOperation; + private InterfaceLifecycleTypeImportManager interfaceLifecycleTypeImportManager; private final CapabilityTypeImportManager capabilityTypeImportManager; private final CapabilityTypeOperation capabilityTypeOperation; @@ -219,6 +222,8 @@ public class ServiceImportBusinessLogic { final DataTypeBusinessLogic dataTypeBusinessLogic, final ArtifactTypeOperation artifactTypeOperation, final ArtifactTypeImportManager artifactTypeImportManager, final GroupTypeImportManager groupTypeImportManager, final GroupTypeOperation groupTypeOperation, + final InterfaceLifecycleOperation interfaceLifecycleTypeOperation, + final InterfaceLifecycleTypeImportManager interfaceLifecycleTypeImportManager, final CapabilityTypeImportManager capabilityTypeImportManager, final CapabilityTypeOperation capabilityTypeOperation) { this.componentsUtils = componentsUtils; @@ -242,6 +247,8 @@ public class ServiceImportBusinessLogic { this.artifactTypeImportManager = artifactTypeImportManager; this.groupTypeImportManager = groupTypeImportManager; this.groupTypeOperation = groupTypeOperation; + this.interfaceLifecycleTypeOperation = interfaceLifecycleTypeOperation; + this.interfaceLifecycleTypeImportManager = interfaceLifecycleTypeImportManager; this.capabilityTypeImportManager = capabilityTypeImportManager; this.capabilityTypeOperation = capabilityTypeOperation; } @@ -310,6 +317,12 @@ public class ServiceImportBusinessLogic { groupTypeImportManager.createGroupTypes(toscaTypeImportData, service.getModel(), true); } + final Map interfaceTypesToCreate = getInterfaceTypesToCreate(service.getModel(), csarInfo); + if (MapUtils.isNotEmpty(interfaceTypesToCreate)) { + interfaceLifecycleTypeImportManager + .createLifecycleTypes(new Yaml().dump(interfaceTypesToCreate), service.getModel(), true); + } + final Map capabilityTypesToCreate = getCapabilityTypesToCreate(service.getModel(), csarInfo); if (MapUtils.isNotEmpty(capabilityTypesToCreate)) { @@ -426,8 +439,21 @@ public class ServiceImportBusinessLogic { return artifactTypesToCreate; } - private boolean hasNewProperties(final Either result, - final Map> dataType) { + private Map getInterfaceTypesToCreate(final String model, final CsarInfo csarInfo) { + final Map interfaceTypesToCreate = new HashMap<>(); + Map interfacetypeMap = csarInfo.getInterfaceTypes(); + + interfacetypeMap.entrySet().forEach(interfacetypeDef -> { + Either interfaceDefinition = + interfaceLifecycleTypeOperation.getInterface(UniqueIdBuilder.buildInterfaceTypeUid(model, interfacetypeDef.getKey())); + if (interfaceDefinition.isRight() && interfaceDefinition.right().value().equals(StorageOperationStatus.NOT_FOUND)) { + interfaceTypesToCreate.put(interfacetypeDef.getKey(), interfacetypeDef.getValue()); + } + }); + return interfaceTypesToCreate; + } + + 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(); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfoTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfoTest.java index 80ecc212f1..add427d164 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfoTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfoTest.java @@ -47,7 +47,7 @@ class ServiceCsarInfoTest { private User user; private static final String CSAR_UUID = "csarUUID"; - private static final String PAYLOAD_NAME = "csars/serviceWithUnknownDataTypes.csar"; + private static final String PAYLOAD_NAME = "csars/serviceWithUnknownTypes.csar"; private static final String SERVICE_NAME = "serviceWithDataType"; private static final String MAIN_TEMPLATE_NAME = "Definitions/service-Servicewithdatatype-template.yml"; @@ -78,4 +78,16 @@ return new ServiceCsarInfo(user, CSAR_UUID, payload, SERVICE_NAME, mainTemplateN ((Map) ((Map) dataTypeDefinition.get("properties")).get("prop2")).get("type")); } + @SuppressWarnings("unchecked") + @Test + void testGetInterfaceTypes() { + final Map interfaceTypes = csarInfo.getInterfaceTypes(); + assertEquals(9, interfaceTypes.size()); + final Map interfaceTypeDefinition = (Map) interfaceTypes.get( + "tosca.interfaces.test.node.lifecycle.Reconfigure"); + assertNotNull(interfaceTypeDefinition); + assertEquals("tosca.interfaces.Root", interfaceTypeDefinition.get("derived_from")); + assertEquals("reconfigure", ((Map) interfaceTypeDefinition.get("Reconfigure")).get("description")); + } + } 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 944f51c244..faaa7e3162 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 @@ -143,6 +143,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest private final GroupTypeOperation groupTypeOperation = mock(GroupTypeOperation.class); private final CapabilityTypeOperation capabilityTypeOperation = mock(CapabilityTypeOperation.class); private final CapabilityTypeImportManager capabilityTypeImportManager = mock(CapabilityTypeImportManager.class); + private final InterfaceLifecycleTypeImportManager interfaceLifecycleTypeImportManager = mock(InterfaceLifecycleTypeImportManager.class); @InjectMocks private ServiceImportBusinessLogic sIBL; @@ -256,6 +257,10 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest 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(capabilityTypeOperation.getCapabilityType(anyString())) .thenReturn(Either.left(new CapabilityTypeDefinition())); when(capabilityTypeOperation.getCapabilityType(contains("tosca.testcapabilitytypes.Name"))) @@ -313,6 +318,15 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest Map nodeTypesMap = nodeTypes.getValue(); Map newUpdatedNodeType = (Map) nodeTypesMap.get(updatedNodeType); assertEquals(8, ((Map) newUpdatedNodeType.get("properties")).size()); + + ArgumentCaptor interfaceTypes = ArgumentCaptor.forClass(String.class); + verify(interfaceLifecycleTypeImportManager).createLifecycleTypes(interfaceTypes.capture(), any(), anyBoolean()); + Map yamlInterfaceMap = new Yaml().load(interfaceTypes.getValue()); + assertEquals(3, yamlInterfaceMap.size()); + assertNotNull(yamlInterfaceMap.get("tosca.interfaces.test.node.lifecycle.Attach")); + assertNotNull(yamlInterfaceMap.get("tosca.interfaces.test.node.lifecycle.Detach")); + assertNotNull(yamlInterfaceMap.get("tosca.interfaces.test.node.lifecycle.Reconfigure")); + } @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 c780e3484c..de7d71fc37 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 diff --git a/catalog-be/src/test/resources/csars/serviceWithUnknownDataTypes.csar b/catalog-be/src/test/resources/csars/serviceWithUnknownDataTypes.csar deleted file mode 100644 index ffd209978f..0000000000 Binary files a/catalog-be/src/test/resources/csars/serviceWithUnknownDataTypes.csar and /dev/null differ diff --git a/catalog-be/src/test/resources/csars/serviceWithUnknownTypes.csar b/catalog-be/src/test/resources/csars/serviceWithUnknownTypes.csar new file mode 100644 index 0000000000..b50113c2d2 Binary files /dev/null and b/catalog-be/src/test/resources/csars/serviceWithUnknownTypes.csar differ -- cgit 1.2.3-korg