com.netflix.loadbalancer.AbstractServerPredicate Java Examples

The following examples show how to use com.netflix.loadbalancer.AbstractServerPredicate. 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: MetadataCanaryRuleHandler.java    From pig with MIT License 5 votes vote down vote up
@Override
public AbstractServerPredicate getPredicate() {
    return new AbstractServerPredicate() {
        @Override
        public boolean apply(PredicateKey predicateKey) {
            String targetVersion = RibbonVersionHolder.getContext();
            RibbonVersionHolder.clearContext();
            if (StrUtil.isBlank(targetVersion)) {
                log.debug("客户端未配置目标版本直接路由");
                return true;
            }

            DiscoveryEnabledServer server = (DiscoveryEnabledServer) predicateKey.getServer();
            final Map<String, String> metadata = server.getInstanceInfo().getMetadata();
            if (StrUtil.isBlank(metadata.get(SecurityConstants.VERSION))) {
                log.debug("当前微服务{} 未配置版本直接路由");
                return true;
            }

            if (metadata.get(SecurityConstants.VERSION).equals(targetVersion)) {
                return true;
            } else {
                log.debug("当前微服务{} 版本为{},目标版本{} 匹配失败", server.getInstanceInfo().getAppName()
                        , metadata.get(SecurityConstants.VERSION), targetVersion);
                return false;
            }
        }
    };
}
 
Example #2
Source File: DiscoveryEnabledRule.java    From lion with Apache License 2.0 4 votes vote down vote up
@Override
public AbstractServerPredicate getPredicate() {
    return predicate;
}
 
Example #3
Source File: PredicateBasedRuleSupport.java    From spring-cloud-ribbon-extensions with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public AbstractServerPredicate getPredicate() {
    return predicate;
}
 
Example #4
Source File: DiscoveryEnabledRule.java    From ribbon-discovery-filter-spring-cloud-starter with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public AbstractServerPredicate getPredicate() {
    return predicate;
}
 
Example #5
Source File: RuleDescription.java    From spring-cloud-ribbon-extensions with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs a rule description from a predicate.
 *
 * @param predicate the predicate.
 * @return the predicate rule description.
 */
static RuleDescription from(AbstractServerPredicate predicate) {
    return predicate::toString;
}
 
Example #6
Source File: PredicateBasedRuleSupport.java    From spring-cloud-ribbon-extensions with Apache License 2.0 2 votes vote down vote up
/**
 * Creates new instance of {@link PredicateBasedRuleSupport} class with specific predicate.
 *
 * @param predicate the server predicate, can't be null
 * @throws IllegalArgumentException if {@code predicate} is {@code null}
 */
public PredicateBasedRuleSupport(@NotNull AbstractServerPredicate predicate) {
    setPredicate(predicate);
}