public OvsdbConnectionInfo getConnectionInfo() { return client.getConnectionInfo(); }
@Override public void onFailure(Throwable failureException) { LOG.error("Probe failed to OVSDB switch. Disconnecting the channel {}", client.getConnectionInfo()); client.disconnect(); } }, connectionNotifierService);
public DatabaseSchema getDatabaseSchema(String dbName) { return client.getDatabaseSchema(dbName); }
@Override public void run() { for (OvsdbClient client : clientFutureMap.keySet()) { Future<?> clientFuture = clientFutureMap.get(client); if ( !clientFuture.isDone() && !clientFuture.isCancelled()) { clientFuture.cancel(true); } if (client.isActive()) { client.disconnect(); } } } }, ECHO_TIMEOUT, TimeUnit.SECONDS);
private static void handleNewPassiveConnection(OvsdbClient client) { ListenableFuture<List<String>> echoFuture = client.echo(); LOG.debug("Send echo message to probe the OVSDB switch {}",client.getConnectionInfo()); Futures.addCallback(echoFuture, new FutureCallback<List<String>>() { @Override public void onSuccess(@Nullable List<String> result) { LOG.debug("Probe was successful to OVSDB switch {}",client.getConnectionInfo()); List<OvsdbClient> clientsFromSameNode = getPassiveClientsFromSameNode(client); if (clientsFromSameNode.size() == 0) { notifyListenerForPassiveConnection(client); } else { STALE_PASSIVE_CONNECTION_SERVICE.handleNewPassiveConnection(client, clientsFromSameNode); } } @Override public void onFailure(Throwable failureException) { LOG.error("Probe failed to OVSDB switch. Disconnecting the channel {}", client.getConnectionInfo()); client.disconnect(); } }, connectionNotifierService); }
client.getConnectionInfo(), databaseName, tableName, uuid, parentColumn[0], parentColumn[1]); DatabaseSchema dbSchema = client.getDatabaseSchema(databaseName); TransactionBuilder transactionBuilder = client.transactBuilder(dbSchema); this.processDeleteTransaction(client, OvsVswitchdSchemaConstants.DATABASE_NAME, tableName, parentColumn[0], parentColumn[1], uuid, transactionBuilder);
@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()); List<String> databases = new ArrayList<>(); try { databases = externalClient.getDatabases().get(DB_FETCH_TIMEOUT, TimeUnit.MILLISECONDS); if (databases.contains(SouthboundConstants.OPEN_V_SWITCH)) { OvsdbConnectionInstance client = connectedButCallBacksNotRegistered(externalClient); // Register Cluster Ownership for ConnectionInfo registerEntityForOwnership(client); } } catch (InterruptedException | ExecutionException | TimeoutException e) { LOG.warn("Unable to fetch Database list from device {}. Disconnecting from the device.", externalClient.getConnectionInfo().getRemoteAddress(), e); externalClient.disconnect(); } }
private void initializeInventoryForNewNode (Connection connection) throws InterruptedException, ExecutionException, IOException { OvsdbClient client = connection.getClient(); InetAddress address = client.getConnectionInfo().getRemoteAddress(); int port = client.getConnectionInfo().getRemotePort(); List<String> databases = client.getDatabases().get(); if (databases == null) { logger.error("Unable to get Databases for the ovsdb connection : {}", client.getConnectionInfo()); return; } for (String database : databases) { DatabaseSchema dbSchema = client.getSchema(database).get(); TableUpdates updates = this.monitorTables(connection.getNode(), dbSchema); ovsdbInventoryService.processTableUpdates(connection.getNode(), dbSchema.getName(), updates); } logger.info("Notifying Inventory Listeners for Node Added: {}", connection.getNode().toString()); ovsdbInventoryService.notifyNodeAdded(connection.getNode(), address, port); }
private Node handleNewConnection(String identifier, OvsdbClient client) throws InterruptedException, ExecutionException { Connection connection = new Connection(identifier, client); Node node = connection.getNode(); ovsdbConnections.put(identifier, connection); List<String> dbs = client.getDatabases().get(); for (String db : dbs) { client.getSchema(db).get(); } // Keeping the Initial inventory update(s) on its own thread. new Thread() { Connection connection; String identifier; @Override public void run() { try { logger.info("Initialize inventory for {}", connection.toString()); initializeInventoryForNewNode(connection); } catch (InterruptedException | ExecutionException | IOException e) { logger.error("Failed to initialize inventory for node with identifier " + identifier, e); ovsdbConnections.remove(identifier); } } public Thread initializeConnectionParams(String identifier, Connection connection) { this.identifier = identifier; this.connection = connection; return this; } }.initializeConnectionParams(identifier, connection).start(); return node; }
public TableUpdates monitorTables(Node node, DatabaseSchema dbSchema) throws ExecutionException, InterruptedException, IOException { Connection connection = getConnection(node); OvsdbClient client = connection.getClient(); if (dbSchema == null) { logger.error("Unable to get Database Schema for the ovsdb connection : {}", client.getConnectionInfo()); return null; } Set<String> tables = dbSchema.getTables(); if (tables == null) { logger.warn("Database {} without any tables. Strange !", dbSchema.getName()); return null; } List<MonitorRequest> monitorRequests = Lists.newArrayList(); for (String tableName : tables) { GenericTableSchema tableSchema = dbSchema.table(tableName, GenericTableSchema.class); monitorRequests.add(this.getAllColumnsMonitorRequest(tableSchema)); } return client.monitor(dbSchema, monitorRequests, new UpdateMonitor(node)); }
public static void channelClosed(final OvsdbClient client) { LOG.info("Connection closed {}", client.getConnectionInfo().toString()); connections.remove(client); if (client.isConnectionPublished()) { for (OvsdbConnectionListener listener : connectionListeners) { listener.disconnected(client); } } STALE_PASSIVE_CONNECTION_SERVICE.clientDisconnected(client); }
private void handleSpecialInsertCase(OvsdbClient client, String databaseName, String tableName, String uuid, Row<GenericTableSchema> row, TransactionBuilder transactionBuilder) { Port port = client.getTypedRowWrapper(Port.class, null); if (databaseName.equals(OvsVswitchdSchemaConstants.DATABASE_NAME) && tableName.equals(port.getSchema().getName())) { port = client.getTypedRowWrapper(Port.class, row); DatabaseSchema dbSchema = client.getDatabaseSchema(databaseName); TableSchema<GenericTableSchema> tableSchema = dbSchema.table(tableName, GenericTableSchema.class); ColumnSchema<GenericTableSchema, Set<UUID>> columnSchema = tableSchema.multiValuedColumn("interfaces", UUID.class); String namedUuid = "Special_"+tableName; List<Operation> priorOperations = transactionBuilder.getOperations(); Insert portOperation = (Insert)priorOperations.get(0); portOperation.value(columnSchema, new UUID(namedUuid)); Column<GenericTableSchema, ?> nameColumn = port.getNameColumn(); List<Column<GenericTableSchema, ?>> columns = new ArrayList<Column<GenericTableSchema, ?>>(); columns.add(nameColumn); Row<GenericTableSchema> intfRow = new Row<GenericTableSchema>(tableSchema, columns); this.processTypedInsertTransaction(client, databaseName, "Interface", null, null, null, namedUuid, intfRow, transactionBuilder); } }
public ListenableFuture<DatabaseSchema> getSchema(String database) { return client.getSchema(database); }
public ListenableFuture<List<String>> getDatabases() { return client.getDatabases(); }
public <T extends TypedBaseTable<?>> T getTypedRowWrapper(Class<T> klazz, Row<GenericTableSchema> row) { return client.getTypedRowWrapper(klazz, row); }
public boolean isActive() { return client.isActive(); }
public void disconnect() { client.disconnect(); }
public <T extends TypedBaseTable<?>> T createTypedRowWrapper( DatabaseSchema dbSchema, Class<T> klazz) { return client.createTypedRowWrapper(dbSchema, klazz); }
public ListenableFuture<List<OperationResult>> transact( DatabaseSchema dbSchema, List<Operation> operations) { return client.transact(dbSchema, operations); }
public <E extends TableSchema<E>> TableUpdates monitor( DatabaseSchema schema, List<MonitorRequest> monitorRequests, MonitorCallBack callbackArgument) { return client.monitor(schema, monitorRequests, callbackArgument); }