75bf6ae39fc0118c1d425d35cf37001fa5986df6
[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.databind.JsonNode;
29
30 import java.util.List;
31
32 /**
33  * Parse policyConfigurations from Policy json properties.
34  * <p>
35  * Example json:
36  * "Policy_005sny1":[[{"name":"timeout","value":"5"}],{"policyConfigurations":[[
37  * {"name":"recipe","value":["restart"]},{"name":"maxRetries","value":["3"]},{
38  * "name":"retryTimeLimit","value":["180"]},{"name":"_id","value":["vf3RtPi"]},{
39  * "name":"location","value":["san_diego"]},{"name":"resource","value":["vCTS"]}
40  * ,{"name":"onMaxRetriesLimit","value":[""]},{"name":"onTimeLimit","value":[""]
41  * },{"name":"onOtherFailure","value":[""]},{"name":"policy_parent","value":[""]
42  * }],[{"name":"recipe","value":["rebuild"]},{"name":"maxRetries","value":["3"]}
43  * ,{"name":"retryTimeLimit","value":["180"]},{"name":"_id","value":["89z8Ncl"]}
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  * "vf3RtPi"]},{"name":
48  * "targetResourceId","value":["Eace933104d443b496b8.nodes.heat.vpg"]}]]}]
49  */
50 public class PolicyItem implements Cloneable {
51     protected static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyItem.class);
52     protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
53
54     private String id;
55     private String recipe;
56     private int maxRetries;
57     private int retryTimeLimit;
58     private String parentPolicy;
59     private List<String> parentPolicyConditions;
60     private String actor;
61     private String targetResourceId;
62     private String recipeInfo;
63     private String recipeLevel;
64     private String recipePayload;
65     private String oapRop;
66     private String oapLimit;
67
68     /**
69      * Parse Policy given json node.
70      *
71      * @param node
72      */
73     public PolicyItem(JsonNode node) {
74         id = AbstractModelElement.getValueByName(node, "_id");
75         recipe = AbstractModelElement.getValueByName(node, "recipe");
76         maxRetries = AbstractModelElement.getIntValueByName(node, "maxRetries");
77         retryTimeLimit = AbstractModelElement.getIntValueByName(node, "retryTimeLimit");
78         parentPolicy = AbstractModelElement.getValueByName(node, "parentPolicy");
79         parentPolicyConditions = AbstractModelElement.getValuesByName(node, "parentPolicyConditions");
80         targetResourceId = AbstractModelElement.getValueByName(node, "targetResourceId");
81         if (targetResourceId != null && targetResourceId.isEmpty()) {
82             this.setTargetResourceId(null);
83         }
84         recipeInfo = AbstractModelElement.getValueByName(node, "recipeInfo");
85         recipeLevel = AbstractModelElement.getValueByName(node, "recipeLevel");
86         recipePayload = AbstractModelElement.getValueByName(node, "recipeInput");
87         oapRop = AbstractModelElement.getValueByName(node, "oapRop");
88         oapLimit = AbstractModelElement.getValueByName(node, "oapLimit");
89     }
90
91     /**
92      * @return the id
93      */
94     public String getId() {
95         return id;
96     }
97
98     /**
99      * @return the recipe
100      */
101     public String getRecipe() {
102         return recipe;
103     }
104
105     /**
106      * @set the id
107      */
108     public void setId(String id) {
109         this.id = id;
110     }
111
112     /**
113      * @set the recipe
114      */
115     public void setRecipe(String recipe) {
116         this.recipe = recipe;
117     }
118
119     /**
120      * @set the parentPolicy
121      */
122     public void setParentPolicy(String parentPolicy) {
123         this.parentPolicy = parentPolicy;
124     }
125
126     /**
127      * @set the maxRetries
128      */
129     public void setMaxRetries(int maxRetries) {
130         this.maxRetries = maxRetries;
131     }
132
133     /**
134      * @set the retryTimeLimit
135      */
136     public void setRetryTimeLimit(int retryTimeLimit) {
137         this.retryTimeLimit = retryTimeLimit;
138     }
139
140     /**
141      * @set the parentPolicyConditions
142      */
143     public void setParentPolicyConditions(List<String> parentPolicyConditions) {
144         this.parentPolicyConditions = parentPolicyConditions;
145     }
146
147     /**
148      * @return the maxRetries
149      */
150     public int getMaxRetries() {
151         return maxRetries;
152     }
153
154     /**
155      * @return the retryTimeLimit
156      */
157     public int getRetryTimeLimit() {
158         return retryTimeLimit;
159     }
160
161     /**
162      * @return the parentPolicy
163      */
164     public String getParentPolicy() {
165         return parentPolicy;
166     }
167
168     /**
169      * @return the parentPolicyConditions
170      */
171     public List<String> getParentPolicyConditions() {
172         return parentPolicyConditions;
173     }
174
175     /**
176      * @return the actor
177      */
178     public String getActor() {
179         return actor;
180     }
181
182     /**
183      * @set the actor
184      */
185     public void setActor(String actor) {
186         this.actor = actor;
187     }
188
189     public String getTargetResourceId() {
190         return targetResourceId;
191     }
192
193     public void setTargetResourceId(String targetResourceId) {
194         this.targetResourceId = targetResourceId;
195     }
196
197     public String getRecipeInfo() {
198         return recipeInfo;
199     }
200
201     public String getRecipeLevel() {
202         return recipeLevel;
203     }
204
205     public String getRecipePayload() {
206         return recipePayload;
207     }
208
209     public String getOapRop() {
210         if (oapRop == null) {
211             oapRop = "0m";
212         }
213         return oapRop;
214     }
215
216     public String getOapLimit() {
217         if (oapLimit == null) {
218             oapLimit = "0";
219         }
220         return oapLimit;
221     }
222
223     @Override
224     public Object clone() throws CloneNotSupportedException {
225         return super.clone();
226     }
227 }