*/
package org.opendaylight.netvirt.elan.l2gw.jobs;
+import com.google.common.util.concurrent.FluentFuture;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
-import java.util.Collections;
+import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import java.util.concurrent.ExecutionException;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils;
import org.opendaylight.genius.utils.hwvtep.HwvtepUtils;
-import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.common.api.CommitInfo;
import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
+import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayBcGroupUtils;
import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
+import org.opendaylight.netvirt.elan.l2gw.utils.L2GatewayUtils;
import org.opendaylight.netvirt.elan.utils.ElanUtils;
import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
import org.opendaylight.ovsdb.utils.southbound.utils.SouthboundUtils;
/**
* Created by ekvsver on 4/15/2016.
*/
-public class AssociateHwvtepToElanJob implements Callable<List<ListenableFuture<Void>>> {
+public class AssociateHwvtepToElanJob implements Callable<List<? extends ListenableFuture<?>>> {
private static final Logger LOG = LoggerFactory.getLogger(AssociateHwvtepToElanJob.class);
- private final DataBroker broker;
+ private final DataBroker dataBroker;
private final ElanL2GatewayUtils elanL2GatewayUtils;
private final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
- private final ElanInstanceCache elanInstanceCache;
+ private final ElanL2GatewayBcGroupUtils elanL2GatewayBcGroupUtils;
private final L2GatewayDevice l2GatewayDevice;
private final ElanInstance elanInstance;
private final Devices l2Device;
private final Integer defaultVlan;
- private final boolean createLogicalSwitch;
- public AssociateHwvtepToElanJob(DataBroker broker, ElanL2GatewayUtils elanL2GatewayUtils,
- ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils, ElanInstanceCache elanInstanceCache,
- L2GatewayDevice l2GatewayDevice, ElanInstance elanInstance, Devices l2Device, Integer defaultVlan,
- boolean createLogicalSwitch) {
- this.broker = broker;
+ public AssociateHwvtepToElanJob(DataBroker dataBroker, ElanL2GatewayUtils elanL2GatewayUtils,
+ ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils,
+ ElanL2GatewayBcGroupUtils elanL2GatewayBcGroupUtils,
+ L2GatewayDevice l2GatewayDevice, ElanInstance elanInstance,
+ Devices l2Device, Integer defaultVlan) {
+ this.dataBroker = dataBroker;
this.elanL2GatewayUtils = elanL2GatewayUtils;
this.elanL2GatewayMulticastUtils = elanL2GatewayMulticastUtils;
- this.elanInstanceCache = elanInstanceCache;
+ this.elanL2GatewayBcGroupUtils = elanL2GatewayBcGroupUtils;
this.l2GatewayDevice = l2GatewayDevice;
this.elanInstance = elanInstance;
this.l2Device = l2Device;
this.defaultVlan = defaultVlan;
- this.createLogicalSwitch = createLogicalSwitch;
LOG.debug("created assosiate l2gw connection job for {} {} ", elanInstance.getElanInstanceName(),
l2GatewayDevice.getHwvtepNodeId());
}
public String getJobKey() {
- return elanInstance.getElanInstanceName() + HwvtepHAUtil.L2GW_JOB_KEY;
+ return l2GatewayDevice.getHwvtepNodeId() + HwvtepHAUtil.L2GW_JOB_KEY;
}
@Override
- public List<ListenableFuture<Void>> call() {
+ public List<ListenableFuture<?>> call() throws Exception {
+ List<ListenableFuture<?>> futures = new ArrayList<>();
String hwvtepNodeId = l2GatewayDevice.getHwvtepNodeId();
String elanInstanceName = elanInstance.getElanInstanceName();
- LOG.debug("running assosiate l2gw connection job for {} {} ", elanInstanceName, hwvtepNodeId);
+ LOG.info("AssociateHwvtepToElanJob Running associate l2gw connection job for {} {} ",
+ elanInstanceName, hwvtepNodeId);
elanL2GatewayUtils.cancelDeleteLogicalSwitch(new NodeId(hwvtepNodeId),
ElanL2GatewayUtils.getLogicalSwitchFromElan(elanInstanceName));
// Create Logical Switch if it's not created already in the device
- if (createLogicalSwitch) {
- LOG.info("creating logical switch {} for {} ", elanInstanceName, hwvtepNodeId);
-
- return Collections.singletonList(createLogicalSwitch());
- } else {
- createLogicalSwitch();
- String logicalSwitchName = ElanL2GatewayUtils.getLogicalSwitchFromElan(elanInstanceName);
- LOG.info("{} is already created in {}; adding remaining configurations", logicalSwitchName, hwvtepNodeId);
-
- LogicalSwitchAddedJob logicalSwitchAddedJob =
- new LogicalSwitchAddedJob(elanL2GatewayUtils, elanL2GatewayMulticastUtils,
- logicalSwitchName, l2Device, l2GatewayDevice, defaultVlan
- );
- return logicalSwitchAddedJob.call();
- }
+ FluentFuture<? extends @NonNull CommitInfo> lsCreateFuture = createLogicalSwitch();
+ futures.add(lsCreateFuture);
+ String logicalSwitchName = ElanL2GatewayUtils.getLogicalSwitchFromElan(elanInstanceName);
+
+ LogicalSwitchAddedJob logicalSwitchAddedJob =
+ new LogicalSwitchAddedJob(elanL2GatewayUtils, elanL2GatewayMulticastUtils,
+ elanL2GatewayBcGroupUtils, logicalSwitchName, l2Device, l2GatewayDevice, defaultVlan);
+ futures.addAll(logicalSwitchAddedJob.call());
+ return futures;
}
- private ListenableFuture<Void> createLogicalSwitch() {
+ private FluentFuture<? extends @NonNull CommitInfo> createLogicalSwitch() {
final String logicalSwitchName = ElanL2GatewayUtils.getLogicalSwitchFromElan(
elanInstance.getElanInstanceName());
String segmentationId = ElanUtils.getVxlanSegmentationId(elanInstance).toString();
LOG.trace("logical switch {} is created on {} with VNI {}", logicalSwitchName,
l2GatewayDevice.getHwvtepNodeId(), segmentationId);
NodeId hwvtepNodeId = new NodeId(l2GatewayDevice.getHwvtepNodeId());
- String dbVersion = HwvtepUtils.getDbVersion(broker,hwvtepNodeId);
+ String dbVersion = L2GatewayUtils.getConfigDbVersion(dataBroker, hwvtepNodeId);
+ try {
+ dbVersion =
+ dbVersion != null ? dbVersion : HwvtepUtils.getDbVersion(dataBroker, hwvtepNodeId);
+ } catch (ExecutionException | InterruptedException e) {
+ LOG.error("Failed to Read Node {} from Oper-Topo for retrieving DB version", hwvtepNodeId);
+ }
if (SouthboundUtils.compareDbVersionToMinVersion(dbVersion, "1.6.0")) {
replicationMode = "source_node";
}
LogicalSwitches logicalSwitch = HwvtepSouthboundUtils.createLogicalSwitch(logicalSwitchName,
elanInstance.getDescription(), segmentationId, replicationMode);
- ListenableFuture<Void> lsCreateFuture = HwvtepUtils.addLogicalSwitch(broker, hwvtepNodeId, logicalSwitch);
- Futures.addCallback(lsCreateFuture, new FutureCallback<Void>() {
+ FluentFuture<? extends @NonNull CommitInfo> lsCreateFuture =
+ HwvtepUtils.addLogicalSwitch(dataBroker, hwvtepNodeId, logicalSwitch);
+ Futures.addCallback(lsCreateFuture, new FutureCallback<CommitInfo>() {
@Override
- public void onSuccess(Void noarg) {
+ public void onSuccess(CommitInfo noarg) {
// Listener will be closed after all configuration completed
// on hwvtep by
// listener itself