Merge "Remove incorrect or unnecessary relativePaths"
[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
9 package org.opendaylight.ovsdb.southbound.transactions.md;
10
11 import java.util.Collection;
12
13 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.ovsdb.lib.message.TableUpdates;
16 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
17 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
18 import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
19 import org.opendaylight.ovsdb.southbound.OvsdbConnectionInstance;
20 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeRef;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagedNodeEntry;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagedNodeEntryKey;
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 public class OvsdbBridgeRemovedCommand extends AbstractTransactionCommand {
31     private static final Logger LOG = LoggerFactory.getLogger(OvsdbBridgeRemovedCommand.class);
32
33     public OvsdbBridgeRemovedCommand(OvsdbConnectionInstance key, TableUpdates updates,
34             DatabaseSchema dbSchema) {
35         super(key,updates,dbSchema);
36     }
37
38     @Override
39     public void execute(ReadWriteTransaction transaction) {
40         Collection<Bridge> removedRows = TyperUtils.extractRowsRemoved(Bridge.class,
41                 getUpdates(), getDbSchema()).values();
42         for (Bridge bridge : removedRows) {
43             InstanceIdentifier<Node> bridgeIid = SouthboundMapper.createInstanceIdentifier(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 }