2 * Copyright IBM Corporation, 2013. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.md.statistics.manager;
10 import java.util.concurrent.ConcurrentMap;
12 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupDescStatsUpdated;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupFeaturesUpdated;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupStatisticsUpdated;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupDescStats;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupDescStatsBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupFeatures;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupFeaturesBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupStatistics;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupStatisticsBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.OpendaylightGroupStatisticsListener;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.desc.GroupDescBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.features.GroupFeaturesBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.statistics.GroupStatisticsBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterConfigStatsUpdated;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterFeaturesUpdated;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterStatisticsUpdated;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterConfigStats;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterConfigStatsBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterFeatures;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterFeaturesBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterStatistics;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterStatisticsBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.OpendaylightMeterStatisticsListener;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.MeterConfigStatsBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.MeterFeaturesBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.MeterStatisticsBuilder;
45 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
46 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
48 public class StatisticsUpdateCommiter implements OpendaylightGroupStatisticsListener,
49 OpendaylightMeterStatisticsListener {
51 private final StatisticsProvider statisticsManager;
53 public StatisticsUpdateCommiter(final StatisticsProvider manager){
55 this.statisticsManager = manager;
58 public StatisticsProvider getStatisticsManager(){
59 return statisticsManager;
63 public void onMeterConfigStatsUpdated(MeterConfigStatsUpdated notification) {
65 //Add statistics to local cache
66 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
67 if(!cache.containsKey(notification.getId())){
68 cache.put(notification.getId(), new NodeStatistics());
70 cache.get(notification.getId()).setMeterConfigStats(notification.getMeterConfigStats());
72 //Publish data to configuration data store
73 DataModificationTransaction it = this.statisticsManager.startChange();
74 NodeKey key = new NodeKey(notification.getId());
75 NodeRef ref = getNodeRef(key);
77 final NodeBuilder nodeData = new NodeBuilder();
80 NodeMeterConfigStatsBuilder meterConfig= new NodeMeterConfigStatsBuilder();
81 MeterConfigStatsBuilder stats = new MeterConfigStatsBuilder();
82 stats.setMeterConfigStats(notification.getMeterConfigStats());
83 meterConfig.setMeterConfigStats(stats.build());
85 //Update augmented data
86 nodeData.addAugmentation(NodeMeterConfigStats.class, meterConfig.build());
88 InstanceIdentifier<? extends Object> refValue = ref.getValue();
89 it.putOperationalData(refValue, nodeData.build());
95 public void onMeterStatisticsUpdated(MeterStatisticsUpdated notification) {
96 //Add statistics to local cache
97 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
98 if(!cache.containsKey(notification.getId())){
99 cache.put(notification.getId(), new NodeStatistics());
101 cache.get(notification.getId()).setMeterStatistics(notification.getMeterStats());
103 //Publish data to configuration data store
104 DataModificationTransaction it = this.statisticsManager.startChange();
105 NodeKey key = new NodeKey(notification.getId());
106 NodeRef ref = getNodeRef(key);
108 final NodeBuilder nodeData = new NodeBuilder();
109 nodeData.setKey(key);
111 NodeMeterStatisticsBuilder meterStats= new NodeMeterStatisticsBuilder();
112 MeterStatisticsBuilder stats = new MeterStatisticsBuilder();
113 stats.setMeterStats(notification.getMeterStats());
114 meterStats.setMeterStatistics(stats.build());
116 //Update augmented data
117 nodeData.addAugmentation(NodeMeterStatistics.class, meterStats.build());
119 InstanceIdentifier<? extends Object> refValue = ref.getValue();
120 it.putOperationalData(refValue, nodeData.build());
126 public void onGroupDescStatsUpdated(GroupDescStatsUpdated notification) {
127 //Add statistics to local cache
128 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
129 if(!cache.containsKey(notification.getId())){
130 cache.put(notification.getId(), new NodeStatistics());
132 cache.get(notification.getId()).setGroupDescStats(notification.getGroupDescStats());
134 //Publish data to configuration data store
135 DataModificationTransaction it = this.statisticsManager.startChange();
136 NodeKey key = new NodeKey(notification.getId());
137 NodeRef ref = getNodeRef(key);
139 final NodeBuilder nodeData = new NodeBuilder();
140 nodeData.setKey(key);
142 NodeGroupDescStatsBuilder groupDesc= new NodeGroupDescStatsBuilder();
143 GroupDescBuilder stats = new GroupDescBuilder();
144 stats.setGroupDescStats(notification.getGroupDescStats());
145 groupDesc.setGroupDesc(stats.build());
147 //Update augmented data
148 nodeData.addAugmentation(NodeGroupDescStats.class, groupDesc.build());
150 InstanceIdentifier<? extends Object> refValue = ref.getValue();
151 it.putOperationalData(refValue, nodeData.build());
157 public void onGroupStatisticsUpdated(GroupStatisticsUpdated notification) {
159 //Add statistics to local cache
160 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
161 if(!cache.containsKey(notification.getId())){
162 cache.put(notification.getId(), new NodeStatistics());
164 cache.get(notification.getId()).setGroupStatistics(notification.getGroupStats());
166 //Publish data to configuration data store
168 DataModificationTransaction it = this.statisticsManager.startChange();
169 NodeKey key = new NodeKey(notification.getId());
170 NodeRef ref = getNodeRef(key);
172 final NodeBuilder nodeData = new NodeBuilder();
173 nodeData.setKey(key);
175 NodeGroupStatisticsBuilder groupStats = new NodeGroupStatisticsBuilder();
176 GroupStatisticsBuilder stats = new GroupStatisticsBuilder();
177 stats.setGroupStats(notification.getGroupStats());
178 groupStats.setGroupStatistics(stats.build());
180 //Update augmented data
181 nodeData.addAugmentation(NodeGroupStatistics.class, groupStats.build());
183 InstanceIdentifier<? extends Object> refValue = ref.getValue();
184 it.putOperationalData(refValue, nodeData.build());
187 // for (GroupStats groupstat : notification.getGroupStats()) {
189 // GroupStatsKey groupKey = groupstat.getKey();
190 // InstanceIdentifier<? extends Object> id = InstanceIdentifier.builder(Nodes.class).child(Node.class, key).augmentation(NodeGroupStatistics.class).child(GroupStatistics.class).child(GroupStats.class,groupKey).toInstance();
191 // it.putOperationalData(id, groupstat);
197 public void onMeterFeaturesUpdated(MeterFeaturesUpdated notification) {
199 //Add statistics to local cache
200 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
201 if(!cache.containsKey(notification.getId())){
202 cache.put(notification.getId(), new NodeStatistics());
204 MeterFeaturesBuilder meterFeature = new MeterFeaturesBuilder();
205 meterFeature.setMeterBandSupported(notification.getMeterBandSupported());
206 meterFeature.setMeterCapabilitiesSupported(notification.getMeterCapabilitiesSupported());
207 meterFeature.setMaxBands(notification.getMaxBands());
208 meterFeature.setMaxColor(notification.getMaxColor());
209 meterFeature.setMaxMeter(notification.getMaxMeter());
211 cache.get(notification.getId()).setMeterFeatures(meterFeature.build());
213 //Publish data to configuration data store
214 DataModificationTransaction it = this.statisticsManager.startChange();
215 NodeKey key = new NodeKey(notification.getId());
216 NodeRef ref = getNodeRef(key);
218 final NodeBuilder nodeData = new NodeBuilder();
219 nodeData.setKey(key);
221 NodeMeterFeaturesBuilder nodeMeterFeatures= new NodeMeterFeaturesBuilder();
222 nodeMeterFeatures.setMeterFeatures(meterFeature.build());
224 //Update augmented data
225 nodeData.addAugmentation(NodeMeterFeatures.class, nodeMeterFeatures.build());
227 InstanceIdentifier<? extends Object> refValue = ref.getValue();
228 it.putOperationalData(refValue, nodeData.build());
233 public void onGroupFeaturesUpdated(GroupFeaturesUpdated notification) {
235 //Add statistics to local cache
236 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
237 if(!cache.containsKey(notification.getId())){
238 cache.put(notification.getId(), new NodeStatistics());
241 GroupFeaturesBuilder groupFeatures = new GroupFeaturesBuilder();
242 groupFeatures.setActions(notification.getActions());
243 groupFeatures.setGroupCapabilitiesSupported(notification.getGroupCapabilitiesSupported());
244 groupFeatures.setGroupTypesSupported(notification.getGroupTypesSupported());
245 groupFeatures.setMaxGroups(notification.getMaxGroups());
246 cache.get(notification.getId()).setGroupFeatures(groupFeatures.build());
248 //Publish data to configuration data store
249 DataModificationTransaction it = this.statisticsManager.startChange();
250 NodeKey key = new NodeKey(notification.getId());
251 NodeRef ref = getNodeRef(key);
253 final NodeBuilder nodeData = new NodeBuilder();
254 nodeData.setKey(key);
256 NodeGroupFeaturesBuilder nodeGroupFeatures= new NodeGroupFeaturesBuilder();
257 nodeGroupFeatures.setGroupFeatures(groupFeatures.build());
259 //Update augmented data
260 nodeData.addAugmentation(NodeGroupFeatures.class, nodeGroupFeatures.build());
262 InstanceIdentifier<? extends Object> refValue = ref.getValue();
263 it.putOperationalData(refValue, nodeData.build());
267 private NodeRef getNodeRef(NodeKey nodeKey){
268 InstanceIdentifierBuilder<?> builder = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey);
269 return new NodeRef(builder.toInstance());