Add support for ScaleOut
[clamp.git] / src / main / java / org / onap / clamp / clds / model / properties / Policy.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017-2018 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  *
22  */
23
24 package org.onap.clamp.clds.model.properties;
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.io.IOException;
31 import java.util.ArrayList;
32 import java.util.Iterator;
33 import java.util.List;
34
35 /**
36  * Parse Policy json properties.
37  * <p>
38  * Example json:
39  * "Policy_005sny1":[[{"name":"timeout","value":"5"}],{"policyConfigurations":[[
40  * {"name":"recipe","value":["restart"]},{"name":"maxRetries","value":["3"]},{
41  * "name":"retryTimeLimit","value":["180"]},{"name":"_id","value":["vf3RtPi"]},{
42  * "name":"location","value":["san_diego"]},{"name":"resource","value":["vCTS"]}
43  * ,{"name":"onMaxRetriesLimit","value":[""]},{"name":"onTimeLimit","value":[""]
44  * },{"name":"onOtherFailure","value":[""]},{"name":"policy_parent","value":[""]
45  * }],[{"name":"recipe","value":["rebuild"]},{"name":"maxRetries","value":["3"]}
46  * ,{"name":"retryTimeLimit","value":["180"]},{"name":"_id","value":["89z8Ncl"]}
47  * ,{"name":"location","value":["san_diego"]},{"name":"resource","value":["vCTS"
48  * ]},{"name":"onMaxRetriesLimit","value":[""]},{"name":"onTimeLimit","value":[
49  * ""]},{"name":"onOtherFailure","value":[""]},{"name":"policy_parent","value":[
50  * "vf3RtPi"]}]]}]
51  */
52 public class Policy extends AbstractModelElement {
53     protected static final EELFLogger logger      = EELFManager.getInstance().getLogger(Policy.class);
54     protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
55
56     private List<PolicyChain>         policyChains;
57
58     private static final String       TYPE_POLICY = "policy";
59
60     /**
61      * Parse Policy given json node.
62      *
63      * @param modelProp
64      * @param modelBpmn
65      * @param modelJson
66      * @throws IOException
67      */
68     public Policy(ModelProperties modelProp, ModelBpmn modelBpmn, JsonNode modelJson) throws IOException {
69         super(TYPE_POLICY, modelProp, modelBpmn, modelJson);
70
71         // process policies
72         if (modelElementJsonNode != null) {
73             Iterator<JsonNode> itr = modelElementJsonNode.elements();
74             policyChains = new ArrayList<>();
75             while (itr.hasNext()) {
76                 policyChains.add(new PolicyChain(itr.next()));
77             }
78         }
79     }
80
81     /**
82      * @return the policyChains
83      */
84     public List<PolicyChain> getPolicyChains() {
85         return policyChains;
86     }
87
88     public static final String getType() {
89         return TYPE_POLICY;
90     }
91
92 }