2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
24 package org.onap.clamp.clds.model.properties;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
29 import com.google.gson.JsonElement;
30 import com.google.gson.reflect.TypeToken;
31 import java.io.IOException;
32 import java.util.List;
35 import org.onap.clamp.clds.util.JsonUtils;
36 import org.yaml.snakeyaml.Yaml;
39 * Parse policyConfigurations from Policy json properties.
41 * "Policy_005sny1":[[{"name":"timeout","value":"5"}],{"policyConfigurations":[[
42 * {"name":"recipe","value":["restart"]},{"name":"maxRetries","value":["3"]},{
43 * "name":"retryTimeLimit","value":["180"]},{"name":"_id","value":["vf3RtPi"]},{
44 * "name":"location","value":["san_diego"]},{"name":"resource","value":["vCTS"]}
45 * ,{"name":"onMaxRetriesLimit","value":[""]},{"name":"onTimeLimit","value":[""]
46 * },{"name":"onOtherFailure","value":[""]},{"name":"policy_parent","value":[""]
47 * }],[{"name":"recipe","value":["rebuild"]},{"name":"maxRetries","value":["3"]}
48 * ,{"name":"retryTimeLimit","value":["180"]},{"name":"_id","value":["89z8Ncl"]}
49 * ,{"name":"location","value":["san_diego"]},{"name":"resource","value":["vCTS"
50 * ]},{"name":"onMaxRetriesLimit","value":[""]},{"name":"onTimeLimit","value":[
51 * ""]},{"name":"onOtherFailure","value":[""]},{"name":"policy_parent","value":[
52 * "vf3RtPi"]},{"name":
53 * "targetResourceId","value":["Eace933104d443b496b8.nodes.heat.vpg"]}]]}]
55 public class PolicyItem implements Cloneable {
56 protected static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyItem.class);
57 protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
60 private String recipe;
61 private int maxRetries;
62 private int retryTimeLimit;
63 private String parentPolicy;
64 private List<String> parentPolicyConditions;
66 private String targetResourceId;
67 private String recipeInfo;
68 private String recipeLevel;
69 private String recipeInput;
70 private Map<String, String> recipePayload;
71 private String oapRop;
72 private String oapLimit;
74 private String enableGuardPolicy;
75 private String guardPolicyType;
76 private String guardTargets;
77 private String minGuard;
78 private String maxGuard;
79 private String limitGuard;
80 private String timeUnitsGuard;
81 private String timeWindowGuard;
82 private String guardActiveStart;
83 private String guardActiveEnd;
86 * Parse Policy given json node.
91 public PolicyItem(JsonElement item) throws IOException {
92 id = JsonUtils.getStringValueByName(item, "_id");
93 recipe = JsonUtils.getStringValueByName(item, "recipe");
94 maxRetries = JsonUtils.getIntValueByName(item, "maxRetries");
95 retryTimeLimit = JsonUtils.getIntValueByName(item, "retryTimeLimit");
96 parentPolicy = JsonUtils.getStringValueByName(item, "parentPolicy");
97 parentPolicyConditions = JsonUtils.getStringValuesByName(item, "parentPolicyConditions");
98 targetResourceId = JsonUtils.getStringValueByName(item, "targetResourceId");
99 if (targetResourceId != null && targetResourceId.isEmpty()) {
100 this.setTargetResourceId(null);
102 recipeInfo = JsonUtils.getStringValueByName(item, "recipeInfo");
103 recipeLevel = JsonUtils.getStringValueByName(item, "recipeLevel");
104 recipeInput = JsonUtils.getStringValueByName(item, "recipeInput");
105 String payload = JsonUtils.getStringValueByName(item, "recipePayload");
107 if (payload != null && !payload.isEmpty()) {
108 if (payload.trim().startsWith("{") && payload.trim().endsWith("}")) {
109 // Seems to be a JSON
110 recipePayload = JsonUtils.GSON.fromJson(payload, new TypeToken<Map<String, String>>() {}.getType());
112 // SHould be a YAML then
113 recipePayload = new Yaml().load(payload);
116 oapRop = JsonUtils.getStringValueByName(item, "oapRop");
117 oapLimit = JsonUtils.getStringValueByName(item, "oapLimit");
118 actor = JsonUtils.getStringValueByName(item, "actor");
120 enableGuardPolicy = JsonUtils.getStringValueByName(item, "enableGuardPolicy");
121 guardPolicyType = JsonUtils.getStringValueByName(item, "guardPolicyType");
122 guardTargets = JsonUtils.getStringValueByName(item, "guardTargets");
123 minGuard = JsonUtils.getStringValueByName(item, "minGuard");
124 maxGuard = JsonUtils.getStringValueByName(item, "maxGuard");
125 limitGuard = JsonUtils.getStringValueByName(item, "limitGuard");
126 timeUnitsGuard = JsonUtils.getStringValueByName(item, "timeUnitsGuard");
127 timeWindowGuard = JsonUtils.getStringValueByName(item, "timeWindowGuard");
128 guardActiveStart = JsonUtils.getStringValueByName(item, "guardActiveStart");
129 guardActiveEnd = JsonUtils.getStringValueByName(item, "guardActiveEnd");
136 public String getId() {
144 public String getRecipe() {
152 public void setId(String id) {
160 public void setRecipe(String recipe) {
161 this.recipe = recipe;
165 * Set the parent policy.
166 * @param the parentPolicy
168 public void setParentPolicy(String parentPolicy) {
169 this.parentPolicy = parentPolicy;
173 * Set the max retries.
174 * @param the maxRetries
176 public void setMaxRetries(int maxRetries) {
177 this.maxRetries = maxRetries;
181 * Set the retry time limit.
182 * @param the retryTimeLimit
184 public void setRetryTimeLimit(int retryTimeLimit) {
185 this.retryTimeLimit = retryTimeLimit;
189 * Set the parent policy conditions.
190 * @param the parentPolicyConditions
192 public void setParentPolicyConditions(List<String> parentPolicyConditions) {
193 this.parentPolicyConditions = parentPolicyConditions;
197 * Get the max retires.
198 * @return the maxRetries
200 public int getMaxRetries() {
205 * Get the retry time limit.
206 * @return the retryTimeLimit
208 public int getRetryTimeLimit() {
209 return retryTimeLimit;
213 * Get the parent policy.
214 * @return the parentPolicy
216 public String getParentPolicy() {
221 * Get the list of parent policy conditions.
222 * @return the parentPolicyConditions
224 public List<String> getParentPolicyConditions() {
225 return parentPolicyConditions;
232 public String getActor() {
240 public void setActor(String actor) {
244 public String getTargetResourceId() {
245 return targetResourceId;
248 public void setTargetResourceId(String targetResourceId) {
249 this.targetResourceId = targetResourceId;
252 public String getRecipeInfo() {
256 public String getRecipeLevel() {
260 public String getRecipeInput() {
264 public Map<String, String> getRecipePayload() {
265 return recipePayload;
270 * @return The oap rop?
272 public String getOapRop() {
273 if (oapRop == null) {
281 * @return the oap limit
283 public String getOapLimit() {
284 if (oapLimit == null) {
290 public String getEnableGuardPolicy() {
291 return enableGuardPolicy;
294 public String getGuardPolicyType() {
295 return guardPolicyType;
298 public String getGuardTargets() {
302 public String getMinGuard() {
306 public String getMaxGuard() {
310 public String getLimitGuard() {
314 public String getTimeUnitsGuard() {
315 return timeUnitsGuard;
318 public String getTimeWindowGuard() {
319 return timeWindowGuard;
322 public String getGuardActiveStart() {
323 return guardActiveStart;
326 public String getGuardActiveEnd() {
327 return guardActiveEnd;