Search in sources :

Example 6 with Row

use of org.onosproject.ovsdb.rfc.notation.Row in project onos by opennetworkinglab.

the class DefaultOvsdbClient method getBridgeUuid.

@Override
public String getBridgeUuid(String bridgeName) {
    DatabaseSchema dbSchema = schema.get(DATABASENAME);
    OvsdbRowStore rowStore = getRowStore(DATABASENAME, BRIDGE);
    if (rowStore == null) {
        log.debug("The bridge uuid is null");
        return null;
    }
    ConcurrentMap<String, Row> bridgeTableRows = rowStore.getRowStore();
    if (bridgeTableRows == null) {
        log.debug("The bridge uuid is null");
        return null;
    }
    for (String uuid : bridgeTableRows.keySet()) {
        Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, bridgeTableRows.get(uuid), OvsdbTable.BRIDGE);
        if (bridge.getName().equals(bridgeName)) {
            return uuid;
        }
    }
    return null;
}
Also used : Row(org.onosproject.ovsdb.rfc.notation.Row) OvsdbRowStore(org.onosproject.ovsdb.controller.OvsdbRowStore) Bridge(org.onosproject.ovsdb.rfc.table.Bridge) OvsdbBridge(org.onosproject.ovsdb.controller.OvsdbBridge) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Example 7 with Row

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

Example 8 with Row

use of org.onosproject.ovsdb.rfc.notation.Row in project onos by opennetworkinglab.

the class FromJsonUtil method jsonNodeToTableUpdate.

/**
 * convert the params of Update Notification into TableUpdate.
 * @param tableSchema TableSchema entity
 * @param updateJson the table-update in params of Update Notification
 * @return TableUpdate
 */
public static TableUpdate jsonNodeToTableUpdate(TableSchema tableSchema, JsonNode updateJson) {
    Map<Uuid, RowUpdate> rows = Maps.newHashMap();
    Iterator<Map.Entry<String, JsonNode>> tableUpdateItr = updateJson.fields();
    while (tableUpdateItr.hasNext()) {
        Map.Entry<String, JsonNode> oldNewRow = tableUpdateItr.next();
        String uuidStr = oldNewRow.getKey();
        Uuid uuid = Uuid.uuid(uuidStr);
        JsonNode newR = oldNewRow.getValue().get("new");
        JsonNode oldR = oldNewRow.getValue().get("old");
        Row newRow = newR != null ? createRow(tableSchema, uuid, newR) : null;
        Row oldRow = oldR != null ? createRow(tableSchema, uuid, oldR) : null;
        RowUpdate rowUpdate = new RowUpdate(uuid, oldRow, newRow);
        rows.put(uuid, rowUpdate);
    }
    return TableUpdate.tableUpdate(rows);
}
Also used : Uuid(org.onosproject.ovsdb.rfc.notation.Uuid) JsonNode(com.fasterxml.jackson.databind.JsonNode) RowUpdate(org.onosproject.ovsdb.rfc.message.RowUpdate) Row(org.onosproject.ovsdb.rfc.notation.Row) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with Row

use of org.onosproject.ovsdb.rfc.notation.Row in project onos by opennetworkinglab.

the class FromJsonUtil method createRows.

/**
 * Convert Operation JsonNode into Rows.
 * @param tableSchema TableSchema entity
 * @param rowsNode JsonNode
 * @return ArrayList<Row> the List of Row
 */
private static ArrayList<Row> createRows(TableSchema tableSchema, JsonNode rowsNode) {
    validateJsonNode(rowsNode, "rows");
    ArrayList<Row> rows = Lists.newArrayList();
    for (JsonNode rowNode : rowsNode.get("rows")) {
        // FIXME null will throw exception
        rows.add(createRow(tableSchema, null, rowNode));
    }
    return rows;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) Row(org.onosproject.ovsdb.rfc.notation.Row)

Example 10 with Row

use of org.onosproject.ovsdb.rfc.notation.Row in project onos by opennetworkinglab.

the class DefaultOvsdbClient method applyQos.

@Override
public void applyQos(PortNumber portNumber, String qosName) {
    DatabaseSchema dbSchema = schema.get(DATABASENAME);
    OvsdbRowStore portRowStore = getRowStore(DATABASENAME, PORT);
    if (portRowStore == null) {
        log.debug("The port uuid is null");
        return;
    }
    OvsdbRowStore qosRowStore = getRowStore(DATABASENAME, QOS);
    if (qosRowStore == null) {
        log.debug("The qos uuid is null");
        return;
    }
    // Due to Qos Table doesn't have a unique identifier except uuid, unlike
    // Bridge or Port Table has a name column,in order to make the api more
    // general, put qos name in external_ids column of Qos Table if this qos
    // created by onos.
    ConcurrentMap<String, Row> qosTableRows = qosRowStore.getRowStore();
    ConcurrentMap<String, Row> portTableRows = portRowStore.getRowStore();
    Row qosRow = qosTableRows.values().stream().filter(r -> {
        OvsdbMap ovsdbMap = (OvsdbMap) (r.getColumn(EXTERNAL_ID).data());
        return qosName.equals(ovsdbMap.map().get(QOS_EXTERNAL_ID_KEY));
    }).findFirst().orElse(null);
    Row portRow = portTableRows.values().stream().filter(r -> r.getColumn("name").data().equals(portNumber.name())).findFirst().orElse(null);
    if (portRow != null && qosRow != null) {
        String qosId = qosRow.uuid().value();
        Uuid portUuid = portRow.uuid();
        Map<String, Column> columns = new HashMap<>();
        Row newPortRow = new Row(PORT, portUuid, columns);
        Port newport = new Port(dbSchema, newPortRow);
        columns.put(Port.PortColumn.QOS.columnName(), newport.getQosColumn());
        newport.setQos(Uuid.uuid(qosId));
        updateConfig(PORT, UUID, portUuid.value(), newport.getRow());
    }
}
Also used : Uuid(org.onosproject.ovsdb.rfc.notation.Uuid) Column(org.onosproject.ovsdb.rfc.notation.Column) HashMap(java.util.HashMap) OvsdbPort(org.onosproject.ovsdb.controller.OvsdbPort) Port(org.onosproject.ovsdb.rfc.table.Port) OvsdbMap(org.onosproject.ovsdb.rfc.notation.OvsdbMap) Row(org.onosproject.ovsdb.rfc.notation.Row) OvsdbRowStore(org.onosproject.ovsdb.controller.OvsdbRowStore) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Aggregations

Row (org.onosproject.ovsdb.rfc.notation.Row)30 OvsdbRowStore (org.onosproject.ovsdb.controller.OvsdbRowStore)23 DatabaseSchema (org.onosproject.ovsdb.rfc.schema.DatabaseSchema)19 Uuid (org.onosproject.ovsdb.rfc.notation.Uuid)17 HashMap (java.util.HashMap)13 OvsdbMap (org.onosproject.ovsdb.rfc.notation.OvsdbMap)13 HashSet (java.util.HashSet)12 Map (java.util.Map)11 OvsdbBridge (org.onosproject.ovsdb.controller.OvsdbBridge)11 OvsdbSet (org.onosproject.ovsdb.rfc.notation.OvsdbSet)11 Bridge (org.onosproject.ovsdb.rfc.table.Bridge)11 Operation (org.onosproject.ovsdb.rfc.operations.Operation)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 ConcurrentMap (java.util.concurrent.ConcurrentMap)9 ArrayList (java.util.ArrayList)8 Set (java.util.Set)8 OvsdbPort (org.onosproject.ovsdb.controller.OvsdbPort)8 OvsdbTableStore (org.onosproject.ovsdb.controller.OvsdbTableStore)8 Condition (org.onosproject.ovsdb.rfc.notation.Condition)8 Mutation (org.onosproject.ovsdb.rfc.notation.Mutation)8