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;
36 import org.yaml.snakeyaml.Yaml;
39 * Parse policyConfigurations from Policy json properties.
42 * "Policy_005sny1":[[{"name":"timeout","value":"5"}],{"policyConfigurations":[[
43 * {"name":"recipe","value":["restart"]},{"name":"maxRetries","value":["3"]},{
44 * "name":"retryTimeLimit","value":["180"]},{"name":"_id","value":["vf3RtPi"]},{
45 * "name":"location","value":["san_diego"]},{"name":"resource","value":["vCTS"]}
46 * ,{"name":"onMaxRetriesLimit","value":[""]},{"name":"onTimeLimit","value":[""]
47 * },{"name":"onOtherFailure","value":[""]},{"name":"policy_parent","value":[""]
48 * }],[{"name":"recipe","value":["rebuild"]},{"name":"maxRetries","value":["3"]}
49 * ,{"name":"retryTimeLimit","value":["180"]},{"name":"_id","value":["89z8Ncl"]}
50 * ,{"name":"location","value":["san_diego"]},{"name":"resource","value":["vCTS"
51 * ]},{"name":"onMaxRetriesLimit","value":[""]},{"name":"onTimeLimit","value":[
52 * ""]},{"name":"onOtherFailure","value":[""]},{"name":"policy_parent","value":[
53 * "vf3RtPi"]},{"name":
54 * "targetResourceId","value":["Eace933104d443b496b8.nodes.heat.vpg"]}]]}]
56 public class PolicyItem implements Cloneable {
57 protected static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyItem.class);
58 protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
61 private String recipe;
62 private int maxRetries;
63 private int retryTimeLimit;
64 private String parentPolicy;
65 private List<String> parentPolicyConditions;
67 private String targetResourceId;
68 private String recipeInfo;
69 private String recipeLevel;
70 private String recipeInput;
71 private Map<String, String> recipePayload;
72 private String oapRop;
73 private String oapLimit;
75 private String enableGuardPolicy;
76 private String guardPolicyType;
77 private String guardTargets;
78 private String minGuard;
79 private String maxGuard;
80 private String limitGuard;
81 private String timeUnitsGuard;
82 private String timeWindowGuard;
83 private String guardActiveStart;
84 private String guardActiveEnd;
87 * Parse Policy given json node.
92 public PolicyItem(JsonNode node) throws IOException {
93 id = AbstractModelElement.getValueByName(node, "_id");
94 recipe = AbstractModelElement.getValueByName(node, "recipe");
95 maxRetries = AbstractModelElement.getIntValueByName(node, "maxRetries");
96 retryTimeLimit = AbstractModelElement.getIntValueByName(node, "retryTimeLimit");
97 parentPolicy = AbstractModelElement.getValueByName(node, "parentPolicy");
98 parentPolicyConditions = AbstractModelElement.getValuesByName(node, "parentPolicyConditions");
99 targetResourceId = AbstractModelElement.getValueByName(node, "targetResourceId");
100 if (targetResourceId != null && targetResourceId.isEmpty()) {
101 this.setTargetResourceId(null);
103 recipeInfo = AbstractModelElement.getValueByName(node, "recipeInfo");
104 recipeLevel = AbstractModelElement.getValueByName(node, "recipeLevel");
105 recipeInput = AbstractModelElement.getValueByName(node, "recipeInput");
106 String payload = AbstractModelElement.getValueByName(node, "recipePayload");
108 if (payload != null && !payload.isEmpty()) {
109 if (payload.trim().startsWith("{") && payload.trim().endsWith("}")) {
110 // Seems to be a JSON
111 recipePayload = JacksonUtils.getObjectMapperInstance().readValue(payload,
112 new TypeReference<Map<String, String>>() {
115 // SHould be a YAML then
116 Yaml yaml = new Yaml();
117 recipePayload = (Map<String, String>) yaml.load(payload);
120 oapRop = AbstractModelElement.getValueByName(node, "oapRop");
121 oapLimit = AbstractModelElement.getValueByName(node, "oapLimit");
122 actor = AbstractModelElement.getValueByName(node, "actor");
124 enableGuardPolicy = AbstractModelElement.getValueByName(node, "enableGuardPolicy");
125 guardPolicyType = AbstractModelElement.getValueByName(node, "guardPolicyType");
126 guardTargets = AbstractModelElement.getValueByName(node, "guardTargets");
127 minGuard = AbstractModelElement.getValueByName(node, "minGuard");
128 maxGuard = AbstractModelElement.getValueByName(node, "maxGuard");
129 limitGuard = AbstractModelElement.getValueByName(node, "limitGuard");
130 timeUnitsGuard = AbstractModelElement.getValueByName(node, "timeUnitsGuard");
131 timeWindowGuard = AbstractModelElement.getValueByName(node, "timeWindowGuard");
132 guardActiveStart = AbstractModelElement.getValueByName(node, "guardActiveStart");
133 guardActiveEnd = AbstractModelElement.getValueByName(node, "guardActiveEnd");
139 public String getId() {
146 public String getRecipe() {
153 public void setId(String id) {
160 public void setRecipe(String recipe) {
161 this.recipe = recipe;
165 * @set the parentPolicy
167 public void setParentPolicy(String parentPolicy) {
168 this.parentPolicy = parentPolicy;
172 * @set the maxRetries
174 public void setMaxRetries(int maxRetries) {
175 this.maxRetries = maxRetries;
179 * @set the retryTimeLimit
181 public void setRetryTimeLimit(int retryTimeLimit) {
182 this.retryTimeLimit = retryTimeLimit;
186 * @set the parentPolicyConditions
188 public void setParentPolicyConditions(List<String> parentPolicyConditions) {
189 this.parentPolicyConditions = parentPolicyConditions;
193 * @return the maxRetries
195 public int getMaxRetries() {
200 * @return the retryTimeLimit
202 public int getRetryTimeLimit() {
203 return retryTimeLimit;
207 * @return the parentPolicy
209 public String getParentPolicy() {
214 * @return the parentPolicyConditions
216 public List<String> getParentPolicyConditions() {
217 return parentPolicyConditions;
223 public String getActor() {
230 public void setActor(String actor) {
234 public String getTargetResourceId() {
235 return targetResourceId;
238 public void setTargetResourceId(String targetResourceId) {
239 this.targetResourceId = targetResourceId;
242 public String getRecipeInfo() {
246 public String getRecipeLevel() {
250 public String getRecipeInput() {
254 public Map<String, String> getRecipePayload() {
255 return recipePayload;
258 public String getOapRop() {
259 if (oapRop == null) {
265 public String getOapLimit() {
266 if (oapLimit == null) {
272 public String getEnableGuardPolicy() {
273 return enableGuardPolicy;
276 public String getGuardPolicyType() {
277 return guardPolicyType;
280 public String getGuardTargets() {
284 public String getMinGuard() {
288 public String getMaxGuard() {
292 public String getLimitGuard() {
296 public String getTimeUnitsGuard() {
297 return timeUnitsGuard;
300 public String getTimeWindowGuard() {
301 return timeWindowGuard;
304 public String getGuardActiveStart() {
305 return guardActiveStart;
308 public String getGuardActiveEnd() {
309 return guardActiveEnd;