Add the target resource ID
[clamp.git] / src / main / java / org / onap / clamp / clds / model / prop / PolicyChain.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.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28 import com.fasterxml.jackson.databind.JsonNode;
29
30 import java.util.ArrayList;
31 import java.util.Iterator;
32 import java.util.List;
33
34 /**
35  * Parse Policy json properties.
36  *
37  * Example json:
38  * {"Policy_1e33tn8":{"PolicyTest1":[{"name":"pname","value":"PolicyTest1"},{
39  * "name":"pid","value":"1"},{"name":"timeout","value":"345"},{
40  * "policyConfigurations":[[{"name":"recipe","value":["restart"]},{"name":
41  * "maxRetries","value":["3"]},{"name":"retryTimeLimit","value":["180"]},{"name"
42  * :"_id","value":["q2JmHD5"]},{"name":"parentPolicy","value":[""]}],[{"name":
43  * "recipe","value":["rebuild"]},{"name":"maxRetries","value":["3"]},{"name":
44  * "retryTimeLimit","value":["180"]},{"name":"_id","value":["0ZqHdrR"]},{"name":
45  * "parentPolicy","value":[""]},{"name":
46  * "targetResourceId","value":["Eace933104d443b496b8.nodes.heat.vpg"]}]]}],
47  * "PolicyTest2":[{"name":"pname","value":
48  * "PolicyTest2"},{"name":"pid","value":"2"},{"name":"timeout","value":"345"},{
49  * "policyConfigurations":[[{"name":"recipe","value":["restart"]},{"name":
50  * "maxRetries","value":["3"]},{"name":"retryTimeLimit","value":["180"]},{"name"
51  * :"_id","value":["q2JmHD5"]},{"name":"parentPolicy","value":[""]}],[{"name":
52  * "recipe","value":["rebuild"]},{"name":"maxRetries","value":["3"]},{"name":
53  * "retryTimeLimit","value":["180"]},{"name":"_id","value":["0ZqHdrR"]},{"name":
54  * "parentPolicy","value":[""]},{"name":
55  * "targetResourceId","value":["Eace933104d443b496b8.nodes.heat.vpg"]}]]}]}} f
56  *
57  */
58 public class PolicyChain {
59
60     protected static final EELFLogger logger      = EELFManager.getInstance().getLogger(PolicyChain.class);
61     protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
62
63     private String                    policyId;
64     private Integer                   timeout;
65     private List<PolicyItem>          policyItems;
66
67     public PolicyChain(JsonNode node) {
68
69         policyId = AbstractModelElement.getValueByName(node, "pid");
70         timeout = AbstractModelElement.getIntValueByName(node, "timeout");
71
72         // process policy configurations
73         JsonNode policyNode = node.get(node.size() - 1).get("policyConfigurations");
74         Iterator<JsonNode> itr = policyNode.elements();
75         policyItems = new ArrayList<>();
76         while (itr.hasNext()) {
77             policyItems.add(new PolicyItem(itr.next()));
78         }
79     }
80
81     /**
82      * @return the policyId
83      */
84     public String getPolicyId() {
85         return policyId;
86     }
87
88     /**
89      * @return the timeout
90      */
91     public Integer getTimeout() {
92         return timeout;
93     }
94
95     /**
96      * @return the policyItems
97      */
98     public List<PolicyItem> getPolicyItems() {
99         return policyItems;
100     }
101
102 }