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;
16 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
17 import org.opendaylight.ovsdb.lib.notation.UUID;
18 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
19 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
20 import org.opendaylight.ovsdb.schema.openvswitch.Queue;
21 import org.opendaylight.ovsdb.southbound.InstanceIdentifierCodec;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.Queues;
26 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 public class QueueRemovedCommand implements TransactCommand {
32 private static final Logger LOG = LoggerFactory.getLogger(QueueRemovedCommand.class);
35 public void execute(TransactionBuilder transaction, BridgeOperationalState state,
36 DataChangeEvent events, InstanceIdentifierCodec instanceIdentifierCodec) {
37 execute(transaction, state, TransactUtils.extractOriginal(events, OvsdbNodeAugmentation.class),
38 TransactUtils.extractUpdated(events, OvsdbNodeAugmentation.class));
42 public void execute(TransactionBuilder transaction, BridgeOperationalState state,
43 Collection<DataTreeModification<Node>> modifications, InstanceIdentifierCodec instanceIdentifierCodec) {
44 execute(transaction, state, TransactUtils.extractOriginal(modifications, OvsdbNodeAugmentation.class),
45 TransactUtils.extractUpdated(modifications, OvsdbNodeAugmentation.class));
48 private void execute(TransactionBuilder transaction, BridgeOperationalState state,
49 Map<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> originals,
50 Map<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> updated) {
51 for (Map.Entry<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> originalEntry : originals
53 InstanceIdentifier<OvsdbNodeAugmentation> ovsdbNodeIid = originalEntry.getKey();
54 OvsdbNodeAugmentation original = originalEntry.getValue();
55 OvsdbNodeAugmentation update = updated.get(ovsdbNodeIid);
57 if (original != null && update != null) {
58 List<Queues> origQueues = original.getQueues();
59 List<Queues> updatedQueues = update.getQueues();
60 if (origQueues != null && !origQueues.isEmpty()) {
61 for (Queues origQueue : origQueues) {
62 OvsdbNodeAugmentation operNode =
63 state.getBridgeNode(ovsdbNodeIid).get().augmentation(
64 OvsdbNodeAugmentation.class);
65 List<Queues> operQueues = operNode.getQueues();
67 boolean found = false;
68 if (updatedQueues != null && !updatedQueues.isEmpty()) {
69 for (Queues updatedQueue : updatedQueues) {
70 if (origQueue.getQueueId().equals(updatedQueue.getQueueId())) {
77 LOG.debug("Received request to delete Queue entry {}", origQueue.getQueueId());
78 Uuid queueUuid = getQueueUuid(operQueues, origQueue.getQueueId());
79 if (queueUuid != null) {
81 TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Queue.class,
83 transaction.add(op.delete(queue.getSchema())
84 .where(queue.getUuidColumn().getSchema().opEqual(
85 new UUID(queueUuid.getValue())))
87 LOG.info("Deleted queue Uuid : {} for the Ovsdb Node : {}", queueUuid, operNode);
89 LOG.warn("Unable to delete Queue{} for node {} because it was not found in the "
90 + "operational store, and thus we cannot retrieve its UUID",
91 ovsdbNodeIid, origQueue.getQueueId());
100 private Uuid getQueueUuid(List<Queues> operQueues, Uri queueId) {
101 if (operQueues != null && !operQueues.isEmpty()) {
102 for (Queues queueEntry : operQueues) {
103 if (queueEntry.getQueueId().equals(queueId)) {
104 return queueEntry.getQueueUuid();