2 * Copyright (c) 2016 Intel Communications Systems, Inc. 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.southbound.transactions.md;
11 import com.google.common.base.Optional;
12 import java.util.ArrayList;
13 import java.util.Iterator;
14 import java.util.List;
16 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
17 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
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.openvswitch.OpenVSwitch;
23 import org.opendaylight.ovsdb.schema.openvswitch.Qos;
24 import org.opendaylight.ovsdb.southbound.OvsdbConnectionInstance;
25 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
26 import org.opendaylight.ovsdb.southbound.SouthboundUtil;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QosEntries;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QosEntriesKey;
31 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
32 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 public class OvsdbQosRemovedCommand extends AbstractTransactionCommand {
37 private static final Logger LOG = LoggerFactory.getLogger(OvsdbQueueUpdateCommand.class);
39 private Map<UUID, Qos> removedQosRows;
40 private Map<UUID, OpenVSwitch> updatedOpenVSwitchRows;
42 public OvsdbQosRemovedCommand(OvsdbConnectionInstance key,
43 TableUpdates updates, DatabaseSchema dbSchema) {
44 super(key, updates, dbSchema);
45 updatedOpenVSwitchRows = TyperUtils.extractRowsUpdated(OpenVSwitch.class, getUpdates(), getDbSchema());
46 removedQosRows = TyperUtils.extractRowsRemoved(Qos.class, getUpdates(), getDbSchema());
50 public void execute(ReadWriteTransaction transaction) {
51 final InstanceIdentifier<Node> nodeIId = getOvsdbConnectionInstance().getInstanceIdentifier();
52 final Optional<Node> ovsdbNode = SouthboundUtil.readNode(transaction, nodeIId);
53 if (ovsdbNode.isPresent()) {
54 List<InstanceIdentifier<QosEntries>> result = new ArrayList<>();
55 InstanceIdentifier<Node> ovsdbNodeIid =
56 SouthboundMapper.createInstanceIdentifier(getOvsdbConnectionInstance().getNodeId());
57 if (removedQosRows != null && !removedQosRows.isEmpty()) {
58 for (UUID qosUuid : removedQosRows.keySet()) {
59 QosEntriesKey qosKey = getQosEntriesKey(ovsdbNode.get(), qosUuid);
61 InstanceIdentifier<QosEntries> iid = ovsdbNodeIid
62 .augmentation(OvsdbNodeAugmentation.class)
63 .child(QosEntries.class, qosKey);
68 deleteQos(transaction, result);
72 private QosEntriesKey getQosEntriesKey(Node node, UUID qosUuid) {
73 List<QosEntries> qosList = node.getAugmentation(OvsdbNodeAugmentation.class).getQosEntries();
74 if (qosList == null || qosList.isEmpty()) {
75 LOG.debug("Deleting Qos {}, Ovsdb Node {} does not have a Qos list.", qosUuid.toString(), node);
78 Iterator<QosEntries> itr = qosList.iterator();
79 Uuid quUuid = new Uuid(qosUuid.toString());
80 while (itr.hasNext()) {
81 QosEntries qos = itr.next();
82 if (qos.getQosUuid().equals(quUuid)) {
86 LOG.debug("Deleted Queue {} not found in Ovsdb Node {}", qosUuid.toString(), node);
90 private void deleteQos(ReadWriteTransaction transaction,
91 List<InstanceIdentifier<QosEntries>> qosEntryIids) {
92 for (InstanceIdentifier<QosEntries> qosEntryIid: qosEntryIids) {
93 transaction.delete(LogicalDatastoreType.OPERATIONAL, qosEntryIid);