BUG 8476 Fix checkstyle error
[netvirt.git] / vpnservice / elanmanager / elanmanager-impl / src / main / java / org / opendaylight / netvirt / elan / l2gw / jobs / AssociateHwvtepToElanJob.java
index cb92c28b9e2d0852661850cabbaeb5184c3888ca..4510cec78ea123cb4864e8ccd3e8fbb6b4406486 100644 (file)
@@ -7,43 +7,51 @@
  */
 package org.opendaylight.netvirt.elan.l2gw.jobs;
 
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.Callable;
-
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils;
+import org.opendaylight.genius.utils.hwvtep.HwvtepUtils;
+import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
+import org.opendaylight.netvirt.elan.utils.ElanUtils;
 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
-import org.opendaylight.vpnservice.utils.hwvtep.HwvtepSouthboundUtils;
-import org.opendaylight.vpnservice.utils.hwvtep.HwvtepUtils;
+import org.opendaylight.ovsdb.utils.southbound.utils.SouthboundUtils;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
-
 /**
 * Created by ekvsver on 4/15/2016.
 */
 public class AssociateHwvtepToElanJob implements Callable<List<ListenableFuture<Void>>> {
-    DataBroker broker;
-    L2GatewayDevice l2GatewayDevice;
-    ElanInstance elanInstance;
-    Devices l2Device;
-    Integer defaultVlan;
-    boolean createLogicalSwitch;
     private static final Logger LOG = LoggerFactory.getLogger(AssociateHwvtepToElanJob.class);
 
-    public AssociateHwvtepToElanJob(DataBroker broker, L2GatewayDevice l2GatewayDevice, ElanInstance elanInstance,
-            Devices l2Device, Integer defaultVlan, boolean createLogicalSwitch) {
+    private final DataBroker broker;
+    private final ElanL2GatewayUtils elanL2GatewayUtils;
+    private final ElanUtils elanUtils;
+    private final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
+    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, ElanUtils elanUtils,
+                                    ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils,
+                                    L2GatewayDevice l2GatewayDevice, ElanInstance elanInstance, Devices l2Device,
+                                    Integer defaultVlan, boolean createLogicalSwitch) {
         this.broker = broker;
+        this.elanL2GatewayUtils = elanL2GatewayUtils;
+        this.elanUtils = elanUtils;
+        this.elanL2GatewayMulticastUtils = elanL2GatewayMulticastUtils;
         this.l2GatewayDevice = l2GatewayDevice;
         this.elanInstance = elanInstance;
         this.l2Device = l2Device;
@@ -71,11 +79,14 @@ public class AssociateHwvtepToElanJob implements Callable<List<ListenableFuture<
             ListenableFuture<Void> lsCreateFuture = createLogicalSwitch(l2GatewayDevice, elanInstance);
             futures.add(lsCreateFuture);
         } else {
+            createLogicalSwitch(l2GatewayDevice, elanInstance);
             String logicalSwitchName = ElanL2GatewayUtils.getLogicalSwitchFromElan(elanInstanceName);
             LOG.info("{} is already created in {}; adding remaining configurations", logicalSwitchName, hwvtepNodeId);
 
-            LogicalSwitchAddedJob logicalSwitchAddedJob = new LogicalSwitchAddedJob(logicalSwitchName, l2Device,
-                    l2GatewayDevice, defaultVlan);
+            LogicalSwitchAddedJob logicalSwitchAddedJob =
+                    new LogicalSwitchAddedJob(broker, elanL2GatewayUtils, elanUtils, elanL2GatewayMulticastUtils,
+                            logicalSwitchName, l2Device,
+                            l2GatewayDevice, defaultVlan);
             return logicalSwitchAddedJob.call();
         }
 
@@ -85,17 +96,22 @@ public class AssociateHwvtepToElanJob implements Callable<List<ListenableFuture<
     private ListenableFuture<Void> createLogicalSwitch(L2GatewayDevice l2GatewayDevice, ElanInstance elanInstance) {
         final String logicalSwitchName = ElanL2GatewayUtils.getLogicalSwitchFromElan(
                 elanInstance.getElanInstanceName());
-        String segmentationId = elanInstance.getVni().toString();
+        String segmentationId = ElanUtils.getVxlanSegmentationId(elanInstance).toString();
+        String replicationMode = "";
 
-        if (LOG.isTraceEnabled()) {
-            LOG.trace("logical switch {} is created on {} with VNI {}", logicalSwitchName,
-                    l2GatewayDevice.getHwvtepNodeId(), segmentationId);
-        }
+        LOG.trace("logical switch {} is created on {} with VNI {}", logicalSwitchName,
+                l2GatewayDevice.getHwvtepNodeId(), segmentationId);
         NodeId hwvtepNodeId = new NodeId(l2GatewayDevice.getHwvtepNodeId());
-        InstanceIdentifier<LogicalSwitches> path = HwvtepSouthboundUtils
-                .createLogicalSwitchesInstanceIdentifier(hwvtepNodeId, new HwvtepNodeName(logicalSwitchName));
+        String dbVersion = HwvtepUtils.getDbVersion(broker,hwvtepNodeId);
+        if (SouthboundUtils.compareDbVersionToMinVersion(dbVersion, "1.6.0")) {
+            replicationMode = "source_node";
+        }
+
+        LOG.trace("logical switch {} has schema version {}, replication mode set to {}", logicalSwitchName,
+                dbVersion, replicationMode);
+
         LogicalSwitches logicalSwitch = HwvtepSouthboundUtils.createLogicalSwitch(logicalSwitchName,
-                elanInstance.getDescription(), segmentationId);
+                elanInstance.getDescription(), segmentationId, replicationMode);
 
         ListenableFuture<Void> lsCreateFuture = HwvtepUtils.addLogicalSwitch(broker, hwvtepNodeId, logicalSwitch);
         Futures.addCallback(lsCreateFuture, new FutureCallback<Void>() {
@@ -104,9 +120,7 @@ public class AssociateHwvtepToElanJob implements Callable<List<ListenableFuture<
                 // Listener will be closed after all configuration completed
                 // on hwvtep by
                 // listener itself
-                if (LOG.isTraceEnabled()) {
-                    LOG.trace("Successful in initiating logical switch {} creation", logicalSwitchName);
-                }
+                LOG.trace("Successful in initiating logical switch {} creation", logicalSwitchName);
             }
 
             @Override