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;
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.Qos;
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.QosEntries;
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 QosRemovedCommand implements TransactCommand {
32 private static final Logger LOG = LoggerFactory.getLogger(QosRemovedCommand.class);
35 public void execute(TransactionBuilder transaction, BridgeOperationalState state,
36 DataChangeEvent events, InstanceIdentifierCodec instanceIdentifierCodec) {
37 execute(transaction, state,
38 TransactUtils.extractOriginal(events, OvsdbNodeAugmentation.class),
39 TransactUtils.extractUpdated(events, OvsdbNodeAugmentation.class));
43 public void execute(TransactionBuilder transaction, BridgeOperationalState state,
44 Collection<DataTreeModification<Node>> modifications, InstanceIdentifierCodec instanceIdentifierCodec) {
45 execute(transaction, state,
46 TransactUtils.extractOriginal(modifications, OvsdbNodeAugmentation.class),
47 TransactUtils.extractUpdated(modifications, OvsdbNodeAugmentation.class));
50 private void execute(TransactionBuilder transaction, BridgeOperationalState state,
51 Map<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> originals,
52 Map<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> updated) {
53 for (Map.Entry<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> originalEntry : originals
55 InstanceIdentifier<OvsdbNodeAugmentation> ovsdbNodeIid = originalEntry.getKey();
56 OvsdbNodeAugmentation original = originalEntry.getValue();
57 OvsdbNodeAugmentation update = updated.get(ovsdbNodeIid);
59 if (original != null && update != null) {
60 List<QosEntries> origQosEntries = original.getQosEntries();
61 List<QosEntries> updatedQosEntries = update.getQosEntries();
62 if (origQosEntries != null && !origQosEntries.isEmpty()) {
63 for (QosEntries origQosEntry : origQosEntries) {
64 OvsdbNodeAugmentation operNode =
65 state.getBridgeNode(ovsdbNodeIid).get().augmentation(OvsdbNodeAugmentation.class);
66 List<QosEntries> operQosEntries = operNode.getQosEntries();
68 boolean found = false;
69 if (updatedQosEntries != null && !updatedQosEntries.isEmpty()) {
70 for (QosEntries updatedQosEntry : updatedQosEntries) {
71 if (origQosEntry.getQosId().equals(updatedQosEntry.getQosId())) {
78 LOG.debug("Received request to delete QoS entry {}", origQosEntry.getQosId());
79 Uuid qosUuid = getQosEntryUuid(operQosEntries, origQosEntry.getQosId());
80 if (qosUuid != null) {
82 TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Qos.class, null);
83 transaction.add(op.delete(qos.getSchema())
84 .where(qos.getUuidColumn().getSchema().opEqual(new UUID(qosUuid.getValue())))
86 LOG.info("Removed QoS Uuid : {} for node : {} ",
87 origQosEntry.getQosId(), ovsdbNodeIid);
89 LOG.warn("Unable to delete QoS{} for node {} because it was not found in the "
90 + "operational store, and thus we cannot retrieve its UUID",
91 origQosEntry.getQosId(), ovsdbNodeIid);
100 private Uuid getQosEntryUuid(List<QosEntries> operQosEntries, Uri qosId) {
101 if (operQosEntries != null && !operQosEntries.isEmpty()) {
102 for (QosEntries qosEntry : operQosEntries) {
103 if (qosEntry.getQosId().equals(qosId)) {
104 return qosEntry.getQosUuid();