2 * Copyright (c) 2016 Intel Corporation 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
8 package org.opendaylight.ovsdb.southbound.ovsdb.transact;
10 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
12 import java.util.Collection;
14 import org.opendaylight.mdsal.binding.api.DataTreeModification;
15 import org.opendaylight.ovsdb.lib.notation.UUID;
16 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
17 import org.opendaylight.ovsdb.schema.openvswitch.Qos;
18 import org.opendaylight.ovsdb.southbound.InstanceIdentifierCodec;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QosEntries;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QosEntriesKey;
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 public class QosRemovedCommand implements TransactCommand {
29 private static final Logger LOG = LoggerFactory.getLogger(QosRemovedCommand.class);
32 public void execute(final TransactionBuilder transaction, final BridgeOperationalState state,
33 final DataChangeEvent events, final InstanceIdentifierCodec instanceIdentifierCodec) {
34 execute(transaction, state,
35 TransactUtils.extractOriginal(events, OvsdbNodeAugmentation.class),
36 TransactUtils.extractUpdated(events, OvsdbNodeAugmentation.class));
40 public void execute(final TransactionBuilder transaction, final BridgeOperationalState state,
41 final Collection<DataTreeModification<Node>> modifications,
42 final InstanceIdentifierCodec instanceIdentifierCodec) {
43 execute(transaction, state,
44 TransactUtils.extractOriginal(modifications, OvsdbNodeAugmentation.class),
45 TransactUtils.extractUpdated(modifications, OvsdbNodeAugmentation.class));
48 private static void execute(final TransactionBuilder transaction, final BridgeOperationalState state,
49 final Map<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> originals,
50 final 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 Map<QosEntriesKey, QosEntries> origQosEntries = original.getQosEntries();
59 Map<QosEntriesKey, QosEntries> updatedQosEntries = update.getQosEntries();
60 if (origQosEntries != null && !origQosEntries.isEmpty()) {
61 for (QosEntries origQosEntry : origQosEntries.values()) {
62 OvsdbNodeAugmentation operNode =
63 state.getBridgeNode(ovsdbNodeIid).get().augmentation(OvsdbNodeAugmentation.class);
64 if (updatedQosEntries == null || !updatedQosEntries.containsKey(origQosEntry.key())) {
65 LOG.debug("Received request to delete QoS entry {}", origQosEntry.getQosId());
66 Uuid qosUuid = getQosEntryUuid(operNode.getQosEntries(), origQosEntry.key());
67 if (qosUuid != null) {
68 Qos qos = transaction.getTypedRowSchema(Qos.class);
69 transaction.add(op.delete(qos.getSchema())
70 .where(qos.getUuidColumn().getSchema().opEqual(new UUID(qosUuid.getValue())))
72 LOG.info("Removed QoS Uuid : {} for node : {} ",
73 origQosEntry.getQosId(), ovsdbNodeIid);
75 LOG.warn("Unable to delete QoS{} for node {} because it was not found in the "
76 + "operational store, and thus we cannot retrieve its UUID",
77 origQosEntry.getQosId(), ovsdbNodeIid);
86 private static Uuid getQosEntryUuid(final Map<QosEntriesKey, QosEntries> operQosEntries,
87 final QosEntriesKey qosId) {
88 if (operQosEntries != null && !operQosEntries.isEmpty()) {
89 QosEntries qosEntry = operQosEntries.get(qosId);
90 if (qosEntry != null) {
91 return qosEntry.getQosUuid();