use of org.onosproject.ovsdb.rfc.operations.Operation 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.operations.Operation in project onos by opennetworkinglab.
the class DefaultOvsdbClient method createQos.
@Override
public boolean createQos(OvsdbQos ovsdbQos) {
DatabaseSchema dbSchema = schema.get(DATABASENAME);
Qos qos = (Qos) TableGenerator.createTable(dbSchema, OvsdbTable.QOS);
OvsdbRowStore rowStore = getRowStore(DATABASENAME, QOS);
if (rowStore == null) {
log.debug("The qos uuid is null");
return false;
}
ArrayList<Operation> operations = Lists.newArrayList();
Set<String> types = Sets.newHashSet();
Map<Long, Uuid> queues = Maps.newHashMap();
types.add(ovsdbQos.qosType());
qos.setOtherConfig(ovsdbQos.otherConfigs());
qos.setExternalIds(ovsdbQos.externalIds());
qos.setType(types);
if (ovsdbQos.qosQueues().isPresent()) {
for (Map.Entry<Long, String> entry : ovsdbQos.qosQueues().get().entrySet()) {
OvsdbRowStore queueRowStore = getRowStore(DATABASENAME, QUEUE);
if (queueRowStore != null) {
ConcurrentMap<String, Row> queueTableRows = queueRowStore.getRowStore();
Row queueRow = queueTableRows.values().stream().filter(r -> {
OvsdbMap ovsdbMap = (OvsdbMap) (r.getColumn(EXTERNAL_ID).data());
return entry.getValue().equals(ovsdbMap.map().get(QUEUE_EXTERNAL_ID_KEY));
}).findFirst().orElse(null);
if (queueRow != null) {
queues.put(entry.getKey(), queueRow.uuid());
}
}
}
qos.setQueues(queues);
}
Insert qosInsert = new Insert(dbSchema.getTableSchema(QOS), QOS, qos.getRow());
operations.add(qosInsert);
try {
transactConfig(DATABASENAME, operations).get();
} catch (InterruptedException | ExecutionException e) {
return false;
}
return true;
}
use of org.onosproject.ovsdb.rfc.operations.Operation in project onos by opennetworkinglab.
the class DefaultOvsdbClient method createQueue.
@Override
public boolean createQueue(OvsdbQueue ovsdbQueue) {
DatabaseSchema dbSchema = schema.get(DATABASENAME);
Queue queue = (Queue) TableGenerator.createTable(dbSchema, OvsdbTable.QUEUE);
ArrayList<Operation> operations = Lists.newArrayList();
OvsdbRowStore rowStore = getRowStore(DATABASENAME, QUEUE);
if (rowStore == null) {
log.debug("The queue uuid is null");
return false;
}
if (ovsdbQueue.dscp().isPresent()) {
queue.setDscp(ImmutableSet.of(ovsdbQueue.dscp().get()));
}
queue.setOtherConfig(ovsdbQueue.otherConfigs());
queue.setExternalIds(ovsdbQueue.externalIds());
Insert queueInsert = new Insert(dbSchema.getTableSchema(QUEUE), QUEUE, queue.getRow());
operations.add(queueInsert);
try {
transactConfig(DATABASENAME, operations).get();
} catch (InterruptedException | ExecutionException e) {
log.error("createQueue transactConfig get exception !");
}
return true;
}
use of org.onosproject.ovsdb.rfc.operations.Operation in project onos by opennetworkinglab.
the class DefaultOvsdbClient method updateConfig.
/**
* Update transact config.
*
* @param tableName table name
* @param columnName column name
* @param uuid uuid
* @param row the config data
*/
private void updateConfig(String tableName, String columnName, String uuid, Row row) {
DatabaseSchema dbSchema = schema.get(DATABASENAME);
TableSchema tableSchema = dbSchema.getTableSchema(tableName);
List<Condition> conditions = Lists.newArrayList();
Condition condition = ConditionUtil.isEqual(columnName, Uuid.uuid(uuid));
conditions.add(condition);
Update update = new Update(tableSchema, row, conditions);
ArrayList<Operation> operations = Lists.newArrayList();
operations.add(update);
transactConfig(DATABASENAME, operations);
}
use of org.onosproject.ovsdb.rfc.operations.Operation 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);
}
}
Aggregations