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;
private final HwvtepConnectionInstance connectionInstance;
- public HwvtepTableReader(HwvtepConnectionInstance connectionInstance) {
+ public HwvtepTableReader(final HwvtepConnectionInstance connectionInstance) {
this.connectionInstance = connectionInstance;
DatabaseSchema dbSchema = null;
try {
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(
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(
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);
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);
}
@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());
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())
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;
}
- 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) {