4b59ab9e7d19e93909db8aaca3a961a6e043971b
[ovsdb.git] / hwvtepsouthbound / hwvtepsouthbound-impl / src / main / java / org / opendaylight / ovsdb / hwvtepsouthbound / transactions / md / HwvtepPhysicalLocatorRemoveCommand.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 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.PhysicalLocator;
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23
24 public class HwvtepPhysicalLocatorRemoveCommand extends AbstractTransactionCommand {
25
26     public HwvtepPhysicalLocatorRemoveCommand(HwvtepConnectionInstance key, TableUpdates updates,
27             DatabaseSchema dbSchema) {
28         super(key, updates, dbSchema);
29     }
30
31     @Override
32     public void execute(ReadWriteTransaction transaction) {
33         Collection<PhysicalLocator> deletedPLRows =
34                 TyperUtils.extractRowsRemoved(PhysicalLocator.class, getUpdates(), getDbSchema()).values();
35         for (PhysicalLocator locator : deletedPLRows) {
36             final InstanceIdentifier<Node> connectionIId = getOvsdbConnectionInstance().getInstanceIdentifier();
37             final InstanceIdentifier<TerminationPoint> nodePath = HwvtepSouthboundMapper
38                     .createInstanceIdentifier(connectionIId, locator);
39             transaction.delete(LogicalDatastoreType.OPERATIONAL, nodePath);
40             getOvsdbConnectionInstance().getDeviceInfo().clearDeviceOperData(TerminationPoint.class, nodePath);
41
42             //TODO: Check if any cleanup is required
43         }
44     }
45 }