summaryrefslogtreecommitdiffstats
path: root/controlloop/templates/template.demo/src
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2018-08-29 07:58:53 -0400
committerPamela Dragosh <pdragosh@research.att.com>2018-08-29 12:34:55 -0400
commit8279af376b435e1d7dd118a1955c5681edf3b847 (patch)
treef0e9f24028b8e96908184192f9e2813a2981938a /controlloop/templates/template.demo/src
parent17435998307f9f86ec5ebe55d6d36eceee1f1943 (diff)
Fix remaining checkstyle
Lots of formatting, missing javadoc, distance from use, imports must be explicit, ordering of methods. Fixed some abbreviation problems in classes and renamed JUnit tests to fix this. Issue-ID: POLICY-883 Change-Id: I8494f63d88d63c0232aca97f7bcc848816228fb1 Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'controlloop/templates/template.demo/src')
-rw-r--r--controlloop/templates/template.demo/src/main/resources/blacklist_template.xml145
-rw-r--r--controlloop/templates/template.demo/src/main/resources/frequency_limiter_template.xml158
-rw-r--r--controlloop/templates/template.demo/src/main/resources/frequency_limiter_template_old.xml122
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java48
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java439
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VcpeControlLoopTest.java (renamed from controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VCPEControlLoopTest.java)54
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VdnsControlLoopTest.java (renamed from controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VDNSControlLoopTest.java)58
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfcControlLoopTest.java (renamed from controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFCControlLoopTest.java)54
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfwControlLoopTest.java (renamed from controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java)58
-rw-r--r--controlloop/templates/template.demo/src/test/resources/META-INF/persistence.xml39
10 files changed, 701 insertions, 474 deletions
diff --git a/controlloop/templates/template.demo/src/main/resources/blacklist_template.xml b/controlloop/templates/template.demo/src/main/resources/blacklist_template.xml
index c27ced3ac..590b19d25 100644
--- a/controlloop/templates/template.demo/src/main/resources/blacklist_template.xml
+++ b/controlloop/templates/template.demo/src/main/resources/blacklist_template.xml
@@ -18,57 +18,100 @@
limitations under the License.
============LICENSE_END=========================================================
-->
-<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" PolicyId="urn:com:att:xacml:policy:id:25e12b06-11d5-4895-b2a2-6f6c594de069" Version="1" RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-unless-deny">
- <Description>Policy for frequency limiter.</Description>
- <Target>
- <AnyOf>
- <AllOf>
- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
+<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17"
+ PolicyId="urn:com:att:xacml:policy:id:25e12b06-11d5-4895-b2a2-6f6c594de069"
+ Version="1"
+ RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-unless-deny">
+ <Description>Policy for frequency limiter.</Description>
+ <Target>
+ <AnyOf>
+ <AllOf>
+ <Match
+ MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
<!-- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">.*</AttributeValue>-->
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">${clname}</AttributeValue>
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" AttributeId="urn:oasis:names:tc:xacml:1.0:clname:clname-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
- </Match>
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#string">${clname}</AttributeValue>
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
+ AttributeId="urn:oasis:names:tc:xacml:1.0:clname:clname-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string"
+ MustBePresent="false" />
+ </Match>
- <!-- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">-->
- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">${actor}</AttributeValue>
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" AttributeId="urn:oasis:names:tc:xacml:1.0:actor:actor-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
- </Match>
- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">${recipe}</AttributeValue>
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action" AttributeId="urn:oasis:names:tc:xacml:1.0:operation:operation-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
- </Match>
- </AllOf>
- </AnyOf>
- </Target>
- <Rule RuleId="urn:com:att:xacml:rule:id:e1e8c5c0-e2ba-47d5-9289-6c015305ed21" Effect="Deny">
- <Description>DENY - only if target is in black list and guard is active.</Description>
- <Condition>
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:and">
- <VariableReference VariableId="isGuardActive"/>
- <VariableReference VariableId="isInBlackList"/>
- </Apply>
- </Condition>
- </Rule>
- <VariableDefinition VariableId="isInBlackList">
- <Apply FunctionId="urn:oasis:names:tc:xacml:3.0:function:any-of">
- <Function FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal"/>
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-one-and-only">
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource" AttributeId="urn:oasis:names:tc:xacml:1.0:target:target-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
- </Apply>
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-bag">
- ${blackListElement}
- <!-- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">vserver.vserver-name</AttributeValue>-->
- </Apply>
- </Apply>
- </VariableDefinition>
- <VariableDefinition VariableId="isGuardActive">
- <Apply FunctionId="urn:oasis:names:tc:xacml:2.0:function:time-in-range">
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:time-one-and-only">
- <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:environment:current-time" DataType="http://www.w3.org/2001/XMLSchema#time" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:environment" MustBePresent="false"/>
- </Apply>
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveStart}</AttributeValue>
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveEnd}</AttributeValue>
- </Apply>
- </VariableDefinition>
+ <!-- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">-->
+ <Match
+ MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#string">${actor}</AttributeValue>
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
+ AttributeId="urn:oasis:names:tc:xacml:1.0:actor:actor-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string"
+ MustBePresent="false" />
+ </Match>
+ <Match
+ MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#string">${recipe}</AttributeValue>
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action"
+ AttributeId="urn:oasis:names:tc:xacml:1.0:operation:operation-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string"
+ MustBePresent="false" />
+ </Match>
+ </AllOf>
+ </AnyOf>
+ </Target>
+ <Rule
+ RuleId="urn:com:att:xacml:rule:id:e1e8c5c0-e2ba-47d5-9289-6c015305ed21"
+ Effect="Deny">
+ <Description>DENY - only if target is in black list and guard is
+ active.</Description>
+ <Condition>
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:and">
+ <VariableReference
+ VariableId="isGuardActive" />
+ <VariableReference
+ VariableId="isInBlackList" />
+ </Apply>
+ </Condition>
+ </Rule>
+ <VariableDefinition VariableId="isInBlackList">
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:3.0:function:any-of">
+ <Function
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal" />
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-one-and-only">
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
+ AttributeId="urn:oasis:names:tc:xacml:1.0:target:target-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string"
+ MustBePresent="false" />
+ </Apply>
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-bag">
+ ${blackListElement}
+ <!-- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">vserver.vserver-name</AttributeValue>-->
+ </Apply>
+ </Apply>
+ </VariableDefinition>
+ <VariableDefinition VariableId="isGuardActive">
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:2.0:function:time-in-range">
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:time-one-and-only">
+ <AttributeDesignator
+ AttributeId="urn:oasis:names:tc:xacml:1.0:environment:current-time"
+ DataType="http://www.w3.org/2001/XMLSchema#time"
+ Category="urn:oasis:names:tc:xacml:3.0:attribute-category:environment"
+ MustBePresent="false" />
+ </Apply>
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveStart}</AttributeValue>
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveEnd}</AttributeValue>
+ </Apply>
+ </VariableDefinition>
</Policy>
diff --git a/controlloop/templates/template.demo/src/main/resources/frequency_limiter_template.xml b/controlloop/templates/template.demo/src/main/resources/frequency_limiter_template.xml
index 9e44ae846..34aa1af69 100644
--- a/controlloop/templates/template.demo/src/main/resources/frequency_limiter_template.xml
+++ b/controlloop/templates/template.demo/src/main/resources/frequency_limiter_template.xml
@@ -18,60 +18,110 @@
limitations under the License.
============LICENSE_END=========================================================
-->
-<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" PolicyId="urn:com:att:xacml:policy:id:25e12b06-11d5-4895-b2a2-6f6c594de069" Version="1" RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-unless-deny">
- <Description>Policy for frequency limiter.</Description>
- <Target>
- <AnyOf>
- <AllOf>
-
- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
+<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17"
+ PolicyId="urn:com:att:xacml:policy:id:25e12b06-11d5-4895-b2a2-6f6c594de069"
+ Version="1"
+ RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-unless-deny">
+ <Description>Policy for frequency limiter.</Description>
+ <Target>
+ <AnyOf>
+ <AllOf>
+
+ <Match
+ MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
<!-- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">.*</AttributeValue>-->
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">${clname}</AttributeValue>
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" AttributeId="urn:oasis:names:tc:xacml:1.0:clname:clname-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
- </Match>
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#string">${clname}</AttributeValue>
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
+ AttributeId="urn:oasis:names:tc:xacml:1.0:clname:clname-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string"
+ MustBePresent="false" />
+ </Match>
- <!-- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">-->
- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">${actor}</AttributeValue>
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" AttributeId="urn:oasis:names:tc:xacml:1.0:actor:actor-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
- </Match>
- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">${recipe}</AttributeValue>
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action" AttributeId="urn:oasis:names:tc:xacml:1.0:operation:operation-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
- </Match>
-
- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">${targets}</AttributeValue>
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource" AttributeId="urn:oasis:names:tc:xacml:1.0:target:target-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
- </Match>
-
- </AllOf>
- </AnyOf>
- </Target>
- <Rule RuleId="urn:com:att:xacml:rule:id:e1e8c5c0-e2ba-47d5-9289-6c015305ed21" Effect="Deny">
- <Description>DENY - only if number of operations performed in the past is larger than the limit and the Guard is active.</Description>
- <Condition>
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:and">
- <VariableReference VariableId="isGuardActive"/>
- <VariableReference VariableId="isHistoryGreaterThanLimit"/>
- </Apply>
- </Condition>
- </Rule>
- <VariableDefinition VariableId="isGuardActive">
- <Apply FunctionId="urn:oasis:names:tc:xacml:2.0:function:time-in-range">
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:time-one-and-only">
- <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:environment:current-time" DataType="http://www.w3.org/2001/XMLSchema#time" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:environment" MustBePresent="false"/>
- </Apply>
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveStart}</AttributeValue>
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveEnd}</AttributeValue>
- </Apply>
- </VariableDefinition>
- <VariableDefinition VariableId="isHistoryGreaterThanLimit">
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-greater-than-or-equal">
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-one-and-only">
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource" AttributeId="com:att:research:xacml:test:sql:resource:operations:count" DataType="http://www.w3.org/2001/XMLSchema#integer" Issuer="com:att:research:xacml:guard:historydb:tw:${twValue}:${twUnits}" MustBePresent="false"/>
- </Apply>
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#integer">${limit}</AttributeValue>
- </Apply>
- </VariableDefinition>
+ <!-- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">-->
+ <Match
+ MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#string">${actor}</AttributeValue>
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
+ AttributeId="urn:oasis:names:tc:xacml:1.0:actor:actor-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string"
+ MustBePresent="false" />
+ </Match>
+ <Match
+ MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#string">${recipe}</AttributeValue>
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action"
+ AttributeId="urn:oasis:names:tc:xacml:1.0:operation:operation-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string"
+ MustBePresent="false" />
+ </Match>
+
+ <Match
+ MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#string">${targets}</AttributeValue>
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
+ AttributeId="urn:oasis:names:tc:xacml:1.0:target:target-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string"
+ MustBePresent="false" />
+ </Match>
+
+ </AllOf>
+ </AnyOf>
+ </Target>
+ <Rule
+ RuleId="urn:com:att:xacml:rule:id:e1e8c5c0-e2ba-47d5-9289-6c015305ed21"
+ Effect="Deny">
+ <Description>DENY - only if number of operations performed in
+ the past is larger than the limit and the Guard is active.</Description>
+ <Condition>
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:and">
+ <VariableReference
+ VariableId="isGuardActive" />
+ <VariableReference
+ VariableId="isHistoryGreaterThanLimit" />
+ </Apply>
+ </Condition>
+ </Rule>
+ <VariableDefinition VariableId="isGuardActive">
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:2.0:function:time-in-range">
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:time-one-and-only">
+ <AttributeDesignator
+ AttributeId="urn:oasis:names:tc:xacml:1.0:environment:current-time"
+ DataType="http://www.w3.org/2001/XMLSchema#time"
+ Category="urn:oasis:names:tc:xacml:3.0:attribute-category:environment"
+ MustBePresent="false" />
+ </Apply>
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveStart}</AttributeValue>
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveEnd}</AttributeValue>
+ </Apply>
+ </VariableDefinition>
+ <VariableDefinition
+ VariableId="isHistoryGreaterThanLimit">
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-greater-than-or-equal">
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-one-and-only">
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
+ AttributeId="com:att:research:xacml:test:sql:resource:operations:count"
+ DataType="http://www.w3.org/2001/XMLSchema#integer"
+ Issuer="com:att:research:xacml:guard:historydb:tw:${twValue}:${twUnits}"
+ MustBePresent="false" />
+ </Apply>
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#integer">${limit}</AttributeValue>
+ </Apply>
+ </VariableDefinition>
</Policy>
diff --git a/controlloop/templates/template.demo/src/main/resources/frequency_limiter_template_old.xml b/controlloop/templates/template.demo/src/main/resources/frequency_limiter_template_old.xml
index 0bc182e71..b41fdb3f2 100644
--- a/controlloop/templates/template.demo/src/main/resources/frequency_limiter_template_old.xml
+++ b/controlloop/templates/template.demo/src/main/resources/frequency_limiter_template_old.xml
@@ -18,46 +18,84 @@
limitations under the License.
============LICENSE_END=========================================================
-->
-<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" PolicyId="urn:com:att:xacml:policy:id:25e12b06-11d5-4895-b2a2-6f6c594de069" Version="1" RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-unless-deny">
- <Description>Policy for frequency limiter.</Description>
- <Target>
- <AnyOf>
- <AllOf>
- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">${actor}</AttributeValue>
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" AttributeId="urn:oasis:names:tc:xacml:1.0:actor:actor-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
- </Match>
- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">${recipe}</AttributeValue>
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action" AttributeId="urn:oasis:names:tc:xacml:1.0:operation:operation-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
- </Match>
- </AllOf>
- </AnyOf>
- </Target>
- <Rule RuleId="urn:com:att:xacml:rule:id:e1e8c5c0-e2ba-47d5-9289-6c015305ed21" Effect="Deny">
- <Description>DENY - only if number of operations performed in the past is larger than the limit and the Guard is active.</Description>
- <Condition>
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:and">
- <VariableReference VariableId="isGuardActive"/>
- <VariableReference VariableId="isHistoryGreaterThanLimit"/>
- </Apply>
- </Condition>
- </Rule>
- <VariableDefinition VariableId="isGuardActive">
- <Apply FunctionId="urn:oasis:names:tc:xacml:2.0:function:time-in-range">
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:time-one-and-only">
- <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:environment:current-time" DataType="http://www.w3.org/2001/XMLSchema#time" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:environment" MustBePresent="false"/>
- </Apply>
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveStart}</AttributeValue>
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveEnd}</AttributeValue>
- </Apply>
- </VariableDefinition>
- <VariableDefinition VariableId="isHistoryGreaterThanLimit">
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-greater-than-or-equal">
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-one-and-only">
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource" AttributeId="com:att:research:xacml:test:sql:resource:operations:count" DataType="http://www.w3.org/2001/XMLSchema#integer" Issuer="com:att:research:xacml:test:sql:${timeWindow}" MustBePresent="false"/>
- </Apply>
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#integer">${limit}</AttributeValue>
- </Apply>
- </VariableDefinition>
+<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17"
+ PolicyId="urn:com:att:xacml:policy:id:25e12b06-11d5-4895-b2a2-6f6c594de069"
+ Version="1"
+ RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-unless-deny">
+ <Description>Policy for frequency limiter.</Description>
+ <Target>
+ <AnyOf>
+ <AllOf>
+ <Match
+ MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#string">${actor}</AttributeValue>
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
+ AttributeId="urn:oasis:names:tc:xacml:1.0:actor:actor-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string"
+ MustBePresent="false" />
+ </Match>
+ <Match
+ MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#string">${recipe}</AttributeValue>
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action"
+ AttributeId="urn:oasis:names:tc:xacml:1.0:operation:operation-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string"
+ MustBePresent="false" />
+ </Match>
+ </AllOf>
+ </AnyOf>
+ </Target>
+ <Rule
+ RuleId="urn:com:att:xacml:rule:id:e1e8c5c0-e2ba-47d5-9289-6c015305ed21"
+ Effect="Deny">
+ <Description>DENY - only if number of operations performed in
+ the past is larger than the limit and the Guard is active.</Description>
+ <Condition>
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:and">
+ <VariableReference
+ VariableId="isGuardActive" />
+ <VariableReference
+ VariableId="isHistoryGreaterThanLimit" />
+ </Apply>
+ </Condition>
+ </Rule>
+ <VariableDefinition VariableId="isGuardActive">
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:2.0:function:time-in-range">
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:time-one-and-only">
+ <AttributeDesignator
+ AttributeId="urn:oasis:names:tc:xacml:1.0:environment:current-time"
+ DataType="http://www.w3.org/2001/XMLSchema#time"
+ Category="urn:oasis:names:tc:xacml:3.0:attribute-category:environment"
+ MustBePresent="false" />
+ </Apply>
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveStart}</AttributeValue>
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveEnd}</AttributeValue>
+ </Apply>
+ </VariableDefinition>
+ <VariableDefinition
+ VariableId="isHistoryGreaterThanLimit">
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-greater-than-or-equal">
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-one-and-only">
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
+ AttributeId="com:att:research:xacml:test:sql:resource:operations:count"
+ DataType="http://www.w3.org/2001/XMLSchema#integer"
+ Issuer="com:att:research:xacml:test:sql:${timeWindow}"
+ MustBePresent="false" />
+ </Apply>
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#integer">${limit}</AttributeValue>
+ </Apply>
+ </VariableDefinition>
</Policy>
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java
index 584a8e349..31b6b2e30 100644
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java
@@ -62,7 +62,7 @@ import org.slf4j.LoggerFactory;
public class ControlLoopFailureTest implements TopicListener {
- private static final Logger logger = LoggerFactory.getLogger(VCPEControlLoopTest.class);
+ private static final Logger logger = LoggerFactory.getLogger(ControlLoopFailureTest.class);
private static List<? extends TopicSink> noopTopics;
@@ -75,11 +75,14 @@ public class ControlLoopFailureTest implements TopicListener {
static {
/* Set environment properties */
- Util.setAAIProps();
+ Util.setAaiProps();
Util.setGuardProps();
- Util.setPUProp();
+ Util.setPuProp();
}
+ /**
+ * Setup simulator.
+ */
@BeforeClass
public static void setUpSimulator() {
PolicyEngine.manager.configure(new Properties());
@@ -112,7 +115,8 @@ public class ControlLoopFailureTest implements TopicListener {
*/
try {
kieSession = startSession(
- "../archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl",
+ "../archetype-cl-amsterdam/src/main/resources/archetype-resources"
+ + "/src/main/resources/__closedLoopControlName__.drl",
"src/test/resources/yaml/policy_ControlLoop_vCPE.yaml",
"service=ServiceDemo;resource=Res1Demo;type=operational", "CL_vCPE",
"org.onap.closed_loop.ServiceDemo:VNFS:1.0.0");
@@ -123,6 +127,9 @@ public class ControlLoopFailureTest implements TopicListener {
}
}
+ /**
+ * Tear down simulator.
+ */
@AfterClass
public static void tearDownSimulator() {
/*
@@ -176,12 +183,12 @@ public class ControlLoopFailureTest implements TopicListener {
* Simulate an onset event the policy engine will receive from DCAE to kick off processing
* through the rules
*/
- sendEvent(pair.a, requestId, ControlLoopEventStatus.ONSET, "vnf01");
+ sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET, "vnf01");
/*
* Send a second event requesting an action for a different target entity
*/
- sendEvent(pair.a, requestId2, ControlLoopEventStatus.ONSET, "vnf02");
+ sendEvent(pair.first, requestId2, ControlLoopEventStatus.ONSET, "vnf02");
/*
* Send a second event for a different target to ensure there are no problems with obtaining
@@ -210,7 +217,7 @@ public class ControlLoopFailureTest implements TopicListener {
* @param policyName name of the policy
* @param policyVersion version of the policy
* @return the kieSession to be used to insert facts
- * @throws IOException
+ * @throws IOException throws IO exception
*/
private static KieSession startSession(String droolsTemplate, String yamlFile, String policyScope,
String policyName, String policyVersion) throws IOException {
@@ -220,23 +227,24 @@ public class ControlLoopFailureTest implements TopicListener {
*/
pair = Util.loadYaml(yamlFile);
assertNotNull(pair);
- assertNotNull(pair.a);
- assertNotNull(pair.a.getControlLoop());
- assertNotNull(pair.a.getControlLoop().getControlLoopName());
- assertTrue(pair.a.getControlLoop().getControlLoopName().length() > 0);
+ assertNotNull(pair.first);
+ assertNotNull(pair.first.getControlLoop());
+ assertNotNull(pair.first.getControlLoop().getControlLoopName());
+ assertTrue(pair.first.getControlLoop().getControlLoopName().length() > 0);
/*
* Construct a kie session
*/
- final KieSession kieSession = Util.buildContainer(droolsTemplate, pair.a.getControlLoop().getControlLoopName(),
- policyScope, policyName, policyVersion, URLEncoder.encode(pair.b, "UTF-8"));
+ final KieSession kieSession = Util.buildContainer(droolsTemplate,
+ pair.first.getControlLoop().getControlLoopName(),
+ policyScope, policyName, policyVersion, URLEncoder.encode(pair.second, "UTF-8"));
/*
* Retrieve the Policy Engine
*/
logger.debug("============");
- logger.debug(URLEncoder.encode(pair.b, "UTF-8"));
+ logger.debug(URLEncoder.encode(pair.second, "UTF-8"));
logger.debug("============");
return kieSession;
@@ -294,9 +302,9 @@ public class ControlLoopFailureTest implements TopicListener {
assertNotNull(notification.getMessage());
assertTrue(notification.getMessage().startsWith("actor=APPC"));
if (requestId.equals(notification.getRequestId())) {
- sendEvent(pair.a, requestId, ControlLoopEventStatus.ABATED, "vnf01");
+ sendEvent(pair.first, requestId, ControlLoopEventStatus.ABATED, "vnf01");
} else if (requestId2.equals(notification.getRequestId())) {
- sendEvent(pair.a, requestId2, ControlLoopEventStatus.ABATED, "vnf02");
+ sendEvent(pair.first, requestId2, ControlLoopEventStatus.ABATED, "vnf02");
}
} else if (policyName.endsWith("EVENT.MANAGER")) {
logger.debug("Rule Fired: " + notification.getPolicyName());
@@ -341,7 +349,7 @@ public class ControlLoopFailureTest implements TopicListener {
* will be denied
*/
if (requestId.equals(appcResponse.getCommonHeader().getRequestId())) {
- sendEvent(pair.a, requestId3, ControlLoopEventStatus.ONSET, "vnf01");
+ sendEvent(pair.first, requestId3, ControlLoopEventStatus.ONSET, "vnf01");
}
kieSession.insert(dmaapResponse);
}
@@ -354,12 +362,12 @@ public class ControlLoopFailureTest implements TopicListener {
* @param policy the controlLoopName comes from the policy
* @param requestID the requestId for this event
* @param status could be onset or abated
- * @param target, the target entity to take an action on
+ * @param target the target entity to take an action on
*/
- protected void sendEvent(ControlLoopPolicy policy, UUID requestID, ControlLoopEventStatus status, String target) {
+ protected void sendEvent(ControlLoopPolicy policy, UUID requestId, ControlLoopEventStatus status, String target) {
VirtualControlLoopEvent event = new VirtualControlLoopEvent();
event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
- event.setRequestId(requestID);
+ event.setRequestId(requestId);
event.setTarget("generic-vnf.vnf-id");
event.setClosedLoopAlarmStart(Instant.now());
event.setAai(new HashMap<>());
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java
index b69369181..4ec51772f 100644
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* demo
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -22,6 +22,8 @@ package org.onap.policy.template.demo;
import static org.junit.Assert.fail;
+import com.att.research.xacml.util.XACMLProperties;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -44,9 +46,9 @@ import org.kie.api.builder.Results;
import org.kie.api.builder.model.KieModuleModel;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
+import org.onap.policy.common.endpoints.http.server.HttpServletServer;
import org.onap.policy.controlloop.policy.ControlLoopPolicy;
import org.onap.policy.controlloop.policy.guard.ControlLoopGuard;
-import org.onap.policy.common.endpoints.http.server.HttpServletServer;
import org.onap.policy.drools.system.PolicyEngine;
import org.onap.policy.guard.PolicyGuardYamlToXacml;
import org.slf4j.Logger;
@@ -54,135 +56,159 @@ import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
-import com.att.research.xacml.util.XACMLProperties;
public final class Util {
- private static final String OPSHISTPUPROP = "OperationsHistoryPU";
- private static final Logger logger = LoggerFactory.getLogger(Util.class);
-
- public static class Pair<A, B> {
- public final A a;
- public final B b;
-
- public Pair(A a, B b) {
- this.a = a;
- this.b = b;
- }
- }
-
- public static Pair<ControlLoopPolicy, String> loadYaml(String testFile) {
- try (InputStream is = new FileInputStream(new File(testFile))) {
- String contents = IOUtils.toString(is, StandardCharsets.UTF_8);
- //
- // Read the yaml into our Java Object
- //
- Yaml yaml = new Yaml(new Constructor(ControlLoopPolicy.class));
- Object obj = yaml.load(contents);
-
- //String ttt = ((ControlLoopPolicy)obj).policies.getFirst().payload.get("asdas");
- logger.debug(contents);
- //for(Policy policy : ((ControlLoopPolicy)obj).policies){
-
- return new Pair<ControlLoopPolicy, String>((ControlLoopPolicy) obj, contents);
- } catch (FileNotFoundException e) {
- fail(e.getLocalizedMessage());
- } catch (IOException e) {
- fail(e.getLocalizedMessage());
- }
- return null;
- }
-
- public static ControlLoopGuard loadYamlGuard(String testFile) {
- try (InputStream is = new FileInputStream(new File(testFile))) {
- String contents = IOUtils.toString(is, StandardCharsets.UTF_8);
- //
- // Read the yaml into our Java Object
- //
- Yaml yaml = new Yaml(new Constructor(ControlLoopGuard.class));
- Object obj = yaml.load(contents);
- return (ControlLoopGuard) obj;
- } catch (FileNotFoundException e) {
- fail(e.getLocalizedMessage());
- } catch (IOException e) {
- fail(e.getLocalizedMessage());
- }
- return null;
- }
-
- public static HttpServletServer buildAaiSim() throws InterruptedException, IOException {
- return org.onap.policy.simulators.Util.buildAaiSim();
- }
-
- public static HttpServletServer buildSoSim() throws InterruptedException, IOException {
- return org.onap.policy.simulators.Util.buildSoSim();
- }
-
- public static HttpServletServer buildVfcSim() throws InterruptedException, IOException {
- return org.onap.policy.simulators.Util.buildVfcSim();
- }
-
- public static HttpServletServer buildGuardSim() throws InterruptedException, IOException {
+ private static final String OPSHISTPUPROP = "OperationsHistoryPU";
+ private static final Logger logger = LoggerFactory.getLogger(Util.class);
+
+ public static class Pair<A, B> {
+ public final A first;
+ public final B second;
+
+ public Pair(A first, B second) {
+ this.first = first;
+ this.second = second;
+ }
+ }
+
+ /**
+ * Load YAML.
+ *
+ * @param testFile test file to load
+ * @return the Pair of a policy and the yaml contents
+ */
+ public static Pair<ControlLoopPolicy, String> loadYaml(String testFile) {
+ try (InputStream is = new FileInputStream(new File(testFile))) {
+ String contents = IOUtils.toString(is, StandardCharsets.UTF_8);
+ //
+ // Read the yaml into our Java Object
+ //
+ Yaml yaml = new Yaml(new Constructor(ControlLoopPolicy.class));
+ Object obj = yaml.load(contents);
+
+ logger.debug(contents);
+
+ return new Pair<ControlLoopPolicy, String>((ControlLoopPolicy) obj, contents);
+ } catch (FileNotFoundException e) {
+ fail(e.getLocalizedMessage());
+ } catch (IOException e) {
+ fail(e.getLocalizedMessage());
+ }
+ return null;
+ }
+
+ /**
+ * Load the YAML guard policy.
+ *
+ * @param testFile the test file to load
+ * @return return the guard object
+ */
+ public static ControlLoopGuard loadYamlGuard(String testFile) {
+ try (InputStream is = new FileInputStream(new File(testFile))) {
+ String contents = IOUtils.toString(is, StandardCharsets.UTF_8);
+ //
+ // Read the yaml into our Java Object
+ //
+ Yaml yaml = new Yaml(new Constructor(ControlLoopGuard.class));
+ Object obj = yaml.load(contents);
+ return (ControlLoopGuard) obj;
+ } catch (FileNotFoundException e) {
+ fail(e.getLocalizedMessage());
+ } catch (IOException e) {
+ fail(e.getLocalizedMessage());
+ }
+ return null;
+ }
+
+ public static HttpServletServer buildAaiSim() throws InterruptedException, IOException {
+ return org.onap.policy.simulators.Util.buildAaiSim();
+ }
+
+ public static HttpServletServer buildSoSim() throws InterruptedException, IOException {
+ return org.onap.policy.simulators.Util.buildSoSim();
+ }
+
+ public static HttpServletServer buildVfcSim() throws InterruptedException, IOException {
+ return org.onap.policy.simulators.Util.buildVfcSim();
+ }
+
+ public static HttpServletServer buildGuardSim() throws InterruptedException, IOException {
return org.onap.policy.simulators.Util.buildGuardSim();
}
-
- private static String generatePolicy(String ruleContents,
- String closedLoopControlName,
- String policyScope,
- String policyName,
- String policyVersion,
- String controlLoopYaml) {
-
- Pattern p = Pattern.compile("\\$\\{closedLoopControlName\\}");
- Matcher m = p.matcher(ruleContents);
- ruleContents = m.replaceAll(closedLoopControlName);
-
- p = Pattern.compile("\\$\\{policyScope\\}");
- m = p.matcher(ruleContents);
- ruleContents = m.replaceAll(policyScope);
-
- p = Pattern.compile("\\$\\{policyName\\}");
- m = p.matcher(ruleContents);
- ruleContents = m.replaceAll(policyName);
-
- p = Pattern.compile("\\$\\{policyVersion\\}");
- m = p.matcher(ruleContents);
- ruleContents = m.replaceAll(policyVersion);
-
- p = Pattern.compile("\\$\\{controlLoopYaml\\}");
- m = p.matcher(ruleContents);
- ruleContents = m.replaceAll(controlLoopYaml);
-
- return ruleContents;
- }
-
- public static KieSession buildContainer(String droolsTemplate, String closedLoopControlName, String policyScope, String policyName, String policyVersion, String yamlSpecification) throws IOException {
- //
- // Get our Drools Kie factory
- //
+
+ private static String generatePolicy(String ruleContents,
+ String closedLoopControlName,
+ String policyScope,
+ String policyName,
+ String policyVersion,
+ String controlLoopYaml) {
+
+ Pattern pattern = Pattern.compile("\\$\\{closedLoopControlName\\}");
+ Matcher matcher = pattern.matcher(ruleContents);
+ ruleContents = matcher.replaceAll(closedLoopControlName);
+
+ pattern = Pattern.compile("\\$\\{policyScope\\}");
+ matcher = pattern.matcher(ruleContents);
+ ruleContents = matcher.replaceAll(policyScope);
+
+ pattern = Pattern.compile("\\$\\{policyName\\}");
+ matcher = pattern.matcher(ruleContents);
+ ruleContents = matcher.replaceAll(policyName);
+
+ pattern = Pattern.compile("\\$\\{policyVersion\\}");
+ matcher = pattern.matcher(ruleContents);
+ ruleContents = matcher.replaceAll(policyVersion);
+
+ pattern = Pattern.compile("\\$\\{controlLoopYaml\\}");
+ matcher = pattern.matcher(ruleContents);
+ ruleContents = matcher.replaceAll(controlLoopYaml);
+
+ return ruleContents;
+ }
+
+ /**
+ * Build the container.
+ *
+ * @param droolsTemplate template
+ * @param closedLoopControlName control loop id
+ * @param policyScope policy scope
+ * @param policyName policy name
+ * @param policyVersion policy version
+ * @param yamlSpecification incoming yaml specification
+ * @return the Kie session
+ * @throws IOException if the container cannot be built
+ */
+ public static KieSession buildContainer(String droolsTemplate, String closedLoopControlName,
+ String policyScope, String policyName, String policyVersion,
+ String yamlSpecification) throws IOException {
+ //
+ // Get our Drools Kie factory
+ //
KieServices ks = KieServices.Factory.get();
-
- KieModuleModel kModule = ks.newKieModuleModel();
-
- logger.debug("KMODULE:" + System.lineSeparator() + kModule.toXML());
-
+
+ KieModuleModel kieModule = ks.newKieModuleModel();
+
+ logger.debug("KMODULE:" + System.lineSeparator() + kieModule.toXML());
+
//
// Generate our drools rule from our template
//
KieFileSystem kfs = ks.newKieFileSystem();
-
- kfs.writeKModuleXML(kModule.toXML());
+
+ kfs.writeKModuleXML(kieModule.toXML());
{
- Path rule = Paths.get(droolsTemplate);
- String ruleTemplate = new String(Files.readAllBytes(rule));
- String drlContents = generatePolicy(ruleTemplate,
- closedLoopControlName,
- policyScope,
- policyName,
- policyVersion,
- yamlSpecification);
-
- kfs.write("src/main/resources/" + policyName + ".drl", ks.getResources().newByteArrayResource(drlContents.getBytes()));
+ Path rule = Paths.get(droolsTemplate);
+ String ruleTemplate = new String(Files.readAllBytes(rule));
+ String drlContents = generatePolicy(ruleTemplate,
+ closedLoopControlName,
+ policyScope,
+ policyName,
+ policyVersion,
+ yamlSpecification);
+
+ kfs.write("src/main/resources/" + policyName + ".drl",
+ ks.getResources().newByteArrayResource(drlContents.getBytes()));
}
//
// Compile the rule
@@ -190,95 +216,112 @@ public final class Util {
KieBuilder builder = ks.newKieBuilder(kfs).buildAll();
Results results = builder.getResults();
if (results.hasMessages(Message.Level.ERROR)) {
- for (Message msg : results.getMessages()) {
- logger.error(msg.toString());
- }
- throw new RuntimeException("Drools Rule has Errors");
+ for (Message msg : results.getMessages()) {
+ logger.error(msg.toString());
+ }
+ throw new RuntimeException("Drools Rule has Errors");
+ }
+ for (Message msg : results.getMessages()) {
+ logger.debug(msg.toString());
}
- for (Message msg : results.getMessages()) {
- logger.debug(msg.toString());
- }
- //
- // Create our kie Session and container
- //
+ //
+ // Create our kie Session and container
+ //
ReleaseId releaseId = ks.getRepository().getDefaultReleaseId();
logger.debug(releaseId.toString());
- KieContainer kContainer = ks.newKieContainer(releaseId);
-
- return setupSession(kContainer.newKieSession());
- }
-
- private static KieSession setupSession (KieSession kieSession) {
-
-
- //
- // Create XACML Guard policy from YAML
- // We prepare 4 Guards. Notice that Rebuilds recipe has two Guards (for checking policy combining algorithm)
- //
- PolicyGuardYamlToXacml.fromYamlToXacml("src/test/resources/yaml/policy_guard_appc_restart.yaml",
- "src/main/resources/frequency_limiter_template.xml",
- "src/test/resources/xacml/autogenerated_frequency_limiter_restart.xml");
-
- PolicyGuardYamlToXacml.fromYamlToXacml("src/test/resources/yaml/policy_guard_appc_rebuild.yaml",
- "src/main/resources/frequency_limiter_template.xml",
- "src/test/resources/xacml/autogenerated_frequency_limiter_rebuild.xml");
-
- PolicyGuardYamlToXacml.fromYamlToXacml("src/test/resources/yaml/policy_guard_appc_rebuild_1.yaml",
- "src/main/resources/frequency_limiter_template.xml",
- "src/test/resources/xacml/autogenerated_frequency_limiter_rebuild_1.xml");
-
- PolicyGuardYamlToXacml.fromYamlToXacml("src/test/resources/yaml/policy_guard_appc_migrate.yaml",
- "src/main/resources/frequency_limiter_template.xml",
- "src/test/resources/xacml/autogenerated_frequency_limiter_migrate.xml");
-
- PolicyGuardYamlToXacml.fromYamlToXacml("src/test/resources/yaml/policy_guard_appc_modifyconfig.yaml",
+ KieContainer keyContainer = ks.newKieContainer(releaseId);
+
+ return setupSession(keyContainer.newKieSession());
+ }
+
+ private static KieSession setupSession(KieSession kieSession) {
+
+
+ //
+ // Create XACML Guard policy from YAML
+ // We prepare 4 Guards. Notice that Rebuilds recipe has two Guards (for checking policy combining algorithm)
+ //
+ PolicyGuardYamlToXacml.fromYamlToXacml("src/test/resources/yaml/policy_guard_appc_restart.yaml",
+ "src/main/resources/frequency_limiter_template.xml",
+ "src/test/resources/xacml/autogenerated_frequency_limiter_restart.xml");
+
+ PolicyGuardYamlToXacml.fromYamlToXacml("src/test/resources/yaml/policy_guard_appc_rebuild.yaml",
+ "src/main/resources/frequency_limiter_template.xml",
+ "src/test/resources/xacml/autogenerated_frequency_limiter_rebuild.xml");
+
+ PolicyGuardYamlToXacml.fromYamlToXacml("src/test/resources/yaml/policy_guard_appc_rebuild_1.yaml",
+ "src/main/resources/frequency_limiter_template.xml",
+ "src/test/resources/xacml/autogenerated_frequency_limiter_rebuild_1.xml");
+
+ PolicyGuardYamlToXacml.fromYamlToXacml("src/test/resources/yaml/policy_guard_appc_migrate.yaml",
+ "src/main/resources/frequency_limiter_template.xml",
+ "src/test/resources/xacml/autogenerated_frequency_limiter_migrate.xml");
+
+ PolicyGuardYamlToXacml.fromYamlToXacml("src/test/resources/yaml/policy_guard_appc_modifyconfig.yaml",
"src/main/resources/frequency_limiter_template.xml",
"src/test/resources/xacml/autogenerated_frequency_limiter_modifyconfig.xml");
-
- PolicyGuardYamlToXacml.fromYamlToXacmlBlacklist("src/test/resources/yaml/policy_guard_appc_restart_blacklist.yaml",
- "src/main/resources/blacklist_template.xml",
- "src/test/resources/xacml/autogenerated_blacklist.xml");
-
- //
- // Creating an embedded XACML PDP
- //
- System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, "src/test/resources/xacml/xacml_guard.properties");
-
- return kieSession;
- }
-
- public static void setAAIProps(){
- PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666");
+
+ PolicyGuardYamlToXacml.fromYamlToXacmlBlacklist(
+ "src/test/resources/yaml/policy_guard_appc_restart_blacklist.yaml",
+ "src/main/resources/blacklist_template.xml",
+ "src/test/resources/xacml/autogenerated_blacklist.xml");
+
+ //
+ // Creating an embedded XACML PDP
+ //
+ System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, "src/test/resources/xacml/xacml_guard.properties");
+
+ return kieSession;
+ }
+
+ /**
+ * Set the A&AI properties.
+ */
+ public static void setAaiProps() {
+ PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666");
PolicyEngine.manager.setEnvironmentProperty("aai.username", "AAI");
PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI");
- }
-
- public static void setSOProps(){
- PolicyEngine.manager.setEnvironmentProperty("so.url", "http://localhost:6667");
+ }
+
+ /**
+ * Set the SO properties.
+ */
+ public static void setSoProps() {
+ PolicyEngine.manager.setEnvironmentProperty("so.url", "http://localhost:6667");
PolicyEngine.manager.setEnvironmentProperty("so.username", "SO");
PolicyEngine.manager.setEnvironmentProperty("so.password", "SO");
- }
-
- public static void setGuardProps(){
- /*
- * Guard PDP-x connection Properties
- */
- PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_URL, "http://localhost:6669/pdp/api/getDecision");
- PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_USER, "python");
- PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_PASS, "test");
- PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_CLIENT_USER, "python");
- PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_CLIENT_PASS, "test");
- PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_ENV, "TEST");
- PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_DISABLED, "false");
}
-
- public static void setVFCProps() {
- PolicyEngine.manager.setEnvironmentProperty("vfc.url", "http://localhost:6668");
+
+ /**
+ * Set the Guard properties.
+ */
+ public static void setGuardProps() {
+ /*
+ * Guard PDP-x connection Properties
+ */
+ PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_URL, "http://localhost:6669/pdp/api/getDecision");
+ PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_USER, "python");
+ PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_PASS, "test");
+ PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_CLIENT_USER, "python");
+ PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_CLIENT_PASS, "test");
+ PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_ENV, "TEST");
+ PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_DISABLED, "false");
+ }
+
+ /**
+ * Set the VFC properties.
+ */
+ public static void setVfcProps() {
+ PolicyEngine.manager.setEnvironmentProperty("vfc.url", "http://localhost:6668");
PolicyEngine.manager.setEnvironmentProperty("vfc.username", "VFC");
PolicyEngine.manager.setEnvironmentProperty("vfc.password", "VFC");
- }
- public static void setPUProp(){
- System.setProperty(OPSHISTPUPROP, "TestOperationsHistoryPU");
- }
+ }
+
+ /**
+ * Set the operation history properties.
+ */
+ public static void setPuProp() {
+ System.setProperty(OPSHISTPUPROP, "TestOperationsHistoryPU");
+ }
}
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VCPEControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VcpeControlLoopTest.java
index 785be9907..c1e8e1e66 100644
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VCPEControlLoopTest.java
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VcpeControlLoopTest.java
@@ -62,24 +62,27 @@ import org.onap.policy.drools.utils.logging.LoggerUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class VCPEControlLoopTest implements TopicListener {
+public class VcpeControlLoopTest implements TopicListener {
- private static final Logger logger = LoggerFactory.getLogger(VCPEControlLoopTest.class);
+ private static final Logger logger = LoggerFactory.getLogger(VcpeControlLoopTest.class);
private static List<? extends TopicSink> noopTopics;
private static KieSession kieSession;
private static Util.Pair<ControlLoopPolicy, String> pair;
- private UUID requestID;
+ private UUID requestId;
static {
/* Set environment properties */
- Util.setAAIProps();
+ Util.setAaiProps();
Util.setGuardProps();
- Util.setPUProp();
+ Util.setPuProp();
LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "INFO");
}
+ /**
+ * Setup the simulator.
+ */
@BeforeClass
public static void setUpSimulator() {
PolicyEngine.manager.configure(new Properties());
@@ -111,7 +114,8 @@ public class VCPEControlLoopTest implements TopicListener {
*/
try {
kieSession = startSession(
- "../archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl",
+ "../archetype-cl-amsterdam/src/main/resources/archetype-resources"
+ + "/src/main/resources/__closedLoopControlName__.drl",
"src/test/resources/yaml/policy_ControlLoop_vCPE.yaml",
"service=ServiceDemo;resource=Res1Demo;type=operational", "CL_vCPE",
"org.onap.closed_loop.ServiceDemo:VNFS:1.0.0");
@@ -122,6 +126,9 @@ public class VCPEControlLoopTest implements TopicListener {
}
}
+ /**
+ * Tear down the simulator.
+ */
@AfterClass
public static void tearDownSimulator() {
/*
@@ -150,13 +157,13 @@ public class VCPEControlLoopTest implements TopicListener {
/*
* Create a unique requestId
*/
- requestID = UUID.randomUUID();
+ requestId = UUID.randomUUID();
/*
* Simulate an onset event the policy engine will receive from DCAE to kick off processing
* through the rules
*/
- sendEvent(pair.a, requestID, ControlLoopEventStatus.ONSET, "vCPEInfraVNF13", true);
+ sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET, "vCPEInfraVNF13", true);
kieSession.fireUntilHalt();
@@ -186,13 +193,13 @@ public class VCPEControlLoopTest implements TopicListener {
/*
* Create a unique requestId
*/
- requestID = UUID.randomUUID();
+ requestId = UUID.randomUUID();
/*
* Simulate an onset event the policy engine will receive from DCAE to kick off processing
* through the rules
*/
- sendEvent(pair.a, requestID, ControlLoopEventStatus.ONSET, "getFail", false);
+ sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET, "getFail", false);
kieSession.fireUntilHalt();
@@ -218,7 +225,7 @@ public class VCPEControlLoopTest implements TopicListener {
* @param policyName name of the policy
* @param policyVersion version of the policy
* @return the kieSession to be used to insert facts
- * @throws IOException
+ * @throws IOException IO exception
*/
private static KieSession startSession(String droolsTemplate, String yamlFile, String policyScope,
String policyName, String policyVersion) throws IOException {
@@ -228,23 +235,24 @@ public class VCPEControlLoopTest implements TopicListener {
*/
pair = Util.loadYaml(yamlFile);
assertNotNull(pair);
- assertNotNull(pair.a);
- assertNotNull(pair.a.getControlLoop());
- assertNotNull(pair.a.getControlLoop().getControlLoopName());
- assertTrue(pair.a.getControlLoop().getControlLoopName().length() > 0);
+ assertNotNull(pair.first);
+ assertNotNull(pair.first.getControlLoop());
+ assertNotNull(pair.first.getControlLoop().getControlLoopName());
+ assertTrue(pair.first.getControlLoop().getControlLoopName().length() > 0);
/*
* Construct a kie session
*/
- final KieSession kieSession = Util.buildContainer(droolsTemplate, pair.a.getControlLoop().getControlLoopName(),
- policyScope, policyName, policyVersion, URLEncoder.encode(pair.b, "UTF-8"));
+ final KieSession kieSession = Util.buildContainer(droolsTemplate,
+ pair.first.getControlLoop().getControlLoopName(),
+ policyScope, policyName, policyVersion, URLEncoder.encode(pair.second, "UTF-8"));
/*
* Retrieve the Policy Engine
*/
logger.debug("============");
- logger.debug(URLEncoder.encode(pair.b, "UTF-8"));
+ logger.debug(URLEncoder.encode(pair.second, "UTF-8"));
logger.debug("============");
return kieSession;
@@ -301,7 +309,7 @@ public class VCPEControlLoopTest implements TopicListener {
assertTrue(ControlLoopNotificationType.OPERATION_SUCCESS.equals(notification.getNotification()));
assertNotNull(notification.getMessage());
assertTrue(notification.getMessage().startsWith("actor=APPC"));
- sendEvent(pair.a, requestID, ControlLoopEventStatus.ABATED);
+ sendEvent(pair.first, requestId, ControlLoopEventStatus.ABATED);
} else if (policyName.endsWith("EVENT.MANAGER")) {
logger.debug("Rule Fired: " + notification.getPolicyName());
if ("getFail".equals(notification.getAai().get("generic-vnf.vnf-name"))) {
@@ -348,10 +356,10 @@ public class VCPEControlLoopTest implements TopicListener {
* @param requestID the requestId for this event
* @param status could be onset or abated
*/
- protected void sendEvent(ControlLoopPolicy policy, UUID requestID, ControlLoopEventStatus status) {
+ protected void sendEvent(ControlLoopPolicy policy, UUID requestId, ControlLoopEventStatus status) {
VirtualControlLoopEvent event = new VirtualControlLoopEvent();
event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
- event.setRequestId(requestID);
+ event.setRequestId(requestId);
event.setTarget("generic-vnf.vnf-name");
event.setClosedLoopAlarmStart(Instant.now());
event.setAai(new HashMap<>());
@@ -360,11 +368,11 @@ public class VCPEControlLoopTest implements TopicListener {
kieSession.insert(event);
}
- protected void sendEvent(ControlLoopPolicy policy, UUID requestID, ControlLoopEventStatus status, String vnfName,
+ protected void sendEvent(ControlLoopPolicy policy, UUID requestId, ControlLoopEventStatus status, String vnfName,
boolean isEnriched) {
VirtualControlLoopEvent event = new VirtualControlLoopEvent();
event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
- event.setRequestId(requestID);
+ event.setRequestId(requestId);
event.setTarget("generic-vnf.vnf-name");
event.setTargetType(ControlLoopTargetType.VNF);
event.setClosedLoopAlarmStart(Instant.now());
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VDNSControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VdnsControlLoopTest.java
index 630ade8c5..d1fb29e0a 100644
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VDNSControlLoopTest.java
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VdnsControlLoopTest.java
@@ -58,25 +58,28 @@ import org.onap.policy.so.SORequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class VDNSControlLoopTest implements TopicListener {
+public class VdnsControlLoopTest implements TopicListener {
- private static final Logger logger = LoggerFactory.getLogger(VDNSControlLoopTest.class);
+ private static final Logger logger = LoggerFactory.getLogger(VdnsControlLoopTest.class);
private static List<? extends TopicSink> noopTopics;
private static KieSession kieSession;
private static Util.Pair<ControlLoopPolicy, String> pair;
- private UUID requestID;
+ private UUID requestId;
static {
/* Set environment properties */
- Util.setAAIProps();
- Util.setSOProps();
+ Util.setAaiProps();
+ Util.setSoProps();
Util.setGuardProps();
- Util.setPUProp();
+ Util.setPuProp();
LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "INFO");
}
+ /**
+ * Setup the simulator.
+ */
@BeforeClass
public static void setUpSimulator() {
PolicyEngine.manager.configure(new Properties());
@@ -106,7 +109,8 @@ public class VDNSControlLoopTest implements TopicListener {
*/
try {
kieSession = startSession(
- "../archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl",
+ "../archetype-cl-amsterdam/src/main/resources/archetype-resources/"
+ + "src/main/resources/__closedLoopControlName__.drl",
"src/test/resources/yaml/policy_ControlLoop_SO-test.yaml", "type=operational", "CL_vDNS", "v2.0");
} catch (IOException e) {
e.printStackTrace();
@@ -115,6 +119,9 @@ public class VDNSControlLoopTest implements TopicListener {
}
}
+ /**
+ * Tear down the simulator.
+ */
@AfterClass
public static void tearDownSimulator() {
@@ -144,13 +151,13 @@ public class VDNSControlLoopTest implements TopicListener {
/*
* Create a unique requestId
*/
- requestID = UUID.randomUUID();
+ requestId = UUID.randomUUID();
/*
* Simulate an onset event the policy engine will receive from DCAE to kick off processing
* through the rules
*/
- sendEvent(pair.a, requestID, ControlLoopEventStatus.ONSET);
+ sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET);
kieSession.fireUntilHalt();
@@ -180,13 +187,13 @@ public class VDNSControlLoopTest implements TopicListener {
/*
* Create a unique requestId
*/
- requestID = UUID.randomUUID();
+ requestId = UUID.randomUUID();
/*
* Simulate an onset event the policy engine will receive from DCAE to kick off processing
* through the rules
*/
- sendEvent(pair.a, requestID, ControlLoopEventStatus.ONSET, "error");
+ sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET, "error");
kieSession.fireUntilHalt();
@@ -216,13 +223,13 @@ public class VDNSControlLoopTest implements TopicListener {
/*
* Create a unique requestId
*/
- requestID = UUID.randomUUID();
+ requestId = UUID.randomUUID();
/*
* Simulate an onset event the policy engine will receive from DCAE to kick off processing
* through the rules
*/
- sendEvent(pair.a, requestID, ControlLoopEventStatus.ONSET, "getFail");
+ sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET, "getFail");
try {
kieSession.fireUntilHalt();
@@ -253,7 +260,7 @@ public class VDNSControlLoopTest implements TopicListener {
* @param policyName name of the policy
* @param policyVersion version of the policy
* @return the kieSession to be used to insert facts
- * @throws IOException
+ * @throws IOException IO Exception
*/
private static KieSession startSession(String droolsTemplate, String yamlFile, String policyScope,
String policyName, String policyVersion) throws IOException {
@@ -263,23 +270,24 @@ public class VDNSControlLoopTest implements TopicListener {
*/
pair = Util.loadYaml(yamlFile);
assertNotNull(pair);
- assertNotNull(pair.a);
- assertNotNull(pair.a.getControlLoop());
- assertNotNull(pair.a.getControlLoop().getControlLoopName());
- assertTrue(pair.a.getControlLoop().getControlLoopName().length() > 0);
+ assertNotNull(pair.first);
+ assertNotNull(pair.first.getControlLoop());
+ assertNotNull(pair.first.getControlLoop().getControlLoopName());
+ assertTrue(pair.first.getControlLoop().getControlLoopName().length() > 0);
/*
* Construct a kie session
*/
- final KieSession kieSession = Util.buildContainer(droolsTemplate, pair.a.getControlLoop().getControlLoopName(),
- policyScope, policyName, policyVersion, URLEncoder.encode(pair.b, "UTF-8"));
+ final KieSession kieSession = Util.buildContainer(droolsTemplate,
+ pair.first.getControlLoop().getControlLoopName(),
+ policyScope, policyName, policyVersion, URLEncoder.encode(pair.second, "UTF-8"));
/*
* Retrieve the Policy Engine
*/
logger.debug("============");
- logger.debug(URLEncoder.encode(pair.b, "UTF-8"));
+ logger.debug(URLEncoder.encode(pair.second, "UTF-8"));
logger.debug("============");
return kieSession;
@@ -362,10 +370,10 @@ public class VDNSControlLoopTest implements TopicListener {
* @param requestID the requestId for this event
* @param status could be onset or abated
*/
- protected void sendEvent(ControlLoopPolicy policy, UUID requestID, ControlLoopEventStatus status) {
+ protected void sendEvent(ControlLoopPolicy policy, UUID requestId, ControlLoopEventStatus status) {
VirtualControlLoopEvent event = new VirtualControlLoopEvent();
event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
- event.setRequestId(requestID);
+ event.setRequestId(requestId);
event.setTarget("vserver.vserver-name");
event.setClosedLoopAlarmStart(Instant.now());
event.setAai(new HashMap<>());
@@ -376,11 +384,11 @@ public class VDNSControlLoopTest implements TopicListener {
kieSession.insert(event);
}
- protected void sendEvent(ControlLoopPolicy policy, UUID requestID, ControlLoopEventStatus status,
+ protected void sendEvent(ControlLoopPolicy policy, UUID requestId, ControlLoopEventStatus status,
String vserverName) {
VirtualControlLoopEvent event = new VirtualControlLoopEvent();
event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
- event.setRequestId(requestID);
+ event.setRequestId(requestId);
event.setTarget("vserver.vserver-name");
event.setClosedLoopAlarmStart(Instant.now());
event.setAai(new HashMap<>());
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFCControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfcControlLoopTest.java
index 6f11bc65c..449a90fe0 100644
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFCControlLoopTest.java
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfcControlLoopTest.java
@@ -3,6 +3,7 @@
* demo
* ================================================================================
* Copyright (C) 2017-2018 Intel Corp. All rights reserved.
+ * Modifications Copyright (C) 2018 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.
@@ -60,25 +61,28 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class VFCControlLoopTest implements TopicListener {
+public class VfcControlLoopTest implements TopicListener {
- private static final Logger logger = LoggerFactory.getLogger(VFCControlLoopTest.class);
+ private static final Logger logger = LoggerFactory.getLogger(VfcControlLoopTest.class);
private static List<? extends TopicSink> noopTopics;
private static KieSession kieSession;
private static Util.Pair<ControlLoopPolicy, String> pair;
- private UUID requestID;
+ private UUID requestId;
static {
/* Set environment properties */
- Util.setAAIProps();
- Util.setVFCProps();
+ Util.setAaiProps();
+ Util.setVfcProps();
Util.setGuardProps();
- Util.setPUProp();
+ Util.setPuProp();
LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "INFO");
}
+ /**
+ * Setup the simulator.
+ */
@BeforeClass
public static void setUpSimulator() {
PolicyEngine.manager.configure(new Properties());
@@ -108,7 +112,8 @@ public class VFCControlLoopTest implements TopicListener {
*/
try {
kieSession = startSession(
- "../archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl",
+ "../archetype-cl-amsterdam/src/main/resources/archetype-resources/"
+ + "src/main/resources/__closedLoopControlName__.drl",
"src/test/resources/yaml/policy_ControlLoop_VFC.yaml", "type=operational", "CL_VoLTE", "v2.0");
} catch (IOException e) {
e.printStackTrace();
@@ -117,6 +122,9 @@ public class VFCControlLoopTest implements TopicListener {
}
}
+ /**
+ * Tear down the simulator.
+ */
@AfterClass
public static void tearDownSimulator() {
@@ -146,13 +154,13 @@ public class VFCControlLoopTest implements TopicListener {
/*
* Create a unique requestId
*/
- requestID = UUID.randomUUID();
+ requestId = UUID.randomUUID();
/*
* Simulate an onset event the policy engine will receive from DCAE to kick off processing
* through the rules
*/
- sendEvent(pair.a, requestID, ControlLoopEventStatus.ONSET);
+ sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET);
kieSession.fireUntilHalt();
@@ -182,7 +190,7 @@ public class VFCControlLoopTest implements TopicListener {
/*
* Create a unique requestId
*/
- requestID = UUID.randomUUID();
+ requestId = UUID.randomUUID();
/*
* Simulate an onset event the policy engine will receive from DCAE to kick off processing
@@ -190,7 +198,7 @@ public class VFCControlLoopTest implements TopicListener {
*/
VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- event.setClosedLoopControlName(pair.a.getControlLoop().getControlLoopName());
+ event.setClosedLoopControlName(pair.first.getControlLoop().getControlLoopName());
event.setRequestId(UUID.randomUUID());
event.setClosedLoopEventClient("tca.instance00009");
event.setTargetType(ControlLoopTargetType.VM);
@@ -224,7 +232,7 @@ public class VFCControlLoopTest implements TopicListener {
* @param policyName name of the policy
* @param policyVersion version of the policy
* @return the kieSession to be used to insert facts
- * @throws IOException
+ * @throws IOException IO Exception
*/
private static KieSession startSession(String droolsTemplate, String yamlFile, String policyScope,
String policyName, String policyVersion) throws IOException {
@@ -234,23 +242,24 @@ public class VFCControlLoopTest implements TopicListener {
*/
pair = Util.loadYaml(yamlFile);
assertNotNull(pair);
- assertNotNull(pair.a);
- assertNotNull(pair.a.getControlLoop());
- assertNotNull(pair.a.getControlLoop().getControlLoopName());
- assertTrue(pair.a.getControlLoop().getControlLoopName().length() > 0);
+ assertNotNull(pair.first);
+ assertNotNull(pair.first.getControlLoop());
+ assertNotNull(pair.first.getControlLoop().getControlLoopName());
+ assertTrue(pair.first.getControlLoop().getControlLoopName().length() > 0);
/*
* Construct a kie session
*/
- final KieSession kieSession = Util.buildContainer(droolsTemplate, pair.a.getControlLoop().getControlLoopName(),
- policyScope, policyName, policyVersion, URLEncoder.encode(pair.b, "UTF-8"));
+ final KieSession kieSession = Util.buildContainer(droolsTemplate,
+ pair.first.getControlLoop().getControlLoopName(),
+ policyScope, policyName, policyVersion, URLEncoder.encode(pair.second, "UTF-8"));
/*
* Retrieve the Policy Engine
*/
logger.debug("============");
- logger.debug(URLEncoder.encode(pair.b, "UTF-8"));
+ logger.debug(URLEncoder.encode(pair.second, "UTF-8"));
logger.debug("============");
return kieSession;
@@ -331,7 +340,7 @@ public class VFCControlLoopTest implements TopicListener {
* @param requestID the requestId for this event
* @param status could be onset or abated
*/
- protected void sendEvent(ControlLoopPolicy policy, UUID requestID, ControlLoopEventStatus status) {
+ protected void sendEvent(ControlLoopPolicy policy, UUID requestId, ControlLoopEventStatus status) {
VirtualControlLoopEvent event = new VirtualControlLoopEvent();
event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
event.setRequestId(UUID.randomUUID());
@@ -351,6 +360,11 @@ public class VFCControlLoopTest implements TopicListener {
kieSession.insert(event);
}
+ /**
+ * Dumps the kie session facts.
+ *
+ * @param kieSession input session
+ */
public static void dumpFacts(KieSession kieSession) {
logger.debug("Fact Count: " + kieSession.getFactCount());
for (FactHandle handle : kieSession.getFactHandles()) {
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfwControlLoopTest.java
index 756fb202f..b06f4c695 100644
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfwControlLoopTest.java
@@ -60,24 +60,27 @@ import org.onap.policy.drools.utils.logging.LoggerUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class VFWControlLoopTest implements TopicListener {
+public class VfwControlLoopTest implements TopicListener {
- private static final Logger logger = LoggerFactory.getLogger(VFWControlLoopTest.class);
+ private static final Logger logger = LoggerFactory.getLogger(VfwControlLoopTest.class);
private static List<? extends TopicSink> noopTopics;
private static KieSession kieSession;
private static Util.Pair<ControlLoopPolicy, String> pair;
- private UUID requestID;
+ private UUID requestId;
static {
/* Set environment properties */
- Util.setAAIProps();
+ Util.setAaiProps();
Util.setGuardProps();
- Util.setPUProp();
+ Util.setPuProp();
LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "INFO");
}
+ /**
+ * Setup the simulator.
+ */
@BeforeClass
public static void setUpSimulator() {
PolicyEngine.manager.configure(new Properties());
@@ -111,7 +114,8 @@ public class VFWControlLoopTest implements TopicListener {
*/
try {
kieSession = startSession(
- "../archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl",
+ "../archetype-cl-amsterdam/src/main/resources/archetype-resources/src/"
+ + "main/resources/__closedLoopControlName__.drl",
"src/test/resources/yaml/policy_ControlLoop_vFW.yaml",
"service=ServiceDemo;resource=Res1Demo;type=operational", "CL_vFW",
"org.onap.closed_loop.ServiceDemo:VNFS:1.0.0");
@@ -122,6 +126,9 @@ public class VFWControlLoopTest implements TopicListener {
}
}
+ /**
+ * Tear down the simulator.
+ */
@AfterClass
public static void tearDownSimulator() {
/*
@@ -150,13 +157,13 @@ public class VFWControlLoopTest implements TopicListener {
/*
* Create a unique requestId
*/
- requestID = UUID.randomUUID();
+ requestId = UUID.randomUUID();
/*
* Simulate an onset event the policy engine will receive from DCAE to kick off processing
* through the rules
*/
- sendEvent(pair.a, requestID, ControlLoopEventStatus.ONSET);
+ sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET);
try {
kieSession.fireUntilHalt();
@@ -193,13 +200,13 @@ public class VFWControlLoopTest implements TopicListener {
/*
* Create a unique requestId
*/
- requestID = UUID.randomUUID();
+ requestId = UUID.randomUUID();
/*
* Simulate an onset event the policy engine will receive from DCAE to kick off processing
* through the rules
*/
- sendEvent(pair.a, requestID, ControlLoopEventStatus.ONSET, "error");
+ sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET, "error");
try {
kieSession.fireUntilHalt();
} catch (Exception e) {
@@ -221,14 +228,14 @@ public class VFWControlLoopTest implements TopicListener {
/*
* Create a unique requestId
*/
- requestID = UUID.randomUUID();
+ requestId = UUID.randomUUID();
/*
* Simulate an onset event the policy engine will receive from DCAE to kick off processing
* through the rules
*/
- sendEvent(pair.a, requestID, ControlLoopEventStatus.ONSET, "getFail");
+ sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET, "getFail");
try {
kieSession.fireUntilHalt();
@@ -258,7 +265,7 @@ public class VFWControlLoopTest implements TopicListener {
* @param policyName name of the policy
* @param policyVersion version of the policy
* @return the kieSession to be used to insert facts
- * @throws IOException
+ * @throws IOException IO Exception
*/
private static KieSession startSession(String droolsTemplate, String yamlFile, String policyScope,
String policyName, String policyVersion) throws IOException {
@@ -268,23 +275,24 @@ public class VFWControlLoopTest implements TopicListener {
*/
pair = Util.loadYaml(yamlFile);
assertNotNull(pair);
- assertNotNull(pair.a);
- assertNotNull(pair.a.getControlLoop());
- assertNotNull(pair.a.getControlLoop().getControlLoopName());
- assertTrue(pair.a.getControlLoop().getControlLoopName().length() > 0);
+ assertNotNull(pair.first);
+ assertNotNull(pair.first.getControlLoop());
+ assertNotNull(pair.first.getControlLoop().getControlLoopName());
+ assertTrue(pair.first.getControlLoop().getControlLoopName().length() > 0);
/*
* Construct a kie session
*/
- final KieSession kieSession = Util.buildContainer(droolsTemplate, pair.a.getControlLoop().getControlLoopName(),
- policyScope, policyName, policyVersion, URLEncoder.encode(pair.b, "UTF-8"));
+ final KieSession kieSession = Util.buildContainer(droolsTemplate,
+ pair.first.getControlLoop().getControlLoopName(),
+ policyScope, policyName, policyVersion, URLEncoder.encode(pair.second, "UTF-8"));
/*
* Retrieve the Policy Engine
*/
logger.debug("============");
- logger.debug(URLEncoder.encode(pair.b, "UTF-8"));
+ logger.debug(URLEncoder.encode(pair.second, "UTF-8"));
logger.debug("============");
return kieSession;
@@ -339,7 +347,7 @@ public class VFWControlLoopTest implements TopicListener {
assertTrue(ControlLoopNotificationType.OPERATION_SUCCESS.equals(notification.getNotification()));
assertNotNull(notification.getMessage());
assertTrue(notification.getMessage().startsWith("actor=APPC"));
- sendEvent(pair.a, requestID, ControlLoopEventStatus.ABATED);
+ sendEvent(pair.first, requestId, ControlLoopEventStatus.ABATED);
} else if (policyName.endsWith("EVENT.MANAGER")) {
logger.debug("Rule Fired: " + notification.getPolicyName());
if ("error".equals(notification.getAai().get("generic-vnf.vnf-name"))) {
@@ -381,10 +389,10 @@ public class VFWControlLoopTest implements TopicListener {
* @param requestID the requestId for this event
* @param status could be onset or abated
*/
- protected void sendEvent(ControlLoopPolicy policy, UUID requestID, ControlLoopEventStatus status) {
+ protected void sendEvent(ControlLoopPolicy policy, UUID requestId, ControlLoopEventStatus status) {
VirtualControlLoopEvent event = new VirtualControlLoopEvent();
event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
- event.setRequestId(requestID);
+ event.setRequestId(requestId);
event.setTarget("generic-vnf.vnf-name");
event.setClosedLoopAlarmStart(Instant.now());
event.setAai(new HashMap<>());
@@ -401,10 +409,10 @@ public class VFWControlLoopTest implements TopicListener {
* @param requestID the requestId for this event
* @param status could be onset or abated
*/
- protected void sendEvent(ControlLoopPolicy policy, UUID requestID, ControlLoopEventStatus status, String vnfId) {
+ protected void sendEvent(ControlLoopPolicy policy, UUID requestId, ControlLoopEventStatus status, String vnfId) {
VirtualControlLoopEvent event = new VirtualControlLoopEvent();
event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
- event.setRequestId(requestID);
+ event.setRequestId(requestId);
event.setTarget("generic-vnf.vnf-name");
event.setClosedLoopAlarmStart(Instant.now());
event.setAai(new HashMap<>());
diff --git a/controlloop/templates/template.demo/src/test/resources/META-INF/persistence.xml b/controlloop/templates/template.demo/src/test/resources/META-INF/persistence.xml
index ec956a274..808cef9b6 100644
--- a/controlloop/templates/template.demo/src/test/resources/META-INF/persistence.xml
+++ b/controlloop/templates/template.demo/src/test/resources/META-INF/persistence.xml
@@ -19,23 +19,30 @@
============LICENSE_END=========================================================
-->
<persistence version="2.1"
- xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
+ xmlns="http://xmlns.jcp.org/xml/ns/persistence"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
- <!-- In-mem DB for junit -->
- <persistence-unit name="TestOperationsHistoryPU"
- transaction-type="RESOURCE_LOCAL">
- <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
- <class>org.onap.policy.controlloop.eventmanager.OperationsHistoryDbEntry</class>
- <properties>
- <property name="eclipselink.ddl-generation" value="create-tables" />
- <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
- <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test" />
- <property name="javax.persistence.jdbc.user" value="sa" />
- <property name="javax.persistence.jdbc.password" value="" />
- <property name="eclipselink.logging.level" value="CONFIG" />
- </properties>
- </persistence-unit>
+ <!-- In-mem DB for junit -->
+ <persistence-unit name="TestOperationsHistoryPU"
+ transaction-type="RESOURCE_LOCAL">
+ <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
+ <class>org.onap.policy.controlloop.eventmanager.OperationsHistoryDbEntry</class>
+ <properties>
+ <property name="eclipselink.ddl-generation"
+ value="create-tables" />
+ <property name="javax.persistence.jdbc.driver"
+ value="org.h2.Driver" />
+ <property name="javax.persistence.jdbc.url"
+ value="jdbc:h2:mem:test" />
+ <property name="javax.persistence.jdbc.user"
+ value="sa" />
+ <property name="javax.persistence.jdbc.password"
+ value="" />
+ <property name="eclipselink.logging.level"
+ value="CONFIG" />
+ </properties>
+ </persistence-unit>
</persistence>