public DatabaseClient getForestClient(Forest forest) { if ( forest == null ) throw new IllegalArgumentException("forest must not be null"); if (getConnectionType() == DatabaseClient.ConnectionType.GATEWAY) { return getPrimaryClient(); } String hostName = forest.getPreferredHost(); String key = hostName; DatabaseClient client = clientMap.get(key); if ( client != null ) return client; // since this is shared across threads, let's get an exclusive lock on it before updating it synchronized(clientMap) { // just to avoid creating unnecessary DatabaseClient instances, let's check one more time if // another thread just barely inserted an instance that matches client = clientMap.get(key); if ( client != null ) return client; client = DatabaseClientFactory.newClient( hostName, primaryClient.getPort(), forest.getDatabaseName(), primaryClient.getSecurityContext() ); clientMap.put(key, client); } return client; }
client.getSecurityContext().getSSLContext() != null ? "https" : "http", client.getHost(), client.getPort(), "/v1/internal/hubcollector", URLEncoder.encode(jobId, "UTF-8"),
new AuthScope(client.getHost(), client.getPort(), AuthScope.ANY_REALM), new UsernamePasswordCredentials(username, password));
if (getMoveMgr().getConnectionType() == DatabaseClient.ConnectionType.DIRECT) { logger.info("Adding DatabaseClient on port {} for host \"{}\" to the rotation", newHostInfos[i].client.getPort(), host);
MlcpBean bean = new ObjectMapper().readerFor(MlcpBean.class).readValue(mlcpOptions); bean.setHost(databaseClient.getHost()); bean.setPort(databaseClient.getPort()); if (database != null) { bean.setDatabase(database);
@Test public void testArgs() throws Exception { if (moveMgr.getConnectionType() == DatabaseClient.ConnectionType.GATEWAY) return; int defaultPort = client.getPort(); Class<?> defaultAuthContext = client.getSecurityContext().getClass(); ForestConfiguration forestConfig = moveMgr.readForestConfig(); Forest[] forests = forestConfig.listForests(); String defaultDatabase = forests[0].getDatabaseName(); // expect three forests per node assertTrue(forests.length % 3 == 0); for ( Forest forest : forests ) { DatabaseClient forestClient = ((DataMovementManagerImpl) moveMgr).getForestClient(forest); // not all forests for a database are on the same host, so all we // can check is that the hostname is not null assertNotNull(forest.getHost()); // not all hosts have the original REST server, but all hosts have the uber port assertEquals(defaultPort, forestClient.getPort()); assertEquals(defaultDatabase, forest.getDatabaseName()); assertEquals(defaultAuthContext, forestClient.getSecurityContext().getClass()); assertEquals(true, forest.isUpdateable()); if ( forest.getForestName() == null || ! forest.getForestName().startsWith("java-unittest-") ) { fail("Unexpected forestName \"" + forest.getForestName() + "\""); } } } }