@Override public <T extends TypedBaseTable<?>> T getTypedRow(Node node, Class<T> typedClass, Row row) { Connection connection = connectionService.getConnection(node); if (connection == null) { return null; } OvsdbClient client = connection.getClient(); return (T)client.getTypedRowWrapper(typedClass, row); }
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; }
/** * Function called by the dependency manager before the services exported by * the component are unregistered, this will be followed by a "destroy ()" * calls */ void stopping() { for (Connection connection : ovsdbConnections.values()) { connection.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); }
@Override public List<Node> getNodes() { List<Node> nodes = new ArrayList<Node>(); for (Connection connection : ovsdbConnections.values()) { nodes.add(connection.getNode()); } return nodes; }
@Override public Node getNode (String identifier) { Connection connection = ovsdbConnections.get(normalizeId(identifier)); if (connection != null) { return connection.getNode(); } else { return null; } }
private Connection getConnection (Node node) { Connection connection = connectionService.getConnection(node); if (connection == null || !connection.getClient().isActive()) { return null; } return connection; } /*
@Override public void disconnected(OvsdbClient client) { Connection connection = ovsdbConnections.get(this.getConnectionIdentifier(client)); if (connection == null) { return; } this.disconnect(connection.getNode()); } }
public Status disconnect(Node node) { Connection connection = getConnection(node); if (connection != null) { ovsdbConnections.remove(normalizeId(node.getId().getValue())); connection.disconnect(); ovsdbInventoryService.removeNode(node); return new Status(StatusCode.SUCCESS); } else { return new Status(StatusCode.NOTFOUND); } }
@Override public <T extends TypedBaseTable<?>> T createTypedRow(Node node, Class<T> typedClass) { Connection connection = connectionService.getConnection(node); if (connection == null) { return null; } OvsdbClient client = connection.getClient(); return client.createTypedRowWrapper(typedClass); }
public static OvsdbClient getOvsdbClient(String nodeId, Object bundleClassRef) { Connection connection = NodeResource.getOvsdbConnection(nodeId, bundleClassRef); OvsdbClient client = connection.getClient(); if (client == null) { throw new ResourceNotFoundException("No Ovsdb Client to handle Node "+nodeId); } return client; }
public String getSpecialCaseParentUUID(Node node, String databaseName, String childTableName) { if (!databaseName.equals(OvsVswitchdSchemaConstants.DATABASE_NAME)) return null; String[] parentColumn = OvsVswitchdSchemaConstants.getParentColumnToMutate(childTableName); if (parentColumn != null && parentColumn[0].equals(OvsVswitchdSchemaConstants.DATABASE_NAME)) { Connection connection = connectionService.getConnection(node); OpenVSwitch openVSwitch = connection.getClient().getTypedRowWrapper(OpenVSwitch.class, null); ConcurrentMap<String, Row> row = this.getRows(node, openVSwitch.getSchema().getName()); if (row == null || row.size() == 0) return null; return (String)row.keySet().toArray()[0]; } return null; }
controllerIP = connection.getClient().getConnectionInfo().getLocalAddress(); return controllerIP; } catch (Exception e) {
public Boolean setBridgeOFController(Node node, String bridgeIdentifier) { if (connectionService == null) { logger.error("Couldn't refer to the ConnectionService"); return false; } try{ Connection connection = connectionService.getConnection(node); Bridge bridge = connection.getClient().getTypedRowWrapper(Bridge.class, null); Map<String, Row> brTableCache = ovsdbInventoryService.getTableCache(node, OvsVswitchdSchemaConstants.DATABASE_NAME, bridge.getSchema().getName()); for (String uuid : brTableCache.keySet()) { bridge = connection.getClient().getTypedRowWrapper(Bridge.class, brTableCache.get(uuid)); if (bridge.getName().contains(bridgeIdentifier)) { return setOFController(node, uuid); } } } catch(Exception e) { logger.error("Error in setBridgeOFController()",e); } return false; }
@Override public <T extends TypedBaseTable<?>> String getTableName(Node node, Class<T> typedClass) { Connection connection = connectionService.getConnection(node); if (connection == null) { return null; } OvsdbClient client = connection.getClient(); TypedBaseTable<?> typedTable = client.getTypedRowWrapper(typedClass, null); if (typedTable == null) { return null; } return typedTable.getSchema().getName(); }
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)); }
String databaseName = OvsVswitchdSchemaConstants.DATABASE_NAME; Connection connection = connectionService.getConnection(node); OvsdbClient client = connection.getClient();
OvsdbClient client = connection.getClient();
connectionService = (OvsdbConnectionService)ServiceHelper.getGlobalInstance(OvsdbConnectionService.class, this); Node node = connectionService.getNode(nodeId); OvsdbClient client = connectionService.getConnection(node).getClient(); String bckCompatibleTableName = this.getBackwardCompatibleTableName(client, OvsVswitchdSchemaConstants.DATABASE_NAME, tableName); OvsdbRow localRow = OvsdbRow.fromJsonNode(client, OvsVswitchdSchemaConstants.DATABASE_NAME, rowJson);
String parentColumn, UUID rowUuid) throws OvsdbPluginException { Connection connection = connectionService.getConnection(node); OvsdbClient client = connection.getClient();