Bump versions by x.(y+1).z
[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.mdsal.binding.api.ReadWriteTransaction;
13 import org.opendaylight.mdsal.common.api.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.ovsdb.utils.mdsal.utils.TransactionType;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalSwitchRef;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Switches;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.SwitchesKey;
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 HwvtepPhysicalSwitchRemoveCommand extends AbstractTransactionCommand {
31
32     private static final Logger LOG = LoggerFactory.getLogger(HwvtepPhysicalSwitchRemoveCommand.class);
33
34     public HwvtepPhysicalSwitchRemoveCommand(HwvtepConnectionInstance key, TableUpdates updates,
35             DatabaseSchema dbSchema) {
36         super(key, updates, dbSchema);
37     }
38
39     @Override
40     public void execute(ReadWriteTransaction transaction) {
41         Collection<PhysicalSwitch> deletedPSRows =
42                 TyperUtils.extractRowsRemoved(PhysicalSwitch.class, getUpdates(), getDbSchema()).values();
43         for (PhysicalSwitch phySwitch : deletedPSRows) {
44             InstanceIdentifier<Node> nodeIid = HwvtepSouthboundMapper.createInstanceIdentifier(
45                     getOvsdbConnectionInstance(), phySwitch);
46             InstanceIdentifier<Switches> switchIid = getOvsdbConnectionInstance().getInstanceIdentifier()
47                     .augmentation(HwvtepGlobalAugmentation.class)
48                     .child(Switches.class, new SwitchesKey(new HwvtepPhysicalSwitchRef(nodeIid)));
49             // TODO handle removal of reference to managed switch from model
50             transaction.delete(LogicalDatastoreType.OPERATIONAL, nodeIid);
51             transaction.delete(LogicalDatastoreType.OPERATIONAL, switchIid);
52             getDeviceInfo().clearDeviceOperData(Node.class, switchIid);
53             addToDeviceUpdate(TransactionType.DELETE, phySwitch);
54             LOG.info("DEVICE - {} {}", TransactionType.DELETE, phySwitch);
55         }
56     }
57 }