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;
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;
);
}
+ @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());
// 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();
+ }
}
}
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
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;
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;
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="
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();