Search in sources :

Example 1 with TableUpdate

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

Example 2 with TableUpdate

use of org.onosproject.ovsdb.rfc.message.TableUpdate in project onos by opennetworkinglab.

the class OvsdbControllerImpl method processTableUpdates.

/**
 * Processes table updates.
 *
 * @param clientService OvsdbClientService instance
 * @param updates       TableUpdates instance
 * @param dbName        ovsdb database name
 */
private void processTableUpdates(OvsdbClientService clientService, TableUpdates updates, String dbName) throws InterruptedException {
    checkNotNull(clientService, "OvsdbClientService is not null");
    DatabaseSchema dbSchema = clientService.getDatabaseSchema(dbName);
    for (String tableName : updates.result().keySet()) {
        TableUpdate update = updates.result().get(tableName);
        for (Uuid uuid : (Set<Uuid>) update.rows().keySet()) {
            log.debug("Begin to process table updates uuid: {}, databaseName: {}, tableName: {}", uuid.value(), dbName, tableName);
            Row newRow = update.getNew(uuid);
            if (newRow != null) {
                clientService.updateOvsdbStore(dbName, tableName, uuid.value(), newRow);
                if (OvsdbConstant.INTERFACE.equals(tableName)) {
                    dispatchInterfaceEvent(clientService, newRow, OvsdbEvent.Type.PORT_ADDED, dbSchema);
                }
            } else if (update.getOld(uuid) != null) {
                if (OvsdbConstant.INTERFACE.equals(tableName)) {
                    Row row = clientService.getRow(OvsdbConstant.DATABASENAME, tableName, uuid.value());
                    dispatchInterfaceEvent(clientService, row, OvsdbEvent.Type.PORT_REMOVED, dbSchema);
                }
                clientService.removeRow(dbName, tableName, uuid.value());
            }
        }
    }
}
Also used : Uuid(org.onosproject.ovsdb.rfc.notation.Uuid) Set(java.util.Set) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) HashSet(java.util.HashSet) OvsdbSet(org.onosproject.ovsdb.rfc.notation.OvsdbSet) Row(org.onosproject.ovsdb.rfc.notation.Row) TableUpdate(org.onosproject.ovsdb.rfc.message.TableUpdate) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Aggregations

TableUpdate (org.onosproject.ovsdb.rfc.message.TableUpdate)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)1 OvsdbSet (org.onosproject.ovsdb.rfc.notation.OvsdbSet)1 Row (org.onosproject.ovsdb.rfc.notation.Row)1 Uuid (org.onosproject.ovsdb.rfc.notation.Uuid)1 DatabaseSchema (org.onosproject.ovsdb.rfc.schema.DatabaseSchema)1 TableSchema (org.onosproject.ovsdb.rfc.schema.TableSchema)1