Bug 7757 -Removing qos deprecations in carbon
[ovsdb.git] / southbound / southbound-impl / src / main / java / org / opendaylight / ovsdb / southbound / transactions / md / OvsdbQosUpdateCommand.java
index 7fff0ba220c12fb75413c958422d7e5f4e13f508..f14c11e9085bcb2c4d2a22c687b7e9f94b231986 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Intel Communications Systems, Inc. and others.  All rights reserved.
+ * Copyright © 2016, 2017 Intel Communications Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -8,13 +8,13 @@
 
 package org.opendaylight.ovsdb.southbound.transactions.md;
 
+import com.google.common.base.Optional;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 import java.util.Map.Entry;
-
+import java.util.Set;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.ovsdb.lib.message.TableUpdates;
@@ -23,19 +23,20 @@ import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
 import org.opendaylight.ovsdb.schema.openvswitch.Qos;
 import org.opendaylight.ovsdb.schema.openvswitch.Queue;
+import org.opendaylight.ovsdb.southbound.InstanceIdentifierCodec;
 import org.opendaylight.ovsdb.southbound.OvsdbConnectionInstance;
 import org.opendaylight.ovsdb.southbound.SouthboundConstants;
 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
 import org.opendaylight.ovsdb.southbound.SouthboundUtil;
+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.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
 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;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QosEntries;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QosEntriesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QosEntriesKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.Queues;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QueuesKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QosEntriesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.qos.entries.QosExternalIds;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.qos.entries.QosExternalIdsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.qos.entries.QosExternalIdsKey;
@@ -51,18 +52,19 @@ import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Optional;
-
 public class OvsdbQosUpdateCommand extends AbstractTransactionCommand {
     private static final Logger LOG = LoggerFactory.getLogger(OvsdbQosUpdateCommand.class);
 
+    private final InstanceIdentifierCodec instanceIdentifierCodec;
+
     private Map<UUID, Qos> updatedQosRows;
     private Map<UUID, Qos> oldQosRows;
     private Map<UUID, Queue> updatedQueueRows;
 
-    public OvsdbQosUpdateCommand(OvsdbConnectionInstance key,
+    public OvsdbQosUpdateCommand(InstanceIdentifierCodec instanceIdentifierCodec, OvsdbConnectionInstance key,
             TableUpdates updates, DatabaseSchema dbSchema) {
         super(key, updates, dbSchema);
+        this.instanceIdentifierCodec = instanceIdentifierCodec;
         updatedQosRows = TyperUtils.extractRowsUpdated(Qos.class,getUpdates(), getDbSchema());
         oldQosRows = TyperUtils.extractRowsOld(Qos.class, getUpdates(), getDbSchema());
         updatedQueueRows = TyperUtils.extractRowsUpdated(Queue.class, getUpdates(), getDbSchema());
@@ -76,7 +78,8 @@ public class OvsdbQosUpdateCommand extends AbstractTransactionCommand {
     }
 
     /**
-     * Update the QosEntries values after finding the related {@link OpenVSwitch} list.
+     * Update the QosEntries values after finding the related
+     * {@link org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch} list.
      * <p>
      * Qos and OpenVSwitch are independent tables in the Open_vSwitch schema
      * but the OVSDB yang model includes the Qos fields in the
@@ -86,23 +89,23 @@ public class OvsdbQosUpdateCommand extends AbstractTransactionCommand {
      * </p>
      *
      * @param transaction the {@link ReadWriteTransaction}
-     * @param updatedQosRows updated {@link Qos} rows
+     * @param newUpdatedQosRows updated {@link Qos} rows
 
      */
     private void updateQos(ReadWriteTransaction transaction,
-                                  Map<UUID, Qos> updatedQosRows) {
+                                  Map<UUID, Qos> newUpdatedQosRows) {
 
         final InstanceIdentifier<Node> nodeIId = getOvsdbConnectionInstance().getInstanceIdentifier();
         final Optional<Node> ovsdbNode = SouthboundUtil.readNode(transaction, nodeIId);
         if (ovsdbNode.isPresent()) {
-            for (Entry<UUID, Qos> entry : updatedQosRows.entrySet()) {
+            for (Entry<UUID, Qos> entry : newUpdatedQosRows.entrySet()) {
                 Qos qos = entry.getValue();
-                Qos oldQos = oldQosRows.get(entry.getKey());
                 QosEntriesBuilder qosEntryBuilder = new QosEntriesBuilder();
                 qosEntryBuilder.setQosId(new Uri(getQosId(qos)));
                 qosEntryBuilder.setQosUuid(new Uuid(entry.getKey().toString()));
                 qosEntryBuilder.setQosType(
-                        SouthboundMapper.createQosType(qos.getTypeColumn().getData().toString()));
+                        SouthboundMapper.createQosType(qos.getTypeColumn().getData()));
+                Qos oldQos = oldQosRows.get(entry.getKey());
                 setOtherConfig(transaction, qosEntryBuilder, oldQos, qos, nodeIId);
                 setExternalIds(transaction, qosEntryBuilder, oldQos, qos, nodeIId);
                 setQueueList(transaction, qosEntryBuilder, oldQos, qos, nodeIId, ovsdbNode.get());
@@ -118,24 +121,28 @@ public class OvsdbQosUpdateCommand extends AbstractTransactionCommand {
         }
     }
 
+    @SuppressWarnings("unchecked")
     private String getQosId(Qos qos) {
         if (qos.getExternalIdsColumn() != null
-                && qos.getExternalIdsColumn().getData() != null
-                && qos.getExternalIdsColumn().getData().containsKey(SouthboundConstants.IID_EXTERNAL_ID_KEY)) {
-            InstanceIdentifier<QosEntries> qosIid = (InstanceIdentifier<QosEntries>) SouthboundUtil.deserializeInstanceIdentifier(
-                    qos.getExternalIdsColumn().getData().get(SouthboundConstants.IID_EXTERNAL_ID_KEY));
-            if (qosIid != null) {
-                QosEntriesKey qosEntriesKey = qosIid.firstKeyOf(QosEntries.class);
-                if (qosEntriesKey != null) {
-                    return qosEntriesKey.getQosId().getValue();
+                && qos.getExternalIdsColumn().getData() != null) {
+            if (qos.getExternalIdsColumn().getData().containsKey(SouthboundConstants.IID_EXTERNAL_ID_KEY)) {
+                InstanceIdentifier<QosEntries> qosIid =
+                        (InstanceIdentifier<QosEntries>) instanceIdentifierCodec.bindingDeserializerOrNull(
+                                qos.getExternalIdsColumn().getData().get(SouthboundConstants.IID_EXTERNAL_ID_KEY));
+                if (qosIid != null) {
+                    QosEntriesKey qosEntriesKey = qosIid.firstKeyOf(QosEntries.class);
+                    if (qosEntriesKey != null) {
+                        return qosEntriesKey.getQosId().getValue();
+                    }
                 }
+            } else if (qos.getExternalIdsColumn().getData().containsKey(SouthboundConstants.QOS_ID_EXTERNAL_ID_KEY)) {
+                return qos.getExternalIdsColumn().getData().get(SouthboundConstants.QOS_ID_EXTERNAL_ID_KEY);
             }
         }
         return SouthboundConstants.QOS_URI_PREFIX + "://" + qos.getUuid().toString();
     }
 
-    private Queue getQueue(UUID queueUuid)
-    {
+    private Queue getQueue(UUID queueUuid) {
         for (Entry<UUID, Queue> entry : updatedQueueRows.entrySet()) {
             if (entry.getKey().equals(queueUuid)) {
                 return entry.getValue();
@@ -144,12 +151,13 @@ public class OvsdbQosUpdateCommand extends AbstractTransactionCommand {
         return null;
     }
 
+    @SuppressWarnings("unchecked")
     private InstanceIdentifier<Queues> getQueueIid(UUID queueUuid, Node ovsdbNode) {
         Queue queue = getQueue(queueUuid);
         if (queue != null && queue.getExternalIdsColumn() != null
                 && queue.getExternalIdsColumn().getData() != null
                 && queue.getExternalIdsColumn().getData().containsKey(SouthboundConstants.IID_EXTERNAL_ID_KEY)) {
-            return (InstanceIdentifier<Queues>) SouthboundUtil.deserializeInstanceIdentifier(
+            return (InstanceIdentifier<Queues>) instanceIdentifierCodec.bindingDeserializerOrNull(
                     queue.getExternalIdsColumn().getData().get(SouthboundConstants.IID_EXTERNAL_ID_KEY));
         } else {
             OvsdbNodeAugmentation node = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
@@ -312,12 +320,12 @@ public class OvsdbQosUpdateCommand extends AbstractTransactionCommand {
         for (Entry<Long, UUID> queueEntry : queueEntries) {
             InstanceIdentifier<Queues> queueIid = getQueueIid(queueEntry.getValue(), ovsdbNode);
             if (queueIid != null) {
-            newQueueList.add(
+                newQueueList.add(
                     new QueueListBuilder()
                     .setQueueNumber(queueEntry.getKey())
-                    .setQueueRef(new OvsdbQueueRef(queueIid))
-                    .setQueueUuid(new Uuid(queueEntry.getValue().toString())).build());
+                    .setQueueRef(new OvsdbQueueRef(queueIid)).build());
             }
+
         }
         qosEntryBuilder.setQueueList(newQueueList);
     }