use of org.onosproject.ovsdb.rfc.message.OperationResult in project onos by opennetworkinglab.
the class DefaultOvsdbClient method insertConfig.
/**
* Insert transact config.
*
* @param childTableName child table name
* @param childColumnName child column name
* @param parentTableName parent table name
* @param parentColumnName parent column
* @param parentUuid parent uuid
* @param row the config data
* @return uuid, empty if no uuid is find
*/
private String insertConfig(String childTableName, String childColumnName, String parentTableName, String parentColumnName, String parentUuid, Row row) {
DatabaseSchema dbSchema = schema.get(DATABASENAME);
TableSchema tableSchema = dbSchema.getTableSchema(childTableName);
Insert insert = new Insert(tableSchema, childTableName, row);
ArrayList<Operation> operations = Lists.newArrayList();
operations.add(insert);
if (parentTableName != null && parentColumnName != null) {
TableSchema parentTableSchema = dbSchema.getTableSchema(parentTableName);
ColumnSchema parentColumnSchema = parentTableSchema.getColumnSchema(parentColumnName);
List<Mutation> mutations = Lists.newArrayList();
Mutation mutation = MutationUtil.insert(parentColumnSchema.name(), Uuid.uuid(childTableName));
mutations.add(mutation);
List<Condition> conditions = Lists.newArrayList();
Condition condition = ConditionUtil.isEqual(UUID, Uuid.uuid(parentUuid));
conditions.add(condition);
Mutate op = new Mutate(parentTableSchema, conditions, mutations);
operations.add(op);
}
if (childTableName.equalsIgnoreCase(PORT)) {
log.debug("Handle port insert");
Insert intfInsert = handlePortInsertTable(row);
if (intfInsert != null) {
operations.add(intfInsert);
}
Insert ins = (Insert) operations.get(0);
ins.getRow().put("interfaces", Uuid.uuid(INTERFACE));
}
List<OperationResult> results;
try {
results = transactConfig(DATABASENAME, operations).get(TRANSACTCONFIG_TIMEOUT, TimeUnit.SECONDS);
return results.get(0).getUuid().value();
} catch (TimeoutException e) {
log.warn("TimeoutException thrown while to get result");
} catch (InterruptedException e) {
log.warn("Interrupted while waiting to get result");
Thread.currentThread().interrupt();
} catch (ExecutionException e) {
log.error("Exception thrown while to get result");
}
return null;
}
use of org.onosproject.ovsdb.rfc.message.OperationResult in project onos by opennetworkinglab.
the class DefaultOvsdbClient method transactConfig.
private ListenableFuture<List<OperationResult>> transactConfig(String dbName, List<Operation> operations) {
if (dbName == null) {
return null;
}
DatabaseSchema dbSchema = schema.get(dbName);
if (dbSchema != null) {
Function<List<JsonNode>, List<OperationResult>> rowFunction = (input -> {
try {
log.debug("Get ovsdb operation result");
List<OperationResult> result = FromJsonUtil.jsonNodeToOperationResult(input, operations);
if (result == null) {
log.debug("The operation result is null");
return null;
}
return result;
} catch (Exception e) {
log.error("Exception while parsing result", e);
}
return null;
});
return futureTransform(transact(dbSchema, operations), rowFunction);
}
return null;
}
use of org.onosproject.ovsdb.rfc.message.OperationResult in project onos by opennetworkinglab.
the class FromJsonUtil method jsonNodeToOperationResult.
/**
* Convert the List of Operation result into List of OperationResult .
* @param input the List of JsonNode
* @param operations the List of Operation
* @return the List of OperationResult
*/
public static List<OperationResult> jsonNodeToOperationResult(List<JsonNode> input, List<Operation> operations) {
ObjectMapper objectMapper = ObjectMapperUtil.getObjectMapper(false);
List<OperationResult> operationResults = new ArrayList<>();
for (int i = 0; i < input.size(); i++) {
JsonNode jsonNode = input.get(i);
if (jsonNode != null && jsonNode.size() > 0) {
if (i >= operations.size()) {
OperationResult or = objectMapper.convertValue(jsonNode, OperationResult.class);
operationResults.add(or);
} else {
Operation operation = operations.get(i);
if (!operation.getOp().equals("select")) {
OperationResult or = objectMapper.convertValue(jsonNode, OperationResult.class);
operationResults.add(or);
} else {
List<Row> rows = createRows(operation.getTableSchema(), jsonNode);
OperationResult or = new OperationResult(rows);
operationResults.add(or);
}
}
}
}
return operationResults;
}
Aggregations