d1b682d9b3f938fdaec4e92b1bd6195c138bf684
[ovsdb.git] / hwvtepsouthbound / hwvtepsouthbound-impl / src / main / java / org / opendaylight / ovsdb / hwvtepsouthbound / transactions / md / HwvtepPhysicalSwitchRemoveCommand.java
1 /*
2  * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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.hwvtepsouthbound.transactions.md;
10
11 import java.util.Collection;
12 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
13 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
15 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundMapper;
16 import org.opendaylight.ovsdb.lib.message.TableUpdates;
17 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
18 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
19 import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalSwitch;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalSwitchRef;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Switches;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.SwitchesKey;
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 HwvtepPhysicalSwitchRemoveCommand extends AbstractTransactionCommand {
28
29     public HwvtepPhysicalSwitchRemoveCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
30         super(key, updates, dbSchema);
31     }
32
33     @Override
34     public void execute(ReadWriteTransaction transaction) {
35         Collection<PhysicalSwitch> deletedPSRows =
36                 TyperUtils.extractRowsRemoved(PhysicalSwitch.class, getUpdates(), getDbSchema()).values();
37         for (PhysicalSwitch pSwitch : deletedPSRows) {
38             InstanceIdentifier<Node> nodeIid = HwvtepSouthboundMapper.createInstanceIdentifier(
39                     getOvsdbConnectionInstance(), pSwitch);
40             InstanceIdentifier<Switches> switchIid = getOvsdbConnectionInstance().getInstanceIdentifier()
41                     .augmentation(HwvtepGlobalAugmentation.class)
42                     .child(Switches.class, new SwitchesKey(new HwvtepPhysicalSwitchRef(nodeIid)));
43             // TODO handle removal of reference to managed switch from model
44             transaction.delete(LogicalDatastoreType.OPERATIONAL, nodeIid);
45             transaction.delete(LogicalDatastoreType.OPERATIONAL, switchIid);
46             getOvsdbConnectionInstance().getDeviceInfo().removePhysicalSwitch(pSwitch.getUuid());
47         }
48     }
49
50 }