Merge "Guard policy Backend"
[clamp.git] / src / main / java / org / onap / clamp / clds / model / properties / PolicyItem.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
6  *                             reserved.
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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  * ===================================================================
21  *
22  */
23
24 package org.onap.clamp.clds.model.properties;
25
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;
30
31 import java.io.IOException;
32 import java.util.List;
33 import java.util.Map;
34
35 import org.onap.clamp.clds.util.JacksonUtils;
36
37 /**
38  * Parse policyConfigurations from Policy json properties.
39  * <p>
40  * Example json:
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"]}]]}]
54  */
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();
58
59     private String id;
60     private String recipe;
61     private int maxRetries;
62     private int retryTimeLimit;
63     private String parentPolicy;
64     private List<String> parentPolicyConditions;
65     private String actor;
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;
73
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;
84
85     /**
86      * Parse Policy given json node.
87      *
88      * @param node
89      * @throws IOException
90      */
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);
101         }
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");
106
107         if (payload != null && !payload.isEmpty()) {
108             recipePayload = JacksonUtils.getObjectMapperInstance().readValue(payload, new TypeReference<Map<String, String>>(){});
109         }
110         oapRop = AbstractModelElement.getValueByName(node, "oapRop");
111         oapLimit = AbstractModelElement.getValueByName(node, "oapLimit");
112         actor = AbstractModelElement.getValueByName(node, "actor");
113
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");
124     }
125
126     /**
127      * @return the id
128      */
129     public String getId() {
130         return id;
131     }
132
133     /**
134      * @return the recipe
135      */
136     public String getRecipe() {
137         return recipe;
138     }
139
140     /**
141      * @set the id
142      */
143     public void setId(String id) {
144         this.id = id;
145     }
146
147     /**
148      * @set the recipe
149      */
150     public void setRecipe(String recipe) {
151         this.recipe = recipe;
152     }
153
154     /**
155      * @set the parentPolicy
156      */
157     public void setParentPolicy(String parentPolicy) {
158         this.parentPolicy = parentPolicy;
159     }
160
161     /**
162      * @set the maxRetries
163      */
164     public void setMaxRetries(int maxRetries) {
165         this.maxRetries = maxRetries;
166     }
167
168     /**
169      * @set the retryTimeLimit
170      */
171     public void setRetryTimeLimit(int retryTimeLimit) {
172         this.retryTimeLimit = retryTimeLimit;
173     }
174
175     /**
176      * @set the parentPolicyConditions
177      */
178     public void setParentPolicyConditions(List<String> parentPolicyConditions) {
179         this.parentPolicyConditions = parentPolicyConditions;
180     }
181
182     /**
183      * @return the maxRetries
184      */
185     public int getMaxRetries() {
186         return maxRetries;
187     }
188
189     /**
190      * @return the retryTimeLimit
191      */
192     public int getRetryTimeLimit() {
193         return retryTimeLimit;
194     }
195
196     /**
197      * @return the parentPolicy
198      */
199     public String getParentPolicy() {
200         return parentPolicy;
201     }
202
203     /**
204      * @return the parentPolicyConditions
205      */
206     public List<String> getParentPolicyConditions() {
207         return parentPolicyConditions;
208     }
209
210     /**
211      * @return the actor
212      */
213     public String getActor() {
214         return actor;
215     }
216
217     /**
218      * @set the actor
219      */
220     public void setActor(String actor) {
221         this.actor = actor;
222     }
223
224     public String getTargetResourceId() {
225         return targetResourceId;
226     }
227
228     public void setTargetResourceId(String targetResourceId) {
229         this.targetResourceId = targetResourceId;
230     }
231
232     public String getRecipeInfo() {
233         return recipeInfo;
234     }
235
236     public String getRecipeLevel() {
237         return recipeLevel;
238     }
239
240     public String getRecipeInput() {
241         return recipeInput;
242     }
243
244     public Map<String, String> getRecipePayload() {
245         return recipePayload;
246     }
247
248     public String getOapRop() {
249         if (oapRop == null) {
250             oapRop = "0m";
251         }
252         return oapRop;
253     }
254
255     public String getOapLimit() {
256         if (oapLimit == null) {
257             oapLimit = "0";
258         }
259         return oapLimit;
260     }
261
262     public String getEnableGuardPolicy() {
263         return enableGuardPolicy;
264     }
265
266     public String getGuardPolicyType() {
267         return guardPolicyType;
268     }
269
270     public String getGuardTargets() {
271         return guardTargets;
272     }
273
274     public String getMinGuard() {
275         return minGuard;
276     }
277
278     public String getMaxGuard() {
279         return maxGuard;
280     }
281
282     public String getLimitGuard() {
283         return limitGuard;
284     }
285
286     public String getTimeUnitsGuard() {
287         return timeUnitsGuard;
288     }
289
290     public String getTimeWindowGuard() {
291         return timeWindowGuard;
292     }
293
294     public String getGuardActiveStart() {
295         return guardActiveStart;
296     }
297
298     public String getGuardActiveEnd() {
299         return guardActiveEnd;
300     }
301
302 }