Add proxies for statistics getters 11/5311/3
authorRobert Varga <rovarga@cisco.com>
Thu, 13 Feb 2014 08:33:28 +0000 (09:33 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Sat, 15 Feb 2014 02:10:00 +0000 (02:10 +0000)
This is a simple unification of stats collection triggers so they are
centered about their per-node collector.

Change-Id: Iaf63d782b58b84ed3270b9215587f96f93aab3cc
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsProvider.java
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsUpdateHandler.java

index 7432db7..d8ee80a 100644 (file)
@@ -235,11 +235,11 @@ public class StatisticsProvider implements AutoCloseable {
             }
             if(groupStatsService != null){
                 sendAllGroupStatisticsRequest(h);
-                sendGroupDescriptionRequest(h.getTargetNodeRef());
+                sendGroupDescriptionRequest(h);
             }
             if(meterStatsService != null){
                 sendAllMeterStatisticsRequest(h);
-                sendMeterConfigStatisticsRequest(h.getTargetNodeRef());
+                sendMeterConfigStatisticsRequest(h);
             }
             if(queueStatsService != null){
                 sendAllQueueStatsFromAllNodeConnector(h);
@@ -278,19 +278,25 @@ public class StatisticsProvider implements AutoCloseable {
 
     }
 
-    public void sendFlowStatsFromTableRequest(NodeRef targetNode,Flow flow) throws InterruptedException, ExecutionException{
+    public void sendFlowStatsFromTableRequest(NodeKey node, Flow flow) throws InterruptedException, ExecutionException {
+        final NodeStatisticsHandler h = getStatisticsHandler(node.getId());
+        if (h != null) {
+            sendFlowStatsFromTableRequest(h, flow);
+        }
+    }
+
+    private void sendFlowStatsFromTableRequest(NodeStatisticsHandler h, Flow flow) throws InterruptedException, ExecutionException{
         final GetFlowStatisticsFromFlowTableInputBuilder input =
                 new GetFlowStatisticsFromFlowTableInputBuilder();
 
-        input.setNode(targetNode);
+        input.setNode(h.getTargetNodeRef());
         input.fieldsFrom(flow);
 
         Future<RpcResult<GetFlowStatisticsFromFlowTableOutput>> response =
                 flowStatsService.getFlowStatisticsFromFlowTable(input.build());
 
-        this.multipartMessageManager.addTxIdToRequestTypeEntry(getNodeId(targetNode), response.get().getResult().getTransactionId()
-                , StatsRequestType.ALL_FLOW);
-
+        this.multipartMessageManager.addTxIdToRequestTypeEntry(h.getTargetNodeKey().getId(),
+                response.get().getResult().getTransactionId(), StatsRequestType.ALL_FLOW);
     }
 
     private void sendAggregateFlowsStatsFromAllTablesRequest(final NodeStatisticsHandler h) throws InterruptedException, ExecutionException{
@@ -345,17 +351,23 @@ public class StatisticsProvider implements AutoCloseable {
 
     }
 
-    public void sendGroupDescriptionRequest(NodeRef targetNode) throws InterruptedException, ExecutionException{
+    public void sendGroupDescriptionRequest(NodeKey node) throws InterruptedException, ExecutionException{
+        final NodeStatisticsHandler h = getStatisticsHandler(node.getId());
+        if (h != null) {
+            sendGroupDescriptionRequest(h);
+        }
+    }
+
+    private void sendGroupDescriptionRequest(NodeStatisticsHandler h) throws InterruptedException, ExecutionException{
         final GetGroupDescriptionInputBuilder input = new GetGroupDescriptionInputBuilder();
 
-        input.setNode(targetNode);
+        input.setNode(h.getTargetNodeRef());
 
         Future<RpcResult<GetGroupDescriptionOutput>> response =
                 groupStatsService.getGroupDescription(input.build());
 
-        this.multipartMessageManager.addTxIdToRequestTypeEntry(getNodeId(targetNode), response.get().getResult().getTransactionId()
-                , StatsRequestType.GROUP_DESC);
-
+        this.multipartMessageManager.addTxIdToRequestTypeEntry(h.getTargetNodeKey().getId(),
+                response.get().getResult().getTransactionId(), StatsRequestType.GROUP_DESC);
     }
 
     private void sendAllMeterStatisticsRequest(NodeStatisticsHandler h) throws InterruptedException, ExecutionException{
@@ -372,18 +384,24 @@ public class StatisticsProvider implements AutoCloseable {
 
     }
 
-    public void sendMeterConfigStatisticsRequest(NodeRef targetNode) throws InterruptedException, ExecutionException{
+    public void sendMeterConfigStatisticsRequest(NodeKey node) throws InterruptedException, ExecutionException {
+        final NodeStatisticsHandler h = getStatisticsHandler(node.getId());
+        if (h != null) {
+            sendMeterConfigStatisticsRequest(h);
+        }
+    }
+
+    private void sendMeterConfigStatisticsRequest(NodeStatisticsHandler h) throws InterruptedException, ExecutionException{
 
         GetAllMeterConfigStatisticsInputBuilder input = new GetAllMeterConfigStatisticsInputBuilder();
 
-        input.setNode(targetNode);
+        input.setNode(h.getTargetNodeRef());
 
         Future<RpcResult<GetAllMeterConfigStatisticsOutput>> response =
                 meterStatsService.getAllMeterConfigStatistics(input.build());
 
-        this.multipartMessageManager.addTxIdToRequestTypeEntry(getNodeId(targetNode), response.get().getResult().getTransactionId()
-                , StatsRequestType.METER_CONFIG);;
-
+        this.multipartMessageManager.addTxIdToRequestTypeEntry(h.getTargetNodeKey().getId(),
+                response.get().getResult().getTransactionId(), StatsRequestType.METER_CONFIG);;
     }
 
     private void sendAllQueueStatsFromAllNodeConnector(NodeStatisticsHandler h) throws InterruptedException, ExecutionException {
@@ -394,23 +412,28 @@ public class StatisticsProvider implements AutoCloseable {
         Future<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> response =
                 queueStatsService.getAllQueuesStatisticsFromAllPorts(input.build());
 
-        this.multipartMessageManager.addTxIdToRequestTypeEntry(h.getTargetNodeKey().getId(), response.get().getResult().getTransactionId()
-                , StatsRequestType.ALL_QUEUE_STATS);;
+        this.multipartMessageManager.addTxIdToRequestTypeEntry(h.getTargetNodeKey().getId(),
+                response.get().getResult().getTransactionId(), StatsRequestType.ALL_QUEUE_STATS);;
+    }
 
+    public void sendQueueStatsFromGivenNodeConnector(NodeKey node,NodeConnectorId nodeConnectorId, QueueId queueId) throws InterruptedException, ExecutionException {
+        final NodeStatisticsHandler h = getStatisticsHandler(node.getId());
+        if (h != null) {
+            sendQueueStatsFromGivenNodeConnector(h, nodeConnectorId, queueId);
+        }
     }
 
-    public void sendQueueStatsFromGivenNodeConnector(NodeRef targetNode,NodeConnectorId nodeConnectorId, QueueId queueId) throws InterruptedException, ExecutionException {
+    private void sendQueueStatsFromGivenNodeConnector(NodeStatisticsHandler h, NodeConnectorId nodeConnectorId, QueueId queueId) throws InterruptedException, ExecutionException {
         GetQueueStatisticsFromGivenPortInputBuilder input = new GetQueueStatisticsFromGivenPortInputBuilder();
 
-        input.setNode(targetNode);
+        input.setNode(h.getTargetNodeRef());
         input.setNodeConnectorId(nodeConnectorId);
         input.setQueueId(queueId);
         Future<RpcResult<GetQueueStatisticsFromGivenPortOutput>> response =
                 queueStatsService.getQueueStatisticsFromGivenPort(input.build());
 
-        this.multipartMessageManager.addTxIdToRequestTypeEntry(getNodeId(targetNode), response.get().getResult().getTransactionId()
-                , StatsRequestType.ALL_QUEUE_STATS);;
-
+        this.multipartMessageManager.addTxIdToRequestTypeEntry(h.getTargetNodeKey().getId(),
+                response.get().getResult().getTransactionId(), StatsRequestType.ALL_QUEUE_STATS);;
     }
 
     /**
@@ -429,13 +452,6 @@ public class StatisticsProvider implements AutoCloseable {
         return handler;
     }
 
-    @SuppressWarnings("unchecked")
-    private NodeId getNodeId(NodeRef nodeRef){
-        InstanceIdentifier<Node> nodeII = (InstanceIdentifier<Node>) nodeRef.getValue();
-        NodeKey nodeKey = InstanceIdentifier.keyOf(nodeII);
-        return nodeKey.getId();
-    }
-
     @Override
     public void close() {
         try {
index d188a74..0459bc8 100644 (file)
@@ -21,10 +21,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.q
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupDescStats;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupStatistics;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterConfigStats;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterStatistics;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.FlowCapableNodeConnectorQueueStatisticsData;
@@ -59,26 +59,25 @@ public class StatisticsUpdateHandler implements DataChangeListener {
         Map<InstanceIdentifier<?>, DataObject> additions = change.getCreatedConfigurationData();
         for (InstanceIdentifier<? extends DataObject> dataObjectInstance : additions.keySet()) {
             DataObject dataObject = additions.get(dataObjectInstance);
-            InstanceIdentifier<Node> nodeII = dataObjectInstance.firstIdentifierOf(Node.class);
-            NodeRef nodeRef = new NodeRef(nodeII);
+            NodeKey nodeII = dataObjectInstance.firstKeyOf(Node.class, NodeKey.class);
             if(dataObject instanceof Flow){
                 Flow flow = (Flow) dataObject;
                 try {
-                    this.statisticsManager.sendFlowStatsFromTableRequest(nodeRef, flow);
+                    this.statisticsManager.sendFlowStatsFromTableRequest(nodeII, flow);
                 } catch (InterruptedException | ExecutionException e) {
                     suhLogger.warn("Following exception occured while sending flow statistics request newly added flow: {}", e);
                 }
             }
             if(dataObject instanceof Meter){
                 try {
-                    this.statisticsManager.sendMeterConfigStatisticsRequest(nodeRef);
+                    this.statisticsManager.sendMeterConfigStatisticsRequest(nodeII);
                 } catch (InterruptedException | ExecutionException e) {
                     suhLogger.warn("Following exception occured while sending meter statistics request for newly added meter: {}", e);
                 }
             }
             if(dataObject instanceof Group){
                 try {
-                    this.statisticsManager.sendGroupDescriptionRequest(nodeRef);
+                    this.statisticsManager.sendGroupDescriptionRequest(nodeII);
                 } catch (InterruptedException | ExecutionException e) {
                     suhLogger.warn("Following exception occured while sending group description request for newly added group: {}", e);
                 }
@@ -88,7 +87,8 @@ public class StatisticsUpdateHandler implements DataChangeListener {
                 InstanceIdentifier<NodeConnector> nodeConnectorII = dataObjectInstance.firstIdentifierOf(NodeConnector.class);
                 NodeConnectorKey nodeConnectorKey = InstanceIdentifier.keyOf(nodeConnectorII);
                 try {
-                    this.statisticsManager.sendQueueStatsFromGivenNodeConnector(nodeRef, nodeConnectorKey.getId(), queue.getQueueId());
+                    this.statisticsManager.sendQueueStatsFromGivenNodeConnector(nodeII,
+                            nodeConnectorKey.getId(), queue.getQueueId());
                 } catch (InterruptedException | ExecutionException e) {
                     suhLogger.warn("Following exception occured while sending queue statistics request for newly added group: {}", e);
                 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.