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 java.util.ArrayList;
12 import java.util.Iterator;
13 import java.util.List;
15 import java.util.Optional;
16 import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
17 import org.opendaylight.mdsal.common.api.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.Qos;
23 import org.opendaylight.ovsdb.southbound.OvsdbConnectionInstance;
24 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
25 import org.opendaylight.ovsdb.southbound.SouthboundUtil;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QosEntries;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QosEntriesKey;
30 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 public class OvsdbQosRemovedCommand extends AbstractTransactionCommand {
36 private static final Logger LOG = LoggerFactory.getLogger(OvsdbQosRemovedCommand.class);
38 private Map<UUID, Qos> removedQosRows;
40 public OvsdbQosRemovedCommand(OvsdbConnectionInstance key,
41 TableUpdates updates, DatabaseSchema dbSchema) {
42 super(key, updates, dbSchema);
43 removedQosRows = TyperUtils.extractRowsRemoved(Qos.class, getUpdates(), getDbSchema());
47 public void execute(ReadWriteTransaction transaction) {
48 if (removedQosRows == null || removedQosRows.isEmpty()) {
52 final InstanceIdentifier<Node> nodeIId = getOvsdbConnectionInstance().getInstanceIdentifier();
53 final Optional<Node> ovsdbNode = SouthboundUtil.readNode(transaction, nodeIId);
54 if (ovsdbNode.isPresent()) {
55 List<InstanceIdentifier<QosEntries>> result = new ArrayList<>();
56 InstanceIdentifier<Node> ovsdbNodeIid =
57 SouthboundMapper.createInstanceIdentifier(getOvsdbConnectionInstance().getNodeId());
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);
67 deleteQos(transaction, result);
71 private QosEntriesKey getQosEntriesKey(Node node, UUID qosUuid) {
72 List<QosEntries> qosList = node.augmentation(OvsdbNodeAugmentation.class).getQosEntries();
73 if (qosList == null || qosList.isEmpty()) {
74 LOG.debug("Deleting Qos {}, Ovsdb Node {} does not have a Qos list.", qosUuid, node);
77 Iterator<QosEntries> itr = qosList.iterator();
78 Uuid quUuid = new Uuid(qosUuid.toString());
79 while (itr.hasNext()) {
80 QosEntries qos = itr.next();
81 if (qos.getQosUuid().equals(quUuid)) {
85 LOG.debug("Deleted Queue {} not found in Ovsdb Node {}", qosUuid, node);
89 private void deleteQos(ReadWriteTransaction transaction,
90 List<InstanceIdentifier<QosEntries>> qosEntryIids) {
91 for (InstanceIdentifier<QosEntries> qosEntryIid: qosEntryIids) {
92 transaction.delete(LogicalDatastoreType.OPERATIONAL, qosEntryIid);