2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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 * ===================================================================
24 package org.onap.clamp.clds.model.properties;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28 import com.fasterxml.jackson.core.type.TypeReference;
29 import com.fasterxml.jackson.databind.JsonNode;
31 import java.io.IOException;
32 import java.util.List;
35 import org.onap.clamp.clds.util.JacksonUtils;
38 * Parse policyConfigurations from Policy json properties.
41 * "Policy_005sny1":[[{"name":"timeout","value":"5"}],{"policyConfigurations":[[
42 * {"name":"recipe","value":["restart"]},{"name":"maxRetries","value":["3"]},{
43 * "name":"retryTimeLimit","value":["180"]},{"name":"_id","value":["vf3RtPi"]},{
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 * }],[{"name":"recipe","value":["rebuild"]},{"name":"maxRetries","value":["3"]}
48 * ,{"name":"retryTimeLimit","value":["180"]},{"name":"_id","value":["89z8Ncl"]}
49 * ,{"name":"location","value":["san_diego"]},{"name":"resource","value":["vCTS"
50 * ]},{"name":"onMaxRetriesLimit","value":[""]},{"name":"onTimeLimit","value":[
51 * ""]},{"name":"onOtherFailure","value":[""]},{"name":"policy_parent","value":[
52 * "vf3RtPi"]},{"name":
53 * "targetResourceId","value":["Eace933104d443b496b8.nodes.heat.vpg"]}]]}]
55 public class PolicyItem implements Cloneable {
56 protected static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyItem.class);
57 protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
60 private String recipe;
61 private int maxRetries;
62 private int retryTimeLimit;
63 private String parentPolicy;
64 private List<String> parentPolicyConditions;
66 private String targetResourceId;
67 private String recipeInfo;
68 private String recipeLevel;
69 private String recipeInput;
70 private Map<String, String> recipePayload;
71 private String oapRop;
72 private String oapLimit;
75 * Parse Policy given json node.
80 public PolicyItem(JsonNode node) throws IOException {
81 id = AbstractModelElement.getValueByName(node, "_id");
82 recipe = AbstractModelElement.getValueByName(node, "recipe");
83 maxRetries = AbstractModelElement.getIntValueByName(node, "maxRetries");
84 retryTimeLimit = AbstractModelElement.getIntValueByName(node, "retryTimeLimit");
85 parentPolicy = AbstractModelElement.getValueByName(node, "parentPolicy");
86 parentPolicyConditions = AbstractModelElement.getValuesByName(node, "parentPolicyConditions");
87 targetResourceId = AbstractModelElement.getValueByName(node, "targetResourceId");
88 if (targetResourceId != null && targetResourceId.isEmpty()) {
89 this.setTargetResourceId(null);
91 recipeInfo = AbstractModelElement.getValueByName(node, "recipeInfo");
92 recipeLevel = AbstractModelElement.getValueByName(node, "recipeLevel");
93 recipeInput = AbstractModelElement.getValueByName(node, "recipeInput");
94 String payload = AbstractModelElement.getValueByName(node, "recipePayload");
96 if (payload != null && !payload.isEmpty()) {
97 recipePayload = JacksonUtils.getObjectMapperInstance().readValue(payload, new TypeReference<Map<String, String>>(){});
99 oapRop = AbstractModelElement.getValueByName(node, "oapRop");
100 oapLimit = AbstractModelElement.getValueByName(node, "oapLimit");
101 actor = AbstractModelElement.getValueByName(node, "actor");
107 public String getId() {
114 public String getRecipe() {
121 public void setId(String id) {
128 public void setRecipe(String recipe) {
129 this.recipe = recipe;
133 * @set the parentPolicy
135 public void setParentPolicy(String parentPolicy) {
136 this.parentPolicy = parentPolicy;
140 * @set the maxRetries
142 public void setMaxRetries(int maxRetries) {
143 this.maxRetries = maxRetries;
147 * @set the retryTimeLimit
149 public void setRetryTimeLimit(int retryTimeLimit) {
150 this.retryTimeLimit = retryTimeLimit;
154 * @set the parentPolicyConditions
156 public void setParentPolicyConditions(List<String> parentPolicyConditions) {
157 this.parentPolicyConditions = parentPolicyConditions;
161 * @return the maxRetries
163 public int getMaxRetries() {
168 * @return the retryTimeLimit
170 public int getRetryTimeLimit() {
171 return retryTimeLimit;
175 * @return the parentPolicy
177 public String getParentPolicy() {
182 * @return the parentPolicyConditions
184 public List<String> getParentPolicyConditions() {
185 return parentPolicyConditions;
191 public String getActor() {
198 public void setActor(String actor) {
202 public String getTargetResourceId() {
203 return targetResourceId;
206 public void setTargetResourceId(String targetResourceId) {
207 this.targetResourceId = targetResourceId;
210 public String getRecipeInfo() {
214 public String getRecipeLevel() {
218 public String getRecipeInput() {
222 public Map<String, String> getRecipePayload() {
223 return recipePayload;
226 public String getOapRop() {
227 if (oapRop == null) {
233 public String getOapLimit() {
234 if (oapLimit == null) {