From 76d89535ee9378bea060593183097b87efaf59c3 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 2 Dec 2019 03:50:45 +0100 Subject: [PATCH] Migrate TyperUtils.getTableSchema() users TypedDatabaseSchema has the same capability, migrate users as they have this functionality at their fingertip. Change-Id: I51fa3edb2cfda6894f9f9354ee3ab8dc9bdf7c17 Signed-off-by: Robert Varga --- .../HwvtepConnectionInstance.java | 6 +- .../HwvtepConnectionManager.java | 6 +- .../hwvtepsouthbound/HwvtepTableReader.java | 204 +++++++++--------- .../schema/typed/TypedDatabaseSchemaImpl.java | 2 +- .../ovsdb/lib/schema/typed/TyperUtils.java | 3 +- .../southbound/OvsdbConnectionInstance.java | 6 +- .../southbound/OvsdbConnectionManager.java | 48 ++--- .../OvsdbConnectionInstanceTest.java | 2 +- 8 files changed, 133 insertions(+), 144 deletions(-) diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionInstance.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionInstance.java index 1103fe7da..6e141e98f 100644 --- a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionInstance.java +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionInstance.java @@ -68,7 +68,7 @@ public class HwvtepConnectionInstance { private final HwvtepTableReader hwvtepTableReader; private InstanceIdentifier instanceIdentifier; private final TransactionInvoker txInvoker; - private Map transactInvokers; + private Map 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); diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionManager.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionManager.java index dfdfc1cac..56a5c29cc 100644 --- a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionManager.java +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionManager.java @@ -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 selectOperation = op.select(hwvtepSchema); selectOperation.setColumns(new ArrayList<>(hwvtepSchema.getColumns())); diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepTableReader.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepTableReader.java index ae3716b8e..291261260 100644 --- a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepTableReader.java +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepTableReader.java @@ -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> { @Override - public List apply(InstanceIdentifier iid) { + public List apply(final InstanceIdentifier iid) { InstanceIdentifier macIid = iid; String mac = macIid.firstKeyOf(RemoteMcastMacs.class).getMacEntryKey().getValue(); InstanceIdentifier lsIid = (InstanceIdentifier) macIid.firstKeyOf( @@ -137,7 +138,7 @@ public class HwvtepTableReader { class RemoteUcastMacWhereClauseGetter implements Function> { @Override - public List apply(InstanceIdentifier iid) { + public List apply(final InstanceIdentifier iid) { InstanceIdentifier macIid = iid; String mac = macIid.firstKeyOf(RemoteUcastMacs.class).getMacEntryKey().getValue(); InstanceIdentifier lsIid = (InstanceIdentifier) macIid.firstKeyOf( @@ -158,7 +159,7 @@ public class HwvtepTableReader { class LogicalSwitchWhereClauseGetter implements Function> { @Override - public List apply(InstanceIdentifier iid) { + public List apply(final InstanceIdentifier iid) { InstanceIdentifier 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> { @Override - public List apply(InstanceIdentifier iid) { + public List apply(final InstanceIdentifier iid) { InstanceIdentifier 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 getHwvtepTableEntryUUID(Class cls, - InstanceIdentifier iid, - UUID existingUUID) { + public Optional getHwvtepTableEntryUUID(final Class cls, + final InstanceIdentifier iid, + final UUID existingUUID) { + final TypedDatabaseSchema dbSchema; try { - DatabaseSchema dbSchema = null; - TypedBaseTable globalRow = null; - Class 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 hwvtepTableColumn = new ArrayList<>(); - hwvtepTableColumn.addAll(hwvtepSchema.getColumns()); - Select 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 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 operations = new ArrayList<>(); - operations.add(selectOperation); - try { - List 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 tableClass = tableMap.get(cls); + final GenericTableSchema hwvtepSchema = dbSchema.getTableSchema(tableClass); + + final Select selectOperation = op.select(hwvtepSchema); + selectOperation.setColumns(new ArrayList<>(hwvtepSchema.getColumns())); + + if (existingUUID == null) { + final Function> 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 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 operations = new ArrayList<>(); + operations.add(selectOperation); + + final List 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> 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 getHwvtepTableEntries(Class cls) { + public List getHwvtepTableEntries(final Class cls) { + final TypedDatabaseSchema dbSchema; try { - List tableRows = new ArrayList<>(); - DatabaseSchema dbSchema = null; - TypedBaseTable globalRow = null; - Class 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 hwvtepTableColumn = new ArrayList<>(); - hwvtepTableColumn.addAll(hwvtepSchema.getColumns()); - Select selectOperation = op.select(hwvtepSchema); - selectOperation.setColumns(hwvtepTableColumn); - - ArrayList operations = Lists.newArrayList(selectOperation); - try { - List results = connectionInstance.transact(dbSchema, operations).get(); - if (results != null && !results.isEmpty()) { - for (OperationResult selectResult : results) { - if (selectResult.getRows() != null && !selectResult.getRows().isEmpty()) { - for (Row row : selectResult.getRows()) { - tableRows.add(TyperUtils.getTypedRowWrapper(dbSchema, tableClass, row)); - } - } - } + final Class tableClass = tableMap.get(cls); + final GenericTableSchema hwvtepSchema = dbSchema.getTableSchema(tableClass); + final Select selectOperation = op.select(hwvtepSchema); + selectOperation.setColumns(new ArrayList<>(hwvtepSchema.getColumns())); + + final List 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 tableRows = new ArrayList<>(); + for (OperationResult selectResult : results) { + if (selectResult.getRows() != null && !selectResult.getRows().isEmpty()) { + for (Row 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 tableUpdates = new HashMap<>(); - DatabaseSchema dbSchema = connectionInstance.getSchema(HwvtepSchemaConstants.HARDWARE_VTEP).get(); + TypedDatabaseSchema dbSchema = connectionInstance.getSchema(HwvtepSchemaConstants.HARDWARE_VTEP).get(); List 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 buildSelectOperationFor(GenericTableSchema tableSchema) { + private Select buildSelectOperationFor(final GenericTableSchema tableSchema) { Select selectOpearation = op.select(tableSchema); selectOpearation.setColumns(new ArrayList<>(tableSchema.getColumns())); return selectOpearation; } - private UUID getRowUuid(Row row) { + private UUID getRowUuid(final Row row) { return row.getColumns().stream() .filter(column -> column.getSchema().getName().equals("_uuid")) .map(column -> (UUID) column.getData()) diff --git a/library/impl/src/main/java/org/opendaylight/ovsdb/lib/schema/typed/TypedDatabaseSchemaImpl.java b/library/impl/src/main/java/org/opendaylight/ovsdb/lib/schema/typed/TypedDatabaseSchemaImpl.java index ced7787e2..b482b555b 100644 --- a/library/impl/src/main/java/org/opendaylight/ovsdb/lib/schema/typed/TypedDatabaseSchemaImpl.java +++ b/library/impl/src/main/java/org/opendaylight/ovsdb/lib/schema/typed/TypedDatabaseSchemaImpl.java @@ -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 diff --git a/library/impl/src/main/java/org/opendaylight/ovsdb/lib/schema/typed/TyperUtils.java b/library/impl/src/main/java/org/opendaylight/ovsdb/lib/schema/typed/TyperUtils.java index 3162130ac..61034a8c7 100644 --- a/library/impl/src/main/java/org/opendaylight/ovsdb/lib/schema/typed/TyperUtils.java +++ b/library/impl/src/main/java/org/opendaylight/ovsdb/lib/schema/typed/TyperUtils.java @@ -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 getColumnSchema(final GenericTableSchema tableSchema, diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionInstance.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionInstance.java index b4ed06e8c..5655489db 100644 --- a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionInstance.java +++ b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionInstance.java @@ -71,7 +71,7 @@ public class OvsdbConnectionInstance { private final OvsdbClient client; private ConnectionInfo connectionInfo; private final TransactionInvoker txInvoker; - private Map transactInvokers; + private Map transactInvokers; private MonitorCallBack callback; private InstanceIdentifier 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 entry: transactInvokers.entrySet()) { + for (Map.Entry entry: transactInvokers.entrySet()) { TransactionBuilder transaction = new TransactionBuilder(this.client, entry.getKey()); diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionManager.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionManager.java index 73d14de44..91905ca84 100644 --- a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionManager.java +++ b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionManager.java @@ -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 openVSwitchTableColumn = new ArrayList<>(); - openVSwitchTableColumn.addAll(openVSwitchSchema.getColumns()); - Select selectOperation = op.select(openVSwitchSchema); - selectOperation.setColumns(openVSwitchTableColumn); - - List operations = new ArrayList<>(); - operations.add(selectOperation); - operations.add(op.comment("Fetching Open_VSwitch table rows")); - try { - List 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 selectOperation = op.select(openVSwitchSchema); + selectOperation.setColumns(new ArrayList<>(openVSwitchSchema.getColumns())); + + List operations = new ArrayList<>(); + operations.add(selectOperation); + operations.add(op.comment("Fetching Open_VSwitch table rows")); + final List 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) { diff --git a/southbound/southbound-impl/src/test/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionInstanceTest.java b/southbound/southbound-impl/src/test/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionInstanceTest.java index 0777956f0..0ce6bcb8c 100644 --- a/southbound/southbound-impl/src/test/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionInstanceTest.java +++ b/southbound/southbound-impl/src/test/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionInstanceTest.java @@ -134,7 +134,7 @@ public class OvsdbConnectionInstanceTest { getField(OvsdbConnectionInstance.class, "transactInvokers").set(ovsdbConnectionInstance , null); ListenableFuture 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); -- 2.36.6