From 3e9ae1b9e14cfe9aee4cb20f78f845c1de7a986b Mon Sep 17 00:00:00 2001 From: Sam Hague Date: Tue, 3 Mar 2015 19:41:13 -0500 Subject: [PATCH 1/1] Migrate from adsal Node to mdsal Node This is a large commit becuase the sal Node is used all over the code. There is no way to build without doing it all in once shot. Patch Set 2,3: No changes, just testing openstack integration. Something was broken in controller code causing failures. A rebuild this morning pulled in numerous new artifacts and cleared up the issue. Change-Id: I9e53f61ad82dc0c6c1c447d9a7d4f2bcf11dbca0 Signed-off-by: Sam Hague --- commons/integrationtest/pom.xml | 5 + .../ovsdb/src/main/resources/features.xml | 3 + .../CompatOvsdbIntegrationTestBase.java | 60 ++++ .../integrationtest/ConfigurationBundles.java | 11 + .../OvsdbIntegrationTestBase.java | 2 +- .../library/OvsdbLibraryIT.java | 5 +- .../integrationtest/neutron/NeutronIT.java | 41 +-- .../northbound/OvsdbNorthboundV2IT.java | 14 +- .../integrationtest/plugin/OvsdbPluginIT.java | 22 +- .../plugin/OvsdbPluginV3CompatIT.java | 284 ++++++++++++++++++ .../plugin/OvsdbPluginV3IT.java | 25 +- .../schema/hardwarevtep/HardwareVTEPIT.java | 4 +- .../schema/openvswitch/OpenVSwitchIT.java | 4 +- northbound/pom.xml | 4 + .../ovsdb/northbound/NodeResource.java | 2 +- .../ovsdb/northbound/OvsdbNorthboundV2.java | 2 +- .../ovsdb/northbound/RowResource.java | 2 +- .../ovsdb/northbound/NodeResourceTest.java | 7 +- ovsdb-plugin-compatibility-layer/pom.xml | 10 + .../compatibility/plugin/api/NodeUtils.java | 69 +++++ .../plugin/impl/ConfigurationServiceImpl.java | 51 ++-- .../plugin/impl/ConnectionServiceImpl.java | 11 +- .../plugin/impl/InventoryServiceImpl.java | 52 ++-- .../plugin/internal/Activator.java | 3 + .../impl/ConnectionServiceImplTest.java | 83 +++++ .../plugin/impl/NodeFactoryTest.java | 21 -- .../ovsdb/plugin/shell/PrintCache.java | 12 +- .../ovsdb/plugin/shell/PrintCacheTest.java | 29 +- plugin/pom.xml | 8 + .../ovsdb/plugin/api/Connection.java | 19 +- .../plugin/api/OvsdbConfigurationService.java | 3 +- .../plugin/api/OvsdbConnectionService.java | 2 +- .../plugin/api/OvsdbInventoryListener.java | 2 +- .../plugin/api/OvsdbInventoryService.java | 2 +- .../plugin/impl/ConfigurationServiceImpl.java | 2 +- .../plugin/impl/ConnectionServiceImpl.java | 31 +- .../plugin/impl/InventoryServiceImpl.java | 3 +- .../ovsdb/plugin/internal/Activator.java | 7 - .../impl/ConnectionServiceImplTest.java | 34 ++- .../ovsdb/plugin/impl/NodeFactoryTest.java | 21 -- pom.xml | 1 - 41 files changed, 762 insertions(+), 211 deletions(-) create mode 100644 integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/CompatOvsdbIntegrationTestBase.java create mode 100644 integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/plugin/OvsdbPluginV3CompatIT.java create mode 100644 ovsdb-plugin-compatibility-layer/src/main/java/org/opendaylight/ovsdb/compatibility/plugin/api/NodeUtils.java create mode 100644 ovsdb-plugin-compatibility-layer/src/test/java/org/opendaylight/ovsdb/compatibility/plugin/impl/ConnectionServiceImplTest.java delete mode 100644 ovsdb-plugin-compatibility-layer/src/test/java/org/opendaylight/ovsdb/compatibility/plugin/impl/NodeFactoryTest.java delete mode 100644 plugin/src/test/java/org/opendaylight/ovsdb/plugin/impl/NodeFactoryTest.java diff --git a/commons/integrationtest/pom.xml b/commons/integrationtest/pom.xml index ccaf699e9..58cf3feab 100644 --- a/commons/integrationtest/pom.xml +++ b/commons/integrationtest/pom.xml @@ -515,6 +515,11 @@ and is available at http://www.eclipse.org/legal/epl-v10.html sal.implementation ${sal.implementation.version} + + org.opendaylight.controller + sal-binding-it + ${mdsal.version} + org.opendaylight.controller security diff --git a/features/ovsdb/src/main/resources/features.xml b/features/ovsdb/src/main/resources/features.xml index b35bdb6bd..11b462250 100644 --- a/features/ovsdb/src/main/resources/features.xml +++ b/features/ovsdb/src/main/resources/features.xml @@ -33,6 +33,7 @@ odl-adsal-all + odl-openflowplugin-nsf-services odl-ovsdb-library odl-ovsdb-schema-openvswitch odl-ovsdb-schema-hardwarevtep @@ -43,10 +44,12 @@ odl-ovsdb-plugin odl-adsal-northbound + odl-openflowplugin-nsf-services mvn:org.opendaylight.ovsdb/northbound/${ovsdb.northbound.version} + odl-openflowplugin-nsf-services odl-ovsdb-plugin mvn:org.opendaylight.ovsdb/ovsdb-plugin-compatibility-layer/${ovsdb.plugin.compatibility.layer.version} diff --git a/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/CompatOvsdbIntegrationTestBase.java b/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/CompatOvsdbIntegrationTestBase.java new file mode 100644 index 000000000..ac21fa7e5 --- /dev/null +++ b/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/CompatOvsdbIntegrationTestBase.java @@ -0,0 +1,60 @@ +package org.opendaylight.ovsdb.integrationtest; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; +import org.opendaylight.controller.sal.core.Node; +import org.opendaylight.controller.sal.utils.ServiceHelper; +import org.opendaylight.ovsdb.plugin.api.ConnectionConstants; +import org.opendaylight.ovsdb.compatibility.plugin.api.OvsdbConnectionService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public abstract class CompatOvsdbIntegrationTestBase extends OvsdbIntegrationTestBase { + private static final Logger LOG = LoggerFactory.getLogger(OvsdbIntegrationTestBase.class); + + public Node getCompatPluginTestConnection() throws IOException, + InterruptedException, ExecutionException, TimeoutException { + Properties props = loadProperties(); + String addressStr = props.getProperty(SERVER_IPADDRESS); + String portStr = props.getProperty(SERVER_PORT, DEFAULT_SERVER_PORT); + String connectionType = props.getProperty(CONNECTION_TYPE, "active"); + org.opendaylight.controller.sal.core.Node node = null; + + OvsdbConnectionService connection = (OvsdbConnectionService) + ServiceHelper.getGlobalInstance(OvsdbConnectionService.class, this); + // If the connection type is active, controller connects to the ovsdb-server + if (connectionType.equalsIgnoreCase(CONNECTION_TYPE_ACTIVE)) { + if (addressStr == null) { + fail(usage()); + } + + Map params = new HashMap(); + params.put(ConnectionConstants.ADDRESS, addressStr); + params.put(ConnectionConstants.PORT, portStr); + node = connection.connect(IDENTIFIER, params); + } else if (connectionType.equalsIgnoreCase(CONNECTION_TYPE_PASSIVE)) { + // Wait for CONNECTION_INIT_TIMEOUT for the Passive connection to be initiated by the ovsdb-server. + Thread.sleep(CONNECTION_INIT_TIMEOUT); + List nodes = connection.getNodes(); + assertNotNull(nodes); + assertTrue(nodes.size() > 0); + node = nodes.get(0); + } + + if (node != null) { + LOG.info("getPluginTestConnection: Successfully connected to {}", node); + } else { + fail("Connection parameter (" + CONNECTION_TYPE + ") must be active or passive"); + } + return node; + } +} diff --git a/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/ConfigurationBundles.java b/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/ConfigurationBundles.java index f4a1e189c..329edb144 100644 --- a/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/ConfigurationBundles.java +++ b/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/ConfigurationBundles.java @@ -14,6 +14,7 @@ import static org.ops4j.pax.exam.CoreOptions.mavenBundle; import static org.ops4j.pax.exam.CoreOptions.systemPackages; import static org.ops4j.pax.exam.CoreOptions.systemProperty; +import org.opendaylight.controller.test.sal.binding.it.TestHelper; import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.options.DefaultCompositeOption; @@ -206,4 +207,14 @@ public class ConfigurationBundles { ); } + public static Option mdsalBundles() { + return new DefaultCompositeOption( + //TestHelper.mdSalCoreBundles(), + //TestHelper.bindingAwareSalBundles(), + TestHelper.configMinumumBundles(), + TestHelper.baseModelBundles(), + TestHelper.flowCapableModelBundles(), + TestHelper.junitAndMockitoBundles() + ); + } } diff --git a/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/OvsdbIntegrationTestBase.java b/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/OvsdbIntegrationTestBase.java index df3000bd9..287189447 100644 --- a/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/OvsdbIntegrationTestBase.java +++ b/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/OvsdbIntegrationTestBase.java @@ -29,8 +29,8 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.utils.ServiceHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.opendaylight.ovsdb.lib.OvsdbClient; import org.opendaylight.ovsdb.lib.OvsdbConnection; import org.opendaylight.ovsdb.lib.OvsdbConnectionListener; diff --git a/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/library/OvsdbLibraryIT.java b/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/library/OvsdbLibraryIT.java index 66f8d5dad..4d5ea56b1 100644 --- a/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/library/OvsdbLibraryIT.java +++ b/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/library/OvsdbLibraryIT.java @@ -15,7 +15,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; import static org.opendaylight.ovsdb.lib.operations.Operations.op; -import static org.ops4j.pax.exam.CoreOptions.junitBundles; import static org.ops4j.pax.exam.CoreOptions.options; import static org.ops4j.pax.exam.CoreOptions.propagateSystemProperty; import static org.ops4j.pax.exam.CoreOptions.systemProperty; @@ -75,10 +74,10 @@ public class OvsdbLibraryIT extends OvsdbIntegrationTestBase { propagateSystemProperty("ovsdbserver.ipaddress"), propagateSystemProperty("ovsdbserver.port"), + ConfigurationBundles.mdsalBundles(), ConfigurationBundles.controllerBundles(), ConfigurationBundles.ovsdbLibraryBundles(), - ConfigurationBundles.ovsdbDefaultSchemaBundles(), - junitBundles() + ConfigurationBundles.ovsdbDefaultSchemaBundles() ); } diff --git a/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/neutron/NeutronIT.java b/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/neutron/NeutronIT.java index b5908772b..8ae8a716b 100644 --- a/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/neutron/NeutronIT.java +++ b/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/neutron/NeutronIT.java @@ -13,14 +13,13 @@ package org.opendaylight.ovsdb.integrationtest.neutron; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; -import static org.ops4j.pax.exam.CoreOptions.junitBundles; import static org.ops4j.pax.exam.CoreOptions.options; import static org.ops4j.pax.exam.CoreOptions.propagateSystemProperty; import static org.ops4j.pax.exam.CoreOptions.systemProperty; -import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.utils.Status; import org.opendaylight.neutron.spi.NeutronNetwork; +import org.opendaylight.ovsdb.compatibility.plugin.api.NodeUtils; import org.opendaylight.ovsdb.integrationtest.ConfigurationBundles; import org.opendaylight.ovsdb.integrationtest.OvsdbIntegrationTestBase; import org.opendaylight.ovsdb.lib.notation.Row; @@ -34,6 +33,7 @@ import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService; import org.opendaylight.ovsdb.schema.openvswitch.Bridge; import org.opendaylight.ovsdb.schema.openvswitch.Interface; import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import com.google.common.collect.ImmutableMap; @@ -102,12 +102,12 @@ public class NeutronIT extends OvsdbIntegrationTestBase { propagateSystemProperty("ovsdbserver.ipaddress"), propagateSystemProperty("ovsdbserver.port"), + ConfigurationBundles.mdsalBundles(), ConfigurationBundles.controllerBundles(), ConfigurationBundles.ovsdbLibraryBundles(), ConfigurationBundles.ovsdbDefaultSchemaBundles(), ConfigurationBundles.ovsdbPluginBundles(), - ConfigurationBundles.ovsdbNeutronBundles(), - junitBundles() + ConfigurationBundles.ovsdbNeutronBundles() ); } @@ -156,7 +156,7 @@ public class NeutronIT extends OvsdbIntegrationTestBase { Thread.sleep(5000); // Create the integration bridge - bridgeConfigurationManager.prepareNode(node); + bridgeConfigurationManager.prepareNode(NodeUtils.getSalNode(node)); Map bridgeRows = @@ -166,7 +166,8 @@ public class NeutronIT extends OvsdbIntegrationTestBase { Bridge bridgeRow = ovsdbConfigurationService.getTypedRow(node, Bridge.class, bridgeRows.values().iterator().next()); Assert.assertEquals(netVirtConfigurationService.getIntegrationBridgeName(), bridgeRow.getName()); - String uuid = bridgeConfigurationManager.getBridgeUuid(node, netVirtConfigurationService.getIntegrationBridgeName()); + String uuid = bridgeConfigurationManager.getBridgeUuid(NodeUtils.getSalNode(node), + netVirtConfigurationService.getIntegrationBridgeName()); Assert.assertEquals(uuid, bridgeRow.getUuid().toString()); tearDownBridge = true; @@ -184,7 +185,7 @@ public class NeutronIT extends OvsdbIntegrationTestBase { OpenVSwitch.class, ovsRows.values().iterator().next()); - Assert.assertEquals(null, netVirtConfigurationService.getTunnelEndPoint(node)); + Assert.assertEquals(null, netVirtConfigurationService.getTunnelEndPoint(NodeUtils.getSalNode(node))); final UUID originalVersion = ovsRow.getVersion(); OpenVSwitch updateOvsRow = ovsdbConfigurationService.createTypedRow(node, OpenVSwitch.class); @@ -203,11 +204,13 @@ public class NeutronIT extends OvsdbIntegrationTestBase { ovsRow.getOtherConfigColumn().getData()); // Make sure tunnel end point was set - Assert.assertEquals(InetAddress.getByName(endpointAddress), netVirtConfigurationService.getTunnelEndPoint(node)); + Assert.assertEquals(InetAddress.getByName(endpointAddress), + netVirtConfigurationService.getTunnelEndPoint(NodeUtils.getSalNode(node))); // Fetch rows again, and compare tunnel end point values ovsRows = ovsdbConfigurationService.getRows(node, - ovsdbConfigurationService.getTableName(node, OpenVSwitch.class)); + ovsdbConfigurationService.getTableName(node, + OpenVSwitch.class)); ovsRow = ovsdbConfigurationService.getTypedRow(node, OpenVSwitch.class, ovsRows.values().iterator().next()); @@ -224,14 +227,16 @@ public class NeutronIT extends OvsdbIntegrationTestBase { Version ovsVersion = this.getOvsVersion(); if (ovsVersion.compareTo(Constants.OPENFLOW13_SUPPORTED) >= 0) { - Assert.assertEquals(Constants.OPENFLOW13, netVirtConfigurationService.getOpenflowVersion(node)); + Assert.assertEquals(Constants.OPENFLOW13, + netVirtConfigurationService.getOpenflowVersion(NodeUtils.getSalNode(node))); } } @Test public void testGetDefaultGatewayMacAddress() throws Exception { // Thread.sleep(5000); - String defaultGatewayMacAddress = netVirtConfigurationService.getDefaultGatewayMacAddress(node); + String defaultGatewayMacAddress = netVirtConfigurationService. + getDefaultGatewayMacAddress(NodeUtils.getSalNode(node)); if (defaultGatewayMacAddress != null) { String[] splits = defaultGatewayMacAddress.split(":"); @@ -246,8 +251,8 @@ public class NeutronIT extends OvsdbIntegrationTestBase { if (tearDownBridge) { try { - String uuid = bridgeConfigurationManager.getBridgeUuid(node, - netVirtConfigurationService.getIntegrationBridgeName()); + String uuid = bridgeConfigurationManager.getBridgeUuid(NodeUtils.getSalNode(node), + netVirtConfigurationService.getIntegrationBridgeName()); ovsdbConfigurationService.deleteRow(node, ovsdbConfigurationService.getTableName(node, Bridge.class), uuid); } catch (Exception e) { log.error("tearDownBridge Exception : " + e.getMessage()); @@ -306,23 +311,25 @@ public class NeutronIT extends OvsdbIntegrationTestBase { } @Override - public Status handleInterfaceUpdate(NeutronNetwork network, Node source, Interface intf) { + public Status handleInterfaceUpdate(NeutronNetwork network, + org.opendaylight.controller.sal.core.Node source, Interface intf) { return null; } @Override - public Status handleInterfaceDelete(String tunnelType, NeutronNetwork network, Node source, Interface intf, + public Status handleInterfaceDelete(String tunnelType, NeutronNetwork network, + org.opendaylight.controller.sal.core.Node source, Interface intf, boolean isLastInstanceOnNode) { return null; } @Override - public void initializeFlowRules(Node node) { + public void initializeFlowRules(org.opendaylight.controller.sal.core.Node node) { } @Override - public void initializeOFFlowRules(Node openflowNode) { + public void initializeOFFlowRules(org.opendaylight.controller.sal.core.Node openflowNode) { } } diff --git a/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/northbound/OvsdbNorthboundV2IT.java b/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/northbound/OvsdbNorthboundV2IT.java index 29d01aecf..adbdbce5c 100644 --- a/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/northbound/OvsdbNorthboundV2IT.java +++ b/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/northbound/OvsdbNorthboundV2IT.java @@ -15,7 +15,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.ops4j.pax.exam.CoreOptions.junitBundles; import static org.ops4j.pax.exam.CoreOptions.mavenBundle; import static org.ops4j.pax.exam.CoreOptions.options; import static org.ops4j.pax.exam.CoreOptions.propagateSystemProperty; @@ -36,7 +35,7 @@ import org.junit.runners.Parameterized; import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.usermanager.IUserManager; import org.opendaylight.ovsdb.integrationtest.ConfigurationBundles; -import org.opendaylight.ovsdb.integrationtest.OvsdbIntegrationTestBase; +import org.opendaylight.ovsdb.integrationtest.CompatOvsdbIntegrationTestBase; import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExamParameterized; @@ -60,7 +59,7 @@ import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; @RunWith(PaxExamParameterized.class) @ExamReactorStrategy(PerClass.class) -public class OvsdbNorthboundV2IT extends OvsdbIntegrationTestBase { +public class OvsdbNorthboundV2IT extends CompatOvsdbIntegrationTestBase { private Logger log = LoggerFactory.getLogger(OvsdbNorthboundV2IT.class); public static final String USERNAME = "admin"; @@ -90,6 +89,7 @@ public class OvsdbNorthboundV2IT extends OvsdbIntegrationTestBase { for (Map o : object){ Object[] l = o.values().toArray(); parameters.add(l); + break; } return parameters; @@ -245,7 +245,7 @@ public class OvsdbNorthboundV2IT extends OvsdbIntegrationTestBase { assertTrue(this.userManager != null); try { - node = getPluginTestConnection(); + node = getCompatPluginTestConnection(); } catch (Exception e) { fail("Exception : "+e.getMessage()); } @@ -272,13 +272,13 @@ public class OvsdbNorthboundV2IT extends OvsdbIntegrationTestBase { propagateSystemProperty("ovsdbserver.ipaddress"), propagateSystemProperty("ovsdbserver.port"), + ConfigurationBundles.mdsalBundles(), ConfigurationBundles.controllerBundles(), ConfigurationBundles.controllerNorthboundBundles(), ConfigurationBundles.ovsdbLibraryBundles(), ConfigurationBundles.ovsdbDefaultSchemaBundles(), - mavenBundle("org.opendaylight.ovsdb", "plugin").versionAsInProject(), - mavenBundle("org.opendaylight.ovsdb", "northbound").versionAsInProject(), - junitBundles() + ConfigurationBundles.ovsdbPluginBundles(), + mavenBundle("org.opendaylight.ovsdb", "northbound").versionAsInProject() ); } } diff --git a/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/plugin/OvsdbPluginIT.java b/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/plugin/OvsdbPluginIT.java index bb56ea881..3bc3f92e0 100644 --- a/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/plugin/OvsdbPluginIT.java +++ b/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/plugin/OvsdbPluginIT.java @@ -21,7 +21,6 @@ import static org.ops4j.pax.exam.CoreOptions.propagateSystemProperty; import static org.ops4j.pax.exam.CoreOptions.systemProperty; import org.junit.After; -import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.utils.ServiceHelper; import org.opendaylight.ovsdb.integrationtest.ConfigurationBundles; import org.opendaylight.ovsdb.integrationtest.OvsdbIntegrationTestBase; @@ -37,6 +36,8 @@ import org.opendaylight.ovsdb.plugin.api.Status; import org.opendaylight.ovsdb.plugin.api.StatusWithUuid; import org.opendaylight.ovsdb.schema.openvswitch.Bridge; import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Sets; @@ -47,6 +48,8 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; @@ -92,11 +95,11 @@ public class OvsdbPluginIT extends OvsdbIntegrationTestBase { propagateSystemProperty("ovsdbserver.ipaddress"), propagateSystemProperty("ovsdbserver.port"), + ConfigurationBundles.mdsalBundles(), ConfigurationBundles.controllerBundles(), ConfigurationBundles.ovsdbLibraryBundles(), ConfigurationBundles.ovsdbDefaultSchemaBundles(), - ConfigurationBundles.ovsdbPluginBundles(), - junitBundles() + ConfigurationBundles.ovsdbPluginBundles() ); } @@ -179,15 +182,20 @@ public class OvsdbPluginIT extends OvsdbIntegrationTestBase { componentB.setImplementation(listenerB); dm.add(componentB); - Node newNode = Node.fromString("OVS|10.10.10.10:65342"); + NodeId nodeId = new NodeId("OVS|10.10.10.10:65342"); + NodeKey nodeKey = new NodeKey(nodeId); + node = new NodeBuilder() + .setId(nodeId) + .setKey(nodeKey) + .build(); InetAddress address = InetAddress.getByName("10.10.10.10"); int port = 65342; // Trigger event - ovsdbInventoryService.notifyNodeAdded(newNode, address, port); + ovsdbInventoryService.notifyNodeAdded(node, address, port); - Mockito.verify(listenerA, Mockito.times(1)).nodeAdded(newNode, address, port); - Mockito.verify(listenerB, Mockito.times(1)).nodeAdded(newNode, address, port); + Mockito.verify(listenerA, Mockito.times(1)).nodeAdded(node, address, port); + Mockito.verify(listenerB, Mockito.times(1)).nodeAdded(node, address, port); dm.remove(componentA); dm.remove(componentB); diff --git a/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/plugin/OvsdbPluginV3CompatIT.java b/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/plugin/OvsdbPluginV3CompatIT.java new file mode 100644 index 000000000..af70d7bf4 --- /dev/null +++ b/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/plugin/OvsdbPluginV3CompatIT.java @@ -0,0 +1,284 @@ +/* + * Copyright (c) 2014 Red Hat, 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 + * + * Authors : Madhu Venugopal + */ +package org.opendaylight.ovsdb.integrationtest.plugin; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.ops4j.pax.exam.CoreOptions.options; +import static org.ops4j.pax.exam.CoreOptions.propagateSystemProperty; +import static org.ops4j.pax.exam.CoreOptions.systemProperty; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Sets; +import java.io.IOException; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.List; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ExecutionException; +import javax.inject.Inject; +import org.apache.felix.dm.Component; +import org.apache.felix.dm.DependencyManager; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.opendaylight.controller.sal.core.ConstructionException; +import org.opendaylight.controller.sal.core.Node; +import org.opendaylight.controller.sal.utils.ServiceHelper; +import org.opendaylight.ovsdb.integrationtest.CompatOvsdbIntegrationTestBase; +import org.opendaylight.ovsdb.integrationtest.ConfigurationBundles; +import org.opendaylight.ovsdb.lib.OvsdbClient; +import org.opendaylight.ovsdb.lib.OvsdbConnectionInfo; +import org.opendaylight.ovsdb.lib.notation.Row; +import org.opendaylight.ovsdb.lib.notation.UUID; +import org.opendaylight.ovsdb.lib.schema.GenericTableSchema; +import org.opendaylight.ovsdb.plugin.api.Connection; +import org.opendaylight.ovsdb.compatibility.plugin.api.OvsdbConfigurationService; +import org.opendaylight.ovsdb.compatibility.plugin.api.OvsdbConnectionService; +import org.opendaylight.ovsdb.compatibility.plugin.api.OvsdbInventoryListener; +import org.opendaylight.ovsdb.compatibility.plugin.api.OvsdbInventoryService; +import org.opendaylight.controller.sal.utils.StatusCode; +import org.opendaylight.ovsdb.compatibility.plugin.api.StatusWithUuid; +import org.opendaylight.ovsdb.schema.openvswitch.Bridge; +import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch; +import org.ops4j.pax.exam.Configuration; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.junit.PaxExam; +import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; +import org.ops4j.pax.exam.spi.reactors.PerSuite; +import org.ops4j.pax.exam.util.PathUtils; +import org.osgi.framework.BundleContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@RunWith(PaxExam.class) +@ExamReactorStrategy(PerSuite.class) +public class OvsdbPluginV3CompatIT extends CompatOvsdbIntegrationTestBase { + private Logger log = LoggerFactory.getLogger(OvsdbPluginV3CompatIT.class); + @Inject + private BundleContext bc; + private OvsdbConfigurationService ovsdbConfigurationService = null; + private String databaseName = "Open_vSwitch"; + + private Node node = null; + private OvsdbClient client = null; + + // Configure the OSGi container + @Configuration + public Option[] config() { + return options( + // + systemProperty("logback.configurationFile").value( + "file:" + PathUtils.getBaseDir() + + "/src/test/resources/logback.xml" + ), + // To start OSGi console for inspection remotely + systemProperty("osgi.console").value("2401"), + + propagateSystemProperty("ovsdbserver.ipaddress"), + propagateSystemProperty("ovsdbserver.port"), + + ConfigurationBundles.mdsalBundles(), + ConfigurationBundles.controllerBundles(), + ConfigurationBundles.ovsdbLibraryBundles(), + ConfigurationBundles.ovsdbDefaultSchemaBundles(), + ConfigurationBundles.ovsdbPluginBundles() + ); + } + + @Before + public void setUp () throws ExecutionException, InterruptedException, IOException { + areWeReady(bc); + } + + public void getConnection () throws InterruptedException { + try { + node = getCompatPluginTestConnection(); + } catch (Exception e) { + fail("Exception : "+e.getMessage()); + } + this.ovsdbConfigurationService = (OvsdbConfigurationService)ServiceHelper.getGlobalInstance(OvsdbConfigurationService.class, this); + } + + @Test + public void apiTests() throws Exception { + getConnection(); + assertNotNull("Node should not be null", node); + assertNotNull("OvsdbConfigurationService should not be null", ovsdbConfigurationService); + + Thread.sleep(1000); + OvsdbConnectionService + connectionService = (OvsdbConnectionService)ServiceHelper.getGlobalInstance(OvsdbConnectionService.class, this); + + // Check for the ovsdb Connection as seen by the Plugin layer + assertNotNull(connectionService.getNodes()); + assertTrue(connectionService.getNodes().size() > 0); + Node node = connectionService.getNodes().get(0); + Connection connection = connectionService.getConnection(node); + OvsdbConnectionInfo connectionInfo = connection.getClient().getConnectionInfo(); + String identifier = IDENTIFIER; + if (connectionInfo.getType().equals(OvsdbConnectionInfo.ConnectionType.PASSIVE)) { + identifier = connectionInfo.getRemoteAddress().getHostAddress()+":"+connectionInfo.getRemotePort(); + } + assertEquals(node, connectionService.getNode("OVS|" + identifier)); + log.info("Nodes = "+ connectionService.getNodes()); + /* + * Test sequence : + * 1. Print Cache and Assert to make sure the bridge is not created yet. + * 2. Create a bridge with a valid parent_uuid & Assert to make sure the return status is success. + * 3. Assert to make sure the bridge is created with a valid Uuid. + * 4. Delete the bridge & Assert to make sure the return status is success. + * 5. Assert to make sure the bridge is deleted + */ + + this.endToEndApiTest(connection, getOpenVSwitchTableUUID(connection)); + } + + @Test + public void testInventoryListeners() throws UnknownHostException { + DependencyManager dm = new DependencyManager(bc); + + OvsdbInventoryListener listenerA = Mockito.mock(FakeListener.class); + OvsdbInventoryListener listenerB = Mockito.mock(FakeListener.class); + + Component componentA = dm.createComponent(); + componentA.setInterface(OvsdbInventoryListener.class.getName(), null); + componentA.setImplementation(listenerA); + dm.add(componentA); + + Component componentB = dm.createComponent(); + componentB.setInterface(OvsdbInventoryListener.class.getName(), null); + componentB.setImplementation(listenerB); + dm.add(componentB); + + try { + node = new Node("OVS", "10.10.10.10:65342"); + } catch (ConstructionException e) { + log.error("Failed to allocate sal Node", e); + } + InetAddress address = InetAddress.getByName("10.10.10.10"); + int port = 65342; + + // Trigger event + OvsdbInventoryService + ovsdbInventoryService = (OvsdbInventoryService)ServiceHelper + .getGlobalInstance(OvsdbInventoryService.class, this); + ovsdbInventoryService.notifyNodeAdded(node, address, port); + + Mockito.verify(listenerA, Mockito.times(1)).nodeAdded(node, address, port); + Mockito.verify(listenerB, Mockito.times(1)).nodeAdded(node, address, port); + + dm.remove(componentA); + dm.remove(componentB); + + } + + public void endToEndApiTest(Connection connection, String parentUuid) throws Exception { + // 1. Print Cache and Assert to make sure the bridge is not created yet. + printCache(); + + // 2. Create a bridge with a valid parent_uuid & Assert to make sure the return status is success. + StatusWithUuid status = insertBridge(connection, parentUuid); + assertTrue(status.isSuccess()); + + // 3. Assert to make sure the bridge is created with a valid Uuid. + printCache(); + Bridge bridge = connection.getClient().getTypedRowWrapper(Bridge.class, null); + Row bridgeRow = ovsdbConfigurationService.getRow(node, databaseName, bridge.getSchema().getName(), status.getUuid()); + assertNotNull(bridgeRow); + bridge = connection.getClient().getTypedRowWrapper(Bridge.class, bridgeRow); + log.info("Bridge UUID "+bridge.getUuid()+" Status Uuid "+status.getUuid()); + assertEquals(bridge.getUuid(), status.getUuid()); + + bridge = connection.getClient().createTypedRowWrapper(Bridge.class); + bridge.setDatapathType("netdev"); + try { + ovsdbConfigurationService.updateRow(node, databaseName, bridge.getSchema().getName(), status.getUuid(), bridge.getRow(), false); + } catch (Exception e) { + fail("Failed to updated Bridge "+e.getMessage()); + } + + // 4. Delete the bridge & Assert to make sure the return status is success. + try { + ovsdbConfigurationService.deleteRow(node, databaseName, bridge.getSchema().getName(), null, new UUID(parentUuid) ,null, status.getUuid()); + } catch (Exception e) { + fail(e.getMessage()); + } + + // 5. Assert to make sure the bridge is deleted + bridgeRow = ovsdbConfigurationService.getRow(node, databaseName, bridge.getSchema().getName(), status.getUuid()); + assertNull(bridgeRow); + } + + public StatusWithUuid insertBridge(Connection connection, String parentUuid) throws Exception { + Bridge bridge = connection.getClient().createTypedRowWrapper(Bridge.class); + bridge.setName("br_test1"); + bridge.setStatus(ImmutableMap.of("key", "value")); + bridge.setFloodVlans(Sets.newHashSet(34L)); + try { + Row row = ovsdbConfigurationService.insertTree(node, databaseName, bridge.getSchema().getName(), new UUID(parentUuid), bridge.getRow()); + bridge = connection.getClient().getTypedRowWrapper(Bridge.class, row); + return new StatusWithUuid(StatusCode.SUCCESS, bridge.getUuid()); + } catch (Exception e) { + return new StatusWithUuid(StatusCode.INTERNALERROR); + } + } + + public String getOpenVSwitchTableUUID(Connection connection) throws Exception { + OpenVSwitch openVSwitch = connection.getClient().getTypedRowWrapper(OpenVSwitch.class, null); + ConcurrentMap> rows = ovsdbConfigurationService.getRows(node, databaseName, openVSwitch.getSchema().getName()); + if (rows == null || rows.size() == 0) return null; + return rows.keySet().toArray()[0].toString(); + } + + public void printCache() throws Exception { + List tables = ovsdbConfigurationService.getTables(node, databaseName); + log.info("Tables = "+tables); + assertNotNull(tables); + for (String table : tables) { + log.info("Table "+table); + ConcurrentMap> rows = ovsdbConfigurationService.getRows(node, databaseName, table); + log.info(rows.toString()); + } + } + + public class FakeListener implements OvsdbInventoryListener { + + @Override + public void nodeAdded(Node node, InetAddress address, int port) { + + } + + @Override + public void nodeRemoved(Node node) { + + } + + @Override + public void rowAdded(Node node, String tableName, String uuid, Row row) { + + } + + @Override + public void rowUpdated(Node node, String tableName, String uuid, Row old, Row row) { + + } + + @Override + public void rowRemoved(Node node, String tableName, String uuid, Row row, Object context) { + + } + } + +} diff --git a/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/plugin/OvsdbPluginV3IT.java b/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/plugin/OvsdbPluginV3IT.java index 4431268c4..7c7b13bdd 100644 --- a/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/plugin/OvsdbPluginV3IT.java +++ b/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/plugin/OvsdbPluginV3IT.java @@ -14,7 +14,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.ops4j.pax.exam.CoreOptions.junitBundles; import static org.ops4j.pax.exam.CoreOptions.options; import static org.ops4j.pax.exam.CoreOptions.propagateSystemProperty; import static org.ops4j.pax.exam.CoreOptions.systemProperty; @@ -34,7 +33,6 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; -import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.utils.ServiceHelper; import org.opendaylight.ovsdb.integrationtest.ConfigurationBundles; import org.opendaylight.ovsdb.integrationtest.OvsdbIntegrationTestBase; @@ -52,6 +50,10 @@ import org.opendaylight.ovsdb.plugin.api.StatusCode; import org.opendaylight.ovsdb.plugin.api.StatusWithUuid; import org.opendaylight.ovsdb.schema.openvswitch.Bridge; import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; @@ -95,11 +97,11 @@ public class OvsdbPluginV3IT extends OvsdbIntegrationTestBase { propagateSystemProperty("ovsdbserver.ipaddress"), propagateSystemProperty("ovsdbserver.port"), + ConfigurationBundles.mdsalBundles(), ConfigurationBundles.controllerBundles(), ConfigurationBundles.ovsdbLibraryBundles(), ConfigurationBundles.ovsdbDefaultSchemaBundles(), - ConfigurationBundles.ovsdbPluginBundles(), - junitBundles() + ConfigurationBundles.ovsdbPluginBundles() ); } @@ -168,19 +170,24 @@ public class OvsdbPluginV3IT extends OvsdbIntegrationTestBase { componentB.setImplementation(listenerB); dm.add(componentB); - Node newNode = Node.fromString("OVS|10.10.10.10:65342"); + NodeId nodeId = new NodeId("OVS|10.10.10.10:65342"); + NodeKey nodeKey = new NodeKey(nodeId); + node = new NodeBuilder() + .setId(nodeId) + .setKey(nodeKey) + .build(); + InetAddress address = InetAddress.getByName("10.10.10.10"); int port = 65342; // Trigger event - ovsdbInventoryService.notifyNodeAdded(newNode, address, port); + ovsdbInventoryService.notifyNodeAdded(node, address, port); - Mockito.verify(listenerA, Mockito.times(1)).nodeAdded(newNode, address, port); - Mockito.verify(listenerB, Mockito.times(1)).nodeAdded(newNode, address, port); + Mockito.verify(listenerA, Mockito.times(1)).nodeAdded(node, address, port); + Mockito.verify(listenerB, Mockito.times(1)).nodeAdded(node, address, port); dm.remove(componentA); dm.remove(componentB); - } public void endToEndApiTest(Connection connection, String parentUuid) throws Exception { diff --git a/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/schema/hardwarevtep/HardwareVTEPIT.java b/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/schema/hardwarevtep/HardwareVTEPIT.java index 202f92d37..18e566bba 100644 --- a/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/schema/hardwarevtep/HardwareVTEPIT.java +++ b/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/schema/hardwarevtep/HardwareVTEPIT.java @@ -109,10 +109,10 @@ public class HardwareVTEPIT extends OvsdbIntegrationTestBase { propagateSystemProperty("ovsdbserver.ipaddress"), propagateSystemProperty("ovsdbserver.port"), + ConfigurationBundles.mdsalBundles(), ConfigurationBundles.controllerBundles(), ConfigurationBundles.ovsdbLibraryBundles(), - ConfigurationBundles.ovsdbDefaultSchemaBundles(), - junitBundles() + ConfigurationBundles.ovsdbDefaultSchemaBundles() ); } diff --git a/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/schema/openvswitch/OpenVSwitchIT.java b/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/schema/openvswitch/OpenVSwitchIT.java index 17f6e0536..e98074cc4 100644 --- a/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/schema/openvswitch/OpenVSwitchIT.java +++ b/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/schema/openvswitch/OpenVSwitchIT.java @@ -151,10 +151,10 @@ public class OpenVSwitchIT extends OvsdbIntegrationTestBase { propagateSystemProperty("ovsdbserver.ipaddress"), propagateSystemProperty("ovsdbserver.port"), + ConfigurationBundles.mdsalBundles(), ConfigurationBundles.controllerBundles(), ConfigurationBundles.ovsdbLibraryBundles(), - ConfigurationBundles.ovsdbDefaultSchemaBundles(), - junitBundles() + ConfigurationBundles.ovsdbDefaultSchemaBundles() ); } diff --git a/northbound/pom.xml b/northbound/pom.xml index 594fd4cc5..91b51573d 100644 --- a/northbound/pom.xml +++ b/northbound/pom.xml @@ -83,6 +83,10 @@ and is available at http://www.eclipse.org/legal/epl-v10.html org.slf4j slf4j-api + + org.slf4j + slf4j-simple + junit junit diff --git a/northbound/src/main/java/org/opendaylight/ovsdb/northbound/NodeResource.java b/northbound/src/main/java/org/opendaylight/ovsdb/northbound/NodeResource.java index 3cdf0f126..dff799e44 100644 --- a/northbound/src/main/java/org/opendaylight/ovsdb/northbound/NodeResource.java +++ b/northbound/src/main/java/org/opendaylight/ovsdb/northbound/NodeResource.java @@ -18,11 +18,11 @@ import javax.ws.rs.core.Response; import org.opendaylight.controller.northbound.commons.RestMessages; import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException; import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException; -import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.utils.ServiceHelper; import org.opendaylight.ovsdb.lib.OvsdbClient; import org.opendaylight.ovsdb.plugin.api.Connection; import org.opendaylight.ovsdb.plugin.api.OvsdbConnectionService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; diff --git a/northbound/src/main/java/org/opendaylight/ovsdb/northbound/OvsdbNorthboundV2.java b/northbound/src/main/java/org/opendaylight/ovsdb/northbound/OvsdbNorthboundV2.java index 9cba35579..fa25baf92 100644 --- a/northbound/src/main/java/org/opendaylight/ovsdb/northbound/OvsdbNorthboundV2.java +++ b/northbound/src/main/java/org/opendaylight/ovsdb/northbound/OvsdbNorthboundV2.java @@ -37,7 +37,6 @@ import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailab import org.opendaylight.controller.northbound.commons.exception.UnauthorizedException; import org.opendaylight.controller.northbound.commons.utils.NorthboundUtils; import org.opendaylight.controller.sal.authorization.Privilege; -import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.utils.ServiceHelper; import org.opendaylight.ovsdb.plugin.api.Status; import org.opendaylight.ovsdb.lib.OvsdbClient; @@ -48,6 +47,7 @@ import org.opendaylight.ovsdb.plugin.api.OvsVswitchdSchemaConstants; import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService; import org.opendaylight.ovsdb.plugin.api.OvsdbConnectionService; import org.opendaylight.ovsdb.plugin.api.StatusWithUuid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/northbound/src/main/java/org/opendaylight/ovsdb/northbound/RowResource.java b/northbound/src/main/java/org/opendaylight/ovsdb/northbound/RowResource.java index 038a0b597..c6c1ae397 100644 --- a/northbound/src/main/java/org/opendaylight/ovsdb/northbound/RowResource.java +++ b/northbound/src/main/java/org/opendaylight/ovsdb/northbound/RowResource.java @@ -21,7 +21,6 @@ import javax.ws.rs.core.Response; import org.opendaylight.controller.northbound.commons.RestMessages; import org.opendaylight.controller.northbound.commons.exception.BadRequestException; import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException; -import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.utils.ServiceHelper; import org.opendaylight.ovsdb.lib.OvsdbClient; import org.opendaylight.ovsdb.lib.notation.Row; @@ -29,6 +28,7 @@ import org.opendaylight.ovsdb.lib.notation.UUID; import org.opendaylight.ovsdb.lib.schema.GenericTableSchema; import org.opendaylight.ovsdb.plugin.api.OvsVswitchdSchemaConstants; import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; diff --git a/northbound/src/test/java/org/opendaylight/ovsdb/northbound/NodeResourceTest.java b/northbound/src/test/java/org/opendaylight/ovsdb/northbound/NodeResourceTest.java index 159c9d253..9c98e78bf 100644 --- a/northbound/src/test/java/org/opendaylight/ovsdb/northbound/NodeResourceTest.java +++ b/northbound/src/test/java/org/opendaylight/ovsdb/northbound/NodeResourceTest.java @@ -20,12 +20,11 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException; import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException; -import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.controller.sal.core.NodeConnector; import org.opendaylight.controller.sal.utils.ServiceHelper; import org.opendaylight.ovsdb.plugin.api.Connection; import org.opendaylight.ovsdb.plugin.api.OvsdbConnectionService; import org.opendaylight.ovsdb.plugin.impl.ConnectionServiceImpl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; @@ -40,8 +39,6 @@ public class NodeResourceTest { @Test public void testGetOvsdbNode () { - Node.NodeIDType.registerIDType(OVS, String.class); - NodeConnector.NodeConnectorIDType.registerIDType(OVS, String.class, OVS); ConnectionServiceImpl connectionService = new ConnectionServiceImpl(); Connection connection = new Connection(IDENTIFIER, null); connectionService.putOvsdbConnection(IDENTIFIER, connection); @@ -73,8 +70,6 @@ public class NodeResourceTest { @Test public void testGetOvsdbConnection () { - Node.NodeIDType.registerIDType(OVS, String.class); - NodeConnector.NodeConnectorIDType.registerIDType(OVS, String.class, OVS); ConnectionServiceImpl connectionService = new ConnectionServiceImpl(); Connection connection = new Connection(IDENTIFIER, null); connectionService.putOvsdbConnection(IDENTIFIER, connection); diff --git a/ovsdb-plugin-compatibility-layer/pom.xml b/ovsdb-plugin-compatibility-layer/pom.xml index 5debf8632..32d625fd7 100755 --- a/ovsdb-plugin-compatibility-layer/pom.xml +++ b/ovsdb-plugin-compatibility-layer/pom.xml @@ -47,6 +47,16 @@ org.slf4j slf4j-api + + org.slf4j + slf4j-simple + + + org.powermock + powermock-module-junit4 + 1.5.4 + test + diff --git a/ovsdb-plugin-compatibility-layer/src/main/java/org/opendaylight/ovsdb/compatibility/plugin/api/NodeUtils.java b/ovsdb-plugin-compatibility-layer/src/main/java/org/opendaylight/ovsdb/compatibility/plugin/api/NodeUtils.java new file mode 100644 index 000000000..0e28de8cc --- /dev/null +++ b/ovsdb-plugin-compatibility-layer/src/main/java/org/opendaylight/ovsdb/compatibility/plugin/api/NodeUtils.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * 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 + * + * Authors : Sam Hague + */ +package org.opendaylight.ovsdb.compatibility.plugin.api; + +import java.util.ArrayList; +import java.util.List; +import org.opendaylight.controller.sal.core.ConstructionException; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class NodeUtils { + protected static final Logger LOG = LoggerFactory.getLogger(NodeUtils.class); + + public static String getId (String identifier) { + String id = identifier; + + String[] pair = identifier.split("\\|"); + if (pair[0].equals("OVS")) { + id = pair[1]; + } + return id; + } + + public static Node getMdsalNode (org.opendaylight.controller.sal.core.Node salNode) { + String identifier = salNode.getNodeIDString(); + + NodeId nodeId = new NodeId("OVS" + "|" + identifier); + NodeKey nodeKey = new NodeKey(nodeId); + Node node = new NodeBuilder() + .setId(nodeId) + .setKey(nodeKey) + .build(); + + return node; + } + + public static org.opendaylight.controller.sal.core.Node getSalNode (Node mdsalNode) { + String identifier = NodeUtils.getId(mdsalNode.getId().getValue()); + org.opendaylight.controller.sal.core.Node node = null; + + try { + node = new org.opendaylight.controller.sal.core.Node("OVS", identifier); + } catch (ConstructionException e) { + LOG.error("Failed to allocate sal Node", e); + } + + return node; + } + + public static List getSalNodes (List mdsalNodes) { + List nodes = new ArrayList<>(); + + for (Node mdsalNode : mdsalNodes) { + nodes.add(NodeUtils.getSalNode(mdsalNode)); + } + return nodes; + } +} diff --git a/ovsdb-plugin-compatibility-layer/src/main/java/org/opendaylight/ovsdb/compatibility/plugin/impl/ConfigurationServiceImpl.java b/ovsdb-plugin-compatibility-layer/src/main/java/org/opendaylight/ovsdb/compatibility/plugin/impl/ConfigurationServiceImpl.java index 5137fcd1f..628e6798d 100644 --- a/ovsdb-plugin-compatibility-layer/src/main/java/org/opendaylight/ovsdb/compatibility/plugin/impl/ConfigurationServiceImpl.java +++ b/ovsdb-plugin-compatibility-layer/src/main/java/org/opendaylight/ovsdb/compatibility/plugin/impl/ConfigurationServiceImpl.java @@ -13,6 +13,7 @@ import java.util.concurrent.ExecutionException; import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.utils.Status; +import org.opendaylight.ovsdb.compatibility.plugin.api.NodeUtils; import org.opendaylight.ovsdb.compatibility.plugin.api.OvsdbConfigurationService; import org.opendaylight.ovsdb.compatibility.plugin.api.StatusWithUuid; import org.opendaylight.ovsdb.compatibility.plugin.error.OvsdbPluginException; @@ -31,7 +32,7 @@ import org.opendaylight.ovsdb.lib.schema.typed.TypedBaseTable; */ public class ConfigurationServiceImpl implements OvsdbConfigurationService { - org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService pluginOvsdbConfigurationService; + private volatile org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService pluginOvsdbConfigurationService; void init() { } @@ -74,59 +75,64 @@ public class ConfigurationServiceImpl implements OvsdbConfigurationService @Override public StatusWithUuid insertRow(Node node, String tableName, String parentUuid, Row row) { - return StatusConvertorUtil.convertOvsdbStatusWithUuidToCompLayerStatusWithUuid(pluginOvsdbConfigurationService.insertRow(node, tableName, parentUuid, row)); + return StatusConvertorUtil.convertOvsdbStatusWithUuidToCompLayerStatusWithUuid(pluginOvsdbConfigurationService.insertRow(NodeUtils.getMdsalNode(node), tableName, parentUuid, row)); } @Override public Status updateRow (Node node, String tableName, String parentUUID, String rowUUID, Row row) { - return StatusConvertorUtil.convertOvsdbStatusToSalStatus(pluginOvsdbConfigurationService.updateRow(node, tableName, parentUUID, rowUUID, row)); + return StatusConvertorUtil + .convertOvsdbStatusToSalStatus(pluginOvsdbConfigurationService + .updateRow(NodeUtils.getMdsalNode(node), tableName, parentUUID, rowUUID, row)); } @Override public Status deleteRow(Node node, String tableName, String uuid) { - return StatusConvertorUtil.convertOvsdbStatusToSalStatus(pluginOvsdbConfigurationService.deleteRow(node, tableName, uuid)); + return StatusConvertorUtil + .convertOvsdbStatusToSalStatus(pluginOvsdbConfigurationService. + deleteRow(NodeUtils.getMdsalNode(node), tableName, uuid)); } @Override public ConcurrentMap getRows(Node node, String tableName) { - return pluginOvsdbConfigurationService.getRows(node, tableName); + return pluginOvsdbConfigurationService.getRows(NodeUtils.getMdsalNode(node), tableName); } @Override public Row getRow(Node node, String tableName, String uuid) { - return pluginOvsdbConfigurationService.getRow(node, tableName, uuid); + return pluginOvsdbConfigurationService.getRow(NodeUtils.getMdsalNode(node), tableName, uuid); } @Override public List getTables(Node node) { - return pluginOvsdbConfigurationService.getTables(node); + return pluginOvsdbConfigurationService.getTables(NodeUtils.getMdsalNode(node)); } @Override public Boolean setOFController(Node node, String bridgeUUID) throws InterruptedException, ExecutionException { - return pluginOvsdbConfigurationService.setOFController(node, bridgeUUID); + return pluginOvsdbConfigurationService.setOFController(NodeUtils.getMdsalNode(node), bridgeUUID); } @Override public > String getTableName(Node node, Class typedClass) { - return pluginOvsdbConfigurationService.getTableName(node, typedClass); + return pluginOvsdbConfigurationService.getTableName(NodeUtils.getMdsalNode(node), typedClass); } @Override public > T getTypedRow(Node node, Class typedClass, Row row) { - return pluginOvsdbConfigurationService.getTypedRow(node, typedClass, row); + return pluginOvsdbConfigurationService.getTypedRow(NodeUtils.getMdsalNode(node), typedClass, row); } @Override public > T createTypedRow(Node node, Class typedClass) { - return pluginOvsdbConfigurationService.createTypedRow(node, typedClass); + return pluginOvsdbConfigurationService.createTypedRow(NodeUtils.getMdsalNode(node), typedClass); } @Override public UUID insertRow(Node node, String databaseName, String tableName, String parentTable, UUID parentUuid, String parentColumn, Row row) throws OvsdbPluginException { - return pluginOvsdbConfigurationService.insertRow(node, databaseName, tableName, parentTable, parentUuid, - parentColumn, row); + return pluginOvsdbConfigurationService + .insertRow(NodeUtils.getMdsalNode(node), databaseName, tableName, parentTable, parentUuid, + parentColumn, row); } @Override @@ -139,7 +145,9 @@ public class ConfigurationServiceImpl implements OvsdbConfigurationService @Override public Row insertTree(Node node, String databaseName, String tableName, String parentTable, UUID parentUuid, String parentColumn, Row row) throws OvsdbPluginException { - return pluginOvsdbConfigurationService.insertTree(node, databaseName, tableName, parentTable, parentUuid, parentColumn, row); + return pluginOvsdbConfigurationService + .insertTree(NodeUtils.getMdsalNode(node), databaseName, tableName, parentTable, + parentUuid, parentColumn, row); } @Override @@ -153,13 +161,16 @@ public class ConfigurationServiceImpl implements OvsdbConfigurationService public Row updateRow(Node node, String databaseName, String tableName, UUID rowUuid, Row row, boolean overwrite) throws OvsdbPluginException { - return pluginOvsdbConfigurationService.updateRow(node, databaseName, tableName, rowUuid, row, overwrite); + return pluginOvsdbConfigurationService + .updateRow(NodeUtils.getMdsalNode(node), databaseName, tableName, rowUuid, row, overwrite); } @Override public void deleteRow(Node node, String databaseName, String tableName, String parentTable, UUID parentRowUuid, String parentColumn, UUID rowUuid) throws OvsdbPluginException { - pluginOvsdbConfigurationService.deleteRow(node, databaseName, tableName, parentTable, parentRowUuid, parentColumn, rowUuid); + pluginOvsdbConfigurationService + .deleteRow(NodeUtils.getMdsalNode(node), databaseName, tableName, parentTable, + parentRowUuid, parentColumn, rowUuid); } @Override @@ -170,13 +181,15 @@ public class ConfigurationServiceImpl implements OvsdbConfigurationService @Override public Row getRow(Node node, String databaseName, String tableName, UUID uuid) throws OvsdbPluginException { - return pluginOvsdbConfigurationService.getRow(node, databaseName, tableName, uuid); + return pluginOvsdbConfigurationService + .getRow(NodeUtils.getMdsalNode(node), databaseName, tableName, uuid); } @Override public ConcurrentMap> getRows(Node node, String databaseName, String tableName) throws OvsdbPluginException { - return pluginOvsdbConfigurationService.getRows(node, databaseName, tableName); + return pluginOvsdbConfigurationService + .getRows(NodeUtils.getMdsalNode(node), databaseName, tableName); } @Override @@ -188,6 +201,6 @@ public class ConfigurationServiceImpl implements OvsdbConfigurationService @Override public List getTables(Node node, String databaseName) throws OvsdbPluginException { - return pluginOvsdbConfigurationService.getTables(node, databaseName); + return pluginOvsdbConfigurationService.getTables(NodeUtils.getMdsalNode(node), databaseName); } } diff --git a/ovsdb-plugin-compatibility-layer/src/main/java/org/opendaylight/ovsdb/compatibility/plugin/impl/ConnectionServiceImpl.java b/ovsdb-plugin-compatibility-layer/src/main/java/org/opendaylight/ovsdb/compatibility/plugin/impl/ConnectionServiceImpl.java index 25fb245a1..db6daa05d 100644 --- a/ovsdb-plugin-compatibility-layer/src/main/java/org/opendaylight/ovsdb/compatibility/plugin/impl/ConnectionServiceImpl.java +++ b/ovsdb-plugin-compatibility-layer/src/main/java/org/opendaylight/ovsdb/compatibility/plugin/impl/ConnectionServiceImpl.java @@ -11,6 +11,7 @@ import java.util.List; import java.util.Map; import org.opendaylight.controller.sal.core.Node; +import org.opendaylight.ovsdb.compatibility.plugin.api.NodeUtils; import org.opendaylight.ovsdb.compatibility.plugin.api.OvsdbConnectionService; import org.opendaylight.ovsdb.plugin.api.Connection; import org.opendaylight.ovsdb.plugin.api.ConnectionConstants; @@ -28,7 +29,7 @@ import org.slf4j.LoggerFactory; public class ConnectionServiceImpl implements OvsdbConnectionService{ protected static final Logger logger = LoggerFactory.getLogger(ConnectionServiceImpl.class); - org.opendaylight.ovsdb.plugin.api.OvsdbConnectionService pluginOvsdbConnectionService; + private volatile org.opendaylight.ovsdb.plugin.api.OvsdbConnectionService pluginOvsdbConnectionService; public void init() { } @@ -66,22 +67,22 @@ public class ConnectionServiceImpl implements OvsdbConnectionService{ } @Override public Connection getConnection(Node node) { - return pluginOvsdbConnectionService.getConnection(node); + return pluginOvsdbConnectionService.getConnection(NodeUtils.getMdsalNode(node)); } @Override public Node getNode (String identifier) { - return pluginOvsdbConnectionService.getNode(identifier); + return NodeUtils.getSalNode(pluginOvsdbConnectionService.getNode(identifier)); } @Override public List getNodes() { - return pluginOvsdbConnectionService.getNodes(); + return NodeUtils.getSalNodes(pluginOvsdbConnectionService.getNodes()); } @Override public Node connect(String identifier, Map params) { - return pluginOvsdbConnectionService.connect(identifier, params); + return NodeUtils.getSalNode(pluginOvsdbConnectionService.connect(identifier, params)); } } diff --git a/ovsdb-plugin-compatibility-layer/src/main/java/org/opendaylight/ovsdb/compatibility/plugin/impl/InventoryServiceImpl.java b/ovsdb-plugin-compatibility-layer/src/main/java/org/opendaylight/ovsdb/compatibility/plugin/impl/InventoryServiceImpl.java index e5413c236..5e7e7d8d3 100644 --- a/ovsdb-plugin-compatibility-layer/src/main/java/org/opendaylight/ovsdb/compatibility/plugin/impl/InventoryServiceImpl.java +++ b/ovsdb-plugin-compatibility-layer/src/main/java/org/opendaylight/ovsdb/compatibility/plugin/impl/InventoryServiceImpl.java @@ -14,6 +14,7 @@ import java.util.concurrent.ConcurrentMap; import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.core.Property; import org.opendaylight.controller.sal.core.UpdateType; +import org.opendaylight.ovsdb.compatibility.plugin.api.NodeUtils; import org.opendaylight.ovsdb.compatibility.plugin.api.OvsdbInventoryListener; import org.opendaylight.ovsdb.compatibility.plugin.api.OvsdbInventoryService; import org.opendaylight.ovsdb.lib.message.TableUpdates; @@ -31,8 +32,9 @@ import com.google.common.collect.Sets; * @author Anil Vishnoi (vishnoianil@gmail.com) * */ -public class InventoryServiceImpl implements OvsdbInventoryService, org.opendaylight.ovsdb.plugin.api.OvsdbInventoryListener { - org.opendaylight.ovsdb.plugin.api.OvsdbInventoryService pluginOvsdbInventoryService; +public class InventoryServiceImpl implements OvsdbInventoryService, + org.opendaylight.ovsdb.plugin.api.OvsdbInventoryListener { + private volatile org.opendaylight.ovsdb.plugin.api.OvsdbInventoryService pluginOvsdbInventoryService; private Set ovsdbInventoryListeners = Sets.newCopyOnWriteArraySet(); @@ -91,94 +93,98 @@ public class InventoryServiceImpl implements OvsdbInventoryService, org.opendayl @Override public ConcurrentMap> getCache(Node n, String databaseName) { - return pluginOvsdbInventoryService.getCache(n, databaseName); + return pluginOvsdbInventoryService.getCache(NodeUtils.getMdsalNode(n), databaseName); } @Override public ConcurrentMap getTableCache(Node n, String databaseName, String tableName) { - return pluginOvsdbInventoryService.getTableCache(n, databaseName, tableName); + return pluginOvsdbInventoryService.getTableCache(NodeUtils.getMdsalNode(n), databaseName, tableName); } @Override public Row getRow(Node n, String databaseName, String tableName, String uuid) { - return pluginOvsdbInventoryService.getRow(n, databaseName, tableName, uuid); + return pluginOvsdbInventoryService.getRow(NodeUtils.getMdsalNode(n), databaseName, tableName, uuid); } @Override public void updateRow(Node n, String databaseName, String tableName, String uuid, Row row) { - pluginOvsdbInventoryService.updateRow(n, databaseName, tableName, uuid, row); + pluginOvsdbInventoryService.updateRow(NodeUtils.getMdsalNode(n), databaseName, tableName, uuid, row); } @Override public void removeRow(Node n, String databaseName, String tableName, String uuid) { - pluginOvsdbInventoryService.removeRow(n, databaseName, tableName, uuid); + pluginOvsdbInventoryService.removeRow(NodeUtils.getMdsalNode(n), databaseName, tableName, uuid); } @Override public void processTableUpdates(Node n, String databaseName, TableUpdates tableUpdates) { - pluginOvsdbInventoryService.processTableUpdates(n, databaseName, tableUpdates); + pluginOvsdbInventoryService.processTableUpdates(NodeUtils.getMdsalNode(n), databaseName, tableUpdates); } @Override public void printCache(Node n) { - pluginOvsdbInventoryService.printCache(n); + pluginOvsdbInventoryService.printCache(NodeUtils.getMdsalNode(n)); } @Override public void addNode(Node node, Set props) { - pluginOvsdbInventoryService.addNode(node, props); + pluginOvsdbInventoryService.addNode(NodeUtils.getMdsalNode(node), props); } @Override public void notifyNodeAdded(Node node, InetAddress address, int port) { - pluginOvsdbInventoryService.notifyNodeAdded(node, address, port); + pluginOvsdbInventoryService.notifyNodeAdded(NodeUtils.getMdsalNode(node), address, port); } @Override public void addNodeProperty(Node node, UpdateType type, Set props) { - pluginOvsdbInventoryService.addNodeProperty(node, type, props); + pluginOvsdbInventoryService.addNodeProperty(NodeUtils.getMdsalNode(node), type, props); } @Override public void removeNode(Node node) { - pluginOvsdbInventoryService.removeNode(node); + pluginOvsdbInventoryService.removeNode(NodeUtils.getMdsalNode(node)); } @Override - public void nodeAdded(Node node, InetAddress address, int port) { + public void nodeAdded(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node node, + InetAddress address, int port) { for(OvsdbInventoryListener listener : this.ovsdbInventoryListeners) - listener.nodeAdded(node, address, port); + listener.nodeAdded(NodeUtils.getSalNode(node), address, port); } @Override - public void nodeRemoved(Node node) { + public void nodeRemoved(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node node) { for(OvsdbInventoryListener listener : this.ovsdbInventoryListeners) - listener.nodeRemoved(node); + listener.nodeRemoved(NodeUtils.getSalNode(node)); } @Override - public void rowAdded(Node node, String tableName, String uuid, Row row) { + public void rowAdded(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node node, + String tableName, String uuid, Row row) { for(OvsdbInventoryListener listener : this.ovsdbInventoryListeners) - listener.rowAdded(node, tableName, uuid, row); + listener.rowAdded(NodeUtils.getSalNode(node), tableName, uuid, row); } @Override - public void rowUpdated(Node node, String tableName, String uuid, Row old, + public void rowUpdated(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node node, + String tableName, String uuid, Row old, Row row) { for(OvsdbInventoryListener listener : this.ovsdbInventoryListeners) - listener.rowUpdated(node, tableName, uuid, old, row); + listener.rowUpdated(NodeUtils.getSalNode(node), tableName, uuid, old, row); } @Override - public void rowRemoved(Node node, String tableName, String uuid, Row row, + public void rowRemoved(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node node, + String tableName, String uuid, Row row, Object context) { for(OvsdbInventoryListener listener : this.ovsdbInventoryListeners) - listener.rowRemoved(node, tableName, uuid, row, context); + listener.rowRemoved(NodeUtils.getSalNode(node), tableName, uuid, row, context); } } diff --git a/ovsdb-plugin-compatibility-layer/src/main/java/org/opendaylight/ovsdb/compatibility/plugin/internal/Activator.java b/ovsdb-plugin-compatibility-layer/src/main/java/org/opendaylight/ovsdb/compatibility/plugin/internal/Activator.java index 68df6cb08..70a01e626 100644 --- a/ovsdb-plugin-compatibility-layer/src/main/java/org/opendaylight/ovsdb/compatibility/plugin/internal/Activator.java +++ b/ovsdb-plugin-compatibility-layer/src/main/java/org/opendaylight/ovsdb/compatibility/plugin/internal/Activator.java @@ -12,6 +12,7 @@ import java.util.Hashtable; import org.apache.felix.dm.Component; import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase; +import org.opendaylight.controller.sal.core.Node; import org.opendaylight.ovsdb.compatibility.plugin.api.OvsdbConfigurationService; import org.opendaylight.ovsdb.compatibility.plugin.api.OvsdbConnectionService; import org.opendaylight.ovsdb.compatibility.plugin.api.OvsdbInventoryListener; @@ -39,6 +40,7 @@ public class Activator extends ComponentActivatorAbstractBase { */ @Override public void init() { + Node.NodeIDType.registerIDType("OVS", String.class); } /** @@ -48,6 +50,7 @@ public class Activator extends ComponentActivatorAbstractBase { */ @Override public void destroy() { + Node.NodeIDType.unRegisterIDType("OVS"); } @Override public Object[] getGlobalImplementations() { diff --git a/ovsdb-plugin-compatibility-layer/src/test/java/org/opendaylight/ovsdb/compatibility/plugin/impl/ConnectionServiceImplTest.java b/ovsdb-plugin-compatibility-layer/src/test/java/org/opendaylight/ovsdb/compatibility/plugin/impl/ConnectionServiceImplTest.java new file mode 100644 index 000000000..694d6b3ea --- /dev/null +++ b/ovsdb-plugin-compatibility-layer/src/test/java/org/opendaylight/ovsdb/compatibility/plugin/impl/ConnectionServiceImplTest.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * 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 + * + * Authors : Sam Hague + */ +package org.opendaylight.ovsdb.compatibility.plugin.impl; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.fail; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.opendaylight.controller.sal.core.ConstructionException; +import org.opendaylight.controller.sal.core.Node; +import org.opendaylight.controller.sal.core.NodeConnector; +import org.opendaylight.ovsdb.plugin.api.Connection; + +public class ConnectionServiceImplTest { + private static final String OVS = "OVS"; + private static final String IDENTIFIER = "192.168.120.31:45001"; + private static final String OVS_IDENTIFIER = OVS + "|" + IDENTIFIER; + private static final String BAD_IDENTIFIER = "BAD" + "|" + IDENTIFIER; + private static org.opendaylight.ovsdb.plugin.impl.ConnectionServiceImpl pluginConnectionService; + private static ConnectionServiceImpl connectionService; + + @BeforeClass + public static void setUp () { + Node.NodeIDType.registerIDType(OVS, String.class); + NodeConnector.NodeConnectorIDType.registerIDType(OVS, String.class, OVS); + pluginConnectionService = new org.opendaylight.ovsdb.plugin.impl.ConnectionServiceImpl(); + Connection connection = new Connection(IDENTIFIER, null); + pluginConnectionService.putOvsdbConnection(IDENTIFIER, connection); + + connectionService = new ConnectionServiceImpl(); + connectionService.setOvsdbConnectionService(pluginConnectionService); + } + + @Test + public void testGetNode () { + Node node = connectionService.getNode(IDENTIFIER); + assertNotNull("Node " + IDENTIFIER + " is null", node); + + node = connectionService.getNode(OVS_IDENTIFIER); + assertNotNull("Node " + OVS_IDENTIFIER + " is null", node); + + try { + node = connectionService.getNode(BAD_IDENTIFIER); + fail("Expected a NullPointerException to be thrown"); + } catch (NullPointerException e) { + assertSame(NullPointerException.class, e.getClass()); + } + } + + @Test + public void testGetConnection () { + Node node = connectionService.getNode(IDENTIFIER); + assertNotNull("Node " + IDENTIFIER + " is null", node); + + Connection connection = connectionService.getConnection(node); + assertNotNull("Connection " + IDENTIFIER + " is null", connection); + + try { + connection = connectionService.getConnection(null); + fail("Expected a NullPointerException to be thrown"); + } catch (NullPointerException e) { + assertSame(NullPointerException.class, e.getClass()); + } + + try { + node = new Node("OVS", BAD_IDENTIFIER); + } catch (ConstructionException e) { + fail("Exception should not have occurred" + e); + } + connection = connectionService.getConnection(node); + assertNull("Connection " + BAD_IDENTIFIER + " is not null", connection); + } +} diff --git a/ovsdb-plugin-compatibility-layer/src/test/java/org/opendaylight/ovsdb/compatibility/plugin/impl/NodeFactoryTest.java b/ovsdb-plugin-compatibility-layer/src/test/java/org/opendaylight/ovsdb/compatibility/plugin/impl/NodeFactoryTest.java deleted file mode 100644 index d4855e522..000000000 --- a/ovsdb-plugin-compatibility-layer/src/test/java/org/opendaylight/ovsdb/compatibility/plugin/impl/NodeFactoryTest.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2014 Red Hat, Inc. - * - * 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 - * - * Authors : Sam Hague - */ -package org.opendaylight.ovsdb.compatibility.plugin.impl; - -import static org.junit.Assert.assertTrue; -import org.junit.Test; - -public class NodeFactoryTest { - - @Test - public void testFromString () { - assertTrue(true); - } -} diff --git a/plugin-shell/src/main/java/org/opendaylight/ovsdb/plugin/shell/PrintCache.java b/plugin-shell/src/main/java/org/opendaylight/ovsdb/plugin/shell/PrintCache.java index 9dc951db5..420f016c4 100644 --- a/plugin-shell/src/main/java/org/opendaylight/ovsdb/plugin/shell/PrintCache.java +++ b/plugin-shell/src/main/java/org/opendaylight/ovsdb/plugin/shell/PrintCache.java @@ -12,8 +12,11 @@ package org.opendaylight.ovsdb.plugin.shell; import org.apache.felix.gogo.commands.Argument; import org.apache.felix.gogo.commands.Command; import org.apache.karaf.shell.console.OsgiCommandSupport; -import org.opendaylight.controller.sal.core.Node; import org.opendaylight.ovsdb.plugin.api.OvsdbInventoryService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; @Command(scope = "ovs", name = "printCache", description="Prints OVSDB Cache") public class PrintCache extends OsgiCommandSupport{ @@ -24,7 +27,12 @@ public class PrintCache extends OsgiCommandSupport{ @Override protected Object doExecute() throws Exception { - Node node = Node.fromString(nodeName); + NodeId nodeId = new NodeId(nodeName); + NodeKey nodeKey = new NodeKey(nodeId); + Node node = new NodeBuilder() + .setId(nodeId) + .setKey(nodeKey) + .build(); ovsdbInventory.printCache(node); return null; } diff --git a/plugin-shell/src/test/java/org/opendaylight/ovsdb/plugin/shell/PrintCacheTest.java b/plugin-shell/src/test/java/org/opendaylight/ovsdb/plugin/shell/PrintCacheTest.java index 7629a24b0..0e34a6e17 100644 --- a/plugin-shell/src/test/java/org/opendaylight/ovsdb/plugin/shell/PrintCacheTest.java +++ b/plugin-shell/src/test/java/org/opendaylight/ovsdb/plugin/shell/PrintCacheTest.java @@ -11,7 +11,6 @@ package org.opendaylight.ovsdb.plugin.shell; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.mockito.Mockito.when; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -20,10 +19,7 @@ import java.io.InputStream; import java.io.PrintStream; import java.lang.reflect.Field; import java.util.Set; -import org.junit.runner.RunWith; import org.junit.Test; -import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.controller.sal.core.NodeConnector; import org.opendaylight.ovsdb.lib.notation.Column; import org.opendaylight.ovsdb.lib.notation.Row; import org.opendaylight.ovsdb.lib.notation.UUID; @@ -33,14 +29,13 @@ import org.opendaylight.ovsdb.lib.schema.DatabaseSchema; import org.opendaylight.ovsdb.lib.schema.GenericTableSchema; import org.opendaylight.ovsdb.plugin.api.OvsVswitchdSchemaConstants; import org.opendaylight.ovsdb.plugin.impl.InventoryServiceImpl; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; -@RunWith(PowerMockRunner.class) -@PrepareForTest(Node.class) public class PrintCacheTest { - private static final String NODESTRING = "OVS:10.10.10.10:65342"; + private static final String NODESTRING = "OVS|10.10.10.10:65342"; private static final String BRIDGES = "bridges"; private static final String OVS = "OVS"; private static final String BRIDGE = "bridge1"; @@ -61,13 +56,6 @@ public class PrintCacheTest { assertNotNull(schema); assertEquals(Version.fromString("6.12.0"), schema.getVersion()); - // mock a node since PrintCache requires a Node - Node.NodeIDType.registerIDType(OVS, String.class); - NodeConnector.NodeConnectorIDType.registerIDType(OVS, String.class, OVS); - Node node = new Node(OVS, "1"); - PowerMockito.mockStatic(Node.class); - when(Node.fromString(NODESTRING)).thenReturn(node); - // Add params to PrintCache PrintCache printCacheTest = new PrintCache(); Field cNField = printCacheTest.getClass().getDeclaredField("nodeName"); @@ -91,6 +79,13 @@ public class PrintCacheTest { Column column = new Column(bridges, new UUID(BRIDGE).toString()); Row row = new Row(ovsTable); row.addColumn(BRIDGES, column); + + NodeId nodeId = new NodeId(NODESTRING); + NodeKey nodeKey = new NodeKey(nodeId); + Node node = new NodeBuilder() + .setId(nodeId) + .setKey(nodeKey) + .build(); inventoryService.updateRow(node, OvsVswitchdSchemaConstants.DATABASE_NAME, OPENVSWITCH, new UUID("1").toString(), row); // Test that a populated cache is printed correctly diff --git a/plugin/pom.xml b/plugin/pom.xml index ea28686db..1a533e3a7 100755 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -69,10 +69,18 @@ and is available at http://www.eclipse.org/legal/epl-v10.html utils.config ${ovsdb.utils.config.version} + + org.opendaylight.controller.model + model-inventory + org.slf4j slf4j-api + + org.slf4j + slf4j-simple + diff --git a/plugin/src/main/java/org/opendaylight/ovsdb/plugin/api/Connection.java b/plugin/src/main/java/org/opendaylight/ovsdb/plugin/api/Connection.java index 1dc1e8f1e..c7091a611 100644 --- a/plugin/src/main/java/org/opendaylight/ovsdb/plugin/api/Connection.java +++ b/plugin/src/main/java/org/opendaylight/ovsdb/plugin/api/Connection.java @@ -9,9 +9,12 @@ */ package org.opendaylight.ovsdb.plugin.api; -import org.opendaylight.controller.sal.core.ConstructionException; -import org.opendaylight.controller.sal.core.Node; import org.opendaylight.ovsdb.lib.OvsdbClient; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,17 +36,17 @@ public class Connection { private static final Logger logger = LoggerFactory.getLogger(Connection.class); public Connection(String identifier, OvsdbClient client) { - super(); this.identifier = identifier; this.client = client; this.idCounter = 0L; - try { - node = new Node("OVS", identifier); - } catch (ConstructionException e) { - logger.error("Error creating OVS node with identifier " + identifier, e); - } + NodeId nodeId = new NodeId("OVS" + "|" + identifier); + NodeKey nodeKey = new NodeKey(nodeId); + node = new NodeBuilder() + .setId(nodeId) + .setKey(nodeKey) + .build(); } public String getIdentifier() { diff --git a/plugin/src/main/java/org/opendaylight/ovsdb/plugin/api/OvsdbConfigurationService.java b/plugin/src/main/java/org/opendaylight/ovsdb/plugin/api/OvsdbConfigurationService.java index a22939341..ff63d5cd1 100644 --- a/plugin/src/main/java/org/opendaylight/ovsdb/plugin/api/OvsdbConfigurationService.java +++ b/plugin/src/main/java/org/opendaylight/ovsdb/plugin/api/OvsdbConfigurationService.java @@ -13,13 +13,12 @@ import java.util.List; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ExecutionException; -import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.ovsdb.plugin.api.Status; import org.opendaylight.ovsdb.lib.notation.Row; import org.opendaylight.ovsdb.lib.notation.UUID; import org.opendaylight.ovsdb.lib.schema.GenericTableSchema; import org.opendaylight.ovsdb.lib.schema.typed.TypedBaseTable; import org.opendaylight.ovsdb.plugin.error.OvsdbPluginException; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; public interface OvsdbConfigurationService { diff --git a/plugin/src/main/java/org/opendaylight/ovsdb/plugin/api/OvsdbConnectionService.java b/plugin/src/main/java/org/opendaylight/ovsdb/plugin/api/OvsdbConnectionService.java index 4270cea0e..9b2d17f7c 100644 --- a/plugin/src/main/java/org/opendaylight/ovsdb/plugin/api/OvsdbConnectionService.java +++ b/plugin/src/main/java/org/opendaylight/ovsdb/plugin/api/OvsdbConnectionService.java @@ -12,7 +12,7 @@ package org.opendaylight.ovsdb.plugin.api; import java.util.List; import java.util.Map; -import org.opendaylight.controller.sal.core.Node; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; public interface OvsdbConnectionService { public Connection getConnection(Node node); diff --git a/plugin/src/main/java/org/opendaylight/ovsdb/plugin/api/OvsdbInventoryListener.java b/plugin/src/main/java/org/opendaylight/ovsdb/plugin/api/OvsdbInventoryListener.java index cf61202d9..3461ede74 100644 --- a/plugin/src/main/java/org/opendaylight/ovsdb/plugin/api/OvsdbInventoryListener.java +++ b/plugin/src/main/java/org/opendaylight/ovsdb/plugin/api/OvsdbInventoryListener.java @@ -9,8 +9,8 @@ */ package org.opendaylight.ovsdb.plugin.api; -import org.opendaylight.controller.sal.core.Node; import org.opendaylight.ovsdb.lib.notation.Row; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import java.net.InetAddress; diff --git a/plugin/src/main/java/org/opendaylight/ovsdb/plugin/api/OvsdbInventoryService.java b/plugin/src/main/java/org/opendaylight/ovsdb/plugin/api/OvsdbInventoryService.java index 5d4d3d203..11fb68420 100644 --- a/plugin/src/main/java/org/opendaylight/ovsdb/plugin/api/OvsdbInventoryService.java +++ b/plugin/src/main/java/org/opendaylight/ovsdb/plugin/api/OvsdbInventoryService.java @@ -13,11 +13,11 @@ import java.net.InetAddress; import java.util.Set; import java.util.concurrent.ConcurrentMap; -import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.core.Property; import org.opendaylight.controller.sal.core.UpdateType; import org.opendaylight.ovsdb.lib.message.TableUpdates; import org.opendaylight.ovsdb.lib.notation.Row; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; public interface OvsdbInventoryService { public ConcurrentMap> getCache(Node n, String databaseName); diff --git a/plugin/src/main/java/org/opendaylight/ovsdb/plugin/impl/ConfigurationServiceImpl.java b/plugin/src/main/java/org/opendaylight/ovsdb/plugin/impl/ConfigurationServiceImpl.java index 276d013d6..9bb2ab250 100644 --- a/plugin/src/main/java/org/opendaylight/ovsdb/plugin/impl/ConfigurationServiceImpl.java +++ b/plugin/src/main/java/org/opendaylight/ovsdb/plugin/impl/ConfigurationServiceImpl.java @@ -22,7 +22,6 @@ import java.util.Set; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ExecutionException; -import org.opendaylight.controller.sal.core.Node; import org.opendaylight.ovsdb.plugin.api.Status; import org.opendaylight.ovsdb.plugin.api.StatusCode; import org.opendaylight.ovsdb.lib.OvsdbClient; @@ -55,6 +54,7 @@ import org.opendaylight.ovsdb.schema.openvswitch.Controller; import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch; import org.opendaylight.ovsdb.schema.openvswitch.Port; import org.opendaylight.ovsdb.utils.config.ConfigProperties; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/plugin/src/main/java/org/opendaylight/ovsdb/plugin/impl/ConnectionServiceImpl.java b/plugin/src/main/java/org/opendaylight/ovsdb/plugin/impl/ConnectionServiceImpl.java index deddb2b96..a2d840376 100644 --- a/plugin/src/main/java/org/opendaylight/ovsdb/plugin/impl/ConnectionServiceImpl.java +++ b/plugin/src/main/java/org/opendaylight/ovsdb/plugin/impl/ConnectionServiceImpl.java @@ -23,7 +23,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ExecutionException; -import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.core.Property; import org.opendaylight.ovsdb.lib.MonitorCallBack; import org.opendaylight.ovsdb.lib.OvsdbClient; @@ -46,6 +45,7 @@ import org.opendaylight.ovsdb.plugin.internal.L4PortProperty; import org.opendaylight.ovsdb.plugin.api.OvsdbConnectionService; import org.opendaylight.ovsdb.plugin.api.OvsdbInventoryService; import org.opendaylight.ovsdb.utils.config.ConfigProperties; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -130,10 +130,9 @@ public class ConnectionServiceImpl implements OvsdbConnectionService, } public Status disconnect(Node node) { - String identifier = (String) node.getID(); - Connection connection = ovsdbConnections.get(identifier); + Connection connection = getConnection(node); if (connection != null) { - ovsdbConnections.remove(identifier); + ovsdbConnections.remove(normalizeId(node.getId().getValue())); connection.disconnect(); ovsdbInventoryService.removeNode(node); return new Status(StatusCode.SUCCESS); @@ -179,14 +178,7 @@ public class ConnectionServiceImpl implements OvsdbConnectionService, this.handlers = handlers; } - @Override - public Connection getConnection(Node node) { - String identifier = (String) node.getID(); - return ovsdbConnections.get(identifier); - } - - @Override - public Node getNode (String identifier) { + private String normalizeId (String identifier) { String id = identifier; String[] pair = identifier.split("\\|"); @@ -194,7 +186,17 @@ public class ConnectionServiceImpl implements OvsdbConnectionService, id = pair[1]; } - Connection connection = ovsdbConnections.get(id); + return id; + } + + @Override + public Connection getConnection(Node node) { + return ovsdbConnections.get(normalizeId(node.getId().getValue())); + } + + @Override + public Node getNode (String identifier) { + Connection connection = ovsdbConnections.get(normalizeId(identifier)); if (connection != null) { return connection.getNode(); } else { @@ -276,8 +278,7 @@ public class ConnectionServiceImpl implements OvsdbConnectionService, } public TableUpdates monitorTables(Node node, DatabaseSchema dbSchema) throws ExecutionException, InterruptedException, IOException { - String identifier = (String) node.getID(); - Connection connection = ovsdbConnections.get(identifier); + Connection connection = getConnection(node); OvsdbClient client = connection.getClient(); if (dbSchema == null) { logger.error("Unable to get Database Schema for the ovsdb connection : {}", client.getConnectionInfo()); diff --git a/plugin/src/main/java/org/opendaylight/ovsdb/plugin/impl/InventoryServiceImpl.java b/plugin/src/main/java/org/opendaylight/ovsdb/plugin/impl/InventoryServiceImpl.java index 3693e167d..b5f6d2ea8 100644 --- a/plugin/src/main/java/org/opendaylight/ovsdb/plugin/impl/InventoryServiceImpl.java +++ b/plugin/src/main/java/org/opendaylight/ovsdb/plugin/impl/InventoryServiceImpl.java @@ -19,8 +19,6 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; -import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.controller.sal.core.NodeConnector; import org.opendaylight.controller.sal.core.Property; import org.opendaylight.controller.sal.core.UpdateType; import org.opendaylight.ovsdb.lib.message.TableUpdate; @@ -32,6 +30,7 @@ import org.opendaylight.ovsdb.plugin.api.OvsVswitchdSchemaConstants; import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService; import org.opendaylight.ovsdb.plugin.api.OvsdbInventoryListener; import org.opendaylight.ovsdb.plugin.api.OvsdbInventoryService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import com.google.common.collect.Sets; import org.slf4j.Logger; diff --git a/plugin/src/main/java/org/opendaylight/ovsdb/plugin/internal/Activator.java b/plugin/src/main/java/org/opendaylight/ovsdb/plugin/internal/Activator.java index fd208b143..4f0212852 100644 --- a/plugin/src/main/java/org/opendaylight/ovsdb/plugin/internal/Activator.java +++ b/plugin/src/main/java/org/opendaylight/ovsdb/plugin/internal/Activator.java @@ -11,8 +11,6 @@ package org.opendaylight.ovsdb.plugin.internal; import org.apache.felix.dm.DependencyActivatorBase; import org.apache.felix.dm.DependencyManager; -import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.controller.sal.core.NodeConnector; import org.opendaylight.ovsdb.lib.OvsdbConnection; import org.opendaylight.ovsdb.lib.OvsdbConnectionListener; import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService; @@ -38,9 +36,6 @@ public class Activator extends DependencyActivatorBase { @Override public void init(BundleContext context, DependencyManager manager) throws Exception { - Node.NodeIDType.registerIDType("OVS", String.class); - NodeConnector.NodeConnectorIDType.registerIDType("OVS", String.class, "OVS"); - manager.add(createComponent() .setInterface(OvsdbConfigurationService.class.getName(), null) .setImplementation(ConfigurationServiceImpl.class) @@ -77,7 +72,5 @@ public class Activator extends DependencyActivatorBase { @Override public void destroy(BundleContext context, DependencyManager manager) throws Exception { - Node.NodeIDType.unRegisterIDType("OVS"); - NodeConnector.NodeConnectorIDType.unRegisterIDType("OVS"); } } diff --git a/plugin/src/test/java/org/opendaylight/ovsdb/plugin/impl/ConnectionServiceImplTest.java b/plugin/src/test/java/org/opendaylight/ovsdb/plugin/impl/ConnectionServiceImplTest.java index 815a06824..ed46c3ffd 100644 --- a/plugin/src/test/java/org/opendaylight/ovsdb/plugin/impl/ConnectionServiceImplTest.java +++ b/plugin/src/test/java/org/opendaylight/ovsdb/plugin/impl/ConnectionServiceImplTest.java @@ -11,10 +11,12 @@ package org.opendaylight.ovsdb.plugin.impl; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.fail; +import org.junit.BeforeClass; import org.junit.Test; -import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.controller.sal.core.NodeConnector; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.opendaylight.ovsdb.plugin.api.Connection; public class ConnectionServiceImplTest { @@ -22,15 +24,17 @@ public class ConnectionServiceImplTest { private static final String IDENTIFIER = "192.168.120.31:45001"; private static final String OVS_IDENTIFIER = OVS + "|" + IDENTIFIER; private static final String BAD_IDENTIFIER = "BAD" + "|" + IDENTIFIER; + private static ConnectionServiceImpl connectionService; - @Test - public void testGetNode () { - Node.NodeIDType.registerIDType(OVS, String.class); - NodeConnector.NodeConnectorIDType.registerIDType(OVS, String.class, OVS); - ConnectionServiceImpl connectionService = new ConnectionServiceImpl(); + @BeforeClass + public static void setUp () { + connectionService = new ConnectionServiceImpl(); Connection connection = new Connection(IDENTIFIER, null); connectionService.putOvsdbConnection(IDENTIFIER, connection); + } + @Test + public void testGetNode () { Node node = connectionService.getNode(IDENTIFIER); assertNotNull("Node " + IDENTIFIER + " is null", node); @@ -40,4 +44,20 @@ public class ConnectionServiceImplTest { node = connectionService.getNode(IDENTIFIER + "extra"); assertNull("Node " + BAD_IDENTIFIER + " is not null", node); } + + @Test + public void testGetConnection () { + Node node = connectionService.getNode(IDENTIFIER); + assertNotNull("Node " + IDENTIFIER + " is null", node); + + Connection connection = connectionService.getConnection(node); + assertNotNull("Connection " + IDENTIFIER + " is null", connection); + + try { + connection = connectionService.getConnection(null); + fail("Expected a NullPointerException to be thrown"); + } catch (NullPointerException e) { + assertSame(NullPointerException.class, e.getClass()); + } + } } diff --git a/plugin/src/test/java/org/opendaylight/ovsdb/plugin/impl/NodeFactoryTest.java b/plugin/src/test/java/org/opendaylight/ovsdb/plugin/impl/NodeFactoryTest.java deleted file mode 100644 index 10761d503..000000000 --- a/plugin/src/test/java/org/opendaylight/ovsdb/plugin/impl/NodeFactoryTest.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2014 Red Hat, Inc. - * - * 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 - * - * Authors : Sam Hague - */ -package org.opendaylight.ovsdb.plugin.impl; - -import static org.junit.Assert.assertTrue; -import org.junit.Test; - -public class NodeFactoryTest { - - @Test - public void testFromString () { - assertTrue(true); - } -} diff --git a/pom.xml b/pom.xml index 7df618cd6..9b4ee9cf1 100644 --- a/pom.xml +++ b/pom.xml @@ -42,7 +42,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html plugin ovsdb-plugin-compatibility-layer plugin-shell - plugin-mdsal-adapter schemas/hardwarevtep schemas/openvswitch southbound -- 2.36.6