public ListenableFuture<List<String>> getDatabases() { return client.getDatabases(); }
private String caseSensitiveDatabaseName (String ciDatabaseName) { OvsdbClient client = NodeResource.getOvsdbClient(nodeId, this); try { List<String> databases = client.getDatabases().get(); if (databases == null) { return ciDatabaseName; } for (String csDatabaseName : databases) { if (csDatabaseName.equalsIgnoreCase(ciDatabaseName)) { return csDatabaseName; } } return ciDatabaseName; } catch (Exception e) { return ciDatabaseName; } } }
@GET @Produces(MediaType.APPLICATION_JSON) public Response getDatabases(){ OvsdbClient client = NodeResource.getOvsdbClient(nodeId, this); try { List<String> databases = client.getDatabases().get(); if (databases == null) { return Response.noContent().build(); } String response = objectMapper.writeValueAsString(databases); return Response.status(Response.Status.OK) .entity(response) .build(); } catch (Exception e) { throw new InternalServerErrorException("Failed due to exception " + e.getMessage()); } }
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; }
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); }
@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(); } }