Search in sources :

Example 1 with OperationResult

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;
}
Also used : Condition(org.onosproject.ovsdb.rfc.notation.Condition) TableSchema(org.onosproject.ovsdb.rfc.schema.TableSchema) ColumnSchema(org.onosproject.ovsdb.rfc.schema.ColumnSchema) Mutate(org.onosproject.ovsdb.rfc.operations.Mutate) OperationResult(org.onosproject.ovsdb.rfc.message.OperationResult) Operation(org.onosproject.ovsdb.rfc.operations.Operation) Insert(org.onosproject.ovsdb.rfc.operations.Insert) Mutation(org.onosproject.ovsdb.rfc.notation.Mutation) ExecutionException(java.util.concurrent.ExecutionException) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with OperationResult

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;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) OperationResult(org.onosproject.ovsdb.rfc.message.OperationResult) ColumnSchemaNotFoundException(org.onosproject.ovsdb.rfc.exception.ColumnSchemaNotFoundException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) VersionMismatchException(org.onosproject.ovsdb.rfc.exception.VersionMismatchException) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Example 3 with OperationResult

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;
}
Also used : ArrayList(java.util.ArrayList) OperationResult(org.onosproject.ovsdb.rfc.message.OperationResult) JsonNode(com.fasterxml.jackson.databind.JsonNode) Operation(org.onosproject.ovsdb.rfc.operations.Operation) Row(org.onosproject.ovsdb.rfc.notation.Row) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

OperationResult (org.onosproject.ovsdb.rfc.message.OperationResult)3 ArrayList (java.util.ArrayList)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 Operation (org.onosproject.ovsdb.rfc.operations.Operation)2 DatabaseSchema (org.onosproject.ovsdb.rfc.schema.DatabaseSchema)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1 ColumnSchemaNotFoundException (org.onosproject.ovsdb.rfc.exception.ColumnSchemaNotFoundException)1 VersionMismatchException (org.onosproject.ovsdb.rfc.exception.VersionMismatchException)1 Condition (org.onosproject.ovsdb.rfc.notation.Condition)1 Mutation (org.onosproject.ovsdb.rfc.notation.Mutation)1 Row (org.onosproject.ovsdb.rfc.notation.Row)1 Insert (org.onosproject.ovsdb.rfc.operations.Insert)1 Mutate (org.onosproject.ovsdb.rfc.operations.Mutate)1 ColumnSchema (org.onosproject.ovsdb.rfc.schema.ColumnSchema)1 TableSchema (org.onosproject.ovsdb.rfc.schema.TableSchema)1