From fa09813ca39cbdb7a0ac6a38507d4ea96e28879f Mon Sep 17 00:00:00 2001 From: Michael Borokhovich Date: Thu, 20 Jul 2017 09:53:57 -0400 Subject: [POLICY-80] Adding the Policy Guard features Two Policy Guard features added: Frequency-limiter and Blacklist. Change-Id: I48184ab0ae9760c9ea7594cd7346b456aa964d48 Signed-off-by: Michael Borokhovich --- .../compiler/ControlLoopGuardCompilerTest.java | 13 +++++++-- .../policy/guard/ControlLoopGuardBuilderTest.java | 31 ++++++++++++++-------- .../policy/guard/ControlLoopGuardTest.java | 4 +-- .../v2.0.0-guard/policy_guard_ONAP_demo_vDNS.yaml | 19 +++++++++++++ .../policy_guard_OpenECOMP_demo_vDNS.yaml | 14 ---------- .../policy_guard_OpenECOMP_demo_vDNS.yaml~ | 12 --------- .../v2.0.0-guard/policy_guard_appc_restart.yaml | 24 +++++++++++++++++ .../v2.0.0-guard/policy_guard_vUSP_1707_appc.yaml | 26 ------------------ 8 files changed, 76 insertions(+), 67 deletions(-) create mode 100644 controlloop/common/policy-yaml/src/test/resources/v2.0.0-guard/policy_guard_ONAP_demo_vDNS.yaml delete mode 100644 controlloop/common/policy-yaml/src/test/resources/v2.0.0-guard/policy_guard_OpenECOMP_demo_vDNS.yaml delete mode 100644 controlloop/common/policy-yaml/src/test/resources/v2.0.0-guard/policy_guard_OpenECOMP_demo_vDNS.yaml~ create mode 100644 controlloop/common/policy-yaml/src/test/resources/v2.0.0-guard/policy_guard_appc_restart.yaml delete mode 100644 controlloop/common/policy-yaml/src/test/resources/v2.0.0-guard/policy_guard_vUSP_1707_appc.yaml (limited to 'controlloop/common/policy-yaml/src/test') diff --git a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopGuardCompilerTest.java b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopGuardCompilerTest.java index ddee23cef..f381aa207 100644 --- a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopGuardCompilerTest.java +++ b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopGuardCompilerTest.java @@ -33,11 +33,20 @@ import org.junit.Test; import org.onap.policy.controlloop.guard.compiler.ControlLoopGuardCompiler; public class ControlLoopGuardCompilerTest { - + @Test public void testTest1() { try { - this.test("src/test/resources/v2.0.0-guard/policy_guard_vUSP_1707_appc.yaml"); + this.test("src/test/resources/v2.0.0-guard/policy_guard_ONAP_demo_vDNS.yaml"); + } catch (Exception e) { + fail(e.getMessage()); + } + } + + @Test + public void testTest2() { + try { + this.test("src/test/resources/v2.0.0-guard/policy_guard_appc_restart.yaml"); } catch (Exception e) { fail(e.getMessage()); } diff --git a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuardBuilderTest.java b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuardBuilderTest.java index 28e3622f8..9cc1bbd6a 100644 --- a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuardBuilderTest.java +++ b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuardBuilderTest.java @@ -20,7 +20,6 @@ package org.onap.policy.controlloop.policy.guard; -import org.junit.Ignore; import org.junit.Test; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.Constructor; @@ -47,7 +46,6 @@ import org.onap.policy.controlloop.poligy.guard.builder.ControlLoopGuardBuilder; public class ControlLoopGuardBuilderTest { - @Ignore @Test public void testControlLoopGuard() { try { @@ -70,7 +68,13 @@ public class ControlLoopGuardBuilderTest { // // Add a guard policy without limit constraint // - GuardPolicy policy1 = new GuardPolicy("1111", "guardpolicy1", "guardpolicy1", "APPC", "restart"); + String clname = "CL_vUSP123"; + LinkedList targets = new LinkedList(); + targets.add("s1"); + targets.add("s2"); + targets.add("s3"); + MatchParameters matchParameters = new MatchParameters(clname, "APPC", "Restart", targets); + GuardPolicy policy1 = new GuardPolicy("id123", "guardpolicy1", "description aaa", matchParameters); builder = builder.addGuardPolicy(policy1); // // Assert there is no limit constraint associated with the only guard policy @@ -87,16 +91,16 @@ public class ControlLoopGuardBuilderTest { // // Add a constraint to policy1 // - Map time_in_range = new HashMap(); - time_in_range.put("arg2", "PT5H"); - time_in_range.put("arg3", "PT24H"); + Map active_time_range = new HashMap(); + active_time_range.put("start", "00:00:00-05:00"); + active_time_range.put("end", "23:59:59-05:00"); List blacklist = new LinkedList(); blacklist.add("eNodeB_common_id1"); blacklist.add("eNodeB_common_id2"); - Map duration = new HashMap(); - duration.put("value", "10"); - duration.put("units", "minute"); - Constraint cons = new Constraint(5, duration, time_in_range, blacklist); + Map time_window = new HashMap(); + time_window.put("value", "10"); + time_window.put("units", "minute"); + Constraint cons = new Constraint(5, time_window, active_time_range, blacklist); builder = builder.addLimitConstraint(policy1.id, cons); // // Add a duplicate constraint to policy1 @@ -152,7 +156,12 @@ public class ControlLoopGuardBuilderTest { @Test public void test1() { - this.test("src/test/resources/v2.0.0-guard/policy_guard_vUSP_1707_appc.yaml"); + this.test("src/test/resources/v2.0.0-guard/policy_guard_ONAP_demo_vDNS.yaml"); + } + + @Test + public void test2() { + this.test("src/test/resources/v2.0.0-guard/policy_guard_appc_restart.yaml"); } public void test(String testFile) { diff --git a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuardTest.java b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuardTest.java index 1475553d4..61ad4dfbf 100644 --- a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuardTest.java +++ b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuardTest.java @@ -39,12 +39,12 @@ public class ControlLoopGuardTest { @Test public void testGuardvDNS() { - this.test("src/test/resources/v2.0.0-guard/policy_guard_OpenECOMP_demo_vDNS.yaml"); + this.test("src/test/resources/v2.0.0-guard/policy_guard_ONAP_demo_vDNS.yaml"); } @Test public void testGuardvUSP() { - this.test("src/test/resources/v2.0.0-guard/policy_guard_vUSP_1707_appc.yaml"); + this.test("src/test/resources/v2.0.0-guard/policy_guard_appc_restart.yaml"); } diff --git a/controlloop/common/policy-yaml/src/test/resources/v2.0.0-guard/policy_guard_ONAP_demo_vDNS.yaml b/controlloop/common/policy-yaml/src/test/resources/v2.0.0-guard/policy_guard_ONAP_demo_vDNS.yaml new file mode 100644 index 000000000..f2390fae0 --- /dev/null +++ b/controlloop/common/policy-yaml/src/test/resources/v2.0.0-guard/policy_guard_ONAP_demo_vDNS.yaml @@ -0,0 +1,19 @@ +guard: + version: 2.0.0 + +guards: + - id: unique_guard_ONAP_vDNS_1 + name: MSO Spinup + description: We only spin up 1 instance over a 10 minute window + match_parameters: + actor: MSO + recipe: VF Module Create + limit_constraints: + - freq_limit_per_target: 1 + # + # https://www.w3.org/TR/xmlschema-2/#duration + # + time_window: + value: 10 + units: hour + \ No newline at end of file diff --git a/controlloop/common/policy-yaml/src/test/resources/v2.0.0-guard/policy_guard_OpenECOMP_demo_vDNS.yaml b/controlloop/common/policy-yaml/src/test/resources/v2.0.0-guard/policy_guard_OpenECOMP_demo_vDNS.yaml deleted file mode 100644 index 7b5f17c61..000000000 --- a/controlloop/common/policy-yaml/src/test/resources/v2.0.0-guard/policy_guard_OpenECOMP_demo_vDNS.yaml +++ /dev/null @@ -1,14 +0,0 @@ -guard: - version: 2.0.0 - -guards: - - id: unique_guard_ONAP_vDNS_1 - name: MSO Spinup - description: We only spin up 1 instance over a 10 minute window - actor: MSO - recipe: VF Module Create - limit_constraints: - - num: 1 - duration: - value: 15 - units: minute diff --git a/controlloop/common/policy-yaml/src/test/resources/v2.0.0-guard/policy_guard_OpenECOMP_demo_vDNS.yaml~ b/controlloop/common/policy-yaml/src/test/resources/v2.0.0-guard/policy_guard_OpenECOMP_demo_vDNS.yaml~ deleted file mode 100644 index a0d76d225..000000000 --- a/controlloop/common/policy-yaml/src/test/resources/v2.0.0-guard/policy_guard_OpenECOMP_demo_vDNS.yaml~ +++ /dev/null @@ -1,12 +0,0 @@ -guard: - version: 2.0.0 - -guards: - - id: unique_guard_ONAP_vDNS_1 - name: MSO Spinup - description: We only spin up 1 instance over a 10 minute window - actor: MSO - recipe: VF Module Create - limit_constraints: - - num: 1 - duration: PT10M diff --git a/controlloop/common/policy-yaml/src/test/resources/v2.0.0-guard/policy_guard_appc_restart.yaml b/controlloop/common/policy-yaml/src/test/resources/v2.0.0-guard/policy_guard_appc_restart.yaml new file mode 100644 index 000000000..6e47ca2b4 --- /dev/null +++ b/controlloop/common/policy-yaml/src/test/resources/v2.0.0-guard/policy_guard_appc_restart.yaml @@ -0,0 +1,24 @@ +guard: + version: 2.0.0 + +guards: + - id: unique_guard_1 + name: APPC 5 Restart + description: + We only allow 5 restarts over 15 minute window during the day time hours (i.e. avoid midnight to 5am) + match_parameters: + controlLoopName: CL_NAME_ABC_123 + actor: APPC + recipe: Restart + targets: + - s1 + s2 + s3 + limit_constraints: + - freq_limit_per_target: 5 + time_window: + value: 15 + units: minute + active_time_range: + start: 00:00:00-05:00 + end: 23:59:59-05:00 \ No newline at end of file diff --git a/controlloop/common/policy-yaml/src/test/resources/v2.0.0-guard/policy_guard_vUSP_1707_appc.yaml b/controlloop/common/policy-yaml/src/test/resources/v2.0.0-guard/policy_guard_vUSP_1707_appc.yaml deleted file mode 100644 index a487210cd..000000000 --- a/controlloop/common/policy-yaml/src/test/resources/v2.0.0-guard/policy_guard_vUSP_1707_appc.yaml +++ /dev/null @@ -1,26 +0,0 @@ -guard: - version: 2.0.0 - -guards: - - id: unique_guard_vUSP_1 - name: APPC 5 Restart - description: - We only allow 5 restarts over 15 minute window during the day time hours (i.e. avoid midnight to 5am) - actor: APPC - recipe: Restart - limit_constraints: - - num: 5 - # - # https://www.w3.org/TR/xmlschema-2/#duration - # - duration: - value: 15 - units: minute - # - # XACML function time-in-range - # - # Assumption is that the "current time" is the 1st argument - # - time_in_range: - arg2: PT5H - arg3: PT24H \ No newline at end of file -- cgit 1.2.3-korg