From: Robert Varga Date: Thu, 13 Feb 2014 03:23:54 +0000 (+0100) Subject: Keep track of the tables we discover X-Git-Tag: autorelease-tag-v20140601202136_82eb3f9~447 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;ds=sidebyside;h=7d1a7a08f2618ec0de1a97b561225c899d5c5715;p=controller.git Keep track of the tables we discover NodeStatisticsHandler has always the most uptodate information about which tables were discovered. Let's cache the table IDs -- we will need them for sending out follow-up requests. And now that we do that, we do not have to read the tables from DataProviderService just to get the keys -- use whatever we cached. Change-Id: I9550ae3330215277d373ec0b2ea67945ef0e7c5c Signed-off-by: Robert Varga --- diff --git a/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/NodeStatisticsHandler.java b/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/NodeStatisticsHandler.java index e9cecc521e..6a7033d795 100644 --- a/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/NodeStatisticsHandler.java +++ b/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/NodeStatisticsHandler.java @@ -7,11 +7,15 @@ */ package org.opendaylight.controller.md.statistics.manager; +import java.util.Collection; +import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import java.util.concurrent.TimeUnit; import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction; @@ -114,6 +118,7 @@ public class NodeStatisticsHandler implements AutoCloseable { private final InstanceIdentifier targetNodeIdentifier; private final StatisticsProvider statisticsProvider; private final NodeKey targetNodeKey; + private Collection knownTables = Collections.emptySet(); private int unaccountedFlowsCounter = 1; public NodeStatisticsHandler(StatisticsProvider statisticsProvider, NodeKey nodeKey){ @@ -171,7 +176,7 @@ public class NodeStatisticsHandler implements AutoCloseable { } } - private static final class QueueEntry{ + private static final class QueueEntry { private final NodeConnectorId nodeConnectorId; private final QueueId queueId; public QueueEntry(NodeConnectorId ncId, QueueId queueId){ @@ -226,6 +231,10 @@ public class NodeStatisticsHandler implements AutoCloseable { return targetNodeKey; } + public Collection getKnownTables() { + return knownTables; + } + public synchronized void updateGroupDescStats(List list){ final Long expiryTime = getExpiryTime(); final DataModificationTransaction trans = statisticsProvider.startChange(); @@ -254,7 +263,6 @@ public class NodeStatisticsHandler implements AutoCloseable { trans.commit(); } - public synchronized void updateGroupStats(List list) { final DataModificationTransaction trans = statisticsProvider.startChange(); @@ -381,19 +389,14 @@ public class NodeStatisticsHandler implements AutoCloseable { public synchronized void updateFlowTableStats(List list) { final DataModificationTransaction trans = statisticsProvider.startChange(); + final Set knownTables = new HashSet<>(list.size()); for (FlowTableAndStatisticsMap ftStats : list) { InstanceIdentifier tableRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, targetNodeKey) .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(ftStats.getTableId().getValue())).toInstance(); FlowTableStatisticsDataBuilder statisticsDataBuilder = new FlowTableStatisticsDataBuilder(); - - FlowTableStatisticsBuilder statisticsBuilder = new FlowTableStatisticsBuilder(); - statisticsBuilder.setActiveFlows(ftStats.getActiveFlows()); - statisticsBuilder.setPacketsLookedUp(ftStats.getPacketsLookedUp()); - statisticsBuilder.setPacketsMatched(ftStats.getPacketsMatched()); - - final FlowTableStatistics stats = statisticsBuilder.build(); + final FlowTableStatistics stats = new FlowTableStatisticsBuilder(ftStats).build(); statisticsDataBuilder.setFlowTableStatistics(stats); logger.debug("Augment flow table statistics: {} for table {} on Node {}", @@ -404,9 +407,10 @@ public class NodeStatisticsHandler implements AutoCloseable { tableBuilder.addAugmentation(FlowTableStatisticsData.class, statisticsDataBuilder.build()); trans.putOperationalData(tableRef, tableBuilder.build()); - // FIXME: should we be tracking this data? + knownTables.add(tableBuilder.getKey()); } + this.knownTables = Collections.unmodifiableCollection(knownTables); trans.commit(); } diff --git a/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsProvider.java b/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsProvider.java index b7fb4e9473..ce2a0b3eeb 100644 --- a/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsProvider.java +++ b/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsProvider.java @@ -8,7 +8,6 @@ package org.opendaylight.controller.md.statistics.manager; import java.util.Collection; -import java.util.List; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ExecutionException; @@ -25,6 +24,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.Fl import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput; @@ -236,26 +236,29 @@ public class StatisticsProvider implements AutoCloseable { private void statsRequestSender() { for (NodeStatisticsHandler h : handlers.values()) { - sendStatisticsRequestsToNode(h.getTargetNodeKey()); + sendStatisticsRequestsToNode(h); } } - private void sendStatisticsRequestsToNode(NodeKey targetNode){ + private void sendStatisticsRequestsToNode(NodeStatisticsHandler h) { + NodeKey targetNode = h.getTargetNodeKey(); + spLogger.debug("Send requests for statistics collection to node : {}", targetNode.getId()); - spLogger.debug("Send requests for statistics collection to node : {})",targetNode.getId()); - - InstanceIdentifier targetInstanceId = InstanceIdentifier.builder(Nodes.class).child(Node.class,targetNode).toInstance(); + InstanceIdentifier targetInstanceId = InstanceIdentifier.builder(Nodes.class).child(Node.class, targetNode).build(); NodeRef targetNodeRef = new NodeRef(targetInstanceId); try{ - if(flowStatsService != null){ - sendAggregateFlowsStatsFromAllTablesRequest(targetNode); - sendAllFlowsStatsFromAllTablesRequest(targetNodeRef); - } if(flowTableStatsService != null){ sendAllFlowTablesStatisticsRequest(targetNodeRef); } + if(flowStatsService != null){ + // FIXME: it does not make sense to trigger this before sendAllFlowTablesStatisticsRequest() + // comes back -- we do not have any tables anyway. + sendAggregateFlowsStatsFromAllTablesRequest(h); + + sendAllFlowsStatsFromAllTablesRequest(targetNodeRef); + } if(portStatsService != null){ sendAllNodeConnectorsStatisticsRequest(targetNodeRef); } @@ -268,7 +271,7 @@ public class StatisticsProvider implements AutoCloseable { sendMeterConfigStatisticsRequest(targetNodeRef); } if(queueStatsService != null){ - sendAllQueueStatsFromAllNodeConnector (targetNodeRef); + sendAllQueueStatsFromAllNodeConnector(targetNodeRef); } }catch(Exception e){ spLogger.error("Exception occured while sending statistics requests : {}", e); @@ -319,21 +322,12 @@ public class StatisticsProvider implements AutoCloseable { } - private void sendAggregateFlowsStatsFromAllTablesRequest(final NodeKey nodeKey) throws InterruptedException, ExecutionException{ - FlowCapableNode node = (FlowCapableNode)dps.readOperationalData( - InstanceIdentifier.builder(Nodes.class).child(Node.class,nodeKey).augmentation(FlowCapableNode.class).build()); - if (node != null) { - final List
tables = node.getTable(); - if (tables != null) { - spLogger.debug("Node {} supports {} table(s)", nodeKey, tables.size()); - for(Table table : tables) { - sendAggregateFlowsStatsFromTableRequest(nodeKey, table.getId()); - } - } else { - spLogger.debug("Node {} has no associated tables", nodeKey); - } - } else { - spLogger.debug("Node {} not found", nodeKey); + private void sendAggregateFlowsStatsFromAllTablesRequest(final NodeStatisticsHandler h) throws InterruptedException, ExecutionException{ + final Collection tables = h.getKnownTables(); + spLogger.debug("Node {} supports {} table(s)", h, tables.size()); + + for (TableKey key : h.getKnownTables()) { + sendAggregateFlowsStatsFromTableRequest(h.getTargetNodeKey(), key.getId().shortValue()); } } @@ -502,7 +496,7 @@ public class StatisticsProvider implements AutoCloseable { spLogger.debug("Started node handler for {}", key.getId()); // FIXME: this should be in the NodeStatisticsHandler itself - sendStatisticsRequestsToNode(key); + sendStatisticsRequestsToNode(h); } }