summaryrefslogtreecommitdiffstats
path: root/catalog-dao
diff options
context:
space:
mode:
authortalio <talio@amdocs.com>2020-06-17 15:57:06 +0300
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-06-21 07:13:29 +0000
commita098edad859459ab116d4587af8262877f2b522a (patch)
treed5ac83bf0ef79e0d0b7de4c28ba2953acf238b9d /catalog-dao
parentb0140364e491df1009cf00e50c0207d2e9ca3453 (diff)
Toggle
Add toggling mechanism to catalog side. The first toggleable feature is healing - this was added to healing flow, in healJanusGraphDao Issue-ID: SDC-2874 Signed-off-by: talio <talio@amdocs.com> Change-Id: If386651cab8304ebaf13497ded3a7a50bd60e477 Signed-off-by: talio <talio@amdocs.com>
Diffstat (limited to 'catalog-dao')
-rw-r--r--catalog-dao/pom.xml6
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/heal/HealJanusGraphDao.java20
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/togglz/FeatureToggleEvent.java1
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/togglz/ToggleableFeature.java43
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/HealingPipelineDaoTest.java12
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/resources/data/togglz/FeatureToggleEventTest.java7
6 files changed, 36 insertions, 53 deletions
diff --git a/catalog-dao/pom.xml b/catalog-dao/pom.xml
index 06cb1e81a0..d1d9b349ae 100644
--- a/catalog-dao/pom.xml
+++ b/catalog-dao/pom.xml
@@ -356,6 +356,12 @@ Modifications copyright (c) 2018 Nokia
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.togglz</groupId>
+ <artifactId>togglz-testing</artifactId>
+ <version>${togglz.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/heal/HealJanusGraphDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/heal/HealJanusGraphDao.java
index e74556ab14..c0a066346d 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/heal/HealJanusGraphDao.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/heal/HealJanusGraphDao.java
@@ -28,6 +28,7 @@ import org.openecomp.sdc.be.dao.jsongraph.heal.HealVersion;
import org.openecomp.sdc.be.dao.jsongraph.heal.HealVersionBuilder;
import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
+import org.openecomp.sdc.be.togglz.ToggleableFeature;
public class HealJanusGraphDao implements HealGraphDao<JanusGraphVertex, GraphEdgeLabels> {
@@ -41,18 +42,23 @@ public class HealJanusGraphDao implements HealGraphDao<JanusGraphVertex, GraphEd
public JanusGraphVertex performGraphReadHealing(JanusGraphVertex childVertex, GraphEdgeLabels graphEdgeLabels) {
final Integer healingVersionInt = (Integer) childVertex.property(GraphPropertyEnum.HEALING_VERSION.getProperty()).orElse(HealConstants.DEFAULT_HEAL_VERSION);
HealVersion<Integer> healingVersion = HealVersionBuilder.build(healingVersionInt);
- healingPipelineDao.getHealersForVertex(graphEdgeLabels.name(), healingVersion).forEach(heal -> healGraphVertex(childVertex, heal));
- childVertex.property(GraphPropertyEnum.HEALING_VERSION.getProperty(), healingPipelineDao.getCurrentHealVersion().getVersion());
+ healingPipelineDao.getHealersForVertex(graphEdgeLabels.name(), healingVersion)
+ .forEach(heal -> healGraphVertex(childVertex, heal));
+ childVertex.property(GraphPropertyEnum.HEALING_VERSION.getProperty(),
+ healingPipelineDao.getCurrentHealVersion().getVersion());
+
return childVertex;
}
private JanusGraphVertex healGraphVertex(JanusGraphVertex childVertex, Heal<JanusGraphVertex> heal) {
- heal.healData(childVertex);
- final HealVersion<Integer> healVersion = heal.fromVersion();
- HealVersion newerVersion = HealVersionBuilder.build(healVersion.getVersion() + 1);
- childVertex.property(GraphPropertyEnum.HEALING_VERSION.getProperty(), newerVersion);
- heal.healData(childVertex);
+ if(ToggleableFeature.HEALING.isActive()) {
+ heal.healData(childVertex);
+ final HealVersion<Integer> healVersion = heal.fromVersion();
+ HealVersion<Integer> newerVersion = HealVersionBuilder.build(healVersion.getVersion() + 1);
+ childVertex.property(GraphPropertyEnum.HEALING_VERSION.getProperty(), newerVersion);
+ heal.healData(childVertex);
+ }
return childVertex;
}
}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/togglz/FeatureToggleEvent.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/togglz/FeatureToggleEvent.java
index 501b421bd5..ed5a5a0b37 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/togglz/FeatureToggleEvent.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/togglz/FeatureToggleEvent.java
@@ -26,6 +26,7 @@ import com.datastax.driver.mapping.annotations.Table;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
+import org.openecomp.sdc.be.togglz.ToggleableFeature;
import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.togglz.core.Feature;
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/togglz/ToggleableFeature.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/togglz/ToggleableFeature.java
deleted file mode 100644
index 2fd2c80b02..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/togglz/ToggleableFeature.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.resources.data.togglz;
-
-import org.togglz.core.Feature;
-import org.togglz.core.annotation.Label;
-import org.togglz.core.context.FeatureContext;
-
-import java.util.Arrays;
-
-public enum ToggleableFeature implements Feature{
- @Label("Default feature")
- DEFAULT_FEATURE;
-
- public static Feature getFeatureByName(String featureName) {
- return Arrays.stream(values()).
- filter(e -> e.name().equals(featureName))
- .findFirst()
- .orElse(null);
- }
-
- public boolean isActive() {
- return FeatureContext.getFeatureManager().isActive(this);
- }
-}
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/HealingPipelineDaoTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/HealingPipelineDaoTest.java
index c0d9e4644c..f079ddd186 100644
--- a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/HealingPipelineDaoTest.java
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/HealingPipelineDaoTest.java
@@ -22,6 +22,8 @@ import org.janusgraph.graphdb.relations.StandardVertexProperty;
import org.janusgraph.graphdb.types.system.EmptyVertex;
import org.janusgraph.graphdb.types.system.ImplicitKey;
import java.util.HashMap;
+import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
@@ -36,11 +38,21 @@ import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import java.util.Map;
import java.util.Optional;
+import org.openecomp.sdc.be.togglz.ToggleableFeature;
+import org.togglz.testing.TestFeatureManager;
+import org.togglz.testing.TestFeatureManagerProvider;
import static org.junit.Assert.*;
public class HealingPipelineDaoTest {
+ @Before
+ public void enableToggleableFeatures(){
+ TestFeatureManager manager = new TestFeatureManager(ToggleableFeature.class);
+ manager.enableAll();
+ TestFeatureManagerProvider.setFeatureManager(manager);
+ }
+
@Test
public void shouldUpgrade() {
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/data/togglz/FeatureToggleEventTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/data/togglz/FeatureToggleEventTest.java
index 53bf27d9f9..9675e3a734 100644
--- a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/data/togglz/FeatureToggleEventTest.java
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/data/togglz/FeatureToggleEventTest.java
@@ -20,15 +20,16 @@
package org.openecomp.sdc.be.resources.data.togglz;
-import org.junit.Test;
-import org.togglz.core.repository.FeatureState;
-
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.isEmptyOrNullString;
import static org.hamcrest.Matchers.isEmptyString;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
+import org.junit.Test;
+import org.openecomp.sdc.be.togglz.ToggleableFeature;
+import org.togglz.core.repository.FeatureState;
+
public class FeatureToggleEventTest {
private final String strategyId = "123456";
private final String param1 = "param1";