Java Code Examples for com.netflix.loadbalancer.PredicateKey#getServer()

The following examples show how to use com.netflix.loadbalancer.PredicateKey#getServer() . 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: DynamicZoneMatcher.java    From spring-cloud-ribbon-extensions with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected boolean doApply(PredicateKey input) {
    Server server = input.getServer();
    String expected = current().get(zoneEntryKey);
    String actual = server.getZone();
    boolean accept = expected != null && expected.equals(actual);
    log.trace("Expected [{}={}] vs {}:{}[zone={}] => {}",
            zoneEntryKey,
            expected,
            server.getHostPort(),
            server.getMetaInfo().getAppName(),
            actual,
            accept);
    return accept;
}
 
Example 2
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 3
Source File: GrayDecisionPredicate.java    From spring-cloud-gray with Apache License 2.0 5 votes vote down vote up
@Override
public boolean apply(PredicateKey input) {

    GrayLoadBalanceRule grayRule = getIRule();
    GrayRequest grayRequest = grayRule.getRequestLocalStorage().getGrayRequest();

    Server server = input.getServer();
    String serviceId = grayRequest.getServiceId();
    String instanceId = server.getMetaInfo().getInstanceId();
    try {
        ServerSpec serverSpec = grayRule.getServerExplainer().apply(server);

        GrayDecisionInputArgs decisionInputArgs = GrayDecisionInputArgs
                .builder().grayRequest(grayRequest).server(serverSpec).build();

        List<GrayDecision> grayDecisions = grayRule.getGrayManager().getGrayDecision(serviceId, instanceId);

        for (GrayDecision grayDecision : grayDecisions) {
            if (grayDecision.test(decisionInputArgs)) {
                return true;
            }
        }
    }catch (Exception e){
        log.error("", e);
    }
    return false;
}
 
Example 4
Source File: DiscoveryEnabledServerPredicate.java    From spring-cloud-ribbon-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
@SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE")
protected boolean doApply(PredicateKey input) {
    return input.getServer() instanceof DiscoveryEnabledServer
            && doApply((DiscoveryEnabledServer) input.getServer());
}
 
Example 5
Source File: NoCanaryFilterMetaPredicate.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean apply(PredicateKey input) {
	if(!DiscoveryEnabledServer.class.isInstance(input.getServer())){
		return false;
	}
	DiscoveryEnabledServer server = (DiscoveryEnabledServer) input.getServer();
	Map<String, String> metaData = server.getInstanceInfo().getMetadata();
	return matchMetaData(metaData);
}
 
Example 6
Source File: CanaryFilterMetaPredicate.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean apply(PredicateKey input) {
	if(!DiscoveryEnabledServer.class.isInstance(input.getServer())){
		return false;
	}
	DiscoveryEnabledServer server = (DiscoveryEnabledServer) input.getServer();
	Map<String, String> metaData = server.getInstanceInfo().getMetadata();
	return matchMetaData(metaData);
}
 
Example 7
Source File: DiscoveryEnabledPredicate.java    From ribbon-discovery-filter-spring-cloud-starter with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean apply(@Nullable PredicateKey input) {
    return input != null
            && input.getServer() instanceof DiscoveryEnabledServer
            && apply((DiscoveryEnabledServer) input.getServer());
}
 
Example 8
Source File: DiscoveryEnabledPredicate.java    From lion with Apache License 2.0 4 votes vote down vote up
@Override
public boolean apply(@Nullable PredicateKey input) {
    return input != null
            && input.getServer() instanceof NacosServer
            && apply((NacosServer) input.getServer());
}
 
Example 9
Source File: NullSafeServerPredicate.java    From spring-cloud-ribbon-extensions with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public final boolean apply(@Nullable PredicateKey input) {
    return input != null && input.getServer() != null && doApply(input);
}