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.List;
14 import java.util.Optional;
15 import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
16 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
17 import org.opendaylight.ovsdb.lib.message.TableUpdates;
18 import org.opendaylight.ovsdb.lib.notation.UUID;
19 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
20 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
21 import org.opendaylight.ovsdb.schema.openvswitch.Queue;
22 import org.opendaylight.ovsdb.southbound.OvsdbConnectionInstance;
23 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
24 import org.opendaylight.ovsdb.southbound.SouthboundUtil;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.Queues;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QueuesKey;
29 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 public class OvsdbQueueRemovedCommand extends AbstractTransactionCommand {
35 private static final Logger LOG = LoggerFactory.getLogger(OvsdbQueueRemovedCommand.class);
37 private final Map<UUID, Queue> removedQueueRows;
39 public OvsdbQueueRemovedCommand(OvsdbConnectionInstance key,
40 TableUpdates updates, DatabaseSchema dbSchema) {
41 super(key, updates, dbSchema);
42 removedQueueRows = TyperUtils.extractRowsRemoved(Queue.class, getUpdates(), getDbSchema());
46 public void execute(ReadWriteTransaction transaction) {
47 if (removedQueueRows == null || removedQueueRows.isEmpty()) {
51 final InstanceIdentifier<Node> nodeIId = getOvsdbConnectionInstance().getInstanceIdentifier();
52 final Optional<Node> ovsdbNode = SouthboundUtil.readNode(transaction, nodeIId);
53 if (ovsdbNode.isPresent()) {
54 List<InstanceIdentifier<Queues>> result = new ArrayList<>();
55 InstanceIdentifier<Node> ovsdbNodeIid =
56 SouthboundMapper.createInstanceIdentifier(getOvsdbConnectionInstance().getNodeId());
57 for (UUID queueUuid : removedQueueRows.keySet()) {
58 QueuesKey queueKey = getQueueKey(ovsdbNode.get(), queueUuid);
59 if (queueKey != null) {
60 InstanceIdentifier<Queues> iid = ovsdbNodeIid
61 .augmentation(OvsdbNodeAugmentation.class)
62 .child(Queues.class, queueKey);
66 deleteQueue(transaction, result);
70 private static QueuesKey getQueueKey(Node node, UUID queueUuid) {
71 Map<QueuesKey, Queues> queueList = node.augmentation(OvsdbNodeAugmentation.class).getQueues();
72 if (queueList == null || queueList.isEmpty()) {
73 LOG.debug("Deleting Queue {}, Ovsdb Node {} does not have a Queue list.", queueUuid, node);
76 Uuid quUuid = new Uuid(queueUuid.toString());
77 for (Queues queue : queueList.values()) {
78 if (queue.getQueueUuid().equals(quUuid)) {
82 LOG.debug("Deleted Queue {} not found in Ovsdb Node {}", queueUuid, node);
86 private static void deleteQueue(ReadWriteTransaction transaction,
87 List<InstanceIdentifier<Queues>> queueIids) {
88 for (InstanceIdentifier<Queues> queueIid: queueIids) {
89 transaction.delete(LogicalDatastoreType.OPERATIONAL, queueIid);