Package io.grpc.xds
Class LoadBalancerConfigFactory
- java.lang.Object
-
- io.grpc.xds.LoadBalancerConfigFactory
-
class LoadBalancerConfigFactory extends java.lang.Object
Creates service config JSON load balancer config objects for a given xDS Cluster message. Supports both the "legacy" configuration style and the new, more advanced one that utilizes the xDS "typed extension" mechanism.Legacy configuration is done by setting the lb_policy enum field and any supporting configuration fields needed by the particular policy.
The new approach is to set the load_balancing_policy field that contains both the policy selection as well as any supporting configuration data. Providing a list of acceptable policies is also supported. Note that if this field is used, it will override any configuration set using the legacy approach. The new configuration approach is explained in detail in the Custom LB Policies gRFC
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
LoadBalancerConfigFactory.LegacyLoadBalancingPolicyConverter
Builds a JSON LB configuration based on the old style of using the xDS Cluster proto message.(package private) static class
LoadBalancerConfigFactory.LoadBalancingPolicyConverter
Responsible for converting from aenvoy.config.cluster.v3.LoadBalancingPolicy
proto message to a gRPC service config format.
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.lang.String
BLACK_OUT_PERIOD
(package private) static java.lang.String
CHILD_POLICY_FIELD
(package private) static java.lang.String
CHOICE_COUNT_FIELD_NAME
(package private) static java.lang.String
ENABLE_OOB_LOAD_REPORT
(package private) static java.lang.String
ERROR_UTILIZATION_PENALTY
(package private) static java.lang.String
LEAST_REQUEST_FIELD_NAME
private static XdsLogger
logger
(package private) static java.lang.String
MAX_RING_SIZE_FIELD_NAME
(package private) static java.lang.String
MIN_RING_SIZE_FIELD_NAME
(package private) static java.lang.String
OOB_REPORTING_PERIOD
(package private) static java.lang.String
PICK_FIRST_FIELD_NAME
(package private) static java.lang.String
RING_HASH_FIELD_NAME
(package private) static java.lang.String
ROUND_ROBIN_FIELD_NAME
(package private) static java.lang.String
SHUFFLE_ADDRESS_LIST_FIELD_NAME
(package private) static java.lang.String
WEIGHT_EXPIRATION_PERIOD
(package private) static java.lang.String
WEIGHT_UPDATE_PERIOD
(package private) static java.lang.String
WRR_LOCALITY_FIELD_NAME
-
Constructor Summary
Constructors Constructor Description LoadBalancerConfigFactory()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static com.google.common.collect.ImmutableMap<java.lang.String,?>
buildLeastRequestConfig(java.lang.Integer choiceCount)
Builds a service config JSON object for the least_request load balancer config based on the given config values.private static com.google.common.collect.ImmutableMap<java.lang.String,?>
buildPickFirstConfig(boolean shuffleAddressList)
Builds a service config JSON object for the pick_first load balancer config based on the given config values.private static com.google.common.collect.ImmutableMap<java.lang.String,?>
buildRingHashConfig(java.lang.Long minRingSize, java.lang.Long maxRingSize)
Builds a service config JSON object for the ring_hash load balancer config based on the given config values.private static com.google.common.collect.ImmutableMap<java.lang.String,?>
buildRoundRobinConfig()
Builds an empty service config JSON config object for round robin (it is not configurable).private static com.google.common.collect.ImmutableMap<java.lang.String,?>
buildWrrConfig(java.lang.String blackoutPeriod, java.lang.String weightExpirationPeriod, java.lang.String oobReportingPeriod, java.lang.Boolean enableOobLoadReport, java.lang.String weightUpdatePeriod, java.lang.Float errorUtilizationPenalty)
Builds a service config JSON object for the weighted_round_robin load balancer config based on the given config values.private static com.google.common.collect.ImmutableMap<java.lang.String,?>
buildWrrLocalityConfig(com.google.common.collect.ImmutableMap<java.lang.String,?> childConfig)
Builds a service config JSON wrr_locality by wrapping another policy config.(package private) static com.google.common.collect.ImmutableMap<java.lang.String,?>
newConfig(Cluster cluster, boolean enableLeastRequest)
Factory method for creating a new {link LoadBalancerConfigConverter} for a given xDSCluster
.
-
-
-
Field Detail
-
logger
private static final XdsLogger logger
-
ROUND_ROBIN_FIELD_NAME
static final java.lang.String ROUND_ROBIN_FIELD_NAME
- See Also:
- Constant Field Values
-
RING_HASH_FIELD_NAME
static final java.lang.String RING_HASH_FIELD_NAME
- See Also:
- Constant Field Values
-
MIN_RING_SIZE_FIELD_NAME
static final java.lang.String MIN_RING_SIZE_FIELD_NAME
- See Also:
- Constant Field Values
-
MAX_RING_SIZE_FIELD_NAME
static final java.lang.String MAX_RING_SIZE_FIELD_NAME
- See Also:
- Constant Field Values
-
LEAST_REQUEST_FIELD_NAME
static final java.lang.String LEAST_REQUEST_FIELD_NAME
- See Also:
- Constant Field Values
-
CHOICE_COUNT_FIELD_NAME
static final java.lang.String CHOICE_COUNT_FIELD_NAME
- See Also:
- Constant Field Values
-
WRR_LOCALITY_FIELD_NAME
static final java.lang.String WRR_LOCALITY_FIELD_NAME
- See Also:
- Constant Field Values
-
CHILD_POLICY_FIELD
static final java.lang.String CHILD_POLICY_FIELD
- See Also:
- Constant Field Values
-
BLACK_OUT_PERIOD
static final java.lang.String BLACK_OUT_PERIOD
- See Also:
- Constant Field Values
-
WEIGHT_EXPIRATION_PERIOD
static final java.lang.String WEIGHT_EXPIRATION_PERIOD
- See Also:
- Constant Field Values
-
OOB_REPORTING_PERIOD
static final java.lang.String OOB_REPORTING_PERIOD
- See Also:
- Constant Field Values
-
ENABLE_OOB_LOAD_REPORT
static final java.lang.String ENABLE_OOB_LOAD_REPORT
- See Also:
- Constant Field Values
-
WEIGHT_UPDATE_PERIOD
static final java.lang.String WEIGHT_UPDATE_PERIOD
- See Also:
- Constant Field Values
-
PICK_FIRST_FIELD_NAME
static final java.lang.String PICK_FIRST_FIELD_NAME
- See Also:
- Constant Field Values
-
SHUFFLE_ADDRESS_LIST_FIELD_NAME
static final java.lang.String SHUFFLE_ADDRESS_LIST_FIELD_NAME
- See Also:
- Constant Field Values
-
ERROR_UTILIZATION_PENALTY
static final java.lang.String ERROR_UTILIZATION_PENALTY
- See Also:
- Constant Field Values
-
-
Method Detail
-
newConfig
static com.google.common.collect.ImmutableMap<java.lang.String,?> newConfig(Cluster cluster, boolean enableLeastRequest) throws XdsResourceType.ResourceInvalidException
Factory method for creating a new {link LoadBalancerConfigConverter} for a given xDSCluster
.- Throws:
XdsResourceType.ResourceInvalidException
- If theCluster
has an invalid LB configuration.
-
buildRingHashConfig
private static com.google.common.collect.ImmutableMap<java.lang.String,?> buildRingHashConfig(java.lang.Long minRingSize, java.lang.Long maxRingSize)
Builds a service config JSON object for the ring_hash load balancer config based on the given config values.
-
buildWrrConfig
private static com.google.common.collect.ImmutableMap<java.lang.String,?> buildWrrConfig(java.lang.String blackoutPeriod, java.lang.String weightExpirationPeriod, java.lang.String oobReportingPeriod, java.lang.Boolean enableOobLoadReport, java.lang.String weightUpdatePeriod, java.lang.Float errorUtilizationPenalty)
Builds a service config JSON object for the weighted_round_robin load balancer config based on the given config values.
-
buildLeastRequestConfig
private static com.google.common.collect.ImmutableMap<java.lang.String,?> buildLeastRequestConfig(java.lang.Integer choiceCount)
Builds a service config JSON object for the least_request load balancer config based on the given config values.
-
buildWrrLocalityConfig
private static com.google.common.collect.ImmutableMap<java.lang.String,?> buildWrrLocalityConfig(com.google.common.collect.ImmutableMap<java.lang.String,?> childConfig)
Builds a service config JSON wrr_locality by wrapping another policy config.
-
buildRoundRobinConfig
private static com.google.common.collect.ImmutableMap<java.lang.String,?> buildRoundRobinConfig()
Builds an empty service config JSON config object for round robin (it is not configurable).
-
buildPickFirstConfig
private static com.google.common.collect.ImmutableMap<java.lang.String,?> buildPickFirstConfig(boolean shuffleAddressList)
Builds a service config JSON object for the pick_first load balancer config based on the given config values.
-
-