Fix checkstyle violations in hwvtepsouthbound-impl
[ovsdb.git] / hwvtepsouthbound / hwvtepsouthbound-impl / src / main / java / org / opendaylight / ovsdb / hwvtepsouthbound / transact / PhysicalSwitchUpdateCommand.java
index d2ece230dee3c6fca2847ce3420d853a85421027..f16a6c1ee342ea7a6c0bb7834e6c00beba734c11 100644 (file)
@@ -11,6 +11,8 @@ package org.opendaylight.ovsdb.hwvtepsouthbound.transact;
 import static org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundUtil.schemaMismatchLog;
 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
 
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableMap;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -19,7 +21,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
-
 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -47,10 +48,6 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Sets;
-
 public class PhysicalSwitchUpdateCommand extends AbstractTransactCommand {
     private static final Logger LOG = LoggerFactory.getLogger(PhysicalSwitchUpdateCommand.class);
 
@@ -85,7 +82,8 @@ public class PhysicalSwitchUpdateCommand extends AbstractTransactCommand {
         LOG.debug("Creating a physical switch named: {}", physicalSwitchAugmentation.getHwvtepNodeName());
         Optional<PhysicalSwitchAugmentation> operationalPhysicalSwitchOptional =
                 getOperationalState().getPhysicalSwitchAugmentation(iid);
-        PhysicalSwitch physicalSwitch = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), PhysicalSwitch.class);
+        PhysicalSwitch physicalSwitch = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(),
+                PhysicalSwitch.class);
         setDescription(physicalSwitch, physicalSwitchAugmentation);
         setManagementIps(physicalSwitch, physicalSwitchAugmentation);
         setTunnuleIps(physicalSwitch, operationalPhysicalSwitchOptional.get());
@@ -100,8 +98,8 @@ public class PhysicalSwitchUpdateCommand extends AbstractTransactCommand {
             setName(physicalSwitch, physicalSwitchAugmentation, operationalPhysicalSwitchOptional);
             String pswitchUuid = "PhysicalSwitch_" + HwvtepSouthboundMapper.getRandomUUID();
             transaction.add(op.insert(physicalSwitch).withId(pswitchUuid));
-            transaction.add(op.comment("Physical Switch: Creating " +
-                            physicalSwitchAugmentation.getHwvtepNodeName().getValue()));
+            transaction.add(op.comment("Physical Switch: Creating "
+                    + physicalSwitchAugmentation.getHwvtepNodeName().getValue()));
             //update global table
             Global global = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Global.class);
             global.setSwitches(Collections.singleton(new UUID(pswitchUuid)));
@@ -110,21 +108,22 @@ public class PhysicalSwitchUpdateCommand extends AbstractTransactCommand {
             transaction.add(op.mutate(global)
                     .addMutation(global.getSwitchesColumn().getSchema(), Mutator.INSERT,
                             global.getSwitchesColumn().getData()));
-            transaction.add(op.comment("Global: Mutating " +
-                            physicalSwitchAugmentation.getHwvtepNodeName().getValue() + " " + pswitchUuid));
+            transaction.add(op.comment("Global: Mutating "
+                            physicalSwitchAugmentation.getHwvtepNodeName().getValue() + " " + pswitchUuid));
         } else {
             PhysicalSwitchAugmentation updatedPhysicalSwitch = operationalPhysicalSwitchOptional.get();
             String existingPhysicalSwitchName = updatedPhysicalSwitch.getHwvtepNodeName().getValue();
             /* In case TOR devices don't allow creation of PhysicalSwitch name might be null
              * as user is only adding configurable parameters to MDSAL like BFD params
-             * 
+             *
              * TODO Note: Consider handling tunnel udpate/remove in separate command
              */
-            if(existingPhysicalSwitchName == null) {
+            if (existingPhysicalSwitchName == null) {
                 existingPhysicalSwitchName = operationalPhysicalSwitchOptional.get().getHwvtepNodeName().getValue();
             }
             // Name is immutable, and so we *can't* update it.  So we use extraPhysicalSwitch for the schema stuff
-            PhysicalSwitch extraPhysicalSwitch = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), PhysicalSwitch.class);
+            PhysicalSwitch extraPhysicalSwitch = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(),
+                    PhysicalSwitch.class);
             extraPhysicalSwitch.setName("");
             LOG.trace("execute: updating physical switch: {}", physicalSwitch);
             transaction.add(op.update(physicalSwitch)
@@ -138,7 +137,8 @@ public class PhysicalSwitchUpdateCommand extends AbstractTransactCommand {
             Optional<PhysicalSwitchAugmentation> operationalPhysicalSwitchOptional) {
         if (physicalSwitchAugmentation.getHwvtepNodeName() != null) {
             physicalSwitch.setName(physicalSwitchAugmentation.getHwvtepNodeName().getValue());
-        } else if (operationalPhysicalSwitchOptional.isPresent() && operationalPhysicalSwitchOptional.get().getHwvtepNodeName() != null) {
+        } else if (operationalPhysicalSwitchOptional.isPresent()
+                && operationalPhysicalSwitchOptional.get().getHwvtepNodeName() != null) {
             physicalSwitch.setName(operationalPhysicalSwitchOptional.get().getHwvtepNodeName().getValue());
         }
     }
@@ -149,7 +149,8 @@ public class PhysicalSwitchUpdateCommand extends AbstractTransactCommand {
         }
     }
 
-    private void setManagementIps(PhysicalSwitch physicalSwitch, PhysicalSwitchAugmentation physicalSwitchAugmentation) {
+    private void setManagementIps(PhysicalSwitch physicalSwitch,
+            PhysicalSwitchAugmentation physicalSwitchAugmentation) {
         Set<String> ipSet = new HashSet<>();
         if (physicalSwitchAugmentation.getManagementIps() != null) {
             for (ManagementIps ip: physicalSwitchAugmentation.getManagementIps()) {
@@ -172,11 +173,11 @@ public class PhysicalSwitchUpdateCommand extends AbstractTransactCommand {
     @SuppressWarnings("unchecked")
     private void setTunnels(TransactionBuilder transaction, InstanceIdentifier<Node> iid,
                     PhysicalSwitch physicalSwitch, PhysicalSwitchAugmentation physicalSwitchAugmentation,
-                    boolean pSwitchExists) {
+                    boolean switchExists) {
         //TODO: revisit this code for optimizations
         //TODO: needs more testing
-        if(physicalSwitchAugmentation.getTunnels() != null) {
-            for(Tunnels tunnel: physicalSwitchAugmentation.getTunnels()) {
+        if (physicalSwitchAugmentation.getTunnels() != null) {
+            for (Tunnels tunnel : physicalSwitchAugmentation.getTunnels()) {
                 Optional<Tunnels> opTunnelOpt = getOperationalState().getTunnels(iid, tunnel.getKey());
                 Tunnel newTunnel = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Tunnel.class);
 
@@ -184,7 +185,7 @@ public class PhysicalSwitchUpdateCommand extends AbstractTransactCommand {
                                 (InstanceIdentifier<TerminationPoint>) tunnel.getLocalLocatorRef().getValue());
                 UUID remoteUUID = getLocatorUUID(transaction,
                                 (InstanceIdentifier<TerminationPoint>) tunnel.getRemoteLocatorRef().getValue());
-                if(localUUID != null && remoteUUID != null) {
+                if (localUUID != null && remoteUUID != null) {
                     UUID uuid;
                     // local and remote must exist
                     newTunnel.setLocal(localUUID);
@@ -192,31 +193,31 @@ public class PhysicalSwitchUpdateCommand extends AbstractTransactCommand {
                     setBfdParams(newTunnel, tunnel);
                     setBfdLocalConfigs(newTunnel, tunnel);
                     setBfdRemoteConfigs(newTunnel, tunnel);
-                    if(!opTunnelOpt.isPresent()) {
+                    if (!opTunnelOpt.isPresent()) {
                         String tunnelUuid = "Tunnel_" + HwvtepSouthboundMapper.getRandomUUID();
                         transaction.add(op.insert(newTunnel).withId(tunnelUuid));
                         transaction.add(op.comment("Tunnel: Creating " + tunnelUuid));
-                        if(!pSwitchExists) {
+                        if (!switchExists) {
                             //TODO: Figure out a way to handle this
                             LOG.warn("Tunnel configuration requires pre-existing physicalSwitch");
                         } else {
                             // TODO: Can we reuse physicalSwitch instead?
-                            PhysicalSwitch pSwitch =
+                            PhysicalSwitch phySwitch =
                                             TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(),
                                                             PhysicalSwitch.class);
-                            pSwitch.setTunnels(Collections.singleton(new UUID(tunnelUuid)));
-                            pSwitch.setName(physicalSwitchAugmentation.getHwvtepNodeName().getValue());
-                            transaction.add(op.mutate(pSwitch)
-                                            .addMutation(pSwitch.getTunnels().getSchema(), Mutator.INSERT,
-                                                    pSwitch.getTunnels().getData())
-                                            .where(pSwitch.getNameColumn().getSchema().
-                                                            opEqual(pSwitch.getNameColumn().getData()))
+                            phySwitch.setTunnels(Collections.singleton(new UUID(tunnelUuid)));
+                            phySwitch.setName(physicalSwitchAugmentation.getHwvtepNodeName().getValue());
+                            transaction.add(op.mutate(phySwitch)
+                                            .addMutation(phySwitch.getTunnels().getSchema(), Mutator.INSERT,
+                                                    phySwitch.getTunnels().getData())
+                                            .where(phySwitch.getNameColumn().getSchema()
+                                                            .opEqual(phySwitch.getNameColumn().getData()))
                                             .build());
                             transaction.add(op.comment("PhysicalSwitch: Mutating " + tunnelUuid));
                         }
                         uuid = new UUID(tunnelUuid);
                     } else {
-                        uuid = new UUID (opTunnelOpt.get().getTunnelUuid().getValue());
+                        uuid = new UUID(opTunnelOpt.get().getTunnelUuid().getValue());
                         Tunnel extraTunnel =
                                 TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Tunnel.class, null);
                         extraTunnel.getUuidColumn().setData(uuid);
@@ -232,9 +233,9 @@ public class PhysicalSwitchUpdateCommand extends AbstractTransactCommand {
 
     private void setBfdParams(Tunnel tunnel, Tunnels psAugTunnel) {
         List<BfdParams> bfdParams = psAugTunnel.getBfdParams();
-        if(bfdParams != null) {
+        if (bfdParams != null) {
             Map<String, String> bfdParamMap = new HashMap<>();
-            for(BfdParams bfdParam : bfdParams) {
+            for (BfdParams bfdParam : bfdParams) {
                 bfdParamMap.put(bfdParam.getBfdParamKey(), bfdParam.getBfdParamValue());
             }
             try {
@@ -247,9 +248,9 @@ public class PhysicalSwitchUpdateCommand extends AbstractTransactCommand {
 
     private void setBfdLocalConfigs(Tunnel tunnel, Tunnels psAugTunnel) {
         List<BfdLocalConfigs> bfdLocalConfigs = psAugTunnel.getBfdLocalConfigs();
-        if(bfdLocalConfigs != null) {
+        if (bfdLocalConfigs != null) {
             Map<String, String> configLocalMap = new HashMap<>();
-            for(BfdLocalConfigs localConfig : bfdLocalConfigs) {
+            for (BfdLocalConfigs localConfig : bfdLocalConfigs) {
                 configLocalMap.put(localConfig.getBfdLocalConfigKey(), localConfig.getBfdLocalConfigValue());
             }
             try {
@@ -262,9 +263,9 @@ public class PhysicalSwitchUpdateCommand extends AbstractTransactCommand {
 
     private void setBfdRemoteConfigs(Tunnel tunnel, Tunnels psAugTunnel) {
         List<BfdRemoteConfigs> bfdRemoteConfigs = psAugTunnel.getBfdRemoteConfigs();
-        if(bfdRemoteConfigs != null) {
+        if (bfdRemoteConfigs != null) {
             Map<String, String> configRemoteMap = new HashMap<>();
-            for(BfdRemoteConfigs remoteConfig : bfdRemoteConfigs) {
+            for (BfdRemoteConfigs remoteConfig : bfdRemoteConfigs) {
                 configRemoteMap.put(remoteConfig.getBfdRemoteConfigKey(), remoteConfig.getBfdRemoteConfigValue());
             }
             try {
@@ -308,7 +309,8 @@ public class PhysicalSwitchUpdateCommand extends AbstractTransactCommand {
                 final DataObjectModification<Node> mod = change.getRootNode();
                 Node created = TransactUtils.getCreated(mod);
                 if (created != null) {
-                    PhysicalSwitchAugmentation physicalSwitch = created.getAugmentation(PhysicalSwitchAugmentation.class);
+                    PhysicalSwitchAugmentation physicalSwitch =
+                            created.getAugmentation(PhysicalSwitchAugmentation.class);
                     if (physicalSwitch != null) {
                         result.put(key, physicalSwitch);
                     }
@@ -327,7 +329,8 @@ public class PhysicalSwitchUpdateCommand extends AbstractTransactCommand {
                 final DataObjectModification<Node> mod = change.getRootNode();
                 Node updated = TransactUtils.getUpdated(mod);
                 if (updated != null) {
-                    PhysicalSwitchAugmentation physicalSwitch = updated.getAugmentation(PhysicalSwitchAugmentation.class);
+                    PhysicalSwitchAugmentation physicalSwitch =
+                            updated.getAugmentation(PhysicalSwitchAugmentation.class);
                     if (physicalSwitch != null) {
                         result.put(key, physicalSwitch);
                     }