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.Iterator;
14 import java.util.List;
18 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
19 import org.opendaylight.ovsdb.lib.notation.Mutator;
20 import org.opendaylight.ovsdb.lib.notation.UUID;
21 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
22 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
23 import org.opendaylight.ovsdb.schema.openvswitch.Qos;
24 import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QosEntries;
29 import org.opendaylight.yangtools.yang.binding.DataObject;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 import com.google.common.base.Optional;
35 import com.google.common.collect.Sets;
37 public class QosRemovedCommand extends AbstractTransactCommand {
38 private static final Logger LOG = LoggerFactory.getLogger(QosRemovedCommand.class);
40 public QosRemovedCommand(BridgeOperationalState state,
41 AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes) {
42 super(state, changes);
46 public void execute(TransactionBuilder transaction) {
47 Set<InstanceIdentifier<QosEntries>> removed =
48 TransactUtils.extractRemoved(getChanges(),QosEntries.class);
50 Map<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> originals
51 = TransactUtils.extractOriginal(getChanges(),OvsdbNodeAugmentation.class);
53 Map<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> updated
54 = TransactUtils.extractUpdated(getChanges(), OvsdbNodeAugmentation.class);
56 Iterator<InstanceIdentifier<OvsdbNodeAugmentation>> itr = originals.keySet().iterator();
57 while (itr.hasNext()) {
58 InstanceIdentifier<OvsdbNodeAugmentation> ovsdbNodeIid = itr.next();
59 OvsdbNodeAugmentation original = originals.get(ovsdbNodeIid);
60 OvsdbNodeAugmentation update = updated.get(ovsdbNodeIid);
62 if (original != null && update != null) {
63 List<QosEntries> origQosEntries = original.getQosEntries();
64 List<QosEntries> updatedQosEntries = update.getQosEntries();
65 if (origQosEntries != null && !origQosEntries.isEmpty()) {
66 for (QosEntries origQosEntry : origQosEntries) {
67 OvsdbNodeAugmentation operNode = getOperationalState().getBridgeNode(ovsdbNodeIid).get().getAugmentation(OvsdbNodeAugmentation.class);
68 List<QosEntries> operQosEntries = operNode.getQosEntries();
70 boolean found = false;
71 if (updatedQosEntries != null && !updatedQosEntries.isEmpty()) {
72 for (QosEntries updatedQosEntry : updatedQosEntries) {
73 if (origQosEntry.getQosId().equals(updatedQosEntry.getQosId())) {
80 LOG.debug("Received request to delete QoS entry {}",origQosEntry.getQosId());
81 Uuid qosUuid = getQosEntryUuid(operQosEntries, origQosEntry.getQosId());
82 if (qosUuid != null) {
83 Qos qos = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Qos.class, null);
84 transaction.add(op.delete(qos.getSchema())
85 .where(qos.getUuidColumn().getSchema().opEqual(new UUID(qosUuid.getValue())))
88 LOG.warn("Unable to delete QoS{} for node {} because it was not found in the operational store, "
89 + "and thus we cannot retrieve its UUID", origQosEntry.getQosId(), ovsdbNodeIid);
98 private Uuid getQosEntryUuid(List<QosEntries> operQosEntries, Uri qosId) {
99 if (operQosEntries != null && !operQosEntries.isEmpty()) {
100 for (QosEntries qosEntry : operQosEntries) {
101 if (qosEntry.getQosId().equals(qosId)) {
102 return qosEntry.getQosUuid();