From 8279af376b435e1d7dd118a1955c5681edf3b847 Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Wed, 29 Aug 2018 07:58:53 -0400 Subject: 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 --- .../controlloop/compiler/ControlLoopCompiler.java | 4 +- .../guard/compiler/ControlLoopGuardCompiler.java | 38 +++-- .../policy/controlloop/policy/ControlLoop.java | 9 +- .../controlloop/policy/ControlLoopPolicy.java | 23 ++- .../policy/controlloop/policy/FinalResult.java | 13 ++ .../policy/OperationsAccumulateParams.java | 27 ++-- .../org/onap/policy/controlloop/policy/Policy.java | 38 +++++ .../policy/controlloop/policy/PolicyResult.java | 8 +- .../org/onap/policy/controlloop/policy/Target.java | 51 +++--- .../policy/builder/ControlLoopPolicyBuilder.java | 180 +++++++++++---------- .../controlloop/policy/builder/MessageLevel.java | 12 +- .../builder/impl/ControlLoopPolicyBuilderImpl.java | 174 +++++++++++--------- .../controlloop/policy/guard/Constraint.java | 58 +++++-- .../controlloop/policy/guard/ControlLoopGuard.java | 27 ++-- .../policy/controlloop/policy/guard/Guard.java | 19 ++- .../controlloop/policy/guard/GuardPolicy.java | 20 +++ .../controlloop/policy/guard/MatchParameters.java | 35 ++-- .../guard/builder/ControlLoopGuardBuilder.java | 51 +++--- .../builder/impl/ControlLoopGuardBuilderImpl.java | 32 ++-- 19 files changed, 514 insertions(+), 305 deletions(-) (limited to 'controlloop/common/policy-yaml/src/main') diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/compiler/ControlLoopCompiler.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/compiler/ControlLoopCompiler.java index 27c9bf8cd..45ff1847b 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/compiler/ControlLoopCompiler.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/compiler/ControlLoopCompiler.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml * ================================================================================ - * 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. @@ -101,7 +101,7 @@ public class ControlLoopCompiler implements Serializable { && callback != null) { callback.onError("Missing controlLoopName"); } - if ((!controlLoop.getVersion().contentEquals(ControlLoop.getVERSION())) && callback != null) { + if ((!controlLoop.getVersion().contentEquals(ControlLoop.getCompilerVersion())) && callback != null) { callback.onError("Unsupported version for this compiler"); } if (controlLoop.getTrigger_policy() == null || controlLoop.getTrigger_policy().length() < 1) { diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/guard/compiler/ControlLoopGuardCompiler.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/guard/compiler/ControlLoopGuardCompiler.java index 2897fde26..4cee39cb4 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/guard/compiler/ControlLoopGuardCompiler.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/guard/compiler/ControlLoopGuardCompiler.java @@ -20,8 +20,8 @@ package org.onap.policy.controlloop.guard.compiler; - import java.io.InputStream; + import java.util.HashSet; import java.util.List; import java.util.Set; @@ -43,24 +43,40 @@ public class ControlLoopGuardCompiler { // Private Constructor } - public static ControlLoopGuard compile(ControlLoopGuard cLGuard, + /** + * Compile the control loop guard. + * + * @param clGuard the guard + * @param callback callback routine + * @return the guard object + * @throws CompilerException compilation exception + */ + public static ControlLoopGuard compile(ControlLoopGuard clGuard, ControlLoopCompilerCallback callback) throws CompilerException { // // Ensure ControlLoopGuard has at least one guard policies // - validateControlLoopGuard(cLGuard, callback); + validateControlLoopGuard(clGuard, callback); // // Ensure each guard policy has at least one constraints and all guard policies are unique // - validateGuardPolicies(cLGuard.getGuards(), callback); + validateGuardPolicies(clGuard.getGuards(), callback); // // Ensure constraints for each guard policy are unique // - validateConstraints(cLGuard.getGuards(), callback); + validateConstraints(clGuard.getGuards(), callback); - return cLGuard; + return clGuard; } + /** + * Compile the control loop guard. + * + * @param yamlSpecification yaml specification as a stream + * @param callback callback method + * @return guard object + * @throws CompilerException throws compile exception + */ public static ControlLoopGuard compile(InputStream yamlSpecification, ControlLoopCompilerCallback callback) throws CompilerException { Yaml yaml = new Yaml(new Constructor(ControlLoopGuard.class)); @@ -74,22 +90,22 @@ public class ControlLoopGuardCompiler { return ControlLoopGuardCompiler.compile((ControlLoopGuard) obj, callback); } - private static void validateControlLoopGuard(ControlLoopGuard cLGuard, + private static void validateControlLoopGuard(ControlLoopGuard clGuard, ControlLoopCompilerCallback callback) throws CompilerException { - if (cLGuard == null) { + if (clGuard == null) { if (callback != null) { callback.onError("ControlLoop Guard cannot be null"); } throw new CompilerException("ControlLoop Guard cannot be null"); } - if (cLGuard.getGuard() == null && callback != null) { + if (clGuard.getGuard() == null && callback != null) { callback.onError("Guard version cannot be null"); } - if (cLGuard.getGuards() == null) { + if (clGuard.getGuards() == null) { if (callback != null) { callback.onError("ControlLoop Guard should have at least one guard policies"); } - } else if (cLGuard.getGuards().isEmpty() && callback != null) { + } else if (clGuard.getGuards().isEmpty() && callback != null) { callback.onError("ControlLoop Guard should have at least one guard policies"); } } diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/ControlLoop.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/ControlLoop.java index fc835dd51..a8edf7a81 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/ControlLoop.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/ControlLoop.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml * ================================================================================ - * 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. @@ -44,7 +44,7 @@ public class ControlLoop { // Empty Constructor. } - public static String getVERSION() { + public static String getCompilerVersion() { return ControlLoop.COMPILER_VERSION; } @@ -112,6 +112,11 @@ public class ControlLoop { this.pnf = pnf; } + /** + * Constructor. + * + * @param controlLoop copy object + */ public ControlLoop(ControlLoop controlLoop) { this.controlLoopName = controlLoop.controlLoopName; this.services = new LinkedList<>(); diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/ControlLoopPolicy.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/ControlLoopPolicy.java index e0c5839b1..161fe1def 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/ControlLoopPolicy.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/ControlLoopPolicy.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml * ================================================================================ - * 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. @@ -60,23 +60,30 @@ public class ControlLoopPolicy { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } ControlLoopPolicy other = (ControlLoopPolicy) obj; if (controlLoop == null) { - if (other.controlLoop != null) + if (other.controlLoop != null) { return false; - } else if (!controlLoop.equals(other.controlLoop)) + } + } else if (!controlLoop.equals(other.controlLoop)) { return false; + } if (policies == null) { - if (other.policies != null) + if (other.policies != null) { return false; - } else if (!policies.equals(other.policies)) + } + } else if (!policies.equals(other.policies)) { return false; + } return true; } diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/FinalResult.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/FinalResult.java index b9fdc2e6d..473b102e7 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/FinalResult.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/FinalResult.java @@ -58,6 +58,12 @@ public enum FinalResult { this.result = result; } + /** + * Converts to a result object. + * + * @param result input string + * @return result object + */ public static FinalResult toResult(String result) { if (result.equalsIgnoreCase(FINAL_SUCCESS.toString())) { return FINAL_SUCCESS; @@ -83,6 +89,13 @@ public enum FinalResult { return null; } + /** + * Check if the result really is a result. + * + * @param result string + * @param finalResult result object + * @return true if a result + */ public static boolean isResult(String result, FinalResult finalResult) { FinalResult toResult = FinalResult.toResult(result); if (toResult == null) { diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/OperationsAccumulateParams.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/OperationsAccumulateParams.java index 4d0f03a06..594c42023 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/OperationsAccumulateParams.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/OperationsAccumulateParams.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml * ================================================================================ - * 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. @@ -24,9 +24,6 @@ import java.io.Serializable; public class OperationsAccumulateParams implements Serializable { - /** - * - */ private static final long serialVersionUID = -3597358159130168247L; private String period; @@ -75,25 +72,33 @@ public class OperationsAccumulateParams implements Serializable { result = prime * result + ((limit == null) ? 0 : limit.hashCode()); return result; } + @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } OperationsAccumulateParams other = (OperationsAccumulateParams) obj; if (period == null) { - if (other.period != null) + if (other.period != null) { return false; - } else if (!period.equals(other.period)) + } + } else if (!period.equals(other.period)) { return false; + } if (limit == null) { - if (other.limit != null) + if (other.limit != null) { return false; - } else if (!limit.equals(other.limit)) + } + } else if (!limit.equals(other.limit)) { return false; + } return true; } diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Policy.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Policy.java index 4e0a0c99b..8585b674b 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Policy.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Policy.java @@ -180,6 +180,15 @@ public class Policy { this.id = id; } + /** + * Constructor. + * + * @param name name + * @param actor actor + * @param recipe recipe + * @param payload payload + * @param target target + */ public Policy(String name, String actor, String recipe, Map payload, Target target) { this.name = name; this.actor = actor; @@ -190,6 +199,17 @@ public class Policy { } } + /** + * Constructor. + * + * @param name name + * @param actor actor + * @param recipe recipe + * @param payload payload + * @param target target + * @param retries retries + * @param timeout timeout + */ public Policy(String name, String actor, String recipe, Map payload, Target target, Integer retries, Integer timeout) { this(name, actor, recipe, payload, target); @@ -197,6 +217,19 @@ public class Policy { this.timeout = timeout; } + /** + * Constructor. + * + * @param id id + * @param name name + * @param description description + * @param actor actor + * @param payload payload + * @param target target + * @param recipe recipe + * @param retries retries + * @param timeout timeout + */ public Policy(String id, String name, String description, String actor, Map payload, Target target, String recipe, Integer retries, Integer timeout) { this(name, actor, recipe, payload, target, retries, timeout); @@ -204,6 +237,11 @@ public class Policy { this.description = description; } + /** + * Constructor. + * + * @param policy copy object + */ public Policy(Policy policy) { this.id = policy.id; this.name = policy.name; diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/PolicyResult.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/PolicyResult.java index 574e14225..d9e1557d4 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/PolicyResult.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/PolicyResult.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml * ================================================================================ - * 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. @@ -58,6 +58,12 @@ public enum PolicyResult { return this.result; } + /** + * Convert to a result. + * + * @param result result string + * @return Result object + */ public static PolicyResult toResult(String result) { if (result.equalsIgnoreCase(SUCCESS.toString())) { return SUCCESS; diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Target.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Target.java index bc5b934b2..61d1ae285 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Target.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Target.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml * ================================================================================ - * 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. @@ -24,12 +24,9 @@ import java.io.Serializable; public class Target implements Serializable { - /** - * - */ private static final long serialVersionUID = 2180988443264988319L; - private String resourceID; + private String resourceId; private TargetType type; public Target() { @@ -37,11 +34,11 @@ public class Target implements Serializable { } public String getResourceID() { - return resourceID; + return resourceId; } - public void setResourceID(String resourceID) { - this.resourceID = resourceID; + public void setResourceID(String resourceId) { + this.resourceId = resourceId; } public TargetType getType() { @@ -56,23 +53,23 @@ public class Target implements Serializable { this.type = type; } - public Target(String resourceID) { - this.resourceID = resourceID; + public Target(String resourceId) { + this.resourceId = resourceId; } - public Target(TargetType type, String resourceID) { + public Target(TargetType type, String resourceId) { this.type = type; - this.resourceID = resourceID; + this.resourceId = resourceId; } public Target(Target target) { this.type = target.type; - this.resourceID = target.resourceID; + this.resourceId = target.resourceId; } @Override public String toString() { - return "Target [type=" + type + ", resourceID=" + resourceID + "]"; + return "Target [type=" + type + ", resourceId=" + resourceId + "]"; } @Override @@ -80,28 +77,36 @@ public class Target implements Serializable { final int prime = 31; int result = 1; result = prime * result + ((type == null) ? 0 : type.hashCode()); - result = prime * result + ((resourceID == null) ? 0 : resourceID.hashCode()); + result = prime * result + ((resourceId == null) ? 0 : resourceId.hashCode()); return result; } + @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } Target other = (Target) obj; if (type == null) { - if (other.type != null) + if (other.type != null) { return false; - } else if (!type.equals(other.type)) + } + } else if (!type.equals(other.type)) { return false; - if (resourceID == null) { - if (other.resourceID != null) + } + if (resourceId == null) { + if (other.resourceId != null) { return false; - } else if (!resourceID.equals(other.resourceID)) + } + } else if (!resourceId.equals(other.resourceId)) { return false; + } return true; } } diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/ControlLoopPolicyBuilder.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/ControlLoopPolicyBuilder.java index 4e034cb0e..9d00793b9 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/ControlLoopPolicyBuilder.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/ControlLoopPolicyBuilder.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml * ================================================================================ - * 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. @@ -35,68 +35,79 @@ import org.onap.policy.sdc.Service; public interface ControlLoopPolicyBuilder { /** - * Adds one or more services to the ControlLoop + * Adds one or more services to the ControlLoop. * - * - * @param service - * @return - * @throws BuilderException + * @param services service to add + * @return builder object + * @throws BuilderException builder exception */ public ControlLoopPolicyBuilder addService(Service... services) throws BuilderException; /** - * @param services - * @return - * @throws BuilderException + * Remove service. + * + * @param services to remove + * @return builder object + * @throws BuilderException builder exception */ public ControlLoopPolicyBuilder removeService(Service... services) throws BuilderException; /** - * @return - * @throws BuilderException + * Remove all the services. + * + * @return builder object + * @throws BuilderException builder exception */ public ControlLoopPolicyBuilder removeAllServices() throws BuilderException; /** - * Adds one or more resources to the ControlLoop - * + * Adds one or more resources to the ControlLoop. * - * @param resource - * @return - * @throws BuilderException + * @return builder object + * @throws BuilderException builder exception */ public ControlLoopPolicyBuilder addResource(Resource... resources) throws BuilderException; /** - * @param resources - * @return - * @throws BuilderException + * Remove the resources. + * + * @param resources resources to be removed + * @return object + * @throws BuilderException builder exception */ public ControlLoopPolicyBuilder removeResource(Resource... resources) throws BuilderException; /** - * @return - * @throws BuilderException + * Remove all resources. + * + * @return object + * @throws BuilderException builder exception */ public ControlLoopPolicyBuilder removeAllResources() throws BuilderException; /** - * @param pnf - * @return - * @throws BuilderException + * Set the PNF. + * + * @param pnf input pnf + * @return builder object + * @throws BuilderException builder exception */ public ControlLoopPolicyBuilder setPNF(Pnf pnf) throws BuilderException; /** - * @return - * @throws BuilderException + * Remove PNF. + * + * @return the object + * @throws BuilderException builder exception */ public ControlLoopPolicyBuilder removePNF() throws BuilderException; /** - * @param abatement - * @return - * @throws BuilderException + * Set the abatement. + * + * @param abatement whether abatement is possible + * @return object + * @throws BuilderException builder exception */ public ControlLoopPolicyBuilder setAbatement(Boolean abatement) throws BuilderException; @@ -105,9 +116,9 @@ public interface ControlLoopPolicyBuilder { * Sets the overall timeout value for the Control Loop. If any operational policies have retries * and timeouts, then this overall timeout value should exceed all those values. * - * @param timeout - * @return - * @throws BuilderException + * @param timeout timeout value + * @return control loop policy builder + * @throws BuilderException builder exception */ public ControlLoopPolicyBuilder setTimeout(Integer timeout) throws BuilderException; @@ -124,38 +135,40 @@ public interface ControlLoopPolicyBuilder { * Platform. * * - * @param name - * @param description - * @param actor - * @param target - * @param recipe - * @param retries - * @param timeout - * @return Policy - * @throws BuilderException + * @param name name + * @param description description + * @param actor actor + * @param target target + * @param recipe recipe + * @param retries retries + * @param timeout timeout + * @return Policy object + * @throws BuilderException builder exception */ public Policy setTriggerPolicy(String name, String description, String actor, Target target, String recipe, Map payload, Integer retries, Integer timeout) throws BuilderException; /** - * * Changes the trigger policy to point to another existing Policy. * - * - * @param id - * @return ControlLoop - * @throws BuilderException + * @param id the id + * @return ControlLoop object + * @throws BuilderException build exception */ public ControlLoop setTriggerPolicy(String id) throws BuilderException; /** - * @return + * Is an open loop. + * + * @return true or false */ public boolean isOpenLoop(); /** - * @return - * @throws BuilderException + * Get the trigger policy. + * + * @return the policy object + * @throws BuilderException if there is a builder exception */ public Policy getTriggerPolicy() throws BuilderException; @@ -170,35 +183,33 @@ public interface ControlLoopPolicyBuilder { /** * Creates a policy that is chained to the result of another Policy. * - * - * @param name - * @param description - * @param actor - * @param target - * @param recipe - * @param retries - * @param timeout - * @param policyID - * @param results - * @return - * @throws BuilderException + * @param name name + * @param description description + * @param actor actor + * @param target target + * @param recipe recipe + * @param retries retries + * @param timeout timeout + * @param policyId id + * @param results results + * @return Policy that was set + * @throws BuilderException builder exception */ public Policy setPolicyForPolicyResult(String name, String description, String actor, Target target, String recipe, - Map payload, Integer retries, Integer timeout, String policyID, PolicyResult... results) + Map payload, Integer retries, Integer timeout, String policyId, PolicyResult... results) throws BuilderException; /** * Sets the policy result(s) to an existing Operational Policy. * - * - * @param policyResultID - * @param policyID - * @param results - * @return - * @throws BuilderException + * @param policyResultId result ID + * @param policyId id + * @param results results + * @return Policy that was set + * @throws BuilderException builder exception */ - public Policy setPolicyForPolicyResult(String policyResultID, String policyID, PolicyResult... results) + public Policy setPolicyForPolicyResult(String policyResultId, String policyId, PolicyResult... results) throws BuilderException; /** @@ -207,17 +218,16 @@ public interface ControlLoopPolicyBuilder { * their result reset to the appropriate default FINAL_* result. * * - * @param policyID - * @return - * @throws BuilderException + * @param policyID id for the policy + * @return true if removed else false + * @throws BuilderException builder exception */ public boolean removePolicy(String policyID) throws BuilderException; /** * Resets a policy's results to defualt FINAL_* codes. * - * - * @return Policy + * @return Policy object * @throws BuilderException - Policy does not exist */ public Policy resetPolicyResults(String policyID) throws BuilderException; @@ -230,7 +240,7 @@ public interface ControlLoopPolicyBuilder { public ControlLoopPolicyBuilder removeAllPolicies(); /** - * Adds an operationsAccumulateParams to an existing operational policy + * Adds an operationsAccumulateParams to an existing operational policy. * * @return Policy * @throws BuilderException - Policy does not exist @@ -280,7 +290,7 @@ public interface ControlLoopPolicyBuilder { * @param services - Zero or more services associated with this resource. Should come from * ASDC, but if not available use serviceName to distinguish. * @return ControlLoopPolicyBuilder object - * @throws BuilderException + * @throws BuilderException builder exception */ public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout, Resource resource, Service... services) throws BuilderException { @@ -288,12 +298,14 @@ public interface ControlLoopPolicyBuilder { } /** - * @param controlLoopName - * @param timeout - * @param service - * @param resources - * @return - * @throws BuilderException + * Build the control loop. + * + * @param controlLoopName control loop id + * @param timeout timeout + * @param service service + * @param resources resources + * @return builder object + * @throws BuilderException builder exception */ public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout, Service service, Resource... resources) throws BuilderException { @@ -301,12 +313,14 @@ public interface ControlLoopPolicyBuilder { } /** + * Build control loop. + * * @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop. * @param timeout - Overall timeout for the Closed Loop to execute. * @param pnf - Physical Network Function. Should come from AIC, but if not available use * well-known name to distinguish. Eg. eNodeB * @return ControlLoopPolicyBuilder object - * @throws BuilderException + * @throws BuilderException builder exception */ public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout, Pnf pnf) throws BuilderException { diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/MessageLevel.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/MessageLevel.java index ffd63d691..bfe6fc080 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/MessageLevel.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/MessageLevel.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml * ================================================================================ - * 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. @@ -21,10 +21,8 @@ package org.onap.policy.controlloop.policy.builder; public enum MessageLevel { - INFO, - WARNING, - ERROR, - EXCEPTION - ; - + INFO, + WARNING, + ERROR, + EXCEPTION; } diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/impl/ControlLoopPolicyBuilderImpl.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/impl/ControlLoopPolicyBuilderImpl.java index adbf12748..ba434356a 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/impl/ControlLoopPolicyBuilderImpl.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/impl/ControlLoopPolicyBuilderImpl.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml * ================================================================================ - * 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. @@ -54,6 +54,12 @@ public class ControlLoopPolicyBuilderImpl implements ControlLoopPolicyBuilder { private static Logger logger = LoggerFactory.getLogger(ControlLoopPolicyBuilderImpl.class.getName()); private ControlLoopPolicy controlLoopPolicy; + /** + * Constructor. + * + * @param controlLoopName control loop id + * @param timeout timeout value + */ public ControlLoopPolicyBuilderImpl(String controlLoopName, Integer timeout) { controlLoopPolicy = new ControlLoopPolicy(); ControlLoop controlLoop = new ControlLoop(); @@ -62,6 +68,15 @@ public class ControlLoopPolicyBuilderImpl implements ControlLoopPolicyBuilder { controlLoopPolicy.setControlLoop(controlLoop); } + /** + * Constructor. + * + * @param controlLoopName control loop id + * @param timeout timeout value + * @param resource resource + * @param services services + * @throws BuilderException builder exception + */ public ControlLoopPolicyBuilderImpl(String controlLoopName, Integer timeout, Resource resource, Service... services) throws BuilderException { this(controlLoopName, timeout); @@ -74,6 +89,15 @@ public class ControlLoopPolicyBuilderImpl implements ControlLoopPolicyBuilder { this.setPNF(pnf); } + /** + * Constructor. + * + * @param controlLoopName control loop id + * @param timeout timeout + * @param service service + * @param resources resources + * @throws BuilderException builder exception + */ public ControlLoopPolicyBuilderImpl(String controlLoopName, Integer timeout, Service service, Resource[] resources) throws BuilderException { this(controlLoopName, timeout); @@ -137,7 +161,7 @@ public class ControlLoopPolicyBuilderImpl implements ControlLoopPolicyBuilder { if (resource == null) { throw new BuilderException("Resource must not be null"); } - if (resource.getResourceUUID() == null && Strings.isNullOrEmpty(resource.getResourceName())) { + if (resource.getResourceUuid() == null && Strings.isNullOrEmpty(resource.getResourceName())) { throw new BuilderException("Invalid resource - need either resourceUUID or resourceName"); } if (controlLoopPolicy.getControlLoop().getResources() == null) { @@ -191,16 +215,30 @@ public class ControlLoopPolicyBuilderImpl implements ControlLoopPolicyBuilder { return new Policy(trigger); } + @Override + public ControlLoop setTriggerPolicy(String id) throws BuilderException { + if (id == null) { + throw new BuilderException("Id must not be null"); + } + Policy trigger = this.findPolicy(id); + if (trigger == null) { + throw new BuilderException(UNKNOWN_POLICY + id); + } else { + this.controlLoopPolicy.getControlLoop().setTrigger_policy(id); + } + return new ControlLoop(this.controlLoopPolicy.getControlLoop()); + } + @Override public Policy setPolicyForPolicyResult(String name, String description, String actor, Target target, String recipe, - Map payload, Integer retries, Integer timeout, String policyID, PolicyResult... results) + Map payload, Integer retries, Integer timeout, String policyId, PolicyResult... results) throws BuilderException { // // Find the existing policy // - Policy existingPolicy = this.findPolicy(policyID); + Policy existingPolicy = this.findPolicy(policyId); if (existingPolicy == null) { - throw new BuilderException(UNKNOWN_POLICY + policyID); + throw new BuilderException(UNKNOWN_POLICY + policyId); } // // Create the new Policy @@ -244,6 +282,49 @@ public class ControlLoopPolicyBuilderImpl implements ControlLoopPolicyBuilder { return new Policy(newPolicy); } + @Override + public Policy setPolicyForPolicyResult(String policyResultId, String policyId, PolicyResult... results) + throws BuilderException { + // + // Find the existing policy + // + Policy existingPolicy = this.findPolicy(policyId); + if (existingPolicy == null) { + throw new BuilderException(policyId + " does not exist"); + } + if (this.findPolicy(policyResultId) == null) { + throw new BuilderException("Operational policy " + policyResultId + " does not exist"); + } + // + // Connect the results + // + for (PolicyResult result : results) { + switch (result) { + case FAILURE: + existingPolicy.setFailure(policyResultId); + break; + case FAILURE_EXCEPTION: + existingPolicy.setFailure_exception(policyResultId); + break; + case FAILURE_RETRIES: + existingPolicy.setFailure_retries(policyResultId); + break; + case FAILURE_TIMEOUT: + existingPolicy.setFailure_timeout(policyResultId); + break; + case FAILURE_GUARD: + existingPolicy.setFailure_guard(policyResultId); + break; + case SUCCESS: + existingPolicy.setSuccess(policyResultId); + break; + default: + throw new BuilderException("Invalid PolicyResult " + result); + } + } + return new Policy(this.findPolicy(policyResultId)); + } + private class BuilderCompilerCallback implements ControlLoopCompilerCallback { private ResultsImpl results = new ResultsImpl(); @@ -318,7 +399,7 @@ public class ControlLoopPolicyBuilderImpl implements ControlLoopPolicyBuilder { if (resource == null) { throw new BuilderException("Resource must not be null"); } - if (resource.getResourceUUID() == null && Strings.isNullOrEmpty(resource.getResourceName())) { + if (resource.getResourceUuid() == null && Strings.isNullOrEmpty(resource.getResourceName())) { throw new BuilderException("Invalid resource - need either a resourceUUID or resourceName"); } boolean removed = controlLoopPolicy.getControlLoop().getResources().remove(resource); @@ -344,20 +425,6 @@ public class ControlLoopPolicyBuilderImpl implements ControlLoopPolicyBuilder { return Integer.valueOf(sum); } - @Override - public ControlLoop setTriggerPolicy(String id) throws BuilderException { - if (id == null) { - throw new BuilderException("Id must not be null"); - } - Policy trigger = this.findPolicy(id); - if (trigger == null) { - throw new BuilderException(UNKNOWN_POLICY + id); - } else { - this.controlLoopPolicy.getControlLoop().setTrigger_policy(id); - } - return new ControlLoop(this.controlLoopPolicy.getControlLoop()); - } - @Override public boolean isOpenLoop() { return this.controlLoopPolicy.getControlLoop().getTrigger_policy() @@ -379,61 +446,18 @@ public class ControlLoopPolicyBuilderImpl implements ControlLoopPolicyBuilder { } @Override - public Policy setPolicyForPolicyResult(String policyResultID, String policyID, PolicyResult... results) - throws BuilderException { - // - // Find the existing policy - // - Policy existingPolicy = this.findPolicy(policyID); - if (existingPolicy == null) { - throw new BuilderException(policyID + " does not exist"); - } - if (this.findPolicy(policyResultID) == null) { - throw new BuilderException("Operational policy " + policyResultID + " does not exist"); - } - // - // Connect the results - // - for (PolicyResult result : results) { - switch (result) { - case FAILURE: - existingPolicy.setFailure(policyResultID); - break; - case FAILURE_EXCEPTION: - existingPolicy.setFailure_exception(policyResultID); - break; - case FAILURE_RETRIES: - existingPolicy.setFailure_retries(policyResultID); - break; - case FAILURE_TIMEOUT: - existingPolicy.setFailure_timeout(policyResultID); - break; - case FAILURE_GUARD: - existingPolicy.setFailure_guard(policyResultID); - break; - case SUCCESS: - existingPolicy.setSuccess(policyResultID); - break; - default: - throw new BuilderException("Invalid PolicyResult " + result); - } - } - return new Policy(this.findPolicy(policyResultID)); - } - - @Override - public boolean removePolicy(String policyID) throws BuilderException { - Policy existingPolicy = this.findPolicy(policyID); + public boolean removePolicy(String policyId) throws BuilderException { + Policy existingPolicy = this.findPolicy(policyId); if (existingPolicy == null) { - throw new BuilderException(UNKNOWN_POLICY + policyID); + throw new BuilderException(UNKNOWN_POLICY + policyId); } // // Check if the policy to remove is trigger_policy // - if (this.controlLoopPolicy.getControlLoop().getTrigger_policy().equals(policyID)) { + if (this.controlLoopPolicy.getControlLoop().getTrigger_policy().equals(policyId)) { this.controlLoopPolicy.getControlLoop().setTrigger_policy(FinalResult.FINAL_OPENLOOP.toString()); } else { - updateChainedPoliciesForPolicyRemoval(policyID); + updateChainedPoliciesForPolicyRemoval(policyId); } // // remove the policy @@ -443,7 +467,7 @@ public class ControlLoopPolicyBuilderImpl implements ControlLoopPolicyBuilder { private void updateChainedPoliciesForPolicyRemoval(String idOfPolicyBeingRemoved) { for (Policy policy : this.controlLoopPolicy.getPolicies()) { - int index = this.controlLoopPolicy.getPolicies().indexOf(policy); + final int index = this.controlLoopPolicy.getPolicies().indexOf(policy); if (policy.getSuccess().equals(idOfPolicyBeingRemoved)) { policy.setSuccess(FinalResult.FINAL_SUCCESS.toString()); } @@ -467,10 +491,10 @@ public class ControlLoopPolicyBuilderImpl implements ControlLoopPolicyBuilder { } @Override - public Policy resetPolicyResults(String policyID) throws BuilderException { - Policy existingPolicy = this.findPolicy(policyID); + public Policy resetPolicyResults(String policyId) throws BuilderException { + Policy existingPolicy = this.findPolicy(policyId); if (existingPolicy == null) { - throw new BuilderException(UNKNOWN_POLICY + policyID); + throw new BuilderException(UNKNOWN_POLICY + policyId); } // // reset policy results @@ -498,11 +522,11 @@ public class ControlLoopPolicyBuilderImpl implements ControlLoopPolicyBuilder { } @Override - public Policy addOperationsAccumulateParams(String policyID, OperationsAccumulateParams operationsAccumulateParams) + public Policy addOperationsAccumulateParams(String policyId, OperationsAccumulateParams operationsAccumulateParams) throws BuilderException { - Policy existingPolicy = this.findPolicy(policyID); + Policy existingPolicy = this.findPolicy(policyId); if (existingPolicy == null) { - throw new BuilderException(UNKNOWN_POLICY + policyID); + throw new BuilderException(UNKNOWN_POLICY + policyId); } // // Add operationsAccumulateParams to existingPolicy 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 e53f3e40f..6931de430 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 @@ -75,9 +75,15 @@ public class Constraint { this.blacklist = blacklist; } + /** + * Constructor. + * + * @param freqLimitPerTarget frequency limit + * @param timeWindow time window + */ public Constraint(Integer freqLimitPerTarget, Map timeWindow) { this.freqLimitPerTarget = freqLimitPerTarget; - if(timeWindow!=null){ + if (timeWindow != null) { this.timeWindow = Collections.unmodifiableMap(timeWindow); } } @@ -86,12 +92,26 @@ public class Constraint { this.blacklist = new LinkedList<>(blacklist); } + /** + * Constructor. + * + * @param freqLimitPerTarget frequency limit + * @param timeWindow time window + * @param blacklist blacklist + */ public Constraint(Integer freqLimitPerTarget, Map timeWindow, List blacklist) { this.freqLimitPerTarget = freqLimitPerTarget; this.timeWindow = Collections.unmodifiableMap(timeWindow); this.blacklist = new LinkedList<>(blacklist); } + /** + * Constructor. + * + * @param freqLimitPerTarget frequency limit + * @param timeWindow time window + * @param activeTimeRange active time range + */ public Constraint(Integer freqLimitPerTarget, Map timeWindow, Map activeTimeRange) { this(freqLimitPerTarget, timeWindow); if (activeTimeRange != null) { @@ -99,17 +119,30 @@ public class Constraint { } } + /** + * Constructor. + * + * @param freqLimitPerTarget frequency limit + * @param timeWindow the time window + * @param activeTimeRange active time range + * @param blacklist incoming blacklist + */ public Constraint(Integer freqLimitPerTarget, Map timeWindow, Map activeTimeRange, List blacklist) { this(freqLimitPerTarget, timeWindow); if (activeTimeRange != null) { this.activeTimeRange = Collections.unmodifiableMap(activeTimeRange); } - if(blacklist != null){ + if (blacklist != null) { this.blacklist = new LinkedList<>(blacklist); } } + /** + * Constructor. + * + * @param constraint objec to copy + */ public Constraint(Constraint constraint) { this.freqLimitPerTarget = constraint.freqLimitPerTarget; this.timeWindow = constraint.timeWindow; @@ -143,23 +176,26 @@ public class Constraint { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + 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); + && equalsMayBeNull(timeWindow, other.timeWindow) + && equalsMayBeNull(activeTimeRange, other.activeTimeRange) + && equalsMayBeNull(blacklist, other.blacklist); } - private boolean equalsMayBeNull(final Object obj1, final Object obj2){ - if ( obj1 == null ) { + private boolean equalsMayBeNull(final Object obj1, final Object obj2) { + if (obj1 == null) { return obj2 == null; } - return obj1.equals(obj2); + 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 6fb0ca9f0..66ac3e612 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml * ================================================================================ - * 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. @@ -48,9 +48,9 @@ public class ControlLoopGuard { this.guards = guards; } - public ControlLoopGuard(ControlLoopGuard cLGuard) { + public ControlLoopGuard(ControlLoopGuard clGuard) { this.guard = new Guard(); - this.guards = new LinkedList<>(cLGuard.guards); + this.guards = new LinkedList<>(clGuard.guards); } @Override @@ -69,23 +69,30 @@ public class ControlLoopGuard { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } ControlLoopGuard other = (ControlLoopGuard) obj; if (guard == null) { - if (other.guard != null) + if (other.guard != null) { return false; - } else if (!guard.equals(other.guard)) + } + } else if (!guard.equals(other.guard)) { return false; + } if (guards == null) { - if (other.guards != null) + if (other.guards != null) { return false; - } else if (!guards.equals(other.guards)) + } + } 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 291004611..dcce13597 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml * ================================================================================ - * 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. @@ -42,6 +42,7 @@ public class Guard { public String toString() { return "Guard [version=" + version + "]"; } + @Override public int hashCode() { final int prime = 31; @@ -49,20 +50,26 @@ public class Guard { result = prime * result + ((version == null) ? 0 : version.hashCode()); return result; } + @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } Guard other = (Guard) obj; if (version == null) { - if (other.version != null) + if (other.version != null) { return false; - } else if (!version.equals(other.version)) + } + } 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 759a0533d..799c5fcd7 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 @@ -85,12 +85,27 @@ public class GuardPolicy { this.matchParameters = matchParameters; } + /** + * Constructor. + * + * @param id id + * @param name name + * @param description description + * @param matchParameters match parameters + */ public GuardPolicy(String id, String name, String description, MatchParameters matchParameters) { this(name, matchParameters); this.id = id; this.description = description; } + /** + * Constructor. + * + * @param name name + * @param matchParameters match parameters + * @param limitConstraints limit constraints + */ public GuardPolicy(String name, MatchParameters matchParameters, List limitConstraints) { this(name, matchParameters); if (limitConstraints != null) { @@ -110,6 +125,11 @@ public class GuardPolicy { this.id = id; } + /** + * Constructor. + * + * @param policy copy object + */ public GuardPolicy(GuardPolicy policy) { this.id = policy.id; this.name = policy.name; 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 445e00f38..1bf10734d 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-yaml * ================================================================================ - * 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. @@ -71,6 +71,13 @@ public class MatchParameters { this.recipe = recipe; } + /** + * Constructor. + * + * @param actor actor + * @param recipe recipe + * @param targets targets + */ public MatchParameters(String actor, String recipe, List targets) { this(actor, recipe); if (targets != null) { @@ -83,6 +90,11 @@ public class MatchParameters { this.controlLoopName = controlLoopName; } + /** + * Constructor. + * + * @param matchParameters match parameters + */ public MatchParameters(MatchParameters matchParameters) { this.controlLoopName = matchParameters.controlLoopName; @@ -112,24 +124,27 @@ public class MatchParameters { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + 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); + && equalsMayBeNull(controlLoopName, other.controlLoopName) + && equalsMayBeNull(recipe, other.recipe) + && equalsMayBeNull(targets, other.targets); } - private boolean equalsMayBeNull(final Object obj1, final Object obj2){ - if ( obj1 == null ) { + private boolean equalsMayBeNull(final Object obj1, final Object obj2) { + if (obj1 == null) { return obj2 == null; } - return obj1.equals(obj2); + return obj1.equals(obj2); } } diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/builder/ControlLoopGuardBuilder.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/builder/ControlLoopGuardBuilder.java index 77651dcbf..850b487a7 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/builder/ControlLoopGuardBuilder.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/builder/ControlLoopGuardBuilder.java @@ -31,64 +31,57 @@ import org.onap.policy.controlloop.policy.guard.builder.impl.ControlLoopGuardBui public interface ControlLoopGuardBuilder { /** - * Adds one or more guard policies to the Control Loop Guard + * Adds one or more guard policies to the Control Loop Guard. * - * - * @param policies - * @return - * @throws BuilderException + * @param policies policies to add + * @return builder object + * @throws BuilderException builder exception */ public ControlLoopGuardBuilder addGuardPolicy(GuardPolicy... policies) throws BuilderException; /** - * Removes one or more guard policies from the Control Loop Guard - * + * Removes one or more guard policies from the Control Loop Guard. * - * @param policies - * @return - * @throws BuilderException + * @param policies policies to add + * @return builder object + * @throws BuilderException builder exception */ public ControlLoopGuardBuilder removeGuardPolicy(GuardPolicy... policies) throws BuilderException; /** - * Removes all guard policies from the Control Loop Guard - * + * Removes all guard policies from the Control Loop Guard. * - * @param - * @return - * @throws BuilderException + * @return builder object + * @throws BuilderException builder exception */ public ControlLoopGuardBuilder removeAllGuardPolicies() throws BuilderException; /** - * Adds one or more time limit constraints to the guard policy - * + * Adds one or more time limit constraints to the guard policy. * * @param id (guard policy id) - * @param constraints - * @return - * @throws BuilderException + * @param constraints the constraints to add + * @return builder object + * @throws BuilderException builder exception */ public ControlLoopGuardBuilder addLimitConstraint(String id, Constraint... constraints) throws BuilderException; /** - * Removes one or more time limit constraints from the guard policy - * + * Removes one or more time limit constraints from the guard policy. * * @param id (guard policy id) - * @param constraints - * @return - * @throws BuilderException + * @param constraints constraints to remove + * @return builder object + * @throws BuilderException builder exception */ public ControlLoopGuardBuilder removeLimitConstraint(String id, Constraint... constraints) throws BuilderException; /** - * Removes all time limit constraints from the guard policy - * + * Removes all time limit constraints from the guard policy. * * @param id (guard policy id) - * @return - * @throws BuilderException + * @return builder object + * @throws BuilderException builder exception */ public ControlLoopGuardBuilder removeAllLimitConstraints(String id) throws BuilderException; 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 b4d251e7f..f995ba4c6 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 @@ -46,11 +46,11 @@ public class ControlLoopGuardBuilderImpl implements ControlLoopGuardBuilder { 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; + private ControlLoopGuard clGuard; public ControlLoopGuardBuilderImpl(Guard guard) { - cLGuard = new ControlLoopGuard(); - cLGuard.setGuard(guard); + clGuard = new ControlLoopGuard(); + clGuard.setGuard(guard); } @Override @@ -62,10 +62,10 @@ public class ControlLoopGuardBuilderImpl implements ControlLoopGuardBuilder { if (!policy.isValid()) { throw new BuilderException("Invalid guard policy - some required fields are missing"); } - if (cLGuard.getGuards() == null) { - cLGuard.setGuards(new LinkedList<>()); + if (clGuard.getGuards() == null) { + clGuard.setGuards(new LinkedList<>()); } - cLGuard.getGuards().add(policy); + clGuard.getGuards().add(policy); } return this; } @@ -75,14 +75,14 @@ public class ControlLoopGuardBuilderImpl implements ControlLoopGuardBuilder { if (policies == null) { throw new BuilderException("GuardPolicy must not be null"); } - if (cLGuard.getGuards() == 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); + boolean removed = clGuard.getGuards().remove(policy); if (!removed) { throw new BuilderException("Unknown guard policy: " + policy.getName()); } @@ -92,7 +92,7 @@ public class ControlLoopGuardBuilderImpl implements ControlLoopGuardBuilder { @Override public ControlLoopGuardBuilder removeAllGuardPolicies() throws BuilderException { - cLGuard.getGuards().clear(); + clGuard.getGuards().clear(); return this; } @@ -112,7 +112,7 @@ public class ControlLoopGuardBuilderImpl implements ControlLoopGuardBuilder { private boolean addLimitConstraints(String id, Constraint... constraints) throws BuilderException { boolean exist = false; - for (GuardPolicy policy: cLGuard.getGuards()) { + for (GuardPolicy policy: clGuard.getGuards()) { // // We could have only one guard policy matching the id // @@ -149,7 +149,7 @@ public class ControlLoopGuardBuilderImpl implements ControlLoopGuardBuilder { private boolean removeConstraints(String id, Constraint... constraints) throws BuilderException { boolean exist = false; - for (GuardPolicy policy: cLGuard.getGuards()) { + for (GuardPolicy policy: clGuard.getGuards()) { // // We could have only one guard policy matching the id // @@ -172,14 +172,14 @@ public class ControlLoopGuardBuilderImpl implements ControlLoopGuardBuilder { @Override public ControlLoopGuardBuilder removeAllLimitConstraints(String id) throws BuilderException { - if (cLGuard.getGuards() == null || cLGuard.getGuards().isEmpty()) { + 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()) { + for (GuardPolicy policy: clGuard.getGuards()) { if (policy.getId().equals(id)) { exist = true; policy.getLimit_constraints().clear(); @@ -211,7 +211,7 @@ public class ControlLoopGuardBuilderImpl implements ControlLoopGuardBuilder { @Override public ControlLoopGuard getControlLoopGuard() { - return new ControlLoopGuard(this.cLGuard); + return new ControlLoopGuard(this.clGuard); } @@ -224,7 +224,7 @@ public class ControlLoopGuardBuilderImpl implements ControlLoopGuardBuilder { options.setDefaultFlowStyle(FlowStyle.BLOCK); options.setPrettyFlow(true); Yaml yaml = new Yaml(options); - String dumpedYaml = yaml.dump(cLGuard); + String dumpedYaml = yaml.dump(clGuard); // // This is our callback class for our compiler // @@ -233,7 +233,7 @@ public class ControlLoopGuardBuilderImpl implements ControlLoopGuardBuilder { // Compile it // try { - ControlLoopGuardCompiler.compile(cLGuard, callback); + ControlLoopGuardCompiler.compile(clGuard, callback); } catch (CompilerException e) { logger.error(e.getMessage() + e); callback.results.addMessage(new MessageImpl(e.getMessage(), MessageLevel.EXCEPTION)); -- cgit 1.2.3-korg