Merge "logstash input"
[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     /**
75      * Parse Policy given json node.
76      *
77      * @param node
78      * @throws IOException
79      */
80     public PolicyItem(JsonNode node) throws IOException {
81         id = AbstractModelElement.getValueByName(node, "_id");
82         recipe = AbstractModelElement.getValueByName(node, "recipe");
83         maxRetries = AbstractModelElement.getIntValueByName(node, "maxRetries");
84         retryTimeLimit = AbstractModelElement.getIntValueByName(node, "retryTimeLimit");
85         parentPolicy = AbstractModelElement.getValueByName(node, "parentPolicy");
86         parentPolicyConditions = AbstractModelElement.getValuesByName(node, "parentPolicyConditions");
87         targetResourceId = AbstractModelElement.getValueByName(node, "targetResourceId");
88         if (targetResourceId != null && targetResourceId.isEmpty()) {
89             this.setTargetResourceId(null);
90         }
91         recipeInfo = AbstractModelElement.getValueByName(node, "recipeInfo");
92         recipeLevel = AbstractModelElement.getValueByName(node, "recipeLevel");
93         recipeInput = AbstractModelElement.getValueByName(node, "recipeInput");
94         String payload = AbstractModelElement.getValueByName(node, "recipePayload");
95
96         if (payload != null && !payload.isEmpty()) {
97             recipePayload = JacksonUtils.getObjectMapperInstance().readValue(payload, new TypeReference<Map<String, String>>(){});
98         }
99         oapRop = AbstractModelElement.getValueByName(node, "oapRop");
100         oapLimit = AbstractModelElement.getValueByName(node, "oapLimit");
101         actor = AbstractModelElement.getValueByName(node, "actor");
102     }
103
104     /**
105      * @return the id
106      */
107     public String getId() {
108         return id;
109     }
110
111     /**
112      * @return the recipe
113      */
114     public String getRecipe() {
115         return recipe;
116     }
117
118     /**
119      * @set the id
120      */
121     public void setId(String id) {
122         this.id = id;
123     }
124
125     /**
126      * @set the recipe
127      */
128     public void setRecipe(String recipe) {
129         this.recipe = recipe;
130     }
131
132     /**
133      * @set the parentPolicy
134      */
135     public void setParentPolicy(String parentPolicy) {
136         this.parentPolicy = parentPolicy;
137     }
138
139     /**
140      * @set the maxRetries
141      */
142     public void setMaxRetries(int maxRetries) {
143         this.maxRetries = maxRetries;
144     }
145
146     /**
147      * @set the retryTimeLimit
148      */
149     public void setRetryTimeLimit(int retryTimeLimit) {
150         this.retryTimeLimit = retryTimeLimit;
151     }
152
153     /**
154      * @set the parentPolicyConditions
155      */
156     public void setParentPolicyConditions(List<String> parentPolicyConditions) {
157         this.parentPolicyConditions = parentPolicyConditions;
158     }
159
160     /**
161      * @return the maxRetries
162      */
163     public int getMaxRetries() {
164         return maxRetries;
165     }
166
167     /**
168      * @return the retryTimeLimit
169      */
170     public int getRetryTimeLimit() {
171         return retryTimeLimit;
172     }
173
174     /**
175      * @return the parentPolicy
176      */
177     public String getParentPolicy() {
178         return parentPolicy;
179     }
180
181     /**
182      * @return the parentPolicyConditions
183      */
184     public List<String> getParentPolicyConditions() {
185         return parentPolicyConditions;
186     }
187
188     /**
189      * @return the actor
190      */
191     public String getActor() {
192         return actor;
193     }
194
195     /**
196      * @set the actor
197      */
198     public void setActor(String actor) {
199         this.actor = actor;
200     }
201
202     public String getTargetResourceId() {
203         return targetResourceId;
204     }
205
206     public void setTargetResourceId(String targetResourceId) {
207         this.targetResourceId = targetResourceId;
208     }
209
210     public String getRecipeInfo() {
211         return recipeInfo;
212     }
213
214     public String getRecipeLevel() {
215         return recipeLevel;
216     }
217
218     public String getRecipeInput() {
219         return recipeInput;
220     }
221
222     public Map<String, String> getRecipePayload() {
223         return recipePayload;
224     }
225
226     public String getOapRop() {
227         if (oapRop == null) {
228             oapRop = "0m";
229         }
230         return oapRop;
231     }
232
233     public String getOapLimit() {
234         if (oapLimit == null) {
235             oapLimit = "0";
236         }
237         return oapLimit;
238     }
239 }