2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 package org.onap.clamp.clds.model.prop;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28 import com.fasterxml.jackson.databind.JsonNode;
30 import java.util.ArrayList;
31 import java.util.Iterator;
32 import java.util.List;
35 * Parse Policy json properties.
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
58 public class PolicyChain {
60 protected static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyChain.class);
61 protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
63 private String policyId;
64 private Integer timeout;
65 private List<PolicyItem> policyItems;
67 public PolicyChain(JsonNode node) {
69 policyId = AbstractModelElement.getValueByName(node, "pid");
70 timeout = AbstractModelElement.getIntValueByName(node, "timeout");
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()));
82 * @return the policyId
84 public String getPolicyId() {
91 public Integer getTimeout() {
96 * @return the policyItems
98 public List<PolicyItem> getPolicyItems() {