Sonar clean-ups 67/26767/1
authorStephen Kitt <skitt@redhat.com>
Thu, 10 Sep 2015 12:40:14 +0000 (14:40 +0200)
committerStephen Kitt <skitt@redhat.com>
Thu, 10 Sep 2015 12:54:25 +0000 (14:54 +0200)
Starting from source files containing collapsible ifs:
* merge collapsible ifs;
* remove unused parameters;
* remove unused exceptions;
* remove unused fields;
* rename shadowing variables;
* add private constructors for utility classes;
* use more specific exceptions than RuntimeException;
* clean up "if () return true; else return false;";
* some Java 7 <> operators;
* add missing "static" for constants;
* remove unused private methods (except in OF13Provider);
* move some inline comments above the corresponding source line;
* used boolean instead of Boolean for Map::contains();
* replace foreach-style constructs examining the first element only
  with explicit "if (...hasNext()) ... = ... next()";
* prohibit overriding methods called from constructors;
* remove useless casts.

Reverse the order of node augmentation handling in SouthboundUtil so
that the augmentation case can actually trigger.

Change-Id: Ie4fc662bdcc0e2133fdd4f57b783723466b1f2a9
Signed-off-by: Stephen Kitt <skitt@redhat.com>
20 files changed:
library/impl/src/main/java/org/opendaylight/ovsdb/lib/jsonrpc/JsonRpcDecoder.java
library/impl/src/main/java/org/opendaylight/ovsdb/lib/notation/json/ConditionSerializer.java
library/impl/src/main/java/org/opendaylight/ovsdb/lib/notation/json/Converter.java
library/impl/src/main/java/org/opendaylight/ovsdb/lib/notation/json/MutationSerializer.java
library/impl/src/main/java/org/opendaylight/ovsdb/lib/notation/json/OvsdbMapSerializer.java
library/impl/src/main/java/org/opendaylight/ovsdb/lib/notation/json/OvsdbSetSerializer.java
library/impl/src/main/java/org/opendaylight/ovsdb/lib/notation/json/RowSerializer.java
library/impl/src/main/java/org/opendaylight/ovsdb/lib/notation/json/UUIDSerializer.java
library/impl/src/main/java/org/opendaylight/ovsdb/lib/schema/ColumnSchema.java
library/impl/src/main/java/org/opendaylight/ovsdb/lib/schema/ColumnType.java
library/impl/src/main/java/org/opendaylight/ovsdb/lib/schema/typed/TyperUtils.java
northbound/src/main/java/org/opendaylight/ovsdb/northbound/OvsdbRow.java
openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/OF13Provider.java
openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/PipelineOrchestratorImpl.java
openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/services/arp/GatewayMacResolverService.java
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/SouthboundHandler.java
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/impl/BridgeConfigurationManagerImpl.java
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/impl/NeutronL3Adapter.java
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/impl/SecurityServicesImpl.java
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundUtil.java

index 20f559465180c50be311e43cdb3968b68d7116c7..557d17db5486c2e73fabf3d6c7c9926ba9d95abd 100644 (file)
@@ -117,21 +117,19 @@ public class JsonRpcDecoder extends ByteToMessageDecoder {
                 break;
             }
 
-            if (index - buf.readerIndex() >= maxFrameLength) {
-                /*
-                 * Changing this limit to being a warning, we do not wish to "break" in scale environment
-                 * and currently this limits the ovs of having only around 50 ports defined...
-                 * I do acknowledge the fast that this might be risky in case of huge amount of strings
-                 * in which the controller can crash with an OOM, however seems that we need a really huge
-                 * ovs to reach that limit.
-                 */
-
-                //We do not want to issue a log message on every extent of the buffer
-                //hence logging only once
-                if (!maxFrameLimitWasReached) {
-                    maxFrameLimitWasReached = true;
-                    LOG.warn("***** OVSDB Frame limit of {} bytes has been reached! *****", this.maxFrameLength);
-                }
+            /*
+             * Changing this limit to being a warning, we do not wish to "break" in scale environment
+             * and currently this limits the ovs of having only around 50 ports defined...
+             * I do acknowledge the fast that this might be risky in case of huge amount of strings
+             * in which the controller can crash with an OOM, however seems that we need a really huge
+             * ovs to reach that limit.
+             */
+
+            //We do not want to issue a log message on every extent of the buffer
+            //hence logging only once
+            if (index - buf.readerIndex() >= maxFrameLength && !maxFrameLimitWasReached) {
+                maxFrameLimitWasReached = true;
+                LOG.warn("***** OVSDB Frame limit of {} bytes has been reached! *****", this.maxFrameLength);
             }
         }
 
index bc518941e1c1184b79fff6d246c9d8853e366e38..3185feff5f6cc37932a51c0f4d1b597834194292 100644 (file)
@@ -13,15 +13,13 @@ import java.io.IOException;
 import org.opendaylight.ovsdb.lib.notation.Condition;
 
 import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.JsonSerializer;
 import com.fasterxml.jackson.databind.SerializerProvider;
 
 public class ConditionSerializer extends JsonSerializer<Condition> {
     @Override
     public void serialize(Condition condition, JsonGenerator generator,
-        SerializerProvider provider) throws IOException,
-            JsonProcessingException {
+        SerializerProvider provider) throws IOException {
         generator.writeStartArray();
         generator.writeString(condition.getColumn());
         generator.writeString(condition.getFunction().toString());
index c0bce1b7eed630f8566038803cec2e0e412b1840..0a43b41286d7456b5c4bf4eb6e4bff1718387682 100644 (file)
@@ -26,6 +26,10 @@ public class Converter {
     static SetDeser setDeser = new SetDeser();
     static UpdateNotificationDeser unDeser = new UpdateNotificationDeser();
 
+    private Converter() {
+        // Prevent instantiating a utility class
+    }
+
     public static class MapConverter extends StdConverter<JsonNode, OvsdbMap<Object, Object>> {
         @Override
         public OvsdbMap<Object, Object> convert(JsonNode value) {
@@ -49,30 +53,28 @@ public class Converter {
 
     static class MapDeser {
         public OvsdbMap<Object, Object> deserialize(JsonNode node) {
-            if (node.isArray()) {
-                if (node.size() == 2) {
-                    if (node.get(0).isTextual() && "map".equals(node.get(0).asText())) {
-                        OvsdbMap<Object, Object> map = new OvsdbMap<Object, Object>();
-                        for (JsonNode pairNode : node.get(1)) {
-                            if (pairNode.isArray() && node.size() == 2) {
-                                Object key = atomDeser.deserialize(pairNode.get(0));
-                                Object value = atomDeser.deserialize(pairNode.get(1));
-                                map.put(key, value);
-                            }
+            if (node.isArray() && node.size() == 2) {
+                if (node.get(0).isTextual() && "map".equals(node.get(0).asText())) {
+                    OvsdbMap<Object, Object> map = new OvsdbMap<>();
+                    for (JsonNode pairNode : node.get(1)) {
+                        if (pairNode.isArray() && node.size() == 2) {
+                            Object key = atomDeser.deserialize(pairNode.get(0));
+                            Object value = atomDeser.deserialize(pairNode.get(1));
+                            map.put(key, value);
                         }
-                        return map;
-                    } else if (node.size() == 0) {
-                        return null;
                     }
+                    return map;
+                } else if (node.size() == 0) {
+                    return null;
                 }
             }
-            throw new RuntimeException("not a map type");
+            throw new IllegalArgumentException("not a map type");
         }
     }
 
     static class SetDeser {
         public OvsdbSet<Object> deserialize(JsonNode node) {
-            OvsdbSet<Object> set = new OvsdbSet<Object>();
+            OvsdbSet<Object> set = new OvsdbSet<>();
             if (node.isArray()) {
                 if (node.size() == 2) {
                     if (node.get(0).isTextual() && "set".equals(node.get(0).asText())) {
@@ -97,16 +99,14 @@ public class Converter {
     static class UpdateNotificationDeser {
         public UpdateNotification deserialize(JsonNode node) {
             UpdateNotification un = new UpdateNotification();
-            if (node.isArray()) {
-                if (node.size() == 2) {
-                    un.setContext(node.get(0).asText());
-                    un.setUpdates(node.get(1));
-                    ObjectMapper objectMapper = new ObjectMapper();
-                    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                    TableUpdates updates = objectMapper.convertValue(node.get(1), TableUpdates.class);
-                    un.setUpdate(updates);
-                    return un;
-                }
+            if (node.isArray() && node.size() == 2) {
+                un.setContext(node.get(0).asText());
+                un.setUpdates(node.get(1));
+                ObjectMapper objectMapper = new ObjectMapper();
+                objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+                TableUpdates updates = objectMapper.convertValue(node.get(1), TableUpdates.class);
+                un.setUpdate(updates);
+                return un;
             }
             return null;
         }
@@ -132,13 +132,12 @@ public class Converter {
                 }
             }
 
-            if (node.isArray() && node.get(0).isTextual()) {
-                if ("uuid".equals(node.get(0).asText()) || "named-uuid".equals(node.get(0).asText())) {
-                    return new UUID(node.get(1).asText());
-                }
+            if (node.isArray() && node.get(0).isTextual()
+                    && ("uuid".equals(node.get(0).asText()) || "named-uuid".equals(node.get(0).asText()))) {
+                return new UUID(node.get(1).asText());
             }
 
-            throw new RuntimeException("not an atom node");
+            throw new IllegalArgumentException("not an atom node");
         }
     }
 }
index 2bc56694495df380d9a0b10712d4c335e7c2901d..127c6f364c61e62e3d85544989ea19c9bc357c59 100644 (file)
@@ -13,15 +13,13 @@ import java.io.IOException;
 import org.opendaylight.ovsdb.lib.notation.Mutation;
 
 import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.JsonSerializer;
 import com.fasterxml.jackson.databind.SerializerProvider;
 
 public class MutationSerializer extends JsonSerializer<Mutation> {
     @Override
     public void serialize(Mutation condition, JsonGenerator generator,
-        SerializerProvider provider) throws IOException,
-            JsonProcessingException {
+        SerializerProvider provider) throws IOException {
         generator.writeStartArray();
         generator.writeString(condition.getColumn());
         generator.writeString(condition.getMutator().toString());
index b184725e268f5be0b552ebf5998c6879251d2bb8..ee5299363e7cdf427f2f2653f434b98345444448 100644 (file)
@@ -13,15 +13,13 @@ import java.util.Map;
 import org.opendaylight.ovsdb.lib.notation.OvsdbMap;
 
 import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.JsonSerializer;
 import com.fasterxml.jackson.databind.SerializerProvider;
 
 public class OvsdbMapSerializer extends JsonSerializer<OvsdbMap<?,?>> {
     @Override
     public void serialize(OvsdbMap<?,?> map, JsonGenerator generator,
-        SerializerProvider provider) throws IOException,
-            JsonProcessingException {
+        SerializerProvider provider) throws IOException {
         generator.writeStartArray();
         generator.writeString("map");
         generator.writeStartArray();
index 6675ba8060b3f5ee24ddf3d6f33398a6f53d2080..0c8f7071222366bfbc3387eb0ca5da9fe8f0b03a 100644 (file)
@@ -14,15 +14,13 @@ import java.util.Set;
 import org.opendaylight.ovsdb.lib.notation.OvsdbSet;
 
 import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.JsonSerializer;
 import com.fasterxml.jackson.databind.SerializerProvider;
 
 public class OvsdbSetSerializer extends JsonSerializer<OvsdbSet<?>> {
     @Override
     public void serialize(OvsdbSet<?> set, JsonGenerator generator,
-        SerializerProvider provider) throws IOException,
-            JsonProcessingException {
+        SerializerProvider provider) throws IOException {
         generator.writeStartArray();
         generator.writeString("set");
         generator.writeStartArray();
index 136ff728aab6332cc6f6599761b29b2525edb3c8..79d0e9e842a1f4ecbb10fd346d051c5907fe2576 100644 (file)
@@ -15,15 +15,13 @@ import org.opendaylight.ovsdb.lib.notation.Column;
 import org.opendaylight.ovsdb.lib.notation.Row;
 
 import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.JsonSerializer;
 import com.fasterxml.jackson.databind.SerializerProvider;
 
 public class RowSerializer extends JsonSerializer<Row> {
     @Override
     public void serialize(Row row, JsonGenerator generator,
-        SerializerProvider provider) throws IOException,
-            JsonProcessingException {
+        SerializerProvider provider) throws IOException {
         generator.writeStartObject();
         Collection<Column> columns = row.getColumns();
         for (Column<?,?> column : columns) {
index 04ccb312e593e983707faf6f3bcd437aa8587d4c..038165a98057fcbc8bb0200a54ce126de63b193f 100644 (file)
@@ -13,15 +13,13 @@ import java.io.IOException;
 import org.opendaylight.ovsdb.lib.notation.UUID;
 
 import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.JsonSerializer;
 import com.fasterxml.jackson.databind.SerializerProvider;
 
 public class UUIDSerializer extends JsonSerializer<UUID> {
     @Override
     public void serialize(UUID value, JsonGenerator generator,
-        SerializerProvider provider) throws IOException,
-            JsonProcessingException {
+        SerializerProvider provider) throws IOException {
         generator.writeStartArray();
         try {
             java.util.UUID.fromString(value.toString());
index 1db19b6595240579c4efa2b4a0be44bf62faf904..17d8de0242d80daff33d03ab131fd46d9fec0590 100644 (file)
@@ -23,8 +23,6 @@ import com.fasterxml.jackson.databind.JsonNode;
 public class ColumnSchema<E extends TableSchema<E>, D> {
     String name;
     ColumnType type;
-    boolean ephemeral;
-    boolean mutable;
 
     public ColumnSchema(String name, ColumnType columnType) {
         this.name = name;
@@ -125,9 +123,8 @@ public class ColumnSchema<E extends TableSchema<E>, D> {
     /**
      * Validates the passed in value against the constraints set for this ColumnSchema
      * @param value
-     * @throws java.lang.RuntimeException (validation exception)
      */
-    public D validate(Object value)throws RuntimeException {
+    public D validate(Object value) {
         //todo(type check and validate based on constraints set)
         this.type.validate(value);
         return (D) value;
@@ -146,7 +143,7 @@ public class ColumnSchema<E extends TableSchema<E>, D> {
     }
 
     public Object getNormalizeData(D value) {
-        Object untypedValue = null;
+        Object untypedValue;
         if (value instanceof Set) {
             untypedValue = OvsdbSet.fromSet((Set) value);
         } else if (value instanceof Map) {
index 85c4417eaa2127dbd3d1b5d21f163f90da1be88d..13074387bd54df90f5876fe22b96d574088a68f4 100644 (file)
@@ -164,8 +164,8 @@ public abstract class ColumnType {
         public AtomicColumnType() {
         }
 
-        public AtomicColumnType(BaseType baseType1) {
-            super(baseType1);
+        public AtomicColumnType(BaseType baseType) {
+            super(baseType);
         }
 
         @Override
@@ -173,11 +173,11 @@ public abstract class ColumnType {
             if (json.isObject() && json.has("value")) {
                 return null;
             }
-            BaseType baseType = BaseType.fromJson(json, "key");
+            BaseType jsonBaseType = BaseType.fromJson(json, "key");
 
-            if (baseType != null) {
+            if (jsonBaseType != null) {
 
-                AtomicColumnType atomicColumnType = new AtomicColumnType(baseType);
+                AtomicColumnType atomicColumnType = new AtomicColumnType(jsonBaseType);
 
                 JsonNode node;
                 if ((node = json.get("min")) != null) {
@@ -247,10 +247,10 @@ public abstract class ColumnType {
             if (json.isValueNode() || !json.has("value")) {
                 return null;
             }
-            BaseType keyType = BaseType.fromJson(json, "key");
+            BaseType jsonKeyType = BaseType.fromJson(json, "key");
             BaseType valueType = BaseType.fromJson(json, "value");
 
-            KeyValuedColumnType keyValueColumnType = new KeyValuedColumnType(keyType, valueType);
+            KeyValuedColumnType keyValueColumnType = new KeyValuedColumnType(jsonKeyType, valueType);
             JsonNode node;
             if ((node = json.get("min")) != null) {
                 keyValueColumnType.setMin(node.asLong());
@@ -269,21 +269,19 @@ public abstract class ColumnType {
 
         @Override
         public Object valueFromJson(JsonNode node) {
-            if (node.isArray()) {
-                if (node.size() == 2) {
-                    if (node.get(0).isTextual() && "map".equals(node.get(0).asText())) {
-                        OvsdbMap<Object, Object> map = new OvsdbMap<>();
-                        for (JsonNode pairNode : node.get(1)) {
-                            if (pairNode.isArray() && node.size() == 2) {
-                                Object key = getKeyType().toValue(pairNode.get(0));
-                                Object value = getBaseType().toValue(pairNode.get(1));
-                                map.put(key, value);
-                            }
+            if (node.isArray() && node.size() == 2) {
+                if (node.get(0).isTextual() && "map".equals(node.get(0).asText())) {
+                    OvsdbMap<Object, Object> map = new OvsdbMap<>();
+                    for (JsonNode pairNode : node.get(1)) {
+                        if (pairNode.isArray() && node.size() == 2) {
+                            Object key = getKeyType().toValue(pairNode.get(0));
+                            Object value = getBaseType().toValue(pairNode.get(1));
+                            map.put(key, value);
                         }
-                        return map;
-                    } else if (node.size() == 0) {
-                        return null;
                     }
+                    return map;
+                } else if (node.size() == 0) {
+                    return null;
                 }
             }
             return null;
index 934639f34a0fcbf0fcb1e8b1fd92ae18be568594..d59121e0675a49f6052949c7691e30d5dc507e5c 100644 (file)
@@ -38,6 +38,10 @@ public class TyperUtils {
     private static final String GETCOLUMN_ENDS_WITH = "Column";
     private static final String GETROW_ENDS_WITH = "Row";
 
+    private TyperUtils() {
+        // Prevent instantiating a utility class
+    }
+
     private static <T> String getTableName(Class<T> klazz) {
         TypedTable typedTable = klazz.getAnnotation(TypedTable.class);
         if (typedTable != null) {
@@ -82,58 +86,43 @@ public class TyperUtils {
 
     private static boolean isGetTableSchema(Method method) {
         TypedColumn typedColumn = method.getAnnotation(TypedColumn.class);
-        if (typedColumn != null) {
-            return typedColumn.method().equals(MethodType.GETTABLESCHEMA) ? true : false;
-        }
-        return false;
+        return typedColumn != null && typedColumn.method().equals(MethodType.GETTABLESCHEMA);
     }
 
     private static boolean isGetRow(Method method) {
         TypedColumn typedColumn = method.getAnnotation(TypedColumn.class);
         if (typedColumn != null) {
-            return typedColumn.method().equals(MethodType.GETROW) ? true : false;
+            return typedColumn.method().equals(MethodType.GETROW);
         }
 
-        if (method.getName().startsWith(GET_STARTS_WITH) && method.getName().endsWith(GETROW_ENDS_WITH)) {
-            return true;
-        }
-        return false;
+        return method.getName().startsWith(GET_STARTS_WITH) && method.getName().endsWith(GETROW_ENDS_WITH);
     }
 
     private static boolean isGetColumn(Method method) {
         TypedColumn typedColumn = method.getAnnotation(TypedColumn.class);
         if (typedColumn != null) {
-            return typedColumn.method().equals(MethodType.GETCOLUMN) ? true : false;
+            return typedColumn.method().equals(MethodType.GETCOLUMN);
         }
 
-        if (method.getName().startsWith(GET_STARTS_WITH) && method.getName().endsWith(GETCOLUMN_ENDS_WITH)) {
-            return true;
-        }
-        return false;
+        return method.getName().startsWith(GET_STARTS_WITH) && method.getName().endsWith(GETCOLUMN_ENDS_WITH);
     }
 
     private static boolean isGetData(Method method) {
         TypedColumn typedColumn = method.getAnnotation(TypedColumn.class);
         if (typedColumn != null) {
-            return typedColumn.method().equals(MethodType.GETDATA) ? true : false;
+            return typedColumn.method().equals(MethodType.GETDATA);
         }
 
-        if (method.getName().startsWith(GET_STARTS_WITH) && !method.getName().endsWith(GETCOLUMN_ENDS_WITH)) {
-            return true;
-        }
-        return false;
+        return method.getName().startsWith(GET_STARTS_WITH) && !method.getName().endsWith(GETCOLUMN_ENDS_WITH);
     }
 
     private static boolean isSetData(Method method) {
         TypedColumn typedColumn = method.getAnnotation(TypedColumn.class);
         if (typedColumn != null) {
-            return typedColumn.method().equals(MethodType.SETDATA) ? true : false;
+            return typedColumn.method().equals(MethodType.SETDATA);
         }
 
-        if (method.getName().startsWith(SET_STARTS_WITH)) {
-            return true;
-        }
-        return false;
+        return method.getName().startsWith(SET_STARTS_WITH);
     }
 
     public static Version getColumnFromVersion(Method method) {
@@ -183,10 +172,8 @@ public class TyperUtils {
         }
 
         TypedTable typedTable = klazz.getAnnotation(TypedTable.class);
-        if (typedTable != null) {
-            if (!dbSchema.getName().equalsIgnoreCase(typedTable.database())) {
-                return false;
-            }
+        if (typedTable != null && !dbSchema.getName().equalsIgnoreCase(typedTable.database())) {
+            return false;
         }
 
         checkTableSchemaVersion(dbSchema, klazz);
@@ -209,17 +196,13 @@ public class TyperUtils {
     }
 
     private static void checkVersion(Version schemaVersion, Version fromVersion, Version untilVersion) {
-        if (!fromVersion.equals(Version.NULL)) {
-            if (schemaVersion.compareTo(fromVersion) < 0) {
-                String message = SchemaVersionMismatchException.createMessage(schemaVersion, fromVersion);
-                throw new SchemaVersionMismatchException(message);
-            }
+        if (!fromVersion.equals(Version.NULL) && schemaVersion.compareTo(fromVersion) < 0) {
+            String message = SchemaVersionMismatchException.createMessage(schemaVersion, fromVersion);
+            throw new SchemaVersionMismatchException(message);
         }
-        if (!untilVersion.equals(Version.NULL)) {
-            if (schemaVersion.compareTo(untilVersion) > 0) {
-                String message = SchemaVersionMismatchException.createMessage(schemaVersion, untilVersion);
-                throw new SchemaVersionMismatchException(message);
-            }
+        if (!untilVersion.equals(Version.NULL) && schemaVersion.compareTo(untilVersion) > 0) {
+            String message = SchemaVersionMismatchException.createMessage(schemaVersion, untilVersion);
+            throw new SchemaVersionMismatchException(message);
         }
     }
 
@@ -272,7 +255,7 @@ public class TyperUtils {
             row.setTableSchema(getTableSchema(dbSchema, klazz));
         }
         return Reflection.newProxy(klazz, new InvocationHandler() {
-            private Object processGetData(Method method) throws Throwable {
+            private Object processGetData(Method method) {
                 String columnName = getColumnName(method);
                 checkColumnSchemaVersion(dbSchema, method);
                 if (columnName == null) {
@@ -296,11 +279,11 @@ public class TyperUtils {
                 return row.getColumn(columnSchema).getData();
             }
 
-            private Object processGetRow() throws Throwable {
+            private Object processGetRow() {
                 return row;
             }
 
-            private Object processGetColumn(Method method) throws Throwable {
+            private Object processGetColumn(Method method) {
                 String columnName = getColumnName(method);
                 checkColumnSchemaVersion(dbSchema, method);
                 if (columnName == null) {
@@ -326,7 +309,7 @@ public class TyperUtils {
                 return row.getColumn(columnSchema);
             }
 
-            private Object processSetData(Object proxy, Method method, Object[] args) throws Throwable {
+            private Object processSetData(Object proxy, Method method, Object[] args) {
                 if (args == null || args.length != 1) {
                     throw new TyperException("Setter method : " + method.getName() + " requires 1 argument");
                 }
@@ -339,7 +322,7 @@ public class TyperUtils {
                 ColumnSchema<GenericTableSchema, Object> columnSchema =
                         getColumnSchema(tableSchema, columnName, (Class<Object>) args[0].getClass());
                 Column<GenericTableSchema, Object> column =
-                        new Column<GenericTableSchema, Object>(columnSchema, args[0]);
+                        new Column<>(columnSchema, args[0]);
                 row.addColumn(columnName, column);
                 return proxy;
             }
@@ -358,7 +341,7 @@ public class TyperUtils {
                 return (args != null
                         && args.length == 1
                         && method.getName().equals("equals")
-                        && method.getParameterTypes()[0] == Object.class);
+                        && Object.class.equals(method.getParameterTypes()[0]));
             }
             private Boolean isToStringMethod(Method method, Object[] args) {
                 return (args == null || args.length == 0) && method.getName().equals("toString");
@@ -408,7 +391,7 @@ public class TyperUtils {
             }
 
             @Override public String toString() {
-                String tableName = null;
+                String tableName;
                 try {
                     TableSchema<?> schema = (TableSchema<?>)processGetTableSchema();
                     tableName = schema.getName();
@@ -441,15 +424,13 @@ public class TyperUtils {
         Preconditions.checkNotNull(klazz);
         Preconditions.checkNotNull(updates);
         Preconditions.checkNotNull(dbSchema);
-        Map<UUID,T> result = new HashMap<UUID,T>();
+        Map<UUID,T> result = new HashMap<>();
         Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> rowUpdates =
                 extractRowUpdates(klazz,updates,dbSchema);
         for (TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema> rowUpdate : rowUpdates.values()) {
-            if (rowUpdate != null) {
-                if (rowUpdate.getNew() != null) {
-                    Row<GenericTableSchema> row = rowUpdate.getNew();
-                    result.put(rowUpdate.getUuid(),TyperUtils.getTypedRowWrapper(dbSchema,klazz,row));
-                }
+            if (rowUpdate != null && rowUpdate.getNew() != null) {
+                Row<GenericTableSchema> row = rowUpdate.getNew();
+                result.put(rowUpdate.getUuid(),TyperUtils.getTypedRowWrapper(dbSchema,klazz,row));
             }
         }
         return result;
@@ -472,15 +453,13 @@ public class TyperUtils {
         Preconditions.checkNotNull(klazz);
         Preconditions.checkNotNull(updates);
         Preconditions.checkNotNull(dbSchema);
-        Map<UUID,T> result = new HashMap<UUID,T>();
+        Map<UUID,T> result = new HashMap<>();
         Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> rowUpdates =
                 extractRowUpdates(klazz,updates,dbSchema);
         for (TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema> rowUpdate : rowUpdates.values()) {
-            if (rowUpdate != null) {
-                if (rowUpdate.getOld() != null) {
-                    Row<GenericTableSchema> row = rowUpdate.getOld();
-                    result.put(rowUpdate.getUuid(),TyperUtils.getTypedRowWrapper(dbSchema,klazz,row));
-                }
+            if (rowUpdate != null && rowUpdate.getOld() != null) {
+                Row<GenericTableSchema> row = rowUpdate.getOld();
+                result.put(rowUpdate.getUuid(),TyperUtils.getTypedRowWrapper(dbSchema,klazz,row));
             }
         }
         return result;
@@ -503,15 +482,13 @@ public class TyperUtils {
         Preconditions.checkNotNull(klazz);
         Preconditions.checkNotNull(updates);
         Preconditions.checkNotNull(dbSchema);
-        Map<UUID,T> result = new HashMap<UUID,T>();
+        Map<UUID,T> result = new HashMap<>();
         Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> rowUpdates =
                 extractRowUpdates(klazz,updates,dbSchema);
         for (TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema> rowUpdate : rowUpdates.values()) {
-            if (rowUpdate != null) {
-                if (rowUpdate.getNew() == null && rowUpdate.getOld() != null) {
-                    Row<GenericTableSchema> row = rowUpdate.getOld();
-                    result.put(rowUpdate.getUuid(),TyperUtils.getTypedRowWrapper(dbSchema,klazz,row));
-                }
+            if (rowUpdate != null && rowUpdate.getNew() == null && rowUpdate.getOld() != null) {
+                Row<GenericTableSchema> row = rowUpdate.getOld();
+                result.put(rowUpdate.getUuid(),TyperUtils.getTypedRowWrapper(dbSchema,klazz,row));
             }
         }
         return result;
@@ -538,7 +515,7 @@ public class TyperUtils {
         Preconditions.checkNotNull(updates);
         Preconditions.checkNotNull(dbSchema);
         Map<UUID, TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> result =
-                new HashMap<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>>();
+                new HashMap<>();
         TableUpdate<GenericTableSchema> update = updates.getUpdate(TyperUtils.getTableSchema(dbSchema, klazz));
         if (update != null) {
             Map<UUID, TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> rows = update.getRows();
index 977bbbd9725e4f94f9cba49bd5e53d35399a56d8..ac954bf9efa0f77489aea4d3ea8920809493f642 100644 (file)
@@ -16,12 +16,14 @@ import org.opendaylight.ovsdb.lib.OvsdbClient;
 import org.opendaylight.ovsdb.lib.notation.Row;
 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
 import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-import com.fasterxml.jackson.core.JsonParseException;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 
 public class OvsdbRow {
+    private static final Logger LOG = LoggerFactory.getLogger(OvsdbRow.class);
     private static final String PARENTUUID = "parent_uuid";
     private static final String PARENTTABLE = "parent_table";
     private static final String PARENTCOLUMN = "parent_column";
@@ -70,21 +72,21 @@ public class OvsdbRow {
         if (rowNode == null) {
             return null;
         }
-        for(Iterator<String> fieldNames = rowNode.fieldNames(); fieldNames.hasNext();) {
+        Iterator<String> fieldNames = rowNode.fieldNames();
+        if (fieldNames.hasNext()) {
             String tableName = fieldNames.next();
-            Row<GenericTableSchema> row = null;
             try {
-                row = getRow(client, dbName, tableName, rowNode.get(tableName));
+                Row<GenericTableSchema> row = getRow(client, dbName, tableName, rowNode.get(tableName));
+                return new OvsdbRow(parentTable, parentUuid, parentColumn, tableName, row);
             } catch (InterruptedException | ExecutionException | IOException e) {
-                e.printStackTrace();
+                LOG.error("Error retrieving the row for {}", tableName, e);
                 return null;
             }
-            return new OvsdbRow(parentTable, parentUuid, parentColumn, tableName, row);
         }
         return null;
     }
 
-    public static Row<GenericTableSchema> getRow(OvsdbClient client, String dbName, String tableName, JsonNode rowJson) throws InterruptedException, ExecutionException, JsonParseException, IOException {
+    public static Row<GenericTableSchema> getRow(OvsdbClient client, String dbName, String tableName, JsonNode rowJson) throws InterruptedException, ExecutionException, IOException {
         DatabaseSchema dbSchema = client.getSchema(dbName).get();
         GenericTableSchema schema = dbSchema.table(tableName, GenericTableSchema.class);
         return schema.createRow((ObjectNode)rowJson);
index b8a096389b95d024011a9f2566ca88fb4c593c69..12879dadda1c22db175238ea5b35d3002beb1fe8 100644 (file)
@@ -1643,29 +1643,27 @@ public class OF13Provider implements ConfigInterface, NetworkingProvider {
                 }
             }
             LOG.debug("createOutputGroupInstructions: addNew {}", addNew);
-            if (addNew) {
+            if (addNew && !buckets.getBucket().isEmpty()) {
                 /* the new output action is not in the bucket, add to bucket */
-                if (!buckets.getBucket().isEmpty()) {
-                    Bucket bucket = buckets.getBucket().get(0);
-                    List<Action> bucketActionList = Lists.newArrayList();
-                    bucketActionList.addAll(bucket.getAction());
-                    /* set order for new action and add to action list */
-                    ab.setOrder(bucketActionList.size());
-                    ab.setKey(new ActionKey(bucketActionList.size()));
-                    bucketActionList.add(ab.build());
-
-                    /* set bucket and buckets list. Reset groupBuilder with new buckets.*/
-                    BucketsBuilder bucketsBuilder = new BucketsBuilder();
-                    List<Bucket> bucketList = Lists.newArrayList();
-                    BucketBuilder bucketBuilder = new BucketBuilder();
-                    bucketBuilder.setBucketId(new BucketId((long) 1));
-                    bucketBuilder.setKey(new BucketKey(new BucketId((long) 1)));
-                    bucketBuilder.setAction(bucketActionList);
-                    bucketList.add(bucketBuilder.build());
-                    bucketsBuilder.setBucket(bucketList);
-                    groupBuilder.setBuckets(bucketsBuilder.build());
-                    LOG.debug("createOutputGroupInstructions: bucketList {}", bucketList);
-                }
+                Bucket bucket = buckets.getBucket().get(0);
+                List<Action> bucketActionList = Lists.newArrayList();
+                bucketActionList.addAll(bucket.getAction());
+                /* set order for new action and add to action list */
+                ab.setOrder(bucketActionList.size());
+                ab.setKey(new ActionKey(bucketActionList.size()));
+                bucketActionList.add(ab.build());
+
+                /* set bucket and buckets list. Reset groupBuilder with new buckets.*/
+                BucketsBuilder bucketsBuilder = new BucketsBuilder();
+                List<Bucket> bucketList = Lists.newArrayList();
+                BucketBuilder bucketBuilder = new BucketBuilder();
+                bucketBuilder.setBucketId(new BucketId((long) 1));
+                bucketBuilder.setKey(new BucketKey(new BucketId((long) 1)));
+                bucketBuilder.setAction(bucketActionList);
+                bucketList.add(bucketBuilder.build());
+                bucketsBuilder.setBucket(bucketList);
+                groupBuilder.setBuckets(bucketsBuilder.build());
+                LOG.debug("createOutputGroupInstructions: bucketList {}", bucketList);
             }
         } else {
             /* create group */
index 87b3dee1d364fc815c22884b9af81ac0231f06dc..edea48c26cdc122d5e2c6cbd29dd478f62e90075 100644 (file)
@@ -83,7 +83,7 @@ public class PipelineOrchestratorImpl implements ConfigInterface, NodeCacheListe
         return serviceRegistry.get(service);
     }
 
-    public void start() {
+    public final void start() {
         eventHandler.submit(new Runnable()  {
             @Override
             public void run() {
@@ -93,11 +93,8 @@ public class PipelineOrchestratorImpl implements ConfigInterface, NodeCacheListe
                         LOG.info(">>>>> dequeue: {}", node);
                         for (Service service : staticPipeline) {
                             AbstractServiceInstance serviceInstance = getServiceInstance(service);
-                            //LOG.info("pipeline: {} - {}", service, serviceInstance);
-                            if (serviceInstance != null) {
-                                if (southbound.getBridge(node) != null) {
-                                    serviceInstance.programDefaultPipelineRule(node);
-                                }
+                            if (serviceInstance != null && southbound.getBridge(node) != null) {
+                                serviceInstance.programDefaultPipelineRule(node);
                             }
                         }
                     }
index d6ce3d8b7c4a5700ae81c087b04db56e82866b43..7c2cfbebae8a3ab589561b4d89ec27bd831f686b 100644 (file)
@@ -21,8 +21,6 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicLong;
 
-import javax.annotation.Nullable;
-
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.openflowplugin.api.OFConstants;
 import org.opendaylight.ovsdb.openstack.netvirt.api.GatewayMacResolver;
@@ -30,7 +28,6 @@ import org.opendaylight.ovsdb.openstack.netvirt.providers.ConfigInterface;
 import org.opendaylight.ovsdb.openstack.netvirt.providers.NetvirtProvidersProvider;
 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.AbstractServiceInstance;
 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.Service;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
@@ -100,11 +97,11 @@ public class GatewayMacResolverService extends AbstractServiceInstance
     private SalFlowService flowService;
     private final AtomicLong flowCookie = new AtomicLong();
     private final ConcurrentMap<Ipv4Address, ArpResolverMetadata> gatewayToArpMetadataMap =
-            new ConcurrentHashMap<Ipv4Address, ArpResolverMetadata>();
-    private final int ARP_WATCH_BROTHERS = 10;
-    private final int WAIT_CYCLES = 3;
-    private final int PER_CYCLE_WAIT_DURATION = 1000;
-    private final int REFRESH_INTERVAL = 10;
+            new ConcurrentHashMap<>();
+    private static final int ARP_WATCH_BROTHERS = 10;
+    private static final int WAIT_CYCLES = 3;
+    private static final int PER_CYCLE_WAIT_DURATION = 1000;
+    private static final int REFRESH_INTERVAL = 10;
     private final ListeningExecutorService arpWatcherWall = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(ARP_WATCH_BROTHERS));
     private final ScheduledExecutorService gatewayMacRefresherPool = Executors.newScheduledThreadPool(1);
     private final ScheduledExecutorService refreshRequester = Executors.newSingleThreadScheduledExecutor();
@@ -183,7 +180,6 @@ public class GatewayMacResolverService extends AbstractServiceInstance
      * @param sourceMacAddress Source Mac address for the ARP request packet
      * @param periodicRefresh Enable/Disable periodic refresh of the Gateway Mac address
      * NOTE:Periodic refresh is not supported yet.
-     * @param gatewayIp  Resolve MAC address of this Gateway Ip
      * @return Future object
      */
     @Override
@@ -305,13 +301,6 @@ public class GatewayMacResolverService extends AbstractServiceInstance
         });
     }
 
-    private static @Nullable Ipv4Address getIPv4Addresses(IpAddress ipAddress) {
-        if (ipAddress.getIpv4Address() == null) {
-            return null;
-        }
-        return ipAddress.getIpv4Address();
-    }
-
     private Flow createArpReplyToControllerFlow(final ArpMessageAddress senderAddress, final Ipv4Address ipForRequestedMac) {
         checkNotNull(senderAddress);
         checkNotNull(ipForRequestedMac);
@@ -330,11 +319,11 @@ public class GatewayMacResolverService extends AbstractServiceInstance
         arpFlow.setMatch(match);
         arpFlow.setInstructions(new InstructionsBuilder().setInstruction(
                 ImmutableList.of(SEND_TO_CONTROLLER_INSTRUCTION)).build());
-        arpFlow.setId(createFlowId(senderAddress, ipForRequestedMac));
+        arpFlow.setId(createFlowId(ipForRequestedMac));
         return arpFlow.build();
     }
 
-    private FlowId createFlowId(ArpMessageAddress senderAddress, Ipv4Address ipForRequestedMac) {
+    private FlowId createFlowId(Ipv4Address ipForRequestedMac) {
         String flowId = ARP_REPLY_TO_CONTROLLER_FLOW_NAME + "|" + ipForRequestedMac.getValue();
         return new FlowId(flowId);
     }
index 8f21cb8902070819fbb1aebc0b4718dbe45d13b1..8eaed984f10a106608882576d3d20b789f70b94b 100644 (file)
@@ -295,10 +295,8 @@ public class SouthboundHandler extends AbstractHandler
     private void processPortUpdate(Node node, OvsdbTerminationPointAugmentation port) {
         LOG.debug("processPortUpdate <{}> <{}>", node, port);
         NeutronNetwork network = tenantNetworkManager.getTenantNetwork(port);
-        if (network != null ){
-            if(!network.getRouterExternal()){
-                this.handleInterfaceUpdate(node, port);
-            }
+        if (network != null && !network.getRouterExternal()) {
+            this.handleInterfaceUpdate(node, port);
         }
     }
 
index a9e84bad2dc9f657b07c9c55433393d50818aa49..bc40093955545c17c1e73b8af2728f9f0a016d38 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.ovsdb.openstack.netvirt.impl;
 
 import org.opendaylight.neutron.spi.NeutronNetwork;
 import org.opendaylight.ovsdb.openstack.netvirt.ConfigInterface;
-import org.opendaylight.ovsdb.openstack.netvirt.MdsalHelper;
 import org.opendaylight.ovsdb.openstack.netvirt.NetworkHandler;
 import org.opendaylight.ovsdb.openstack.netvirt.api.BridgeConfigurationManager;
 import org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService;
@@ -127,19 +126,7 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
             Preconditions.checkNotNull(portNameExt);
 
             if (southbound.isBridgeOnOvsdbNode(ovsdbNode, brExt)) {
-                //this would look better if used a method like isNetworkPatchCreated()
-                if (isPortOnBridge(bridgeNode, portNameInt)) {
-                    Node extBridgeNode = southbound.readBridgeNode(ovsdbNode, brExt);
-                    if (isPortOnBridge(extBridgeNode, portNameExt)) {
-                        ready = true;
-                    } else {
-                        LOG.trace("isNodeL3Ready: node: {}, {} missing",
-                                bridgeNode, portNameExt);
-                    }
-                } else {
-                    LOG.trace("isNodeL3Ready: node: {}, {} missing",
-                            bridgeNode, portNameInt);
-                }
+                ready = isNetworkPatchCreated(bridgeNode, southbound.readBridgeNode(ovsdbNode, brExt));
             } else {
                 LOG.trace("isNodeL3Ready: node: {}, {} missing",
                         bridgeNode, brExt);
@@ -261,7 +248,7 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
     /**
      * Returns true if a patch port exists between the Integration Bridge and Network Bridge
      */
-    private boolean isNetworkPatchCreated(Node node, Node intBridge, Node netBridge) {
+    private boolean isNetworkPatchCreated(Node intBridge, Node netBridge) {
         Preconditions.checkNotNull(configurationService);
 
         boolean isPatchCreated = false;
@@ -280,7 +267,7 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
     /**
      * Creates the Integration Bridge
      */
-    private boolean createIntegrationBridge(Node ovsdbNode) throws Exception {
+    private boolean createIntegrationBridge(Node ovsdbNode) {
         Preconditions.checkNotNull(configurationService);
 
         if (!addBridge(ovsdbNode, configurationService.getIntegrationBridgeName())) {
@@ -290,7 +277,7 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
         return true;
     }
 
-    private boolean createExternalBridge(Node ovsdbNode) throws Exception {
+    private boolean createExternalBridge(Node ovsdbNode) {
         Preconditions.checkNotNull(configurationService);
 
         if (!addBridge(ovsdbNode, configurationService.getExternalBridgeName())) {
@@ -355,7 +342,7 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
                 Interface br-int
                     type: internal
      */
-    private boolean createBridges(Node bridgeNode, Node ovsdbNode, NeutronNetwork network) throws Exception {
+    private boolean createBridges(Node bridgeNode, Node ovsdbNode, NeutronNetwork network) {
         Preconditions.checkNotNull(configurationService);
         Preconditions.checkNotNull(networkingProviderManager);
 
@@ -408,7 +395,7 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
     /**
      * Add a Port to a Bridge
      */
-    private boolean addPortToBridge (Node node, String bridgeName, String portName) throws Exception {
+    private boolean addPortToBridge (Node node, String bridgeName, String portName) {
         boolean rv = true;
 
         if (southbound.extractTerminationPointAugmentation(node, portName) == null) {
@@ -432,7 +419,7 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
     /**
      * Add a Patch Port to a Bridge
      */
-    private boolean addPatchPort (Node node, String bridgeName, String portName, String peerPortName) throws Exception {
+    private boolean addPatchPort (Node node, String bridgeName, String portName, String peerPortName) {
         boolean rv = true;
 
         if (southbound.extractTerminationPointAugmentation(node, portName) == null) {
@@ -456,7 +443,7 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
     /**
      * Add Bridge to a Node
      */
-    private boolean addBridge(Node ovsdbNode, String bridgeName) throws Exception {
+    private boolean addBridge(Node ovsdbNode, String bridgeName) {
         boolean rv = true;
         if ((!southbound.isBridgeOnOvsdbNode(ovsdbNode, bridgeName)) ||
                 (southbound.getBridgeFromConfig(ovsdbNode, bridgeName) == null)) {
@@ -466,13 +453,10 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
     }
 
     private String getControllerIPAddress() {
-        InetAddress controllerIP = null;
-
         String addressString = ConfigProperties.getProperty(this.getClass(), "ovsdb.controller.address");
         if (addressString != null) {
             try {
-                controllerIP = InetAddress.getByName(addressString);
-                if (controllerIP != null) {
+                if (InetAddress.getByName(addressString) != null) {
                     return addressString;
                 }
             } catch (UnknownHostException e) {
@@ -483,8 +467,7 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
         addressString = ConfigProperties.getProperty(this.getClass(), "of.address");
         if (addressString != null) {
             try {
-                controllerIP = InetAddress.getByName(addressString);
-                if (controllerIP != null) {
+                if (InetAddress.getByName(addressString) != null) {
                     return addressString;
                 }
             } catch (UnknownHostException e) {
index f5ef9be5dea61ca7cb7e8af190fc6886699a62cc..b679902d379915abf3bdc006b1efc5cee6cd065a 100644 (file)
@@ -73,12 +73,17 @@ public class NeutronL3Adapter implements ConfigInterface {
     private volatile GatewayMacResolver gatewayMacResolver;
 
     private class FloatIpData {
-        private final Long dpid;          // br-int of node where floating ip is associated with tenant port
-        private final Long ofPort;        // patch port in br-int used to reach br-ex
-        private final String segId;       // segmentation id of the net where fixed ip is instantiated
-        private final String macAddress;  // mac address assigned to neutron port of floating ip
+        // br-int of node where floating ip is associated with tenant port
+        private final Long dpid;
+        // patch port in br-int used to reach br-ex
+        private final Long ofPort;
+        // segmentation id of the net where fixed ip is instantiated
+        private final String segId;
+        // mac address assigned to neutron port of floating ip
+        private final String macAddress;
         private final String floatingIpAddress;
-        private final String fixedIpAddress;  // ip address given to tenant vm
+        // ip address given to tenant vm
+        private final String fixedIpAddress;
         private final String neutronRouterMac;
 
         FloatIpData(final Long dpid, final Long ofPort, final String segId, final String macAddress,
@@ -212,14 +217,12 @@ public class NeutronL3Adapter implements ConfigInterface {
             }else{
                 NeutronNetwork externalNetwork = neutronNetworkCache.getNetwork(neutronPort.getNetworkUUID());
 
-                if(externalNetwork != null){
-                    if(externalNetwork.isRouterExternal()){
-                        final NeutronSubnet externalSubnet = getExternalNetworkSubnet(neutronPort);
-                        // TODO support IPv6
-                        if (externalSubnet != null &&
+                if (externalNetwork != null && externalNetwork.isRouterExternal()) {
+                    final NeutronSubnet externalSubnet = getExternalNetworkSubnet(neutronPort);
+                    // TODO support IPv6
+                    if (externalSubnet != null &&
                             externalSubnet.getIpVersion() == 4) {
-                            gatewayMacResolver.stopPeriodicRefresh(new Ipv4Address(externalSubnet.getGatewayIP()));
-                        }
+                        gatewayMacResolver.stopPeriodicRefresh(new Ipv4Address(externalSubnet.getGatewayIP()));
                     }
                 }
             }
@@ -234,7 +237,8 @@ public class NeutronL3Adapter implements ConfigInterface {
             for (Neutron_IPs neutronIP : neutronPort.getFixedIPs()) {
                 NeutronRouter_Interface neutronRouterInterface =
                         new NeutronRouter_Interface(neutronIP.getSubnetUUID(), neutronPort.getPortUUID());
-                neutronRouterInterface.setID(neutronIP.getSubnetUUID());  // id of router interface to be same as subnet
+                // id of router interface to be same as subnet
+                neutronRouterInterface.setID(neutronIP.getSubnetUUID());
                 neutronRouterInterface.setTenantID(neutronPort.getTenantID());
 
                 this.handleNeutronRouterInterfaceEvent(null /*neutronRouter*/, neutronRouterInterface, action);
@@ -245,14 +249,12 @@ public class NeutronL3Adapter implements ConfigInterface {
             // need to do this check here because a router interface is not added to a node until tenant becomes needed
             // there.
             //
-            if (!isDelete) {
-                if (neutronPort.getFixedIPs() != null) {
-                    for (Neutron_IPs neutronIP : neutronPort.getFixedIPs()) {
-                        NeutronRouter_Interface neutronRouterInterface =
+            if (!isDelete && neutronPort.getFixedIPs() != null) {
+                for (Neutron_IPs neutronIP : neutronPort.getFixedIPs()) {
+                    NeutronRouter_Interface neutronRouterInterface =
                             subnetIdToRouterInterfaceCache.get(neutronIP.getSubnetUUID());
-                        if (neutronRouterInterface != null) {
-                            this.handleNeutronRouterInterfaceEvent(null /*neutronRouter*/, neutronRouterInterface, action);
-                        }
+                    if (neutronRouterInterface != null) {
+                        this.handleNeutronRouterInterfaceEvent(null /*neutronRouter*/, neutronRouterInterface, action);
                     }
                 }
             }
@@ -345,7 +347,8 @@ public class NeutronL3Adapter implements ConfigInterface {
         // this.programFlowsForFloatingIP(neutronFloatingIP, action == Action.DELETE);
 
         if (action != Action.DELETE) {
-            programFlowsForFloatingIPArpAdd(neutronFloatingIP);  // must be first, as it updates floatIpDataMapCache
+            // must be first, as it updates floatIpDataMapCache
+            programFlowsForFloatingIPArpAdd(neutronFloatingIP);
 
             programFlowsForFloatingIPInbound(neutronFloatingIP, Action.ADD);
             programFlowsForFloatingIPOutbound(neutronFloatingIP, Action.ADD);
@@ -353,7 +356,8 @@ public class NeutronL3Adapter implements ConfigInterface {
             programFlowsForFloatingIPOutbound(neutronFloatingIP, Action.DELETE);
             programFlowsForFloatingIPInbound(neutronFloatingIP, Action.DELETE);
 
-            programFlowsForFloatingIPArpDelete(neutronFloatingIP.getID()); // must be last, as it updates floatIpDataMapCache
+            // must be last, as it updates floatIpDataMapCache
+            programFlowsForFloatingIPArpDelete(neutronFloatingIP.getID());
         }
     }
 
@@ -654,14 +658,14 @@ public class NeutronL3Adapter implements ConfigInterface {
         // will look at desired action for node.
 
         final String cacheKey = node.getNodeId().getValue() + ":" + providerSegmentationId + ":" + ipStr;
-        final Boolean isProgrammed = l3ForwardingCache.contains(cacheKey);
+        final boolean isProgrammed = l3ForwardingCache.contains(cacheKey);
 
-        if (actionForNode == Action.DELETE && isProgrammed == Boolean.FALSE) {
+        if (actionForNode == Action.DELETE && !isProgrammed) {
             LOG.trace("programL3ForwardingStage1 for node {} providerId {} mac {} ip {} action {} is already done",
                          node.getNodeId().getValue(), providerSegmentationId, macAddress, ipStr, actionForNode);
             return;
         }
-        if (actionForNode == Action.ADD && isProgrammed == Boolean.TRUE) {
+        if (actionForNode == Action.ADD && isProgrammed) {
             LOG.trace("programL3ForwardingStage1 for node {} providerId {} mac {} ip {} action {} is already done",
                     node.getNodeId().getValue(), providerSegmentationId, macAddress, ipStr, actionForNode);
             return;
@@ -914,16 +918,16 @@ public class NeutronL3Adapter implements ConfigInterface {
         final String cacheKey = node.getNodeId().getValue() + ":" +
                                 sourceSegmentationId + ":" + destinationSegmentationId + ":" +
                                 ipStr + "/" + Integer.toString(mask);
-        final Boolean isProgrammed = routerInterfacesCache.contains(cacheKey);
+        final boolean isProgrammed = routerInterfacesCache.contains(cacheKey);
 
-        if (actionForNode == Action.DELETE && isProgrammed == Boolean.FALSE) {
+        if (actionForNode == Action.DELETE && !isProgrammed) {
             LOG.trace("programRouterInterfaceStage1 for node {} sourceSegId {} destSegId {} mac {} ip {} mask {}" +
                          " action {} is already done",
                          node.getNodeId().getValue(), sourceSegmentationId, destinationSegmentationId,
                          macAddress, ipStr, mask, actionForNode);
             return;
         }
-        if (actionForNode == Action.ADD && isProgrammed == Boolean.TRUE) {
+        if (actionForNode == Action.ADD && isProgrammed) {
             LOG.trace("programRouterInterfaceStage1 for node {} sourceSegId {} destSegId {} mac {} ip {} mask {}" +
                          " action {} is already done",
                          node.getNodeId().getValue(), sourceSegmentationId, destinationSegmentationId,
@@ -981,14 +985,14 @@ public class NeutronL3Adapter implements ConfigInterface {
         // will look at desired action for node.
         //
         final String cacheKey = dpid + ":" + segOrOfPort + ":" + ipStr;
-        final Boolean isProgrammed = staticArpEntryCache.contains(cacheKey);
+        final boolean isProgrammed = staticArpEntryCache.contains(cacheKey);
 
-        if (action == Action.DELETE && isProgrammed == Boolean.FALSE) {
+        if (action == Action.DELETE && !isProgrammed) {
             LOG.trace("programStaticArpStage1 dpid {} segOrOfPort {} mac {} ip {} action {} is already done",
                     dpid, segOrOfPort, macAddress, ipStr, action);
             return true;
         }
-        if (action == Action.ADD && isProgrammed == Boolean.TRUE) {
+        if (action == Action.ADD && isProgrammed) {
             LOG.trace("programStaticArpStage1 dpid {} segOrOfPort {} mac {} ip {} action {} is already done",
                     dpid, segOrOfPort, macAddress, ipStr, action);
             return true;
@@ -1041,15 +1045,15 @@ public class NeutronL3Adapter implements ConfigInterface {
         // will look at desired action for node.
         //
         final String cacheKey = dpid + ":" + inboundOFPort + ":" + providerSegmentationId + ":" + matchAddress;
-        final Boolean isProgrammed = inboundIpRewriteCache.contains(cacheKey);
+        final boolean isProgrammed = inboundIpRewriteCache.contains(cacheKey);
 
-        if (action == Action.DELETE && isProgrammed == Boolean.FALSE) {
+        if (action == Action.DELETE && !isProgrammed) {
             LOG.trace("programInboundIpRewriteStage1 dpid {} OFPort {} seg {} matchAddress {} rewriteAddress {}" +
                     " action {} is already done",
                     dpid, inboundOFPort, providerSegmentationId, matchAddress, rewriteAddress, action);
             return true;
         }
-        if (action == Action.ADD && isProgrammed == Boolean.TRUE) {
+        if (action == Action.ADD && isProgrammed) {
             LOG.trace("programInboundIpRewriteStage1 dpid {} OFPort {} seg {} matchAddress {} rewriteAddress {}" +
                     " action is already done",
                     dpid, inboundOFPort, providerSegmentationId, matchAddress, rewriteAddress, action);
@@ -1106,14 +1110,14 @@ public class NeutronL3Adapter implements ConfigInterface {
         // will look at desired action for node.
         //
         final String cacheKey = node.getNodeId().getValue() + ":" + providerSegmentationId + ":" + cidr;
-        final Boolean isProgrammed = outboundIpRewriteExclusionCache.contains(cacheKey);
+        final boolean isProgrammed = outboundIpRewriteExclusionCache.contains(cacheKey);
 
-        if (actionForRewriteExclusion == Action.DELETE && isProgrammed == Boolean.FALSE) {
+        if (actionForRewriteExclusion == Action.DELETE && !isProgrammed) {
             LOG.trace("programIpRewriteExclusionStage1 node {} providerId {} cidr {} action {} is already done",
                          node.getNodeId().getValue(), providerSegmentationId, cidr, actionForRewriteExclusion);
             return;
         }
-        if (actionForRewriteExclusion == Action.ADD && isProgrammed == Boolean.TRUE) {
+        if (actionForRewriteExclusion == Action.ADD && isProgrammed) {
             LOG.trace("programIpRewriteExclusionStage1 node {} providerId {} cidr {} action {} is already done",
                          node.getNodeId().getValue(), providerSegmentationId, cidr, actionForRewriteExclusion);
             return;
@@ -1153,15 +1157,15 @@ public class NeutronL3Adapter implements ConfigInterface {
         // will look at desired action for node.
         //
         final String cacheKey = fid.dpid + ":" + fid.segId + ":" + fid.fixedIpAddress;
-        final Boolean isProgrammed = outboundIpRewriteCache.contains(cacheKey);
+        final boolean isProgrammed = outboundIpRewriteCache.contains(cacheKey);
 
-        if (action == Action.DELETE && isProgrammed == Boolean.FALSE) {
+        if (action == Action.DELETE && !isProgrammed) {
             LOG.trace("programOutboundIpRewriteStage1 dpid {} seg {} fixedIpAddress {} floatIp {} action {} " +
                          "is already done",
                     fid.dpid, fid.segId, fid.fixedIpAddress, fid.floatingIpAddress, action);
             return;
         }
-        if (action == Action.ADD && isProgrammed == Boolean.TRUE) {
+        if (action == Action.ADD && isProgrammed) {
             LOG.trace("programOutboundIpRewriteStage1 dpid {} seg {} fixedIpAddress {} floatIp {} action {} " +
                          "is already done",
                     fid.dpid, fid.segId, fid.fixedIpAddress, fid.floatingIpAddress, action);
index 284074d936f6c66cce757b9ef263f4c918041a28..efad7fca4db2eb449d2b1b27e050dbef2ba69ebe 100644 (file)
@@ -197,18 +197,16 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
                                                                                 Constants.EXTERNAL_ID_INTERFACE_ID);
                         if (null != portId) {
                             NeutronPort port = neutronPortCache.getPort(portId);
-                            if (null != port) {
-                                if (!(port.getID().equals(neutronPort.getID()))
-                                        && port.getDeviceOwner().contains("compute")) {
-                                    List<Neutron_IPs> portFixedIp = port.getFixedIPs();
-                                    if (null == portFixedIp || portFixedIp.isEmpty()) {
-                                        return false;
-                                    }
-                                    if (portFixedIp.iterator().next().getSubnetUUID()
-                                            .equals(neutronPort.getFixedIPs().iterator().next().getSubnetUUID())) {
-                                        LOG.trace("isLastPortinSubnet: Port is not the only port.");
-                                        return false;
-                                    }
+                            if (null != port && !(port.getID().equals(neutronPort.getID()))
+                                    && port.getDeviceOwner().contains("compute")) {
+                                List<Neutron_IPs> portFixedIp = port.getFixedIPs();
+                                if (null == portFixedIp || portFixedIp.isEmpty()) {
+                                    return false;
+                                }
+                                if (portFixedIp.iterator().next().getSubnetUUID()
+                                        .equals(neutronPort.getFixedIPs().iterator().next().getSubnetUUID())) {
+                                    LOG.trace("isLastPortinSubnet: Port is not the only port.");
+                                    return false;
                                 }
                             }
                         }
@@ -231,14 +229,13 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
             for (TerminationPoint tp : terminationPoints) {
                 OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation =
                         tp.getAugmentation(OvsdbTerminationPointAugmentation.class);
-                if (null != ovsdbTerminationPointAugmentation) {
-                    if (!(ovsdbTerminationPointAugmentation.getName().equals(Constants.INTEGRATION_BRIDGE))
-                            && !(terminationPointAugmentation.getInterfaceUuid()
-                                    .equals(ovsdbTerminationPointAugmentation.getInterfaceUuid()))) {
-                        LOG.debug("isLastPortinBridge: it the last port in bridge {}",
-                                  terminationPointAugmentation.getName());
-                        return false;
-                    }
+                if (null != ovsdbTerminationPointAugmentation
+                        && !(ovsdbTerminationPointAugmentation.getName().equals(Constants.INTEGRATION_BRIDGE))
+                        && !(terminationPointAugmentation.getInterfaceUuid()
+                        .equals(ovsdbTerminationPointAugmentation.getInterfaceUuid()))) {
+                    LOG.debug("isLastPortinBridge: it the last port in bridge {}",
+                            terminationPointAugmentation.getName());
+                    return false;
                 }
             }
         }
index 5a909b104ea6acdeee9bba3fd5165a6a24fdf641..3e2ecb9743844d0978e2789dd7d6e969a2f3aa32 100644 (file)
@@ -34,6 +34,10 @@ public class SouthboundUtil {
 
     private static InstanceIdentifierCodec instanceIdentifierCodec;
 
+    private SouthboundUtil() {
+        // Prevent instantiating a utility class
+    }
+
     public static void setInstanceIdentifierCodec(InstanceIdentifierCodec iidc) {
         instanceIdentifierCodec = iidc;
     }
@@ -68,10 +72,11 @@ public class SouthboundUtil {
                 Optional<Node> optional = nf.get();
                 if (optional != null && optional.isPresent()) {
                     OvsdbNodeAugmentation ovsdbNode = null;
-                    if (optional.get() instanceof Node) {
-                        ovsdbNode = optional.get().getAugmentation(OvsdbNodeAugmentation.class);
-                    } else if (optional.get() instanceof OvsdbNodeAugmentation) {
-                        ovsdbNode = (OvsdbNodeAugmentation) optional.get();
+                    Node node = optional.get();
+                    if (node instanceof OvsdbNodeAugmentation) {
+                        ovsdbNode = (OvsdbNodeAugmentation) node;
+                    } else if (node != null) {
+                        ovsdbNode = node.getAugmentation(OvsdbNodeAugmentation.class);
                     }
                     if (ovsdbNode != null) {
                         return Optional.of(ovsdbNode);
@@ -110,15 +115,13 @@ public class SouthboundUtil {
         try {
             for (Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();
                  ifaces.hasMoreElements();) {
-                NetworkInterface iface = (NetworkInterface) ifaces.nextElement();
+                NetworkInterface iface = ifaces.nextElement();
 
                 for (Enumeration<InetAddress> inetAddrs = iface.getInetAddresses(); inetAddrs.hasMoreElements();) {
-                    InetAddress inetAddr = (InetAddress) inetAddrs.nextElement();
-                    if (!inetAddr.isLoopbackAddress()) {
-                        if (inetAddr.isSiteLocalAddress()) {
-                            ipaddress = inetAddr.getHostAddress();
-                            break;
-                        }
+                    InetAddress inetAddr = inetAddrs.nextElement();
+                    if (!inetAddr.isLoopbackAddress() && inetAddr.isSiteLocalAddress()) {
+                        ipaddress = inetAddr.getHostAddress();
+                        break;
                     }
                 }
             }