--- /dev/null
+package org.opendaylight.ovsdb.southbound.transactions.md;
+
+import org.opendaylight.ovsdb.lib.message.TableUpdates;
+import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
+import org.opendaylight.ovsdb.southbound.OvsdbClientKey;
+
+public abstract class AbstractTransactionCommand implements TransactionCommand {
+
+ private TableUpdates updates;
+ private DatabaseSchema dbSchema;
+ private OvsdbClientKey key;
+
+ public TableUpdates getUpdates() {
+ return updates;
+ }
+
+ public DatabaseSchema getDbSchema() {
+ return dbSchema;
+ }
+
+ public OvsdbClientKey getKey() {
+ return key;
+ }
+
+ protected AbstractTransactionCommand() {
+ // NO OP
+ }
+
+ public AbstractTransactionCommand(OvsdbClientKey key,TableUpdates updates, DatabaseSchema dbSchema) {
+ this.updates = updates;
+ this.dbSchema = dbSchema;
+ this.key = key;
+ }
+
+}
\ No newline at end of file
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class OvsdbBridgeRemovedCommand implements TransactionCommand {
+public class OvsdbBridgeRemovedCommand extends AbstractTransactionCommand {
private static final Logger LOG = LoggerFactory.getLogger(OvsdbBridgeUpdateCommand.class);
- private TableUpdates updates;
- private DatabaseSchema dbSchema;
-
- private OvsdbClientKey key;
-
- public OvsdbBridgeRemovedCommand(OvsdbClientKey key,TableUpdates updates, DatabaseSchema dbSchema) {
- this.updates = updates;
- this.dbSchema = dbSchema;
- this.key = key;
+ public OvsdbBridgeRemovedCommand(OvsdbClientKey key, TableUpdates updates,
+ DatabaseSchema dbSchema) {
+ super(key,updates,dbSchema);
}
+
@Override
public void execute(ReadWriteTransaction transaction) {
- List<TypedBaseTable<?>> removedRows = TransactionUtils.extractRowsRemoved(Bridge.class, updates, dbSchema);
+ List<TypedBaseTable<?>> removedRows = TransactionUtils.extractRowsRemoved(Bridge.class, getUpdates(), getDbSchema());
for(TypedBaseTable<?> removedRow : removedRows) {
if(removedRow instanceof Bridge) {
Bridge bridge = (Bridge)removedRow;
- InstanceIdentifier<Node> bridgeIid = SouthboundMapper.createInstanceIdentifier(key, bridge.getUuid());
- InstanceIdentifier<ManagedNodeEntry> mnIid = SouthboundMapper.createInstanceIndentifier(key)
+ InstanceIdentifier<Node> bridgeIid = SouthboundMapper.createInstanceIdentifier(getKey(), bridge.getUuid());
+ InstanceIdentifier<ManagedNodeEntry> mnIid = SouthboundMapper.createInstanceIndentifier(getKey())
.augmentation(OvsdbNodeAugmentation.class)
.child(ManagedNodeEntry.class, new ManagedNodeEntryKey(new OvsdbBridgeRef(bridgeIid)));
// TODO handle removal of reference to managed node from model
import com.google.common.base.Optional;
-public class OvsdbBridgeUpdateCommand implements TransactionCommand {
+public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
private static final Logger LOG = LoggerFactory.getLogger(OvsdbBridgeUpdateCommand.class);
- private TableUpdates updates;
- private DatabaseSchema dbSchema;
-
- private OvsdbClientKey key;
-
- public OvsdbBridgeUpdateCommand(OvsdbClientKey key,TableUpdates updates, DatabaseSchema dbSchema) {
- this.updates = updates;
- this.dbSchema = dbSchema;
- this.key = key;
+ public OvsdbBridgeUpdateCommand(OvsdbClientKey key, TableUpdates updates,
+ DatabaseSchema dbSchema) {
+ super(key,updates,dbSchema);
}
+
@Override
public void execute(ReadWriteTransaction transaction) {
- List<TypedBaseTable<?>> updatedRows = TransactionUtils.extractRowsUpdated(Bridge.class, updates, dbSchema);
+ List<TypedBaseTable<?>> updatedRows = TransactionUtils.extractRowsUpdated(Bridge.class, getUpdates(), getDbSchema());
for(TypedBaseTable<?> updatedRow : updatedRows) {
if(updatedRow instanceof Bridge) {
Bridge bridge = (Bridge)updatedRow;
- final InstanceIdentifier<Node> nodePath = key.toInstanceIndentifier();
+ final InstanceIdentifier<Node> nodePath = getKey().toInstanceIndentifier();
Optional<Node> node = Optional.absent();
try{
node = transaction.read(LogicalDatastoreType.OPERATIONAL, nodePath).checkedGet();
if(node.isPresent()){
LOG.info("Node {} is present",node);
NodeBuilder managedNodeBuilder = new NodeBuilder();
- NodeId manageNodeId = SouthboundMapper.createManagedNodeId(key, bridge.getUuid());
+ NodeId manageNodeId = SouthboundMapper.createManagedNodeId(getKey(), bridge.getUuid());
managedNodeBuilder.setNodeId(manageNodeId);
OvsdbManagedNodeAugmentationBuilder ovsdbManagedNodeBuilder = new OvsdbManagedNodeAugmentationBuilder();
//Update node with managed node reference
NodeBuilder nodeBuilder = new NodeBuilder();
- nodeBuilder.setNodeId(SouthboundMapper.createNodeId(key.getIp(),key.getPort()));
+ nodeBuilder.setNodeId(SouthboundMapper.createNodeId(getKey().getIp(),getKey().getPort()));
OvsdbNodeAugmentationBuilder ovsdbNodeBuilder = new OvsdbNodeAugmentationBuilder();
List<ManagedNodeEntry> managedNodes = new ArrayList<ManagedNodeEntry>();
import org.opendaylight.ovsdb.southbound.OvsdbClientKey;
import org.opendaylight.ovsdb.southbound.SouthboundMapper;
-public class OvsdbNodeCreateCommand implements TransactionCommand {
-
- private OvsdbClientKey key;
+public class OvsdbNodeCreateCommand extends AbstractTransactionCommand {
public OvsdbNodeCreateCommand(OvsdbClientKey key,TableUpdates updates,DatabaseSchema dbSchema) {
- this.key = key;
+ super(key,updates,dbSchema);
}
@Override
public void execute(ReadWriteTransaction transaction) {
- transaction.put(LogicalDatastoreType.OPERATIONAL, key.toInstanceIndentifier(),
- SouthboundMapper.createNode(key));
+ transaction.put(LogicalDatastoreType.OPERATIONAL, getKey().toInstanceIndentifier(),
+ SouthboundMapper.createNode(getKey()));
}
}
import org.opendaylight.ovsdb.lib.message.TableUpdates;
import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
import org.opendaylight.ovsdb.southbound.OvsdbClientKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeRef;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagedNodeEntry;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import com.google.common.base.Optional;
import com.google.common.util.concurrent.CheckedFuture;
-public class OvsdbNodeRemoveCommand implements TransactionCommand {
+public class OvsdbNodeRemoveCommand extends AbstractTransactionCommand {
private static final Logger LOG = LoggerFactory.getLogger(OvsdbNodeRemoveCommand.class);
- private OvsdbClientKey key;
-
public OvsdbNodeRemoveCommand(OvsdbClientKey key,TableUpdates updates,DatabaseSchema dbSchema) {
- this.key = key;
+ super(key,updates,dbSchema);
}
@Override
public void execute(ReadWriteTransaction transaction) {
- CheckedFuture<Optional<Node>, ReadFailedException> ovsdbNodeFuture = transaction.read(LogicalDatastoreType.OPERATIONAL, key.toInstanceIndentifier());
+ CheckedFuture<Optional<Node>, ReadFailedException> ovsdbNodeFuture = transaction.read(LogicalDatastoreType.OPERATIONAL, getKey().toInstanceIndentifier());
Optional<Node> ovsdbNodeOptional;
try {
ovsdbNodeOptional = ovsdbNodeFuture.get();
for(ManagedNodeEntry managedNode: ovsdbNodeAugmentation.getManagedNodeEntry()) {
transaction.delete(LogicalDatastoreType.OPERATIONAL, managedNode.getBridgeRef().getValue());
}
- transaction.delete(LogicalDatastoreType.OPERATIONAL, key.toInstanceIndentifier());
+ transaction.delete(LogicalDatastoreType.OPERATIONAL, getKey().toInstanceIndentifier());
}
} catch (Exception e) {
LOG.warn("Failure to delete ovsdbNode {}",e);