X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fcompatibility%2Fsal-compatibility%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fcompatibility%2FInventoryAndReadAdapter.xtend;h=60e43247c2810383f49b05a24699d14c1c1f355b;hp=47a3d113254eee1ad85a66a63132de283fe4ac73;hb=405ea7ce68d22bd3d2501857c5253793b581b086;hpb=f4af9d60d50ef6be66290641263dbebe95e2894c diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/InventoryAndReadAdapter.xtend b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/InventoryAndReadAdapter.xtend index 47a3d11325..60e43247c2 100644 --- a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/InventoryAndReadAdapter.xtend +++ b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/InventoryAndReadAdapter.xtend @@ -1,8 +1,17 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. 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, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.controller.sal.compatibility import java.util.ArrayList import java.util.Collections import java.util.List +import java.util.Set +import java.util.concurrent.CopyOnWriteArrayList; import org.opendaylight.controller.sal.binding.api.data.DataBrokerService import org.opendaylight.controller.sal.binding.api.data.DataProviderService import org.opendaylight.controller.sal.core.Edge @@ -93,15 +102,23 @@ class InventoryAndReadAdapter implements IPluginInReadService, @Property OpendaylightFlowTableStatisticsService flowTableStatisticsService; - @Property - IPluginOutInventoryService inventoryPublisher; - @Property FlowTopologyDiscoveryService topologyDiscovery; @Property - List statisticsPublisher = new ArrayList(); - + List statisticsPublisher = new CopyOnWriteArrayList(); + + @Property + List inventoryPublisher = new CopyOnWriteArrayList(); + + def setInventoryPublisher(IPluginOutInventoryService listener){ + inventoryPublisher.add(listener); + } + + def unsetInventoryPublisher(IPluginOutInventoryService listener){ + inventoryPublisher.remove(listener); + } + def setReadPublisher(IPluginOutReadService listener) { statisticsPublisher.add(listener); } @@ -132,11 +149,11 @@ class InventoryAndReadAdapter implements IPluginInReadService, val table= it.readConfigurationData(tableRef) as Table; if(table != null){ - LOG.info("Number of flows installed in table 0 of node {} : {}",node,table.flow.size); + LOG.trace("Number of flows installed in table 0 of node {} : {}",node,table.flow.size); for(flow : table.flow){ - val adsalFlow = ToSalConversionsUtils.toFlow(flow); + val adsalFlow = ToSalConversionsUtils.toFlow(flow,node); val statsFromDataStore = flow.getAugmentation(FlowStatisticsData); if(statsFromDataStore != null){ @@ -238,7 +255,7 @@ class InventoryAndReadAdapter implements IPluginInReadService, val table= it.readConfigurationData(tableRef) as Table; if(table != null){ - LOG.info("Number of flows installed in table 0 of node {} : {}",node,table.flow.size); + LOG.trace("Number of flows installed in table 0 of node {} : {}",node,table.flow.size); for(mdsalFlow : table.flow){ if(FromSalConversionsUtils.flowEquals(mdsalFlow, MDFlowMapping.toMDSalflow(targetFlow))){ @@ -330,7 +347,7 @@ class InventoryAndReadAdapter implements IPluginInReadService, override onNodeRemoved(NodeRemoved notification) { val properties = Collections.emptySet(); - inventoryPublisher.updateNode(notification.nodeRef.toADNode, UpdateType.REMOVED, properties); + publishNodeUpdate(notification.nodeRef.toADNode, UpdateType.REMOVED, properties); } override onNodeConnectorUpdated(NodeConnectorUpdated update) { @@ -341,7 +358,7 @@ class InventoryAndReadAdapter implements IPluginInReadService, var nodeConnector = update.nodeConnectorRef.toADNodeConnector - inventoryPublisher.updateNodeConnector(nodeConnector , updateType , update.toADNodeConnectorProperties); + publishNodeConnectorUpdate(nodeConnector , updateType , update.toADNodeConnectorProperties); } override onNodeUpdated(NodeUpdated notification) { @@ -351,13 +368,16 @@ class InventoryAndReadAdapter implements IPluginInReadService, if ( this._dataService.readOperationalData(identifier) == null ){ updateType = UpdateType.ADDED; } - inventoryPublisher.updateNode(notification.nodeRef.toADNode, updateType, notification.toADNodeProperties); + publishNodeUpdate(notification.nodeRef.toADNode, updateType, notification.toADNodeProperties); //Notify the listeners of IPluginOutReadService for (statsPublisher : statisticsPublisher){ val nodeRef = InstanceIdentifier.builder(Nodes).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node,new NodeKey(notification.id)).toInstance; - statsPublisher.descriptionStatisticsUpdated(nodeRef.toADNode,toNodeDescription(notification.nodeRef)); + val description = notification.nodeRef.toNodeDescription + if(description != null) { + statsPublisher.descriptionStatisticsUpdated(nodeRef.toADNode,description); + } } } @@ -424,9 +444,12 @@ class InventoryAndReadAdapter implements IPluginInReadService, private def FlowCapableNode readFlowCapableNode(NodeRef ref) { val dataObject = dataService.readOperationalData(ref.value as InstanceIdentifier); - val node = dataObject.checkInstanceOf( - org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node); - return node.getAugmentation(FlowCapableNode); + if(dataObject != null) { + val node = dataObject.checkInstanceOf( + org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node); + return node.getAugmentation(FlowCapableNode); + } + return null; } private def FlowCapableNodeConnector readFlowCapableNodeConnector(NodeConnectorRef ref) { @@ -482,14 +505,16 @@ class InventoryAndReadAdapter implements IPluginInReadService, private def toNodeDescription(NodeRef nodeRef){ val capableNode = readFlowCapableNode(nodeRef); - - val it = new NodeDescription() - manufacturer = capableNode.manufacturer - serialNumber = capableNode.serialNumber - software = capableNode.software - description = capableNode.description - - return it; + if(capableNode !=null) { + val it = new NodeDescription() + manufacturer = capableNode.manufacturer + serialNumber = capableNode.serialNumber + software = capableNode.software + description = capableNode.description + + return it; + } + return null; } @@ -507,14 +532,14 @@ class InventoryAndReadAdapter implements IPluginInReadService, override onFlowsStatisticsUpdate(FlowsStatisticsUpdate notification) { val adsalFlowsStatistics = new ArrayList(); + val nodeRef = InstanceIdentifier.builder(Nodes).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node,new NodeKey(notification.id)).toInstance; for(flowStats : notification.flowAndStatisticsMapList){ if(flowStats.tableId == 0) - adsalFlowsStatistics.add(toFlowOnNode(flowStats)); + adsalFlowsStatistics.add(toFlowOnNode(flowStats,nodeRef.toADNode)); } for (statsPublisher : statisticsPublisher){ - val nodeRef = InstanceIdentifier.builder(Nodes).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node,new NodeKey(notification.id)).toInstance; statsPublisher.nodeFlowStatisticsUpdated(nodeRef.toADNode,adsalFlowsStatistics); } @@ -559,9 +584,9 @@ class InventoryAndReadAdapter implements IPluginInReadService, } - private static def toFlowOnNode (FlowAndStatisticsMapList flowAndStatsMap){ + private static def toFlowOnNode (FlowAndStatisticsMapList flowAndStatsMap,Node node){ - val it = new FlowOnNode(ToSalConversionsUtils.toFlow(flowAndStatsMap)); + val it = new FlowOnNode(ToSalConversionsUtils.toFlow(flowAndStatsMap,node)); byteCount = flowAndStatsMap.byteCount.value.longValue; packetCount = flowAndStatsMap.packetCount.value.longValue; @@ -574,4 +599,17 @@ class InventoryAndReadAdapter implements IPluginInReadService, override getConfiguredNotConnectedNodes() { return Collections.emptySet(); } + + + private def publishNodeUpdate(Node node, UpdateType updateType, Set properties){ + for( publisher : inventoryPublisher){ + publisher.updateNode(node, updateType, properties); + } + } + + private def publishNodeConnectorUpdate(org.opendaylight.controller.sal.core.NodeConnector nodeConnector, UpdateType updateType, Set properties){ + for( publisher : inventoryPublisher){ + publisher.updateNodeConnector(nodeConnector, updateType, properties); + } + } }