MD-SAL API integration
[ovsdb.git] / southbound / southbound-impl / src / main / java / org / opendaylight / ovsdb / southbound / transactions / md / OvsdbBridgeRemovedCommand.java
index cdf383dff95451831b38f9502ee1b7aa215d638a..410f4815f44ca9f32cda449107ac5aa13f3e2800 100644 (file)
@@ -1,14 +1,23 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
 package org.opendaylight.ovsdb.southbound.transactions.md;
 
-import java.util.List;
+import java.util.Collection;
 
-import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.ovsdb.lib.message.TableUpdates;
 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
-import org.opendaylight.ovsdb.lib.schema.typed.TypedBaseTable;
+import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
 import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
-import org.opendaylight.ovsdb.southbound.OvsdbClientKey;
+import org.opendaylight.ovsdb.southbound.InstanceIdentifierCodec;
+import org.opendaylight.ovsdb.southbound.OvsdbConnectionInstance;
 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
 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;
@@ -16,36 +25,31 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.re
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagedNodeEntryKey;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class OvsdbBridgeRemovedCommand implements TransactionCommand {
-    private static final Logger LOG = LoggerFactory.getLogger(OvsdbBridgeUpdateCommand.class);
 
-    private TableUpdates updates;
-    private DatabaseSchema dbSchema;
+public class OvsdbBridgeRemovedCommand extends AbstractTransactionCommand {
 
-    private OvsdbClientKey key;
+    private final InstanceIdentifierCodec instanceIdentifierCodec;
 
-    public OvsdbBridgeRemovedCommand(OvsdbClientKey key,TableUpdates updates, DatabaseSchema dbSchema) {
-        this.updates = updates;
-        this.dbSchema = dbSchema;
-        this.key = key;
+    public OvsdbBridgeRemovedCommand(InstanceIdentifierCodec instanceIdentifierCodec, OvsdbConnectionInstance key,
+            TableUpdates updates, DatabaseSchema dbSchema) {
+        super(key,updates,dbSchema);
+        this.instanceIdentifierCodec = instanceIdentifierCodec;
     }
+
     @Override
     public void execute(ReadWriteTransaction transaction) {
-        List<TypedBaseTable<?>> removedRows = TransactionUtils.extractRowsRemoved(Bridge.class, updates, dbSchema);
-        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)
-                        .augmentation(OvsdbNodeAugmentation.class)
-                        .child(ManagedNodeEntry.class, new ManagedNodeEntryKey(new OvsdbBridgeRef(bridgeIid)));
-                // TODO handle removal of reference to managed node from model
-                transaction.delete(LogicalDatastoreType.OPERATIONAL, bridgeIid);
-                transaction.delete(LogicalDatastoreType.OPERATIONAL, mnIid);
-            }
+        Collection<Bridge> removedRows = TyperUtils.extractRowsRemoved(Bridge.class,
+                getUpdates(), getDbSchema()).values();
+        for (Bridge bridge : removedRows) {
+            InstanceIdentifier<Node> bridgeIid =
+                    SouthboundMapper.createInstanceIdentifier(instanceIdentifierCodec, getOvsdbConnectionInstance(),
+                            bridge);
+            InstanceIdentifier<ManagedNodeEntry> mnIid = getOvsdbConnectionInstance().getInstanceIdentifier()
+                    .augmentation(OvsdbNodeAugmentation.class)
+                    .child(ManagedNodeEntry.class, new ManagedNodeEntryKey(new OvsdbBridgeRef(bridgeIid)));
+            // TODO handle removal of reference to managed node from model
+            transaction.delete(LogicalDatastoreType.OPERATIONAL, bridgeIid);
+            transaction.delete(LogicalDatastoreType.OPERATIONAL, mnIid);
         }
     }