ITM checkstyle enforcement
[genius.git] / itm / itm-impl / src / main / java / org / opendaylight / genius / itm / confighelpers / OvsdbTepRemoveConfigHelper.java
index b57cf984b3bd508d39ea3490673d0d6bf7cbccaf..c6235d9b554b005a5f55f79ed4fe294d32141007 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -19,7 +19,10 @@ import org.opendaylight.genius.mdsalutil.MDSALUtil;
 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.IpPrefix;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.*;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TepsNotHostedInTransportZone;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TepsNotHostedInTransportZoneKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.tepsnothostedintransportzone.UnknownVteps;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.tepsnothostedintransportzone.UnknownVtepsKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Subnets;
@@ -35,50 +38,51 @@ public class OvsdbTepRemoveConfigHelper {
     private static final Logger LOG = LoggerFactory.getLogger(OvsdbTepRemoveConfigHelper.class);
 
     /**
-     * Removes the TEP from ITM configuration Datastore in one of the following cases:
+     * Removes the TEP from ITM configuration Datastore in one of the following cases.
      * 1) default transport zone
      * 2) Configured transport zone
      * 3) Unhosted transport zone
      * Function checks for above three cases and calls other sub-function to remove the TEP
      *
      * @param tepIp TEP-IP address in string
-     * @param strDpid bridge datapath ID in string
+     * @param strDpnId bridge datapath ID in string
      * @param tzName transport zone name in string
      * @param dataBroker data broker handle to perform operations on config datastore
      * @param wrTx WriteTransaction object
      */
-    public static void removeTepReceivedFromOvsdb(String tepIp, String strDpid, String tzName,
-        DataBroker dataBroker, WriteTransaction wrTx) {
-        BigInteger dpid = BigInteger.valueOf(0);
 
-        LOG.trace("Remove TEP: TEP-IP: {}, TZ name: {}, DPID: {}", tepIp, tzName, strDpid);
+    public static void removeTepReceivedFromOvsdb(String tepIp, String strDpnId, String tzName,
+                                                  DataBroker dataBroker, WriteTransaction wrTx) {
+        BigInteger dpnId = BigInteger.valueOf(0);
 
-        if (strDpid != null && !strDpid.isEmpty()) {
-            dpid = MDSALUtil.getDpnId(strDpid);
+        LOG.trace("Remove TEP: TEP-IP: {}, TZ name: {}, DPID: {}", tepIp, tzName, strDpnId);
+
+        if (strDpnId != null && !strDpnId.isEmpty()) {
+            dpnId = MDSALUtil.getDpnId(strDpnId);
         }
 
         // Get tep IP
         IpAddress tepIpAddress = new IpAddress(tepIp.toCharArray());
-        TransportZone tZone = null;
+        TransportZone transportZone = null;
 
         // Case: TZ name is not given from OVS's other_config parameters.
         if (tzName == null) {
             tzName = ITMConstants.DEFAULT_TRANSPORT_ZONE;
             // add TEP into default-TZ
-            tZone = ItmUtils.getTransportZoneFromConfigDS(tzName, dataBroker);
-            if (tZone == null) {
+            transportZone = ItmUtils.getTransportZoneFromConfigDS(tzName, dataBroker);
+            if (transportZone == null) {
                 LOG.error("Error: default-transport-zone is not yet created.");
                 return;
             }
             LOG.trace("Remove TEP from default-transport-zone.");
         } else {
             // Case: Add TEP into corresponding TZ created from Northbound.
-            tZone = ItmUtils.getTransportZoneFromConfigDS(tzName, dataBroker);
-            if (tZone == null) {
+            transportZone = ItmUtils.getTransportZoneFromConfigDS(tzName, dataBroker);
+            if (transportZone == null) {
                 // Case: TZ is not configured from Northbound, then add TEP into
                 // "teps-not-hosted-in-transport-zone"
                 LOG.trace("Removing TEP from unknown TZ into teps-not-hosted-in-transport-zone.");
-                removeUnknownTzTepFromTepsNotHosted(tzName, tepIpAddress, dpid, dataBroker, wrTx);
+                removeUnknownTzTepFromTepsNotHosted(tzName, tepIpAddress, dpnId, dataBroker, wrTx);
                 return;
             } else {
                 LOG.trace("Remove TEP from transport-zone already configured by Northbound.");
@@ -88,7 +92,7 @@ public class OvsdbTepRemoveConfigHelper {
         // Remove TEP from (default transport-zone) OR (transport-zone already configured by Northbound)
 
         // Get subnet list of corresponding TZ created from Northbound.
-        List<Subnets> subnetList = tZone.getSubnets();
+        List<Subnets> subnetList = transportZone.getSubnets();
 
         if (subnetList == null || subnetList.isEmpty()) {
             LOG.trace("No subnet list in transport-zone. Nothing to do.");
@@ -117,7 +121,7 @@ public class OvsdbTepRemoveConfigHelper {
                 Vteps oldVtep = null;
 
                 for (Vteps vtep : vtepList) {
-                    if (vtep.getDpnId().equals(dpid)) {
+                    if (vtep.getDpnId().equals(dpnId)) {
                         vtepFound = true;
                         oldVtep = vtep;
                         // get portName of existing vtep
@@ -128,9 +132,9 @@ public class OvsdbTepRemoveConfigHelper {
                 if (vtepFound) {
                     // vtep is found, update it with tep-ip
                     LOG.trace("Remove TEP from vtep list in subnet list of transport-zone.");
-                    dpid = oldVtep.getDpnId();
+                    dpnId = oldVtep.getDpnId();
                     portName = oldVtep.getPortname();
-                    removeVtepFromTZConfig(subnetMaskObj, tzName, dpid, portName, wrTx);
+                    removeVtepFromTZConfig(subnetMaskObj, tzName, dpnId, portName, wrTx);
                 } else {
                     LOG.trace(
                         "TEP is not found in the vtep list in subnet list of transport-zone. Nothing to do.");
@@ -144,38 +148,39 @@ public class OvsdbTepRemoveConfigHelper {
      * from ITM configuration Datastore by delete operation with write transaction.
      *
      * @param subnetMaskObj subnet mask in IpPrefix object
-     * @param dpid bridge datapath ID in BigInteger
+     * @param dpnId bridge datapath ID in BigInteger
      * @param tzName transport zone name in string
      * @param portName port name as a part of VtepsKey
      * @param wrTx WriteTransaction object
      */
-    protected static void removeVtepFromTZConfig(IpPrefix subnetMaskObj, String tzName, BigInteger dpid,
+    protected static void removeVtepFromTZConfig(IpPrefix subnetMaskObj, String tzName, BigInteger dpnId,
         String portName, WriteTransaction wrTx) {
         SubnetsKey subnetsKey = new SubnetsKey(subnetMaskObj);
-        VtepsKey vtepkey = new VtepsKey(dpid, portName);
+        VtepsKey vtepkey = new VtepsKey(dpnId, portName);
 
-        InstanceIdentifier<Vteps> vTepPath = InstanceIdentifier.builder(TransportZones.class)
+        InstanceIdentifier<Vteps> vtepPath = InstanceIdentifier.builder(TransportZones.class)
             .child(TransportZone.class, new TransportZoneKey(tzName))
             .child(Subnets.class, subnetsKey).child(Vteps.class, vtepkey).build();
 
-        LOG.trace("Removing TEP (TZ: {} Subnet: {} DPID: {}) in ITM Config DS.", tzName,
-            subnetMaskObj.getValue().toString(), dpid);
+        LOG.trace("Removing TEP (TZ: {} Subnet: {} DPN-ID: {}) in ITM Config DS.", tzName,
+                subnetMaskObj.getValue().toString(), dpnId);
         // remove vtep
-        wrTx.delete(LogicalDatastoreType.CONFIGURATION, vTepPath);
+        wrTx.delete(LogicalDatastoreType.CONFIGURATION, vtepPath);
     }
 
     /**
      * Removes the TEP from the not-hosted transport zone in the TepsNotHosted list
-     * from ITM configuration Datastore
+     * from ITM configuration Datastore.
      *
      * @param tzName transport zone name in string
      * @param tepIpAddress TEP IP address in IpAddress object
-     * @param dpid bridge datapath ID in BigInteger
+     * @param dpnId bridge datapath ID in BigInteger
      * @param dataBroker data broker handle to perform operations on config datastore
      * @param wrTx WriteTransaction object
      */
     public static void removeUnknownTzTepFromTepsNotHosted(String tzName, IpAddress tepIpAddress,
-        BigInteger dpid, DataBroker dataBroker, WriteTransaction wrTx) {
+                                                           BigInteger dpnId, DataBroker dataBroker,
+                                                           WriteTransaction wrTx) {
         List<UnknownVteps> vtepList = null;
 
         TepsNotHostedInTransportZone unknownTz =
@@ -196,7 +201,7 @@ public class OvsdbTepRemoveConfigHelper {
                 UnknownVteps foundVtep = null;
 
                 for (UnknownVteps vtep : vtepList) {
-                    if (vtep.getDpnId().equals(dpid)) {
+                    if (vtep.getDpnId().equals(dpnId)) {
                         vtepFound = true;
                         foundVtep = vtep;
                         break;
@@ -210,7 +215,7 @@ public class OvsdbTepRemoveConfigHelper {
                     if (vtepList.size() == 1) {
                         removeTzFromTepsNotHosted(tzName, wrTx);
                     } else {
-                        removeVtepFromTepsNotHosted(tzName, dpid, wrTx);
+                        removeVtepFromTepsNotHosted(tzName, dpnId, wrTx);
                     }
                     vtepList.remove(foundVtep);
                 }
@@ -223,21 +228,21 @@ public class OvsdbTepRemoveConfigHelper {
      * from ITM configuration Datastore by delete operation with write transaction.
      *
      * @param tzName transport zone name in string
-     * @param dpid bridge datapath ID in BigInteger
+     * @param dpnId bridge datapath ID in BigInteger
      * @param wrTx WriteTransaction object
      */
-    protected static void removeVtepFromTepsNotHosted(String tzName, BigInteger dpid,
-        WriteTransaction wrTx) {
+    protected static void removeVtepFromTepsNotHosted(String tzName, BigInteger dpnId,
+                                                      WriteTransaction wrTx) {
 
-        UnknownVtepsKey unknownVtepkey = new UnknownVtepsKey(dpid);
-        InstanceIdentifier<UnknownVteps> vTepPath = InstanceIdentifier.builder(TransportZones.class)
+        UnknownVtepsKey unknownVtepkey = new UnknownVtepsKey(dpnId);
+        InstanceIdentifier<UnknownVteps> vtepPath = InstanceIdentifier.builder(TransportZones.class)
             .child(TepsNotHostedInTransportZone.class, new TepsNotHostedInTransportZoneKey(tzName))
             .child(UnknownVteps.class, unknownVtepkey).build();
 
-        LOG.trace("Removing TEP from unhosted (TZ: {}, DPID: {}) from ITM Config DS.", tzName,
-            dpid);
+        LOG.trace("Removing TEP from unhosted (TZ: {}, DPID: {}) from ITM Config DS.",
+                tzName, dpnId);
         // remove vtep
-        wrTx.delete(LogicalDatastoreType.CONFIGURATION, vTepPath);
+        wrTx.delete(LogicalDatastoreType.CONFIGURATION, vtepPath);
     }
 
     /**
@@ -249,7 +254,7 @@ public class OvsdbTepRemoveConfigHelper {
      */
     protected static void removeTzFromTepsNotHosted(String tzName, WriteTransaction wrTx) {
         InstanceIdentifier<TepsNotHostedInTransportZone> tzTepsNotHostedTepPath =
-            InstanceIdentifier.builder(TransportZones.class)
+                InstanceIdentifier.builder(TransportZones.class)
                 .child(TepsNotHostedInTransportZone.class,
                     new TepsNotHostedInTransportZoneKey(tzName)).build();