Java Code Examples for io.grpc.LoadBalancerProvider#parseLoadBalancingPolicyConfig()

The following examples show how to use io.grpc.LoadBalancerProvider#parseLoadBalancingPolicyConfig() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CachingRlsLbClient.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
private void startFallbackChildPolicy() {
  String defaultTarget = lbPolicyConfig.getRouteLookupConfig().getDefaultTarget();
  fallbackChildPolicyWrapper = refCountedChildPolicyWrapperFactory.createOrGet(defaultTarget);

  LoadBalancerProvider lbProvider =
      lbPolicyConfig.getLoadBalancingPolicy().getEffectiveLbProvider();
  final LoadBalancer lb =
      lbProvider.newLoadBalancer(fallbackChildPolicyWrapper.getHelper());
  final ConfigOrError lbConfig =
      lbProvider
          .parseLoadBalancingPolicyConfig(
              lbPolicyConfig
                  .getLoadBalancingPolicy()
                  .getEffectiveChildPolicy(defaultTarget));
  helper.getSynchronizationContext().execute(
      new Runnable() {
        @Override
        public void run() {
          lb.handleResolvedAddresses(
              childLbResolvedAddressFactory.create(lbConfig.getConfig()));
          lb.requestConnection();
        }
      });
}
 
Example 2
Source File: CachingRlsLbClient.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
private void createChildLbPolicy() {
  ChildLoadBalancingPolicy childPolicy = lbPolicyConfig.getLoadBalancingPolicy();
  LoadBalancerProvider lbProvider = childPolicy.getEffectiveLbProvider();
  ConfigOrError lbConfig =
      lbProvider
          .parseLoadBalancingPolicyConfig(
              childPolicy.getEffectiveChildPolicy(childPolicyWrapper.getTarget()));

  LoadBalancer lb = lbProvider.newLoadBalancer(childPolicyWrapper.getHelper());
  lb.handleResolvedAddresses(childLbResolvedAddressFactory.create(lbConfig.getConfig()));
  lb.requestConnection();
}
 
Example 3
Source File: ServiceConfigUtil.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
/**
 * Parses and selects a load balancing policy from a non-empty list of raw configs. If selection
 * is successful, the returned ConfigOrError object will include a {@link
 * ServiceConfigUtil.PolicySelection} as its config value.
 */
public static ConfigOrError selectLbPolicyFromList(
    List<LbConfig> lbConfigs, LoadBalancerRegistry lbRegistry) {
  List<String> policiesTried = new ArrayList<>();
  for (LbConfig lbConfig : lbConfigs) {
    String policy = lbConfig.getPolicyName();
    LoadBalancerProvider provider = lbRegistry.getProvider(policy);
    if (provider == null) {
      policiesTried.add(policy);
    } else {
      if (!policiesTried.isEmpty()) {
        Logger.getLogger(ServiceConfigUtil.class.getName()).log(
            Level.FINEST,
            "{0} specified by Service Config are not available", policiesTried);
      }
      ConfigOrError parsedLbPolicyConfig =
          provider.parseLoadBalancingPolicyConfig(lbConfig.getRawConfigValue());
      if (parsedLbPolicyConfig.getError() != null) {
        return parsedLbPolicyConfig;
      }
      return ConfigOrError.fromConfig(new PolicySelection(
          provider, lbConfig.rawConfigValue, parsedLbPolicyConfig.getConfig()));
    }
  }
  return ConfigOrError.fromError(
      Status.UNKNOWN.withDescription(
          "None of " + policiesTried + " specified by Service Config are available."));
}