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
9 package org.opendaylight.ovsdb.southbound.ovsdb.transact;
11 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
13 import java.util.List;
16 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
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.Qos;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QosEntries;
25 import org.opendaylight.yangtools.yang.binding.DataObject;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 public class QosRemovedCommand implements TransactCommand {
31 private static final Logger LOG = LoggerFactory.getLogger(QosRemovedCommand.class);
34 public void execute(TransactionBuilder transaction, BridgeOperationalState state,
35 AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> events) {
36 execute(transaction, state,
37 TransactUtils.extractOriginal(events, OvsdbNodeAugmentation.class),
38 TransactUtils.extractUpdated(events, OvsdbNodeAugmentation.class));
41 private void execute(TransactionBuilder transaction, BridgeOperationalState state,
42 Map<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> originals,
43 Map<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> updated) {
44 for (Map.Entry<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> originalEntry : originals
46 InstanceIdentifier<OvsdbNodeAugmentation> ovsdbNodeIid = originalEntry.getKey();
47 OvsdbNodeAugmentation original = originalEntry.getValue();
48 OvsdbNodeAugmentation update = updated.get(ovsdbNodeIid);
50 if (original != null && update != null) {
51 List<QosEntries> origQosEntries = original.getQosEntries();
52 List<QosEntries> updatedQosEntries = update.getQosEntries();
53 if (origQosEntries != null && !origQosEntries.isEmpty()) {
54 for (QosEntries origQosEntry : origQosEntries) {
55 OvsdbNodeAugmentation operNode =
56 state.getBridgeNode(ovsdbNodeIid).get().getAugmentation(OvsdbNodeAugmentation.class);
57 List<QosEntries> operQosEntries = operNode.getQosEntries();
59 boolean found = false;
60 if (updatedQosEntries != null && !updatedQosEntries.isEmpty()) {
61 for (QosEntries updatedQosEntry : updatedQosEntries) {
62 if (origQosEntry.getQosId().equals(updatedQosEntry.getQosId())) {
69 LOG.debug("Received request to delete QoS entry {}", origQosEntry.getQosId());
70 Uuid qosUuid = getQosEntryUuid(operQosEntries, origQosEntry.getQosId());
71 if (qosUuid != null) {
73 TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Qos.class, null);
74 transaction.add(op.delete(qos.getSchema())
75 .where(qos.getUuidColumn().getSchema().opEqual(new UUID(qosUuid.getValue())))
79 "Unable to delete QoS{} for node {} because it was not found in the " +
81 + "and thus we cannot retrieve its UUID", origQosEntry.getQosId(),
91 private Uuid getQosEntryUuid(List<QosEntries> operQosEntries, Uri qosId) {
92 if (operQosEntries != null && !operQosEntries.isEmpty()) {
93 for (QosEntries qosEntry : operQosEntries) {
94 if (qosEntry.getQosId().equals(qosId)) {
95 return qosEntry.getQosUuid();