summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java17
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java7
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperationTest.java102
3 files changed, 126 insertions, 0 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
index dcccfd961d..76db103525 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
@@ -2990,6 +2990,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
newComponentInstance.setInstanceCount(resResourceInfo.getInstanceCount());
newComponentInstance.setMaxOccurrences(resResourceInfo.getMaxOccurrences());
newComponentInstance.setMinOccurrences(resResourceInfo.getMinOccurrences());
+ newComponentInstance.setDirectives(resResourceInfo.getDirectives());
checkForExternalReqAndCapabilities(origComponent, resResourceInfo);
ComponentInstance updatedComponentInstance =
@@ -3014,6 +3015,9 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
log.debug("Component with id {} was not found", containerComponentId);
throw new ByActionStatusComponentException(actionStatus, Constants.EMPTY_STRING);
}
+
+ maintainNodeFilters(currentResourceInstance, newComponentInstance, containerComponentId);
+
resourceInstanceStatus = getResourceInstanceById(updatedComponentRes.left().value(),
updatedComponentInstance.getUniqueId());
if (resourceInstanceStatus.isRight()) {
@@ -3030,6 +3034,19 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
}
+ private void maintainNodeFilters(
+ ComponentInstance currentResourceInstance,
+ ComponentInstance newComponentInstance,
+ String containerComponentId) {
+ CINodeFilterDataDefinition filterToMaintain = currentResourceInstance.getNodeFilter();
+ if (null != filterToMaintain) {
+ nodeFilterOperation.addNodeFilterData(
+ containerComponentId.toLowerCase(),
+ newComponentInstance.getUniqueId(),
+ filterToMaintain);
+ }
+ }
+
private void checkForExternalReqAndCapabilities(Component component, ComponentInstance resResourceInfo) {
Map<String, List<RequirementDefinition>> requirementsMap = resResourceInfo.getRequirements();
Map<String, List<RequirementDefinition>> externalRequirementsMap = new HashMap<>();
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java
index c99ff9cd43..bcc005e6e3 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java
@@ -147,6 +147,13 @@ public class NodeFilterOperation extends BaseOperation {
return addOrUpdateNodeFilter(true, serviceId, componentInstanceId, ciNodeFilterDataDefinition);
}
+ public Either<CINodeFilterDataDefinition, StorageOperationStatus> addNodeFilterData(
+ final String componentId,
+ final String componentInstanceId,
+ final CINodeFilterDataDefinition nodeFilterDataDefinition) {
+ return addOrUpdateNodeFilter(false, componentId, componentInstanceId, nodeFilterDataDefinition);
+ }
+
private Either<CINodeFilterDataDefinition, StorageOperationStatus> addOrUpdateNodeFilter(final boolean isUpdateAction, final String componentId,
final String componentInstanceId,
final CINodeFilterDataDefinition ciNodeFilterDataDefinition) {
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperationTest.java
new file mode 100644
index 0000000000..0cbba25e04
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperationTest.java
@@ -0,0 +1,102 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdc.be.model.jsonjanusgraph.operations;
+
+import fj.data.Either;
+import org.janusgraph.core.JanusGraphVertex;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
+import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
+import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
+import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
+import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterPropertyDataDefinition;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+
+import java.util.Arrays;
+import java.util.HashMap;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class NodeFilterOperationTest {
+
+ private final NodeFilterOperation nodeFilterOperation = new NodeFilterOperation();
+
+ @Mock
+ private JanusGraphDao janusGraphDao;
+
+ @BeforeEach
+ void setUp() {
+ MockitoAnnotations.openMocks(this);
+ nodeFilterOperation.setJanusGraphDao(janusGraphDao);
+ }
+
+ @Test
+ void addOrUpdateNodeFilterData() {
+ CINodeFilterDataDefinition nodeFilterDataDefinition = new CINodeFilterDataDefinition();
+ nodeFilterDataDefinition.setName("new node filter name");
+ String prop1 = "property1";
+ String prop2 = "property2";
+ RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition = new RequirementNodeFilterPropertyDataDefinition();
+ requirementNodeFilterPropertyDataDefinition.setName("Name1");
+ requirementNodeFilterPropertyDataDefinition
+ .setConstraints(Arrays.asList("mem_size:\n" + " equal: { get_property : [" + prop1 + ", size]}\n"));
+ RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition2 = new RequirementNodeFilterPropertyDataDefinition();
+ requirementNodeFilterPropertyDataDefinition2.setName("Name2");
+ requirementNodeFilterPropertyDataDefinition2
+ .setConstraints(Arrays.asList("mem_size:\n {equal: { get_property : [SELF, " + prop2 + "]}}\n"));
+
+ ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> listDataDefinition =
+ new ListDataDefinition<>(Arrays.asList(
+ requirementNodeFilterPropertyDataDefinition,
+ requirementNodeFilterPropertyDataDefinition2));
+ nodeFilterDataDefinition.setProperties(listDataDefinition);
+
+ String componentId = "componentId";
+ final GraphVertex serviceVertexMock = mock(GraphVertex.class);
+ final JanusGraphVertex serviceJanusVertex = mock(JanusGraphVertex.class);
+ when(serviceVertexMock.getVertex()).thenReturn(serviceJanusVertex);
+ when(serviceVertexMock.getUniqueId()).thenReturn("componentId");
+ when(janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)).thenReturn(Either.left(serviceVertexMock));
+ when(janusGraphDao.getChildVertex(serviceVertexMock, EdgeLabelEnum.NODE_FILTER_TEMPLATE, JsonParseFlagEnum.ParseJson))
+ .thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
+ when(janusGraphDao.createVertex(any())).thenReturn(Either.left(new GraphVertex()));
+ when(janusGraphDao.createEdge(eq(serviceJanusVertex), nullable(JanusGraphVertex.class), eq(EdgeLabelEnum.NODE_FILTER_TEMPLATE), eq(new HashMap<>())))
+ .thenReturn(JanusGraphOperationStatus.OK);
+ final Either<CINodeFilterDataDefinition, StorageOperationStatus> expectedNodeFilterEither = nodeFilterOperation.updateNodeFilter(
+ componentId, "componentInstanceId", nodeFilterDataDefinition);
+ assertTrue(expectedNodeFilterEither.isLeft());
+ final CINodeFilterDataDefinition expectedNodeFilter = expectedNodeFilterEither.left().value();
+ assertEquals("new node filter name", expectedNodeFilter.getName());
+ assertEquals(listDataDefinition, expectedNodeFilter.getProperties());
+ }
+} \ No newline at end of file