Search in sources :

Example 1 with TableSchema

use of org.onosproject.ovsdb.rfc.schema.TableSchema in project onos by opennetworkinglab.

the class DefaultOvsdbClient method handlePortInsertTable.

/**
 * Handles port insert.
 *
 * @param portRow   row of port
 * @return insert, empty if null
 */
private Insert handlePortInsertTable(Row portRow) {
    DatabaseSchema dbSchema = schema.get(DATABASENAME);
    TableSchema portTableSchema = dbSchema.getTableSchema(PORT);
    ColumnSchema portColumnSchema = portTableSchema.getColumnSchema("name");
    String portName = (String) portRow.getColumn(portColumnSchema.name()).data();
    Interface inf = (Interface) TableGenerator.createTable(dbSchema, OvsdbTable.INTERFACE);
    inf.setName(portName);
    TableSchema intfTableSchema = dbSchema.getTableSchema(INTERFACE);
    return new Insert(intfTableSchema, INTERFACE, inf.getRow());
}
Also used : TableSchema(org.onosproject.ovsdb.rfc.schema.TableSchema) ColumnSchema(org.onosproject.ovsdb.rfc.schema.ColumnSchema) Insert(org.onosproject.ovsdb.rfc.operations.Insert) Interface(org.onosproject.ovsdb.rfc.table.Interface) OvsdbInterface(org.onosproject.ovsdb.controller.OvsdbInterface) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Example 2 with TableSchema

use of org.onosproject.ovsdb.rfc.schema.TableSchema 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 3 with TableSchema

use of org.onosproject.ovsdb.rfc.schema.TableSchema in project onos by opennetworkinglab.

the class AbstractOvsdbTableService method toString.

@Override
public String toString() {
    TableSchema schema = getTableSchema();
    String tableName = schema.name();
    return toStringHelper(this).add("tableName", tableName).add("row", row).toString();
}
Also used : TableSchema(org.onosproject.ovsdb.rfc.schema.TableSchema)

Example 4 with TableSchema

use of org.onosproject.ovsdb.rfc.schema.TableSchema in project onos by opennetworkinglab.

the class AbstractOvsdbTableService method getColumnSchema.

/**
 * Returns ColumnSchema from TableSchema by column name.
 * @param columnName column name
 * @return ColumnSchema
 */
private ColumnSchema getColumnSchema(String columnName) {
    TableSchema tableSchema = getTableSchema();
    if (tableSchema == null) {
        String message = TableSchemaNotFoundException.createMessage(tableDesc.name(), dbSchema.name());
        throw new TableSchemaNotFoundException(message);
    }
    ColumnSchema columnSchema = tableSchema.getColumnSchema(columnName);
    if (columnSchema == null) {
        String message = ColumnSchemaNotFoundException.createMessage(columnName, tableSchema.name());
        throw new ColumnSchemaNotFoundException(message);
    }
    return columnSchema;
}
Also used : TableSchemaNotFoundException(org.onosproject.ovsdb.rfc.exception.TableSchemaNotFoundException) TableSchema(org.onosproject.ovsdb.rfc.schema.TableSchema) ColumnSchema(org.onosproject.ovsdb.rfc.schema.ColumnSchema) ColumnSchemaNotFoundException(org.onosproject.ovsdb.rfc.exception.ColumnSchemaNotFoundException)

Example 5 with TableSchema

use of org.onosproject.ovsdb.rfc.schema.TableSchema in project onos by opennetworkinglab.

the class FromJsonUtil method jsonNodeToTableUpdates.

/**
 * convert the params of Update Notification into TableUpdates.
 * @param updatesJson the params of Update Notification
 * @param dbSchema DatabaseSchema entity
 * @return TableUpdates
 */
public static TableUpdates jsonNodeToTableUpdates(JsonNode updatesJson, DatabaseSchema dbSchema) {
    Map<String, TableUpdate> tableUpdateMap = Maps.newHashMap();
    Iterator<Map.Entry<String, JsonNode>> tableUpdatesItr = updatesJson.fields();
    while (tableUpdatesItr.hasNext()) {
        Map.Entry<String, JsonNode> entry = tableUpdatesItr.next();
        TableSchema tableSchema = dbSchema.getTableSchema(entry.getKey());
        TableUpdate tableUpdate = jsonNodeToTableUpdate(tableSchema, entry.getValue());
        tableUpdateMap.put(entry.getKey(), tableUpdate);
    }
    return TableUpdates.tableUpdates(tableUpdateMap);
}
Also used : TableSchema(org.onosproject.ovsdb.rfc.schema.TableSchema) JsonNode(com.fasterxml.jackson.databind.JsonNode) TableUpdate(org.onosproject.ovsdb.rfc.message.TableUpdate) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

TableSchema (org.onosproject.ovsdb.rfc.schema.TableSchema)9 ColumnSchema (org.onosproject.ovsdb.rfc.schema.ColumnSchema)5 DatabaseSchema (org.onosproject.ovsdb.rfc.schema.DatabaseSchema)5 Condition (org.onosproject.ovsdb.rfc.notation.Condition)4 Operation (org.onosproject.ovsdb.rfc.operations.Operation)4 Mutation (org.onosproject.ovsdb.rfc.notation.Mutation)3 Mutate (org.onosproject.ovsdb.rfc.operations.Mutate)3 Insert (org.onosproject.ovsdb.rfc.operations.Insert)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 OvsdbInterface (org.onosproject.ovsdb.controller.OvsdbInterface)1 OvsdbRowStore (org.onosproject.ovsdb.controller.OvsdbRowStore)1 ColumnSchemaNotFoundException (org.onosproject.ovsdb.rfc.exception.ColumnSchemaNotFoundException)1 TableSchemaNotFoundException (org.onosproject.ovsdb.rfc.exception.TableSchemaNotFoundException)1 MonitorRequest (org.onosproject.ovsdb.rfc.message.MonitorRequest)1 OperationResult (org.onosproject.ovsdb.rfc.message.OperationResult)1 TableUpdate (org.onosproject.ovsdb.rfc.message.TableUpdate)1