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.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.Qos;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.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.QosEntries;
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 QosRemovedCommand implements TransactCommand {
34 private static final Logger LOG = LoggerFactory.getLogger(QosRemovedCommand.class);
37 public void execute(TransactionBuilder transaction, BridgeOperationalState state,
38 AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> events) {
39 execute(transaction, state,
40 TransactUtils.extractOriginal(events, OvsdbNodeAugmentation.class),
41 TransactUtils.extractUpdated(events, OvsdbNodeAugmentation.class));
45 public void execute(TransactionBuilder transaction, BridgeOperationalState state,
46 Collection<DataTreeModification<Node>> modifications) {
47 execute(transaction, state,
48 TransactUtils.extractOriginal(modifications, OvsdbNodeAugmentation.class),
49 TransactUtils.extractUpdated(modifications, OvsdbNodeAugmentation.class));
52 private void execute(TransactionBuilder transaction, BridgeOperationalState state,
53 Map<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> originals,
54 Map<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> updated) {
55 for (Map.Entry<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> originalEntry : originals
57 InstanceIdentifier<OvsdbNodeAugmentation> ovsdbNodeIid = originalEntry.getKey();
58 OvsdbNodeAugmentation original = originalEntry.getValue();
59 OvsdbNodeAugmentation update = updated.get(ovsdbNodeIid);
61 if (original != null && update != null) {
62 List<QosEntries> origQosEntries = original.getQosEntries();
63 List<QosEntries> updatedQosEntries = update.getQosEntries();
64 if (origQosEntries != null && !origQosEntries.isEmpty()) {
65 for (QosEntries origQosEntry : origQosEntries) {
66 OvsdbNodeAugmentation operNode =
67 state.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) {
84 TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Qos.class, null);
85 transaction.add(op.delete(qos.getSchema())
86 .where(qos.getUuidColumn().getSchema().opEqual(new UUID(qosUuid.getValue())))
88 LOG.info("Removed QoS Uuid : {} for node : {} ",
89 origQosEntry.getQosId(), ovsdbNodeIid);
91 LOG.warn("Unable to delete QoS{} for node {} because it was not found in the "
92 + "operational store, and thus we cannot retrieve its UUID",
93 origQosEntry.getQosId(), ovsdbNodeIid);
102 private Uuid getQosEntryUuid(List<QosEntries> operQosEntries, Uri qosId) {
103 if (operQosEntries != null && !operQosEntries.isEmpty()) {
104 for (QosEntries qosEntry : operQosEntries) {
105 if (qosEntry.getQosId().equals(qosId)) {
106 return qosEntry.getQosUuid();