summaryrefslogtreecommitdiffstats
path: root/controlloop/common/policy-yaml/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'controlloop/common/policy-yaml/src/main')
-rw-r--r--controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/Constraint.java324
-rw-r--r--controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuard.java186
-rw-r--r--controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/Guard.java136
-rw-r--r--controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/GuardPolicy.java330
-rw-r--r--controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/MatchParameters.java270
-rw-r--r--controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/builder/impl/ControlLoopGuardBuilderImpl.java494
6 files changed, 870 insertions, 870 deletions
diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/Constraint.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/Constraint.java
index 96c277b26..3ebf7013e 100644
--- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/Constraint.java
+++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/Constraint.java
@@ -1,162 +1,162 @@
-/*-
- * ============LICENSE_START=======================================================
- * policy-yaml
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.controlloop.policy.guard;
-
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-public class Constraint {
-
- private Integer freqLimitPerTarget;
- private Map<String,String> timeWindow;
- private Map<String, String> activeTimeRange;
-
- private List<String> blacklist;
-
- public Constraint() {
- // Do Nothing empty constructor.
- }
-
- public Integer getFreq_limit_per_target() {
- return freqLimitPerTarget;
- }
-
-
- public void setFreq_limit_per_target(Integer freqLimitPerTarget) {
- this.freqLimitPerTarget = freqLimitPerTarget;
- }
-
-
- public Map<String, String> getTime_window() {
- return timeWindow;
- }
-
-
- public void setTime_window(Map<String, String> timeWindow) {
- this.timeWindow = timeWindow;
- }
-
-
- public Map<String, String> getActive_time_range() {
- return activeTimeRange;
- }
-
-
- public void setActive_time_range(Map<String, String> activeTimeRange) {
- this.activeTimeRange = activeTimeRange;
- }
-
-
- public List<String> getBlacklist() {
- return blacklist;
- }
-
- public void setBlacklist(List<String> blacklist) {
- this.blacklist = blacklist;
- }
-
- public Constraint(Integer freqLimitPerTarget, Map<String, String> timeWindow) {
- this.freqLimitPerTarget = freqLimitPerTarget;
- if(timeWindow!=null){
- this.timeWindow = Collections.unmodifiableMap(timeWindow);
- }
- }
-
- public Constraint(List<String> blacklist) {
- this.blacklist = new LinkedList<>(blacklist);
- }
-
- public Constraint(Integer freqLimitPerTarget, Map<String, String> timeWindow, List<String> blacklist) {
- this.freqLimitPerTarget = freqLimitPerTarget;
- this.timeWindow = Collections.unmodifiableMap(timeWindow);
- this.blacklist = new LinkedList<>(blacklist);
- }
-
- public Constraint(Integer freqLimitPerTarget, Map<String, String> timeWindow, Map<String, String> activeTimeRange) {
- this(freqLimitPerTarget, timeWindow);
- if (activeTimeRange != null) {
- this.activeTimeRange = Collections.unmodifiableMap(activeTimeRange);
- }
- }
-
- public Constraint(Integer freqLimitPerTarget, Map<String, String> timeWindow, Map<String, String> activeTimeRange, List<String> blacklist) {
- this(freqLimitPerTarget, timeWindow);
- if (activeTimeRange != null) {
- this.activeTimeRange = Collections.unmodifiableMap(activeTimeRange);
- }
- if(blacklist!=null){
- this.blacklist = new LinkedList<>(blacklist);
- }
- }
-
- public Constraint(Constraint constraint) {
- this.freqLimitPerTarget = constraint.freqLimitPerTarget;
- this.timeWindow = constraint.timeWindow;
- if (constraint.activeTimeRange != null) {
- this.activeTimeRange = Collections.unmodifiableMap(constraint.activeTimeRange);
- }
- this.blacklist = new LinkedList<>(constraint.blacklist);
- }
-
- public boolean isValid() {
- return ((freqLimitPerTarget == null && timeWindow != null)|| (timeWindow == null && freqLimitPerTarget != null))? false : true;
- }
-
- @Override
- public String toString() {
- return "Constraint [freq_limit_per_target=" + freqLimitPerTarget + ", time_window=" + timeWindow + ", active_time_range=" + activeTimeRange + ", blacklist=" + blacklist + "]";
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((freqLimitPerTarget == null) ? 0 : freqLimitPerTarget.hashCode());
- result = prime * result + ((timeWindow == null) ? 0 : timeWindow.hashCode());
- result = prime * result + ((activeTimeRange == null) ? 0 : activeTimeRange.hashCode());
- result = prime * result + ((blacklist == null) ? 0 : blacklist.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- Constraint other = (Constraint) obj;
- return equalsMayBeNull(freqLimitPerTarget, other.freqLimitPerTarget)
- && equalsMayBeNull(timeWindow, other.timeWindow)
- && equalsMayBeNull(activeTimeRange, other.activeTimeRange)
- && equalsMayBeNull(blacklist, other.blacklist);
- }
-
- private boolean equalsMayBeNull(final Object obj1, final Object obj2){
- if ( obj1 == null ) {
- return obj2 == null;
- }
- return obj1.equals(obj2);
- }
-}
+/*-
+ * ============LICENSE_START=======================================================
+ * policy-yaml
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.controlloop.policy.guard;
+
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+public class Constraint {
+
+ private Integer freqLimitPerTarget;
+ private Map<String,String> timeWindow;
+ private Map<String, String> activeTimeRange;
+
+ private List<String> blacklist;
+
+ public Constraint() {
+ // Do Nothing empty constructor.
+ }
+
+ public Integer getFreq_limit_per_target() {
+ return freqLimitPerTarget;
+ }
+
+
+ public void setFreq_limit_per_target(Integer freqLimitPerTarget) {
+ this.freqLimitPerTarget = freqLimitPerTarget;
+ }
+
+
+ public Map<String, String> getTime_window() {
+ return timeWindow;
+ }
+
+
+ public void setTime_window(Map<String, String> timeWindow) {
+ this.timeWindow = timeWindow;
+ }
+
+
+ public Map<String, String> getActive_time_range() {
+ return activeTimeRange;
+ }
+
+
+ public void setActive_time_range(Map<String, String> activeTimeRange) {
+ this.activeTimeRange = activeTimeRange;
+ }
+
+
+ public List<String> getBlacklist() {
+ return blacklist;
+ }
+
+ public void setBlacklist(List<String> blacklist) {
+ this.blacklist = blacklist;
+ }
+
+ public Constraint(Integer freqLimitPerTarget, Map<String, String> timeWindow) {
+ this.freqLimitPerTarget = freqLimitPerTarget;
+ if(timeWindow!=null){
+ this.timeWindow = Collections.unmodifiableMap(timeWindow);
+ }
+ }
+
+ public Constraint(List<String> blacklist) {
+ this.blacklist = new LinkedList<>(blacklist);
+ }
+
+ public Constraint(Integer freqLimitPerTarget, Map<String, String> timeWindow, List<String> blacklist) {
+ this.freqLimitPerTarget = freqLimitPerTarget;
+ this.timeWindow = Collections.unmodifiableMap(timeWindow);
+ this.blacklist = new LinkedList<>(blacklist);
+ }
+
+ public Constraint(Integer freqLimitPerTarget, Map<String, String> timeWindow, Map<String, String> activeTimeRange) {
+ this(freqLimitPerTarget, timeWindow);
+ if (activeTimeRange != null) {
+ this.activeTimeRange = Collections.unmodifiableMap(activeTimeRange);
+ }
+ }
+
+ public Constraint(Integer freqLimitPerTarget, Map<String, String> timeWindow, Map<String, String> activeTimeRange, List<String> blacklist) {
+ this(freqLimitPerTarget, timeWindow);
+ if (activeTimeRange != null) {
+ this.activeTimeRange = Collections.unmodifiableMap(activeTimeRange);
+ }
+ if(blacklist!=null){
+ this.blacklist = new LinkedList<>(blacklist);
+ }
+ }
+
+ public Constraint(Constraint constraint) {
+ this.freqLimitPerTarget = constraint.freqLimitPerTarget;
+ this.timeWindow = constraint.timeWindow;
+ if (constraint.activeTimeRange != null) {
+ this.activeTimeRange = Collections.unmodifiableMap(constraint.activeTimeRange);
+ }
+ this.blacklist = new LinkedList<>(constraint.blacklist);
+ }
+
+ public boolean isValid() {
+ return ((freqLimitPerTarget == null && timeWindow != null)|| (timeWindow == null && freqLimitPerTarget != null))? false : true;
+ }
+
+ @Override
+ public String toString() {
+ return "Constraint [freq_limit_per_target=" + freqLimitPerTarget + ", time_window=" + timeWindow + ", active_time_range=" + activeTimeRange + ", blacklist=" + blacklist + "]";
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((freqLimitPerTarget == null) ? 0 : freqLimitPerTarget.hashCode());
+ result = prime * result + ((timeWindow == null) ? 0 : timeWindow.hashCode());
+ result = prime * result + ((activeTimeRange == null) ? 0 : activeTimeRange.hashCode());
+ result = prime * result + ((blacklist == null) ? 0 : blacklist.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Constraint other = (Constraint) obj;
+ return equalsMayBeNull(freqLimitPerTarget, other.freqLimitPerTarget)
+ && equalsMayBeNull(timeWindow, other.timeWindow)
+ && equalsMayBeNull(activeTimeRange, other.activeTimeRange)
+ && equalsMayBeNull(blacklist, other.blacklist);
+ }
+
+ private boolean equalsMayBeNull(final Object obj1, final Object obj2){
+ if ( obj1 == null ) {
+ return obj2 == null;
+ }
+ return obj1.equals(obj2);
+ }
+}
diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuard.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuard.java
index 7c90801ec..6fb0ca9f0 100644
--- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuard.java
+++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/ControlLoopGuard.java
@@ -1,93 +1,93 @@
-/*-
- * ============LICENSE_START=======================================================
- * policy-yaml
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.controlloop.policy.guard;
-
-import java.util.LinkedList;
-
-public class ControlLoopGuard {
-
- private Guard guard;
-
- private LinkedList<GuardPolicy> guards;
-
- public ControlLoopGuard() {
- //DO Nothing Empty Constructor
- }
-
- public Guard getGuard() {
- return guard;
- }
-
- public void setGuard(Guard guard) {
- this.guard = guard;
- }
-
- public LinkedList<GuardPolicy> getGuards() {
- return guards;
- }
-
- public void setGuards(LinkedList<GuardPolicy> guards) {
- this.guards = guards;
- }
-
- public ControlLoopGuard(ControlLoopGuard cLGuard) {
- this.guard = new Guard();
- this.guards = new LinkedList<>(cLGuard.guards);
- }
-
- @Override
- public String toString() {
- return "Guard [guard=" + guard + ", GuardPolicies=" + guards + "]";
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((guard == null) ? 0 : guard.hashCode());
- result = prime * result + ((guards == null) ? 0 : guards.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- ControlLoopGuard other = (ControlLoopGuard) obj;
- if (guard == null) {
- if (other.guard != null)
- return false;
- } else if (!guard.equals(other.guard))
- return false;
- if (guards == null) {
- if (other.guards != null)
- return false;
- } else if (!guards.equals(other.guards))
- return false;
- return true;
- }
-
-
-}
+/*-
+ * ============LICENSE_START=======================================================
+ * policy-yaml
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.controlloop.policy.guard;
+
+import java.util.LinkedList;
+
+public class ControlLoopGuard {
+
+ private Guard guard;
+
+ private LinkedList<GuardPolicy> guards;
+
+ public ControlLoopGuard() {
+ //DO Nothing Empty Constructor
+ }
+
+ public Guard getGuard() {
+ return guard;
+ }
+
+ public void setGuard(Guard guard) {
+ this.guard = guard;
+ }
+
+ public LinkedList<GuardPolicy> getGuards() {
+ return guards;
+ }
+
+ public void setGuards(LinkedList<GuardPolicy> guards) {
+ this.guards = guards;
+ }
+
+ public ControlLoopGuard(ControlLoopGuard cLGuard) {
+ this.guard = new Guard();
+ this.guards = new LinkedList<>(cLGuard.guards);
+ }
+
+ @Override
+ public String toString() {
+ return "Guard [guard=" + guard + ", GuardPolicies=" + guards + "]";
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((guard == null) ? 0 : guard.hashCode());
+ result = prime * result + ((guards == null) ? 0 : guards.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ControlLoopGuard other = (ControlLoopGuard) obj;
+ if (guard == null) {
+ if (other.guard != null)
+ return false;
+ } else if (!guard.equals(other.guard))
+ return false;
+ if (guards == null) {
+ if (other.guards != null)
+ return false;
+ } else if (!guards.equals(other.guards))
+ return false;
+ return true;
+ }
+
+
+}
diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/Guard.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/Guard.java
index dedc9a076..291004611 100644
--- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/Guard.java
+++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/Guard.java
@@ -1,68 +1,68 @@
-/*-
- * ============LICENSE_START=======================================================
- * policy-yaml
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.controlloop.policy.guard;
-
-public class Guard {
-
- private static final String DEFAULTVERSION = "2.0.0";
-
- private String version = DEFAULTVERSION;
-
- public Guard() {
- //DO Nothing empty Constructor.
- }
-
- public String getVersion() {
- return version;
- }
-
- public void setVersion(String version) {
- this.version = version;
- }
-
- @Override
- public String toString() {
- return "Guard [version=" + version + "]";
- }
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((version == null) ? 0 : version.hashCode());
- return result;
- }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- Guard other = (Guard) obj;
- if (version == null) {
- if (other.version != null)
- return false;
- } else if (!version.equals(other.version))
- return false;
- return true;
- }
-}
+/*-
+ * ============LICENSE_START=======================================================
+ * policy-yaml
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.controlloop.policy.guard;
+
+public class Guard {
+
+ private static final String DEFAULTVERSION = "2.0.0";
+
+ private String version = DEFAULTVERSION;
+
+ public Guard() {
+ //DO Nothing empty Constructor.
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ @Override
+ public String toString() {
+ return "Guard [version=" + version + "]";
+ }
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((version == null) ? 0 : version.hashCode());
+ return result;
+ }
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Guard other = (Guard) obj;
+ if (version == null) {
+ if (other.version != null)
+ return false;
+ } else if (!version.equals(other.version))
+ return false;
+ return true;
+ }
+}
diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/GuardPolicy.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/GuardPolicy.java
index 16a384a56..c45014c3c 100644
--- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/GuardPolicy.java
+++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/GuardPolicy.java
@@ -1,165 +1,165 @@
-/*-
- * ============LICENSE_START=======================================================
- * policy-yaml
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.controlloop.policy.guard;
-
-import java.util.LinkedList;
-import java.util.List;
-import java.util.UUID;
-
-public class GuardPolicy {
-
- private String id = UUID.randomUUID().toString();
- private String name;
- private String description;
- private MatchParameters matchParameters;
- private LinkedList<Constraint> limitConstraints;
-
- public GuardPolicy() {
- //Do Nothing Empty Constructor.
- }
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public MatchParameters getMatch_parameters() {
- return matchParameters;
- }
-
- public void setMatch_parameters(MatchParameters matchParameters) {
- this.matchParameters = matchParameters;
- }
-
- public LinkedList<Constraint> getLimit_constraints() {
- return limitConstraints;
- }
-
- public void setLimit_constraints(LinkedList<Constraint> limitConstraints) {
- this.limitConstraints = limitConstraints;
- }
-
- public GuardPolicy(String id) {
- this.id = id;
- }
-
- public GuardPolicy(String name, MatchParameters matchParameters) {
- this.name = name;
- this.matchParameters = matchParameters;
- }
-
- public GuardPolicy(String id, String name, String description, MatchParameters matchParameters) {
- this(name, matchParameters);
- this.id = id;
- this.description = description;
- }
-
- public GuardPolicy(String name, MatchParameters matchParameters, List<Constraint> limitConstraints) {
- this(name, matchParameters);
- if (limitConstraints != null) {
- this.limitConstraints = (LinkedList<Constraint>) limitConstraints;
- }
- }
-
- public GuardPolicy(String name, String description, MatchParameters matchParameters, List<Constraint> limitConstraints) {
- this(name, matchParameters, limitConstraints);
- this.description = description;
- }
-
- public GuardPolicy(String id, String name, String description, MatchParameters matchParameters, List<Constraint> limitConstraints) {
- this(name, description, matchParameters, limitConstraints);
- this.id = id;
- }
-
- public GuardPolicy(GuardPolicy policy) {
- this.id = policy.id;
- this.name = policy.name;
- this.description = policy.description;
- this.matchParameters = new MatchParameters(policy.matchParameters);
- if (policy.limitConstraints != null) {
- this.limitConstraints = policy.limitConstraints;
- }
- }
-
- public boolean isValid() {
- return (id==null || name ==null)? false : true;
- }
-
- @Override
- public String toString() {
- return "Policy [id=" + id + ", name=" + name + ", description=" + description + ", match_parameters="
- +matchParameters + ", limitConstraints=" + limitConstraints + "]";
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((description == null) ? 0 : description.hashCode());
- result = prime * result + ((id == null) ? 0 : id.hashCode());
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result + ((limitConstraints == null) ? 0 : limitConstraints.hashCode());
- result = prime * result + ((matchParameters == null) ? 0 : matchParameters.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- GuardPolicy other = (GuardPolicy) obj;
- return equalsMayBeNull(description, other.description)
- && equalsMayBeNull(id, other.id)
- && equalsMayBeNull(name, other.name)
- && equalsMayBeNull(limitConstraints, other.limitConstraints)
- && equalsMayBeNull(matchParameters, other.matchParameters);
- }
-
- private boolean equalsMayBeNull(final Object obj1, final Object obj2){
- if ( obj1 == null ) {
- return obj2 == null;
- }
- return obj1.equals(obj2);
- }
-}
+/*-
+ * ============LICENSE_START=======================================================
+ * policy-yaml
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.controlloop.policy.guard;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.UUID;
+
+public class GuardPolicy {
+
+ private String id = UUID.randomUUID().toString();
+ private String name;
+ private String description;
+ private MatchParameters matchParameters;
+ private LinkedList<Constraint> limitConstraints;
+
+ public GuardPolicy() {
+ //Do Nothing Empty Constructor.
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public MatchParameters getMatch_parameters() {
+ return matchParameters;
+ }
+
+ public void setMatch_parameters(MatchParameters matchParameters) {
+ this.matchParameters = matchParameters;
+ }
+
+ public LinkedList<Constraint> getLimit_constraints() {
+ return limitConstraints;
+ }
+
+ public void setLimit_constraints(LinkedList<Constraint> limitConstraints) {
+ this.limitConstraints = limitConstraints;
+ }
+
+ public GuardPolicy(String id) {
+ this.id = id;
+ }
+
+ public GuardPolicy(String name, MatchParameters matchParameters) {
+ this.name = name;
+ this.matchParameters = matchParameters;
+ }
+
+ public GuardPolicy(String id, String name, String description, MatchParameters matchParameters) {
+ this(name, matchParameters);
+ this.id = id;
+ this.description = description;
+ }
+
+ public GuardPolicy(String name, MatchParameters matchParameters, List<Constraint> limitConstraints) {
+ this(name, matchParameters);
+ if (limitConstraints != null) {
+ this.limitConstraints = (LinkedList<Constraint>) limitConstraints;
+ }
+ }
+
+ public GuardPolicy(String name, String description, MatchParameters matchParameters, List<Constraint> limitConstraints) {
+ this(name, matchParameters, limitConstraints);
+ this.description = description;
+ }
+
+ public GuardPolicy(String id, String name, String description, MatchParameters matchParameters, List<Constraint> limitConstraints) {
+ this(name, description, matchParameters, limitConstraints);
+ this.id = id;
+ }
+
+ public GuardPolicy(GuardPolicy policy) {
+ this.id = policy.id;
+ this.name = policy.name;
+ this.description = policy.description;
+ this.matchParameters = new MatchParameters(policy.matchParameters);
+ if (policy.limitConstraints != null) {
+ this.limitConstraints = policy.limitConstraints;
+ }
+ }
+
+ public boolean isValid() {
+ return (id==null || name ==null)? false : true;
+ }
+
+ @Override
+ public String toString() {
+ return "Policy [id=" + id + ", name=" + name + ", description=" + description + ", match_parameters="
+ +matchParameters + ", limitConstraints=" + limitConstraints + "]";
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((description == null) ? 0 : description.hashCode());
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + ((limitConstraints == null) ? 0 : limitConstraints.hashCode());
+ result = prime * result + ((matchParameters == null) ? 0 : matchParameters.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ GuardPolicy other = (GuardPolicy) obj;
+ return equalsMayBeNull(description, other.description)
+ && equalsMayBeNull(id, other.id)
+ && equalsMayBeNull(name, other.name)
+ && equalsMayBeNull(limitConstraints, other.limitConstraints)
+ && equalsMayBeNull(matchParameters, other.matchParameters);
+ }
+
+ private boolean equalsMayBeNull(final Object obj1, final Object obj2){
+ if ( obj1 == null ) {
+ return obj2 == null;
+ }
+ return obj1.equals(obj2);
+ }
+}
diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/MatchParameters.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/MatchParameters.java
index 8e5d0c09c..445e00f38 100644
--- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/MatchParameters.java
+++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/MatchParameters.java
@@ -1,135 +1,135 @@
-/*-
- * ============LICENSE_START=======================================================
- * policy-yaml
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.controlloop.policy.guard;
-
-import java.util.LinkedList;
-import java.util.List;
-
-
-public class MatchParameters {
- private String controlLoopName;
- private String actor;
- private String recipe;
- private List<String> targets;
-
- public MatchParameters() {
- // Do Nothing Empty Constructor.
- }
-
- public String getControlLoopName() {
- return controlLoopName;
- }
-
- public void setControlLoopName(String controlLoopName) {
- this.controlLoopName = controlLoopName;
- }
-
- public String getActor() {
- return actor;
- }
-
- public void setActor(String actor) {
- this.actor = actor;
- }
-
- public String getRecipe() {
- return recipe;
- }
-
- public void setRecipe(String recipe) {
- this.recipe = recipe;
- }
-
- public List<String> getTargets() {
- return targets;
- }
-
- public void setTargets(List<String> targets) {
- this.targets = targets;
- }
-
- public MatchParameters(String actor, String recipe) {
- this.actor = actor;
- this.recipe = recipe;
- }
-
- public MatchParameters(String actor, String recipe, List<String> targets) {
- this(actor, recipe);
- if (targets != null) {
- this.targets = new LinkedList<>(targets);
- }
- }
-
- public MatchParameters(String controlLoopName, String actor, String recipe, List<String> targets) {
- this(actor, recipe, targets);
- this.controlLoopName = controlLoopName;
- }
-
- public MatchParameters(MatchParameters matchParameters) {
-
- this.controlLoopName = matchParameters.controlLoopName;
- this.actor = matchParameters.actor;
- this.recipe = matchParameters.recipe;
- if (matchParameters.targets != null) {
- this.targets = new LinkedList<>(matchParameters.targets);
- }
- }
-
- @Override
- public String toString() {
- return "MatchParameters [controlLoopName=" + controlLoopName + ", actor=" + actor + ", recipe=" + recipe
- + ", targets=" + targets + "]";
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((actor == null) ? 0 : actor.hashCode());
- result = prime * result + ((controlLoopName == null) ? 0 : controlLoopName.hashCode());
- result = prime * result + ((recipe == null) ? 0 : recipe.hashCode());
- result = prime * result + ((targets == null) ? 0 : targets.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- MatchParameters other = (MatchParameters) obj;
-
- return equalsMayBeNull(actor, other.actor)
- && equalsMayBeNull(controlLoopName, other.controlLoopName)
- && equalsMayBeNull(recipe, other.recipe)
- && equalsMayBeNull(targets, other.targets);
- }
-
- private boolean equalsMayBeNull(final Object obj1, final Object obj2){
- if ( obj1 == null ) {
- return obj2 == null;
- }
- return obj1.equals(obj2);
- }
-}
+/*-
+ * ============LICENSE_START=======================================================
+ * policy-yaml
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.controlloop.policy.guard;
+
+import java.util.LinkedList;
+import java.util.List;
+
+
+public class MatchParameters {
+ private String controlLoopName;
+ private String actor;
+ private String recipe;
+ private List<String> targets;
+
+ public MatchParameters() {
+ // Do Nothing Empty Constructor.
+ }
+
+ public String getControlLoopName() {
+ return controlLoopName;
+ }
+
+ public void setControlLoopName(String controlLoopName) {
+ this.controlLoopName = controlLoopName;
+ }
+
+ public String getActor() {
+ return actor;
+ }
+
+ public void setActor(String actor) {
+ this.actor = actor;
+ }
+
+ public String getRecipe() {
+ return recipe;
+ }
+
+ public void setRecipe(String recipe) {
+ this.recipe = recipe;
+ }
+
+ public List<String> getTargets() {
+ return targets;
+ }
+
+ public void setTargets(List<String> targets) {
+ this.targets = targets;
+ }
+
+ public MatchParameters(String actor, String recipe) {
+ this.actor = actor;
+ this.recipe = recipe;
+ }
+
+ public MatchParameters(String actor, String recipe, List<String> targets) {
+ this(actor, recipe);
+ if (targets != null) {
+ this.targets = new LinkedList<>(targets);
+ }
+ }
+
+ public MatchParameters(String controlLoopName, String actor, String recipe, List<String> targets) {
+ this(actor, recipe, targets);
+ this.controlLoopName = controlLoopName;
+ }
+
+ public MatchParameters(MatchParameters matchParameters) {
+
+ this.controlLoopName = matchParameters.controlLoopName;
+ this.actor = matchParameters.actor;
+ this.recipe = matchParameters.recipe;
+ if (matchParameters.targets != null) {
+ this.targets = new LinkedList<>(matchParameters.targets);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "MatchParameters [controlLoopName=" + controlLoopName + ", actor=" + actor + ", recipe=" + recipe
+ + ", targets=" + targets + "]";
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((actor == null) ? 0 : actor.hashCode());
+ result = prime * result + ((controlLoopName == null) ? 0 : controlLoopName.hashCode());
+ result = prime * result + ((recipe == null) ? 0 : recipe.hashCode());
+ result = prime * result + ((targets == null) ? 0 : targets.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ MatchParameters other = (MatchParameters) obj;
+
+ return equalsMayBeNull(actor, other.actor)
+ && equalsMayBeNull(controlLoopName, other.controlLoopName)
+ && equalsMayBeNull(recipe, other.recipe)
+ && equalsMayBeNull(targets, other.targets);
+ }
+
+ private boolean equalsMayBeNull(final Object obj1, final Object obj2){
+ if ( obj1 == null ) {
+ return obj2 == null;
+ }
+ return obj1.equals(obj2);
+ }
+}
diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/builder/impl/ControlLoopGuardBuilderImpl.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/builder/impl/ControlLoopGuardBuilderImpl.java
index 60716383d..a431a0bfe 100644
--- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/builder/impl/ControlLoopGuardBuilderImpl.java
+++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/builder/impl/ControlLoopGuardBuilderImpl.java
@@ -1,247 +1,247 @@
-/*-
- * ============LICENSE_START=======================================================
- * policy-yaml
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.controlloop.policy.guard.builder.impl;
-
-import java.util.LinkedList;
-
-import org.onap.policy.controlloop.compiler.CompilerException;
-import org.onap.policy.controlloop.compiler.ControlLoopCompilerCallback;
-import org.onap.policy.controlloop.guard.compiler.ControlLoopGuardCompiler;
-import org.onap.policy.controlloop.policy.builder.BuilderException;
-import org.onap.policy.controlloop.policy.builder.MessageLevel;
-import org.onap.policy.controlloop.policy.builder.Results;
-import org.onap.policy.controlloop.policy.builder.impl.MessageImpl;
-import org.onap.policy.controlloop.policy.builder.impl.ResultsImpl;
-import org.onap.policy.controlloop.policy.guard.Constraint;
-import org.onap.policy.controlloop.policy.guard.ControlLoopGuard;
-import org.onap.policy.controlloop.policy.guard.Guard;
-import org.onap.policy.controlloop.policy.guard.GuardPolicy;
-import org.onap.policy.controlloop.policy.guard.builder.ControlLoopGuardBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.yaml.snakeyaml.DumperOptions;
-import org.yaml.snakeyaml.DumperOptions.FlowStyle;
-import org.yaml.snakeyaml.Yaml;
-
-public class ControlLoopGuardBuilderImpl implements ControlLoopGuardBuilder {
- private static final String NO_EXISTING_GUARD_POLICY_MATCHING_THE_ID = "No existing guard policy matching the id: ";
- private static final String THE_ID_OF_TARGET_GUARD_POLICY_MUST_NOT_BE_NULL = "The id of target guard policy must not be null";
- private static Logger logger = LoggerFactory.getLogger(ControlLoopGuardBuilderImpl.class.getName());
- private ControlLoopGuard cLGuard;
-
- public ControlLoopGuardBuilderImpl(Guard guard) {
- cLGuard = new ControlLoopGuard();
- cLGuard.setGuard(guard);
- }
-
- @Override
- public ControlLoopGuardBuilder addGuardPolicy(GuardPolicy... policies) throws BuilderException {
- if (policies == null) {
- throw new BuilderException("GuardPolicy must not be null");
- }
- for (GuardPolicy policy : policies) {
- if (!policy.isValid()) {
- throw new BuilderException("Invalid guard policy - some required fields are missing");
- }
- if (cLGuard.getGuards() == null) {
- cLGuard.setGuards(new LinkedList<>());
- }
- cLGuard.getGuards().add(policy);
- }
- return this;
- }
-
- @Override
- public ControlLoopGuardBuilder removeGuardPolicy(GuardPolicy... policies) throws BuilderException {
- if (policies == null) {
- throw new BuilderException("GuardPolicy must not be null");
- }
- if (cLGuard.getGuards() == null) {
- throw new BuilderException("No existing guard policies to remove");
- }
- for (GuardPolicy policy : policies) {
- if (!policy.isValid()) {
- throw new BuilderException("Invalid guard policy - some required fields are missing");
- }
- boolean removed = cLGuard.getGuards().remove(policy);
- if (!removed) {
- throw new BuilderException("Unknown guard policy: " + policy.getName());
- }
- }
- return this;
- }
-
- @Override
- public ControlLoopGuardBuilder removeAllGuardPolicies() throws BuilderException {
- cLGuard.getGuards().clear();
- return this;
- }
-
- @Override
- public ControlLoopGuardBuilder addLimitConstraint(String id, Constraint... constraints) throws BuilderException {
- if (id == null) {
- throw new BuilderException(THE_ID_OF_TARGET_GUARD_POLICY_MUST_NOT_BE_NULL);
- }
- if (constraints == null) {
- throw new BuilderException("Constraint much not be null");
- }
- if (!addLimitConstraints(id,constraints)) {
- throw new BuilderException(NO_EXISTING_GUARD_POLICY_MATCHING_THE_ID + id);
- }
- return this;
- }
-
- private boolean addLimitConstraints(String id, Constraint... constraints) throws BuilderException {
- boolean exist = false;
- for (GuardPolicy policy: cLGuard.getGuards()) {
- //
- // We could have only one guard policy matching the id
- //
- if (policy.getId().equals(id)) {
- exist = true;
- for (Constraint cons: constraints) {
- if (!cons.isValid()) {
- throw new BuilderException("Invalid guard constraint - some required fields are missing");
- }
- if (policy.getLimit_constraints() == null) {
- policy.setLimit_constraints(new LinkedList<>());
- }
- policy.getLimit_constraints().add(cons);
- }
- break;
- }
- }
- return exist;
- }
-
- @Override
- public ControlLoopGuardBuilder removeLimitConstraint(String id, Constraint... constraints) throws BuilderException {
- if (id == null) {
- throw new BuilderException(THE_ID_OF_TARGET_GUARD_POLICY_MUST_NOT_BE_NULL);
- }
- if (constraints == null) {
- throw new BuilderException("Constraint much not be null");
- }
- if (!removeConstraints(id, constraints)) {
- throw new BuilderException(NO_EXISTING_GUARD_POLICY_MATCHING_THE_ID + id);
- }
- return this;
- }
-
- private boolean removeConstraints(String id, Constraint... constraints) throws BuilderException {
- boolean exist = false;
- for (GuardPolicy policy: cLGuard.getGuards()) {
- //
- // We could have only one guard policy matching the id
- //
- if (policy.getId().equals(id)) {
- exist = true;
- for (Constraint cons: constraints) {
- if (!cons.isValid()) {
- throw new BuilderException("Invalid guard constraint - some required fields are missing");
- }
- boolean removed = policy.getLimit_constraints().remove(cons);
- if (!removed) {
- throw new BuilderException("Unknown guard constraint: " + cons);
- }
- }
- break;
- }
- }
- return exist;
- }
-
- @Override
- public ControlLoopGuardBuilder removeAllLimitConstraints(String id) throws BuilderException {
- if (cLGuard.getGuards() == null || cLGuard.getGuards().isEmpty()) {
- throw new BuilderException("No guard policies exist");
- }
- if (id == null) {
- throw new BuilderException(THE_ID_OF_TARGET_GUARD_POLICY_MUST_NOT_BE_NULL);
- }
- boolean exist = false;
- for (GuardPolicy policy: cLGuard.getGuards()) {
- if (policy.getId().equals(id)) {
- exist = true;
- policy.getLimit_constraints().clear();
- }
- }
- if (!exist) {
- throw new BuilderException(NO_EXISTING_GUARD_POLICY_MATCHING_THE_ID + id);
- }
- return this;
- }
-
-
- private class BuilderCompilerCallback implements ControlLoopCompilerCallback {
-
- private ResultsImpl results = new ResultsImpl();
-
- @Override
- public boolean onWarning(String message) {
- results.addMessage(new MessageImpl(message, MessageLevel.WARNING));
- return false;
- }
-
- @Override
- public boolean onError(String message) {
- results.addMessage(new MessageImpl(message, MessageLevel.ERROR));
- return false;
- }
- }
-
- @Override
- public ControlLoopGuard getControlLoopGuard() {
- return new ControlLoopGuard(this.cLGuard);
- }
-
-
- @Override
- public Results buildSpecification() {
- //
- // Dump the specification
- //
- DumperOptions options = new DumperOptions();
- options.setDefaultFlowStyle(FlowStyle.BLOCK);
- options.setPrettyFlow(true);
- Yaml yaml = new Yaml(options);
- String dumpedYaml = yaml.dump(cLGuard);
- //
- // This is our callback class for our compiler
- //
- BuilderCompilerCallback callback = new BuilderCompilerCallback();
- //
- // Compile it
- //
- try {
- ControlLoopGuardCompiler.compile(cLGuard, callback);
- } catch (CompilerException e) {
- logger.error(e.getMessage() + e);
- callback.results.addMessage(new MessageImpl(e.getMessage(), MessageLevel.EXCEPTION));
- }
- //
- // Save the spec
- //
- callback.results.setSpecification(dumpedYaml);
- return callback.results;
- }
-
-}
+/*-
+ * ============LICENSE_START=======================================================
+ * policy-yaml
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.controlloop.policy.guard.builder.impl;
+
+import java.util.LinkedList;
+
+import org.onap.policy.controlloop.compiler.CompilerException;
+import org.onap.policy.controlloop.compiler.ControlLoopCompilerCallback;
+import org.onap.policy.controlloop.guard.compiler.ControlLoopGuardCompiler;
+import org.onap.policy.controlloop.policy.builder.BuilderException;
+import org.onap.policy.controlloop.policy.builder.MessageLevel;
+import org.onap.policy.controlloop.policy.builder.Results;
+import org.onap.policy.controlloop.policy.builder.impl.MessageImpl;
+import org.onap.policy.controlloop.policy.builder.impl.ResultsImpl;
+import org.onap.policy.controlloop.policy.guard.Constraint;
+import org.onap.policy.controlloop.policy.guard.ControlLoopGuard;
+import org.onap.policy.controlloop.policy.guard.Guard;
+import org.onap.policy.controlloop.policy.guard.GuardPolicy;
+import org.onap.policy.controlloop.policy.guard.builder.ControlLoopGuardBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.yaml.snakeyaml.DumperOptions;
+import org.yaml.snakeyaml.DumperOptions.FlowStyle;
+import org.yaml.snakeyaml.Yaml;
+
+public class ControlLoopGuardBuilderImpl implements ControlLoopGuardBuilder {
+ private static final String NO_EXISTING_GUARD_POLICY_MATCHING_THE_ID = "No existing guard policy matching the id: ";
+ private static final String THE_ID_OF_TARGET_GUARD_POLICY_MUST_NOT_BE_NULL = "The id of target guard policy must not be null";
+ private static Logger logger = LoggerFactory.getLogger(ControlLoopGuardBuilderImpl.class.getName());
+ private ControlLoopGuard cLGuard;
+
+ public ControlLoopGuardBuilderImpl(Guard guard) {
+ cLGuard = new ControlLoopGuard();
+ cLGuard.setGuard(guard);
+ }
+
+ @Override
+ public ControlLoopGuardBuilder addGuardPolicy(GuardPolicy... policies) throws BuilderException {
+ if (policies == null) {
+ throw new BuilderException("GuardPolicy must not be null");
+ }
+ for (GuardPolicy policy : policies) {
+ if (!policy.isValid()) {
+ throw new BuilderException("Invalid guard policy - some required fields are missing");
+ }
+ if (cLGuard.getGuards() == null) {
+ cLGuard.setGuards(new LinkedList<>());
+ }
+ cLGuard.getGuards().add(policy);
+ }
+ return this;
+ }
+
+ @Override
+ public ControlLoopGuardBuilder removeGuardPolicy(GuardPolicy... policies) throws BuilderException {
+ if (policies == null) {
+ throw new BuilderException("GuardPolicy must not be null");
+ }
+ if (cLGuard.getGuards() == null) {
+ throw new BuilderException("No existing guard policies to remove");
+ }
+ for (GuardPolicy policy : policies) {
+ if (!policy.isValid()) {
+ throw new BuilderException("Invalid guard policy - some required fields are missing");
+ }
+ boolean removed = cLGuard.getGuards().remove(policy);
+ if (!removed) {
+ throw new BuilderException("Unknown guard policy: " + policy.getName());
+ }
+ }
+ return this;
+ }
+
+ @Override
+ public ControlLoopGuardBuilder removeAllGuardPolicies() throws BuilderException {
+ cLGuard.getGuards().clear();
+ return this;
+ }
+
+ @Override
+ public ControlLoopGuardBuilder addLimitConstraint(String id, Constraint... constraints) throws BuilderException {
+ if (id == null) {
+ throw new BuilderException(THE_ID_OF_TARGET_GUARD_POLICY_MUST_NOT_BE_NULL);
+ }
+ if (constraints == null) {
+ throw new BuilderException("Constraint much not be null");
+ }
+ if (!addLimitConstraints(id,constraints)) {
+ throw new BuilderException(NO_EXISTING_GUARD_POLICY_MATCHING_THE_ID + id);
+ }
+ return this;
+ }
+
+ private boolean addLimitConstraints(String id, Constraint... constraints) throws BuilderException {
+ boolean exist = false;
+ for (GuardPolicy policy: cLGuard.getGuards()) {
+ //
+ // We could have only one guard policy matching the id
+ //
+ if (policy.getId().equals(id)) {
+ exist = true;
+ for (Constraint cons: constraints) {
+ if (!cons.isValid()) {
+ throw new BuilderException("Invalid guard constraint - some required fields are missing");
+ }
+ if (policy.getLimit_constraints() == null) {
+ policy.setLimit_constraints(new LinkedList<>());
+ }
+ policy.getLimit_constraints().add(cons);
+ }
+ break;
+ }
+ }
+ return exist;
+ }
+
+ @Override
+ public ControlLoopGuardBuilder removeLimitConstraint(String id, Constraint... constraints) throws BuilderException {
+ if (id == null) {
+ throw new BuilderException(THE_ID_OF_TARGET_GUARD_POLICY_MUST_NOT_BE_NULL);
+ }
+ if (constraints == null) {
+ throw new BuilderException("Constraint much not be null");
+ }
+ if (!removeConstraints(id, constraints)) {
+ throw new BuilderException(NO_EXISTING_GUARD_POLICY_MATCHING_THE_ID + id);
+ }
+ return this;
+ }
+
+ private boolean removeConstraints(String id, Constraint... constraints) throws BuilderException {
+ boolean exist = false;
+ for (GuardPolicy policy: cLGuard.getGuards()) {
+ //
+ // We could have only one guard policy matching the id
+ //
+ if (policy.getId().equals(id)) {
+ exist = true;
+ for (Constraint cons: constraints) {
+ if (!cons.isValid()) {
+ throw new BuilderException("Invalid guard constraint - some required fields are missing");
+ }
+ boolean removed = policy.getLimit_constraints().remove(cons);
+ if (!removed) {
+ throw new BuilderException("Unknown guard constraint: " + cons);
+ }
+ }
+ break;
+ }
+ }
+ return exist;
+ }
+
+ @Override
+ public ControlLoopGuardBuilder removeAllLimitConstraints(String id) throws BuilderException {
+ if (cLGuard.getGuards() == null || cLGuard.getGuards().isEmpty()) {
+ throw new BuilderException("No guard policies exist");
+ }
+ if (id == null) {
+ throw new BuilderException(THE_ID_OF_TARGET_GUARD_POLICY_MUST_NOT_BE_NULL);
+ }
+ boolean exist = false;
+ for (GuardPolicy policy: cLGuard.getGuards()) {
+ if (policy.getId().equals(id)) {
+ exist = true;
+ policy.getLimit_constraints().clear();
+ }
+ }
+ if (!exist) {
+ throw new BuilderException(NO_EXISTING_GUARD_POLICY_MATCHING_THE_ID + id);
+ }
+ return this;
+ }
+
+
+ private class BuilderCompilerCallback implements ControlLoopCompilerCallback {
+
+ private ResultsImpl results = new ResultsImpl();
+
+ @Override
+ public boolean onWarning(String message) {
+ results.addMessage(new MessageImpl(message, MessageLevel.WARNING));
+ return false;
+ }
+
+ @Override
+ public boolean onError(String message) {
+ results.addMessage(new MessageImpl(message, MessageLevel.ERROR));
+ return false;
+ }
+ }
+
+ @Override
+ public ControlLoopGuard getControlLoopGuard() {
+ return new ControlLoopGuard(this.cLGuard);
+ }
+
+
+ @Override
+ public Results buildSpecification() {
+ //
+ // Dump the specification
+ //
+ DumperOptions options = new DumperOptions();
+ options.setDefaultFlowStyle(FlowStyle.BLOCK);
+ options.setPrettyFlow(true);
+ Yaml yaml = new Yaml(options);
+ String dumpedYaml = yaml.dump(cLGuard);
+ //
+ // This is our callback class for our compiler
+ //
+ BuilderCompilerCallback callback = new BuilderCompilerCallback();
+ //
+ // Compile it
+ //
+ try {
+ ControlLoopGuardCompiler.compile(cLGuard, callback);
+ } catch (CompilerException e) {
+ logger.error(e.getMessage() + e);
+ callback.results.addMessage(new MessageImpl(e.getMessage(), MessageLevel.EXCEPTION));
+ }
+ //
+ // Save the spec
+ //
+ callback.results.setSpecification(dumpedYaml);
+ return callback.results;
+ }
+
+}