Migrate TyperUtils.getTableSchema() users 96/86096/8
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 2 Dec 2019 02:50:45 +0000 (03:50 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 2 Dec 2019 13:03:00 +0000 (14:03 +0100)
TypedDatabaseSchema has the same capability, migrate users as they
have this functionality at their fingertip.

Change-Id: I51fa3edb2cfda6894f9f9354ee3ab8dc9bdf7c17
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionInstance.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionManager.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepTableReader.java
library/impl/src/main/java/org/opendaylight/ovsdb/lib/schema/typed/TypedDatabaseSchemaImpl.java
library/impl/src/main/java/org/opendaylight/ovsdb/lib/schema/typed/TyperUtils.java
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionInstance.java
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionManager.java
southbound/southbound-impl/src/test/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionInstanceTest.java

index 1103fe7da3b2f8d584eafc77827a53a12dcd51de..6e141e98f1f7bbd871844228c4eb29f2966f8ad5 100644 (file)
@@ -68,7 +68,7 @@ public class HwvtepConnectionInstance {
     private final HwvtepTableReader hwvtepTableReader;
     private InstanceIdentifier<Node> instanceIdentifier;
     private final TransactionInvoker txInvoker;
-    private Map<DatabaseSchema,TransactInvoker> transactInvokers;
+    private Map<TypedDatabaseSchema, TransactInvoker> transactInvokers;
     private MonitorCallBack callback;
     private volatile boolean hasDeviceOwnership = false;
     private Entity connectedEntity;
@@ -170,9 +170,9 @@ public class HwvtepConnectionInstance {
         if (transactInvokers == null) {
             try {
                 transactInvokers = new HashMap<>();
-                DatabaseSchema dbSchema = getSchema(HwvtepSchemaConstants.HARDWARE_VTEP).get();
+                TypedDatabaseSchema dbSchema = getSchema(HwvtepSchemaConstants.HARDWARE_VTEP).get();
                 if (dbSchema != null) {
-                    transactInvokers.put(dbSchema, new TransactInvokerImpl(this,dbSchema));
+                    transactInvokers.put(dbSchema, new TransactInvokerImpl(this, dbSchema));
                 }
             } catch (InterruptedException | ExecutionException e) {
                 LOG.warn("Exception attempting to createTransactionInvokers {}", connectionInfo, e);
index dfdfc1cac2180e4c7b33c7bd4364c45996a2af9a..56a5c29cce448b1e47659bf2640944ae53a5836b 100644 (file)
@@ -54,8 +54,8 @@ import org.opendaylight.ovsdb.lib.OvsdbConnectionListener;
 import org.opendaylight.ovsdb.lib.operations.Operation;
 import org.opendaylight.ovsdb.lib.operations.OperationResult;
 import org.opendaylight.ovsdb.lib.operations.Select;
-import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
 import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
+import org.opendaylight.ovsdb.lib.schema.typed.TypedDatabaseSchema;
 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
 import org.opendaylight.ovsdb.schema.hardwarevtep.Global;
 import org.opendaylight.ovsdb.utils.mdsal.utils.TransactionHistory;
@@ -401,7 +401,7 @@ public class HwvtepConnectionManager implements OvsdbConnectionListener, AutoClo
     }
 
     private static Global getHwvtepGlobalTableEntry(final HwvtepConnectionInstance connectionInstance) {
-        final DatabaseSchema dbSchema;
+        final TypedDatabaseSchema dbSchema;
         try {
             dbSchema = connectionInstance.getSchema(HwvtepSchemaConstants.HARDWARE_VTEP).get();
         } catch (InterruptedException | ExecutionException e) {
@@ -410,7 +410,7 @@ public class HwvtepConnectionManager implements OvsdbConnectionListener, AutoClo
             return null;
         }
 
-        GenericTableSchema hwvtepSchema = TyperUtils.getTableSchema(dbSchema, Global.class);
+        GenericTableSchema hwvtepSchema = dbSchema.getTableSchema(Global.class);
         Select<GenericTableSchema> selectOperation = op.select(hwvtepSchema);
         selectOperation.setColumns(new ArrayList<>(hwvtepSchema.getColumns()));
 
index ae3716b8e8d26434c2709ac2acb4e9f9bc8dd3da..2912612607e9149043f024407547dea0adc82688 100644 (file)
@@ -31,6 +31,7 @@ import org.opendaylight.ovsdb.lib.operations.Select;
 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
 import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
 import org.opendaylight.ovsdb.lib.schema.typed.TypedBaseTable;
+import org.opendaylight.ovsdb.lib.schema.typed.TypedDatabaseSchema;
 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
 import org.opendaylight.ovsdb.schema.hardwarevtep.ACL;
 import org.opendaylight.ovsdb.schema.hardwarevtep.ACLEntry;
@@ -88,7 +89,7 @@ public class HwvtepTableReader {
 
     private final HwvtepConnectionInstance connectionInstance;
 
-    public HwvtepTableReader(HwvtepConnectionInstance connectionInstance) {
+    public HwvtepTableReader(final HwvtepConnectionInstance connectionInstance) {
         this.connectionInstance = connectionInstance;
         DatabaseSchema dbSchema = null;
         try {
@@ -116,7 +117,7 @@ public class HwvtepTableReader {
 
     class RemoteMcastMacWhereClauseGetter implements Function<InstanceIdentifier, List<Condition>> {
         @Override
-        public List<Condition> apply(InstanceIdentifier iid) {
+        public List<Condition> apply(final InstanceIdentifier iid) {
             InstanceIdentifier<RemoteMcastMacs> macIid = iid;
             String mac = macIid.firstKeyOf(RemoteMcastMacs.class).getMacEntryKey().getValue();
             InstanceIdentifier<LogicalSwitches> lsIid = (InstanceIdentifier<LogicalSwitches>) macIid.firstKeyOf(
@@ -137,7 +138,7 @@ public class HwvtepTableReader {
 
     class RemoteUcastMacWhereClauseGetter implements Function<InstanceIdentifier, List<Condition>> {
         @Override
-        public List<Condition> apply(InstanceIdentifier iid) {
+        public List<Condition> apply(final InstanceIdentifier iid) {
             InstanceIdentifier<RemoteUcastMacs> macIid = iid;
             String mac = macIid.firstKeyOf(RemoteUcastMacs.class).getMacEntryKey().getValue();
             InstanceIdentifier<LogicalSwitches> lsIid = (InstanceIdentifier<LogicalSwitches>) macIid.firstKeyOf(
@@ -158,7 +159,7 @@ public class HwvtepTableReader {
 
     class LogicalSwitchWhereClauseGetter implements Function<InstanceIdentifier, List<Condition>> {
         @Override
-        public List<Condition> apply(InstanceIdentifier iid) {
+        public List<Condition> apply(final InstanceIdentifier iid) {
             InstanceIdentifier<LogicalSwitches> lsIid = iid;
             String lsName = lsIid.firstKeyOf(LogicalSwitches.class).getHwvtepNodeName().getValue();
             LogicalSwitch logicalSwitch = (LogicalSwitch) tables.get(LogicalSwitch.class);
@@ -168,7 +169,7 @@ public class HwvtepTableReader {
 
     class LocatorWhereClauseGetter implements Function<InstanceIdentifier, List<Condition>> {
         @Override
-        public List<Condition> apply(InstanceIdentifier iid) {
+        public List<Condition> apply(final InstanceIdentifier iid) {
             InstanceIdentifier<TerminationPoint> tepIid = iid;
             String locatorIp = tepIid.firstKeyOf(TerminationPoint.class).getTpId().getValue();
             locatorIp = locatorIp.substring(locatorIp.indexOf(":") + 1);
@@ -179,129 +180,122 @@ public class HwvtepTableReader {
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
-    public Optional<TypedBaseTable> getHwvtepTableEntryUUID(Class<? extends Identifiable> cls,
-                                                            InstanceIdentifier iid,
-                                                            UUID existingUUID) {
+    public Optional<TypedBaseTable> getHwvtepTableEntryUUID(final Class<? extends Identifiable> cls,
+                                                            final InstanceIdentifier iid,
+                                                            final UUID existingUUID) {
+        final TypedDatabaseSchema dbSchema;
         try {
-            DatabaseSchema dbSchema = null;
-            TypedBaseTable globalRow = null;
-            Class<TypedBaseTable> tableClass = tableMap.get(cls);
-            try {
-                dbSchema = connectionInstance.getSchema(HwvtepSchemaConstants.HARDWARE_VTEP).get();
-            } catch (InterruptedException | ExecutionException e) {
-                LOG.warn("Not able to fetch schema for database {} from device {}",
-                        HwvtepSchemaConstants.HARDWARE_VTEP, connectionInstance.getConnectionInfo(), e);
-            }
+            dbSchema = connectionInstance.getSchema(HwvtepSchemaConstants.HARDWARE_VTEP).get();
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.warn("Not able to fetch schema for database {} from device {}",
+                HwvtepSchemaConstants.HARDWARE_VTEP, connectionInstance.getConnectionInfo(), e);
+            return Optional.empty();
+        }
 
-            if (dbSchema != null) {
-                GenericTableSchema hwvtepSchema = TyperUtils.getTableSchema(dbSchema, tableClass);
-
-                List<String> hwvtepTableColumn = new ArrayList<>();
-                hwvtepTableColumn.addAll(hwvtepSchema.getColumns());
-                Select<GenericTableSchema> selectOperation = op.select(hwvtepSchema);
-                selectOperation.setColumns(hwvtepTableColumn);
-
-                if (existingUUID != null) {
-                    TypedBaseTable table = tables.get(tableClass);
-                    LOG.info("Setting uuid condition {} ", existingUUID);
-                    selectOperation.where(table.getUuidColumn().getSchema().opEqual(existingUUID));
-                } else {
-                    if (whereClauseGetterMap.get(cls) != null) {
-                        List<Condition> conditions = whereClauseGetterMap.get(cls).apply(iid);
-                        if (conditions != null) {
-                            if (conditions.size() == 2) {
-                                selectOperation.where(conditions.get(0)).and(conditions.get(1));
-                            } else {
-                                selectOperation.where(conditions.get(0));
-                            }
-                        } else {
-                            LOG.error("Could not get where conditions for cls {} key {}", cls, iid);
-                            return Optional.empty();
-                        }
-                    } else {
-                        LOG.error("Could not get where class for cls {} ", cls);
-                        return Optional.empty();
-                    }
-                }
-                ArrayList<Operation> operations = new ArrayList<>();
-                operations.add(selectOperation);
-                try {
-                    List<OperationResult> results = connectionInstance.transact(dbSchema, operations).get();
-                    if (results != null && !results.isEmpty()) {
-                        OperationResult selectResult = results.get(0);
-                        if (selectResult.getRows() != null && !selectResult.getRows().isEmpty()) {
-                            globalRow = TyperUtils.getTypedRowWrapper(
-                                    dbSchema, tableClass, selectResult.getRows().get(0));
-                        }
-                    }
-                } catch (InterruptedException | ExecutionException e) {
-                    LOG.warn("Not able to fetch hardware_vtep table row from device {}",
-                            connectionInstance.getConnectionInfo(), e);
-                }
+        final Class<TypedBaseTable> tableClass = tableMap.get(cls);
+        final GenericTableSchema hwvtepSchema = dbSchema.getTableSchema(tableClass);
+
+        final Select<GenericTableSchema> selectOperation = op.select(hwvtepSchema);
+        selectOperation.setColumns(new ArrayList<>(hwvtepSchema.getColumns()));
+
+        if (existingUUID == null) {
+            final Function<InstanceIdentifier, List<Condition>> whereClausule = whereClauseGetterMap.get(cls);
+            if (whereClausule == null) {
+                LOG.error("Could not get where class for cls {} ", cls);
+                return Optional.empty();
             }
-            LOG.trace("Fetched {} from hardware_vtep schema", globalRow);
-            if (globalRow != null && globalRow.getUuid() != null) {
-                return Optional.of(globalRow);
+            final List<Condition> conditions = whereClausule.apply(iid);
+            if (conditions == null) {
+                LOG.error("Could not get where conditions for cls {} key {}", cls, iid);
+                return Optional.empty();
+            }
+
+            if (conditions.size() == 2) {
+                selectOperation.where(conditions.get(0)).and(conditions.get(1));
+            } else {
+                selectOperation.where(conditions.get(0));
             }
+        } else {
+            TypedBaseTable table = tables.get(tableClass);
+            LOG.info("Setting uuid condition {} ", existingUUID);
+            selectOperation.where(table.getUuidColumn().getSchema().opEqual(existingUUID));
+        }
+
+        ArrayList<Operation> operations = new ArrayList<>();
+        operations.add(selectOperation);
+
+        final List<OperationResult> results;
+        try {
+            results = connectionInstance.transact(dbSchema, operations).get();
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.warn("Not able to fetch hardware_vtep table row from device {}",
+                connectionInstance.getConnectionInfo(), e);
             return Optional.empty();
-        } catch (RuntimeException e) {
-            LOG.error("Failed to get the hwvtep row for iid {}", iid, e);
+        }
+        if (results == null || results.isEmpty()) {
+            return Optional.empty();
+        }
+
+        final List<Row<GenericTableSchema>> selectResult = results.get(0).getRows();
+        if (selectResult == null || selectResult.isEmpty()) {
             return Optional.empty();
         }
+
+        final TypedBaseTable globalRow = dbSchema.getTypedRowWrapper(tableClass, selectResult.get(0));
+        LOG.trace("Fetched {} from hardware_vtep schema", globalRow);
+        return globalRow != null && globalRow.getUuid() != null ?  Optional.of(globalRow) : Optional.empty();
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
-    public List<TypedBaseTable> getHwvtepTableEntries(Class<? extends Identifiable> cls) {
+    public List<TypedBaseTable> getHwvtepTableEntries(final Class<? extends Identifiable> cls) {
+        final TypedDatabaseSchema dbSchema;
         try {
-            List<TypedBaseTable> tableRows = new ArrayList<>();
-            DatabaseSchema dbSchema = null;
-            TypedBaseTable globalRow = null;
-            Class<TypedBaseTable> tableClass = tableMap.get(cls);
-            try {
-                dbSchema = connectionInstance.getSchema(HwvtepSchemaConstants.HARDWARE_VTEP).get();
-            } catch (InterruptedException | ExecutionException e) {
-                LOG.error("Not able to fetch schema for database {} from device {}",
-                        HwvtepSchemaConstants.HARDWARE_VTEP, connectionInstance.getConnectionInfo(), e);
-            }
+            dbSchema = connectionInstance.getSchema(HwvtepSchemaConstants.HARDWARE_VTEP).get();
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.error("Not able to fetch schema for database {} from device {}",
+                HwvtepSchemaConstants.HARDWARE_VTEP, connectionInstance.getConnectionInfo(), e);
+            return null;
+        }
 
-            if (dbSchema != null) {
-                GenericTableSchema hwvtepSchema = TyperUtils.getTableSchema(dbSchema, tableClass);
-
-                List<String> hwvtepTableColumn = new ArrayList<>();
-                hwvtepTableColumn.addAll(hwvtepSchema.getColumns());
-                Select<GenericTableSchema> selectOperation = op.select(hwvtepSchema);
-                selectOperation.setColumns(hwvtepTableColumn);
-
-                ArrayList<Operation> operations = Lists.newArrayList(selectOperation);
-                try {
-                    List<OperationResult> results = connectionInstance.transact(dbSchema, operations).get();
-                    if (results != null && !results.isEmpty()) {
-                        for (OperationResult selectResult : results) {
-                            if (selectResult.getRows() != null && !selectResult.getRows().isEmpty()) {
-                                for (Row<GenericTableSchema> row : selectResult.getRows()) {
-                                    tableRows.add(TyperUtils.getTypedRowWrapper(dbSchema, tableClass, row));
-                                }
-                            }
-                        }
+        final Class<TypedBaseTable> tableClass = tableMap.get(cls);
+        final GenericTableSchema hwvtepSchema = dbSchema.getTableSchema(tableClass);
+        final Select<GenericTableSchema> selectOperation = op.select(hwvtepSchema);
+        selectOperation.setColumns(new ArrayList<>(hwvtepSchema.getColumns()));
+
+        final List<OperationResult> results;
+        try {
+            results = connectionInstance.transact(dbSchema, Lists.newArrayList(selectOperation)).get();
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.error("Not able to fetch hardware_vtep table row from device {}",
+                connectionInstance.getConnectionInfo(), e);
+            return Collections.emptyList();
+        }
+        if (results == null || results.isEmpty()) {
+            return Collections.emptyList();
+        }
+
+        try {
+            final List<TypedBaseTable> tableRows = new ArrayList<>();
+            for (OperationResult selectResult : results) {
+                if (selectResult.getRows() != null && !selectResult.getRows().isEmpty()) {
+                    for (Row<GenericTableSchema> row : selectResult.getRows()) {
+                        tableRows.add(dbSchema.getTypedRowWrapper(tableClass, row));
                     }
-                } catch (InterruptedException | ExecutionException e) {
-                    LOG.error("Not able to fetch hardware_vtep table row from device {}",
-                            connectionInstance.getConnectionInfo(), e);
                 }
             }
             return tableRows;
         } catch (RuntimeException e) {
             LOG.error("Failed to get the hwvtep ", e);
+            return Collections.emptyList();
         }
-        return Collections.emptyList();
     }
 
     public TableUpdates readAllTables() throws ExecutionException, InterruptedException {
         Map<String, TableUpdate> tableUpdates =  new HashMap<>();
-        DatabaseSchema dbSchema = connectionInstance.getSchema(HwvtepSchemaConstants.HARDWARE_VTEP).get();
+        TypedDatabaseSchema dbSchema = connectionInstance.getSchema(HwvtepSchemaConstants.HARDWARE_VTEP).get();
 
         List<Operation> operations = Arrays.asList(alltables).stream()
-                .map(tableClass -> TyperUtils.getTableSchema(dbSchema, tableClass))
+                .map(tableClass -> dbSchema.getTableSchema(tableClass))
                 .map(tableSchema -> buildSelectOperationFor(tableSchema))
                 .collect(Collectors.toList());
 
@@ -323,13 +317,13 @@ public class HwvtepTableReader {
         return new TableUpdates(tableUpdates);
     }
 
-    private Select<GenericTableSchema> buildSelectOperationFor(GenericTableSchema tableSchema) {
+    private Select<GenericTableSchema> buildSelectOperationFor(final GenericTableSchema tableSchema) {
         Select<GenericTableSchema> selectOpearation = op.select(tableSchema);
         selectOpearation.setColumns(new ArrayList<>(tableSchema.getColumns()));
         return selectOpearation;
     }
 
-    private UUID getRowUuid(Row<GenericTableSchema> row) {
+    private UUID getRowUuid(final Row<GenericTableSchema> row) {
         return row.getColumns().stream()
                 .filter(column -> column.getSchema().getName().equals("_uuid"))
                 .map(column -> (UUID) column.getData())
index ced7787e248a4488ecfef8b0ade884343e9eebb6..b482b555b0962b3df4041d422e04886235e83830 100644 (file)
@@ -40,7 +40,7 @@ final class TypedDatabaseSchemaImpl extends ForwardingDatabaseSchema implements
 
     @Override
     public GenericTableSchema getTableSchema(final Class<?> klazz) {
-        return TyperUtils.getTableSchema(this, klazz);
+        return table(TypedReflections.getTableName(klazz), GenericTableSchema.class);
     }
 
     @Override
index 3162130ac69e442512e73a6538b3fc8f22fa543b..61034a8c7abd2e104faf6dc182642f58804bdd6d 100644 (file)
@@ -45,8 +45,9 @@ public final class TyperUtils {
      *     using their {@link TypedTable} annotation, if they have one, or by name.
      * @return the table schema.
      */
+    @Deprecated
     public static GenericTableSchema getTableSchema(final DatabaseSchema dbSchema, final Class<?> klazz) {
-        return dbSchema.table(TypedReflections.getTableName(klazz), GenericTableSchema.class);
+        return getTyped(dbSchema).getTableSchema(klazz);
     }
 
     static ColumnSchema<GenericTableSchema, Object> getColumnSchema(final GenericTableSchema tableSchema,
index b4ed06e8c29236375908981094d33919a0c6fa05..5655489db306f2f7762e868032838f30d7f28792 100644 (file)
@@ -71,7 +71,7 @@ public class OvsdbConnectionInstance {
     private final OvsdbClient client;
     private ConnectionInfo connectionInfo;
     private final TransactionInvoker txInvoker;
-    private Map<DatabaseSchema,TransactInvoker> transactInvokers;
+    private Map<TypedDatabaseSchema, TransactInvoker> transactInvokers;
     private MonitorCallBack callback;
     private InstanceIdentifier<Node> instanceIdentifier;
     private volatile boolean hasDeviceOwnership = false;
@@ -150,7 +150,7 @@ public class OvsdbConnectionInstance {
         if (transactInvokers == null) {
             try {
                 transactInvokers = new HashMap<>();
-                DatabaseSchema dbSchema = getSchema(SouthboundConstants.OPEN_V_SWITCH).get();
+                TypedDatabaseSchema dbSchema = getSchema(SouthboundConstants.OPEN_V_SWITCH).get();
                 if (dbSchema != null) {
                     transactInvokers.put(dbSchema, new TransactInvokerImpl(this,dbSchema));
                 }
@@ -191,7 +191,7 @@ public class OvsdbConnectionInstance {
         LOG.debug("Update attributes of ovsdb node ip: {} port: {}",
                     this.initialCreateData.getConnectionInfo().getRemoteIp(),
                     this.initialCreateData.getConnectionInfo().getRemotePort());
-        for (Map.Entry<DatabaseSchema,TransactInvoker> entry: transactInvokers.entrySet()) {
+        for (Map.Entry<TypedDatabaseSchema, TransactInvoker> entry: transactInvokers.entrySet()) {
 
             TransactionBuilder transaction = new TransactionBuilder(this.client, entry.getKey());
 
index 73d14de44a122f08dd94a4347f28a742604c840f..91905ca84455b2874f0890b83a0fca6a2064ab71 100644 (file)
@@ -46,8 +46,8 @@ import org.opendaylight.ovsdb.lib.OvsdbConnectionListener;
 import org.opendaylight.ovsdb.lib.operations.Operation;
 import org.opendaylight.ovsdb.lib.operations.OperationResult;
 import org.opendaylight.ovsdb.lib.operations.Select;
-import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
 import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
+import org.opendaylight.ovsdb.lib.schema.typed.TypedDatabaseSchema;
 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
 import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
 import org.opendaylight.ovsdb.southbound.reconciliation.ReconciliationManager;
@@ -503,40 +503,34 @@ public class OvsdbConnectionManager implements OvsdbConnectionListener, AutoClos
 
     }
 
-    private OpenVSwitch getOpenVswitchTableEntry(final OvsdbConnectionInstance connectionInstance) {
-        DatabaseSchema dbSchema = null;
-        OpenVSwitch openVSwitchRow = null;
+    private static OpenVSwitch getOpenVswitchTableEntry(final OvsdbConnectionInstance connectionInstance) {
+        final TypedDatabaseSchema dbSchema;
         try {
             dbSchema = connectionInstance.getSchema(OvsdbSchemaContants.DATABASE_NAME).get();
         } catch (InterruptedException | ExecutionException e) {
             LOG.warn("Not able to fetch schema for database {} from device {}",
                     OvsdbSchemaContants.DATABASE_NAME,connectionInstance.getConnectionInfo(),e);
+            return null;
         }
-        if (dbSchema != null) {
-            GenericTableSchema openVSwitchSchema = TyperUtils.getTableSchema(dbSchema, OpenVSwitch.class);
-
-            List<String> openVSwitchTableColumn = new ArrayList<>();
-            openVSwitchTableColumn.addAll(openVSwitchSchema.getColumns());
-            Select<GenericTableSchema> selectOperation = op.select(openVSwitchSchema);
-            selectOperation.setColumns(openVSwitchTableColumn);
-
-            List<Operation> operations = new ArrayList<>();
-            operations.add(selectOperation);
-            operations.add(op.comment("Fetching Open_VSwitch table rows"));
-            try {
-                List<OperationResult> results = connectionInstance.transact(dbSchema, operations).get();
-                if (results != null) {
-                    OperationResult selectResult = results.get(0);
-                    openVSwitchRow = TyperUtils.getTypedRowWrapper(
-                            dbSchema,OpenVSwitch.class,selectResult.getRows().get(0));
 
-                }
-            } catch (InterruptedException | ExecutionException e) {
-                LOG.warn("Not able to fetch OpenVswitch table row from device {}",
-                        connectionInstance.getConnectionInfo(),e);
-            }
+        final GenericTableSchema openVSwitchSchema = dbSchema.getTableSchema(OpenVSwitch.class);
+        final Select<GenericTableSchema> selectOperation = op.select(openVSwitchSchema);
+        selectOperation.setColumns(new ArrayList<>(openVSwitchSchema.getColumns()));
+
+        List<Operation> operations = new ArrayList<>();
+        operations.add(selectOperation);
+        operations.add(op.comment("Fetching Open_VSwitch table rows"));
+        final List<OperationResult> results;
+        try {
+            results = connectionInstance.transact(dbSchema, operations).get();
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.warn("Not able to fetch OpenVswitch table row from device {}", connectionInstance.getConnectionInfo(),
+                e);
+            return null;
         }
-        return openVSwitchRow;
+
+        return results == null || results.isEmpty() ? null
+                : TyperUtils.getTypedRowWrapper(dbSchema, OpenVSwitch.class, results.get(0).getRows().get(0));
     }
 
     private Entity getEntityFromConnectionInstance(@NonNull final OvsdbConnectionInstance ovsdbConnectionInstance) {
index 0777956f09fc17b4e9a93cb1d3df59908743eb7c..0ce6bcb8cb471b0921964a2cd08c30736c6829ed 100644 (file)
@@ -134,7 +134,7 @@ public class OvsdbConnectionInstanceTest {
         getField(OvsdbConnectionInstance.class, "transactInvokers").set(ovsdbConnectionInstance , null);
 
         ListenableFuture<DatabaseSchema> listenableDbSchema = mock(ListenableFuture.class);
-        DatabaseSchema dbSchema = mock(DatabaseSchema.class);
+        TypedDatabaseSchema dbSchema = mock(TypedDatabaseSchema.class);
         doReturn(listenableDbSchema).when(ovsdbConnectionInstance).getSchema(anyString());
         when(listenableDbSchema.get()).thenReturn(dbSchema);