The patch also adds more clear logging to indicate connection events and indicate which direction the events happened.
Patch Set 4: Review comments. Remove the filter since it doesn't make sense because the caller is asking explictly for the table to monitor.
Patch Set 2, 3: fix unit tests and update commit message
Change-Id: I4ea511906911bf9296e78f57f1b63dc2608c9501
Signed-off-by: Sam Hague <shague@redhat.com>
}
try {
- List<String> databases = getDatabases().get();
- this.callback = new HwvtepMonitorCallback(this,txInvoker);
- for (String database : databases) {
- DatabaseSchema dbSchema = getSchema(database).get();
- if (dbSchema != null) {
- monitorAllTables(database, dbSchema, HwvtepSchemaConstants.databaseName);
- } else {
- LOG.warn("No schema reported for database {} for key {}",database,connectionInfo);
- }
+ String database = HwvtepSchemaConstants.HARDWARE_VTEP;
+ DatabaseSchema dbSchema = getSchema(database).get();
+ if (dbSchema != null) {
+ LOG.info("Monitoring database: {}", database);
+ callback = new HwvtepMonitorCallback(this, txInvoker);
+ monitorAllTables(database, dbSchema);
+ } else {
+ LOG.info("No database {} found on {}", database, connectionInfo);
}
} catch (InterruptedException | ExecutionException e) {
- LOG.warn("Exception attempting to registerCallbacks {}: {}",connectionInfo,e);
+ LOG.warn("Exception attempting to registerCallbacks {}: ", connectionInfo, e);
}
}
}
if (transactInvokers == null) {
try {
transactInvokers = new HashMap<>();
- DatabaseSchema dbSchema = getSchema(HwvtepSchemaConstants.databaseName).get();
+ DatabaseSchema dbSchema = getSchema(HwvtepSchemaConstants.HARDWARE_VTEP).get();
if(dbSchema != null) {
transactInvokers.put(dbSchema, new TransactInvokerImpl(this,dbSchema));
}
}
}
- private void monitorAllTables(String database, DatabaseSchema dbSchema, String filter) {
- if((filter != null) && (!dbSchema.getName().equals(filter))) {
- LOG.debug("Not monitoring tables in {}, filter: {}", dbSchema.getName(), filter);
- return;
- }
+ private void monitorAllTables(String database, DatabaseSchema dbSchema) {
Set<String> tables = dbSchema.getTables();
if (tables != null) {
List<MonitorRequest> monitorRequests = Lists.newArrayList();
@Override
public void connected(@Nonnull final OvsdbClient client) {
+ LOG.info("Library connected {} from {}:{} to {}:{}",
+ client.getConnectionInfo().getType(),
+ client.getConnectionInfo().getRemoteAddress(),
+ client.getConnectionInfo().getRemotePort(),
+ client.getConnectionInfo().getLocalAddress(),
+ client.getConnectionInfo().getLocalPort());
HwvtepConnectionInstance hwClient = connectedButCallBacksNotRegistered(client);
registerEntityForOwnership(hwClient);
- LOG.trace("connected client: {}", client);
}
@Override
public void disconnected(OvsdbClient client) {
- LOG.info("HWVTEP Disconnected from {}:{}. Cleaning up the operational data store"
- ,client.getConnectionInfo().getRemoteAddress(),
- client.getConnectionInfo().getRemotePort());
+ LOG.info("Library disconnected {} from {}:{} to {}:{}. Cleaning up the operational data store",
+ client.getConnectionInfo().getType(),
+ client.getConnectionInfo().getRemoteAddress(),
+ client.getConnectionInfo().getRemotePort(),
+ client.getConnectionInfo().getLocalAddress(),
+ client.getConnectionInfo().getLocalPort());
ConnectionInfo key = HwvtepSouthboundMapper.createConnectionInfo(client);
HwvtepConnectionInstance hwvtepConnectionInstance = getConnectionInstance(key);
if (hwvtepConnectionInstance != null) {
} else {
LOG.warn("HWVTEP disconnected event did not find connection instance for {}", key);
}
- LOG.trace("disconnected client: {}", client);
+ LOG.trace("HwvtepConnectionManager exit disconnected client: {}", client);
}
public OvsdbClient connect(InstanceIdentifier<Node> iid, HwvtepGlobalAugmentation hwvtepGlobal) throws UnknownHostException {
+ LOG.info("Connecting to {}", HwvtepSouthboundUtil.connectionInfoToString(hwvtepGlobal.getConnectionInfo()));
InetAddress ip = HwvtepSouthboundMapper.createInetAddress(hwvtepGlobal.getConnectionInfo().getRemoteIp());
OvsdbClient client = OvsdbConnectionService.getService()
.connect(ip, hwvtepGlobal.getConnectionInfo().getRemotePort().getValue());
return client;
}
public void disconnect(HwvtepGlobalAugmentation ovsdbNode) throws UnknownHostException {
+ LOG.info("Diconnecting from {}", HwvtepSouthboundUtil.connectionInfoToString(ovsdbNode.getConnectionInfo()));
HwvtepConnectionInstance client = getConnectionInstance(ovsdbNode.getConnectionInfo());
if (client != null) {
client.disconnect();
Global globalRow = null;
try {
- dbSchema = connectionInstance.getSchema(HwvtepSchemaConstants.databaseName).get();
+ dbSchema = connectionInstance.getSchema(HwvtepSchemaConstants.HARDWARE_VTEP).get();
} catch (InterruptedException | ExecutionException e) {
LOG.warn("Not able to fetch schema for database {} from device {}",
- HwvtepSchemaConstants.databaseName,connectionInstance.getConnectionInfo(),e);
+ HwvtepSchemaConstants.HARDWARE_VTEP,connectionInstance.getConnectionInfo(),e);
}
if (dbSchema != null) {
package org.opendaylight.ovsdb.hwvtepsouthbound;
public class HwvtepSchemaConstants {
- public static final String databaseName = "hardware_vtep";
+ public static final String HARDWARE_VTEP = "hardware_vtep";
public enum HWVTEPSCHEMATABLES {
GLOBAL("Global", null, null),
MANAGER("Manager","Global","managers"),
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalRef;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepLogicalSwitchAttributes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalSwitchAttributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.ConnectionInfo;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.data.impl.codec.DeserializationException;
return Optional.absent();
}
}
-
+ public static String connectionInfoToString(final ConnectionInfo connectionInfo) {
+ return String.valueOf(
+ connectionInfo.getRemoteIp().getValue()) + ":" + connectionInfo.getRemotePort().getValue();
+ }
}
}
try {
- List<String> databases = getDatabases().get();
- this.callback = new OvsdbMonitorCallback(this,txInvoker);
- for (String database : databases) {
- DatabaseSchema dbSchema = getSchema(database).get();
- if (dbSchema != null) {
- monitorAllTables(database, dbSchema);
- } else {
- LOG.warn("No schema reported for database {} for key {}",database,connectionInfo);
- }
+ String database = SouthboundConstants.OPEN_V_SWITCH;
+ DatabaseSchema dbSchema = getSchema(database).get();
+ if (dbSchema != null) {
+ LOG.info("Monitoring database: {}", database);
+ callback = new OvsdbMonitorCallback(this, txInvoker);
+ monitorAllTables(database, dbSchema);
+ } else {
+ LOG.info("No database {} found on {}", database, connectionInfo);
}
} catch (InterruptedException | ExecutionException e) {
- LOG.warn("Exception attempting to registerCallbacks {}: {}",connectionInfo,e);
+ LOG.warn("Exception attempting to registerCallbacks {}: ", connectionInfo, e);
}
}
}
if (tables != null) {
List<MonitorRequest> monitorRequests = Lists.newArrayList();
for (String tableName : tables) {
+ LOG.info("Southbound monitoring table {} in {}", tableName, dbSchema.getName());
GenericTableSchema tableSchema = dbSchema.table(tableName, GenericTableSchema.class);
Set<String> columns = tableSchema.getColumns();
MonitorRequestBuilder<GenericTableSchema> monitorBuilder = MonitorRequestBuilder.builder(tableSchema);
@Override
public void connected(@Nonnull final OvsdbClient externalClient) {
-
+ LOG.info("Library connected {} from {}:{} to {}:{}",
+ externalClient.getConnectionInfo().getType(),
+ externalClient.getConnectionInfo().getRemoteAddress(),
+ externalClient.getConnectionInfo().getRemotePort(),
+ externalClient.getConnectionInfo().getLocalAddress(),
+ externalClient.getConnectionInfo().getLocalPort());
OvsdbConnectionInstance client = connectedButCallBacksNotRegistered(externalClient);
// Register Cluster Ownership for ConnectionInfo
@Override
public void disconnected(OvsdbClient client) {
- LOG.info("OVSDB Disconnected from {}:{}. Cleaning up the operational data store"
- ,client.getConnectionInfo().getRemoteAddress(),
- client.getConnectionInfo().getRemotePort());
+ LOG.info("Library disconnected {} from {}:{} to {}:{}. Cleaning up the operational data store",
+ client.getConnectionInfo().getType(),
+ client.getConnectionInfo().getRemoteAddress(),
+ client.getConnectionInfo().getRemotePort(),
+ client.getConnectionInfo().getLocalAddress(),
+ client.getConnectionInfo().getLocalPort());
ConnectionInfo key = SouthboundMapper.createConnectionInfo(client);
OvsdbConnectionInstance ovsdbConnectionInstance = getConnectionInstance(key);
if (ovsdbConnectionInstance != null) {
} else {
LOG.warn("disconnected : Connection instance not found for OVSDB Node {} ", key);
}
- LOG.trace("OvsdbConnectionManager: disconnected exit");
+ LOG.trace("OvsdbConnectionManager: exit disconnected client: {}", client);
}
public OvsdbClient connect(InstanceIdentifier<Node> iid,
OvsdbNodeAugmentation ovsdbNode) throws UnknownHostException {
+ LOG.info("Connecting to {}", SouthboundUtil.connectionInfoToString(ovsdbNode.getConnectionInfo()));
+
// TODO handle case where we already have a connection
// TODO use transaction chains to handle ordering issues between disconnected
// TODO and connected when writing to the operational store
}
public void disconnect(OvsdbNodeAugmentation ovsdbNode) throws UnknownHostException {
+ LOG.info("Disconnecting from {}", SouthboundUtil.connectionInfoToString(ovsdbNode.getConnectionInfo()));
OvsdbConnectionInstance client = getConnectionInstance(ovsdbNode.getConnectionInfo());
if (client != null) {
// Unregister Cluster Onwership for ConnectionInfo
import com.google.common.collect.ImmutableBiMap;
public class SouthboundConstants {
+ public static final String OPEN_V_SWITCH = "Open_vSwitch";
public static final TopologyId OVSDB_TOPOLOGY_ID = new TopologyId(new Uri("ovsdb:1"));
public static final String OVSDB_URI_PREFIX = "ovsdb";
public static final String BRIDGE_URI_PREFIX = "bridge";
return target;
}
+
+ public static String connectionInfoToString(final ConnectionInfo connectionInfo) {
+ return String.valueOf(
+ connectionInfo.getRemoteIp().getValue()) + ":" + connectionInfo.getRemotePort().getValue();
+ }
}
MemberModifier.suppress(MemberMatcher.method(OvsdbConnectionInstance.class, "monitorAllTables", String.class,DatabaseSchema.class));
ovsdbConnectionInstance.registerCallbacks();
- PowerMockito.verifyPrivate(ovsdbConnectionInstance, times(2)).invoke("monitorAllTables", anyString(), any(DatabaseSchema.class));
+ PowerMockito.verifyPrivate(ovsdbConnectionInstance, times(1)).invoke("monitorAllTables", anyString(), any(DatabaseSchema.class));
}
@SuppressWarnings({ "unchecked", "rawtypes" })
tables.add("tableName1");
tables.add("tableName2");
DatabaseSchema dbSchema = mock(DatabaseSchema.class);
+ when(dbSchema.getName()).thenReturn(SouthboundConstants.OPEN_V_SWITCH);
when(dbSchema.getTables()).thenReturn(tables);
GenericTableSchema tableSchema = mock(GenericTableSchema.class);
when(dbSchema.table(anyString(), eq(GenericTableSchema.class))).thenReturn(tableSchema);
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAttributes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfoBuilder;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.powermock.api.mockito.PowerMockito;
@Mock private TransactionInvoker txInvoker;
@Mock private EntityOwnershipService entityOwnershipService;
@Mock private OvsdbConnection ovsdbConnection;
+ @Mock private OvsdbClient externalClient;
private Map<ConnectionInfo,OvsdbConnectionInstance> clients;
private Map<ConnectionInfo,InstanceIdentifier<Node>> instanceIdentifiers;
private Map<Entity, OvsdbConnectionInstance> entityConnectionMap;
MemberModifier.field(OvsdbConnectionManager.class, "ovsdbConnection")
.set(ovsdbConnectionManager, ovsdbConnection);
entityConnectionMap = new ConcurrentHashMap<>();
+
+ externalClient = mock(OvsdbClient.class, Mockito.RETURNS_DEEP_STUBS);
+ when(externalClient.getConnectionInfo().getRemoteAddress()).thenReturn(mock(InetAddress.class));
+ when(externalClient.getConnectionInfo().getRemotePort()).thenReturn(8080);
+ when(externalClient.getConnectionInfo().getLocalAddress()).thenReturn(mock(InetAddress.class));
+ when(externalClient.getConnectionInfo().getLocalPort()).thenReturn(8080);
+
+ PowerMockito.mockStatic(SouthboundUtil.class);
+ when(SouthboundUtil.connectionInfoToString(any(ConnectionInfo.class))).thenReturn("192.18.120.31:8080");
}
@Test
public void testConnected() throws Exception {
OvsdbConnectionInstance client = mock(OvsdbConnectionInstance.class);
- OvsdbClient externalClient = mock(OvsdbClient.class);
MemberModifier.suppress(MemberMatcher.method(OvsdbConnectionManager.class, "connectedButCallBacksNotRegistered", OvsdbClient.class));
when(ovsdbConnectionManager.connectedButCallBacksNotRegistered(any(OvsdbClient.class))).thenReturn(client);
doNothing().when(client).registerCallbacks();
@SuppressWarnings("unchecked")
@Test
public void testConnectedButCallBacksNotRegistered() throws Exception {
- OvsdbClient externalClient = mock(OvsdbClient.class, Mockito.RETURNS_DEEP_STUBS);
OvsdbConnectionInstance client = mock(OvsdbConnectionInstance.class);
-
- InetAddress ip = mock(InetAddress.class);
-
- when(externalClient.getConnectionInfo().getRemoteAddress()).thenReturn(ip);
- when(externalClient.getConnectionInfo().getRemotePort()).thenReturn(8080);
-
ConnectionInfo key = mock(ConnectionInfo.class);
+
PowerMockito.mockStatic(SouthboundMapper.class);
when(SouthboundMapper.createConnectionInfo(any(OvsdbClient.class))).thenReturn(key);
@Test
public void testDisconnected() throws Exception {
- OvsdbClient client = mock(OvsdbClient.class, Mockito.RETURNS_DEEP_STUBS);
OvsdbConnectionInstance ovsdbConnectionInstance = mock(OvsdbConnectionInstance.class);
- InetAddress ip = mock(InetAddress.class);
- when(client.getConnectionInfo().getRemoteAddress()).thenReturn(ip);
- when(client.getConnectionInfo().getRemotePort()).thenReturn(8080);
ConnectionInfo key = mock(ConnectionInfo.class);
PowerMockito.mockStatic(SouthboundMapper.class);
//TODO: Write unit tests for EntityOwnershipService
MemberModifier.suppress(MemberMatcher.method(OvsdbConnectionManager.class, "unregisterEntityForOwnership", OvsdbConnectionInstance.class));
- ovsdbConnectionManager.disconnected(client);
+ ovsdbConnectionManager.disconnected(externalClient);
Map<ConnectionInfo,OvsdbConnectionInstance> testClients = Whitebox.getInternalState(ovsdbConnectionManager, "clients");
assertEquals("Error, size of the hashmap is incorrect", 0, testClients.size());
}