f4dcab33eb182abc3173bf442d673d0b7d58e53b
[ovsdb.git] / hwvtepsouthbound / hwvtepsouthbound-impl / src / main / java / org / opendaylight / ovsdb / hwvtepsouthbound / transactions / md / HwvtepLogicalSwitchRemoveCommand.java
1 /*
2  * Copyright (c) 2015, 2017 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
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.hwvtepsouthbound.HwvtepConnectionInstance;
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.LogicalSwitch;
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.HwvtepNodeName;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitchesKey;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25
26 public class HwvtepLogicalSwitchRemoveCommand extends AbstractTransactionCommand<LogicalSwitches> {
27
28     public HwvtepLogicalSwitchRemoveCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
29         super(key, updates, dbSchema);
30     }
31
32     @Override
33     public void execute(ReadWriteTransaction transaction) {
34         Collection<LogicalSwitch> deletedLSRows =
35                 TyperUtils.extractRowsRemoved(LogicalSwitch.class, getUpdates(), getDbSchema()).values();
36         for (LogicalSwitch lSwitch : deletedLSRows) {
37             InstanceIdentifier<LogicalSwitches> switchIid = getOvsdbConnectionInstance().getInstanceIdentifier()
38                     .augmentation(HwvtepGlobalAugmentation.class)
39                     .child(LogicalSwitches.class, new LogicalSwitchesKey(new HwvtepNodeName(lSwitch.getName())));
40             // TODO Delete any references
41             transaction.delete(LogicalDatastoreType.OPERATIONAL, switchIid);
42             getOvsdbConnectionInstance().getDeviceInfo().clearDeviceOperData(LogicalSwitches.class, switchIid);
43         }
44     }
45
46 }