Removing Plugin dependancies from the Library in lieu of bundle isolation. 60/2260/1
authorMadhu Venugopal <mavenugo@gmail.com>
Tue, 29 Oct 2013 18:22:32 +0000 (11:22 -0700)
committerMadhu Venugopal <mavenugo@gmail.com>
Tue, 29 Oct 2013 18:28:43 +0000 (11:28 -0700)
Signed-off-by: Madhu Venugopal <mavenugo@gmail.com>
ovsdb/src/main/java/org/opendaylight/ovsdb/lib/jsonrpc/JsonRpcEndpoint.java
ovsdb/src/main/java/org/opendaylight/ovsdb/lib/message/OVSDB.java
ovsdb/src/main/java/org/opendaylight/ovsdb/plugin/ConnectionService.java
ovsdb/src/test/java/org/opendaylight/ovsdb/lib/message/OVSDBNettyFactoryTest.java

index d29afd111ad78e55c1b7bd214db961859dd935a2..2b9bab06c1a14dfab261947457e04dbf7a3e8562 100644 (file)
@@ -4,7 +4,6 @@ import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.JavaType;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.fasterxml.jackson.databind.type.TypeFactory;
 import com.google.common.collect.Maps;
 import com.google.common.reflect.Reflection;
@@ -14,20 +13,15 @@ import com.google.common.util.concurrent.SettableFuture;
 
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.ovsdb.lib.message.OVSDB;
-import org.opendaylight.ovsdb.lib.message.Response;
-import org.opendaylight.ovsdb.plugin.Connection;
-import org.opendaylight.ovsdb.plugin.ConnectionService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
+import io.netty.channel.Channel;
 
 public class JsonRpcEndpoint {
 
@@ -58,13 +52,13 @@ public class JsonRpcEndpoint {
     }
 
     ObjectMapper objectMapper;
-    ConnectionService service;
+    Channel nettyChannel;
     Map<String, CallContext> methodContext = Maps.newHashMap();
     Map<Node, OVSDB.Callback> requestCallbacks = Maps.newHashMap();
 
-    public JsonRpcEndpoint(ObjectMapper objectMapper, ConnectionService service) {
+    public JsonRpcEndpoint(ObjectMapper objectMapper, Channel channel) {
         this.objectMapper = objectMapper;
-        this.service = service;
+        this.nettyChannel = channel;
     }
 
     public <T> T getClient(final Node node, Class<T> klazz) {
@@ -104,8 +98,7 @@ public class JsonRpcEndpoint {
                 SettableFuture<Object> sf = SettableFuture.create();
                 methodContext.put(request.getId(), new CallContext(request, method, sf));
 
-                Connection connection = service.getConnection(node);
-                connection.getChannel().writeAndFlush(s);
+                nettyChannel.writeAndFlush(s);
 
                 return sf;
             }
@@ -113,7 +106,6 @@ public class JsonRpcEndpoint {
         );
     }
 
-    @SuppressWarnings("deprecation")
     public void processResult(JsonNode response) throws NoSuchMethodException {
 
         CallContext returnCtxt = methodContext.get(response.get("id").asText());
@@ -170,8 +162,7 @@ public class JsonRpcEndpoint {
             response.setError(null);
             try {
                 String s = objectMapper.writeValueAsString(response);
-                Connection connection = service.getConnection(node);
-                connection.getChannel().writeAndFlush(s);
+                nettyChannel.writeAndFlush(s);
             } catch (JsonProcessingException e) {
                 e.printStackTrace();
             }
index 4c0ce4cb4dcc4b44cd21b738e3b9684e3e7f6cc7..cf5d582fccd0ae96d85885d5b8f4c6e1192b3f39 100644 (file)
@@ -35,7 +35,9 @@ public interface OVSDB {
 
     public static interface Callback {
         public void update(Node node, UpdateNotification upadateNotification);
-        public void locked(Node node, Object json_value);
-        // public void echo(Node node, Object json_value);
+        public void locked(Node node, List<String> ids);
+        public void stolen(Node node, List<String> ids);
+        // ECHO is handled by JsonRPCEndpoint directly.
+        // We can add Echo request here if there is a need for clients to handle it.
     }
 }
index e94e8988b96043e222bc64ed7f5b316b88aea9c0..623d899ea340935e76f156710b609a3235ce5721 100755 (executable)
@@ -55,15 +55,6 @@ public class ConnectionService implements IPluginInConnectionService, IConnectio
 
     public void init() {
         ovsdbConnections = new ConcurrentHashMap<String, Connection>();
-
-        //backward compatability with other tests and stuff
-        if (handlers == null) {
-            List<ChannelHandler> _handlers = Lists.newArrayList();
-            _handlers.add(new LoggingHandler(LogLevel.INFO));
-            _handlers.add(new JsonRpcDecoder(100000));
-            _handlers.add(new StringEncoder(CharsetUtil.UTF_8));
-            _handlers.add(new MessageHandler());
-        }
     }
 
     /**
index e4fadd2fbc63bd15c2c6d7b9b41b71ce9ccb2cd7..8ba757ed753b6ce41c478114950188a7b75e55c8 100644 (file)
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import com.google.common.collect.Lists;
 import com.google.common.util.concurrent.ListenableFuture;
 
+import io.netty.channel.Channel;
 import io.netty.channel.ChannelHandler;
 import io.netty.handler.codec.string.StringEncoder;
 import io.netty.handler.logging.LogLevel;
@@ -50,33 +51,36 @@ import java.util.concurrent.ExecutionException;
 public class OVSDBNettyFactoryTest implements OVSDB.Callback {
     InventoryServiceInternal inventoryService;
     private static String bridgeIdentifier = "br1";
+
     @Test
     public void testSome() throws InterruptedException, ExecutionException {
-        ConnectionService service = new ConnectionService();
-        inventoryService = new InventoryService();
-        ObjectMapper objectMapper = new ObjectMapper();
-        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-        JsonRpcEndpoint factory = new JsonRpcEndpoint(objectMapper, service);
-        JsonRpcServiceBinderHandler binderHandler = new JsonRpcServiceBinderHandler(factory);
-
+        ConnectionService connectionService = new ConnectionService();
+        connectionService.init();
         List<ChannelHandler> _handlers = Lists.newArrayList();
         _handlers.add(new LoggingHandler(LogLevel.INFO));
         _handlers.add(new JsonRpcDecoder(100000));
         _handlers.add(new StringEncoder(CharsetUtil.UTF_8));
-        _handlers.add(binderHandler);
+        connectionService.setHandlers(_handlers);
 
-        service.init();
-        service.setHandlers(_handlers);
-        String identifier = "TEST";
+        inventoryService = new InventoryService();
         Node.NodeIDType.registerIDType("OVS", String.class);
         Map<ConnectionConstants, String> params = new HashMap<ConnectionConstants, String>();
         params.put(ConnectionConstants.ADDRESS, "192.168.56.101");
         params.put(ConnectionConstants.PORT, "6634");
-        Node node = service.connect(identifier, params);
-        if (node != null) {
-            binderHandler.setNode(node);
+        Node node = connectionService.connect("TEST", params);
+        if (node == null) {
+            System.out.println("ERROR : Unable to connect to the host");
+            return;
         }
 
+        ObjectMapper objectMapper = new ObjectMapper();
+        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+        Channel channel = connectionService.getConnection(node).getChannel();
+        JsonRpcEndpoint factory = new JsonRpcEndpoint(objectMapper, channel);
+        JsonRpcServiceBinderHandler binderHandler = new JsonRpcServiceBinderHandler(factory);
+        binderHandler.setNode(node);
+        channel.pipeline().addLast(binderHandler);
+
         OVSDB ovsdb = factory.getClient(node, OVSDB.class);
         ovsdb.registerCallback(this);
 
@@ -161,6 +165,7 @@ public class OVSDBNettyFactoryTest implements OVSDB.Callback {
         System.out.println("Request + Response : "+requests.toString());
         if (tr.size() > requests.size()) {
             System.out.println("ERROR : "+tr.get(tr.size()-1).getError());
+            System.out.println("Details : "+tr.get(tr.size()-1).getDetails());
         }
 
         // TEST ECHO
@@ -170,8 +175,9 @@ public class OVSDBNettyFactoryTest implements OVSDB.Callback {
         System.out.printf("Result of echo is %s \n", s);
 
         // TEST ECHO REQUEST/REPLY
+        Thread.sleep(10000);
 
-        service.disconnect(node);
+        connectionService.disconnect(node);
     }
 
     @Override
@@ -181,7 +187,12 @@ public class OVSDBNettyFactoryTest implements OVSDB.Callback {
     }
 
     @Override
-    public void locked(Node node, Object json_value) {
+    public void locked(Node node, List<String> ids) {
+        // TODO Auto-generated method stub
     }
 
+    @Override
+    public void stolen(Node node, List<String> ids) {
+        // TODO Auto-generated method stub
+    }
 }