From 67ffceb81d1577ff772a99a08e07ba53a32f2761 Mon Sep 17 00:00:00 2001 From: bgrozev Date: Fri, 9 Oct 2020 11:01:35 -0500 Subject: [PATCH] Port AWS harvester config. (#216) --- .../harvest/MappingCandidateHarvesters.java | 32 ++++--------------- .../org/ice4j/ice/harvest/HarvestConfig.kt | 14 +++++++- src/main/resources/reference.conf | 5 +++ 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/ice4j/ice/harvest/MappingCandidateHarvesters.java b/src/main/java/org/ice4j/ice/harvest/MappingCandidateHarvesters.java index 30bebfc..1cae9e8 100644 --- a/src/main/java/org/ice4j/ice/harvest/MappingCandidateHarvesters.java +++ b/src/main/java/org/ice4j/ice/harvest/MappingCandidateHarvesters.java @@ -23,6 +23,8 @@ import java.util.*; import java.util.concurrent.*; import java.util.logging.*; +import static org.ice4j.ice.harvest.HarvestConfig.config; + /** * Manages a static list of {@link MappingCandidateHarvester} instances, created * according to configuration provided as system properties. @@ -55,18 +57,6 @@ public class MappingCandidateHarvesters public static final String NAT_HARVESTER_PUBLIC_ADDRESS_PNAME = "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. */ @@ -135,25 +125,15 @@ public class MappingCandidateHarvesters } // AWS harvester - boolean disableAwsHarvester - = StackProperties.getBoolean(DISABLE_AWS_HARVESTER_PNAME, false); - 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())) + boolean enableAwsHarvester = config.enableAwsHarvester(); + if (enableAwsHarvester && (config.forceAwsHarvester() || AwsCandidateHarvester.smellsLikeAnEC2())) { + logger.info("Using AwsCandidateHarvester."); harvesterList.add(new AwsCandidateHarvester()); } // STUN harvesters - List stunServers = HarvestConfig.config.stunMappingCandidateHarvesterAddresses(); + List stunServers = config.stunMappingCandidateHarvesterAddresses(); if (!stunServers.isEmpty()) { // Create STUN harvesters (and wait for all of their discovery to finish). diff --git a/src/main/kotlin/org/ice4j/ice/harvest/HarvestConfig.kt b/src/main/kotlin/org/ice4j/ice/harvest/HarvestConfig.kt index ed37b97..a751484 100644 --- a/src/main/kotlin/org/ice4j/ice/harvest/HarvestConfig.kt +++ b/src/main/kotlin/org/ice4j/ice/harvest/HarvestConfig.kt @@ -61,7 +61,19 @@ class HarvestConfig { .convertFrom { it.split(",") } "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 { @JvmField diff --git a/src/main/resources/reference.conf b/src/main/resources/reference.conf index 3f216dc..c4f7a7f 100644 --- a/src/main/resources/reference.conf +++ b/src/main/resources/reference.conf @@ -44,6 +44,11 @@ ice4j { // Configuration for the set of "mapping" harvesters. 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 { addresses = [ ] # addresses = [ "stun1.example.com:5379", "stun2.example.com:443" ]