use of org.onosproject.ovsdb.rfc.notation.Row in project onos by opennetworkinglab.
the class DefaultOvsdbClient method getFirstRow.
@Override
public Optional<Object> getFirstRow(String dbName, OvsdbTable tblName) {
DatabaseSchema dbSchema = getDatabaseSchema(dbName);
if (Objects.isNull(dbSchema)) {
return Optional.empty();
}
OvsdbTableStore tableStore = ovsdbStore.getOvsdbTableStore(dbName);
if (tableStore == null) {
return Optional.empty();
}
OvsdbRowStore rowStore = tableStore.getRows(tblName.tableName());
if (rowStore == null) {
return Optional.empty();
}
ConcurrentMap<String, Row> rows = rowStore.getRowStore();
if (rows == null) {
log.debug("The {} Table Rows is null", tblName);
return Optional.empty();
}
// There should be only 1 row in this table
Optional<String> uuid = rows.keySet().stream().findFirst();
if (uuid.isPresent() && rows.containsKey(uuid.get())) {
return Optional.of(TableGenerator.getTable(dbSchema, rows.get(uuid.get()), tblName));
} else {
return Optional.empty();
}
}
use of org.onosproject.ovsdb.rfc.notation.Row in project onos by opennetworkinglab.
the class DefaultOvsdbClient method getElements.
private Set<?> getElements(Function<Row, ?> method) {
OvsdbTableStore tableStore = getTableStore(DATABASENAME);
if (tableStore == null) {
return null;
}
OvsdbRowStore rowStore = tableStore.getRows(INTERFACE);
if (rowStore == null) {
return null;
}
ConcurrentMap<String, Row> rows = rowStore.getRowStore();
return rows.keySet().stream().map(uuid -> getRow(DATABASENAME, INTERFACE, uuid)).map(method).filter(Objects::nonNull).collect(Collectors.toSet());
}
use of org.onosproject.ovsdb.rfc.notation.Row in project onos by opennetworkinglab.
the class DefaultOvsdbClient method dropQueue.
@Override
public void dropQueue(QueueId queueId) {
OvsdbRowStore queueRowStore = getRowStore(DATABASENAME, QUEUE);
if (queueRowStore == null) {
return;
}
ConcurrentMap<String, Row> queueTableRows = queueRowStore.getRowStore();
Row queueRow = queueTableRows.values().stream().filter(r -> {
OvsdbMap ovsdbMap = (OvsdbMap) (r.getColumn(EXTERNAL_ID).data());
return queueId.name().equals(ovsdbMap.map().get(QUEUE_EXTERNAL_ID_KEY));
}).findFirst().orElse(null);
if (queueRow == null) {
return;
}
String queueUuid = queueRow.uuid().value();
OvsdbRowStore qosRowStore = getRowStore(DATABASENAME, QOS);
if (qosRowStore != null) {
Map<Long, Uuid> queueMap = new HashMap<>();
ConcurrentMap<String, Row> qosTableRows = qosRowStore.getRowStore();
qosTableRows.values().stream().filter(r -> {
Map<Integer, Uuid> ovsdbMap = ((OvsdbMap) r.getColumn(QUEUES).data()).map();
Set<Integer> keySet = ovsdbMap.keySet();
for (Integer keyId : keySet) {
if (ovsdbMap.get(keyId).equals(Uuid.uuid(queueUuid))) {
queueMap.put(keyId.longValue(), Uuid.uuid(queueUuid));
return true;
}
}
return false;
}).findFirst().orElse(null);
deleteConfig(QUEUE, UUID, queueUuid, QOS, QUEUES, OvsdbMap.ovsdbMap(queueMap));
} else {
deleteConfig(QUEUE, UUID, queueUuid, null, null, null);
}
}
use of org.onosproject.ovsdb.rfc.notation.Row 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);
}
}
use of org.onosproject.ovsdb.rfc.notation.Row in project onos by opennetworkinglab.
the class DefaultOvsdbClient method getQueues.
@Override
public Set<OvsdbQueue> getQueues() {
Set<OvsdbQueue> ovsdbqueues = new HashSet<>();
OvsdbRowStore rowStore = getRowStore(DATABASENAME, QUEUE);
if (rowStore == null) {
log.debug("The queue uuid is null");
return ovsdbqueues;
}
ConcurrentMap<String, Row> rows = rowStore.getRowStore();
ovsdbqueues = rows.keySet().stream().map(uuid -> getRow(DATABASENAME, QUEUE, uuid)).map(this::getOvsdbQueue).filter(Objects::nonNull).collect(Collectors.toSet());
return ovsdbqueues;
}
Aggregations