In general, methods returning collections should never return null.
This patch fixes L2GatewayConnectionUtils and propagates the non-null
results.
Change-Id: If249aec9b8494de736c362f0ea04139151670d68
Signed-off-by: Stephen Kitt <skitt@redhat.com>
}
l2gatewayConnections = L2GatewayConnectionUtils.getAllL2gatewayConnections(dataBroker);
l2gateways = L2GatewayConnectionUtils.getL2gatewayList(dataBroker);
- if (l2gateways != null) {
- for (L2gateway l2gateway : l2gateways) {
- uuidToL2Gateway.put(l2gateway.getUuid(), l2gateway);
- }
+ for (L2gateway l2gateway : l2gateways) {
+ uuidToL2Gateway.put(l2gateway.getUuid(), l2gateway);
}
}
LOG.info("Elan instance {} deleted from Operational tree ", del);
List<L2gatewayConnection> l2gatewayConnections = L2GatewayConnectionUtils.getL2GwConnectionsByElanName(this
.broker, del.getElanInstanceName());
- if (l2gatewayConnections != null) {
- LOG.info("L2Gatewconnection {} to be deleted as part of Elan Instance deletion {} ", l2gatewayConnections,
- del);
- for (L2gatewayConnection l2gatewayConnection : l2gatewayConnections) {
- l2GatewayConnectionUtils.deleteL2GatewayConnection(l2gatewayConnection);
- }
- LOG.info("L2Gatewconnection {} delet task submitted Successfully", l2gatewayConnections);
+ LOG.info("L2Gatewconnection {} to be deleted as part of Elan Instance deletion {} ", l2gatewayConnections,
+ del);
+ for (L2gatewayConnection l2gatewayConnection : l2gatewayConnections) {
+ l2GatewayConnectionUtils.deleteL2GatewayConnection(l2gatewayConnection);
}
+ LOG.info("L2Gatewconnection {} delete task submitted successfully", l2gatewayConnections);
}
if (isL2GatewayConfigured(l2GwDevice)) {
List<L2gatewayConnection> l2GwConns = L2GatewayConnectionUtils.getAssociatedL2GwConnections(broker,
l2GwDevice.getL2GatewayIds());
- if (l2GwConns != null) {
- String newPortId = portAdded.getTpId().getValue();
- NodeId hwvtepNodeId = new NodeId(l2GwDevice.getHwvtepNodeId());
- List<VlanBindings> vlanBindings = getVlanBindings(l2GwConns, hwvtepNodeId, psName, newPortId);
- List<ListenableFuture<Void>> futures = new ArrayList<>();
- futures.add(elanL2GatewayUtils.updateVlanBindingsInL2GatewayDevice(hwvtepNodeId, psName,
- newPortId, vlanBindings));
- return futures;
- }
+ String newPortId = portAdded.getTpId().getValue();
+ NodeId hwvtepNodeId = new NodeId(l2GwDevice.getHwvtepNodeId());
+ List<VlanBindings> vlanBindings = getVlanBindings(l2GwConns, hwvtepNodeId, psName, newPortId);
+ List<ListenableFuture<Void>> futures = new ArrayList<>();
+ futures.add(elanL2GatewayUtils.updateVlanBindingsInL2GatewayDevice(hwvtepNodeId, psName,
+ newPortId, vlanBindings));
+ return futures;
}
} else {
LOG.error("{} details are not present in L2Gateway Cache", psName);
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.SettableFuture;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import javax.annotation.Nonnull;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
return MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, inst).orNull();
}
+ @Nonnull
public static List<L2gateway> getL2gatewayList(DataBroker broker) {
InstanceIdentifier<L2gateways> inst = InstanceIdentifier.create(Neutron.class).child(L2gateways.class);
return MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, inst).transform(
- L2gateways::getL2gateway).orNull();
+ L2gateways::getL2gateway).or(Collections.emptyList());
}
+ @Nonnull
public static List<L2gatewayConnection> getAllL2gatewayConnections(DataBroker broker) {
InstanceIdentifier<L2gatewayConnections> inst = InstanceIdentifier.create(Neutron.class)
.child(L2gatewayConnections.class);
return MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, inst).transform(
- L2gatewayConnections::getL2gatewayConnection).orNull();
+ L2gatewayConnections::getL2gatewayConnection).or(Collections.emptyList());
}
/**
* the l2 gateway ids
* @return the associated l2 gw connections
*/
+ @Nonnull
public static List<L2gatewayConnection> getAssociatedL2GwConnections(DataBroker broker, Set<Uuid> l2GatewayIds) {
- List<L2gatewayConnection> l2GwConnections = null;
List<L2gatewayConnection> allL2GwConns = getAllL2gatewayConnections(broker);
- if (allL2GwConns != null) {
- l2GwConnections = new ArrayList<>();
- for (Uuid l2GatewayId : l2GatewayIds) {
- for (L2gatewayConnection l2GwConn : allL2GwConns) {
- if (l2GwConn.getL2gatewayId().equals(l2GatewayId)) {
- l2GwConnections.add(l2GwConn);
- }
+ List<L2gatewayConnection> l2GwConnections = new ArrayList<>();
+ for (Uuid l2GatewayId : l2GatewayIds) {
+ for (L2gatewayConnection l2GwConn : allL2GwConns) {
+ if (l2GwConn.getL2gatewayId().equals(l2GatewayId)) {
+ l2GwConnections.add(l2GwConn);
}
}
}
* the elan Name
* @return the associated l2 gw connection with elan
*/
+ @Nonnull
public static List<L2gatewayConnection> getL2GwConnectionsByElanName(DataBroker broker, String elanName) {
List<L2gatewayConnection> allL2GwConns = getAllL2gatewayConnections(broker);
List<L2gatewayConnection> elanL2GateWayConnections = new ArrayList<>();
- if (allL2GwConns != null) {
- for (L2gatewayConnection l2GwConn : allL2GwConns) {
- if (l2GwConn.getNetworkId().getValue().equalsIgnoreCase(elanName)) {
- elanL2GateWayConnections.add(l2GwConn);
- }
+ for (L2gatewayConnection l2GwConn : allL2GwConns) {
+ if (l2GwConn.getNetworkId().getValue().equalsIgnoreCase(elanName)) {
+ elanL2GateWayConnections.add(l2GwConn);
}
}
return elanL2GateWayConnections;
List<L2gatewayConnection> l2GwConns = L2GatewayConnectionUtils.getAssociatedL2GwConnections(
dataBroker, l2GwDevice.getL2GatewayIds());
- if (l2GwConns != null) {
- LOG.debug("L2GatewayConnections associated for {} physical switch", psName);
- for (L2gatewayConnection l2GwConn : l2GwConns) {
- LOG.trace("L2GatewayConnection {} changes executed on physical switch {}",
- l2GwConn.getL2gatewayId(), psName);
- elanUtils.getL2GatewayConnectionUtils().addL2GatewayConnection(l2GwConn, psName);
- }
+ LOG.debug("L2GatewayConnections associated for {} physical switch", psName);
+ for (L2gatewayConnection l2GwConn : l2GwConns) {
+ LOG.trace("L2GatewayConnection {} changes executed on physical switch {}",
+ l2GwConn.getL2gatewayId(), psName);
+ elanUtils.getL2GatewayConnectionUtils().addL2GatewayConnection(l2GwConn, psName);
}
}