From fc5c07705edc4dcb7083b39116a43844bb6a1490 Mon Sep 17 00:00:00 2001 From: Ravindra Bakkamanthala Date: Mon, 5 Jun 2017 22:42:02 -0400 Subject: Fixed the Policy API issues and Bugfixes Change-Id: I6e8b54442421b6ebd0ff88426fc6e5f3a36b0690 Signed-off-by: Ravindra Bakkamanthala --- .../controlloop/policy/guard/Constraint.java | 22 +++++++++++++++------- .../controlloop/policy/guard/ControlLoopGuard.java | 7 +++---- .../controlloop/policy/guard/GuardPolicy.java | 8 ++++---- .../compiler/ControlLoopGuardCompilerTest.java | 2 +- .../policy/guard/ControlLoopGuardBuilderTest.java | 4 ++-- .../policy/guard/ControlLoopGuardTest.java | 6 ++++-- 6 files changed, 29 insertions(+), 20 deletions(-) (limited to 'ECOMP-ControlloopPolicy') diff --git a/ECOMP-ControlloopPolicy/src/main/java/org/openecomp/policy/controlloop/policy/guard/Constraint.java b/ECOMP-ControlloopPolicy/src/main/java/org/openecomp/policy/controlloop/policy/guard/Constraint.java index 85ddf066d..42a04e7b7 100644 --- a/ECOMP-ControlloopPolicy/src/main/java/org/openecomp/policy/controlloop/policy/guard/Constraint.java +++ b/ECOMP-ControlloopPolicy/src/main/java/org/openecomp/policy/controlloop/policy/guard/Constraint.java @@ -77,6 +77,13 @@ public class Constraint { this.blacklist = new LinkedList<>(blacklist); } + + public Constraint(Map time_in_range, List blacklist) { + if (time_in_range != null) { + this.time_in_range = Collections.unmodifiableMap(time_in_range); + } + this.blacklist = new LinkedList<>(blacklist); + } public Constraint(Integer num, String duration, List blacklist) { this.num = num; @@ -84,6 +91,13 @@ public class Constraint { this.blacklist = new LinkedList<>(blacklist); } + public Constraint(Integer num, String duration, Map time_in_range) { + this(num, duration); + if (time_in_range != null) { + this.time_in_range = Collections.unmodifiableMap(time_in_range); + } + } + public Constraint(Integer num, String duration, Map time_in_range, List blacklist) { this(num, duration); if (time_in_range != null) { @@ -102,13 +116,7 @@ public class Constraint { } public boolean isValid() { - if (num == null && duration != null) { - return false; - } - if (duration == null && num != null) { - return false; - } - return true; + return ((num == null && duration != null)|| (duration == null && num != null))? false : true; } @Override diff --git a/ECOMP-ControlloopPolicy/src/main/java/org/openecomp/policy/controlloop/policy/guard/ControlLoopGuard.java b/ECOMP-ControlloopPolicy/src/main/java/org/openecomp/policy/controlloop/policy/guard/ControlLoopGuard.java index cfc904823..3df2a0885 100644 --- a/ECOMP-ControlloopPolicy/src/main/java/org/openecomp/policy/controlloop/policy/guard/ControlLoopGuard.java +++ b/ECOMP-ControlloopPolicy/src/main/java/org/openecomp/policy/controlloop/policy/guard/ControlLoopGuard.java @@ -20,13 +20,12 @@ package org.openecomp.policy.controlloop.policy.guard; import java.util.LinkedList; -import java.util.List; public class ControlLoopGuard { private Guard guard; - private List guards; + private LinkedList guards; public ControlLoopGuard() { //DO Nothing Empty Constructor @@ -40,11 +39,11 @@ public class ControlLoopGuard { this.guard = guard; } - public List getGuards() { + public LinkedList getGuards() { return guards; } - public void setGuards(List guards) { + public void setGuards(LinkedList guards) { this.guards = guards; } diff --git a/ECOMP-ControlloopPolicy/src/main/java/org/openecomp/policy/controlloop/policy/guard/GuardPolicy.java b/ECOMP-ControlloopPolicy/src/main/java/org/openecomp/policy/controlloop/policy/guard/GuardPolicy.java index 7eb8af6d1..a4d56ff07 100644 --- a/ECOMP-ControlloopPolicy/src/main/java/org/openecomp/policy/controlloop/policy/guard/GuardPolicy.java +++ b/ECOMP-ControlloopPolicy/src/main/java/org/openecomp/policy/controlloop/policy/guard/GuardPolicy.java @@ -31,7 +31,7 @@ public class GuardPolicy { private String description; private String actor; private String recipe; - private List limit_constraints; + private LinkedList limit_constraints; public GuardPolicy() { //Do Nothing Empty Constructor. @@ -77,11 +77,11 @@ public class GuardPolicy { this.recipe = recipe; } - public List getLimit_constraints() { - return limit_constraints; + public LinkedList getLimit_constraints() { + return limit_constraints; } - public void setLimit_constraints(List limit_constraints) { + public void setLimit_constraints(LinkedList limit_constraints) { this.limit_constraints = limit_constraints; } diff --git a/ECOMP-ControlloopPolicy/src/test/java/org/openecomp/policy/controlloop/compiler/ControlLoopGuardCompilerTest.java b/ECOMP-ControlloopPolicy/src/test/java/org/openecomp/policy/controlloop/compiler/ControlLoopGuardCompilerTest.java index 1e035edf4..e2701eefb 100644 --- a/ECOMP-ControlloopPolicy/src/test/java/org/openecomp/policy/controlloop/compiler/ControlLoopGuardCompilerTest.java +++ b/ECOMP-ControlloopPolicy/src/test/java/org/openecomp/policy/controlloop/compiler/ControlLoopGuardCompilerTest.java @@ -31,7 +31,7 @@ import org.junit.Test; import org.openecomp.policy.controlloop.guard.compiler.ControlLoopGuardCompiler; public class ControlLoopGuardCompilerTest { - + @Test public void testTest1() { try { diff --git a/ECOMP-ControlloopPolicy/src/test/java/org/openecomp/policy/controlloop/policy/guard/ControlLoopGuardBuilderTest.java b/ECOMP-ControlloopPolicy/src/test/java/org/openecomp/policy/controlloop/policy/guard/ControlLoopGuardBuilderTest.java index 5df0266ec..3137a1232 100644 --- a/ECOMP-ControlloopPolicy/src/test/java/org/openecomp/policy/controlloop/policy/guard/ControlLoopGuardBuilderTest.java +++ b/ECOMP-ControlloopPolicy/src/test/java/org/openecomp/policy/controlloop/policy/guard/ControlLoopGuardBuilderTest.java @@ -142,12 +142,12 @@ public class ControlLoopGuardBuilderTest { fail(e.getMessage()); } } - + @Test public void test1() { this.test("src/test/resources/v2.0.0-guard/policy_guard_OpenECOMP_demo_vDNS.yaml"); } - + @Test public void test2() { this.test("src/test/resources/v2.0.0-guard/policy_guard_1707_appc.yaml"); diff --git a/ECOMP-ControlloopPolicy/src/test/java/org/openecomp/policy/controlloop/policy/guard/ControlLoopGuardTest.java b/ECOMP-ControlloopPolicy/src/test/java/org/openecomp/policy/controlloop/policy/guard/ControlLoopGuardTest.java index a09fd2112..4575e594f 100644 --- a/ECOMP-ControlloopPolicy/src/test/java/org/openecomp/policy/controlloop/policy/guard/ControlLoopGuardTest.java +++ b/ECOMP-ControlloopPolicy/src/test/java/org/openecomp/policy/controlloop/policy/guard/ControlLoopGuardTest.java @@ -19,7 +19,9 @@ */ package org.openecomp.policy.controlloop.policy.guard; -import static org.junit.Assert.*; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.io.File; import java.io.FileInputStream; @@ -35,7 +37,7 @@ import org.yaml.snakeyaml.constructor.Constructor; public class ControlLoopGuardTest { - + @Test public void testGuardvDNS() { this.test("src/test/resources/v2.0.0-guard/policy_guard_OpenECOMP_demo_vDNS.yaml"); -- cgit 1.2.3-korg