@Override public TransactionBuilder transactBuilder(DatabaseSchema dbSchema) { return new TransactionBuilder(this, dbSchema); }
private void execute(TransactionBuilder transaction) { Bridge bridge = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Bridge.class); List<Insert> inserts = TransactUtils.extractInsert(transaction, bridge.getSchema()); for (Insert insert : inserts) { OpenVSwitch ovs = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), OpenVSwitch.class); ovs.setBridges(Sets.newHashSet(TransactUtils.extractNamedUuid(insert))); transaction.add(op.mutate(ovs).addMutation(ovs.getBridgesColumn().getSchema(), Mutator.INSERT, ovs.getBridgesColumn().getData())); } } }
private void invoke(TransactionBuilder txBuilder) { ListenableFuture<List<OperationResult>> result = txBuilder.execute(); LOG.debug("invoke: tb: {}", txBuilder); if (txBuilder.getOperations().size() > 0) { try { List<OperationResult> got = result.get(); LOG.debug("OVSDB transaction result: {}", got); } catch (InterruptedException | ExecutionException e) { LOG.warn("Transact execution exception: ", e); } LOG.trace("invoke exit tb: {}", txBuilder); } }
parentColumn, namedUuid, row, transactionBuilder); int referencedRowsInsertIndex = transactionBuilder.getOperations().size(); Map.Entry<String, Row<GenericTableSchema>> referencedRow = referencedRows.get(refUuid); TableSchema<GenericTableSchema> refTableSchema = dbSchema.table(referencedRow.getKey(), GenericTableSchema.class); transactionBuilder.add(op.insert(refTableSchema, referencedRow.getValue()) .withId(refUuid.toString())); ListenableFuture<List<OperationResult>> results = transactionBuilder.execute(); List<OperationResult> operationResults; try { operationResults = results.get(); if (operationResults.isEmpty() || (transactionBuilder.getOperations().size() != operationResults.size())) { throw new OvsdbPluginException("Insert Operation Failed");
for ( Map.Entry<DatabaseSchema,TransactInvoker> entry: transactInvokers.entrySet()) { TransactionBuilder transaction = new TransactionBuilder(this.client, entry.getKey()); OpenVSwitch ovs = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), OpenVSwitch.class); Mutator.INSERT, ovs.getExternalIdsColumn().getData()); transaction.add(mutate); } catch (NullPointerException e) { LOG.warn("Incomplete OVSDB Node external IDs", e); OpenvswitchOtherConfigs::getOtherConfigKey, OpenvswitchOtherConfigs::getOtherConfigValue)); transaction.add(op.mutate(ovs).addMutation(ovs.getOtherConfigColumn().getSchema(), Mutator.INSERT, ovs.getOtherConfigColumn().getData()));
&& entry.getValue().getTarget() != null) { Controller controller = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Controller.class); controller.setTarget(entry.getValue().getTarget().getValue()); String controllerNamedUuidString = SouthboundMapper.getRandomUuid(); UUID controllerNamedUuid = new UUID(controllerNamedUuidString); transaction.add(op.insert(controller).withId(controllerNamedUuidString)); Bridge bridge = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Bridge.class); bridge.setName(ovsdbBridge.getBridgeName().getValue()); bridge.setController(Sets.newHashSet(controllerNamedUuid)); LOG.trace("Added controller : {} for bridge : {}", controller.getTargetColumn(), bridge.getName()); transaction.add(op.mutate(bridge) .addMutation(bridge.getControllerColumn().getSchema(), Mutator.INSERT, bridge.getControllerColumn().getData()) LOG.trace("Executed transaction: {}", transaction.build());
public static <T extends TableSchema<T>> void stampInstanceIdentifier(TransactionBuilder transaction, InstanceIdentifier<?> iid, TableSchema<T> tableSchema, ColumnSchema<T, Map<String,String>> columnSchema) { transaction.add(stampInstanceIdentifierMutation(transaction,iid, tableSchema,columnSchema)); }
public static List<Insert> extractInsert(TransactionBuilder transaction, GenericTableSchema schema) { List<Operation> operations = transaction.getOperations(); List<Insert> inserts = new ArrayList<>(); for (Operation operation : operations) { if (operation instanceof Insert && operation.getTableSchema().equals(schema)) { inserts.add((Insert) operation); } } return inserts; }
private void stampInstanceIdentifier(TransactionBuilder transaction,InstanceIdentifier<Node> iid) { OpenVSwitch ovs = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), OpenVSwitch.class); ovs.setExternalIds(Collections.<String,String>emptyMap()); TransactUtils.stampInstanceIdentifier(transaction, iid, ovs.getSchema(), ovs.getExternalIdsColumn().getSchema()); }
TableSchema<GenericTableSchema> tableSchema = dbSchema.table(tableName, GenericTableSchema.class); ColumnSchema<GenericTableSchema, UUID> _uuid = tableSchema.column("_uuid", UUID.class); transactionBuilder.add(op.update(tableSchema, row) .where(_uuid.opEqual(rowUuid)) .build()); ListenableFuture<List<OperationResult>> results = transactionBuilder.execute(); List<OperationResult> operationResults = results.get(); for (OperationResult result : operationResults) { if (operationResults.isEmpty() || (transactionBuilder.getOperations().size() != operationResults.size())) { throw new OvsdbPluginException("Failed to update row. Please check OVS logs for more info.");
Queue queue = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Queue.class); UUID namedUuid = new UUID(SouthboundConstants.QUEUE_NAMED_UUID_PREFIX + TransactUtils.bytesToHexString(queueEntry.getQueueId().getValue().getBytes())); transaction.add(op.insert(queue).withId(namedUuid.toString())).build(); LOG.info("Added queue Uuid : {} for Ovsdb Node : {}", namedUuid, operNode); UUID uuid = new UUID(operQueueUuid.getValue()); Queue extraQueue = TyperUtils.getTypedRowWrapper( transaction.getDatabaseSchema(), Queue.class, null); extraQueue.getUuidColumn().setData(uuid); transaction.add(op.update(queue) .where(extraQueue.getUuidColumn().getSchema().opEqual(uuid)).build()); LOG.info("Updated queue entries: {} for Ovsdb Node : {}", queue, operNode); transaction.build();
private void processInsertTransaction(OvsdbClient client, String databaseName, String childTable, String parentTable, UUID parentUuid, String parentColumn, String namedUuid, Row<GenericTableSchema> row, TransactionBuilder transactionBuilder) { // Insert the row as the first transaction entry DatabaseSchema dbSchema = client.getDatabaseSchema(databaseName); TableSchema<GenericTableSchema> childTableSchema = dbSchema.table(childTable, GenericTableSchema.class); transactionBuilder.add(op.insert(childTableSchema, row) .withId(namedUuid)); // Followed by the Mutation if (parentColumn != null) { TableSchema<GenericTableSchema> parentTableSchema = dbSchema.table(parentTable, GenericTableSchema.class); ColumnSchema<GenericTableSchema, UUID> parentColumnSchema = parentTableSchema.column(parentColumn, UUID.class); ColumnSchema<GenericTableSchema, UUID> _uuid = parentTableSchema.column("_uuid", UUID.class); transactionBuilder .add(op.mutate(parentTableSchema) .addMutation(parentColumnSchema, Mutator.INSERT, new UUID(namedUuid)) .where(_uuid.opEqual(parentUuid)) .build()); } }
private void handleSpecialInsertCase(OvsdbClient client, String databaseName, String tableName, String uuid, Row<GenericTableSchema> row, TransactionBuilder transactionBuilder) { Port port = client.getTypedRowWrapper(Port.class, null); if (databaseName.equals(OvsVswitchdSchemaConstants.DATABASE_NAME) && tableName.equals(port.getSchema().getName())) { port = client.getTypedRowWrapper(Port.class, row); DatabaseSchema dbSchema = client.getDatabaseSchema(databaseName); TableSchema<GenericTableSchema> tableSchema = dbSchema.table(tableName, GenericTableSchema.class); ColumnSchema<GenericTableSchema, Set<UUID>> columnSchema = tableSchema.multiValuedColumn("interfaces", UUID.class); String namedUuid = "Special_"+tableName; List<Operation> priorOperations = transactionBuilder.getOperations(); Insert portOperation = (Insert)priorOperations.get(0); portOperation.value(columnSchema, new UUID(namedUuid)); Column<GenericTableSchema, ?> nameColumn = port.getNameColumn(); List<Column<GenericTableSchema, ?>> columns = new ArrayList<Column<GenericTableSchema, ?>>(); columns.add(nameColumn); Row<GenericTableSchema> intfRow = new Row<GenericTableSchema>(tableSchema, columns); this.processTypedInsertTransaction(client, databaseName, "Interface", null, null, null, namedUuid, intfRow, transactionBuilder); } }
private void stampInstanceIdentifier(TransactionBuilder transaction,InstanceIdentifier<Node> iid) { OpenVSwitch ovs = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), OpenVSwitch.class); ovs.setExternalIds(Collections.<String,String>emptyMap()); TransactUtils.stampInstanceIdentifier(transaction, iid, ovs.getSchema(), ovs.getExternalIdsColumn().getSchema()); } }
private void execute(TransactionBuilder transaction, BridgeOperationalState state, Set<InstanceIdentifier<OvsdbBridgeAugmentation>> removed, Map<InstanceIdentifier<OvsdbBridgeAugmentation>, OvsdbBridgeAugmentation> originals) { for (InstanceIdentifier<OvsdbBridgeAugmentation> ovsdbManagedNodeIid: removed) { LOG.debug("Received request to delete ovsdb node : {}", ovsdbManagedNodeIid); OvsdbBridgeAugmentation original = originals.get(ovsdbManagedNodeIid); Bridge bridge = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Bridge.class,null); Optional<OvsdbBridgeAugmentation> ovsdbAugmentationOptional = state .getOvsdbBridgeAugmentation(ovsdbManagedNodeIid); if (ovsdbAugmentationOptional.isPresent() && ovsdbAugmentationOptional.get().getBridgeUuid() != null) { UUID bridgeUuid = new UUID(ovsdbAugmentationOptional.get().getBridgeUuid().getValue()); OpenVSwitch ovs = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), OpenVSwitch.class,null); transaction.add(op.delete(bridge.getSchema()) .where(bridge.getUuidColumn().getSchema().opEqual(bridgeUuid)).build()); transaction.add(op.comment("Bridge: Deleting " + original.getBridgeName())); transaction.add(op.mutate(ovs.getSchema()) .addMutation(ovs.getBridgesColumn().getSchema(), Mutator.DELETE, Sets.newHashSet(bridgeUuid))); transaction.add(op.comment("Open_vSwitch: Mutating " + original.getBridgeName() + " " + bridgeUuid)); LOG.info("Bridge Deleted: {}", ovsdbManagedNodeIid); } else { LOG.warn("Unable to delete bridge {} because it was not found in the operational store, " + "and thus we cannot retrieve its UUID", ovsdbManagedNodeIid); } } } }
private void invoke(TransactCommand command, TransactionBuilder tb) { ListenableFuture<List<OperationResult>> result = tb.execute(); LOG.debug("invoke: command: {}, tb: {}", command, tb); if (tb.getOperations().size() > 0) { try { if (!result.isCancelled()) { List<OperationResult> got = result.get(); LOG.debug("OVSDB transaction result: {}", got); } else { LOG.debug("Operation task cancelled for transaction : {}", tb); } } catch (InterruptedException | ExecutionException | CancellationException e) { LOG.warn("Transact execution exception: ", e); } LOG.trace("invoke exit command: {}, tb: {}", command, tb); } } }
Qos qos = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Qos.class); UUID namedUuid = new UUID(SouthboundConstants.QOS_NAMED_UUID_PREFIX + TransactUtils.bytesToHexString(qosEntry.getQosId().getValue().getBytes())); transaction.add(op.insert(qos).withId(namedUuid.toString())).build(); LOG.info("Added QoS Uuid: {} for node : {} ", namedUuid, operNode.getConnectionInfo()); } else { UUID uuid = new UUID(operQosUuid.getValue()); Qos extraQos = TyperUtils.getTypedRowWrapper( transaction.getDatabaseSchema(), Qos.class, null); extraQos.getUuidColumn().setData(uuid); transaction.add(op.update(qos) .where(extraQos.getUuidColumn().getSchema().opEqual(uuid)).build()); LOG.info("Updated QoS Uuid : {} for node : {} ", operQosUuid, operNode.getConnectionInfo()); transaction.build();
private void processDeleteTransaction(OvsdbClient client, String databaseName, String childTable, String parentTable, String parentColumn, String uuid, TransactionBuilder transactionBuilder) { DatabaseSchema dbSchema = client.getDatabaseSchema(databaseName); TableSchema<GenericTableSchema> childTableSchema = dbSchema.table(childTable, GenericTableSchema.class); if (parentColumn != null) { TableSchema<GenericTableSchema> parentTableSchema = dbSchema.table(parentTable, GenericTableSchema.class); ColumnSchema<GenericTableSchema, UUID> parentColumnSchema = parentTableSchema.column(parentColumn, UUID.class); transactionBuilder .add(op.mutate(parentTableSchema) .addMutation(parentColumnSchema, Mutator.DELETE, new UUID(uuid)) .where(parentColumnSchema.opIncludes(new UUID(uuid))) .build()); } ColumnSchema<GenericTableSchema, UUID> _uuid = childTableSchema.column("_uuid", UUID.class); transactionBuilder.add(op.delete(childTableSchema) .where(_uuid.opEqual(new UUID(uuid))) .build()); }
@Override public void invoke(TransactCommand command, BridgeOperationalState state, AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> events) { TransactionBuilder tb = new TransactionBuilder(connectionInstance.getOvsdbClient(), dbSchema); command.execute(tb, state, events); invoke(command, tb); }
private void execute(TransactionBuilder transaction, BridgeOperationalState state, Set<InstanceIdentifier<ControllerEntry>> removedControllers, Map<InstanceIdentifier<OvsdbBridgeAugmentation>, OvsdbBridgeAugmentation> modifiedBridges) { for (InstanceIdentifier<ControllerEntry> controllerIid : removedControllers) { LOG.debug("Removing Registered...ODL controller : {} ", controllerIid); InstanceIdentifier<OvsdbBridgeAugmentation> bridgeIid = controllerIid.firstIdentifierOf(OvsdbBridgeAugmentation.class); OvsdbBridgeAugmentation ovsdbBridge = modifiedBridges.get(bridgeIid); Optional<ControllerEntry> controllerEntryOptional = state.getControllerEntry(controllerIid); if (ovsdbBridge != null && controllerEntryOptional.isPresent()) { ControllerEntry controllerEntry = controllerEntryOptional.get(); Bridge bridge = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Bridge.class); bridge.setController(Sets.newHashSet(new UUID(controllerEntry.getControllerUuid().getValue()))); transaction.add(op.mutate(bridge).addMutation(bridge.getControllerColumn().getSchema(), Mutator.DELETE, bridge.getControllerColumn().getData())); } } }