Bug 7757 -Removing qos deprecations in carbon
[ovsdb.git] / southbound / southbound-impl / src / main / java / org / opendaylight / ovsdb / southbound / ovsdb / transact / QosUpdateCommand.java
index 294e4910d46fc95bd8c11f13c58981525a4101de..cea65595dd48d6f32fb599f4b5d8282a9910b77b 100644 (file)
@@ -20,11 +20,11 @@ import org.opendaylight.ovsdb.lib.notation.UUID;
 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
 import org.opendaylight.ovsdb.schema.openvswitch.Qos;
+import org.opendaylight.ovsdb.southbound.InstanceIdentifierCodec;
 import org.opendaylight.ovsdb.southbound.SouthboundConstants;
 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
-import org.opendaylight.ovsdb.southbound.SouthboundUtil;
 import org.opendaylight.ovsdb.utils.yang.YangUtils;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbQueueRef;
@@ -36,7 +36,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.re
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.qos.entries.QosOtherConfig;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.qos.entries.QueueList;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
@@ -47,95 +46,88 @@ public class QosUpdateCommand implements TransactCommand {
 
     @Override
     public void execute(TransactionBuilder transaction, BridgeOperationalState state,
-                        AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> events) {
-        execute(transaction, state, TransactUtils.extractCreatedOrUpdated(events, OvsdbNodeAugmentation.class));
+            AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> events,
+            InstanceIdentifierCodec instanceIdentifierCodec) {
+        execute(transaction, state, TransactUtils.extractCreatedOrUpdated(events, QosEntries.class),
+                instanceIdentifierCodec);
     }
 
     @Override
     public void execute(TransactionBuilder transaction, BridgeOperationalState state,
-                        Collection<DataTreeModification<Node>> modifications) {
-        execute(transaction, state, TransactUtils.extractCreatedOrUpdated(modifications, OvsdbNodeAugmentation.class));
+            Collection<DataTreeModification<Node>> modifications, InstanceIdentifierCodec instanceIdentifierCodec) {
+        execute(transaction, state, TransactUtils.extractCreatedOrUpdated(modifications, QosEntries.class),
+                instanceIdentifierCodec);
     }
 
     private void execute(TransactionBuilder transaction, BridgeOperationalState state,
-                         Map<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> createdOrUpdated) {
-        for (Entry<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> ovsdbNodeEntry:
-            createdOrUpdated.entrySet()) {
-            updateQos(transaction, state, ovsdbNodeEntry.getKey(), ovsdbNodeEntry.getValue());
-        }
-    }
-
-    private void updateQos(
-            TransactionBuilder transaction, BridgeOperationalState state,
-            InstanceIdentifier<OvsdbNodeAugmentation> iid, OvsdbNodeAugmentation ovsdbNode) {
-
-        List<QosEntries> qosEntries = ovsdbNode.getQosEntries();
-
-        if (!state.getBridgeNode(iid).isPresent()) {
-            return;
-        }
-        OvsdbNodeAugmentation operNode = state.getBridgeNode(iid).get().getAugmentation(OvsdbNodeAugmentation.class);
-        List<QosEntries> operQosEntries = operNode.getQosEntries();
-        List<Queues> operQueues = operNode.getQueues();
+            Map<InstanceIdentifier<QosEntries>, QosEntries> createdOrUpdated,
+            InstanceIdentifierCodec instanceIdentifierCodec) {
+        for (Entry<InstanceIdentifier<QosEntries>, QosEntries> qosMapEntry: createdOrUpdated.entrySet()) {
+            InstanceIdentifier<OvsdbNodeAugmentation> iid =
+                    qosMapEntry.getKey().firstIdentifierOf(OvsdbNodeAugmentation.class);
+            if (!state.getBridgeNode(iid).isPresent()) {
+                return;
+            }
+            OvsdbNodeAugmentation operNode =
+                state.getBridgeNode(iid).get().getAugmentation(OvsdbNodeAugmentation.class);
 
-        if (qosEntries != null) {
-            for (QosEntries qosEntry : qosEntries) {
-                Qos qos = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Qos.class);
+            QosEntries qosEntry = qosMapEntry.getValue();
+            Qos qos = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Qos.class);
 
-                if (qosEntry.getQosType() != null) {
-                    qos.setType(SouthboundMapper.createQosType(qosEntry.getQosType()));
-                }
+            if (qosEntry.getQosType() != null) {
+                qos.setType(SouthboundMapper.createQosType(qosEntry.getQosType()));
+            }
 
-                List<QueueList> queueList = qosEntry.getQueueList();
-                Map<Long, UUID> newQueueList = new HashMap<>();
-                if (queueList != null && !queueList.isEmpty()) {
-                    for (QueueList queue : queueList) {
-                        if (queue.getQueueRef() != null) {
-                            newQueueList.put(queue.getQueueNumber(),
-                                    new UUID(getQueueUuid(queue.getQueueRef(), operNode)));
-                        } else if (queue.getQueueUuid() != null) {
-                            newQueueList.put(queue.getQueueNumber(), new UUID(queue.getQueueUuid().getValue()));
-                        }
+            List<QueueList> queueList = qosEntry.getQueueList();
+            Map<Long, UUID> newQueueList = new HashMap<>();
+            if (queueList != null && !queueList.isEmpty()) {
+                for (QueueList queue : queueList) {
+                    if (queue.getQueueRef() != null) {
+                        newQueueList.put(queue.getQueueNumber(),
+                                new UUID(getQueueUuid(queue.getQueueRef(), operNode)));
                     }
                 }
-                qos.setQueues(newQueueList);
-
-                Map<String, String> externalIdsMap = new HashMap<>();
-                try {
-                    YangUtils.copyYangKeyValueListToMap(externalIdsMap, qosEntry.getQosExternalIds(),
-                            QosExternalIds::getQosExternalIdKey, QosExternalIds::getQosExternalIdValue);
-                } catch (NullPointerException e) {
-                    LOG.warn("Incomplete Qos external IDs", e);
-                }
-                externalIdsMap.put(SouthboundConstants.IID_EXTERNAL_ID_KEY,
-                        SouthboundUtil.serializeInstanceIdentifier(
-                        SouthboundMapper.createInstanceIdentifier(iid.firstKeyOf(Node.class, NodeKey.class).getNodeId())
-                        .augmentation(OvsdbNodeAugmentation.class)
-                        .child(QosEntries.class, new QosEntriesKey(qosEntry.getQosId()))));
-                qos.setExternalIds(externalIdsMap);
-
-                try {
-                    qos.setOtherConfig(YangUtils.convertYangKeyValueListToMap(qosEntry.getQosOtherConfig(),
-                            QosOtherConfig::getOtherConfigKey, QosOtherConfig::getOtherConfigValue));
-                } catch (NullPointerException e) {
-                    LOG.warn("Incomplete Qos other_config", e);
-                }
+            }
+            qos.setQueues(newQueueList);
+
+            Map<String, String> externalIdsMap = new HashMap<>();
+            try {
+                YangUtils.copyYangKeyValueListToMap(externalIdsMap, qosEntry.getQosExternalIds(),
+                        QosExternalIds::getQosExternalIdKey, QosExternalIds::getQosExternalIdValue);
+            } catch (NullPointerException e) {
+                LOG.warn("Incomplete Qos external IDs", e);
+            }
+            externalIdsMap.put(SouthboundConstants.IID_EXTERNAL_ID_KEY,
+
+                    instanceIdentifierCodec.serialize(
+                    SouthboundMapper.createInstanceIdentifier(iid.firstKeyOf(Node.class).getNodeId())
+                    .augmentation(OvsdbNodeAugmentation.class)
+                    .child(QosEntries.class, new QosEntriesKey(qosEntry.getQosId()))));
+            qos.setExternalIds(externalIdsMap);
+
+            try {
+                qos.setOtherConfig(YangUtils.convertYangKeyValueListToMap(qosEntry.getQosOtherConfig(),
+                        QosOtherConfig::getOtherConfigKey, QosOtherConfig::getOtherConfigValue));
+            } catch (NullPointerException e) {
+                LOG.warn("Incomplete Qos other_config", e);
+            }
 
-                Uuid operQosUuid = getQosEntryUuid(operQosEntries, qosEntry.getQosId());
-                if (operQosUuid == null) {
-                    UUID namedUuid = new UUID(SouthboundConstants.QOS_NAMED_UUID_PREFIX
-                            + TransactUtils.bytesToHexString(qosEntry.getQosId().getValue().getBytes()));
-                    transaction.add(op.insert(qos).withId(namedUuid.toString())).build();
-                } else {
-                    UUID uuid = new UUID(operQosUuid.getValue());
-                    Qos extraQos = TyperUtils.getTypedRowWrapper(
-                            transaction.getDatabaseSchema(), Qos.class, null);
-                    extraQos.getUuidColumn().setData(uuid);
-                    transaction.add(op.update(qos)
-                            .where(extraQos.getUuidColumn().getSchema().opEqual(uuid)).build());
-                }
-                transaction.build();
+            Uuid operQosUuid = getQosEntryUuid(operNode.getQosEntries(), qosEntry.getQosId());
+            if (operQosUuid == null) {
+                UUID namedUuid = new UUID(SouthboundConstants.QOS_NAMED_UUID_PREFIX
+                        + TransactUtils.bytesToHexString(qosEntry.getQosId().getValue().getBytes()));
+                transaction.add(op.insert(qos).withId(namedUuid.toString())).build();
+                LOG.info("Added QoS Uuid: {} for node : {} ", namedUuid, operNode.getConnectionInfo());
+            } else {
+                UUID uuid = new UUID(operQosUuid.getValue());
+                Qos extraQos = TyperUtils.getTypedRowWrapper(
+                        transaction.getDatabaseSchema(), Qos.class, null);
+                extraQos.getUuidColumn().setData(uuid);
+                transaction.add(op.update(qos)
+                        .where(extraQos.getUuidColumn().getSchema().opEqual(uuid)).build());
+                LOG.info("Updated  QoS Uuid : {} for node : {} ", operQosUuid, operNode.getConnectionInfo());
             }
+            transaction.build();
         }
     }