2 * Copyright (c) 2016 Intel Communications Systems, Inc. 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.transactions.md;
11 import java.util.ArrayList;
12 import java.util.Iterator;
13 import java.util.List;
16 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
17 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
18 import org.opendaylight.ovsdb.lib.message.TableUpdates;
19 import org.opendaylight.ovsdb.lib.notation.UUID;
20 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
21 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
22 import org.opendaylight.ovsdb.schema.openvswitch.Qos;
23 import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
24 import org.opendaylight.ovsdb.southbound.OvsdbConnectionInstance;
25 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
26 import org.opendaylight.ovsdb.southbound.SouthboundUtil;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QosEntries;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QosEntriesKey;
31 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
32 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 import com.google.common.base.Optional;
38 public class OvsdbQosRemovedCommand extends AbstractTransactionCommand {
39 private static final Logger LOG = LoggerFactory.getLogger(OvsdbQueueUpdateCommand.class);
41 private Map<UUID, Qos> removedQosRows;
42 private Map<UUID, OpenVSwitch> updatedOpenVSwitchRows;
44 public OvsdbQosRemovedCommand(OvsdbConnectionInstance key,
45 TableUpdates updates, DatabaseSchema dbSchema) {
46 super(key, updates, dbSchema);
47 updatedOpenVSwitchRows = TyperUtils.extractRowsUpdated(OpenVSwitch.class, getUpdates(), getDbSchema());
48 removedQosRows = TyperUtils.extractRowsRemoved(Qos.class, getUpdates(), getDbSchema());
52 public void execute(ReadWriteTransaction transaction) {
53 final InstanceIdentifier<Node> nodeIId = getOvsdbConnectionInstance().getInstanceIdentifier();
54 final Optional<Node> ovsdbNode = SouthboundUtil.readNode(transaction, nodeIId);
55 if (ovsdbNode.isPresent()) {
56 List<InstanceIdentifier<QosEntries>> result = new ArrayList<>();
57 InstanceIdentifier<Node> ovsdbNodeIid =
58 SouthboundMapper.createInstanceIdentifier(getOvsdbConnectionInstance().getNodeId());
59 if (removedQosRows != null && !removedQosRows.isEmpty()) {
60 for (UUID qosUuid : removedQosRows.keySet()) {
61 QosEntriesKey qosKey = getQosEntriesKey(ovsdbNode.get(), qosUuid);
63 InstanceIdentifier<QosEntries> iid = ovsdbNodeIid
64 .augmentation(OvsdbNodeAugmentation.class)
65 .child(QosEntries.class, qosKey);
70 deleteQos(transaction, result);
74 private QosEntriesKey getQosEntriesKey(Node node, UUID qosUuid) {
75 List<QosEntries> qosList = node.getAugmentation(OvsdbNodeAugmentation.class).getQosEntries();
76 if (qosList == null || qosList.isEmpty()) {
77 LOG.debug("Deleting Qos {}, Ovsdb Node {} does not have a Qos list.", qosUuid.toString(), node);
80 Iterator<QosEntries> itr = qosList.iterator();
81 Uuid qUuid = new Uuid(qosUuid.toString());
82 while (itr.hasNext()) {
83 QosEntries qos = itr.next();
84 if (qos.getQosUuid().equals(qUuid)) {
88 LOG.debug("Deleted Queue {} not found in Ovsdb Node {}", qosUuid.toString(), node);
92 private void deleteQos(ReadWriteTransaction transaction,
93 List<InstanceIdentifier<QosEntries>> qosEntryIids) {
94 for (InstanceIdentifier<QosEntries> qosEntryIid: qosEntryIids) {
95 transaction.delete(LogicalDatastoreType.OPERATIONAL, qosEntryIid);