for( Forest forest : existingFilteredForestConfiguration.listForests()) { if(forest.getPreferredHostType() == HostType.REQUEST_HOST && !forest.getHost().toLowerCase().equals(forest.getRequestHost().toLowerCase())) { if(preferredHostsList.contains(forest.getHost())) { preferredHostsList.remove(forest.getHost());
alternateHost = renames.get(alternateHost); String host = forest.getHost(); if ( host != null ) host = host.toLowerCase(); if ( renames.containsKey(host) ) { if((blackList.contains(forest.getPreferredHost()) || blackList.contains(forest.getHost())) && forest.getPreferredHostType() == HostType.REQUEST_HOST) { hostArray = new String[] {forest.getOpenReplicaHost(), forest.getAlternateHost()}; } else { hostArray = new String[] {forest.getHost(), forest.getOpenReplicaHost(), forest.getAlternateHost(), forest.getRequestHost()}; replaced = replaced.map( forest -> { if ( blackList.contains(forest.getPreferredHost()) || (forest.getPreferredHostType() == HostType.REQUEST_HOST && blackList.contains(forest.getHost()))) { if ( validHosts.length == 0 ) { throw new IllegalStateException("White list or black list rules are too restrictive:" + String host = forest.getHost(); if ( blackList.contains(requestHost) ) { requestHost = replaceHost(requestHost, validHosts); alternateHost = replaceHost(alternateHost, validHosts); String host = forest.getHost(); if ( ! whiteList.contains(host) ) { host = replaceHost(host, validHosts);
/** * Returns the host your application should talk to for this forest. If * getAlternateHost() is not null, return it. Otherwise, if * getOpenReplicaHost() is not null, return it. Otherwise, if * getRequestHost() is not null, return it. Otherwise, return getHost(). * * @return the preferred host for this forest */ public default String getPreferredHost() { if ( getAlternateHost() != null ) { return getAlternateHost(); } else if ( getOpenReplicaHost() != null ) { return getOpenReplicaHost(); } else if ( getRequestHost() != null ) { return getRequestHost(); } else { return getHost(); } }
assertEquals("host1", filteredForests[0].getHost()); assertEquals("alternatehost1", filteredForests[0].getPreferredHost()); assertEquals("openreplicahost1", filteredForests[0].getOpenReplicaHost()); assertEquals("host2", filteredForests[1].getHost()); assertEquals(null, filteredForests[1].getRequestHost()); assertEquals(null, filteredForests[1].getAlternateHost()); assertEquals("host3", filteredForests[2].getHost()); assertEquals(null, filteredForests[2].getOpenReplicaHost()); assertEquals(null, filteredForests[2].getRequestHost()); assertFalse("host4".equals(filteredForests[3].getHost())); assertEquals(null, filteredForests[3].getOpenReplicaHost()); assertEquals(null, filteredForests[3].getAlternateHost());
@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() + "\""); } } } }
assertEquals("host1", filteredForests[0].getHost()); assertEquals("openreplicahost2", filteredForests[1].getPreferredHost()); assertEquals("host2", filteredForests[1].getHost()); assertEquals(null, filteredForests[1].getAlternateHost()); assertEquals(null, filteredForests[1].getRequestHost()); assertEquals("alternatehost3", filteredForests[2].getPreferredHost()); assertEquals("host3", filteredForests[2].getHost()); assertEquals(null, filteredForests[2].getOpenReplicaHost()); assertEquals(null, filteredForests[1].getRequestHost()); assertEquals("requesthost4", filteredForests[3].getPreferredHost()); assertEquals("host4", filteredForests[3].getHost()); assertEquals(null, filteredForests[3].getOpenReplicaHost()); assertEquals(null, filteredForests[3].getAlternateHost());
assertEquals("host1a", filteredForests[0].getHost()); assertEquals("openreplicahost1", filteredForests[0].getOpenReplicaHost()); assertEquals("alternatehost1", filteredForests[0].getAlternateHost()); assertEquals("host1a", filteredForests[0].getHost()); assertEquals("openreplicahost1a", filteredForests[0].getOpenReplicaHost()); assertEquals("alternatehost1", filteredForests[0].getAlternateHost()); assertEquals("host1a", filteredForests[0].getHost()); assertEquals("openreplicahost1a", filteredForests[0].getOpenReplicaHost()); assertEquals("alternatehost1a", filteredForests[0].getAlternateHost()); assertEquals("host1a", filteredForests[0].getHost()); assertEquals("openreplicahost1a", filteredForests[0].getOpenReplicaHost()); assertEquals("alternatehost1a", filteredForests[0].getAlternateHost());