2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.policy.controlloop.policy;
23 import java.util.Collections;
25 import java.util.UUID;
29 public String id = UUID.randomUUID().toString();
31 public String description;
34 public Map<String, String> payload;
36 public OperationsAccumulateParams operationsAccumulateParams;
37 public Integer retry = 0;
38 public Integer timeout = 300;
39 public String success = FinalResult.FINAL_SUCCESS.toString();
40 public String failure = FinalResult.FINAL_FAILURE.toString();
41 public String failure_retries = FinalResult.FINAL_FAILURE_RETRIES.toString();
42 public String failure_timeout = FinalResult.FINAL_FAILURE_TIMEOUT.toString();
43 public String failure_exception = FinalResult.FINAL_FAILURE_EXCEPTION.toString();
44 public String failure_guard = FinalResult.FINAL_FAILURE_GUARD.toString();
51 public Policy(String id) {
55 public Policy(String name, String actor, String recipe, Map<String, String> payload, Target target) {
60 if (payload != null) {
61 // this.payload = new LinkedList<Map<String, String>>();
62 this.payload = Collections.unmodifiableMap(payload);
66 public Policy(String name, String actor, String recipe, Map<String, String> payload, Target target, Integer retries, Integer timeout) {
67 this(name, actor, recipe, payload, target);
69 this.timeout = timeout;
72 public Policy(String id, String name, String description, String actor, Map<String, String> payload, Target target, String recipe, Integer retries, Integer timeout) {
73 this(name, actor, recipe, payload, target, retries, timeout);
75 this.description = description;
78 public Policy(Policy policy) {
80 this.name = policy.name;
81 this.description = policy.description;
82 this.actor = policy.actor;
83 this.recipe = policy.recipe;
84 if (policy.payload != null) {
85 // this.payload = new LinkedList<Map<String, String>>();
86 // this.payload.addAll(policy.payload);
87 this.payload = Collections.unmodifiableMap(policy.payload);
89 this.target = policy.target;
90 this.operationsAccumulateParams = policy.operationsAccumulateParams;
91 this.retry = policy.retry;
92 this.timeout = policy.timeout;
93 this.success = policy.success;
94 this.failure = policy.failure;
95 this.failure_exception = policy.failure_exception;
96 this.failure_guard = policy.failure_guard;
97 this.failure_retries = policy.failure_retries;
98 this.failure_timeout = policy.failure_timeout;
101 public boolean isValid() {
104 throw new NullPointerException();
107 throw new NullPointerException();
110 throw new NullPointerException();
112 if (recipe == null) {
113 throw new NullPointerException();
115 if (target == null) {
116 throw new NullPointerException();
118 } catch (Exception e) {
126 public String toString() {
127 return "Policy [id=" + id + ", name=" + name + ", description=" + description + ", actor=" + actor + ", recipe="
128 + recipe + ", payload=" + payload + ", target=" + target + ", operationsAccumulateParams=" + operationsAccumulateParams + ", retry=" + retry + ", timeout=" + timeout
129 + ", success=" + success + ", failure=" + failure + ", failure_retries=" + failure_retries
130 + ", failure_timeout=" + failure_timeout + ", failure_exception=" + failure_exception + ", failure_guard=" + failure_guard + "]";
134 public int hashCode() {
135 final int prime = 31;
137 result = prime * result + ((actor == null) ? 0 : actor.hashCode());
138 result = prime * result + ((description == null) ? 0 : description.hashCode());
139 result = prime * result + ((failure == null) ? 0 : failure.hashCode());
140 result = prime * result + ((failure_exception == null) ? 0 : failure_exception.hashCode());
141 result = prime * result + ((failure_guard == null) ? 0 : failure_guard.hashCode());
142 result = prime * result + ((failure_retries == null) ? 0 : failure_retries.hashCode());
143 result = prime * result + ((failure_timeout == null) ? 0 : failure_timeout.hashCode());
144 result = prime * result + ((id == null) ? 0 : id.hashCode());
145 result = prime * result + ((name == null) ? 0 : name.hashCode());
146 result = prime * result + ((payload == null) ? 0 : payload.hashCode());
147 result = prime * result + ((recipe == null) ? 0 : recipe.hashCode());
148 result = prime * result + ((retry == null) ? 0 : retry.hashCode());
149 result = prime * result + ((success == null) ? 0 : success.hashCode());
150 result = prime * result + ((target == null) ? 0 : target.hashCode());
151 result = prime * result + ((operationsAccumulateParams == null) ? 0 : operationsAccumulateParams.hashCode());
152 result = prime * result + ((timeout == null) ? 0 : timeout.hashCode());
157 public boolean equals(Object obj) {
162 if (getClass() != obj.getClass())
164 Policy other = (Policy) obj;
165 if (actor != other.actor)
167 if (description == null) {
168 if (other.description != null)
170 } else if (!description.equals(other.description))
172 if (failure == null) {
173 if (other.failure != null)
175 } else if (!failure.equals(other.failure))
177 if (failure_exception == null) {
178 if (other.failure_exception != null)
180 } else if (!failure_exception.equals(other.failure_exception))
182 if (failure_guard == null) {
183 if (other.failure_guard != null)
185 } else if (!failure_guard.equals(other.failure_guard))
187 if (failure_retries == null) {
188 if (other.failure_retries != null)
190 } else if (!failure_retries.equals(other.failure_retries))
192 if (failure_timeout == null) {
193 if (other.failure_timeout != null)
195 } else if (!failure_timeout.equals(other.failure_timeout))
198 if (other.id != null)
200 } else if (!id.equals(other.id))
203 if (other.name != null)
205 } else if (!name.equals(other.name))
207 if (payload == null) {
208 if (other.payload != null)
210 } else if (!payload.equals(other.payload))
212 if (recipe == null) {
213 if (other.recipe != null)
215 } else if (!recipe.equals(other.recipe))
218 if (other.retry != null)
220 } else if (!retry.equals(other.retry))
222 if (success == null) {
223 if (other.success != null)
225 } else if (!success.equals(other.success))
227 if (operationsAccumulateParams == null) {
228 if (other.operationsAccumulateParams != null)
230 } else if (!operationsAccumulateParams.equals(other.operationsAccumulateParams))
232 if (target == null) {
233 if (other.target != null)
235 } else if (!target.equals(other.target))
237 if (timeout == null) {
238 if (other.timeout != null)
240 } else if (!timeout.equals(other.timeout))