From: Tom Pantelis Date: Thu, 22 Mar 2018 16:24:47 +0000 (-0400) Subject: Fix findbugs violations in southbound-impl X-Git-Tag: release/fluorine~50 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=ee3bd23b9533d762c4ae58530397acd1a461ed6a;p=ovsdb.git Fix findbugs violations in southbound-impl - Method invokes inefficient Number constructor; use static valueOf instead - Inefficient use of keySet iterator instead of entrySet iterator - Reliance on default encoding - Method ignores exceptional return value - Should be a static inner class - Private method is never called - Method invokes inefficient Number constructor; use static valueOf instead - Return value of method without side effect is ignored - Result of integer multiplication cast to long - Dead store to local variable - Write to static field from instance method - Parameter must be non-null but is marked as nullable - Redundant nullcheck of value known to be non-null Change-Id: Ieba8b20d01a47d6b245bb2752f004aa18fd08469 Signed-off-by: Tom Pantelis --- diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionManager.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionManager.java index bfbb7964f..c92894de3 100644 --- a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionManager.java +++ b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionManager.java @@ -14,7 +14,7 @@ import com.google.common.base.Preconditions; import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; - +import com.google.common.util.concurrent.MoreExecutors; import java.net.ConnectException; import java.net.InetAddress; import java.net.UnknownHostException; @@ -26,7 +26,6 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import javax.annotation.Nonnull; -import javax.annotation.Nullable; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; import org.opendaylight.controller.md.sal.common.api.clustering.CandidateAlreadyRegisteredException; @@ -106,9 +105,8 @@ public class OvsdbConnectionManager implements OvsdbConnectionListener, AutoClos externalClient.getConnectionInfo().getRemotePort(), externalClient.getConnectionInfo().getLocalAddress(), externalClient.getConnectionInfo().getLocalPort()); - List databases = new ArrayList<>(); try { - databases = externalClient.getDatabases().get(DB_FETCH_TIMEOUT, TimeUnit.MILLISECONDS); + List databases = externalClient.getDatabases().get(DB_FETCH_TIMEOUT, TimeUnit.MILLISECONDS); if (databases.contains(SouthboundConstants.OPEN_V_SWITCH)) { OvsdbConnectionInstance client = connectedButCallBacksNotRegistered(externalClient); // Register Cluster Ownership for ConnectionInfo @@ -584,7 +582,7 @@ public class OvsdbConnectionManager implements OvsdbConnectionListener, AutoClos } Futures.addCallback(readNodeFuture, new FutureCallback>() { @Override - public void onSuccess(@Nullable Optional node) { + public void onSuccess(@Nonnull Optional node) { if (node.isPresent()) { LOG.info("Disconnected/Failed connection {} was controller initiated, attempting " + "reconnection", ovsdbNode.getConnectionInfo()); @@ -600,7 +598,7 @@ public class OvsdbConnectionManager implements OvsdbConnectionListener, AutoClos public void onFailure(Throwable throwable) { LOG.warn("Read Config/DS for Node failed! {}", iid, throwable); } - }); + }, MoreExecutors.directExecutor()); break; } default: @@ -616,7 +614,7 @@ public class OvsdbConnectionManager implements OvsdbConnectionListener, AutoClos reconciliationManager.enqueue(task); } - private class OvsdbDeviceEntityOwnershipListener implements EntityOwnershipListener { + private static class OvsdbDeviceEntityOwnershipListener implements EntityOwnershipListener { private final OvsdbConnectionManager cm; private final EntityOwnershipListenerRegistration listenerRegistration; diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundProvider.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundProvider.java index cd712e292..e1dc95bfa 100644 --- a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundProvider.java +++ b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundProvider.java @@ -9,12 +9,11 @@ package org.opendaylight.ovsdb.southbound; import com.google.common.base.Optional; import com.google.common.util.concurrent.CheckedFuture; - +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.Collection; import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicBoolean; - import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier; @@ -27,7 +26,6 @@ import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipC import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListener; import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListenerRegistration; import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService; -import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipState; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; @@ -53,6 +51,8 @@ public class SouthboundProvider implements ClusteredDataTreeChangeListener operTopologyRegistration; public SouthboundProvider(final DataBroker dataBroker, @@ -97,7 +97,6 @@ public class SouthboundProvider implements ClusteredDataTreeChangeListener ownershipStateOpt = entityOwnershipService.getOwnershipState(instanceEntity); registration = entityOwnershipService.registerCandidate(instanceEntity); } catch (CandidateAlreadyRegisteredException e) { LOG.warn("OVSDB Southbound Provider instance entity {} was already " @@ -107,7 +106,7 @@ public class SouthboundProvider implements ClusteredDataTreeChangeListener treeId = - new DataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, path); + new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, path); LOG.trace("Registering listener for path {}", treeId); operTopologyRegistration = db.registerDataTreeChangeListener(treeId, this); @@ -179,7 +178,7 @@ public class SouthboundProvider implements ClusteredDataTreeChangeListener, Node> nodeCreateOrUpdate = TransactUtils.extractCreatedOrUpdatedOrRemoved(changes, Node.class); - if (nodeCreateOrUpdate != null) { - for (Entry, Node> entry: nodeCreateOrUpdate.entrySet()) { - CheckedFuture, ReadFailedException> nodeFuture = - transaction.read(LogicalDatastoreType.OPERATIONAL, entry.getKey()); - try { - Optional nodeOptional = nodeFuture.get(); - if (nodeOptional.isPresent()) { - operationalNodes.put(entry.getKey(), nodeOptional.get()); - } - } catch (InterruptedException | ExecutionException e) { - LOG.warn("Error reading from datastore",e); + for (Entry, Node> entry: nodeCreateOrUpdate.entrySet()) { + CheckedFuture, ReadFailedException> nodeFuture = + transaction.read(LogicalDatastoreType.OPERATIONAL, entry.getKey()); + try { + Optional nodeOptional = nodeFuture.get(); + if (nodeOptional.isPresent()) { + operationalNodes.put(entry.getKey(), nodeOptional.get()); } + } catch (InterruptedException | ExecutionException e) { + LOG.warn("Error reading from datastore",e); } } } diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/ovsdb/transact/QosUpdateCommand.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/ovsdb/transact/QosUpdateCommand.java index cea65595d..104ef77b4 100644 --- a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/ovsdb/transact/QosUpdateCommand.java +++ b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/ovsdb/transact/QosUpdateCommand.java @@ -7,6 +7,7 @@ */ package org.opendaylight.ovsdb.southbound.ovsdb.transact; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.opendaylight.ovsdb.lib.operations.Operations.op; import java.util.Collection; @@ -115,8 +116,8 @@ public class QosUpdateCommand implements TransactCommand { 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(); + + TransactUtils.bytesToHexString(qosEntry.getQosId().getValue().getBytes(UTF_8))); + transaction.add(op.insert(qos).withId(namedUuid.toString())); LOG.info("Added QoS Uuid: {} for node : {} ", namedUuid, operNode.getConnectionInfo()); } else { UUID uuid = new UUID(operQosUuid.getValue()); @@ -127,7 +128,6 @@ public class QosUpdateCommand implements TransactCommand { .where(extraQos.getUuidColumn().getSchema().opEqual(uuid)).build()); LOG.info("Updated QoS Uuid : {} for node : {} ", operQosUuid, operNode.getConnectionInfo()); } - transaction.build(); } } @@ -141,7 +141,7 @@ public class QosUpdateCommand implements TransactCommand { } } return SouthboundConstants.QUEUE_NAMED_UUID_PREFIX - + TransactUtils.bytesToHexString(queueKey.getQueueId().getValue().getBytes()); + + TransactUtils.bytesToHexString(queueKey.getQueueId().getValue().getBytes(UTF_8)); } private Uuid getQosEntryUuid(List operQosEntries, Uri qosId) { diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/ovsdb/transact/QueueUpdateCommand.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/ovsdb/transact/QueueUpdateCommand.java index 1d66bb1f8..5c4cae370 100644 --- a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/ovsdb/transact/QueueUpdateCommand.java +++ b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/ovsdb/transact/QueueUpdateCommand.java @@ -7,6 +7,7 @@ */ package org.opendaylight.ovsdb.southbound.ovsdb.transact; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.opendaylight.ovsdb.lib.operations.Operations.op; import java.util.Collection; @@ -16,7 +17,6 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; - import org.opendaylight.controller.md.sal.binding.api.DataTreeModification; import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent; import org.opendaylight.ovsdb.lib.notation.UUID; @@ -73,7 +73,7 @@ public class QueueUpdateCommand implements TransactCommand { if (queueEntry.getDscp() != null) { try { Set dscpSet = new HashSet<>(); - if (dscpSet.add(new Long(queueEntry.getDscp().toString()))) { + if (dscpSet.add(Long.valueOf(queueEntry.getDscp().toString()))) { queue.setDscp(dscpSet); } } catch (NumberFormatException e) { @@ -107,8 +107,8 @@ public class QueueUpdateCommand implements TransactCommand { Uuid operQueueUuid = getQueueEntryUuid(operNode.getQueues(), queueEntry.getQueueId()); if (operQueueUuid == null) { UUID namedUuid = new UUID(SouthboundConstants.QUEUE_NAMED_UUID_PREFIX - + TransactUtils.bytesToHexString(queueEntry.getQueueId().getValue().getBytes())); - transaction.add(op.insert(queue).withId(namedUuid.toString())).build(); + + TransactUtils.bytesToHexString(queueEntry.getQueueId().getValue().getBytes(UTF_8))); + transaction.add(op.insert(queue).withId(namedUuid.toString())); LOG.info("Added queue Uuid : {} for Ovsdb Node : {}", namedUuid, operNode); } else { @@ -121,7 +121,6 @@ public class QueueUpdateCommand implements TransactCommand { LOG.info("Updated queue entries: {} for Ovsdb Node : {}", queue, operNode); } - transaction.build(); } } diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/ovsdb/transact/TerminationPointUpdateCommand.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/ovsdb/transact/TerminationPointUpdateCommand.java index b027cb1ab..c1e252569 100644 --- a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/ovsdb/transact/TerminationPointUpdateCommand.java +++ b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/ovsdb/transact/TerminationPointUpdateCommand.java @@ -7,6 +7,7 @@ */ package org.opendaylight.ovsdb.southbound.ovsdb.transact; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.opendaylight.ovsdb.lib.operations.Operations.op; import static org.opendaylight.ovsdb.southbound.SouthboundUtil.schemaMismatchLog; @@ -184,7 +185,7 @@ public class TerminationPointUpdateCommand implements TransactCommand { } if (uuidSet.size() == 0) { uuidSet.add(new UUID(SouthboundConstants.QOS_NAMED_UUID_PREFIX - + TransactUtils.bytesToHexString(qosId.getValue().getBytes()))); + + TransactUtils.bytesToHexString(qosId.getValue().getBytes(UTF_8)))); } } port.setQos(uuidSet); diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/reconciliation/ReconciliationManager.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/reconciliation/ReconciliationManager.java index 7b4292555..95afbd6ca 100644 --- a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/reconciliation/ReconciliationManager.java +++ b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/reconciliation/ReconciliationManager.java @@ -13,7 +13,6 @@ import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.google.common.util.concurrent.UncheckedExecutionException; - import java.util.Collection; import java.util.List; import java.util.Map; @@ -24,9 +23,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; - import javax.annotation.Nonnull; - import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier; @@ -263,11 +260,11 @@ public class ReconciliationManager implements AutoCloseable { } } - private class NodeConnectionMetadata { - Node node; - InstanceIdentifier nodeIid; - OvsdbConnectionManager connectionManager; - OvsdbConnectionInstance connectionInstance; + private static class NodeConnectionMetadata { + private final Node node; + private InstanceIdentifier nodeIid; + private final OvsdbConnectionManager connectionManager; + private final OvsdbConnectionInstance connectionInstance; NodeConnectionMetadata(Node node, OvsdbConnectionManager connectionManager, diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/reconciliation/connection/ConnectionReconciliationTask.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/reconciliation/connection/ConnectionReconciliationTask.java index 942e2e0cb..3d8f98447 100644 --- a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/reconciliation/connection/ConnectionReconciliationTask.java +++ b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/reconciliation/connection/ConnectionReconciliationTask.java @@ -25,10 +25,10 @@ public class ConnectionReconciliationTask extends ReconciliationTask { private static final Logger LOG = LoggerFactory.getLogger(ConnectionReconciliationTask.class); - private static final int RETRY_INTERVAL_FACTOR = 10000; + private static final long RETRY_INTERVAL_FACTOR = 10000; private static final int MAX_ATTEMPT = 10; - private AtomicInteger connectionAttempt = new AtomicInteger(0); + private final AtomicInteger connectionAttempt = new AtomicInteger(0); public ConnectionReconciliationTask(ReconciliationManager reconciliationManager, OvsdbConnectionManager connectionManager, InstanceIdentifier nodeIid, DataObject configData) { diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OpenVSwitchUpdateCommand.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OpenVSwitchUpdateCommand.java index 5905a061a..accb591c1 100644 --- a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OpenVSwitchUpdateCommand.java +++ b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OpenVSwitchUpdateCommand.java @@ -109,10 +109,10 @@ public class OpenVSwitchUpdateCommand extends AbstractTransactionCommand { oldOtherConfigs = oldEntry.getOtherConfigColumn().getData(); } - if ((oldOtherConfigs != null) && (!oldOtherConfigs.isEmpty())) { + if (oldOtherConfigs != null && !oldOtherConfigs.isEmpty()) { removeOldConfigs(transaction, oldOtherConfigs, openVSwitch); } - if ((otherConfigs != null) && (!otherConfigs.isEmpty())) { + if (otherConfigs != null && !otherConfigs.isEmpty()) { setNewOtherConfigs(ovsdbNodeBuilder, otherConfigs); } } @@ -135,11 +135,10 @@ public class OpenVSwitchUpdateCommand extends AbstractTransactionCommand { private void setNewOtherConfigs(OvsdbNodeAugmentationBuilder ovsdbNodeBuilder, Map otherConfigs) { - Set otherConfigKeys = otherConfigs.keySet(); List otherConfigsList = new ArrayList<>(); - String otherConfigValue; - for (String otherConfigKey : otherConfigKeys) { - otherConfigValue = otherConfigs.get(otherConfigKey); + for (Entry entry : otherConfigs.entrySet()) { + String otherConfigKey = entry.getKey(); + String otherConfigValue = entry.getValue(); if (otherConfigKey != null && otherConfigValue != null) { otherConfigsList.add(new OpenvswitchOtherConfigsBuilder().setOtherConfigKey(otherConfigKey) .setOtherConfigValue(otherConfigValue).build()); @@ -159,7 +158,7 @@ public class OpenVSwitchUpdateCommand extends AbstractTransactionCommand { if (oldEntry != null && oldEntry.getExternalIdsColumn() != null) { oldExternalIds = oldEntry.getExternalIdsColumn().getData(); } - if ((oldExternalIds == null) || oldExternalIds.isEmpty()) { + if (oldExternalIds == null || oldExternalIds.isEmpty()) { setNewExternalIds(ovsdbNodeBuilder, externalIds); } else if (externalIds != null && !externalIds.isEmpty()) { removeExternalIds(transaction, oldExternalIds, openVSwitch); @@ -185,11 +184,10 @@ public class OpenVSwitchUpdateCommand extends AbstractTransactionCommand { private void setNewExternalIds(OvsdbNodeAugmentationBuilder ovsdbNodeBuilder, Map externalIds) { - Set externalIdKeys = externalIds.keySet(); List externalIdsList = new ArrayList<>(); - String externalIdValue; - for (String externalIdKey : externalIdKeys) { - externalIdValue = externalIds.get(externalIdKey); + for (Entry entry : externalIds.entrySet()) { + String externalIdKey = entry.getKey(); + String externalIdValue = entry.getValue(); if (externalIdKey != null && externalIdValue != null) { externalIdsList.add(new OpenvswitchExternalIdsBuilder().setExternalIdKey(externalIdKey) .setExternalIdValue(externalIdValue).build()); diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbAutoAttachUpdateCommand.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbAutoAttachUpdateCommand.java index 57bb97001..5ab23ff8a 100644 --- a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbAutoAttachUpdateCommand.java +++ b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbAutoAttachUpdateCommand.java @@ -13,7 +13,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; 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.controller.md.sal.common.api.data.ReadFailedException; @@ -42,8 +41,8 @@ import org.slf4j.LoggerFactory; public class OvsdbAutoAttachUpdateCommand extends AbstractTransactionCommand { private static final Logger LOG = LoggerFactory.getLogger(OvsdbAutoAttachUpdateCommand.class); - private Map updatedAutoAttachRows; - private Map oldAutoAttachRows; + private final Map updatedAutoAttachRows; + private final Map oldAutoAttachRows; public OvsdbAutoAttachUpdateCommand(OvsdbConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) { @@ -99,7 +98,7 @@ public class OvsdbAutoAttachUpdateCommand extends AbstractTransactionCommand { } final AutoattachBuilder autoAttachBuilder = - (currentAutoattach != null) ? new AutoattachBuilder(currentAutoattach) + currentAutoattach != null ? new AutoattachBuilder(currentAutoattach) : new AutoattachBuilder() .setAutoattachUuid(new Uuid(entry.getKey().toString())) .setAutoattachId(uri) @@ -138,10 +137,10 @@ public class OvsdbAutoAttachUpdateCommand extends AbstractTransactionCommand { private void setMappings(AutoattachBuilder autoAttachBuilder, AutoAttach autoAttach) { final Map mappings = autoAttach.getMappingsColumn().getData(); - final Set mappingsKeys = mappings.keySet(); final List mappingsList = new ArrayList<>(); - for (final Long mappingsKey : mappingsKeys) { - final Integer mappingsValue = new Integer(mappings.get(mappingsKey).toString()); + for (final Entry entry : mappings.entrySet()) { + final Long mappingsKey = entry.getKey(); + final Integer mappingsValue = Integer.valueOf(entry.getValue().intValue()); if (mappingsKey != null) { mappingsList.add(new MappingsBuilder() .setKey(new MappingsKey(mappingsKey)) diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbBridgeUpdateCommand.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbBridgeUpdateCommand.java index 1017f8cd6..a7ef18e2e 100644 --- a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbBridgeUpdateCommand.java +++ b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbBridgeUpdateCommand.java @@ -38,7 +38,6 @@ 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.IpAddress; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber; 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.DatapathId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation; @@ -72,8 +71,8 @@ import org.slf4j.LoggerFactory; public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand { private static final Logger LOG = LoggerFactory.getLogger(OvsdbBridgeUpdateCommand.class); private final InstanceIdentifierCodec instanceIdentifierCodec; - private Map updatedBridgeRows; - private Map oldBridgeRows; + private final Map updatedBridgeRows; + private final Map oldBridgeRows; public OvsdbBridgeUpdateCommand(InstanceIdentifierCodec instanceIdentifierCodec, OvsdbConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) { @@ -289,11 +288,10 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand { Map otherConfigs = bridge .getOtherConfigColumn().getData(); if (otherConfigs != null && !otherConfigs.isEmpty()) { - Set otherConfigKeys = otherConfigs.keySet(); List otherConfigList = new ArrayList<>(); - String otherConfigValue; - for (String otherConfigKey : otherConfigKeys) { - otherConfigValue = otherConfigs.get(otherConfigKey); + for (Entry entry : otherConfigs.entrySet()) { + String otherConfigKey = entry.getKey(); + String otherConfigValue = entry.getValue(); if (otherConfigKey != null && otherConfigValue != null) { otherConfigList.add(new BridgeOtherConfigsBuilder() .setBridgeOtherConfigKey(otherConfigKey) @@ -310,11 +308,10 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand { Map externalIds = bridge.getExternalIdsColumn() .getData(); if (externalIds != null && !externalIds.isEmpty()) { - Set externalIdKeys = externalIds.keySet(); List externalIdsList = new ArrayList<>(); - String externalIdValue; - for (String externalIdKey : externalIdKeys) { - externalIdValue = externalIds.get(externalIdKey); + for (Entry entry : externalIds.entrySet()) { + String externalIdKey = entry.getKey(); + String externalIdValue = entry.getValue(); if (externalIdKey != null && externalIdValue != null) { externalIdsList.add(new BridgeExternalIdsBuilder() .setBridgeExternalIdKey(externalIdKey) @@ -328,9 +325,9 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand { private void setProtocol(OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder, Bridge bridge) { - if (SouthboundMapper.createMdsalProtocols(bridge) != null - && SouthboundMapper.createMdsalProtocols(bridge).size() > 0) { - ovsdbBridgeAugmentationBuilder.setProtocolEntry(SouthboundMapper.createMdsalProtocols(bridge)); + final List protocols = SouthboundMapper.createMdsalProtocols(bridge); + if (!protocols.isEmpty()) { + ovsdbBridgeAugmentationBuilder.setProtocolEntry(protocols); } } @@ -362,15 +359,12 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand { && controllerEntry.isIsConnected() != null && controllerEntry.isIsConnected()) { String [] controllerTarget = controllerEntry.getTarget().getValue().split(":"); IpAddress bridgeControllerIpAddress = null; - PortNumber bridgeControllerPortNumber = null; for (String targetElement : controllerTarget) { if (InetAddresses.isInetAddress(targetElement)) { bridgeControllerIpAddress = new IpAddress(targetElement.toCharArray()); continue; } if (NumberUtils.isNumber(targetElement)) { - bridgeControllerPortNumber = new PortNumber( - Integer.valueOf(String.valueOf(targetElement))); continue; } } diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbPortRemoveCommand.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbPortRemoveCommand.java index bf26be413..b34b04eb6 100644 --- a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbPortRemoveCommand.java +++ b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbPortRemoveCommand.java @@ -10,7 +10,7 @@ package org.opendaylight.ovsdb.southbound.transactions.md; import java.util.Collection; import java.util.Map; - +import java.util.Map.Entry; 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; @@ -59,11 +59,12 @@ public class OvsdbPortRemoveCommand extends AbstractTransactionCommand { continue; } Bridge updatedBridgeData = null; - for (UUID bridgeUuid : bridgeUpdatedOldRows.keySet()) { - Bridge oldBridgeData = bridgeUpdatedOldRows.get(bridgeUuid); + for (Entry entry : bridgeUpdatedOldRows.entrySet()) { + UUID bridgeUuid = entry.getKey(); + Bridge oldBridgeData = entry.getValue(); if (oldBridgeData.getPortsColumn() != null && oldBridgeData.getPortsColumn().getData().contains(port.getUuidColumn().getData()) - && (! bridgeUpdatedRows.isEmpty())) { + && ! bridgeUpdatedRows.isEmpty()) { updatedBridgeData = bridgeUpdatedRows.get(bridgeUuid); break; } diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbPortUpdateCommand.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbPortUpdateCommand.java index 591921aef..ac9ace2f2 100644 --- a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbPortUpdateCommand.java +++ b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbPortUpdateCommand.java @@ -132,7 +132,6 @@ public class OvsdbPortUpdateCommand extends AbstractTransactionCommand { bridgeIid = getTerminationPointBridge(transaction, node, portName); } if (bridgeIid.isPresent()) { - NodeId bridgeId = SouthboundMapper.createManagedNodeId(bridgeIid.get()); TerminationPointKey tpKey = new TerminationPointKey(new TpId(portName)); TerminationPointBuilder tpBuilder = new TerminationPointBuilder(); tpBuilder.setKey(tpKey); @@ -220,8 +219,9 @@ public class OvsdbPortUpdateCommand extends AbstractTransactionCommand { } private Optional> getTerminationPointBridge(UUID portUuid) { - for (UUID bridgeUuid : this.bridgeUpdatedRows.keySet()) { - if (this.bridgeUpdatedRows.get(bridgeUuid).getPortsColumn().getData().contains(portUuid)) { + for (Entry entry : this.bridgeUpdatedRows.entrySet()) { + UUID bridgeUuid = entry.getKey(); + if (entry.getValue().getPortsColumn().getData().contains(portUuid)) { return Optional.of( SouthboundMapper.createInstanceIdentifier(instanceIdentifierCodec, getOvsdbConnectionInstance(), this.bridgeUpdatedRows.get(bridgeUuid))); @@ -366,7 +366,7 @@ public class OvsdbPortUpdateCommand extends AbstractTransactionCommand { InstanceIdentifier oldPortQosIid = tpPath .augmentation(OvsdbTerminationPointAugmentation.class) .child(QosEntry.class, - new QosEntryKey(new Long(SouthboundConstants.PORT_QOS_LIST_KEY))); + new QosEntryKey(Long.valueOf(SouthboundConstants.PORT_QOS_LIST_KEY))); transaction.delete(LogicalDatastoreType.OPERATIONAL, oldPortQosIid); } } @@ -378,7 +378,7 @@ public class OvsdbPortUpdateCommand extends AbstractTransactionCommand { List qosList = new ArrayList<>(); OvsdbQosRef qosRef = new OvsdbQosRef(qosIid); qosList.add(new QosEntryBuilder() - .setKey(new QosEntryKey(new Long(SouthboundConstants.PORT_QOS_LIST_KEY))) + .setKey(new QosEntryKey(Long.valueOf(SouthboundConstants.PORT_QOS_LIST_KEY))) .setQosRef(qosRef).build()); ovsdbTerminationPointBuilder.setQosEntry(qosList); } @@ -480,12 +480,10 @@ public class OvsdbPortUpdateCommand extends AbstractTransactionCommand { Map interfaceExternalIds = interf.getExternalIdsColumn().getData(); if (interfaceExternalIds != null && !interfaceExternalIds.isEmpty()) { - Set externalIdKeys = interfaceExternalIds.keySet(); - List externalIdsList = - new ArrayList<>(); - String externalIdValue; - for (String externalIdKey : externalIdKeys) { - externalIdValue = interfaceExternalIds.get(externalIdKey); + List externalIdsList = new ArrayList<>(); + for (Entry entry : interfaceExternalIds.entrySet()) { + String externalIdKey = entry.getKey(); + String externalIdValue = entry.getValue(); if (externalIdKey != null && externalIdValue != null) { externalIdsList.add(new InterfaceExternalIdsBuilder() .setExternalIdKey(externalIdKey) @@ -501,11 +499,10 @@ public class OvsdbPortUpdateCommand extends AbstractTransactionCommand { Map portExternalIds = port.getExternalIdsColumn().getData(); if (portExternalIds != null && !portExternalIds.isEmpty()) { - Set externalIdKeys = portExternalIds.keySet(); List externalIdsList = new ArrayList<>(); - String externalIdValue; - for (String externalIdKey : externalIdKeys) { - externalIdValue = portExternalIds.get(externalIdKey); + for (Entry entry : portExternalIds.entrySet()) { + String externalIdKey = entry.getKey(); + String externalIdValue = entry.getValue(); if (externalIdKey != null && externalIdValue != null) { externalIdsList.add(new PortExternalIdsBuilder() .setExternalIdKey(externalIdKey) @@ -522,12 +519,11 @@ public class OvsdbPortUpdateCommand extends AbstractTransactionCommand { Map optionsMap = interf.getOptionsColumn().getData(); if (optionsMap != null && !optionsMap.isEmpty()) { List options = new ArrayList<>(); - String optionsValueString; - OptionsKey optionsKey; - for (String optionsKeyString : optionsMap.keySet()) { - optionsValueString = optionsMap.get(optionsKeyString); + for (Entry entry : optionsMap.entrySet()) { + String optionsKeyString = entry.getKey(); + String optionsValueString = entry.getValue(); if (optionsKeyString != null && optionsValueString != null) { - optionsKey = new OptionsKey(optionsKeyString); + OptionsKey optionsKey = new OptionsKey(optionsKeyString); options.add(new OptionsBuilder() .setKey(optionsKey) .setValue(optionsValueString).build()); @@ -543,9 +539,9 @@ public class OvsdbPortUpdateCommand extends AbstractTransactionCommand { Map portOtherConfigMap = port.getOtherConfigColumn().getData(); if (portOtherConfigMap != null && !portOtherConfigMap.isEmpty()) { List portOtherConfigs = new ArrayList<>(); - String portOtherConfigValueString; - for (String portOtherConfigKeyString : portOtherConfigMap.keySet()) { - portOtherConfigValueString = portOtherConfigMap.get(portOtherConfigKeyString); + for (Entry entry : portOtherConfigMap.entrySet()) { + String portOtherConfigKeyString = entry.getKey(); + String portOtherConfigValueString = entry.getValue(); if (portOtherConfigKeyString != null && portOtherConfigValueString != null) { portOtherConfigs.add(new PortOtherConfigsBuilder() .setOtherConfigKey(portOtherConfigKeyString) @@ -563,8 +559,9 @@ public class OvsdbPortUpdateCommand extends AbstractTransactionCommand { Map interfaceLldpMap = interf.getLldpColumn().getData(); if (interfaceLldpMap != null && !interfaceLldpMap.isEmpty()) { List interfaceLldpList = new ArrayList<>(); - for (String interfaceLldpKeyString : interfaceLldpMap.keySet()) { - String interfaceLldpValueString = interfaceLldpMap.get(interfaceLldpKeyString); + for (Entry entry : interfaceLldpMap.entrySet()) { + String interfaceLldpKeyString = entry.getKey(); + String interfaceLldpValueString = entry.getValue(); if (interfaceLldpKeyString != null && interfaceLldpValueString != null) { interfaceLldpList.add(new InterfaceLldpBuilder() .setKey(new InterfaceLldpKey(interfaceLldpKeyString)) @@ -586,9 +583,9 @@ public class OvsdbPortUpdateCommand extends AbstractTransactionCommand { Map interfaceOtherConfigMap = interf.getOtherConfigColumn().getData(); if (interfaceOtherConfigMap != null && !interfaceOtherConfigMap.isEmpty()) { List interfaceOtherConfigs = new ArrayList<>(); - String interfaceOtherConfigValueString; - for (String interfaceOtherConfigKeyString : interfaceOtherConfigMap.keySet()) { - interfaceOtherConfigValueString = interfaceOtherConfigMap.get(interfaceOtherConfigKeyString); + for (Entry entry : interfaceOtherConfigMap.entrySet()) { + String interfaceOtherConfigKeyString = entry.getKey(); + String interfaceOtherConfigValueString = entry.getValue(); if (interfaceOtherConfigKeyString != null && interfaceOtherConfigValueString != null) { interfaceOtherConfigs.add(new InterfaceOtherConfigsBuilder() .setOtherConfigKey(interfaceOtherConfigKeyString) @@ -606,8 +603,9 @@ public class OvsdbPortUpdateCommand extends AbstractTransactionCommand { Map interfaceBfdStatusMap = interf.getBfdStatusColumn().getData(); if (interfaceBfdStatusMap != null && !interfaceBfdStatusMap.isEmpty()) { List interfaceBfdStatusList = new ArrayList<>(); - for (String interfaceBfdStatusKeyString : interfaceBfdStatusMap.keySet()) { - String interfaceBfdStatusValueString = interfaceBfdStatusMap.get(interfaceBfdStatusKeyString); + for (Entry entry : interfaceBfdStatusMap.entrySet()) { + String interfaceBfdStatusKeyString = entry.getKey(); + String interfaceBfdStatusValueString = entry.getValue(); if (interfaceBfdStatusKeyString != null && interfaceBfdStatusValueString != null) { interfaceBfdStatusList.add(new InterfaceBfdStatusBuilder() .setKey(new InterfaceBfdStatusKey(interfaceBfdStatusKeyString)) @@ -630,8 +628,9 @@ public class OvsdbPortUpdateCommand extends AbstractTransactionCommand { Map interfaceBfdMap = interf.getBfdColumn().getData(); if (interfaceBfdMap != null && !interfaceBfdMap.isEmpty()) { List interfaceBfdList = new ArrayList<>(); - for (String interfaceBfdKeyString : interfaceBfdMap.keySet()) { - String interfaceBfdValueString = interfaceBfdMap.get(interfaceBfdKeyString); + for (Entry entry : interfaceBfdMap.entrySet()) { + String interfaceBfdKeyString = entry.getKey(); + String interfaceBfdValueString = entry.getValue(); if (interfaceBfdKeyString != null && interfaceBfdValueString != null) { interfaceBfdList.add(new InterfaceBfdBuilder() .setKey(new InterfaceBfdKey(interfaceBfdKeyString)) diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbQosUpdateCommand.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbQosUpdateCommand.java index f14c11e90..ed9857c21 100644 --- a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbQosUpdateCommand.java +++ b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbQosUpdateCommand.java @@ -57,9 +57,9 @@ public class OvsdbQosUpdateCommand extends AbstractTransactionCommand { private final InstanceIdentifierCodec instanceIdentifierCodec; - private Map updatedQosRows; - private Map oldQosRows; - private Map updatedQueueRows; + private final Map updatedQosRows; + private final Map oldQosRows; + private final Map updatedQueueRows; public OvsdbQosUpdateCommand(InstanceIdentifierCodec instanceIdentifierCodec, OvsdbConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) { @@ -190,7 +190,7 @@ public class OvsdbQosUpdateCommand extends AbstractTransactionCommand { if (oldQos != null && oldQos.getOtherConfigColumn() != null) { oldOtherConfigs = oldQos.getOtherConfigColumn().getData(); } - if ((oldOtherConfigs != null) && !oldOtherConfigs.isEmpty()) { + if (oldOtherConfigs != null && !oldOtherConfigs.isEmpty()) { removeOldConfigs(transaction, qosEntryBuilder, oldOtherConfigs, qos, nodeIId); } if (otherConfigs != null && !otherConfigs.isEmpty()) { @@ -215,11 +215,10 @@ public class OvsdbQosUpdateCommand extends AbstractTransactionCommand { private void setNewOtherConfigs(QosEntriesBuilder qosEntryBuilder, Map otherConfig) { - Set otherConfigKeys = otherConfig.keySet(); List otherConfigList = new ArrayList<>(); - String otherConfigValue; - for (String otherConfigKey : otherConfigKeys) { - otherConfigValue = otherConfig.get(otherConfigKey); + for (Entry entry : otherConfig.entrySet()) { + String otherConfigKey = entry.getKey(); + String otherConfigValue = entry.getValue(); if (otherConfigKey != null && otherConfigValue != null) { otherConfigList.add(new QosOtherConfigBuilder().setOtherConfigKey(otherConfigKey) .setOtherConfigValue(otherConfigValue).build()); @@ -240,7 +239,7 @@ public class OvsdbQosUpdateCommand extends AbstractTransactionCommand { if (oldQos != null && oldQos.getExternalIdsColumn() != null) { oldExternalIds = oldQos.getExternalIdsColumn().getData(); } - if ((oldExternalIds != null) && !oldExternalIds.isEmpty()) { + if (oldExternalIds != null && !oldExternalIds.isEmpty()) { removeOldExternalIds(transaction, qosEntryBuilder, oldExternalIds, qos, nodeIId); } if (externalIds != null && !externalIds.isEmpty()) { @@ -265,11 +264,10 @@ public class OvsdbQosUpdateCommand extends AbstractTransactionCommand { private void setNewExternalIds(QosEntriesBuilder qosEntryBuilder, Map externalIds) { - Set externalIdsKeys = externalIds.keySet(); List externalIdsList = new ArrayList<>(); - String extIdValue; - for (String extIdKey : externalIdsKeys) { - extIdValue = externalIds.get(extIdKey); + for (Entry entry : externalIds.entrySet()) { + String extIdKey = entry.getKey(); + String extIdValue = entry.getValue(); if (extIdKey != null && extIdValue != null) { externalIdsList.add(new QosExternalIdsBuilder().setQosExternalIdKey(extIdKey) .setQosExternalIdValue(extIdValue).build()); @@ -290,7 +288,7 @@ public class OvsdbQosUpdateCommand extends AbstractTransactionCommand { if (oldQos != null && oldQos.getQueuesColumn() != null) { oldQueueList = oldQos.getQueuesColumn().getData(); } - if ((oldQueueList != null) && !oldQueueList.isEmpty()) { + if (oldQueueList != null && !oldQueueList.isEmpty()) { removeOldQueues(transaction, qosEntryBuilder, oldQueueList, qos, nodeIId); } if (queueList != null && !queueList.isEmpty()) { @@ -307,8 +305,7 @@ public class OvsdbQosUpdateCommand extends AbstractTransactionCommand { Collection queueListKeys = oldQueueList.keySet(); for (Long queueListKey : queueListKeys) { KeyedInstanceIdentifier otherIId = - qosIId - .child(QueueList.class, new QueueListKey(new Long(queueListKey.toString()))); + qosIId.child(QueueList.class, new QueueListKey(Long.valueOf(queueListKey.toString()))); transaction.delete(LogicalDatastoreType.OPERATIONAL, otherIId); } } diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbQueueUpdateCommand.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbQueueUpdateCommand.java index cb33cf69c..0ba2bff27 100644 --- a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbQueueUpdateCommand.java +++ b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbQueueUpdateCommand.java @@ -49,8 +49,8 @@ public class OvsdbQueueUpdateCommand extends AbstractTransactionCommand { private final InstanceIdentifierCodec instanceIdentifierCodec; - private Map updatedQueueRows; - private Map oldQueueRows; + private final Map updatedQueueRows; + private final Map oldQueueRows; public OvsdbQueueUpdateCommand(InstanceIdentifierCodec instanceIdentifierCodec, OvsdbConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) { @@ -142,7 +142,7 @@ public class OvsdbQueueUpdateCommand extends AbstractTransactionCommand { if (oldQueue != null && oldQueue.getOtherConfigColumn() != null) { oldOtherConfigs = oldQueue.getOtherConfigColumn().getData(); } - if ((oldOtherConfigs != null) && !oldOtherConfigs.isEmpty()) { + if (oldOtherConfigs != null && !oldOtherConfigs.isEmpty()) { removeOldConfigs(transaction, queuesBuilder, oldOtherConfigs, queue, nodeIId); } if (otherConfigs != null && !otherConfigs.isEmpty()) { @@ -167,11 +167,10 @@ public class OvsdbQueueUpdateCommand extends AbstractTransactionCommand { private void setNewOtherConfigs(QueuesBuilder queuesBuilder, Map otherConfig) { - Set otherConfigKeys = otherConfig.keySet(); List otherConfigList = new ArrayList<>(); - String otherConfigValue; - for (String otherConfigKey : otherConfigKeys) { - otherConfigValue = otherConfig.get(otherConfigKey); + for (Entry entry : otherConfig.entrySet()) { + String otherConfigKey = entry.getKey(); + String otherConfigValue = entry.getValue(); if (otherConfigKey != null && otherConfigValue != null) { otherConfigList.add(new QueuesOtherConfigBuilder().setQueueOtherConfigKey(otherConfigKey) .setQueueOtherConfigValue(otherConfigValue).build()); @@ -192,7 +191,7 @@ public class OvsdbQueueUpdateCommand extends AbstractTransactionCommand { if (oldQueue != null && oldQueue.getExternalIdsColumn() != null) { oldExternalIds = oldQueue.getExternalIdsColumn().getData(); } - if ((oldExternalIds != null) && !oldExternalIds.isEmpty()) { + if (oldExternalIds != null && !oldExternalIds.isEmpty()) { removeOldExternalIds(transaction, queuesBuilder, oldExternalIds, queue, nodeIId); } if (externalIds != null && !externalIds.isEmpty()) { @@ -217,11 +216,10 @@ public class OvsdbQueueUpdateCommand extends AbstractTransactionCommand { private void setNewExternalIds(QueuesBuilder queuesBuilder, Map externalIds) { - Set externalIdsKeys = externalIds.keySet(); List externalIdsList = new ArrayList<>(); - String externalIdValue; - for (String extIdKey : externalIdsKeys) { - externalIdValue = externalIds.get(extIdKey); + for (Entry entry : externalIds.entrySet()) { + String extIdKey = entry.getKey(); + String externalIdValue = entry.getValue(); if (extIdKey != null && externalIdValue != null) { externalIdsList.add(new QueuesExternalIdsBuilder().setQueuesExternalIdKey(extIdKey) .setQueuesExternalIdValue(externalIdValue).build()); diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/TransactionInvokerImpl.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/TransactionInvokerImpl.java index bb815356d..8a547110f 100644 --- a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/TransactionInvokerImpl.java +++ b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/TransactionInvokerImpl.java @@ -10,6 +10,7 @@ package org.opendaylight.ovsdb.southbound.transactions.md; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.ThreadFactoryBuilder; import java.util.ArrayList; import java.util.HashMap; @@ -36,13 +37,13 @@ public class TransactionInvokerImpl implements TransactionInvoker,TransactionCha private static final Logger LOG = LoggerFactory.getLogger(TransactionInvokerImpl.class); private static final int QUEUE_SIZE = 10000; private BindingTransactionChain chain; - private DataBroker db; - private BlockingQueue inputQueue = new LinkedBlockingQueue<>(QUEUE_SIZE); - private BlockingQueue successfulTransactionQueue + private final DataBroker db; + private final BlockingQueue inputQueue = new LinkedBlockingQueue<>(QUEUE_SIZE); + private final BlockingQueue successfulTransactionQueue = new LinkedBlockingQueue<>(QUEUE_SIZE); - private BlockingQueue> failedTransactionQueue + private final BlockingQueue> failedTransactionQueue = new LinkedBlockingQueue<>(QUEUE_SIZE); - private ExecutorService executor; + private final ExecutorService executor; private Map transactionToCommand = new HashMap<>(); private List pendingTransactions = new ArrayList<>(); @@ -53,19 +54,21 @@ public class TransactionInvokerImpl implements TransactionInvoker,TransactionCha this.chain = db.createTransactionChain(this); ThreadFactory threadFact = new ThreadFactoryBuilder().setNameFormat("transaction-invoker-impl-%d").build(); executor = Executors.newSingleThreadExecutor(threadFact); - executor.submit(this); + executor.execute(this); } @Override public void invoke(final TransactionCommand command) { // TODO what do we do if queue is full? - inputQueue.offer(command); + if (!inputQueue.offer(command)) { + LOG.error("inputQueue is full (size: {}) - could not offer {}", inputQueue.size(), command); + } } @Override public void onTransactionChainFailed(TransactionChain chainArg, AsyncTransaction transaction, Throwable cause) { - failedTransactionQueue.offer(transaction); + offerFailedTransaction(transaction); } @Override @@ -96,14 +99,17 @@ public class TransactionInvokerImpl implements TransactionInvoker,TransactionCha Futures.addCallback(transaction.submit(), new FutureCallback() { @Override public void onSuccess(final Void result) { - successfulTransactionQueue.offer(transaction); + if (!successfulTransactionQueue.offer(transaction)) { + LOG.error("successfulTransactionQueue is full (size: {}) - could not offer {}", + successfulTransactionQueue.size(), transaction); + } } @Override public void onFailure(final Throwable throwable) { // NOOP - handled by failure of transaction chain } - }); + }, MoreExecutors.directExecutor()); } } catch (IllegalStateException e) { if (transactionInFlight != null) { @@ -111,13 +117,19 @@ public class TransactionInvokerImpl implements TransactionInvoker,TransactionCha // retried from exceptions on which the command should NOT be retried. // Then it should retry only the commands which should be retried, otherwise // this method will retry commands which will never be successful forever. - failedTransactionQueue.offer(transactionInFlight); + offerFailedTransaction(transactionInFlight); } LOG.warn("Failed to process an update notification from OVS.", e); } } } + private void offerFailedTransaction(AsyncTransaction transaction) { + if (!failedTransactionQueue.offer(transaction)) { + LOG.warn("failedTransactionQueue is full (size: {})", failedTransactionQueue.size()); + } + } + private List extractResubmitCommands() { AsyncTransaction transaction = failedTransactionQueue.poll(); List commands = new ArrayList<>();