Workaround for Node.fromString 19/15519/1
authorSam Hague <shague@redhat.com>
Fri, 20 Feb 2015 01:43:11 +0000 (20:43 -0500)
committerSam Hague <shague@redhat.com>
Fri, 20 Feb 2015 01:43:11 +0000 (20:43 -0500)
Added getnode(id) API to plugin ConnectionService interface to get the node requested by the id.

Also found some cases in the northbound that were using the fromString so replaced them with getNode.

Change-Id: I47dd6bb6cb432d6309744dd0206412a8a6037281
Signed-off-by: Sam Hague <shague@redhat.com>
integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/plugin/OvsdbPluginIT.java
integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/plugin/OvsdbPluginV3IT.java
northbound/src/main/java/org/opendaylight/ovsdb/northbound/OvsdbNorthboundV2.java
plugin-shell/src/main/java/org/opendaylight/ovsdb/plugin/shell/PrintCache.java
plugin-shell/src/test/java/org/opendaylight/ovsdb/plugin/shell/PrintCacheTest.java
plugin/src/main/java/org/opendaylight/ovsdb/plugin/api/OvsdbConnectionService.java
plugin/src/main/java/org/opendaylight/ovsdb/plugin/impl/ConnectionServiceImpl.java

index c5f9063a7f0b52fe58d31507c18e1ae948393fdd..b44d6fe3c342bf8602b22e694b6fe47d38bcb255 100644 (file)
@@ -141,8 +141,7 @@ public class OvsdbPluginIT extends OvsdbIntegrationTestBase {
         if (connectionInfo.getType().equals(OvsdbConnectionInfo.ConnectionType.PASSIVE)) {
             identifier = connectionInfo.getRemoteAddress().getHostAddress()+":"+connectionInfo.getRemotePort();
         }
-        /* TODO Node.fromString lookup fails because the "OVS|id" is no longer written to the node.*/
-        //assertEquals(Node.fromString("OVS|" + identifier), connectionService.getNodes().get(0));
+        assertEquals(node, connectionService.getNode("OVS|" + identifier));
         System.out.println("Nodes = "+ connectionService.getNodes());
         /*
          * Test sequence :
@@ -179,7 +178,7 @@ public class OvsdbPluginIT extends OvsdbIntegrationTestBase {
         componentB.setImplementation(listenerB);
         dm.add(componentB);
 
-        Node newNode = Node.fromString("OVS:10.10.10.10:65342");
+        Node newNode = Node.fromString("OVS|10.10.10.10:65342");
         InetAddress address = InetAddress.getByName("10.10.10.10");
         int port = 65342;
 
index 679711db5e4fb6ac86c26b4183b83909442fc57f..cb05e3948b4f7cc4c73fd3b15685d6aad41679b9 100644 (file)
@@ -137,8 +137,7 @@ public class OvsdbPluginV3IT extends OvsdbIntegrationTestBase {
         if (connectionInfo.getType().equals(OvsdbConnectionInfo.ConnectionType.PASSIVE)) {
             identifier = connectionInfo.getRemoteAddress().getHostAddress()+":"+connectionInfo.getRemotePort();
         }
-        /* TODO Node.fromString lookup fails because the "OVS|id" is no longer written to the node.*/
-        //assertEquals(Node.fromString("OVS|" + identifier), connectionService.getNodes().get(0));
+        assertEquals(node, connectionService.getNode("OVS|" + identifier));
         log.info("Nodes = "+ connectionService.getNodes());
         /*
          * Test sequence :
@@ -169,7 +168,7 @@ public class OvsdbPluginV3IT extends OvsdbIntegrationTestBase {
         componentB.setImplementation(listenerB);
         dm.add(componentB);
 
-        Node newNode = Node.fromString("OVS:10.10.10.10:65342");
+        Node newNode = Node.fromString("OVS|10.10.10.10:65342");
         InetAddress address = InetAddress.getByName("10.10.10.10");
         int port = 65342;
 
index fd023f0470da3eede7902ecccdf3437104661096..771484d0ade9349ef97182d75797745d7b25e8d5 100644 (file)
@@ -332,9 +332,10 @@ public class OvsdbNorthboundV2 {
             throw new ServiceUnavailableException("OVS Configuration Service " + RestMessages.SERVICEUNAVAILABLE.toString());
         }
 
-        Node node = Node.fromString(nodeType, nodeId);
         OvsdbConnectionService
                 connectionService = (OvsdbConnectionService)ServiceHelper.getGlobalInstance(OvsdbConnectionService.class, this);
+        Node node = connectionService.getNode(nodeId);
+
         OvsdbClient client = connectionService.getConnection(node).getClient();
         OvsdbRow localRow = OvsdbRow.fromJsonNode(client, OvsVswitchdSchemaConstants.DATABASE_NAME, rowJson);
         String bckCompatibleTableName = this.getBackwardCompatibleTableName(client, OvsVswitchdSchemaConstants.DATABASE_NAME, tableName);
@@ -424,9 +425,9 @@ public class OvsdbNorthboundV2 {
             throw new ServiceUnavailableException("UserManager " + RestMessages.SERVICEUNAVAILABLE.toString());
         }
 
-        Node node = Node.fromString(nodeType, nodeId);
         OvsdbConnectionService
                 connectionService = (OvsdbConnectionService)ServiceHelper.getGlobalInstance(OvsdbConnectionService.class, this);
+        Node node = connectionService.getNode(nodeId);
         OvsdbClient client = connectionService.getConnection(node).getClient();
         String bckCompatibleTableName = this.getBackwardCompatibleTableName(client, OvsVswitchdSchemaConstants.DATABASE_NAME, tableName);
 
@@ -507,9 +508,9 @@ public class OvsdbNorthboundV2 {
             throw new ServiceUnavailableException("UserManager " + RestMessages.SERVICEUNAVAILABLE.toString());
         }
 
-        Node node = Node.fromString(nodeType, nodeId);
         OvsdbConnectionService
                 connectionService = (OvsdbConnectionService)ServiceHelper.getGlobalInstance(OvsdbConnectionService.class, this);
+        Node node = connectionService.getNode(nodeId);
         OvsdbClient client = connectionService.getConnection(node).getClient();
         String bckCompatibleTableName = this.getBackwardCompatibleTableName(client, OvsVswitchdSchemaConstants.DATABASE_NAME, tableName);
         Map<String, Row> rows = null;
@@ -582,9 +583,9 @@ public class OvsdbNorthboundV2 {
             throw new ServiceUnavailableException("OVS Configuration Service " + RestMessages.SERVICEUNAVAILABLE.toString());
         }
 
-        Node node = Node.fromString(nodeType, nodeId);
         OvsdbConnectionService
                 connectionService = (OvsdbConnectionService)ServiceHelper.getGlobalInstance(OvsdbConnectionService.class, this);
+        Node node = connectionService.getNode(nodeId);
         OvsdbClient client = connectionService.getConnection(node).getClient();
         String bckCompatibleTableName = this.getBackwardCompatibleTableName(client, OvsVswitchdSchemaConstants.DATABASE_NAME, tableName);
         OvsdbRow localRow = OvsdbRow.fromJsonNode(client, OvsVswitchdSchemaConstants.DATABASE_NAME, rowJson);
@@ -663,9 +664,9 @@ public class OvsdbNorthboundV2 {
             throw new ServiceUnavailableException("OVS Configuration Service " + RestMessages.SERVICEUNAVAILABLE.toString());
         }
 
-        Node node = Node.fromString(nodeType, nodeId);
         OvsdbConnectionService
                 connectionService = (OvsdbConnectionService)ServiceHelper.getGlobalInstance(OvsdbConnectionService.class, this);
+        Node node = connectionService.getNode(nodeId);
         OvsdbClient client = connectionService.getConnection(node).getClient();
         String bckCompatibleTableName = this.getBackwardCompatibleTableName(client, OvsVswitchdSchemaConstants.DATABASE_NAME, tableName);
 
index 9b4cfa34215ea2ddd241382bfbf57b8670497b70..9dc951db5fc0eac913ce9c041ff449eed4e2530f 100644 (file)
@@ -24,7 +24,6 @@ public class PrintCache extends OsgiCommandSupport{
 
     @Override
     protected Object doExecute() throws Exception {
-        /* TODO Node.fromString lookup fails because the "OVS|id" is no longer written to the node.*/
         Node node = Node.fromString(nodeName);
         ovsdbInventory.printCache(node);
         return null;
index e28c86f8ed7ea0f94281b2eef9bb0ed3c4e002bb..7629a24b052effebddbab31af855bd2ef2240519 100644 (file)
@@ -62,7 +62,6 @@ public class PrintCacheTest {
         assertEquals(Version.fromString("6.12.0"), schema.getVersion());
 
         // mock a node since PrintCache requires a Node
-        /* TODO Node.fromString lookup fails because the "OVS|id" is no longer written to the node.*/
         Node.NodeIDType.registerIDType(OVS, String.class);
         NodeConnector.NodeConnectorIDType.registerIDType(OVS, String.class, OVS);
         Node node = new Node(OVS, "1");
index d86c0dad146b4d49551a241cf1b2eef3aac23122..5c967b063fbba10359ba8b070143094e1668df89 100644 (file)
@@ -17,5 +17,6 @@ import org.opendaylight.controller.sal.core.Node;
 public interface OvsdbConnectionService {
     public Connection getConnection(Node node);
     public List<Node> getNodes();
+    public Node getNode (String identifier);
     public Node connect(String identifier, Map<ConnectionConstants, String> params);
 }
index 1ed88d732068567e591b9692e9aa767e331a6f01..a7625941151144b09b0b562533bc50c0b01a88ea 100644 (file)
@@ -181,6 +181,23 @@ public class ConnectionServiceImpl implements OvsdbConnectionService,
         return ovsdbConnections.get(identifier);
     }
 
+    @Override
+    public Node getNode (String identifier) {
+        String id = identifier;
+
+        String[] pair = identifier.split("[|,:]+");
+        if (pair[0].equals("OVS")) {
+            id = pair[1];
+        }
+
+        Connection connection = ovsdbConnections.get(id);
+        if (connection != null) {
+            return connection.getNode();
+        } else {
+            return null;
+        }
+    }
+
     @Override
     public List<Node> getNodes() {
         List<Node> nodes = new ArrayList<Node>();