diff options
author | Jorge Hernandez <jorge.hernandez-herrero@att.com> | 2018-11-08 19:06:17 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-11-08 19:06:17 +0000 |
commit | 69aba39cbd866a1b611613a7b14db50d86944b94 (patch) | |
tree | 29fce066cce6de184bd7b4bb1962368d8593ca0e /controlloop/common/policy-yaml/src | |
parent | 830ede893c2a05ac1e7d69068c25d25fd7cc0049 (diff) | |
parent | 91fe0bcd2d0212f949587ec82d93109946491d63 (diff) |
Merge "Apply builder pattern for policy"
Diffstat (limited to 'controlloop/common/policy-yaml/src')
4 files changed, 180 insertions, 28 deletions
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 06dc36e69..b7cb78711 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 @@ -84,8 +84,8 @@ public class Policy implements Serializable { * @param retries retries * @param timeout timeout */ - public Policy(String name, String actor, String recipe, Map<String, String> payload, Target target, - Integer retries, Integer timeout) { + public Policy(String name, String actor, String recipe, Map<String, String> payload, Target target, + Integer retries, Integer timeout) { this(name, actor, recipe, payload, target); this.retry = retries; this.timeout = timeout; @@ -93,22 +93,14 @@ public class Policy implements Serializable { /** * 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 + * + * @param policyParam provide parameter object */ - public Policy(String id, String name, String description, String actor, Map<String, String> payload, - Target target, String recipe, Integer retries, Integer timeout) { - this(name, actor, recipe, payload, target, retries, timeout); - this.id = id; - this.description = description; + public Policy(PolicyParam policyParam) { + this(policyParam.getName(), policyParam.getActor(), policyParam.getRecipe(), policyParam.getPayload(), + policyParam.getTarget(), policyParam.getRetries(), policyParam.getTimeout()); + this.id = policyParam.getId(); + this.description = policyParam.getDescription(); } /** @@ -341,5 +333,4 @@ public class Policy implements Serializable { } return obj1.equals(obj2); } - } diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/PolicyParam.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/PolicyParam.java new file mode 100644 index 000000000..8891a3f5b --- /dev/null +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/PolicyParam.java @@ -0,0 +1,132 @@ +/* + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2018 Samsung Electronics Co., Ltd. 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; + +import java.util.Map; + +public class PolicyParam { + private String id; + private String name; + private String description; + private String actor; + private Map<String, String> payload; + private Target target; + private String recipe; + private Integer retries; + private Integer timeout; + + public static PolicyParamBuilder builder() { + return new PolicyParamBuilder(); + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + + public String getActor() { + return actor; + } + + public Map<String, String> getPayload() { + return payload; + } + + public Target getTarget() { + return target; + } + + public String getRecipe() { + return recipe; + } + + public Integer getRetries() { + return retries; + } + + public Integer getTimeout() { + return timeout; + } + + public static class PolicyParamBuilder { + + PolicyParam policyParm = new PolicyParam(); + + private PolicyParamBuilder() { + } + + public PolicyParam build() { + return policyParm; + } + + public PolicyParamBuilder id(String id) { + policyParm.id = id; + return this; + } + + public PolicyParamBuilder name(String name) { + policyParm.name = name; + return this; + } + + public PolicyParamBuilder description(String description) { + policyParm.description = description; + return this; + } + + public PolicyParamBuilder actor(String actor) { + policyParm.actor = actor; + return this; + } + + public PolicyParamBuilder payload(Map<String, String> payload) { + policyParm.payload = payload; + return this; + } + + public PolicyParamBuilder target(Target target) { + policyParm.target = target; + return this; + } + + public PolicyParamBuilder recipe(String recipe) { + policyParm.recipe = recipe; + return this; + } + + public PolicyParamBuilder retries(Integer retries) { + policyParm.retries = retries; + return this; + } + + public PolicyParamBuilder timeout(Integer timeout) { + policyParm.timeout = timeout; + return this; + } + } +}
\ No newline at end of file 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 ba434356a..48f929149 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 @@ -21,11 +21,9 @@ package org.onap.policy.controlloop.policy.builder.impl; import com.google.common.base.Strings; - import java.util.LinkedList; import java.util.Map; import java.util.UUID; - import org.onap.policy.aai.Pnf; import org.onap.policy.controlloop.compiler.CompilerException; import org.onap.policy.controlloop.compiler.ControlLoopCompiler; @@ -35,6 +33,7 @@ import org.onap.policy.controlloop.policy.ControlLoopPolicy; import org.onap.policy.controlloop.policy.FinalResult; import org.onap.policy.controlloop.policy.OperationsAccumulateParams; import org.onap.policy.controlloop.policy.Policy; +import org.onap.policy.controlloop.policy.PolicyParam; import org.onap.policy.controlloop.policy.PolicyResult; import org.onap.policy.controlloop.policy.Target; import org.onap.policy.controlloop.policy.builder.BuilderException; @@ -200,11 +199,21 @@ public class ControlLoopPolicyBuilderImpl implements ControlLoopPolicyBuilder { } @Override - public Policy setTriggerPolicy(String name, String description, String actor, Target target, String recipe, - Map<String, String> payload, Integer retries, Integer timeout) throws BuilderException { + public Policy setTriggerPolicy(String name, String description, String actor, Target target, + String recipe, Map<String, String> payload, Integer retries, Integer timeout) + throws BuilderException { - Policy trigger = new Policy(UUID.randomUUID().toString(), name, description, actor, payload, target, recipe, - retries, timeout); + Policy trigger = new Policy(PolicyParam.builder() + .id(UUID.randomUUID().toString()) + .name(name) + .description(description) + .actor(actor) + .payload(payload) + .target(target) + .recipe(recipe) + .retries(retries) + .timeout(timeout) + .build()); controlLoopPolicy.getControlLoop().setTrigger_policy(trigger.getId()); @@ -231,7 +240,8 @@ public class ControlLoopPolicyBuilderImpl implements ControlLoopPolicyBuilder { @Override public Policy setPolicyForPolicyResult(String name, String description, String actor, Target target, String recipe, - Map<String, String> payload, Integer retries, Integer timeout, String policyId, PolicyResult... results) + Map<String, String> payload, Integer retries, Integer timeout, + String policyId, PolicyResult... results) throws BuilderException { // // Find the existing policy @@ -243,8 +253,17 @@ public class ControlLoopPolicyBuilderImpl implements ControlLoopPolicyBuilder { // // Create the new Policy // - Policy newPolicy = new Policy(UUID.randomUUID().toString(), name, description, actor, payload, target, recipe, - retries, timeout); + Policy newPolicy = new Policy( + PolicyParam.builder().id(UUID.randomUUID().toString()) + .name(name) + .description(description) + .actor(actor) + .payload(payload) + .target(target) + .recipe(recipe) + .retries(retries) + .timeout(timeout) + .build()); // // Connect the results // diff --git a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/PolicyTest.java b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/PolicyTest.java index 6e13b326b..d903b1534 100644 --- a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/PolicyTest.java +++ b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/PolicyTest.java @@ -161,7 +161,17 @@ public class PolicyTest { Target target = new Target(); target.setResourceID("myresourceD"); - policy = new Policy("idD", "nameD", "descD", "actorD", payload, target, "recipeD", 301, 302); + policy = new Policy( + PolicyParam.builder().id("idD") + .name("nameD") + .description("descD") + .actor("actorD") + .payload(payload) + .target(target) + .recipe("recipeD") + .retries(301) + .timeout(302) + .build()); assertEquals("idD", policy.getId()); assertEquals("nameD", policy.getName()); assertEquals("descD", policy.getDescription()); |