Merge "Added parsing of namespace in Json"
[controller.git] / opendaylight / md-sal / statistics-manager / src / main / java / org / opendaylight / controller / md / statistics / manager / StatisticsUpdateCommiter.java
1 package org.opendaylight.controller.md.statistics.manager;
2
3 import java.util.concurrent.ConcurrentMap;
4
5 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
6 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupDescRef;
7 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupDescStatsUpdated;
8 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupFeaturesRef;
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupFeaturesUpdated;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupStatisticsUpdated;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupStatsRef;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.OpendaylightGroupStatisticsListener;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.all.statistics.GroupDescBuilder;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.all.statistics.GroupFeaturesBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.all.statistics.GroupStatsBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterConfigRef;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterConfigStatsUpdated;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterFeaturesRef;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterFeaturesUpdated;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterStatisticsUpdated;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterStatsRef;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.OpendaylightMeterStatisticsListener;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.meter.all.stats.MeterConfigBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.meter.all.stats.MeterFeaturesBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.meter.all.stats.MeterStatsBuilder;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28
29 public class StatisticsUpdateCommiter implements OpendaylightGroupStatisticsListener,
30         OpendaylightMeterStatisticsListener {
31     
32     private final StatisticsProvider statisticsManager;
33
34     public StatisticsUpdateCommiter(final StatisticsProvider manager){
35
36         this.statisticsManager = manager;
37     }
38     public StatisticsProvider getStatisticsManager(){
39         return statisticsManager;
40     }
41     @Override
42     public void onMeterConfigStatsUpdated(MeterConfigStatsUpdated notification) {
43         //Add statistics to local cache
44         ConcurrentMap<NodeRef, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
45         if(!cache.containsKey(notification.getNode())){
46             cache.put(notification.getNode(), new NodeStatistics());
47         }
48         cache.get(notification.getNode()).setMeterConfigStats(notification.getMeterConfigStats());
49         
50         //Publish data to configuration data store
51         DataModificationTransaction it = this.statisticsManager.startChange();
52         MeterConfigRef ref = notification.getMeterConfigId();
53
54         MeterConfigBuilder meterConfig = new MeterConfigBuilder();
55         meterConfig.setNode(notification.getNode());
56         meterConfig.setMeterConfigStats(notification.getMeterConfigStats());
57         
58         InstanceIdentifier<? extends Object> refValue = ref.getValue();
59         it.putRuntimeData(refValue, meterConfig.build());
60         it.commit();
61     }
62
63     @Override
64     public void onMeterStatisticsUpdated(MeterStatisticsUpdated notification) {
65         //Add statistics to local cache
66         ConcurrentMap<NodeRef, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
67         if(!cache.containsKey(notification.getNode())){
68             cache.put(notification.getNode(), new NodeStatistics());
69         }
70         cache.get(notification.getNode()).setMeterStatistics(notification.getMeterStatistics());
71         
72         //Publish data to configuration data store
73         DataModificationTransaction it = this.statisticsManager.startChange();
74         MeterStatsRef ref = notification.getMeterStatsId();
75
76         MeterStatsBuilder meterStats = new MeterStatsBuilder();
77         meterStats.setNode(notification.getNode());
78         meterStats.setMeterStatistics(notification.getMeterStatistics());
79         
80         InstanceIdentifier<? extends Object> refValue = ref.getValue();
81         it.putRuntimeData(refValue, meterStats.build());
82         it.commit();
83     }
84
85     @Override
86     public void onGroupDescStatsUpdated(GroupDescStatsUpdated notification) {
87         //Add statistics to local cache
88         ConcurrentMap<NodeRef, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
89         if(!cache.containsKey(notification.getNode())){
90             cache.put(notification.getNode(), new NodeStatistics());
91         }
92         cache.get(notification.getNode()).setGroupDescStats(notification.getGroupDescStats());
93         
94         //Publish data to configuration data store
95         DataModificationTransaction it = this.statisticsManager.startChange();
96         GroupDescRef ref = notification.getGroupDescId();
97
98         GroupDescBuilder descStats = new GroupDescBuilder();
99         descStats.setNode(notification.getNode());
100         descStats.setGroupDescStats(notification.getGroupDescStats());
101         
102         InstanceIdentifier<? extends Object> refValue = ref.getValue();
103         it.putRuntimeData(refValue, descStats.build());
104         it.commit();
105     }
106
107     @Override
108     public void onGroupStatisticsUpdated(GroupStatisticsUpdated notification) {
109         
110         //Add statistics to local cache
111         ConcurrentMap<NodeRef, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
112         if(!cache.containsKey(notification.getNode())){
113             cache.put(notification.getNode(), new NodeStatistics());
114         }
115         cache.get(notification.getNode()).setGroupStatistics(notification.getGroupStatistics());
116         
117         //Publish data to configuration data store
118         DataModificationTransaction it = this.statisticsManager.startChange();
119         GroupStatsRef ref = notification.getGroupStatsId();
120
121         GroupStatsBuilder groupStats = new GroupStatsBuilder();
122         groupStats.setNode(notification.getNode());
123         groupStats.setGroupStatistics(notification.getGroupStatistics());
124         
125         InstanceIdentifier<? extends Object> refValue = ref.getValue();
126         it.putRuntimeData(refValue, groupStats.build());
127         it.commit();
128     }
129     @Override
130     public void onMeterFeaturesUpdated(MeterFeaturesUpdated notification) {
131
132         //Add statistics to local cache
133         ConcurrentMap<NodeRef, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
134         if(!cache.containsKey(notification.getNode())){
135             cache.put(notification.getNode(), new NodeStatistics());
136         }
137         cache.get(notification.getNode()).setMeterFeatures(notification.getMeterFeatures());
138         
139         //Publish data to configuration data store
140         DataModificationTransaction it = this.statisticsManager.startChange();
141         MeterFeaturesRef ref = notification.getMeterFeaturesId();
142
143         MeterFeaturesBuilder meterFeatures = new MeterFeaturesBuilder();
144         meterFeatures.setNode(notification.getNode());
145         meterFeatures.setMeterFeatures(notification.getMeterFeatures());
146         
147         InstanceIdentifier<? extends Object> refValue = ref.getValue();
148         it.putRuntimeData(refValue, meterFeatures.build());
149         it.commit();
150     }
151     
152     @Override
153     public void onGroupFeaturesUpdated(GroupFeaturesUpdated notification) {
154         
155         //Add statistics to local cache
156         ConcurrentMap<NodeRef, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
157         if(!cache.containsKey(notification.getNode())){
158             cache.put(notification.getNode(), new NodeStatistics());
159         }
160         cache.get(notification.getNode()).setGroupFeatures(notification.getGroupFeatures());
161         
162         //Publish data to configuration data store
163         DataModificationTransaction it = this.statisticsManager.startChange();
164         GroupFeaturesRef ref = notification.getGroupFeaturesId();
165
166         GroupFeaturesBuilder featuresStats = new GroupFeaturesBuilder();
167         featuresStats.setNode(notification.getNode());
168         featuresStats.setGroupFeatures(notification.getGroupFeatures());
169         
170         InstanceIdentifier<? extends Object> refValue = ref.getValue();
171         it.putRuntimeData(refValue, featuresStats.build());
172         it.commit();
173     }
174 }