Search in sources :

Example 6 with Mutate

use of org.onosproject.ovsdb.rfc.operations.Mutate 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)

Example 7 with Mutate

use of org.onosproject.ovsdb.rfc.operations.Mutate in project onos by opennetworkinglab.

the class DefaultOvsdbClient method createInterface.

@Override
public boolean createInterface(String bridgeName, OvsdbInterface ovsdbIface) {
    String bridgeUuid = getBridgeUuid(bridgeName);
    if (bridgeUuid == null) {
        log.warn("Couldn't find bridge {} in {}", bridgeName, nodeId.getIpAddress());
        return false;
    }
    if (getPortUuid(ovsdbIface.name(), bridgeUuid) != null) {
        log.warn("Interface {} already exists", ovsdbIface.name());
        return false;
    }
    ArrayList<Operation> operations = Lists.newArrayList();
    DatabaseSchema dbSchema = schema.get(DATABASENAME);
    // insert a new port with the interface name
    Port port = (Port) TableGenerator.createTable(dbSchema, OvsdbTable.PORT);
    port.setName(ovsdbIface.name());
    Insert portInsert = new Insert(dbSchema.getTableSchema(PORT), PORT, port.getRow());
    portInsert.getRow().put(INTERFACES, Uuid.uuid(INTERFACE));
    operations.add(portInsert);
    // update the bridge table with the new port
    Condition condition = ConditionUtil.isEqual(UUID, Uuid.uuid(bridgeUuid));
    Mutation mutation = MutationUtil.insert(PORTS, Uuid.uuid(PORT));
    List<Condition> conditions = Lists.newArrayList(condition);
    List<Mutation> mutations = Lists.newArrayList(mutation);
    operations.add(new Mutate(dbSchema.getTableSchema(BRIDGE), conditions, mutations));
    Interface intf = (Interface) TableGenerator.createTable(dbSchema, OvsdbTable.INTERFACE);
    intf.setName(ovsdbIface.name());
    if (ovsdbIface.type() != null) {
        intf.setType(ovsdbIface.typeToString());
    }
    if (ovsdbIface.mtu().isPresent()) {
        Set<Long> mtuSet = Sets.newConcurrentHashSet();
        mtuSet.add(ovsdbIface.mtu().get());
        intf.setMtu(mtuSet);
        intf.setMtuRequest(mtuSet);
    }
    intf.setOptions(ovsdbIface.options());
    ovsdbIface.data().forEach((k, v) -> {
        if (k == Interface.InterfaceColumn.EXTERNALIDS) {
            intf.setExternalIds(v);
        }
    });
    Insert intfInsert = new Insert(dbSchema.getTableSchema(INTERFACE), INTERFACE, intf.getRow());
    operations.add(intfInsert);
    transactConfig(DATABASENAME, operations);
    log.info("Created interface {}", ovsdbIface);
    return true;
}
Also used : Condition(org.onosproject.ovsdb.rfc.notation.Condition) OvsdbPort(org.onosproject.ovsdb.controller.OvsdbPort) Port(org.onosproject.ovsdb.rfc.table.Port) Mutate(org.onosproject.ovsdb.rfc.operations.Mutate) Operation(org.onosproject.ovsdb.rfc.operations.Operation) Insert(org.onosproject.ovsdb.rfc.operations.Insert) Mutation(org.onosproject.ovsdb.rfc.notation.Mutation) Interface(org.onosproject.ovsdb.rfc.table.Interface) OvsdbInterface(org.onosproject.ovsdb.controller.OvsdbInterface) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Aggregations

Condition (org.onosproject.ovsdb.rfc.notation.Condition)7 Mutation (org.onosproject.ovsdb.rfc.notation.Mutation)7 Mutate (org.onosproject.ovsdb.rfc.operations.Mutate)7 Operation (org.onosproject.ovsdb.rfc.operations.Operation)7 DatabaseSchema (org.onosproject.ovsdb.rfc.schema.DatabaseSchema)7 OvsdbRowStore (org.onosproject.ovsdb.controller.OvsdbRowStore)4 Row (org.onosproject.ovsdb.rfc.notation.Row)4 Uuid (org.onosproject.ovsdb.rfc.notation.Uuid)4 ColumnSchema (org.onosproject.ovsdb.rfc.schema.ColumnSchema)4 TableSchema (org.onosproject.ovsdb.rfc.schema.TableSchema)4 OvsdbMap (org.onosproject.ovsdb.rfc.notation.OvsdbMap)3 Insert (org.onosproject.ovsdb.rfc.operations.Insert)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 QueueDescription (org.onosproject.net.behaviour.QueueDescription)2 OperationResult (org.onosproject.ovsdb.rfc.message.OperationResult)2 OvsdbSet (org.onosproject.ovsdb.rfc.notation.OvsdbSet)2