X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=interfacemanager%2Finterfacemanager-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fgenius%2Finterfacemanager%2Fpmcounters%2FNodeConnectorStatsImpl.java;h=9da255b6256b05bf0cc5132806a0adc2be1e5834;hb=fa7e0496d8ac7778cf02f35c3e0ae192f97d46c0;hp=acf5076afb62d9c9e0e5ee4294a6474e82e166cc;hpb=fe77cf52d5a52d677db8cba798fc2eeefa4c1142;p=genius.git diff --git a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/pmcounters/NodeConnectorStatsImpl.java b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/pmcounters/NodeConnectorStatsImpl.java index acf5076af..9da255b62 100644 --- a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/pmcounters/NodeConnectorStatsImpl.java +++ b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/pmcounters/NodeConnectorStatsImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -25,7 +25,7 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.NotificationService; import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.genius.mdsalutil.AbstractDataChangeListener; +import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdate; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInputBuilder; @@ -49,16 +49,15 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Singleton -public class NodeConnectorStatsImpl extends AbstractDataChangeListener{ - - private static final Logger logger = LoggerFactory.getLogger(NodeConnectorStatsImpl.class); +public class NodeConnectorStatsImpl extends AsyncDataTreeChangeListenerBase { + private static final Logger LOG = LoggerFactory.getLogger(NodeConnectorStatsImpl.class); private static final String STATS_POLL_FLAG = "interfacemgr.pmcounters.poll"; private static final int THREAD_POOL_SIZE = 4; private static final int NO_DELAY = 0; - public static final PMAgentForNodeConnectorCounters pmagent = new PMAgentForNodeConnectorCounters(); - private PortRpcStatisticsListener portStatsListener = new PortRpcStatisticsListener(); - private FlowRpcStatisticsListener flowTableStatsListener = new FlowRpcStatisticsListener(); - private List nodes = new ArrayList<>(); + public static final PMAgentForNodeConnectorCounters PMAGENT = new PMAgentForNodeConnectorCounters(); + private final PortRpcStatisticsListener portStatsListener = new PortRpcStatisticsListener(); + private final FlowRpcStatisticsListener flowTableStatsListener = new FlowRpcStatisticsListener(); + private final List nodes = new ArrayList<>(); Map> nodeAndNcIdOFPortDurationMap = new ConcurrentHashMap<>(); Map> nodeAndNcIdOFPortReceiveDropMap = new ConcurrentHashMap<>(); Map> nodeAndNcIdOFPortReceiveError = new ConcurrentHashMap<>(); @@ -69,35 +68,32 @@ public class NodeConnectorStatsImpl extends AbstractDataChangeListener{ Map> nodeAndEntriesPerOFTableMap = new ConcurrentHashMap<>(); private ScheduledFuture scheduledResult; private final OpendaylightPortStatisticsService statPortService; - private ScheduledExecutorService portStatExecutorService; + private final ScheduledExecutorService portStatExecutorService; private final OpendaylightFlowTableStatisticsService opendaylightFlowTableStatisticsService; @Inject public NodeConnectorStatsImpl(DataBroker dataBroker, NotificationService notificationService, final OpendaylightPortStatisticsService opendaylightPortStatisticsService, final OpendaylightFlowTableStatisticsService opendaylightFlowTableStatisticsService) { - super(Node.class); + super(Node.class, NodeConnectorStatsImpl.class); this.statPortService = opendaylightPortStatisticsService; this.opendaylightFlowTableStatisticsService = opendaylightFlowTableStatisticsService; - registerListener(dataBroker); - portStatExecutorService = Executors.newScheduledThreadPool(THREAD_POOL_SIZE, getThreadFactory("Port Stats Request Task")); + registerListener(LogicalDatastoreType.OPERATIONAL, dataBroker); + portStatExecutorService = Executors.newScheduledThreadPool(THREAD_POOL_SIZE, + getThreadFactory("Port Stats " + "Request Task")); notificationService.registerNotificationListener(portStatsListener); notificationService.registerNotificationListener(flowTableStatsListener); - pmagent.registerMbean(); + PMAGENT.registerMbean(); } - private void registerListener(final DataBroker db) { - try { - db.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, - getWildCardPath(), NodeConnectorStatsImpl.this, AsyncDataBroker.DataChangeScope.SUBTREE); - } catch (final Exception e) { - logger.error("NodeConnectorStatsImpl: DataChange listener registration fail!", e); - throw new IllegalStateException("NodeConnectorStatsImpl: registration Listener failed.", e); - } + @Override + public InstanceIdentifier getWildCardPath() { + return InstanceIdentifier.create(Nodes.class).child(Node.class); } - private InstanceIdentifier getWildCardPath() { - return InstanceIdentifier.create(Nodes.class).child(Node.class); + @Override + protected NodeConnectorStatsImpl getDataTreeChangeListener() { + return NodeConnectorStatsImpl.this; } /* @@ -105,37 +101,39 @@ public class NodeConnectorStatsImpl extends AbstractDataChangeListener{ */ private void schedulePortStatRequestTask() { if (!Boolean.getBoolean(STATS_POLL_FLAG)) { - logger.info("Port statistics is turned off"); + LOG.info("Port statistics is turned off"); return; } - logger.info("Scheduling port statistics request"); + LOG.info("Scheduling port statistics request"); PortStatRequestTask portStatRequestTask = new PortStatRequestTask(); - scheduledResult = portStatExecutorService.scheduleAtFixedRate(portStatRequestTask, NO_DELAY, 10000, TimeUnit.MILLISECONDS); + scheduledResult = portStatExecutorService.scheduleAtFixedRate(portStatRequestTask, NO_DELAY, 10000, + TimeUnit.MILLISECONDS); } /* * PortStat request task is stopped when last DPN is removed. */ private void stopPortStatRequestTask() { - if(scheduledResult != null) { - logger.info("Stopping port statistics request"); + if (scheduledResult != null) { + LOG.info("Stopping port statistics request"); scheduledResult.cancel(true); } } /* - * This task queries for node connector statistics as well as flowtables statistics every 10 secs. - * Minimum period which can be configured for PMJob is 10 secs. + * This task queries for node connector statistics as well as flowtables + * statistics every 10 secs. Minimum period which can be configured for + * PMJob is 10 secs. */ private class PortStatRequestTask implements Runnable { @Override public void run() { - if(logger.isTraceEnabled()) { - logger.trace("Requesting port stats - {}"); + if (LOG.isTraceEnabled()) { + LOG.trace("Requesting port stats - {}"); } for (BigInteger node : nodes) { - logger.trace("Requesting AllNodeConnectorStatistics for node - {}", node); + LOG.trace("Requesting AllNodeConnectorStatistics for node - {}", node); statPortService.getAllNodeConnectorsStatistics(buildGetAllNodeConnectorStatistics(node)); opendaylightFlowTableStatisticsService.getFlowTablesStatistics(buildGetFlowTablesStatistics(node)); } @@ -143,30 +141,30 @@ public class NodeConnectorStatsImpl extends AbstractDataChangeListener{ private GetAllNodeConnectorsStatisticsInput buildGetAllNodeConnectorStatistics(BigInteger dpId) { return new GetAllNodeConnectorsStatisticsInputBuilder() - .setNode( - new NodeRef(InstanceIdentifier.builder(Nodes.class) - .child(Node.class, new NodeKey(new NodeId("openflow:" + dpId.toString()))).build())).build(); + .setNode(new NodeRef(InstanceIdentifier.builder(Nodes.class) + .child(Node.class, new NodeKey(new NodeId("openflow:" + dpId.toString()))).build())) + .build(); } private GetFlowTablesStatisticsInput buildGetFlowTablesStatistics(BigInteger dpId) { return new GetFlowTablesStatisticsInputBuilder() - .setNode( - new NodeRef(InstanceIdentifier.builder(Nodes.class) - .child(Node.class, new NodeKey(new NodeId("openflow:" + dpId.toString()))).build())).build(); + .setNode(new NodeRef(InstanceIdentifier.builder(Nodes.class) + .child(Node.class, new NodeKey(new NodeId("openflow:" + dpId.toString()))).build())) + .build(); } - } private ThreadFactory getThreadFactory(String threadNameFormat) { ThreadFactoryBuilder builder = new ThreadFactoryBuilder(); builder.setNameFormat(threadNameFormat); - builder.setUncaughtExceptionHandler( - (t, e) -> logger.error("Received Uncaught Exception event in Thread: {}", t.getName(), e)); + builder.setUncaughtExceptionHandler((thread, exception) -> LOG + .error("Received Uncaught Exception event in Thread: {}", thread.getName(), exception)); return builder.build(); } /* - * PortRpcStatisticsListener listens for the NodeConnectorStatisticsUpdate and then update the corresponding counter map + * PortRpcStatisticsListener listens for the NodeConnectorStatisticsUpdate + * and then update the corresponding counter map */ class PortRpcStatisticsListener implements OpendaylightPortStatisticsListener { @@ -179,23 +177,35 @@ public class NodeConnectorStatsImpl extends AbstractDataChangeListener{ Map ncIdPacketReceiveMap = new HashMap<>(); Map ncIdBytesSentMap = new HashMap<>(); Map ncIdBytesReceiveMap = new HashMap<>(); - List ncStatsAndPortMapList = ncStats.getNodeConnectorStatisticsAndPortNumberMap(); + List ncStatsAndPortMapList = ncStats + .getNodeConnectorStatisticsAndPortNumberMap(); NodeId nodeId = ncStats.getId(); String node = nodeId.getValue().split(":")[1]; for (NodeConnectorStatisticsAndPortNumberMap ncStatsAndPortMap : ncStatsAndPortMapList) { NodeConnectorId nodeConnector = ncStatsAndPortMap.getNodeConnectorId(); String port = nodeConnector.getValue().split(":")[2]; String nodePortStr = "dpnId_" + node + "_portNum_" + port; - ncIdOFPortDurationMap.put("OFPortDuration:" + nodePortStr + "_OFPortDuration", ncStatsAndPortMap.getDuration().getSecond().getValue().toString()); - ncIdOFPortReceiveDropMap.put("PacketsPerOFPortReceiveDrop:" + nodePortStr + "_PacketsPerOFPortReceiveDrop", ncStatsAndPortMap.getReceiveDrops().toString()); - ncIdOFPortReceiveError.put("PacketsPerOFPortReceiveError:" + nodePortStr + "_PacketsPerOFPortReceiveError", ncStatsAndPortMap.getReceiveErrors().toString()); - ncIdPacketSentMap.put("PacketsPerOFPortSent:" + nodePortStr + "_PacketsPerOFPortSent", ncStatsAndPortMap.getPackets().getTransmitted().toString()); - ncIdPacketReceiveMap.put("PacketsPerOFPortReceive:" + nodePortStr + "_PacketsPerOFPortReceive", ncStatsAndPortMap.getPackets().getReceived().toString()); - ncIdBytesSentMap.put("BytesPerOFPortSent:" + nodePortStr + "_BytesPerOFPortSent", ncStatsAndPortMap.getBytes().getTransmitted().toString()); - ncIdBytesReceiveMap.put("BytesPerOFPortReceive:" + nodePortStr + "_BytesPerOFPortReceive", ncStatsAndPortMap.getBytes().getReceived().toString()); + ncIdOFPortDurationMap.put("OFPortDuration:" + nodePortStr + "_OFPortDuration", + ncStatsAndPortMap.getDuration().getSecond().getValue().toString()); + ncIdOFPortReceiveDropMap.put( + "PacketsPerOFPortReceiveDrop:" + nodePortStr + "_PacketsPerOFPortReceiveDrop", + ncStatsAndPortMap.getReceiveDrops().toString()); + ncIdOFPortReceiveError.put( + "PacketsPerOFPortReceiveError:" + nodePortStr + "_PacketsPerOFPortReceiveError", + ncStatsAndPortMap.getReceiveErrors().toString()); + ncIdPacketSentMap.put("PacketsPerOFPortSent:" + nodePortStr + "_PacketsPerOFPortSent", + ncStatsAndPortMap.getPackets().getTransmitted().toString()); + ncIdPacketReceiveMap.put("PacketsPerOFPortReceive:" + nodePortStr + "_PacketsPerOFPortReceive", + ncStatsAndPortMap.getPackets().getReceived().toString()); + ncIdBytesSentMap.put("BytesPerOFPortSent:" + nodePortStr + "_BytesPerOFPortSent", + ncStatsAndPortMap.getBytes().getTransmitted().toString()); + ncIdBytesReceiveMap.put("BytesPerOFPortReceive:" + nodePortStr + "_BytesPerOFPortReceive", + ncStatsAndPortMap.getBytes().getReceived().toString()); } - logger.trace("Port Stats {}", ncStatsAndPortMapList); - //Storing allNodeConnectorStats(like ncIdOFPortDurationMap) in a map with key as node for easy removal and addition of allNodeConnectorStats. + LOG.trace("Port Stats {}", ncStatsAndPortMapList); + // Storing allNodeConnectorStats(like ncIdOFPortDurationMap) in a + // map with key as node for easy removal and addition of + // allNodeConnectorStats. nodeAndNcIdOFPortDurationMap.put(node, ncIdOFPortDurationMap); nodeAndNcIdOFPortReceiveDropMap.put(node, ncIdOFPortReceiveDropMap); nodeAndNcIdOFPortReceiveError.put(node, ncIdOFPortReceiveError); @@ -203,7 +213,9 @@ public class NodeConnectorStatsImpl extends AbstractDataChangeListener{ nodeAndNcIdPacketReceiveMap.put(node, ncIdPacketReceiveMap); nodeAndNcIdBytesSentMap.put(node, ncIdBytesSentMap); nodeAndNcIdBytesReceiveMap.put(node, ncIdBytesReceiveMap); - //Combining the stats of all nodeconnectors in all nodes. This Map will be stored under MBean which will be queried as regular intervals. + // Combining the stats of all nodeconnectors in all nodes. This Map + // will be stored under MBean which will be queried as regular + // intervals. ncIdOFPortDurationMap = combineAllNodesStats(nodeAndNcIdOFPortDurationMap); ncIdOFPortReceiveDropMap = combineAllNodesStats(nodeAndNcIdOFPortReceiveDropMap); ncIdOFPortReceiveError = combineAllNodesStats(nodeAndNcIdOFPortReceiveError); @@ -211,12 +223,16 @@ public class NodeConnectorStatsImpl extends AbstractDataChangeListener{ ncIdPacketReceiveMap = combineAllNodesStats(nodeAndNcIdPacketReceiveMap); ncIdBytesSentMap = combineAllNodesStats(nodeAndNcIdBytesSentMap); ncIdBytesReceiveMap = combineAllNodesStats(nodeAndNcIdBytesReceiveMap); - pmagent.connectToPMAgent(ncIdOFPortDurationMap, ncIdOFPortReceiveDropMap, ncIdOFPortReceiveError, ncIdPacketSentMap, ncIdPacketReceiveMap, ncIdBytesSentMap, ncIdBytesReceiveMap); + PMAGENT.connectToPMAgent(ncIdOFPortDurationMap, ncIdOFPortReceiveDropMap, ncIdOFPortReceiveError, + ncIdPacketSentMap, ncIdPacketReceiveMap, ncIdBytesSentMap, ncIdBytesReceiveMap); } /* - * Input allNodesStats contains statistics of all nodeConnectors of all nodes. Key is the node and values contains another map with key as node connector and value as statresult. - * Output will be a map with key as nodeconnector and value as the statresult. The key contains nodeconnectors of all the nodes. + * Input allNodesStats contains statistics of all nodeConnectors of all + * nodes. Key is the node and values contains another map with key as + * node connector and value as statresult. Output will be a map with key + * as nodeconnector and value as the statresult. The key contains + * nodeconnectors of all the nodes. */ } @@ -232,7 +248,8 @@ public class NodeConnectorStatsImpl extends AbstractDataChangeListener{ } /* - * FlowRpcStatisticsListener listens for the FlowTableStatisticsUpdate and then update the corresponding counter map + * FlowRpcStatisticsListener listens for the FlowTableStatisticsUpdate and + * then update the corresponding counter map */ class FlowRpcStatisticsListener implements OpendaylightFlowTableStatisticsListener { @@ -240,16 +257,18 @@ public class NodeConnectorStatsImpl extends AbstractDataChangeListener{ public void onFlowTableStatisticsUpdate(FlowTableStatisticsUpdate flowTableStats) { String node = flowTableStats.getId().getValue().split(":")[1]; Map entriesPerOFTableMap = new HashMap<>(); - List flowTableAndStatisticsMapList = flowTableStats.getFlowTableAndStatisticsMap(); + List flowTableAndStatisticsMapList = flowTableStats + .getFlowTableAndStatisticsMap(); for (FlowTableAndStatisticsMap flowTableAndStatisticsMap : flowTableAndStatisticsMapList) { - String nodeTableStr = "dpnId_" + node + "_table_" + flowTableAndStatisticsMap.getTableId().getValue().toString(); - entriesPerOFTableMap.put("EntriesPerOFTable:" + nodeTableStr + "_EntriesPerOFTable", flowTableAndStatisticsMap.getActiveFlows().getValue().toString()); + String nodeTableStr = "dpnId_" + node + "_table_" + + flowTableAndStatisticsMap.getTableId().getValue().toString(); + entriesPerOFTableMap.put("EntriesPerOFTable:" + nodeTableStr + "_EntriesPerOFTable", + flowTableAndStatisticsMap.getActiveFlows().getValue().toString()); } nodeAndEntriesPerOFTableMap.put(node, entriesPerOFTableMap); entriesPerOFTableMap = combineAllNodesStats(nodeAndEntriesPerOFTableMap); - pmagent.connectToPMAgentAndInvokeEntriesPerOFTable(entriesPerOFTableMap); + PMAGENT.connectToPMAgentAndInvokeEntriesPerOFTable(entriesPerOFTableMap); } - } @Override @@ -274,8 +293,7 @@ public class NodeConnectorStatsImpl extends AbstractDataChangeListener{ } @Override - protected void update(InstanceIdentifier identifier, Node original, - Node update) { + protected void update(InstanceIdentifier identifier, Node original, Node update) { // TODO Auto-generated method stub }