From 8c15887914175912fe9322ef365d1998f3cf5108 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 13 Feb 2014 09:33:28 +0100 Subject: [PATCH] Add proxies for statistics getters 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 --- .../manager/StatisticsProvider.java | 78 +++++++++++-------- .../manager/StatisticsUpdateHandler.java | 14 ++-- 2 files changed, 54 insertions(+), 38 deletions(-) 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 7432db74eb..d8ee80a10f 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 @@ -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> 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> 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> 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> 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> 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 nodeII = (InstanceIdentifier) nodeRef.getValue(); - NodeKey nodeKey = InstanceIdentifier.keyOf(nodeII); - return nodeKey.getId(); - } - @Override public void close() { try { diff --git a/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsUpdateHandler.java b/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsUpdateHandler.java index d188a74a00..0459bc8512 100644 --- a/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsUpdateHandler.java +++ b/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsUpdateHandler.java @@ -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, DataObject> additions = change.getCreatedConfigurationData(); for (InstanceIdentifier dataObjectInstance : additions.keySet()) { DataObject dataObject = additions.get(dataObjectInstance); - InstanceIdentifier 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 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); } -- 2.36.6