Sonar clean-up: braces for control statements
[netvirt.git] / openstack / net-virt / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / api / LoadBalancerConfiguration.java
index 7965a9e96318bad5979a498bef4ded1ac283910b..ccb8655222fbe51f0d7b8a9c1a847558fcfac608 100755 (executable)
@@ -19,10 +19,9 @@ import java.util.Map;
  */
 
 public class LoadBalancerConfiguration {
+    public static final String PROTOCOL_TCP = "TCP";
     public static final String PROTOCOL_HTTP = "HTTP";
     public static final String PROTOCOL_HTTPS = "HTTPS";
-    public static final Integer PROTOCOL_HTTP_PORT = 80;
-    public static final Integer PROTOCOL_HTTPS_PORT = 443;
 
     public class LoadBalancerPoolMember {
         String ipAddr;
@@ -63,16 +62,50 @@ public class LoadBalancerConfiguration {
         public void setIndex(int index) {
             this.index = index;
         }
-        public boolean equals(LoadBalancerPoolMember other) {
-            if (other.ipAddr != ipAddr)
+
+        /**
+         * Overridden equals() where index is not checked.
+         */
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj) {
+                return true;
+            }
+            if (obj == null) {
+                return false;
+            }
+            if (getClass() != obj.getClass()) {
                 return false;
-            else if (other.macAddr != macAddr)
+            }
+            LoadBalancerPoolMember other = (LoadBalancerPoolMember) obj;
+            if (ipAddr == null) {
+                if (other.ipAddr != null) {
+                    return false;
+                }
+            } else if (!ipAddr.equals(other.ipAddr)) {
                 return false;
-            else if (other.protocol != protocol)
+            }
+            if (macAddr == null) {
+                if (other.macAddr != null) {
+                    return false;
+                }
+            } else if (!macAddr.equals(other.macAddr)) {
                 return false;
-            else if (other.port != port)
+            }
+            if (port == null) {
+                if (other.port != null) {
+                    return false;
+                }
+            } else if (!port.equals(other.port)) {
                 return false;
-            //Ignore Index
+            }
+            if (protocol == null) {
+                if (other.protocol != null) {
+                    return false;
+                }
+            } else if (!protocol.equals(other.protocol)) {
+                return false;
+            }
             return true;
         }
 
@@ -85,18 +118,20 @@ public class LoadBalancerConfiguration {
         @Override
         public int hashCode() {
             final int prime = 31;
-            int result = super.hashCode();
+            int result = 1;
             result = prime * result + ((ipAddr == null) ? 0 : ipAddr.hashCode());
             result = prime * result + ((macAddr == null) ? 0 : macAddr.hashCode());
             result = prime * result + ((protocol == null) ? 0 : protocol.hashCode());
             result = prime * result + ((port == null) ? 0 : port.hashCode());
-            result = prime * result + index;
             return result;
         }
     }
 
     private String name;
     private String vip;
+    private String vmac; //Used when a dummy neutron port is created for the VIP
+    private String providerNetworkType;
+    private String providerSegmentationId;
     private Map <String, LoadBalancerPoolMember> members;
 
     public LoadBalancerConfiguration() {
@@ -107,12 +142,23 @@ public class LoadBalancerConfiguration {
         this.members = Maps.newHashMap();
         this.name = name;
         this.vip = vip;
+        this.vmac = null;
+    }
+
+    public LoadBalancerConfiguration(String name, String vip, String vmac) {
+        this.members = Maps.newHashMap();
+        this.name = name;
+        this.vip = vip;
+        this.vmac = vmac;
     }
 
     public LoadBalancerConfiguration(LoadBalancerConfiguration lbConfig) {
         this.members = Maps.newHashMap(lbConfig.getMembers());
         this.name = lbConfig.getName();
         this.vip = lbConfig.getVip();
+        this.vmac = lbConfig.getVmac();
+        this.providerNetworkType = lbConfig.getProviderNetworkType();
+        this.providerSegmentationId = lbConfig.getProviderSegmentationId();
     }
 
     public Map<String, LoadBalancerPoolMember> getMembers() {
@@ -121,8 +167,9 @@ public class LoadBalancerConfiguration {
 
     public Map<String, LoadBalancerPoolMember> addMember(String uuid, LoadBalancerPoolMember member) {
         //If index is not set for this object, update it before inserting
-        if (member.getIndex() == -1)
+        if (member.getIndex() == -1) {
             member.setIndex(members.size());
+        }
         this.members.put(uuid, member);
         return this.members;
     }
@@ -136,16 +183,21 @@ public class LoadBalancerConfiguration {
         /* Update indices of all other members
          */
         int index = 0;
-        for(Map.Entry<String, LoadBalancerPoolMember> entry : this.getMembers().entrySet())
+        for(Map.Entry<String, LoadBalancerPoolMember> entry : this.getMembers().entrySet()) {
             ((LoadBalancerPoolMember) entry.getValue()).setIndex(index++);
+        }
         return this.members;
     }
 
     public boolean isValid() {
-        if (members.size() == 0)
+        if (members.size() == 0) {
+            return false;
+        } else if (providerNetworkType == null) {
             return false;
+        }
         return true;
     }
+
     public void setVip(String vip) {
         this.vip = vip;
     }
@@ -154,6 +206,14 @@ public class LoadBalancerConfiguration {
         return this.vip;
     }
 
+    public void setVmac(String vmac) {
+        this.vmac = vmac;
+    }
+
+    public String getVmac() {
+        return this.vmac;
+    }
+
     public void setName(String name) {
         this.name = name;
     }
@@ -162,9 +222,27 @@ public class LoadBalancerConfiguration {
         return this.name;
     }
 
+    public void setProviderSegmentationId(String providerSegmentationId) {
+        this.providerSegmentationId = providerSegmentationId;
+    }
+
+    public String getProviderSegmentationId() {
+        return this.providerSegmentationId;
+    }
+    public void setProviderNetworkType(String providerNetworkType) {
+        this.providerNetworkType = providerNetworkType;
+    }
+
+    public String getProviderNetworkType() {
+        return this.providerNetworkType;
+    }
+
     @Override
     public String toString() {
-        return "LoadBalancerConfiguration [name=" + name + ", vip=" + vip +
+        return "LoadBalancerConfiguration [name=" + name +
+                ", vip=" + vip + ", vmac=" + vmac +
+                ", networkType=" + providerNetworkType +
+                ", segmentationId=" + providerSegmentationId +
                 ", members=" + members + "]";
     }
 }