2 * Copyright (c) 2016 Intel 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.ovsdb.transact;
11 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
13 import java.util.Collection;
14 import java.util.List;
17 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
18 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
19 import org.opendaylight.ovsdb.lib.notation.UUID;
20 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
21 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
22 import org.opendaylight.ovsdb.schema.openvswitch.Queue;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.Queues;
27 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
28 import org.opendaylight.yangtools.yang.binding.DataObject;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 public class QueueRemovedCommand implements TransactCommand {
34 private static final Logger LOG = LoggerFactory.getLogger(QueueRemovedCommand.class);
37 public void execute(TransactionBuilder transaction, BridgeOperationalState state,
38 AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> events) {
39 execute(transaction, state, TransactUtils.extractOriginal(events, OvsdbNodeAugmentation.class),
40 TransactUtils.extractUpdated(events, OvsdbNodeAugmentation.class));
44 public void execute(TransactionBuilder transaction, BridgeOperationalState state,
45 Collection<DataTreeModification<Node>> modifications) {
46 execute(transaction, state, TransactUtils.extractOriginal(modifications, OvsdbNodeAugmentation.class),
47 TransactUtils.extractUpdated(modifications, OvsdbNodeAugmentation.class));
50 private void execute(TransactionBuilder transaction, BridgeOperationalState state,
51 Map<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> originals,
52 Map<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> updated) {
53 for (Map.Entry<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> originalEntry : originals
55 InstanceIdentifier<OvsdbNodeAugmentation> ovsdbNodeIid = originalEntry.getKey();
56 OvsdbNodeAugmentation original = originalEntry.getValue();
57 OvsdbNodeAugmentation update = updated.get(ovsdbNodeIid);
59 if (original != null && update != null) {
60 List<Queues> origQueues = original.getQueues();
61 List<Queues> updatedQueues = update.getQueues();
62 if (origQueues != null && !origQueues.isEmpty()) {
63 for (Queues origQueue : origQueues) {
64 OvsdbNodeAugmentation operNode =
65 state.getBridgeNode(ovsdbNodeIid).get().getAugmentation(
66 OvsdbNodeAugmentation.class);
67 List<Queues> operQueues = operNode.getQueues();
69 boolean found = false;
70 if (updatedQueues != null && !updatedQueues.isEmpty()) {
71 for (Queues updatedQueue : updatedQueues) {
72 if (origQueue.getQueueId().equals(updatedQueue.getQueueId())) {
79 LOG.debug("Received request to delete Queue entry {}", origQueue.getQueueId());
80 Uuid queueUuid = getQueueUuid(operQueues, origQueue.getQueueId());
81 if (queueUuid != null) {
83 TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Queue.class,
85 transaction.add(op.delete(queue.getSchema())
86 .where(queue.getUuidColumn().getSchema().opEqual(
87 new UUID(queueUuid.getValue())))
91 "Unable to delete Queue{} for node {} because it was not found in the " +
93 + "and thus we cannot retrieve its UUID", ovsdbNodeIid,
94 origQueue.getQueueId());
103 private Uuid getQueueUuid(List<Queues> operQueues, Uri queueId) {
104 if (operQueues != null && !operQueues.isEmpty()) {
105 for (Queues queueEntry : operQueues) {
106 if (queueEntry.getQueueId().equals(queueId)) {
107 return queueEntry.getQueueUuid();