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;
}
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;
}
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);
}
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;
}
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());
}
}
Aggregations