Bump versions by x.(y+1).z
[ovsdb.git] / southbound / southbound-impl / src / main / java / org / opendaylight / ovsdb / southbound / transactions / md / OvsdbBridgeRemovedCommand.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.ovsdb.southbound.transactions.md;
9
10 import java.util.Collection;
11 import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
12 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
13 import org.opendaylight.ovsdb.lib.message.TableUpdates;
14 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
15 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
16 import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
17 import org.opendaylight.ovsdb.southbound.InstanceIdentifierCodec;
18 import org.opendaylight.ovsdb.southbound.OvsdbConnectionInstance;
19 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeRef;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagedNodeEntry;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagedNodeEntryKey;
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26
27 public class OvsdbBridgeRemovedCommand extends AbstractTransactionCommand {
28
29     private final InstanceIdentifierCodec instanceIdentifierCodec;
30
31     public OvsdbBridgeRemovedCommand(InstanceIdentifierCodec instanceIdentifierCodec, OvsdbConnectionInstance key,
32             TableUpdates updates, DatabaseSchema dbSchema) {
33         super(key,updates,dbSchema);
34         this.instanceIdentifierCodec = instanceIdentifierCodec;
35     }
36
37     @Override
38     public void execute(ReadWriteTransaction transaction) {
39         Collection<Bridge> removedRows = TyperUtils.extractRowsRemoved(Bridge.class,
40                 getUpdates(), getDbSchema()).values();
41         for (Bridge bridge : removedRows) {
42             InstanceIdentifier<Node> bridgeIid =
43                     SouthboundMapper.createInstanceIdentifier(instanceIdentifierCodec, getOvsdbConnectionInstance(),
44                             bridge);
45             InstanceIdentifier<ManagedNodeEntry> mnIid = getOvsdbConnectionInstance().getInstanceIdentifier()
46                     .augmentation(OvsdbNodeAugmentation.class)
47                     .child(ManagedNodeEntry.class, new ManagedNodeEntryKey(new OvsdbBridgeRef(bridgeIid)));
48             // TODO handle removal of reference to managed node from model
49             transaction.delete(LogicalDatastoreType.OPERATIONAL, bridgeIid);
50             transaction.delete(LogicalDatastoreType.OPERATIONAL, mnIid);
51         }
52     }
53
54 }