summaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
authorJvD_Ericsson <jeff.van.dam@est.tech>2023-10-19 15:48:27 +0100
committerMichael Morris <michael.morris@est.tech>2023-10-23 14:52:44 +0000
commit8d59b022d1b35a4549ff4a1f3aeea0c11214c6fb (patch)
tree2f186dab966d3ac6477f67033a1c30f1ba8ea6fd /catalog-be
parent460b149b216cd785932d7d3faf521c0882600928 (diff)
Unable to import service template with interface
Issue-ID: SDC-4661 Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech> Change-Id: Ic7146428502a3f3eb976f6d347a5611b301776ed
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java40
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java36
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java29
3 files changed, 88 insertions, 17 deletions
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<AttributeDefinition> addImplicitAttributeValues(Resource originResource, UploadComponentInstanceInfo uploadComponentInstanceInfo) {
if (uploadComponentInstanceInfo.getAttributes() == null) {
- return Collections.emptyList();
+ return Collections.emptyList();
}
List<String> origAttributes = originResource.getAttributes().stream().map(AttributeDefinition::getName).collect(toList());
Map<String, UploadAttributeInfo> uploadAttributes = uploadComponentInstanceInfo.getAttributes();
@@ -2210,7 +2210,7 @@ public class ServiceImportBusinessLogic {
}
});
List<AttributeDefinition> 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<String, UploadInterfaceInfo> instanceInterfacesMap = uploadComponentInstanceInfo.getInterfaces();
Map<String, InterfaceDefinition> currInterfacesMap = new HashMap<>();
Map<String, InterfaceDefinition> 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<String, InterfaceDefinition> 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<String, OperationDataDefinition> operationsToAdd = new HashMap<>();
Map<String, OperationDataDefinition> operations = uploadInterfaceInfo.getOperations();
@@ -2533,6 +2538,21 @@ public class ServiceImportBusinessLogic {
return componentsUtils.getResponseFormat(ActionStatus.OK);
}
+ private InterfaceDefinition getInterfaceDef(String interfaceName, String model) {
+ Either<Map<String, InterfaceDefinition>, StorageOperationStatus> interfaceLifecycleTypesEither =
+ interfaceLifecycleTypeOperation.getAllInterfaceLifecycleTypes(model);
+ if (interfaceLifecycleTypesEither.isRight()) {
+ return null;
+ }
+ Map<String, InterfaceDefinition> interfaceLifecycleTypes = interfaceLifecycleTypesEither.left().value();
+ Optional<InterfaceDefinition> interfaceType =
+ interfaceLifecycleTypes.values().stream().filter(interfaceDef -> interfaceDef.getUniqueId().contains(interfaceName)).findFirst();
+ if (interfaceType.isEmpty()) {
+ return null;
+ }
+ return interfaceType.get();
+ }
+
private void mergeOperationInputDefinitions(ListDataDefinition<OperationInputDefinition> inputsFromNodeType,
ListDataDefinition<OperationInputDefinition> 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
@@ -1547,6 +1547,37 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
}
@Test
+ void testProcessComponentInstanceInterfaces() {
+ Service service = createServiceObject(true);
+ service.setModel("testModel");
+ Map<String, Map<String, InterfaceDefinition>> 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<String, InterfaceDefinition> 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<String, Map<String, InterfaceDefinition>> 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<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = null;
Map<String, List<CapabilityDefinition>> originCapabilities = new HashMap<>();
@@ -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<String, byte[]> 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<String, UploadInterfaceInfo> 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<String, OperationDataDefinition> operations = new HashMap<>();
+ operations.put("TestInterface", operation);
+ uploadInterfaceInfo.setOperations(operations);
+ Map<String, UploadInterfaceInfo> uploadInterfaceInfoMap = new HashMap<>();
+ uploadInterfaceInfoMap.put("tosca.capabilities.Node", uploadInterfaceInfo);
+ return uploadInterfaceInfoMap;
+ }
+
protected List<ComponentInstance> creatComponentInstances() {
List<ComponentInstance> componentInstances = new ArrayList<>();
ComponentInstance componentInstance = new ComponentInstance();