From: Michal Rehak Date: Sat, 20 Sep 2014 12:11:11 +0000 (+0200) Subject: BUG-1866: sal-compatibility does not register some services X-Git-Tag: release/helium~29^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=175950301a22b48acd9630c40392f0272decba9a;hp=9e59cc0d824e6752a7a3f3ba092abaaf3c1d4193 BUG-1866: sal-compatibility does not register some services - fixed service wiring - involved statistics collected by statisticsManager (instead fresh request) Change-Id: I9914dd7e9b20c87d77f7b5350abb9f5c8ba02c0f Signed-off-by: Michal Rehak --- diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ComponentActivator.java b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ComponentActivator.java index d71858e5c3..4fc0cf75b3 100644 --- a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ComponentActivator.java +++ b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ComponentActivator.java @@ -139,6 +139,7 @@ public class ComponentActivator extends ComponentActivatorAbstractBase { protected Object[] getImplementations() { return new Object[] { dataPacketService, + inventory, }; } @@ -148,6 +149,8 @@ public class ComponentActivator extends ComponentActivatorAbstractBase { _instanceConfigure((ComponentActivator)imp, c, containerName); } else if (imp instanceof DataPacketServiceAdapter) { _instanceConfigure((DataPacketServiceAdapter)imp, c, containerName); + } else if (imp instanceof InventoryAndReadAdapter) { + _instanceConfigure((InventoryAndReadAdapter)imp, c, containerName); } else { throw new IllegalArgumentException(String.format("Unhandled implementation class %s", imp.getClass())); } @@ -215,6 +218,22 @@ public class ComponentActivator extends ComponentActivatorAbstractBase { .setRequired(false)); } + private void _instanceConfigure(final InventoryAndReadAdapter imp, final Component it, String containerName) { + it.setInterface(new String[] { + IPluginInInventoryService.class.getName(), + IPluginInReadService.class.getName(), + }, properties()); + + it.add(createServiceDependency() + .setService(IPluginOutReadService.class) + .setCallbacks("setReadPublisher", "unsetReadPublisher") + .setRequired(false)); + it.add(createServiceDependency() + .setService(IPluginOutInventoryService.class) + .setCallbacks("setInventoryPublisher", "unsetInventoryPublisher") + .setRequired(false)); + } + private void _configure(final TopologyAdapter imp, final Component it) { it.setInterface(IPluginInTopologyService.class.getName(), properties()); diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/InventoryAndReadAdapter.java b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/InventoryAndReadAdapter.java index e2c1386775..1530e909ad 100644 --- a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/InventoryAndReadAdapter.java +++ b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/InventoryAndReadAdapter.java @@ -48,7 +48,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.ta import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsUpdate; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsData; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsListener; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService; @@ -241,20 +240,20 @@ public class InventoryAndReadAdapter implements IPluginInReadService, IPluginInI * @param id Table id * @return Table contents, or null if not present */ - private Table readConfigTable(final Node node, final short id) { + private Table readOperationalTable(final Node node, final short id) { final InstanceIdentifier tableRef = InstanceIdentifier.builder(Nodes.class) - .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class, InventoryMapping.toNodeKey(node)) + .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class, NodeMapping.toNodeKey(node)) .augmentation(FlowCapableNode.class) .child(Table.class, new TableKey(id)) .build(); - return (Table) startChange().readConfigurationData(tableRef); + return (Table) startChange().readOperationalData(tableRef); } @Override public List readAllFlow(final Node node, final boolean cached) { final ArrayList output = new ArrayList<>(); - final Table table = readConfigTable(node, OPENFLOWV10_TABLE_ID); + final Table table = readOperationalTable(node, OPENFLOWV10_TABLE_ID); if (table != null) { final List flows = table.getFlow(); LOG.trace("Number of flows installed in table 0 of node {} : {}", node, flows.size()); @@ -268,12 +267,6 @@ public class InventoryAndReadAdapter implements IPluginInReadService, IPluginInI } } - // TODO (main): Shall we send request to the switch? It will make async request to the switch. - // Once the plugin receives a response, it will let the adaptor know through onFlowStatisticsUpdate() - // If we assume that md-sal statistics manager will always be running, then it is not required - // But if not, then sending request will collect the latest data for adaptor at least. - getFlowStatisticsService().getAllFlowsStatisticsFromAllFlowTables( - new GetAllFlowsStatisticsFromAllFlowTablesInputBuilder().setNode(NodeMapping.toNodeRef(node)).build()); return output; } @@ -334,7 +327,7 @@ public class InventoryAndReadAdapter implements IPluginInReadService, IPluginInI @Override public FlowOnNode readFlow(final Node node, final org.opendaylight.controller.sal.flowprogrammer.Flow targetFlow, final boolean cached) { FlowOnNode ret = null; - final Table table = readConfigTable(node, OPENFLOWV10_TABLE_ID); + final Table table = readOperationalTable(node, OPENFLOWV10_TABLE_ID); if (table != null) { final List flows = table.getFlow(); InventoryAndReadAdapter.LOG.trace("Number of flows installed in table 0 of node {} : {}", node, flows.size()); @@ -386,7 +379,7 @@ public class InventoryAndReadAdapter implements IPluginInReadService, IPluginInI @Override public NodeTableStatistics readNodeTable(final NodeTable nodeTable, final boolean cached) { NodeTableStatistics nodeStats = null; - final Table table = readConfigTable(nodeTable.getNode(), (short) nodeTable.getID()); + final Table table = readOperationalTable(nodeTable.getNode(), (short) nodeTable.getID()); if (table != null) { final FlowTableStatisticsData tableStats = table.getAugmentation(FlowTableStatisticsData.class); if (tableStats != null) { diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/NodeMapping.java b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/NodeMapping.java index b873f8a9fe..bcb2367e7a 100644 --- a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/NodeMapping.java +++ b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/NodeMapping.java @@ -168,7 +168,22 @@ public final class NodeMapping { * @return */ private static NodeId toNodeId(org.opendaylight.controller.sal.core.Node aDNode) { - return new NodeId(aDNode.getType() + ":" + String.valueOf(aDNode.getID())); + String targetPrefix = null; + if (NodeIDType.OPENFLOW.equals(aDNode.getType())) { + targetPrefix = OPENFLOW_ID_PREFIX; + } else { + targetPrefix = aDNode.getType() + ":"; + } + + return new NodeId(targetPrefix + String.valueOf(aDNode.getID())); + } + + /** + * @param aDNode + * @return md-sal {@link NodeKey} + */ + public static NodeKey toNodeKey(org.opendaylight.controller.sal.core.Node aDNode) { + return new NodeKey(toNodeId(aDNode)); } public static String toNodeConnectorType(final NodeConnectorId ncId, final NodeId nodeId) { diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/NodeMappingTest.java b/opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/NodeMappingTest.java index a776ef2312..759e69f5eb 100644 --- a/opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/NodeMappingTest.java +++ b/opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/NodeMappingTest.java @@ -196,6 +196,19 @@ public class NodeMappingTest { Assert.assertEquals(0xCC4E241C4A000000L, NodeMapping.openflowFullNodeIdToLong("14721743935839928320").longValue()); } + /** + * Test method for + * {@link org.opendaylight.controller.sal.compatibility.NodeMapping#toNodeKey(org.opendaylight.controller.sal.core.Node)} + * . + * @throws ConstructionException + */ + @Test + public void testToNodeKey() throws ConstructionException { + org.opendaylight.controller.sal.core.Node aDNode = new org.opendaylight.controller.sal.core.Node(NodeIDType.OPENFLOW, 42L); + NodeKey nodeKey = NodeMapping.toNodeKey(aDNode); + Assert.assertEquals("openflow:42", nodeKey.getId().getValue()); + } + /** * @param nodeId * @param portId