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;
28 import com.fasterxml.jackson.core.type.TypeReference;
29 import com.fasterxml.jackson.databind.JsonNode;
31 import java.io.IOException;
32 import java.util.List;
35 import org.onap.clamp.clds.util.JacksonUtils;
38 * 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(JsonNode node) throws IOException {
92 id = AbstractModelElement.getValueByName(node, "_id");
93 recipe = AbstractModelElement.getValueByName(node, "recipe");
94 maxRetries = AbstractModelElement.getIntValueByName(node, "maxRetries");
95 retryTimeLimit = AbstractModelElement.getIntValueByName(node, "retryTimeLimit");
96 parentPolicy = AbstractModelElement.getValueByName(node, "parentPolicy");
97 parentPolicyConditions = AbstractModelElement.getValuesByName(node, "parentPolicyConditions");
98 targetResourceId = AbstractModelElement.getValueByName(node, "targetResourceId");
99 if (targetResourceId != null && targetResourceId.isEmpty()) {
100 this.setTargetResourceId(null);
102 recipeInfo = AbstractModelElement.getValueByName(node, "recipeInfo");
103 recipeLevel = AbstractModelElement.getValueByName(node, "recipeLevel");
104 recipeInput = AbstractModelElement.getValueByName(node, "recipeInput");
105 String payload = AbstractModelElement.getValueByName(node, "recipePayload");
107 if (payload != null && !payload.isEmpty()) {
108 recipePayload = JacksonUtils.getObjectMapperInstance().readValue(payload, new TypeReference<Map<String, String>>(){});
110 oapRop = AbstractModelElement.getValueByName(node, "oapRop");
111 oapLimit = AbstractModelElement.getValueByName(node, "oapLimit");
112 actor = AbstractModelElement.getValueByName(node, "actor");
114 enableGuardPolicy = AbstractModelElement.getValueByName(node, "enableGuardPolicy");
115 guardPolicyType = AbstractModelElement.getValueByName(node, "guardPolicyType");
116 guardTargets = AbstractModelElement.getValueByName(node, "guardTargets");
117 minGuard = AbstractModelElement.getValueByName(node, "minGuard");
118 maxGuard = AbstractModelElement.getValueByName(node, "maxGuard");
119 limitGuard = AbstractModelElement.getValueByName(node, "limitGuard");
120 timeUnitsGuard = AbstractModelElement.getValueByName(node, "timeUnitsGuard");
121 timeWindowGuard = AbstractModelElement.getValueByName(node, "timeWindowGuard");
122 guardActiveStart = AbstractModelElement.getValueByName(node, "guardActiveStart");
123 guardActiveEnd = AbstractModelElement.getValueByName(node, "guardActiveEnd");
129 public String getId() {
136 public String getRecipe() {
143 public void setId(String id) {
150 public void setRecipe(String recipe) {
151 this.recipe = recipe;
155 * @set the parentPolicy
157 public void setParentPolicy(String parentPolicy) {
158 this.parentPolicy = parentPolicy;
162 * @set the maxRetries
164 public void setMaxRetries(int maxRetries) {
165 this.maxRetries = maxRetries;
169 * @set the retryTimeLimit
171 public void setRetryTimeLimit(int retryTimeLimit) {
172 this.retryTimeLimit = retryTimeLimit;
176 * @set the parentPolicyConditions
178 public void setParentPolicyConditions(List<String> parentPolicyConditions) {
179 this.parentPolicyConditions = parentPolicyConditions;
183 * @return the maxRetries
185 public int getMaxRetries() {
190 * @return the retryTimeLimit
192 public int getRetryTimeLimit() {
193 return retryTimeLimit;
197 * @return the parentPolicy
199 public String getParentPolicy() {
204 * @return the parentPolicyConditions
206 public List<String> getParentPolicyConditions() {
207 return parentPolicyConditions;
213 public String getActor() {
220 public void setActor(String actor) {
224 public String getTargetResourceId() {
225 return targetResourceId;
228 public void setTargetResourceId(String targetResourceId) {
229 this.targetResourceId = targetResourceId;
232 public String getRecipeInfo() {
236 public String getRecipeLevel() {
240 public String getRecipeInput() {
244 public Map<String, String> getRecipePayload() {
245 return recipePayload;
248 public String getOapRop() {
249 if (oapRop == null) {
255 public String getOapLimit() {
256 if (oapLimit == null) {
262 public String getEnableGuardPolicy() {
263 return enableGuardPolicy;
266 public String getGuardPolicyType() {
267 return guardPolicyType;
270 public String getGuardTargets() {
274 public String getMinGuard() {
278 public String getMaxGuard() {
282 public String getLimitGuard() {
286 public String getTimeUnitsGuard() {
287 return timeUnitsGuard;
290 public String getTimeWindowGuard() {
291 return timeWindowGuard;
294 public String getGuardActiveStart() {
295 return guardActiveStart;
298 public String getGuardActiveEnd() {
299 return guardActiveEnd;