aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2022-05-31 18:31:59 +0100
committerVasyl Razinkov <vasyl.razinkov@est.tech>2022-06-03 11:09:32 +0000
commitff317808f308af03321de0f0b0849cd9f6f8ccad (patch)
tree71dd9b6d55ecc7650332ebd99c9d6682e6a0c094 /catalog-be/src
parenta2313b70009cae09db66ccc7b542ec4679e6a23a (diff)
Maintain VFC UI added interface operations after an upgrade
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Change-Id: I908a4480a8929f9aeeabf4f5c14049cade6ae22b Issue-ID: SDC-4018
Diffstat (limited to 'catalog-be/src')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInterfaceOperationBusinessLogic.java1
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java24
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java80
3 files changed, 97 insertions, 8 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInterfaceOperationBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInterfaceOperationBusinessLogic.java
index 4e44967dcb..461edd11dc 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInterfaceOperationBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInterfaceOperationBusinessLogic.java
@@ -249,6 +249,7 @@ public class ComponentInterfaceOperationBusinessLogic extends BaseBusinessLogic
interfaceDefinition.setUniqueId(componentInterfaceUpdatedKey);
interfaceDefinition.setToscaResourceName(componentInterfaceUpdatedKey);
+ interfaceDefinition.setUserCreated(true);
final Optional<OperationDataDefinition> optionalOperationDataDefinition = interfaceDefinition.getOperations().values().stream().findFirst();
if (optionalOperationDataDefinition.isEmpty()) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java
index 8fe742af50..aa420673c7 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java
@@ -380,7 +380,7 @@ public class ResourceImportManager {
setProperties(toscaJson, resource, existingResource);
setAttributes(toscaJson, resource);
setRequirements(toscaJson, resource, parentResource);
- setInterfaceLifecycle(toscaJson, resource);
+ setInterfaceLifecycle(toscaJson, resource, existingResource);
} else {
throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
}
@@ -434,12 +434,13 @@ public class ResourceImportManager {
}
}
- private void setInterfaceLifecycle(Map<String, Object> toscaJson, Resource resource) {
- Either<Map<String, Object>, ResultStatusEnum> toscaInterfaces = ImportUtils
+ private void setInterfaceLifecycle(Map<String, Object> toscaJson, Resource resource, Either<Resource, StorageOperationStatus> existingResource) {
+ final Either<Map<String, Object>, ResultStatusEnum> toscaInterfaces = ImportUtils
.findFirstToscaMapElement(toscaJson, ToscaTagNamesEnum.INTERFACES);
if (toscaInterfaces.isLeft()) {
- Map<String, InterfaceDefinition> moduleInterfaces = new HashMap<>();
- for (final Entry<String, Object> interfaceNameValue : toscaInterfaces.left().value().entrySet()) {
+ final Map<String, InterfaceDefinition> moduleInterfaces = new HashMap<>();
+ final Map<String, Object> map = toscaInterfaces.left().value();
+ for (final Entry<String, Object> interfaceNameValue : map.entrySet()) {
final Either<InterfaceDefinition, ResultStatusEnum> eitherInterface = createModuleInterface(interfaceNameValue.getValue(),
resource.getModel());
if (eitherInterface.isRight()) {
@@ -449,7 +450,18 @@ public class ResourceImportManager {
moduleInterfaces.put(interfaceDefinition.getType(), interfaceDefinition);
}
}
- if (!moduleInterfaces.isEmpty()) {
+ if (existingResource.isLeft()) {
+ final Map<String, InterfaceDefinition> userCreatedInterfaceDefinitions =
+ existingResource.left().value().getInterfaces().entrySet().stream()
+ .filter(i -> i.getValue().isUserCreated())
+ .filter(i -> !map.containsKey(i.getValue().getType()))
+ .collect(Collectors.toMap(Entry::getKey, Entry::getValue));
+ if (MapUtils.isNotEmpty(userCreatedInterfaceDefinitions)) {
+ moduleInterfaces.putAll(userCreatedInterfaceDefinitions);
+ }
+ }
+
+ if (MapUtils.isNotEmpty(moduleInterfaces)) {
resource.setInterfaces(moduleInterfaces);
}
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java
index df679f1402..32d174f194 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java
@@ -47,6 +47,8 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
@@ -358,6 +360,43 @@ class ResourceImportManagerTest {
}
@Test
+ void testReimportVfcWithInterfaceImplementation() throws IOException {
+ user.setUserId(resourceMD.getContactId());
+ when(userAdmin.getUser(anyString(), anyBoolean())).thenReturn(user);
+
+ setResourceBusinessLogicMock();
+
+ String jsonContent = ImportUtilsTest.loadCustomTypeFileNameToJsonString("custom-types-node-type-with-interface-impl.yml");
+
+ Map<String, InterfaceDefinition> interfaceTypes = new HashMap<>();
+ final InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
+ interfaceDefinition.setType("tosca.interfaces.node.lifecycle.Standard");
+ Map<String, OperationDataDefinition> operations = new HashMap<>();
+ operations.put("configure", new OperationDataDefinition());
+ interfaceDefinition.setOperations(operations);
+ interfaceTypes.put("tosca.interfaces.node.lifecycle.standard", interfaceDefinition);
+ when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(interfaceTypes));
+
+ ImmutablePair<Resource, ActionStatus> createResource =
+ importManager.importNormativeResource(jsonContent, resourceMD, user, true, true, false);
+ assertNotNull(createResource);
+ Resource resource = createResource.getLeft();
+ assertNotNull(resource);
+ assertSetInterfaceImplementation(resource);
+
+ final GraphVertex graphVertex = new GraphVertex();
+ graphVertex.setUniqueId("1-2-3-4-5-6-7");
+ when(janusGraphDao.getByCriteria(eq(VertexTypeEnum.NODE_TYPE), anyMap(), anyMap(), eq(JsonParseFlagEnum.ParseAll), any(), anyBoolean()))
+ .thenReturn(Either.left(Arrays.asList(graphVertex)));
+ when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(Either.left(resource));
+ createResource = reimportVfc(resource, jsonContent);
+ assertNotNull(createResource);
+ resource = createResource.getLeft();
+ assertNotNull(resource);
+ assertSetInterfaceImplementationAfterReimport(resource);
+ }
+
+ @Test
void testResourceCreationWithInterfaceImplementation_UnknownInterface() throws IOException {
user.setUserId(resourceMD.getContactId());
when(userAdmin.getUser(anyString(), anyBoolean())).thenReturn(user);
@@ -508,14 +547,33 @@ class ResourceImportManagerTest {
}
- private ImmutablePair<Resource, ActionStatus> reimportVfc(Resource resource, String jsonContent) {
+ private ImmutablePair<Resource, ActionStatus> reimportVfc(final Resource resource, final String jsonContent) {
List<PropertyDefinition> propertiesList = resource.getProperties();
- PropertyDefinition propertyDefinition = new PropertyDefinition();
+ if (CollectionUtils.isEmpty(propertiesList)) {
+ propertiesList = new ArrayList<>();
+ }
+ final PropertyDefinition propertyDefinition = new PropertyDefinition();
propertyDefinition.setName("oneMore");
propertyDefinition.setUserCreated(true);
propertyDefinition.setType("boolean");
propertiesList.add(propertyDefinition);
resource.setProperties(propertiesList);
+
+ Map<String, InterfaceDefinition> interfaces = resource.getInterfaces();
+ if (MapUtils.isEmpty(interfaces)) {
+ interfaces = new HashMap<>();
+ }
+ final InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
+ interfaceDefinition.setType("tosca.interfaces.relationship.Configure");
+ interfaceDefinition.setUserCreated(true);
+ final OperationDataDefinition operationDataDefinition = new OperationDataDefinition();
+ operationDataDefinition.setName("add_source");
+ final Map<String, OperationDataDefinition> operationDataDefinitionMap = new HashMap<>();
+ operationDataDefinitionMap.put(operationDataDefinition.getName(), operationDataDefinition);
+ interfaceDefinition.setOperations(operationDataDefinitionMap);
+ interfaces.put(interfaceDefinition.getType(), interfaceDefinition);
+ resource.setInterfaces(interfaces);
+
return importManager.importNormativeResource(jsonContent, resourceMD, user, true, true, false);
}
@@ -614,6 +672,24 @@ class ResourceImportManagerTest {
assertTrue(operations.containsKey(operationDataDefinition.getName())));
}
+ private void assertSetInterfaceImplementationAfterReimport(final Resource resource) {
+ final Map<String, InterfaceDefinition> interfaces = resource.getInterfaces();
+ assertNotNull(interfaces);
+ assertEquals(2, interfaces.size());
+
+ InterfaceDefinition interfaceDefinition = interfaces.get("tosca.interfaces.node.lifecycle.Standard");
+ assertTrue(interfaces.containsKey(interfaceDefinition.getType()));
+ assertFalse(interfaceDefinition.isUserCreated());
+ final Map<String, OperationDataDefinition> operations_1 = interfaceDefinition.getOperations();
+ operations_1.values().forEach(operationDataDefinition -> assertTrue(operations_1.containsKey(operationDataDefinition.getName())));
+
+ interfaceDefinition = interfaces.get("tosca.interfaces.relationship.Configure");
+ assertTrue(interfaces.containsKey(interfaceDefinition.getType()));
+ assertTrue(interfaceDefinition.isUserCreated());
+ final Map<String, OperationDataDefinition> operations_2 = interfaceDefinition.getOperations();
+ operations_2.values().forEach(operationDataDefinition -> assertTrue(operations_2.containsKey(operationDataDefinition.getName())));
+ }
+
private void testSetDerivedFrom(Resource resource) {
assertEquals(1, resource.getDerivedFrom().size());
assertEquals("tosca.nodes.Root", resource.getDerivedFrom().get(0));