and will be handled in a different commit.
Signed-off-by: Madhu Venugopal <mavenugo@gmail.com>
import com.google.common.util.concurrent.SettableFuture;
import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.ovsdb.lib.message.Response;
import org.opendaylight.ovsdb.plugin.Connection;
import org.opendaylight.ovsdb.plugin.ConnectionService;
import org.slf4j.Logger;
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());
JsonNode result = response.get("result");
+ logger.debug("Response : {}", result.toString());
Object result1 = objectMapper.convertValue(result, retType.getRawType());
+ JsonNode error = response.get("error");
+ if (error != null) {
+ logger.debug("Error : {}", error.toString());
+ }
+
returnCtxt.getFuture().set(result1);
} else {
package org.opendaylight.ovsdb.lib.message;
-
-public class EchoResponse {
+public class EchoResponse extends Response {
}
import com.google.common.util.concurrent.ListenableFuture;
+import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.ovsdb.lib.database.DatabaseSchema;
-
+import org.opendaylight.ovsdb.lib.message.operations.OperationResult;
public interface OVSDB {
public ListenableFuture<List<String>> list_dbs();
- public ListenableFuture<List<Object>> transact(TransactBuilder transact);
- /*
+ public ListenableFuture<List<OperationResult>> transact(TransactBuilder transact);
+
+ public ListenableFuture<Response> cancel(String id);
+
+ public ListenableFuture<Object> monitor_cancel(Object json_value);
+
+ public ListenableFuture<Object> lock(List<String> id);
+
+ public ListenableFuture<Object> steal(List<String> id);
+
+ public ListenableFuture<Object> unlock(List<String> id);
+/*
public void registerListener(Callback callback);
public static interface Callback {
- public void monitorResponse(TableUpdates upadate);
+ public void update(Node node, TableUpdates upadate);
+ public void locked(Node node, Object json_value);
+ public void echo(Node node, Object json_value);
}
- */
+*/
}
--- /dev/null
+package org.opendaylight.ovsdb.lib.message;
+
+public abstract class Response {
+ Object error;
+
+ public Object getError() {
+ return error;
+ }
+
+ public void setError(Object error) {
+ this.error = error;
+ }
+}
import org.opendaylight.ovsdb.lib.table.internal.Table;
-public class TableUpdates {
+public class TableUpdates extends Response {
Map<Table.Name, TableUpdate> map = Maps.newHashMap();
List<Operation> requests = Lists.newArrayList();
+ public List<Operation> getRequests() {
+ return requests;
+ }
+
@Override
public List<Object> params() {
List<Object> lists = Lists.newArrayList((Object)"Open_vSwitch");
--- /dev/null
+package org.opendaylight.ovsdb.lib.message;
+
+import java.util.ArrayList;
+
+import org.opendaylight.ovsdb.lib.message.operations.OperationResult;
+
+public class TransactResponse extends Response {
+ ArrayList<OperationResult> result;
+
+ public ArrayList<OperationResult> getResult() {
+ return result;
+ }
+
+ public void setResult(ArrayList<OperationResult> result) {
+ this.result = result;
+ }
+
+ @Override
+ public String toString() {
+ return "TransactResponse [result=" + result + "]";
+ }
+}
public void setWhere(List<Condition> where) {
this.where = where;
}
+ @Override
+ public String toString() {
+ return "DeleteOperation [table=" + table + ", where=" + where
+ + ", toString()=" + super.toString() + "]";
+ }
}
public void setRow(Map<String, Object> row) {
this.row = row;
}
+
+ @Override
+ public String toString() {
+ return "InsertOperation [table=" + table + ", uuidName=" + uuidName
+ + ", row=" + row + ", toString()=" + super.toString() + "]";
+ }
}
public void setMutations(List<Mutation> mutations) {
this.mutations = mutations;
}
+ @Override
+ public String toString() {
+ return "MutateOperation [table=" + table + ", where=" + where
+ + ", mutations=" + mutations + ", toString()="
+ + super.toString() + "]";
+ }
}
package org.opendaylight.ovsdb.lib.message.operations;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
public abstract class Operation {
private String op;
+ @JsonIgnore
+ // Just a simple way to retain the result of a transact operation which the client can refer to.
+ private OperationResult result;
public String getOp() {
return op;
public void setOp(String op) {
this.op = op;
}
+
+ public OperationResult getResult() {
+ return result;
+ }
+
+ public void setResult(OperationResult result) {
+ this.result = result;
+ }
+
+ @Override
+ public String toString() {
+ return "Operation [op=" + op + ", result=" + result + "]";
+ }
}
--- /dev/null
+package org.opendaylight.ovsdb.lib.message.operations;
+
+import java.util.ArrayList;
+import org.opendaylight.ovsdb.lib.notation.UUID;
+
+// 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
+// concrete child classes for each of the operation response.
+// But this needs proper response handling
+// https://trello.com/c/mfTTS86k/28-generic-response-error-handling-especially-for-transact
+// As a temporary measure, adding all the expected responses under the same response.
+
+public class OperationResult {
+ //public abstract boolean isSuccess();
+ private int count;
+ private UUID uuid;
+ private ArrayList<Object> rows;
+ private String error;
+
+ public int getCount() {
+ return count;
+ }
+ public void setCount(int count) {
+ this.count = count;
+ }
+ public UUID getUuid() {
+ return uuid;
+ }
+ public void setUuid(UUID uuid) {
+ this.uuid = uuid;
+ }
+ public ArrayList<Object> getRows() {
+ return rows;
+ }
+ public void setRows(ArrayList<Object> rows) {
+ this.rows = rows;
+ }
+ public String getError() {
+ return error;
+ }
+ public void setError(String error) {
+ this.error = error;
+ }
+ @Override
+ public String toString() {
+ return "OperationResult [count=" + count + ", uuid=" + uuid + ", rows="
+ + rows + ", error=" + error + "]";
+ }
+}
public void setRow(Object row) {
this.row = row;
}
+ @Override
+ public String toString() {
+ return "UpdateOperation [table=" + table + ", where=" + where
+ + ", row=" + row + ", toString()=" + super.toString() + "]";
+ }
}
import org.opendaylight.ovsdb.lib.message.operations.InsertOperation;
import org.opendaylight.ovsdb.lib.message.operations.MutateOperation;
import org.opendaylight.ovsdb.lib.message.operations.Operation;
+import org.opendaylight.ovsdb.lib.message.operations.OperationResult;
import org.opendaylight.ovsdb.lib.notation.Condition;
import org.opendaylight.ovsdb.lib.notation.Function;
import org.opendaylight.ovsdb.lib.notation.Mutation;
JsonRpcServiceBinderHandler binderHandler = new JsonRpcServiceBinderHandler(factory);
List<ChannelHandler> _handlers = Lists.newArrayList();
- _handlers.add(new LoggingHandler(LogLevel.INFO));
+ //_handlers.add(new LoggingHandler(LogLevel.INFO));
_handlers.add(new JsonRpcDecoder(100000));
_handlers.add(new StringEncoder(CharsetUtil.UTF_8));
_handlers.add(binderHandler);
String newPort = "new_port";
String newSwitch = "new_switch";
- String bridgeIdentifier = "br10";
+ String bridgeIdentifier = "br1";
Operation addSwitchRequest = null;
if(ovsTable != null){
transaction.addOperations(new ArrayList<Operation>(
Arrays.asList(addSwitchRequest, addIntfRequest, addPortRequest, addBridgeRequest)));
- ListenableFuture<List<Object>> transResponse = ovsdb.transact(transaction);
+ ListenableFuture<List<OperationResult>> transResponse = ovsdb.transact(transaction);
System.out.println("Transcation sent :");
- Object tr = transResponse.get();
- System.out.println(tr.toString());
+ List<OperationResult> tr = transResponse.get();
// TEST ECHO
ListenableFuture<List<String>> some = ovsdb.echo();