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 java.util.ArrayList;
27 import java.util.Iterator;
28 import java.util.List;
30 import com.att.eelf.configuration.EELFLogger;
31 import com.att.eelf.configuration.EELFManager;
32 import com.fasterxml.jackson.databind.JsonNode;
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":[""]}]]}],"PolicyTest2":[{"name":"pname","value":
46 * "PolicyTest2"},{"name":"pid","value":"2"},{"name":"timeout","value":"345"},{
47 * "policyConfigurations":[[{"name":"recipe","value":["restart"]},{"name":
48 * "maxRetries","value":["3"]},{"name":"retryTimeLimit","value":["180"]},{"name"
49 * :"_id","value":["q2JmHD5"]},{"name":"parentPolicy","value":[""]}],[{"name":
50 * "recipe","value":["rebuild"]},{"name":"maxRetries","value":["3"]},{"name":
51 * "retryTimeLimit","value":["180"]},{"name":"_id","value":["0ZqHdrR"]},{"name":
52 * "parentPolicy","value":[""]}]]}]}} f
55 public class PolicyChain {
57 protected static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyChain.class);
58 protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
60 private String policyId;
61 private Integer timeout;
62 private List<PolicyItem> policyItems;
64 public PolicyChain(JsonNode node) {
66 policyId = ModelElement.getValueByName(node, "pid");
67 timeout = ModelElement.getIntValueByName(node, "timeout");
69 // process policy configurations
70 JsonNode policyNode = node.get(node.size() - 1).get("policyConfigurations");
71 Iterator<JsonNode> itr = policyNode.elements();
72 policyItems = new ArrayList<PolicyItem>();
73 while (itr.hasNext()) {
74 policyItems.add(new PolicyItem(itr.next()));
79 * @return the policyId
81 public String getPolicyId() {
88 public Integer getTimeout() {
93 * @return the policyItems
95 public List<PolicyItem> getPolicyItems() {