78872c8d45ea2c9f6d60b5aac961b7e89625b38c
[ovsdb.git] / hwvtepsouthbound / hwvtepsouthbound-impl / src / main / java / org / opendaylight / ovsdb / hwvtepsouthbound / transactions / md / HwvtepPhysicalLocatorRemoveCommand.java
1 /*
2  * Copyright (c) 2015 - 2016 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.hwvtepsouthbound.HwvtepSouthboundMapper;
17 import org.opendaylight.ovsdb.lib.message.TableUpdates;
18 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
19 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
20 import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalLocator;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
22 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24
25 public class HwvtepPhysicalLocatorRemoveCommand extends AbstractTransactionCommand {
26
27     public HwvtepPhysicalLocatorRemoveCommand(HwvtepConnectionInstance key, TableUpdates updates, 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 pLoc : deletedPLRows) {
36             final InstanceIdentifier<Node> connectionIId = getOvsdbConnectionInstance().getInstanceIdentifier();
37             final InstanceIdentifier<TerminationPoint> nodePath = HwvtepSouthboundMapper
38                     .createInstanceIdentifier(connectionIId, pLoc);
39             transaction.delete(LogicalDatastoreType.OPERATIONAL, nodePath);
40             getOvsdbConnectionInstance().getDeviceInfo().removePhysicalLocator(pLoc.getUuid());
41             //TODO: Check if any cleanup is required
42         }
43     }
44
45 }