/*
- * 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,
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;
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;
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());
}
/**
- * 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
* </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());
}
}
+ @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();
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);
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);
}