2 * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
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
9 package org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md;
11 import java.util.Collection;
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.PhysicalPort;
23 import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalSwitch;
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
26 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 public class HwvtepPhysicalPortRemoveCommand extends AbstractTransactionCommand {
33 private static final Logger LOG = LoggerFactory.getLogger(HwvtepPhysicalPortRemoveCommand.class);
35 public HwvtepPhysicalPortRemoveCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
36 super(key, updates, dbSchema);
40 public void execute(ReadWriteTransaction transaction) {
41 Collection<PhysicalPort> deletedPortRows =
42 TyperUtils.extractRowsRemoved(PhysicalPort.class, getUpdates(), getDbSchema()).values();
43 Map<UUID, PhysicalSwitch> updatedPSRows =
44 TyperUtils.extractRowsUpdated(PhysicalSwitch.class, getUpdates(), getDbSchema());
45 Map<UUID, PhysicalSwitch> oldPSRows =
46 TyperUtils.extractRowsOld(PhysicalSwitch.class, getUpdates(), getDbSchema());
47 for (PhysicalPort pPort : deletedPortRows) {
48 PhysicalSwitch updatedPSwitchData = null;
49 for (Map.Entry<UUID, PhysicalSwitch> updatedEntry : updatedPSRows.entrySet()) {
50 UUID pSwitchUUID = updatedEntry.getKey();
51 PhysicalSwitch oldPSwitchData = oldPSRows.get(pSwitchUUID);
52 if (oldPSwitchData.getPortsColumn() != null
53 && oldPSwitchData.getPortsColumn().getData().contains(pPort.getUuidColumn().getData())
54 && (!updatedPSRows.isEmpty())) {
55 updatedPSwitchData = updatedEntry.getValue();
59 if (updatedPSwitchData == null) {
60 LOG.warn("PhysicalSwitch not found for port {}", pPort);
62 String portName = pPort.getName();
63 final InstanceIdentifier<TerminationPoint> nodePath =
64 HwvtepSouthboundMapper.createInstanceIdentifier(getOvsdbConnectionInstance(),
65 updatedPSwitchData).child(TerminationPoint.class,
66 new TerminationPointKey(new TpId(portName)));
67 transaction.delete(LogicalDatastoreType.OPERATIONAL, nodePath);
68 getDeviceInfo().clearDeviceOperData(TerminationPoint.class, nodePath);