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 setPort(TransactionBuilder transaction, Bridge bridge, OvsdbBridgeAugmentation ovsdbManagedNode) { Insert<GenericTableSchema> interfaceInsert = setInterface(transaction,ovsdbManagedNode); // Port part String portNamedUuid = "Port_" + SouthboundMapper.getRandomUuid(); Port port = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Port.class); port.setName(ovsdbManagedNode.getBridgeName().getValue()); port.setInterfaces(Sets.newHashSet(TransactUtils.extractNamedUuid(interfaceInsert))); transaction.add(op.insert(port).withId(portNamedUuid)); bridge.setPorts(Sets.newHashSet(new UUID(portNamedUuid))); }
String controllerNamedUuidString = SouthboundMapper.getRandomUuid(); UUID controllerNamedUuid = new UUID(controllerNamedUuidString); transaction.add(op.insert(controller).withId(controllerNamedUuidString)); LOG.trace("Added controller : {} for bridge : {}", controller.getTargetColumn(), bridge.getName()); transaction.add(op.mutate(bridge) .addMutation(bridge.getControllerColumn().getSchema(), Mutator.INSERT, bridge.getControllerColumn().getData())
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); 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 : {}",
public static <T extends TableSchema<T>> Mutate<T> stampInstanceIdentifierMutation(TransactionBuilder transaction, InstanceIdentifier<?> iid, TableSchema<T> tableSchema, ColumnSchema<T, Map<String,String>> columnSchema) { Map<String,String> externalIdsMap = ImmutableMap.of(SouthboundConstants.IID_EXTERNAL_ID_KEY, SouthboundUtil.serializeInstanceIdentifier(iid)); Mutate<T> mutate = op.mutate(tableSchema) .addMutation(columnSchema, Mutator.INSERT, externalIdsMap); Mutation deleteIidMutation = new Mutation(columnSchema.getName(), Mutator.DELETE, OvsdbSet.fromSet(Sets.newHashSet(SouthboundConstants.IID_EXTERNAL_ID_KEY))); List<Mutation> mutations = Lists.newArrayList(Sets.newHashSet(deleteIidMutation)); mutations.addAll(mutate.getMutations()); mutate.setMutations(mutations); return mutate; }
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()); }
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());
Qos qos = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Qos.class, null); transaction.add(op.delete(qos.getSchema()) .where(qos.getUuidColumn().getSchema().opEqual(new UUID(qosUuid.getValue()))) .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()); } }
setName(bridge, ovsdbManagedNode,operationalBridgeOptional); setPort(transaction, bridge, ovsdbManagedNode); transaction.add(op.insert(bridge)); LOG.info("Added ovsdb Bridge name: {} uuid: {}", ovsdbManagedNode.getBridgeName(), transaction.add(op.update(bridge) .where(extraBridge.getNameColumn().getSchema().opEqual(existingBridgeName)) .build());
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())); } } }
transaction.getDatabaseSchema(), Interface.class); extraInterface.setName(""); transaction.add(op.update(ovsInterface) .where(extraInterface.getNameColumn().getSchema().opEqual(terminationPoint.getName())) .build()); transaction.getDatabaseSchema(), Port.class); extraPort.setName(""); transaction.add(op.update(port) .where(extraPort.getNameColumn().getSchema().opEqual(terminationPoint.getName())) .build());
TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Queue.class, null); transaction.add(op.delete(queue.getSchema()) .where(queue.getUuidColumn().getSchema().opEqual( new UUID(queueUuid.getValue())))
Bridge.class,null); transaction.add(op.delete(port.getSchema()) .where(port.getUuidColumn().getSchema().opEqual(portUuid)).build()); transaction.add(op.comment("Port: Deleting " + original.getName() + " attached to " + bridgeName)); transaction.add(op.mutate(bridge.getSchema()) .addMutation(bridge.getPortsColumn().getSchema(), Mutator.DELETE, Sets.newHashSet(portUuid)) .where(bridge.getNameColumn().getSchema().opEqual(bridgeName)).build()); transaction.add(op.comment("Bridge: Mutating " + bridgeName + " to remove port " + portUuid)); LOG.info("Deleted Termination Point : {} with uuid : {}",
TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Interface.class); createInterface(terminationPoint, ovsInterface); transaction.add(op.insert(ovsInterface).withId(interfaceUuid)); Port port = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Port.class); createPort(terminationPoint, port, interfaceUuid); transaction.add(op.insert(port).withId(portUuid)); LOG.info("Created Termination Point : {} with Uuid : {}", terminationPoint.getName(), bridge.setPorts(Sets.newHashSet(new UUID(portUuid))); transaction.add(op.mutate(bridge) .addMutation(bridge.getPortsColumn().getSchema(), Mutator.INSERT, bridge.getPortsColumn().getData())
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 { 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());
private void execute(TransactionBuilder transaction, BridgeOperationalState state, Set<InstanceIdentifier<ProtocolEntry>> removed, Map<InstanceIdentifier<OvsdbBridgeAugmentation>, OvsdbBridgeAugmentation> updatedBridges) { for (InstanceIdentifier<ProtocolEntry> protocolIid : removed) { InstanceIdentifier<OvsdbBridgeAugmentation> bridgeIid = protocolIid.firstIdentifierOf(OvsdbBridgeAugmentation.class); OvsdbBridgeAugmentation ovsdbBridge = updatedBridges.get(bridgeIid); Optional<ProtocolEntry> protocolEntryOptional = state.getProtocolEntry(protocolIid); if (ovsdbBridge != null && protocolEntryOptional.isPresent()) { ProtocolEntry protocolEntry = protocolEntryOptional.get(); if (protocolEntry != null && protocolEntry.getProtocol() != null) { Bridge bridge = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Bridge.class); String protocolString = SouthboundConstants.OVSDB_PROTOCOL_MAP.get(protocolEntry.getProtocol()); if (protocolString != null) { bridge.setProtocols(Sets.newHashSet(protocolString)); try { transaction.add(op.mutate(bridge).addMutation(bridge.getProtocolsColumn().getSchema(), Mutator.DELETE,bridge.getProtocolsColumn().getData())); LOG.info("Removed ProtocolEntry : {} for OVSDB Bridge : {} ", protocolString, bridge.getName()); } catch (SchemaVersionMismatchException e) { schemaMismatchLog("protocols", "Bridge", e); } } } } } }
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()));
private void deleteAutoAttach(TransactionBuilder transaction, InstanceIdentifier<OvsdbNodeAugmentation> ovsdbNodeIid, Uuid autoattachUuid) { LOG.debug("Received request to delete Autoattach entry {}", autoattachUuid); final OvsdbBridgeAugmentation bridgeAugmentation = getBridge(ovsdbNodeIid, autoattachUuid); if (autoattachUuid != null && bridgeAugmentation != null) { final UUID uuid = new UUID(autoattachUuid.getValue()); final AutoAttach autoattach = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), AutoAttach.class, null); transaction.add(op.delete(autoattach.getSchema()) .where(autoattach.getUuidColumn().getSchema().opEqual(uuid)) .build()); transaction.add(op.comment("AutoAttach: Deleting {} " + uuid + " attached to " + bridgeAugmentation.getBridgeName().getValue())); final Bridge bridge = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Bridge.class,null); transaction.add(op.mutate(bridge.getSchema()) .addMutation(bridge.getAutoAttachColumn().getSchema(), Mutator.DELETE, Sets.newHashSet(uuid)) .where(bridge.getNameColumn().getSchema() .opEqual(bridgeAugmentation.getBridgeName().getValue())).build()); transaction.add(op.comment("Bridge: Mutating " + bridgeAugmentation.getBridgeName().getValue() + " to remove autoattach column " + uuid)); } else { LOG.debug("Unable to delete AutoAttach {} for node {} because it was not found in the operational store, " + "and thus we cannot retrieve its UUID", autoattachUuid, ovsdbNodeIid); } }