Search in sources :

Example 6 with Operation

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;
}
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 7 with Operation

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;
}
Also used : Operation(org.onosproject.ovsdb.rfc.operations.Operation) OvsdbRowStore(org.onosproject.ovsdb.controller.OvsdbRowStore) Insert(org.onosproject.ovsdb.rfc.operations.Insert) Uuid(org.onosproject.ovsdb.rfc.notation.Uuid) Qos(org.onosproject.ovsdb.rfc.table.Qos) OvsdbQos(org.onosproject.ovsdb.controller.OvsdbQos) OvsdbMap(org.onosproject.ovsdb.rfc.notation.OvsdbMap) Row(org.onosproject.ovsdb.rfc.notation.Row) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) OvsdbMap(org.onosproject.ovsdb.rfc.notation.OvsdbMap) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Example 8 with Operation

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;
}
Also used : Operation(org.onosproject.ovsdb.rfc.operations.Operation) OvsdbRowStore(org.onosproject.ovsdb.controller.OvsdbRowStore) Insert(org.onosproject.ovsdb.rfc.operations.Insert) ExecutionException(java.util.concurrent.ExecutionException) OvsdbQueue(org.onosproject.ovsdb.controller.OvsdbQueue) Queue(org.onosproject.ovsdb.rfc.table.Queue) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Example 9 with Operation

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);
}
Also used : Condition(org.onosproject.ovsdb.rfc.notation.Condition) TableSchema(org.onosproject.ovsdb.rfc.schema.TableSchema) Operation(org.onosproject.ovsdb.rfc.operations.Operation) Update(org.onosproject.ovsdb.rfc.operations.Update) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Example 10 with Operation

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);
    }
}
Also used : Condition(org.onosproject.ovsdb.rfc.notation.Condition) TableSchema(org.onosproject.ovsdb.rfc.schema.TableSchema) ColumnSchema(org.onosproject.ovsdb.rfc.schema.ColumnSchema) Mutate(org.onosproject.ovsdb.rfc.operations.Mutate) Operation(org.onosproject.ovsdb.rfc.operations.Operation) OvsdbRowStore(org.onosproject.ovsdb.controller.OvsdbRowStore) Uuid(org.onosproject.ovsdb.rfc.notation.Uuid) OvsdbMap(org.onosproject.ovsdb.rfc.notation.OvsdbMap) Row(org.onosproject.ovsdb.rfc.notation.Row) Mutation(org.onosproject.ovsdb.rfc.notation.Mutation) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Aggregations

Operation (org.onosproject.ovsdb.rfc.operations.Operation)12 DatabaseSchema (org.onosproject.ovsdb.rfc.schema.DatabaseSchema)11 Condition (org.onosproject.ovsdb.rfc.notation.Condition)9 Mutation (org.onosproject.ovsdb.rfc.notation.Mutation)8 Mutate (org.onosproject.ovsdb.rfc.operations.Mutate)8 OvsdbRowStore (org.onosproject.ovsdb.controller.OvsdbRowStore)7 Row (org.onosproject.ovsdb.rfc.notation.Row)7 Uuid (org.onosproject.ovsdb.rfc.notation.Uuid)6 Insert (org.onosproject.ovsdb.rfc.operations.Insert)6 TableSchema (org.onosproject.ovsdb.rfc.schema.TableSchema)6 ExecutionException (java.util.concurrent.ExecutionException)5 OvsdbMap (org.onosproject.ovsdb.rfc.notation.OvsdbMap)5 ColumnSchema (org.onosproject.ovsdb.rfc.schema.ColumnSchema)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ConcurrentMap (java.util.concurrent.ConcurrentMap)4 OperationResult (org.onosproject.ovsdb.rfc.message.OperationResult)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ArrayList (java.util.ArrayList)3 TimeoutException (java.util.concurrent.TimeoutException)3