Search in sources :

Example 6 with ColumnSchema

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

the class DefaultOvsdbClient method unbindQueues.

@SuppressWarnings("unchecked")
@Override
public void unbindQueues(QosId qosId, List<Long> queueKeys) {
    DatabaseSchema dbSchema = schema.get(DATABASENAME);
    OvsdbRowStore qosRowStore = getRowStore(DATABASENAME, QOS);
    if (qosRowStore == null) {
        return;
    }
    ConcurrentMap<String, Row> qosTableRows = qosRowStore.getRowStore();
    Row qosRow = qosTableRows.values().stream().filter(r -> {
        OvsdbMap ovsdbMap = (OvsdbMap) (r.getColumn(EXTERNAL_ID).data());
        return qosId.name().equals(ovsdbMap.map().get(QOS_EXTERNAL_ID_KEY));
    }).findFirst().orElse(null);
    if (qosRow == null) {
        log.warn("Can't find QoS {}", qosId);
        return;
    }
    Map<Long, Uuid> deleteQueuesMap;
    Map<Integer, Uuid> queuesMap = ((OvsdbMap) qosRow.getColumn(QUEUES).data()).map();
    deleteQueuesMap = queueKeys.stream().filter(key -> queuesMap.containsKey(key.intValue())).collect(Collectors.toMap(key -> key, key -> queuesMap.get(key.intValue()), (a, b) -> b));
    if (deleteQueuesMap.size() != 0) {
        TableSchema parentTableSchema = dbSchema.getTableSchema(QOS);
        ColumnSchema parentColumnSchema = parentTableSchema.getColumnSchema(QUEUES);
        Mutation mutation = MutationUtil.delete(parentColumnSchema.name(), OvsdbMap.ovsdbMap(deleteQueuesMap));
        List<Mutation> mutations = Collections.singletonList(mutation);
        Condition condition = ConditionUtil.isEqual(UUID, qosRow.uuid());
        List<Condition> conditionList = Collections.singletonList(condition);
        List<Operation> operations = Collections.singletonList(new Mutate(parentTableSchema, conditionList, mutations));
        transactConfig(DATABASENAME, operations);
    }
}
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) Operation(org.onosproject.ovsdb.rfc.operations.Operation) OvsdbRowStore(org.onosproject.ovsdb.controller.OvsdbRowStore) Uuid(org.onosproject.ovsdb.rfc.notation.Uuid) OvsdbMap(org.onosproject.ovsdb.rfc.notation.OvsdbMap) Row(org.onosproject.ovsdb.rfc.notation.Row) Mutation(org.onosproject.ovsdb.rfc.notation.Mutation) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Example 7 with ColumnSchema

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

the class FromJsonUtil method createRow.

/**
 * Convert Operation JsonNode into Row.
 * @param tableSchema TableSchema entity
 * @param rowNode JsonNode
 * @return Row
 */
private static Row createRow(TableSchema tableSchema, Uuid uuid, JsonNode rowNode) {
    if (tableSchema == null) {
        return null;
    }
    Map<String, Column> columns = Maps.newHashMap();
    Iterator<Map.Entry<String, JsonNode>> rowIter = rowNode.fields();
    while (rowIter.hasNext()) {
        Map.Entry<String, JsonNode> next = rowIter.next();
        ColumnSchema columnSchema = tableSchema.getColumnSchema(next.getKey());
        if (columnSchema != null) {
            String columnName = columnSchema.name();
            Object obj = TransValueUtil.getValueFromJson(next.getValue(), columnSchema.type());
            columns.put(columnName, new Column(columnName, obj));
        }
    }
    return new Row(tableSchema.name(), uuid, columns);
}
Also used : Column(org.onosproject.ovsdb.rfc.notation.Column) JsonNode(com.fasterxml.jackson.databind.JsonNode) ColumnSchema(org.onosproject.ovsdb.rfc.schema.ColumnSchema) Row(org.onosproject.ovsdb.rfc.notation.Row) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with ColumnSchema

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

the class AbstractOvsdbTableService method getDataHandler.

@Override
public Object getDataHandler(ColumnDescription columnDesc) {
    if (!isValid()) {
        return null;
    }
    String columnName = columnDesc.name();
    checkColumnSchemaVersion(columnDesc);
    ColumnSchema columnSchema = getColumnSchema(columnName);
    if (row == null || row.getColumn(columnSchema.name()) == null) {
        return null;
    }
    return row.getColumn(columnSchema.name()).data();
}
Also used : ColumnSchema(org.onosproject.ovsdb.rfc.schema.ColumnSchema)

Example 9 with ColumnSchema

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

the class DefaultOvsdbClient method deleteConfig.

/**
 * Delete transact config.
 *
 * @param childTableName   child table name
 * @param childColumnName  child column name
 * @param childUuid        child row uuid
 * @param parentTableName  parent table name
 * @param parentColumnName parent column
 * @param referencedValue  referenced value
 */
private void deleteConfig(String childTableName, String childColumnName, String childUuid, String parentTableName, String parentColumnName, Object referencedValue) {
    DatabaseSchema dbSchema = schema.get(DATABASENAME);
    TableSchema childTableSchema = dbSchema.getTableSchema(childTableName);
    ArrayList<Operation> operations = Lists.newArrayList();
    if (parentTableName != null && parentColumnName != null && referencedValue != null) {
        TableSchema parentTableSchema = dbSchema.getTableSchema(parentTableName);
        ColumnSchema parentColumnSchema = parentTableSchema.getColumnSchema(parentColumnName);
        List<Mutation> mutations = Lists.newArrayList();
        Mutation mutation = MutationUtil.delete(parentColumnSchema.name(), referencedValue);
        mutations.add(mutation);
        List<Condition> conditions = Lists.newArrayList();
        Condition condition = ConditionUtil.includes(parentColumnName, referencedValue);
        conditions.add(condition);
        Mutate op = new Mutate(parentTableSchema, conditions, mutations);
        operations.add(op);
    }
    List<Condition> conditions = Lists.newArrayList();
    Condition condition = ConditionUtil.isEqual(childColumnName, Uuid.uuid(childUuid));
    conditions.add(condition);
    Delete del = new Delete(childTableSchema, conditions);
    operations.add(del);
    transactConfig(DATABASENAME, operations);
}
Also used : Condition(org.onosproject.ovsdb.rfc.notation.Condition) Delete(org.onosproject.ovsdb.rfc.operations.Delete) TableSchema(org.onosproject.ovsdb.rfc.schema.TableSchema) ColumnSchema(org.onosproject.ovsdb.rfc.schema.ColumnSchema) Mutate(org.onosproject.ovsdb.rfc.operations.Mutate) Operation(org.onosproject.ovsdb.rfc.operations.Operation) Mutation(org.onosproject.ovsdb.rfc.notation.Mutation) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Aggregations

ColumnSchema (org.onosproject.ovsdb.rfc.schema.ColumnSchema)9 TableSchema (org.onosproject.ovsdb.rfc.schema.TableSchema)5 DatabaseSchema (org.onosproject.ovsdb.rfc.schema.DatabaseSchema)4 Condition (org.onosproject.ovsdb.rfc.notation.Condition)3 Mutation (org.onosproject.ovsdb.rfc.notation.Mutation)3 Mutate (org.onosproject.ovsdb.rfc.operations.Mutate)3 Operation (org.onosproject.ovsdb.rfc.operations.Operation)3 Column (org.onosproject.ovsdb.rfc.notation.Column)2 Row (org.onosproject.ovsdb.rfc.notation.Row)2 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 OperationResult (org.onosproject.ovsdb.rfc.message.OperationResult)1