/** * Returns the preferred host type for this forest. If * getAlternateHost() is not null, return ALTERNATE_HOST. Otherwise, if * getOpenReplicaHost() is not null, return OPEN_REPLICA_HOST. Otherwise, * if getRequestHost() is not null, return REQUEST_HOST. * Otherwise, return FOREST_HOST. * * @return the host type of the forest */ public default HostType getPreferredHostType() { if ( getAlternateHost() != null ) { return HostType.ALTERNATE_HOST; } else if ( getOpenReplicaHost() != null ) { return HostType.OPEN_REPLICA_HOST; } else if ( getRequestHost() != null ) { return HostType.REQUEST_HOST; } else { return HostType.FOREST_HOST; } } }
/** * 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(); } }
String openReplicaHost = forest.getOpenReplicaHost(); if ( openReplicaHost != null ) openReplicaHost = openReplicaHost.toLowerCase(); if ( renames.containsKey(openReplicaHost) ) { 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()}; String openReplicaHost = forest.getOpenReplicaHost(); if ( blackList.contains(openReplicaHost) ) { openReplicaHost = replaceHost(openReplicaHost, validHosts); String openReplicaHost = forest.getOpenReplicaHost(); if ( ! whiteList.contains(openReplicaHost) ) { openReplicaHost = replaceHost(openReplicaHost, validHosts);
assertEquals("openreplicahost1", filteredForests[0].getOpenReplicaHost()); assertEquals("requesthost1", filteredForests[0].getRequestHost()); assertEquals("alternatehost1", filteredForests[0].getAlternateHost()); assertFalse("openreplicahost2".equals(filteredForests[1].getOpenReplicaHost())); assertFalse("openreplicahost2".equals(filteredForests[1].getPreferredHost())); assertEquals("host2", filteredForests[1].getHost()); assertFalse("alternatehost3".equals(filteredForests[2].getPreferredHost())); assertEquals("host3", filteredForests[2].getHost()); assertEquals(null, filteredForests[2].getOpenReplicaHost()); assertEquals(null, filteredForests[2].getRequestHost()); assertEquals("forestId3", filteredForests[2].getForestId()); assertFalse("requestHost4".equals(filteredForests[3].getPreferredHost())); assertFalse("host4".equals(filteredForests[3].getHost())); assertEquals(null, filteredForests[3].getOpenReplicaHost()); assertEquals(null, filteredForests[3].getAlternateHost()); assertEquals("forestId4", filteredForests[3].getForestId());
assertFalse("openreplicahost1".equals(filteredForests[0].getOpenReplicaHost())); assertFalse("requesthost1".equals(filteredForests[0].getRequestHost())); assertEquals("forestId1", filteredForests[0].getForestId()); assertEquals("openreplicahost2", filteredForests[1].getOpenReplicaHost()); assertEquals("openreplicahost2", filteredForests[1].getPreferredHost()); assertEquals(null, filteredForests[2].getOpenReplicaHost()); assertEquals(null, filteredForests[1].getRequestHost()); assertEquals("forestId3", filteredForests[2].getForestId()); assertEquals(null, filteredForests[3].getOpenReplicaHost()); assertEquals(null, filteredForests[3].getAlternateHost()); assertEquals("forestId4", filteredForests[3].getForestId());
assertEquals("openreplicahost1", filteredForests[0].getOpenReplicaHost()); assertEquals("alternatehost1", filteredForests[0].getAlternateHost()); assertEquals("requesthost1", filteredForests[0].getRequestHost()); assertEquals("openreplicahost1a", filteredForests[0].getOpenReplicaHost()); assertEquals("alternatehost1", filteredForests[0].getAlternateHost()); assertEquals("requesthost1", filteredForests[0].getRequestHost()); assertEquals("openreplicahost1a", filteredForests[0].getOpenReplicaHost()); assertEquals("alternatehost1a", filteredForests[0].getAlternateHost()); assertEquals("requesthost1", filteredForests[0].getRequestHost()); assertEquals("openreplicahost1a", filteredForests[0].getOpenReplicaHost()); assertEquals("alternatehost1a", filteredForests[0].getAlternateHost()); assertEquals("requesthost1a", filteredForests[0].getRequestHost());