Merge "Fix IT tests as per as API change in SFC"
[ovsdb.git] / hwvtepsouthbound / hwvtepsouthbound-impl / src / main / java / org / opendaylight / ovsdb / hwvtepsouthbound / transactions / md / PhysicalLocatorRemoveCommand.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 java.util.Map;
13
14 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
15 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
16 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
17 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundMapper;
18 import org.opendaylight.ovsdb.lib.message.TableUpdates;
19 import org.opendaylight.ovsdb.lib.notation.UUID;
20 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
21 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
22 import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalLocator;
23 import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalPort;
24 import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalSwitch;
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
26 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
27 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
28 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 public class PhysicalLocatorRemoveCommand extends AbstractTransactionCommand {
34
35     private static final Logger LOG = LoggerFactory.getLogger(PhysicalLocatorRemoveCommand.class);
36
37     public PhysicalLocatorRemoveCommand(HwvtepConnectionInstance key, TableUpdates updates,
38             DatabaseSchema dbSchema) {
39         super(key, updates, dbSchema);
40     }
41
42     @Override
43     public void execute(ReadWriteTransaction transaction) {
44         Collection<PhysicalLocator> deletedPLRows = TyperUtils.extractRowsRemoved(PhysicalLocator.class, getUpdates(),getDbSchema()).values();
45         if(deletedPLRows != null && !deletedPLRows.isEmpty()) {
46             for (PhysicalLocator pLoc : deletedPLRows) {
47                 final InstanceIdentifier<Node> connectionIId = getOvsdbConnectionInstance().getInstanceIdentifier();
48                 final InstanceIdentifier<TerminationPoint> nodePath = HwvtepSouthboundMapper
49                         .createInstanceIdentifier(connectionIId, pLoc);
50                 transaction.delete(LogicalDatastoreType.OPERATIONAL, nodePath);
51                 //TODO: Check if any cleanup is required
52             }
53         }
54     }
55
56 }