[CLAMP-1] Initial ONAP CLAMP seed code commit
[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 com.fasterxml.jackson.databind.JsonNode;
27
28 import java.util.List;
29 import java.util.logging.Logger;
30
31 /**
32  * Parse policyConfigurations from Policy json properties.
33  * <p>
34  * Example json: "Policy_005sny1":[[{"name":"timeout","value":"5"}],{"policyConfigurations":[[{"name":"recipe","value":["restart"]},{"name":"maxRetries","value":["3"]},{"name":"retryTimeLimit","value":["180"]},{"name":"_id","value":["vf3RtPi"]},{"name":"location","value":["san_diego"]},{"name":"resource","value":["vCTS"]},{"name":"onMaxRetriesLimit","value":[""]},{"name":"onTimeLimit","value":[""]},{"name":"onOtherFailure","value":[""]},{"name":"policy_parent","value":[""]}],[{"name":"recipe","value":["rebuild"]},{"name":"maxRetries","value":["3"]},{"name":"retryTimeLimit","value":["180"]},{"name":"_id","value":["89z8Ncl"]},{"name":"location","value":["san_diego"]},{"name":"resource","value":["vCTS"]},{"name":"onMaxRetriesLimit","value":[""]},{"name":"onTimeLimit","value":[""]},{"name":"onOtherFailure","value":[""]},{"name":"policy_parent","value":["vf3RtPi"]}]]}]
35  */
36 public class PolicyItem {
37     private static final Logger logger = Logger.getLogger(Policy.class.getName());
38
39     private final String id;
40     private final String recipe;
41     private final int maxRetries;
42     private final int retryTimeLimit;
43     private final String parentPolicy;
44     private final List<String> parentPolicyConditions;
45
46     /**
47      * Parse Policy given json node.
48      *
49      * @param node
50      */
51     public PolicyItem(JsonNode node) {
52         id = ModelElement.getValueByName(node, "_id");
53         recipe = ModelElement.getValueByName(node, "recipe");
54         maxRetries = ModelElement.getIntValueByName(node, "maxRetries");
55         retryTimeLimit = ModelElement.getIntValueByName(node, "retryTimeLimit");
56         parentPolicy = ModelElement.getValueByName(node, "parentPolicy");
57         parentPolicyConditions = ModelElement.getValuesByName(node, "parentPolicyConditions");
58
59     }
60
61     /**
62      * @return the id
63      */
64     public String getId() {
65         return id;
66     }
67
68     /**
69      * @return the recipe
70      */
71     public String getRecipe() {
72         return recipe;
73     }
74
75     /**
76      * @return the maxRetries
77      */
78     public int getMaxRetries() {
79         return maxRetries;
80     }
81
82     /**
83      * @return the retryTimeLimit
84      */
85     public int getRetryTimeLimit() {
86         return retryTimeLimit;
87     }
88
89     /**
90      * @return the parentPolicy
91      */
92     public String getParentPolicy() {
93         return parentPolicy;
94     }
95
96     /**
97      * @return the parentPolicyConditions
98      */
99     public List<String> getParentPolicyConditions() {
100         return parentPolicyConditions;
101     }
102
103 }