From: JvD_Ericsson Date: Thu, 19 Oct 2023 14:48:27 +0000 (+0100) Subject: Unable to import service template with interface X-Git-Tag: 1.13.6~14 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=sdc.git;a=commitdiff_plain;h=8d59b022d1b35a4549ff4a1f3aeea0c11214c6fb Unable to import service template with interface Issue-ID: SDC-4661 Signed-off-by: JvD_Ericsson Change-Id: Ic7146428502a3f3eb976f6d347a5611b301776ed --- 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 d4f67ec13d..8671d9e27a 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 @@ -221,10 +221,10 @@ public class ServiceImportBusinessLogic { private final GroupTypeOperation groupTypeOperation; private final CapabilityTypeImportManager capabilityTypeImportManager; private final CapabilityTypeOperation capabilityTypeOperation; - private ApplicationDataTypeCache applicationDataTypeCache; private final InterfaceLifecycleOperation interfaceLifecycleTypeOperation; private final InterfaceLifecycleTypeImportManager interfaceLifecycleTypeImportManager; private final ModelOperation modelOperation; + private ApplicationDataTypeCache applicationDataTypeCache; public ServiceImportBusinessLogic(final GroupBusinessLogic groupBusinessLogic, final ArtifactsBusinessLogic artifactsBusinessLogic, final ComponentsUtils componentsUtils, final ToscaOperationFacade toscaOperationFacade, @@ -2190,7 +2190,7 @@ public class ServiceImportBusinessLogic { private List addImplicitAttributeValues(Resource originResource, UploadComponentInstanceInfo uploadComponentInstanceInfo) { if (uploadComponentInstanceInfo.getAttributes() == null) { - return Collections.emptyList(); + return Collections.emptyList(); } List origAttributes = originResource.getAttributes().stream().map(AttributeDefinition::getName).collect(toList()); Map uploadAttributes = uploadComponentInstanceInfo.getAttributes(); @@ -2210,7 +2210,7 @@ public class ServiceImportBusinessLogic { } }); List attributesToAdd = new ArrayList<>(); - for (PropertyDefinition prop: propsToAddAsAttributes) { + for (PropertyDefinition prop : propsToAddAsAttributes) { attributesToAdd.add(getPropertyAsAttribute(prop)); } return attributesToAdd; @@ -2463,13 +2463,13 @@ public class ServiceImportBusinessLogic { Map instanceInterfacesMap = uploadComponentInstanceInfo.getInterfaces(); Map currInterfacesMap = new HashMap<>(); Map interfacesFromNodeType = originResource.getInterfaces(); - if ((MapUtils.isNotEmpty(instanceInterfacesMap)) && (MapUtils.isEmpty(interfacesFromNodeType))) { + if (interfacesFromNodeType == null) { + interfacesFromNodeType = new HashMap<>(); + } + if (MapUtils.isEmpty(instanceInterfacesMap) && MapUtils.isEmpty(instanceInterfacesMap)) { log.debug("failed to find interfaces "); return componentsUtils.getResponseFormat(ActionStatus.INTERFACE_NOT_FOUND_IN_COMPONENT); } - if (interfacesFromNodeType == null || interfacesFromNodeType.isEmpty()) { - return componentsUtils.getResponseFormat(ActionStatus.OK); - } for (Map.Entry entryInstances : interfacesFromNodeType.entrySet()) { String interfaceName = entryInstances.getKey().substring(entryInstances.getKey().lastIndexOf(".") + 1); if (!currInterfacesMap.containsKey(interfaceName)) { @@ -2481,11 +2481,16 @@ public class ServiceImportBusinessLogic { if (MapUtils.isNotEmpty(instanceInterfacesMap)) { for (UploadInterfaceInfo uploadInterfaceInfo : instanceInterfacesMap.values()) { String interfaceName = uploadInterfaceInfo.getName(); + InterfaceDefinition currentInterfaceDef; if (!currInterfacesMap.containsKey(interfaceName)) { - log.debug("failed to find interface {} ", interfaceName); - return componentsUtils.getResponseFormat(ActionStatus.INTERFACE_NOT_FOUND_IN_COMPONENT, interfaceName); + currentInterfaceDef = getInterfaceDef(interfaceName, component.getModel()); + if (currentInterfaceDef == null) { + log.debug("failed to find interface {} ", interfaceName); + return componentsUtils.getResponseFormat(ActionStatus.INTERFACE_NOT_FOUND_IN_COMPONENT, interfaceName); + } + } else { + currentInterfaceDef = currInterfacesMap.get(interfaceName); } - InterfaceDefinition currentInterfaceDef = currInterfacesMap.get(interfaceName); Map operationsToAdd = new HashMap<>(); Map operations = uploadInterfaceInfo.getOperations(); @@ -2533,6 +2538,21 @@ public class ServiceImportBusinessLogic { return componentsUtils.getResponseFormat(ActionStatus.OK); } + private InterfaceDefinition getInterfaceDef(String interfaceName, String model) { + Either, StorageOperationStatus> interfaceLifecycleTypesEither = + interfaceLifecycleTypeOperation.getAllInterfaceLifecycleTypes(model); + if (interfaceLifecycleTypesEither.isRight()) { + return null; + } + Map interfaceLifecycleTypes = interfaceLifecycleTypesEither.left().value(); + Optional interfaceType = + interfaceLifecycleTypes.values().stream().filter(interfaceDef -> interfaceDef.getUniqueId().contains(interfaceName)).findFirst(); + if (interfaceType.isEmpty()) { + return null; + } + return interfaceType.get(); + } + private void mergeOperationInputDefinitions(ListDataDefinition inputsFromNodeType, ListDataDefinition instanceInputs) { if (inputsFromNodeType == null || CollectionUtils.isEmpty(inputsFromNodeType.getListToscaDataDefinition()) || instanceInputs == null 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 c6ba0ba9ac..47be73a423 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 @@ -1546,6 +1546,37 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest originResource); } + @Test + void testProcessComponentInstanceInterfaces() { + Service service = createServiceObject(true); + service.setModel("testModel"); + Map> instInterfaces = new HashMap<>(); + UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo(); + uploadComponentInstanceInfo.setInterfaces(getInterfaces()); + ComponentInstance currentCompInstance = new ComponentInstance(); + Resource originResource = createParseResourceObject(false); + Assertions.assertNotNull(originResource); + + InterfaceDefinition interfaceDef = new InterfaceDefinition(); + interfaceDef.setUniqueId("tosca.interfaces.lifecycle.TestInterface"); + Map interfaceLifecycleTypes = new HashMap<>(); + interfaceLifecycleTypes.put("tosca.interfaces.lifecycle.TestInterface", interfaceDef); + when(interfaceLifecycleTypeOperation.getAllInterfaceLifecycleTypes("testModel")).thenReturn(Either.left(interfaceLifecycleTypes)); + + sIBL.addInterfaceValuesToRi(uploadComponentInstanceInfo, service, originResource, currentCompInstance, instInterfaces); + } + + @Test + void testProcessComponentInstanceInterfaces_null() { + Service service = createServiceObject(true); + Map> instInterfaces = new HashMap<>(); + UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo(); + ComponentInstance currentCompInstance = new ComponentInstance(); + Resource originResource = createParseResourceObject(false); + Assertions.assertNotNull(originResource); + sIBL.addInterfaceValuesToRi(uploadComponentInstanceInfo, service, originResource, currentCompInstance, instInterfaces); + } + @Test void testUpdateCapabilityPropertiesValues() { Either, JanusGraphOperationStatus> allDataTypes = null; @@ -2506,7 +2537,8 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest 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); } @@ -2516,7 +2548,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest private ImmutablePair getNodeType() { try { File resource = new File( - ServiceImportBusinessLogicTest.class.getClassLoader().getResource("node-types/resource-Extcp-template.yml").toURI()); + ServiceImportBusinessLogicTest.class.getClassLoader().getResource("node-types/resource-Extcp-template.yml").toURI()); byte[] extcpResource = Files.readAllBytes(resource.toPath()); return new ImmutablePair<>("org.openecomp.resource.cp.extCP", extcpResource); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java index df53faa3b7..14546e01d7 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.openecomp.sdc.be.components.impl; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -65,6 +66,8 @@ import org.openecomp.sdc.be.components.validation.service.ServiceTypeValidator; import org.openecomp.sdc.be.components.validation.service.ServiceValidator; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao; +import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.externalapi.servlet.representation.AbstractResourceInfo; @@ -93,6 +96,7 @@ import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.be.model.Service; import org.openecomp.sdc.be.model.UploadCapInfo; import org.openecomp.sdc.be.model.UploadComponentInstanceInfo; +import org.openecomp.sdc.be.model.UploadInterfaceInfo; import org.openecomp.sdc.be.model.UploadNodeFilterInfo; import org.openecomp.sdc.be.model.UploadReqInfo; import org.openecomp.sdc.be.model.UploadServiceInfo; @@ -117,19 +121,17 @@ public class ServiceImportBussinessLogicBaseTestSetup extends BaseBusinessLogicM protected static final String INSTANTIATION_TYPE = "A-la-carte"; protected static final String COMPONENT_ID = "myUniqueId"; protected static final String GENERIC_SERVICE_NAME = "org.openecomp.resource.abstract.nodes.service"; - private static final String RESOURCE_NAME = "My-Resource_Name with space"; protected static final String RESOURCE_TOSCA_NAME = "org.openecomp.resource.cp.extCP"; + private static final String RESOURCE_NAME = "My-Resource_Name with space"; private static final String RESOURCE_CATEGORY1 = "Network Layer 2-3"; private static final String RESOURCE_SUBCATEGORY = "Router"; - - private final ArtifactDefinition artifactDefinition = mock(ArtifactDefinition.class); - private final ServletUtils servletUtils = mock(ServletUtils.class); - protected final ServletContext servletContext = mock(ServletContext.class); protected final ComponentValidator componentValidator = mock(ComponentValidator.class); final ComponentInstanceBusinessLogic componentInstanceBusinessLogic = mock(ComponentInstanceBusinessLogic.class); final CsarBusinessLogic csarBusinessLogic = mock(CsarBusinessLogic.class); final CompositionBusinessLogic compositionBusinessLogic = mock(CompositionBusinessLogic.class); + private final ArtifactDefinition artifactDefinition = mock(ArtifactDefinition.class); + private final ServletUtils servletUtils = mock(ServletUtils.class); protected UserBusinessLogic userBusinessLogic = mock(UserBusinessLogic.class); protected WebAppContextWrapper webAppContextWrapper = mock(WebAppContextWrapper.class); protected WebApplicationContext webAppContext = mock(WebApplicationContext.class); @@ -406,6 +408,23 @@ public class ServiceImportBussinessLogicBaseTestSetup extends BaseBusinessLogicM return uploadCapInfoMap; } + protected Map getInterfaces() { + UploadInterfaceInfo uploadInterfaceInfo = new UploadInterfaceInfo(); + uploadInterfaceInfo.setName("TestInterface"); + uploadInterfaceInfo.setDescription("Description used for testing interfaces"); + OperationDataDefinition operation = new OperationDataDefinition(); + operation.setDescription("Description used for testing operations"); + ArtifactDataDefinition implementation = new ArtifactDataDefinition(); + implementation.setArtifactName("desc"); + operation.setImplementation(implementation); + Map operations = new HashMap<>(); + operations.put("TestInterface", operation); + uploadInterfaceInfo.setOperations(operations); + Map uploadInterfaceInfoMap = new HashMap<>(); + uploadInterfaceInfoMap.put("tosca.capabilities.Node", uploadInterfaceInfo); + return uploadInterfaceInfoMap; + } + protected List creatComponentInstances() { List componentInstances = new ArrayList<>(); ComponentInstance componentInstance = new ComponentInstance();