*/
package org.opendaylight.netvirt.elan.l2gw.listeners;
+import static java.util.Collections.emptyList;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
+
import com.google.common.util.concurrent.ListenableFuture;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Objects;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.genius.datastoreutils.hwvtep.HwvtepClusteredDataTreeChangeListener;
import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.utils.hwvtep.HwvtepNodeHACache;
import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundConstants;
import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils;
import org.opendaylight.genius.utils.hwvtep.HwvtepUtils;
@Inject
public HwvtepTerminationPointListener(DataBroker broker, ElanL2GatewayUtils elanL2GatewayUtils,
- ElanClusterUtils elanClusterUtils, L2GatewayCache l2GatewayCache) {
- super(TerminationPoint.class, HwvtepTerminationPointListener.class);
+ ElanClusterUtils elanClusterUtils, L2GatewayCache l2GatewayCache,
+ HwvtepNodeHACache hwvtepNodeHACache) {
+ super(TerminationPoint.class, HwvtepTerminationPointListener.class, hwvtepNodeHACache);
this.broker = broker;
this.txRunner = new ManagedNewTransactionRunnerImpl(broker);
protected void removed(InstanceIdentifier<TerminationPoint> identifier, TerminationPoint del) {
LOG.trace("physical locator removed {}", identifier);
final HwvtepPhysicalPortAugmentation portAugmentation =
- del.getAugmentation(HwvtepPhysicalPortAugmentation.class);
+ del.augmentation(HwvtepPhysicalPortAugmentation.class);
if (portAugmentation != null) {
elanClusterUtils.runOnlyInOwnerNode(HwvtepSouthboundConstants.ELAN_ENTITY_NAME,
"Handling Physical port delete",
@Override
protected void added(InstanceIdentifier<TerminationPoint> identifier, final TerminationPoint add) {
final HwvtepPhysicalPortAugmentation portAugmentation =
- add.getAugmentation(HwvtepPhysicalPortAugmentation.class);
+ add.augmentation(HwvtepPhysicalPortAugmentation.class);
if (portAugmentation != null) {
final NodeId nodeId = identifier.firstIdentifierOf(Node.class).firstKeyOf(Node.class).getNodeId();
elanClusterUtils.runOnlyInOwnerNode(HwvtepSouthboundConstants.ELAN_ENTITY_NAME,
private List<ListenableFuture<Void>> handlePortAdded(TerminationPoint portAdded, NodeId psNodeId) {
Node psNode = HwvtepUtils.getHwVtepNode(broker, LogicalDatastoreType.OPERATIONAL, psNodeId);
if (psNode != null) {
- String psName = psNode.getAugmentation(PhysicalSwitchAugmentation.class).getHwvtepNodeName().getValue();
+ String psName = psNode.augmentation(PhysicalSwitchAugmentation.class).getHwvtepNodeName().getValue();
L2GatewayDevice l2GwDevice = l2GatewayCache.get(psName);
if (l2GwDevice != null) {
if (isL2GatewayConfigured(l2GwDevice)) {
} else {
LOG.error("{} entry not in config datastore", psNodeId);
}
- return Collections.emptyList();
+ return emptyList();
}
private List<ListenableFuture<Void>> handlePortDeleted(InstanceIdentifier<TerminationPoint> identifier) {
InstanceIdentifier<Node> psNodeIid = identifier.firstIdentifierOf(Node.class);
- return Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(
- tx -> tx.read(LogicalDatastoreType.CONFIGURATION, psNodeIid).checkedGet().toJavaUtil().ifPresent(
- node -> tx.delete(LogicalDatastoreType.CONFIGURATION, identifier))));
+ return Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
+ tx -> tx.read(psNodeIid).get().toJavaUtil().ifPresent(
+ node -> tx.delete(identifier))));
}
private List<VlanBindings> getVlanBindings(List<L2gatewayConnection> l2GwConns, NodeId hwvtepNodeId, String psName,
} else {
String logicalSwitchName = ElanL2GatewayUtils.getLogicalSwitchFromElan(
l2GwConn.getNetworkId().getValue());
- List<Devices> l2Devices = l2Gateway.getDevices();
+ List<Devices> l2Devices = requireNonNullElse(l2Gateway.getDevices(), emptyList());
for (Devices l2Device : l2Devices) {
String l2DeviceName = l2Device.getDeviceName();
if (l2DeviceName != null && l2DeviceName.equals(psName)) {
- for (Interfaces deviceInterface : l2Device.getInterfaces()) {
- if (deviceInterface.getInterfaceName().equals(newPortId)) {
+ for (Interfaces deviceInterface : requireNonNullElse(l2Device.getInterfaces(),
+ Collections.<Interfaces>emptyList())) {
+ if (Objects.equals(deviceInterface.getInterfaceName(), newPortId)) {
if (deviceInterface.getSegmentationIds() != null
&& !deviceInterface.getSegmentationIds().isEmpty()) {
for (Integer vlanId : deviceInterface.getSegmentationIds()) {