Port AWS harvester config. (#216)

This commit is contained in:
bgrozev 2020-10-09 11:01:35 -05:00 committed by GitHub
parent 3a55627ba0
commit 67ffceb81d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 27 deletions

View File

@ -23,6 +23,8 @@ import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.util.logging.*; import java.util.logging.*;
import static org.ice4j.ice.harvest.HarvestConfig.config;
/** /**
* Manages a static list of {@link MappingCandidateHarvester} instances, created * Manages a static list of {@link MappingCandidateHarvester} instances, created
* according to configuration provided as system properties. * according to configuration provided as system properties.
@ -55,18 +57,6 @@ public class MappingCandidateHarvesters
public static final String NAT_HARVESTER_PUBLIC_ADDRESS_PNAME public static final String NAT_HARVESTER_PUBLIC_ADDRESS_PNAME
= "org.ice4j.ice.harvest.NAT_HARVESTER_PUBLIC_ADDRESS"; = "org.ice4j.ice.harvest.NAT_HARVESTER_PUBLIC_ADDRESS";
/**
* The name of the property used to disable the AWS harvester.
*/
public static final String DISABLE_AWS_HARVESTER_PNAME
= "org.ice4j.ice.harvest.DISABLE_AWS_HARVESTER";
/**
* The name of the property which forces the use of the AWS harvester.
*/
public static final String FORCE_AWS_HARVESTER_PNAME
= "org.ice4j.ice.harvest.FORCE_AWS_HARVESTER";
/** /**
* Whether {@link #harvesters} has been initialized. * Whether {@link #harvesters} has been initialized.
*/ */
@ -135,25 +125,15 @@ public class MappingCandidateHarvesters
} }
// AWS harvester // AWS harvester
boolean disableAwsHarvester boolean enableAwsHarvester = config.enableAwsHarvester();
= StackProperties.getBoolean(DISABLE_AWS_HARVESTER_PNAME, false); if (enableAwsHarvester && (config.forceAwsHarvester() || AwsCandidateHarvester.smellsLikeAnEC2()))
boolean forceAwsHarvester
= StackProperties.getBoolean(FORCE_AWS_HARVESTER_PNAME, false);
if (logger.isLoggable(Level.FINE))
{
logger.fine("AWS configuration: disable=" + disableAwsHarvester
+ "; force=" + forceAwsHarvester);
}
if (!disableAwsHarvester &&
(forceAwsHarvester || AwsCandidateHarvester.smellsLikeAnEC2()))
{ {
logger.info("Using AwsCandidateHarvester.");
harvesterList.add(new AwsCandidateHarvester()); harvesterList.add(new AwsCandidateHarvester());
} }
// STUN harvesters // STUN harvesters
List<String> stunServers = HarvestConfig.config.stunMappingCandidateHarvesterAddresses(); List<String> stunServers = config.stunMappingCandidateHarvesterAddresses();
if (!stunServers.isEmpty()) if (!stunServers.isEmpty())
{ {
// Create STUN harvesters (and wait for all of their discovery to finish). // Create STUN harvesters (and wait for all of their discovery to finish).

View File

@ -61,7 +61,19 @@ class HarvestConfig {
.convertFrom<String> { it.split(",") } .convertFrom<String> { it.split(",") }
"ice4j.harvest.mapping.stun.addresses".from(configSource) "ice4j.harvest.mapping.stun.addresses".from(configSource)
} }
fun stunMappingCandidateHarvesterAddresses() = stunMappingCandidateHarvesterAddresses fun stunMappingCandidateHarvesterAddresses() = stunMappingCandidateHarvesterAddresses
val enableAwsHarvester: Boolean by config {
"org.ice4j.ice.harvest.DISABLE_AWS_HARVESTER".from(configSource).transformedBy { !it }
"ice4j.harvest.mapping.aws.enabled".from(configSource)
}
fun enableAwsHarvester() = enableAwsHarvester
val forceAwsHarvester: Boolean by config {
"org.ice4j.ice.harvest.FORCE_AWS_HARVESTER".from(configSource).transformedBy { !it }
"ice4j.harvest.mapping.aws.force".from(configSource)
}
fun forceAwsHarvester() = enableAwsHarvester
companion object { companion object {
@JvmField @JvmField

View File

@ -44,6 +44,11 @@ ice4j {
// Configuration for the set of "mapping" harvesters. // Configuration for the set of "mapping" harvesters.
mapping { mapping {
aws {
enabled = true
// Whether to use the AWS harvester even when the automatic detection indicates that we are not running in AWS.
force = false
}
stun { stun {
addresses = [ ] addresses = [ ]
# addresses = [ "stun1.example.com:5379", "stun2.example.com:443" ] # addresses = [ "stun1.example.com:5379", "stun2.example.com:443" ]