Fixed Transact response handling and updated the operation response for each request 30/2230/1
authorMadhu Venugopal <mavenugo@gmail.com>
Mon, 28 Oct 2013 22:02:43 +0000 (15:02 -0700)
committerMadhu Venugopal <mavenugo@gmail.com>
Mon, 28 Oct 2013 22:02:43 +0000 (15:02 -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/operations/OperationResult.java
ovsdb/src/test/java/org/opendaylight/ovsdb/lib/message/OVSDBNettyFactoryTest.java

index 684a0a1176088e0d673ec5d22844d7de74d5b3aa..306bb342560bf2959b94cd0faf8c2bc7d69417e0 100644 (file)
@@ -1,9 +1,11 @@
 package org.opendaylight.ovsdb.lib.jsonrpc;
 
 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;
 import com.google.common.reflect.TypeToken;
@@ -19,6 +21,7 @@ import org.slf4j.LoggerFactory;
 
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
+import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -103,20 +106,22 @@ public class JsonRpcEndpoint {
         );
     }
 
+    @SuppressWarnings("deprecation")
     public void processResult(JsonNode response) throws NoSuchMethodException {
 
         CallContext returnCtxt = methodContext.get(response.get("id").asText());
         if (returnCtxt == null) return;
 
-        Class<?> returnType = null;
         if (ListenableFuture.class == returnCtxt.getMethod().getReturnType()) {
             TypeToken<?> retType = TypeToken.of(
                     returnCtxt.getMethod().getGenericReturnType())
                     .resolveType(ListenableFuture.class.getMethod("get").getGenericReturnType());
+            JavaType javaType =  TypeFactory.defaultInstance().constructType (retType.getType());
 
             JsonNode result = response.get("result");
             logger.debug("Response : {}", result.toString());
-            Object result1 = objectMapper.convertValue(result, retType.getRawType());
+
+            Object result1 = objectMapper.convertValue(result, javaType);
             JsonNode error = response.get("error");
             if (error != null) {
                 logger.debug("Error : {}", error.toString());
@@ -136,14 +141,16 @@ public class JsonRpcEndpoint {
         // TODO : Take care of listener interested in the async message from ovsdb-server
         // and return a result to be sent back.
         // The following piece of code will help with ECHO handling as is.
-        JsonRpc10Response response = new JsonRpc10Response(request.getId());
-        response.setError(null);
-        try {
-            String s = objectMapper.writeValueAsString(response);
-            Connection connection = service.getConnection(node);
-            connection.getChannel().writeAndFlush(s);
-        } catch (JsonProcessingException e) {
-            e.printStackTrace();
+        if (request.getMethod().equals("echo")) {
+            JsonRpc10Response response = new JsonRpc10Response(request.getId());
+            response.setError(null);
+            try {
+                String s = objectMapper.writeValueAsString(response);
+                Connection connection = service.getConnection(node);
+                connection.getChannel().writeAndFlush(s);
+            } catch (JsonProcessingException e) {
+                e.printStackTrace();
+            }
         }
     }
 
index 71161768febf9fe0fa067ec70d99c9c2e99c28dd..0200c98d769aeca8a066bc591f62adff163f4669 100644 (file)
@@ -1,8 +1,13 @@
 package org.opendaylight.ovsdb.lib.message.operations;
 
 import java.util.ArrayList;
+import java.util.List;
+
 import org.opendaylight.ovsdb.lib.notation.UUID;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
 // Section 5.2 of ovsdb draft covers the various response structures for
 // each of the Operations covered by Transaction (Insert, Update, Delete, Mutate, etc...)
 // It is better to have the OperationResult as an abstract parent class with individual
@@ -14,9 +19,11 @@ import org.opendaylight.ovsdb.lib.notation.UUID;
 public class OperationResult {
     //public abstract boolean isSuccess();
     private int count;
+    @JsonIgnore
     private UUID uuid;
     private ArrayList<Object> rows;
     private String error;
+    private String details;
 
     public int getCount() {
         return count;
@@ -24,11 +31,12 @@ public class OperationResult {
     public void setCount(int count) {
         this.count = count;
     }
+    @JsonProperty("uuid")
     public UUID getUuid() {
         return uuid;
     }
-    public void setUuid(UUID uuid) {
-        this.uuid = uuid;
+    public void setUuid(List<String> uuidList) {
+        this.uuid = new UUID(uuidList.get(1));
     }
     public ArrayList<Object> getRows() {
         return rows;
@@ -42,6 +50,13 @@ public class OperationResult {
     public void setError(String error) {
         this.error = error;
     }
+    public String getDetails() {
+        return details;
+    }
+    public void setDetails(String details) {
+        this.details = details;
+    }
+
     @Override
     public String toString() {
         return "OperationResult [count=" + count + ", uuid=" + uuid + ", rows="
index 4a83e101461b29ed9e65f57073d153ac814e6bc1..4615e0d98518f4ca032320c5634cd7997346ebce 100644 (file)
@@ -150,6 +150,17 @@ public class OVSDBNettyFactoryTest {
         ListenableFuture<List<OperationResult>> transResponse = ovsdb.transact(transaction);
         System.out.println("Transcation sent :");
         List<OperationResult> tr = transResponse.get();
+        System.out.println("Transaction response : "+transResponse.toString());
+        List<Operation> requests = transaction.getRequests();
+        for (int i = 0; i < tr.size() ; i++) {
+            if (i < requests.size()) requests.get(i).setResult(tr.get(i));
+        }
+
+        System.out.println("Request + Response : "+requests.toString());
+        if (tr.size() > requests.size()) {
+            System.out.println("ERROR : "+tr.get(tr.size()-1).getError());
+        }
+
         // TEST ECHO
 
         ListenableFuture<List<String>> some = ovsdb.echo();