diff options
Diffstat (limited to 'catalog-be')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java | 7 | ||||
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/OnboardedCsarInfo.java | 7 | ||||
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfo.java | 6 | ||||
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java | 30 | ||||
-rw-r--r-- | catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfoTest.java | 14 | ||||
-rw-r--r-- | catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java | 14 | ||||
-rw-r--r-- | catalog-be/src/test/resources/csars/service-Ser09080002-csar.csar | bin | 63922 -> 63966 bytes | |||
-rw-r--r-- | catalog-be/src/test/resources/csars/serviceWithUnknownTypes.csar (renamed from catalog-be/src/test/resources/csars/serviceWithUnknownDataTypes.csar) | bin | 56980 -> 57080 bytes |
8 files changed, 74 insertions, 4 deletions
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<String, Object> 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<String, Object> getInterfaceTypes(); + public Map<String, Object> 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; @@ -217,6 +218,11 @@ public class OnboardedCsarInfo extends CsarInfo { } @Override + public Map<String, Object> getInterfaceTypes() { + return getTypes(INTERFACE_TYPES); + } + + @Override public Map<String, Object> 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<String, Object> getInterfaceTypes() { + return getTypes(ToscaTagNamesEnum.INTERFACE_TYPES); + } + public List<NodeTypeDefinition> 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<String, Object> interfaceTypesToCreate = getInterfaceTypesToCreate(service.getModel(), csarInfo); + if (MapUtils.isNotEmpty(interfaceTypesToCreate)) { + interfaceLifecycleTypeImportManager + .createLifecycleTypes(new Yaml().dump(interfaceTypesToCreate), service.getModel(), true); + } + final Map<String, Object> capabilityTypesToCreate = getCapabilityTypesToCreate(service.getModel(), csarInfo); if (MapUtils.isNotEmpty(capabilityTypesToCreate)) { @@ -426,8 +439,21 @@ public class ServiceImportBusinessLogic { return artifactTypesToCreate; } - private boolean hasNewProperties(final Either<DataTypeDefinition, JanusGraphOperationStatus> result, - final Map<String, Map<String, Object>> dataType) { + private Map<String, Object> getInterfaceTypesToCreate(final String model, final CsarInfo csarInfo) { + final Map<String, Object> interfaceTypesToCreate = new HashMap<>(); + Map<String, Object> interfacetypeMap = csarInfo.getInterfaceTypes(); + + interfacetypeMap.entrySet().forEach(interfacetypeDef -> { + Either<InterfaceDefinition, StorageOperationStatus> 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<DataTypeDefinition, JanusGraphOperationStatus> result, final Map<String, Map<String, Object>> 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<String, Object>) ((Map<String, Object>) dataTypeDefinition.get("properties")).get("prop2")).get("type")); } + @SuppressWarnings("unchecked") + @Test + void testGetInterfaceTypes() { + final Map<String, Object> interfaceTypes = csarInfo.getInterfaceTypes(); + assertEquals(9, interfaceTypes.size()); + final Map<String, Object> interfaceTypeDefinition = (Map<String, Object>) interfaceTypes.get( + "tosca.interfaces.test.node.lifecycle.Reconfigure"); + assertNotNull(interfaceTypeDefinition); + assertEquals("tosca.interfaces.Root", interfaceTypeDefinition.get("derived_from")); + assertEquals("reconfigure", ((Map<String, Object>) 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<String, Object> nodeTypesMap = nodeTypes.getValue(); Map<String, Object> newUpdatedNodeType = (Map<String, Object>) nodeTypesMap.get(updatedNodeType); assertEquals(8, ((Map<String, Object>) newUpdatedNodeType.get("properties")).size()); + + ArgumentCaptor<String> interfaceTypes = ArgumentCaptor.forClass(String.class); + verify(interfaceLifecycleTypeImportManager).createLifecycleTypes(interfaceTypes.capture(), any(), anyBoolean()); + Map<String, Object> 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 Binary files differindex c780e3484c..de7d71fc37 100644 --- a/catalog-be/src/test/resources/csars/service-Ser09080002-csar.csar +++ b/catalog-be/src/test/resources/csars/service-Ser09080002-csar.csar diff --git a/catalog-be/src/test/resources/csars/serviceWithUnknownDataTypes.csar b/catalog-be/src/test/resources/csars/serviceWithUnknownTypes.csar Binary files differindex ffd209978f..b50113c2d2 100644 --- a/catalog-be/src/test/resources/csars/serviceWithUnknownDataTypes.csar +++ b/catalog-be/src/test/resources/csars/serviceWithUnknownTypes.csar |