com.netflix.loadbalancer.PredicateKey Java Examples

The following examples show how to use com.netflix.loadbalancer.PredicateKey. 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: 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 #3
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 #4
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 #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: 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 #7
Source File: ZoneAffinityMatcher.java    From spring-cloud-ribbon-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected boolean doApply(PredicateKey server) {
    boolean accept = zone.equals(server.getServer().getZone());
    log.trace("Expected zone [{}] vs {}:{}[{}] => {}",
            zone,
            server.getServer().getHostPort(),
            server.getServer().getMetaInfo().getAppName(),
            server.getServer().getZone(),
            accept);
    return accept;
}
 
Example #8
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 #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);
}
 
Example #10
Source File: NullSafeServerPredicateTest.java    From spring-cloud-ribbon-extensions with Apache License 2.0 4 votes vote down vote up
@Test
public void should_not_filter_when_null_server() throws Exception {
    when(predicate.doApply(any())).thenReturn(true);
    assertThat(predicate.apply(new PredicateKey(null)), is(false));
}
 
Example #11
Source File: NullSafeServerPredicateTest.java    From spring-cloud-ribbon-extensions with Apache License 2.0 4 votes vote down vote up
@Test
public void should_filter_when_delegate_filter() throws Exception {
    when(predicate.doApply(any())).thenReturn(false);
    assertThat(predicate.apply(new PredicateKey(server)), is(false));
}
 
Example #12
Source File: DiscoveryEnabledPredicateTest.java    From spring-cloud-ribbon-extensions with Apache License 2.0 4 votes vote down vote up
@Test
public void should_filter_non_discovery_server() throws Exception {
    when(predicate.doApply(any(DiscoveryEnabledServer.class))).thenReturn(true);
    assertThat(predicate.apply(new PredicateKey(server)), is(false));
}
 
Example #13
Source File: DiscoveryEnabledPredicateTest.java    From spring-cloud-ribbon-extensions with Apache License 2.0 4 votes vote down vote up
@Test
public void should_not_filter_when_discovery_server() throws Exception {
    when(predicate.doApply(any(DiscoveryEnabledServer.class))).thenReturn(true);
    assertThat(predicate.apply(new PredicateKey(discoveryEnabledServer)), is(true));
}
 
Example #14
Source File: DiscoveryEnabledPredicateTest.java    From spring-cloud-ribbon-extensions with Apache License 2.0 4 votes vote down vote up
@Test
public void should_filter_when_discovery_server() throws Exception {
    when(predicate.doApply(any(DiscoveryEnabledServer.class))).thenReturn(false);
    assertThat(predicate.apply(new PredicateKey(discoveryEnabledServer)), is(false));
}
 
Example #15
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 #16
Source File: NullSafeServerPredicate.java    From spring-cloud-ribbon-extensions with Apache License 2.0 2 votes vote down vote up
/**
 * Tests if {@link DiscoveryEnabledServer} matches this predicate.
 *
 * @param input the current server
 * @return {@code true} if the server matches the predicate otherwise {@code false}
 * @see #apply(PredicateKey)
 */
protected abstract boolean doApply(PredicateKey input);
 
Example #17
Source File: CanaryContext.java    From onetwo with Apache License 2.0 votes vote down vote up
PredicateKey getPredicateKey();