Code Improvement
[clamp.git] / src / main / java / org / onap / clamp / clds / model / prop / ResourceGroup.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 Resource Group json properties.
36  *
37  * Example json:
38  * {"TCA_0aji7go":{"Group1":[{"name":"rgname","value":"1493749598520"},{
39  * "name":"rgfriendlyname","value":"Group1"},{"name":"policyName","value":
40  * "Policy1"},{"name":"policyId","value":"1"},{"serviceConfigurations":[[{"name"
41  * :"aaiMatchingFields","value":["complex.city","vserver.vserver-name"]},{"name"
42  * :"aaiSendFields","value":["complex.city","vserver.vserver-name"]},{"name":
43  * "eventSeverity","value":["OK"]},{"name":"eventSourceType","value":[""]},{
44  * "name":"timeWindow","value":["100"]},{"name":"ageLimit","value":["100"]},{
45  * "name":"createClosedLoopEventId","value":["Initial"]},{"name":
46  * "outputEventName","value":["ONSET"]}]]}],"Group2":[{"name":"rgname","value":
47  * "1493749665149"},{"name":"rgfriendlyname","value":"Group2"},{"name":
48  * "policyName","value":"Policy2"},{"name":"policyId","value":"2"},{
49  * "serviceConfigurations":[[{"name":"aaiMatchingFields","value":[
50  * "cloud-region.identity-url","vserver.vserver-name"]},{"name":"aaiSendFields",
51  * "value":["cloud-region.identity-url","vserver.vserver-name"]},{"name":
52  * "eventSeverity","value":["NORMAL"]},{"name":"eventSourceType","value":[""]},{
53  * "name":"timeWindow","value":["1000"]},{"name":"ageLimit","value":["1000"]},{
54  * "name":"createClosedLoopEventId","value":["Initial"]},{"name":
55  * "outputEventName","value":["ONSET"]}],[{"name":"aaiMatchingFields","value":[
56  * "generic-vnf.vnf-name","vserver.vserver-name"]},{"name":"aaiSendFields",
57  * "value":["generic-vnf.vnf-name","vserver.vserver-name"]},{"name":
58  * "eventSeverity","value":["CRITICAL"]},{"name":"eventSourceType","value":[""]}
59  * ,{"name":"timeWindow","value":["3000"]},{"name":"ageLimit","value":["3000"]},
60  * {"name":"createClosedLoopEventId","value":["Initial"]},{"name":
61  * "outputEventName","value":["ABATED"]}]]}]}}
62  *
63  */
64 public class ResourceGroup {
65
66     protected static final EELFLogger  logger      = EELFManager.getInstance().getLogger(ResourceGroup.class);
67     protected static final EELFLogger  auditLogger = EELFManager.getInstance().getAuditLogger();
68
69     private String                     groupNumber;
70     private String                     policyId;
71     private List<ServiceConfiguration> serviceConfigurations;
72
73     /**
74      * Parse String Match Resource Group given json node.
75      *
76      * @param modelBpmn
77      * @param modelJson
78      */
79     public ResourceGroup(JsonNode node) {
80
81         groupNumber = AbstractModelElement.getValueByName(node, "rgname");
82         policyId = AbstractModelElement.getValueByName(node, "policyId");
83
84         // process Server_Configurations
85         JsonNode serviceConfigurationsNode = node.get(node.size() - 1).get("serviceConfigurations");
86         Iterator<JsonNode> itr = serviceConfigurationsNode.elements();
87         serviceConfigurations = new ArrayList<>();
88         while (itr.hasNext()) {
89             serviceConfigurations.add(new ServiceConfiguration(itr.next()));
90         }
91     }
92
93     /**
94      * @return the groupNumber
95      */
96     public String getGroupNumber() {
97         return groupNumber;
98     }
99
100     /**
101      * @return the policyId
102      */
103     public String getPolicyId() {
104         return policyId;
105     }
106
107     /**
108      * @return the serviceConfigurations
109      */
110     public List<ServiceConfiguration> getServiceConfigurations() {
111         return serviceConfigurations;
112     }
113
114 }