c84affefe648e1dea2291debdeed3112f22f54e5
[clamp.git] / src / main / java / org / onap / clamp / clds / model / prop / PolicyItem.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017 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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23
24 package org.onap.clamp.clds.model.prop;
25
26 import java.util.List;
27
28 import com.att.eelf.configuration.EELFLogger;
29 import com.att.eelf.configuration.EELFManager;
30 import com.fasterxml.jackson.databind.JsonNode;
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"]}]]}]
48  */
49 public class PolicyItem implements Cloneable {
50     protected static final EELFLogger       logger      = EELFManager.getInstance().getLogger(PolicyItem.class);
51     protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
52
53     private String                  id;
54     private String                  recipe;
55     private int                     maxRetries;
56     private int                     retryTimeLimit;
57     private String                  parentPolicy;
58     private List<String>            parentPolicyConditions;
59     private String                  actor;
60
61     /**
62      * Parse Policy given json node.
63      *
64      * @param node
65      */
66     public PolicyItem(JsonNode node) {
67         id = AbstractModelElement.getValueByName(node, "_id");
68         recipe = AbstractModelElement.getValueByName(node, "recipe");
69         maxRetries = AbstractModelElement.getIntValueByName(node, "maxRetries");
70         retryTimeLimit = AbstractModelElement.getIntValueByName(node, "retryTimeLimit");
71         parentPolicy = AbstractModelElement.getValueByName(node, "parentPolicy");
72         parentPolicyConditions = AbstractModelElement.getValuesByName(node, "parentPolicyConditions");
73
74     }
75
76     /**
77      * @return the id
78      */
79     public String getId() {
80         return id;
81     }
82
83     /**
84      * @return the recipe
85      */
86     public String getRecipe() {
87         return recipe;
88     }
89
90     /**
91      * @set the id
92      */
93     public void setId(String id) {
94         this.id = id;
95     }
96
97     /**
98      * @set the recipe
99      */
100     public void setRecipe(String recipe) {
101         this.recipe = recipe;
102     }
103
104     /**
105      * @set the parentPolicy
106      */
107     public void setParentPolicy(String parentPolicy) {
108         this.parentPolicy = parentPolicy;
109     }
110
111     /**
112      * @set the maxRetries
113      */
114     public void setMaxRetries(int maxRetries) {
115         this.maxRetries = maxRetries;
116     }
117
118     /**
119      * @set the retryTimeLimit
120      */
121     public void setRetryTimeLimit(int retryTimeLimit) {
122         this.retryTimeLimit = retryTimeLimit;
123     }
124
125     /**
126      * @set the parentPolicyConditions
127      */
128     public void setParentPolicyConditions(List<String> parentPolicyConditions) {
129         this.parentPolicyConditions = parentPolicyConditions;
130     }
131
132     /**
133      * @return the maxRetries
134      */
135     public int getMaxRetries() {
136         return maxRetries;
137     }
138
139     /**
140      * @return the retryTimeLimit
141      */
142     public int getRetryTimeLimit() {
143         return retryTimeLimit;
144     }
145
146     /**
147      * @return the parentPolicy
148      */
149     public String getParentPolicy() {
150         return parentPolicy;
151     }
152
153     /**
154      * @return the parentPolicyConditions
155      */
156     public List<String> getParentPolicyConditions() {
157         return parentPolicyConditions;
158     }
159
160     /**
161      * @return the actor
162      */
163     public String getActor() {
164         return actor;
165     }
166
167     /**
168      * @set the actor
169      */
170     public void setActor(String actor) {
171         this.actor = actor;
172     }
173
174     @Override
175     public Object clone() throws CloneNotSupportedException {
176         return super.clone();
177     }
178 }